Skip to content

Commit

Permalink
Use CUPS_BOOMAGA format for backend
Browse files Browse the repository at this point in the history
  • Loading branch information
SokoloffA committed Jan 20, 2019
1 parent a891bd4 commit a79f064
Show file tree
Hide file tree
Showing 17 changed files with 297 additions and 140 deletions.
Binary file added PJL_Technical_Reference_Manual.pdf
Binary file not shown.
2 changes: 0 additions & 2 deletions scripts/testDBUS.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ FILE=$(readlink -e "${FILE}")
#
# string file
# string title
# bool autoRemove
# string options
# uint count
dbus-send \
Expand All @@ -26,7 +25,6 @@ dbus-send \
--dest=org.boomaga /boomaga org.boomaga.add \
string:"${FILE}" \
string:'title' \
boolean:false \
string:'options' \
uint32:1

51 changes: 11 additions & 40 deletions src/backend/cups_backend/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,46 +129,19 @@ static string mkUserDir(const string &baseDir, const string &user)
/************************************************
*
************************************************/
static bool createBooFile(istream &src, const string &destFile, const Args &args)
static bool createJobFile(istream &src, const string &destFile, const Args &args)
{
Log::debug("Create job file %s", destFile.c_str());
string header;
getline(src, header);


ofstream dest(destFile, ios::binary | ios::trunc);

dest << "\x1B%-12345X@PJL BOOMAGA_PROGECT\n";
dest << "@PJL BOOMAGA META_TITLE=" << args.title << "\n";
dest << "@PJL BOOMAGA JOB_TITLE=" << args.title << "\n";
dest << "@PJL BOOMAGA CUPS_OPTIONS=" << args.options << "\n";
dest << "@PJL SET COPIES = " << args.count << "\n";

if (header.compare(0, 5, "%PDF-") == 0)
{
dest << "@PJL ENTER LANGUAGE=PDF\n";
}
else if (header.compare(0, 5, "%!PS-Adobe-") == 0)
{
dest << "@PJL ENTER LANGUAGE=POSTSCRIPT\n";
}

bool lf = true;
dest << header << endl;
char buf[BUF_SIZE];
do {
src.read(&buf[0], BUF_SIZE);
if (src.gcount())
lf = buf[src.gcount() - 1] == '\n';
dest.write(&buf[0], src.gcount());
} while (src.gcount() > 0);

if (!lf)
dest << "\n";

dest << "\x1B%-12345X@PJL\n";
dest << "@PJL EOJ\n";
dest << "\x1B%-12345X";
dest << "\x1B CUPS_BOOMAGA\n";
dest << "JOB=" << escapeString(args.jobID) << "\n";
dest << "USER=" << escapeString(args.user) << "\n";
dest << "TITLE=" << escapeString(args.title) << "\n";
dest << "COUNT=" << args.count << "\n";
dest << "OPTIONS=" << escapeString(args.options) << "\n";
dest << "CUPS_BOOMAGA_DATA\n";
dest << src.rdbuf();
dest.close();

if (src.bad() || !dest.good())
Expand All @@ -185,7 +158,6 @@ static bool createBooFile(istream &src, const string &destFile, const Args &args
return false;
}


return true;
}

Expand Down Expand Up @@ -269,12 +241,12 @@ int main(int argc, char *argv[])
if (!src.is_open())
Log::fatalError("Can't write job file %s: %s", argv[6], strerror(errno));

if (!createBooFile(src, booFile, args))
if (!createJobFile(src, booFile, args))
return CUPS_BACKEND_FAILED;
}
else
{
if (!createBooFile(std::cin, booFile, args))
if (!createJobFile(std::cin, booFile, args))
return CUPS_BACKEND_FAILED;
}

Expand Down Expand Up @@ -310,7 +282,6 @@ int main(int argc, char *argv[])
execlp("boomaga",
"boomaga",
"--started-from-cups",
"--autoremove",
booFile.c_str(),
NULL);

Expand Down
9 changes: 9 additions & 0 deletions src/boomaga/boomagatypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ T* findExistingForm()
return 0;
}

class BoomagaError: public std::runtime_error
{
public:
explicit BoomagaError(const char *msg): std::runtime_error(msg){}
explicit BoomagaError(const std::string &msg): std::runtime_error(msg){}
explicit BoomagaError(const QString &msg): std::runtime_error(msg.toStdString()){}
};


QString safeFileName(const QString &str);

QString expandHomeDir(const QString &fileName);
Expand Down
14 changes: 11 additions & 3 deletions src/boomaga/dbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,22 @@ BoomagaDbus::~BoomagaDbus()
************************************************/
void BoomagaDbus::add(const QString &file, const QString &title, bool autoRemove, const QString &options, uint count)
{
Q_UNUSED(autoRemove); // 20.01.2019 We keep this method for compatability
add(file, title, options, count);
}


/************************************************
*
************************************************/
void BoomagaDbus::add(const QString &file, const QString &title, const QString &options, uint count)
{
QMetaObject::invokeMethod(this,
"doAdd",
Qt::QueuedConnection,
Q_ARG(QString, file),
Q_ARG(QString, title),
Q_ARG(bool, autoRemove),
Q_ARG(QString, options),
Q_ARG(uint, count));
}
Expand All @@ -74,7 +83,7 @@ void BoomagaDbus::add(const QString &file, const QString &title, bool autoRemove
/************************************************
************************************************/
void BoomagaDbus::doAdd(const QString &file, const QString &title, bool autoRemove, const QString &options, uint count)
void BoomagaDbus::doAdd(const QString &file, const QString &title, const QString &options, uint count)
{
QStringList files;
for (uint i=0; i<count; ++i)
Expand All @@ -84,7 +93,6 @@ void BoomagaDbus::doAdd(const QString &file, const QString &title, bool autoRemo
foreach (Job job, jobs)
{
job.setTitle(title);
job.setAutoRemove(autoRemove);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/boomaga/dbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ class BoomagaDbus: public QObject
static bool runBoomaga(const QString &file, const QString &title,bool autoRemove = false, const QString &options = "", uint count = 1);

public slots:
void add(const QString &file, const QString &title,bool autoRemove = false, const QString &options = "", uint count = 1);
void add(const QString &file, const QString &title, bool autoRemove, const QString &options = "", uint count = 1);
void add(const QString &file, const QString &title, const QString &options = "", uint count = 1);

private slots:
void doAdd(const QString &file, const QString &title,bool autoRemove, const QString &options, uint count);
void doAdd(const QString &file, const QString &title, const QString &options, uint count);
};


Expand Down
33 changes: 1 addition & 32 deletions src/boomaga/kernel/job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
#define LOCK_CHECK 0
#define LOCK_CREATE 100
#define LOCK_DESTROY -1
#define LOCK_TO_REMOVE -99
#define LOCK_TO_NOTREMOVE 99

class JobData: public QSharedData
{
Expand All @@ -53,7 +51,6 @@ class JobData: public QSharedData
QString mTitle;
Job::State mState;
QString mErrorString;
bool mAutoRemove;

static int lockUnlockFile(const QString &file, int lock);
ProjectPage *takePage(ProjectPage *page);
Expand All @@ -67,8 +64,7 @@ JobData::JobData(const QString &fileName, qint64 startPos, qint64 endPos, const
mFileName(fileName),
mStartPos(startPos),
mEndPos(endPos),
mState(Job::JobEmpty),
mAutoRemove(false)
mState(Job::JobEmpty)
{
if (!fileName.isEmpty())
{
Expand Down Expand Up @@ -400,33 +396,6 @@ QString Job::errorString() const
}


/************************************************
************************************************/
bool Job::autoRemove() const
{
return mData->mAutoRemove;
}


/************************************************
************************************************/
void Job::setAutoRemove(bool value)
{
if (!mData->mFileName.isEmpty())
{
if (!mData->mAutoRemove && value)
mData->lockUnlockFile(mData->mFileName, LOCK_TO_REMOVE);

else if (mData->mAutoRemove && !value)
mData->lockUnlockFile(mData->mFileName, LOCK_TO_NOTREMOVE);
}
mData->mAutoRemove = value;

}


/************************************************
*
* ***********************************************/
Expand Down
2 changes: 0 additions & 2 deletions src/boomaga/kernel/job.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class Job
State state() const;
QString errorString() const;

bool autoRemove() const;
void setAutoRemove(bool value);
ProjectPage *insertBlankPage(int before);

Job clone();
Expand Down
Loading

0 comments on commit a79f064

Please sign in to comment.