00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include "globalsprintersetup.h"
00033
00034
00035 #include "globals.h"
00036
00037
00038 #include <qstring.h>
00039 #include <qtextstream.h>
00040 #include <qmessagebox.h>
00041 #include <qlistbox.h>
00042 #include <qobject.h>
00043 #include <qcursor.h>
00044 #include <qinputdialog.h>
00045
00046
00047 #include <stdlib.h>
00048 using namespace std;
00049
00050 namespace LinuxPrinterSetup
00051 {
00052
00053
00057 PrinterDevice::PrinterDevice()
00058 {
00059 }
00060
00061
00070 PrinterDevice::PrinterDevice( const QString & nativeManufacturer,
00071 const QString & nativeProduct,
00072 ConnectionType connectionType,
00073 const QDomNodeList & drivers)
00074 {
00075 this->nativeManufacturer = nativeManufacturer;
00076 this->nativeProduct = nativeProduct;
00077 this->connectionType = connectionType;
00078 this->drivers = drivers;
00079 }
00080
00081
00087 LpsNotice::LpsNotice( const char * str ) : QString(str)
00088 {
00089 }
00090
00091
00098 LpsNotice::LpsNotice( const QString & str ) : QString(str)
00099 {
00100 }
00101
00102
00108 LpsError::LpsError( const char * str ) : QString(str)
00109 {
00110 }
00111
00112
00119 LpsError::LpsError( const QString & str ) : QString(str)
00120 {
00121 }
00122
00123
00136 QString sudo()
00137 {
00138 bool okPressed;
00139
00140 QString result = "sudo ";
00141
00142 if ( !USE_LIVE_CD_FEATURES )
00143 {
00144
00145
00146
00147 QString rootPassword = QInputDialog::getText(
00148 QObject::tr("Information"),
00149 QObject::tr("Please enter the root password to execute the printer setup command."),
00150 QLineEdit::Password,
00151 0,
00152 &okPressed
00153 );
00154
00155 if ( okPressed )
00156 {
00157 result = QString("echo ") + rootPassword + " | sudo -S ";
00158 }
00159 }
00160
00161 return result;
00162 }
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00187 void showPrinterDriverDetails( const QString & driverName )
00188 {
00189 QString xmlFileName = driverName.section("/", 1, 1);
00190 FILE * pipe = NULL;
00191 QTextStream * reader = NULL;
00192
00193 try
00194 {
00200
00201 QString xmlFilePath = QString(LPS_DRIVER_DETAILS_DIR + xmlFileName + ".xml").remove(" (recommended)");
00202 QString params = "--nonet --stringparam commentTitle " + QObject::tr("Comment");
00203 QString cmd = "xsltproc "+params+" "+MP_DIR() + MONEYPENNY_DATA_DIR + LPS_DRIVER_STYLESHEET_PATH+" " + xmlFilePath;
00204 pipe = popen(cmd.latin1(), "r");
00205
00206 if ( !pipe )
00207 {
00208 throw "Error during xsltproc execution! Could not execute process:<br />" + cmd;
00209 }
00210
00211 reader = new QTextStream(pipe, IO_ReadOnly);
00212
00213 QString details = reader->read().replace(">", ">").replace("<", "<");
00214
00215 QMessageBox::information(0, QObject::tr("Driver Details"), details);
00216 }
00217 catch ( LpsError e )
00218 {
00219
00220
00221
00222 if (reader)
00223 delete reader;
00224 if (pipe)
00225 pclose(pipe);
00226
00227 throw e;
00228 }
00229
00230
00231
00232
00233 if (reader)
00234 delete reader;
00235 if (pipe)
00236 pclose(pipe);
00237 }
00238
00239
00252 void testPrintRequest( QWidget * widget, const QString & printerName )
00253 {
00254
00255
00256
00257 QString question = QObject::tr("Your printer has been configured successfully.") + "<br>" +
00258 QObject::tr("Would you like to print a testpage?");
00259
00260 int answer = QMessageBox::question(widget,
00261 LPS_APP_NAME,
00262 question,
00263 QMessageBox::Yes,
00264 QMessageBox::No,
00265 QMessageBox::NoButton);
00266
00267 if ( answer == QMessageBox::Yes )
00268 {
00269
00270
00271
00272 QString testFile = MP_DIR() + MONEYPENNY_DATA_DIR + "/" + LPS_TESTPAGE_PS_SRC;
00273 QString cmdLpr = "lpr -P "+printerName+" -C "LPS_TESTPAGE_JOBNAME" "+testFile;
00274 qDebug("Printing Testpage: %s", cmdLpr.latin1());
00275
00276
00277
00278
00279
00280 widget->setCursor(Qt::WaitCursor);
00281 if ( system(cmdLpr) != 0 )
00282 {
00283 widget->unsetCursor();
00284 throw LpsError("Error during lpr execution! Could not execute process: " + cmdLpr);
00285 }
00286 widget->unsetCursor();
00287
00288
00289
00290
00291 QDialog dlg;
00292 dlg.setFixedSize(LPS_TESTPAGE_WIDTH, LPS_TESTPAGE_HEIGHT);
00293 QPixmap pxm(MP_DIR() + MONEYPENNY_DATA_DIR + "/" + LPS_TESTPAGE_IMG_SRC);
00294 pxm.resize(LPS_TESTPAGE_WIDTH, LPS_TESTPAGE_HEIGHT);
00295 dlg.setPaletteBackgroundPixmap(pxm);
00296 dlg.setCaption(QObject::tr("Testprint Preview"));
00297 dlg.exec();
00298 }
00299 }
00300
00301
00312 void installPrinter( QWidget * widget,
00313 const QString & printerName,
00314 const QString & deviceUri,
00315 const QString & ppdFilePath )
00316 {
00317
00321
00322 QString cmdLpadmin = sudo() + LPS_LPADMIN_PATH "lpadmin -p " + QString(printerName).replace(" ", "_") + " -E -v " + deviceUri + " -m " + ppdFilePath + "";
00323
00324
00325
00326
00327
00328 widget->setCursor(Qt::WaitCursor);
00329 if ( system(cmdLpadmin) != 0 )
00330 {
00331 widget->unsetCursor();
00332 qDebug("GuiPrinterManualSetup::on_pushButton_saveSettings_clicked: Failed command: %s", cmdLpadmin.latin1());
00333 throw LpsError("Error during lpadmin execution! Could not execute process: " + cmdLpadmin);
00334 }
00335
00336 system("sync");
00337
00338 widget->unsetCursor();
00339 }
00340
00341 };