diff options
author | Simon Rettberg | 2015-10-07 12:12:29 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-10-07 12:12:29 +0200 |
commit | dcdf2ae56ccbce71f7106cd8ba7152e33b28744e (patch) | |
tree | bd63f6d100cab2a7f1b78fb201bc5988722f1681 | |
parent | [printergui] Add paper size option (diff) | |
download | printergui-dcdf2ae56ccbce71f7106cd8ba7152e33b28744e.tar.gz printergui-dcdf2ae56ccbce71f7106cd8ba7152e33b28744e.tar.xz printergui-dcdf2ae56ccbce71f7106cd8ba7152e33b28744e.zip |
[pwgui] Only kill printergui after we tried running the backend for the first time
-rw-r--r-- | src/pwgui/main.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp index 4dcfbfb..ad73c24 100644 --- a/src/pwgui/main.cpp +++ b/src/pwgui/main.cpp @@ -37,6 +37,7 @@ static char gui_env[ENVLEN] = "\0\0\0"; static int run_backend(char *backend, char *uri, char *jobid, char *user, char *title, char *copies, char *options, char *file, char *password); +static void helper_killGui(); static bool helper_getpiduid(char *user, char *title); static bool helper_loadlpuser(); static void helper_dropprivs(); @@ -102,7 +103,6 @@ int main(int argc, char *argv[]) execv(backend, argv); exit(127); } - kill(pid, SIGTERM); // Get document to print if (argc == 6) { @@ -125,12 +125,14 @@ int main(int argc, char *argv[]) if (bytes < 0) { helper_messageBox("PrinterGUI", "Konnte den Druckjob nicht auf STDIN empfangen."); ERROR("Could not read print job from STDIN. Over and out.\n"); + close(fh); remove(tmpfile); return CUPS_BACKEND_FAILED; } if ((ret = write(fh, buffer, bytes)) != bytes) { helper_messageBox("PrinterGUI", "Konnte Druckjob nicht in temporäre Datei schreiben."); ERROR("Could not write %d bytes to %s (wrote %d). Over and out.\n", (int)bytes, tmpfile, (int)ret); + close(fh); remove(tmpfile); return CUPS_BACKEND_FAILED; } @@ -155,6 +157,7 @@ int main(int argc, char *argv[]) // Try right away with what we got spoolres = run_backend(backend, device, argv[1], argv[2], argv[3], argv[4], argv[5], tmpfile, NULL); + helper_killGui(); if (spoolres != CUPS_BACKEND_AUTH_REQUIRED) { return helper_cupsError(spoolres); // Yay } @@ -167,7 +170,7 @@ int main(int argc, char *argv[]) WARNING("Direct printing failed. Opening PW dialog....\n"); int pfd[2]; if (pipe(pfd) != 0) { - helper_messageBox("PrinterGUI", "Konnte pipe für die GUI nicht anlegen."); + helper_messageBox("PrinterGUI", "Konnte pipe für die GUI nicht anlegen. Druckvorgang fehlgeschlagen."); ERROR("Could not create pipe for GUI. Over and out.\n"); return CUPS_BACKEND_FAILED; } @@ -207,6 +210,7 @@ int main(int argc, char *argv[]) } while (status != CUPS_BACKEND_OK); remove(tmpfile); ERROR("Job submitted. Over and out.\n"); + helper_killGui(); return CUPS_BACKEND_OK; } @@ -348,6 +352,14 @@ static int run_backend(char *backend, char *uri, char *jobid, char *user, char * return status; } +static void helper_killGui() +{ + if (pid == -1) + return; + kill(pid, SIGTERM); + pid = -1; +} + static bool helper_getpiduid(char *user, char *title) { // it has to be gui-<PID>, PID has to be an instance of printergui @@ -544,6 +556,7 @@ static int helper_cupsError(const int code) static void helper_messageBox(const char *caption, const char *text, const bool error) { + helper_killGui(); WARNING("Trying to MsgBox: %s\n", text); const pid_t pid = fork(); if (pid == 0) { @@ -554,11 +567,19 @@ static void helper_messageBox(const char *caption, const char *text, const bool helper_dropprivs(); helper_copyenv(); QApplication a(argc, argv); + QMessageBox msgBox; + msgBox.setWindowTitle(QString::fromUtf8(caption)); + msgBox.setText(QString::fromUtf8(text)); + msgBox.setWindowFlags(Qt::WindowStaysOnTopHint); if (error) { - QMessageBox::critical(NULL, QString::fromUtf8(caption), QString::fromUtf8(text)); + msgBox.setIcon(QMessageBox::Critical); } else { - QMessageBox::information(NULL, QString::fromUtf8(caption), QString::fromUtf8(text)); + msgBox.setIcon(QMessageBox::Information); } + msgBox.show(); + msgBox.showNormal(); + msgBox.raise(); + msgBox.activateWindow(); exit(0); return; } @@ -566,4 +587,3 @@ static void helper_messageBox(const char *caption, const char *text, const bool // Wait for child to die waitpid(pid, NULL, 0); } - |