summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/maingui/printergui.cpp59
-rw-r--r--src/maingui/printergui.h6
2 files changed, 31 insertions, 34 deletions
diff --git a/src/maingui/printergui.cpp b/src/maingui/printergui.cpp
index 99980f2..672bd38 100644
--- a/src/maingui/printergui.cpp
+++ b/src/maingui/printergui.cpp
@@ -9,21 +9,21 @@
// ____________________________________________________________________________
PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
QMainWindow(parent),
- ui(new Ui::PrinterGui)
- //bgTimeout(-1)
+ ui(new Ui::PrinterGui),
+ bgTimeout(-1)
{
// When called it is guaranteed that argv has (at least) 3 elements
// Set username
// Do not use getlogin[_r] as it doesn't fucking work!
-// struct passwd *pw = getpwuid(getuid());
-// if (pw != NULL && pw->pw_name != NULL) {
-// // Detect real name
-// this->user = strdup(pw->pw_name);
-// } else {
-// // Fallback to what command line says
- this->user = strdup(argv[1]);
-// }
+ struct passwd *pw = getpwuid(getuid());
+ if (pw != NULL && pw->pw_name != NULL && pw->pw_name[0] != '\0') {
+ // Detect real name
+ this->user = strdup(pw->pw_name);
+ } else {
+ // Fallback to what command line says
+ this->user = strdup(argv[1]);
+ }
// Filename
this->file = new char[strlen(argv[2]) + 10]; // + 10 in case we rename (ghostscript)
@@ -35,11 +35,10 @@ PrinterGui::PrinterGui(char *argv[], QWidget *parent) :
// Initialize UI
initializeUI();
-// // Timer
-// this->bgTimer = new QTimer(this);
-// this->bgTimer->setInterval(1000);
-// this->bgTimer->start(1000);
-// connect(bgTimer, SIGNAL(timeout()), this, SLOT(on_bgTimer_timeout()));
+ // Timer
+ this->bgTimer = new QTimer(this);
+ connect(bgTimer, SIGNAL(timeout()), this, SLOT(bgTimer_timeout()));
+ this->bgTimer->start(1000);
}
// ____________________________________________________________________________
@@ -102,6 +101,7 @@ void PrinterGui::initializeUI()
ui->comboBoxSides->hide();
ui->label_color->hide();
ui->label_duplex->hide();
+
this->show();
this->showNormal();
this->raise();
@@ -218,8 +218,7 @@ void PrinterGui::on_printerList_currentItemChanged(QTreeWidgetItem *current, QTr
// ____________________________________________________________________________
void PrinterGui::on_buttonCancel_clicked()
{
- // Quit with code 1
- QCoreApplication::instance()->exit(1);
+ QCoreApplication::instance()->exit(0);
}
// ____________________________________________________________________________
@@ -268,23 +267,21 @@ void PrinterGui::on_buttonPrint_clicked()
dest->options)) {
QMessageBox::critical(this, "CUPS Fehler", cupsLastErrorString());
} else {
- //this->bgTimeout = 0;
- QCoreApplication::instance()->exit(0);
+ this->bgTimeout = 0;
this->hide();
- QTimer::singleShot(4000, QCoreApplication::instance(), SLOT(quit()));
}
}
-//void PrinterGui::on_bgTimer_timeout()
-//{
-// if (this->bgTimeout == -1) {
-// // Could do something here every second....
-// return;
-// }
-// if (++this->bgTimeout > 4) {
-// // Job was sent, GUI is invisible, quit after a few seconds
-// QCoreApplication::instance()->exit(0);
-// }
-//}
+void PrinterGui::bgTimer_timeout()
+{
+ if (this->bgTimeout == -1) {
+ // Could do something here every second....
+ return;
+ }
+ if (++this->bgTimeout > 120) {
+ // Job was sent, GUI is invisible, quit after a few seconds
+ QCoreApplication::instance()->exit(0);
+ }
+}
diff --git a/src/maingui/printergui.h b/src/maingui/printergui.h
index 77d50b4..624b44c 100644
--- a/src/maingui/printergui.h
+++ b/src/maingui/printergui.h
@@ -26,7 +26,7 @@ private slots:
void on_printerList_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
void on_buttonCancel_clicked();
void on_buttonPrint_clicked();
-// void on_bgTimer_timeout();
+ void bgTimer_timeout();
private:
Ui::PrinterGui *ui;
@@ -35,8 +35,8 @@ private:
int num_dests;
char * user;
char * file;
-// QTimer * bgTimer;
-// int bgTimeout;
+ QTimer * bgTimer;
+ int bgTimeout;
QString _colorOptionName;
QString _duplexOptionName;