summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManuel Schneider2013-09-30 17:00:07 +0200
committerManuel Schneider2013-09-30 17:00:07 +0200
commit3b24a2e128f2938d6d827fdbc696865b9bb0db23 (patch)
tree827725edab41dab0c50473586d20221e08911580
parentInitial (diff)
downloadprintergui-3b24a2e128f2938d6d827fdbc696865b9bb0db23.tar.gz
printergui-3b24a2e128f2938d6d827fdbc696865b9bb0db23.tar.xz
printergui-3b24a2e128f2938d6d827fdbc696865b9bb0db23.zip
Added new param 'username'
-rw-r--r--PrinterGUI/PrinterGUI_SRC/main.cpp6
-rw-r--r--PrinterGUI/PrinterGUI_SRC/mainwindow.cpp108
-rw-r--r--PrinterGUI/PrinterGUI_SRC/mainwindow.h3
-rw-r--r--PrinterGUI/PrinterGUI_SRC/mainwindow.ui8
-rwxr-xr-xprinterd24
5 files changed, 116 insertions, 33 deletions
diff --git a/PrinterGUI/PrinterGUI_SRC/main.cpp b/PrinterGUI/PrinterGUI_SRC/main.cpp
index 784c88a..2b97c95 100644
--- a/PrinterGUI/PrinterGUI_SRC/main.cpp
+++ b/PrinterGUI/PrinterGUI_SRC/main.cpp
@@ -5,14 +5,14 @@
int main(int argc, char *argv[])
{
// First check parameter count
- if (argc != 2)
+ if (argc != 3)
return 2;
// Check if file exists
std::fstream f;
try
{
- f.open(argv[1], std::ios::in);
+ f.open(argv[2], std::ios::in);
}
catch (std::fstream::failure e)
{
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
f.close();
QApplication a(argc, argv);
- MainWindow w(argv[1]);
+ MainWindow w(argv);
w.show();
return a.exec();
diff --git a/PrinterGUI/PrinterGUI_SRC/mainwindow.cpp b/PrinterGUI/PrinterGUI_SRC/mainwindow.cpp
index 03e74e9..cc40d5e 100644
--- a/PrinterGUI/PrinterGUI_SRC/mainwindow.cpp
+++ b/PrinterGUI/PrinterGUI_SRC/mainwindow.cpp
@@ -4,10 +4,11 @@
-MainWindow::MainWindow(char *argv, QWidget *parent) :
+MainWindow::MainWindow(char *argv[], QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
- file(argv)
+ user(argv[1]),
+ file(argv[2])
{
// Initialize cups
num_dests = cupsGetDests(&dests);
@@ -53,6 +54,8 @@ void MainWindow::initializeUI()
wi->setText(1, QString(cupsGetOption("printer-info", dest->num_options, dest->options)));
wi->setText(2, QString(cupsGetOption("printer-location", dest->num_options, dest->options)));
ui->printerList->addTopLevelItem(wi);
+ if (dest->is_default)
+ ui->printerList->setCurrentItem(wi);
}
// Resize columns to contents
@@ -170,46 +173,105 @@ void MainWindow::on_buttonPrint_clicked()
cmd = QString("gs -sDEVICE=psgray -dNOPAUSE -dBATCH -dQUIET -dSAFER -sOutputFile=\"%22\" \"%1\"").arg(
file,
file);
- system(cmd.toAscii());
+ if (system(cmd.toAscii()))
+ return; // TODO WARN ABOUT MISSED GS JOB
+
}
- // Username, part of whoami source
- register uid_t uid = geteuid();
- const char *username = getpwuid(uid)->pw_name;
- cmd = QString("lp -U %1").arg(username);
+
+
+
+/* * Print via sysctem command * */
+// // Username, part of whoami source
+// register uid_t uid = geteuid();
+// const char *username = getpwuid(uid)->pw_name;
+// cmd = QString("lp -U %1").arg(username);
+// // Duplex
+// if (ui->comboBoxSides->isEnabled())
+// {
+// switch (ui->comboBoxSides->currentIndex()){
+// case 0:
+// cmd.append(" -o sides=one-sided");
+// break;
+// case 1:
+// cmd.append(" -o sides=two-sided-long-edge");
+// break;
+// case 2:
+// cmd.append(" -o sides=two-sided-long-edge");
+// break;
+// }
+// }
+// // Kopien
+// if (ui->lineEditCopies->isEnabled())
+// cmd.append(QString(" -n %1").arg(ui->lineEditCopies->text()));
+// // Queue
+// cmd.append(QString(" -d %1").arg(ui->printerList->currentItem()->text(0)));
+// // File
+// cmd.append(QString(" -- \"%1\"").arg(file));
+// // Print results to stdout
+// QTextStream (stdout, QIODevice::WriteOnly) << cmd;
+// // Execute the command
+// system(cmd.toAscii());
+
+
+
+
+ /* * Print via cups lib * */
+
+ // Username
+ cupsSetUser(user);
+
+ // Destination / Queue
+ cups_dest_t *dest = cupsGetDest(
+ ui->printerList->currentItem()->text(0).toAscii(),
+ NULL,
+ num_dests,
+ dests);
// Duplex
if (ui->comboBoxSides->isEnabled())
{
switch (ui->comboBoxSides->currentIndex()){
case 0:
- cmd.append(" -o sides=one-sided");
+ dest->num_options = cupsAddOption ("Duplex",
+ "None",
+ dest->num_options,
+ &(dest->options));
break;
case 1:
- cmd.append(" -o sides=two-sided-long-edge");
+ dest->num_options = cupsAddOption ("Duplex",
+ "DuplexNoTumble",
+ dest->num_options,
+ &(dest->options));
break;
case 2:
- cmd.append(" -o sides=two-sided-long-edge");
+ dest->num_options = cupsAddOption ("Duplex",
+ "DuplexTumble",
+ dest->num_options,
+ &(dest->options));
break;
}
}
// Kopien
if (ui->lineEditCopies->isEnabled())
- cmd.append(QString(" -n %1").arg(ui->lineEditCopies->text()));
-
- // Queue
- cmd.append(QString(" -d %1").arg(ui->printerList->currentItem()->text(0)));
+ {
+ dest->num_options = cupsAddOption ("copies",
+ ui->lineEditCopies->text().toAscii(),
+ dest->num_options,
+ &(dest->options));
+ }
- // File
- cmd.append(QString(" -- \"%1\"").arg(file));
+ // Drucken
+ if( 0 == cupsPrintFile(dest->name,
+ file,
+ NULL,
+ dest->num_options,
+ dest->options))
+ return; // TODO ERROR OUTPUT
+ else // Quit with code 0
+ QCoreApplication::instance()->quit();
- // Print results to stdout
- QTextStream (stdout, QIODevice::WriteOnly) << cmd;
+}
- // Execute the command
- system(cmd.toAscii());
- // Quit with code 0
- QCoreApplication::instance()->quit();
-}
diff --git a/PrinterGUI/PrinterGUI_SRC/mainwindow.h b/PrinterGUI/PrinterGUI_SRC/mainwindow.h
index 0078cde..4b89262 100644
--- a/PrinterGUI/PrinterGUI_SRC/mainwindow.h
+++ b/PrinterGUI/PrinterGUI_SRC/mainwindow.h
@@ -16,7 +16,7 @@ class MainWindow : public QMainWindow
Q_OBJECT
public:
- explicit MainWindow(char *argv, QWidget *parent = 0);
+ explicit MainWindow(char *argv[], QWidget *parent = 0);
~MainWindow();
private slots:
@@ -29,6 +29,7 @@ private:
void initializeUI();
cups_dest_t *dests;
int num_dests;
+ const char * const user;
const char * const file;
};
diff --git a/PrinterGUI/PrinterGUI_SRC/mainwindow.ui b/PrinterGUI/PrinterGUI_SRC/mainwindow.ui
index 1be9776..0a56de6 100644
--- a/PrinterGUI/PrinterGUI_SRC/mainwindow.ui
+++ b/PrinterGUI/PrinterGUI_SRC/mainwindow.ui
@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>559</width>
+ <width>574</width>
<height>286</height>
</rect>
</property>
@@ -19,6 +19,12 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTreeWidget" name="printerList">
+ <property name="showDropIndicator" stdset="0">
+ <bool>false</bool>
+ </property>
+ <property name="alternatingRowColors">
+ <bool>true</bool>
+ </property>
<column>
<property name="text">
<string notr="true">1</string>
diff --git a/printerd b/printerd
index ef93722..05a1052 100755
--- a/printerd
+++ b/printerd
@@ -4,13 +4,28 @@
# incoming data into UNIX lpd, which starts a helper program when a print-
# job is incoming.
-USER="$1"
+USER="manuel"
BUSYBOX="busybox"
IP="0.0.0.0"
PORT="515"
SPOOLDIR="/var/spool"
SPOOLQUEUE="STANDARD"
-GUIBINARY="printerGUI"
+
+
+# SHALL BE UNNECESSARY HENCE printerd RUNS IN USERCONTEXT
+## If there are more than 1 seats open, quit
+#if [ $(loginctl list-seats) != "seat0" ]; then
+# exit
+#fi
+#
+## Get the name(s) of the users physically using the machine
+#NAME=$( loginctl | awk '$3 !~ /root/, $4 ~ /seat0/ { print $3 }' | sort -u )
+#
+## Print error in case of multiple users
+#if (( $(echo $NAME | wc -w ) > 1 )) ; then
+# echo "[$0] To many users on this seat. Usernames: $NAME" > /tmp/debug-report/printer
+# exit
+#fi
# Create the directory for the queue
mkdir -p "$SPOOLDIR/$SPOOLQUEUE"
@@ -20,7 +35,6 @@ mkdir -p "$SPOOLDIR/$SPOOLQUEUE"
chown $USER:$USER "$SPOOLDIR/$SPOOLQUEUE"
# Start the lpdaemon listening on the given port
-exec "$BUSYBOX" tcpsvd -Eu "$USER:$USER" "$IP" "$PORT" \
- "$BUSYBOX" lpd "$SPOOLDIR" \
- "$GUIBINARY"
+"$BUSYBOX" tcpsvd -Eu "$USER:$USER" "$IP" "$PORT" \
+ "$BUSYBOX" lpd "$SPOOLDIR" sh -c 'printerGUI ms1144 $DATAFILE' &