00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "urpomainwindow.h"
00024
00025
00026 #include "urpoconnectionsettings.h"
00027 #include "printerlistjob.h"
00028 #include "debugconsole.h"
00029 #include "printwidget.h"
00030 #include "printjob.h"
00031
00032 #include <QMenuBar>
00033 #include <QMessageBox>
00034 #include <QApplication>
00035 #include <QTextBrowser>
00036 #include <QUrl>
00037 #include <QLocale>
00038 #include <QFile>
00039
00040 #include <cstdlib>
00041
00042 #include "settingsdialog.h"
00043
00044 #define VERSION "0.9.2"
00046 UrpoMainWindow::UrpoMainWindow(QWidget *parent)
00047 : QMainWindow(parent)
00048 {
00049 setWindowTitle(QString("URPO ") + VERSION );
00050 setWindowIcon( QIcon(":/urpo.png"));
00051
00052
00053 settings_ = new UrpoConnectionSettings("Urpo","Urpo");
00054 settings_->load();
00055
00056
00057 monitor_ = new DebugConsole();
00058 settings_->setDebugMonitor(monitor_);
00059
00060
00061 printWidget_ = new PrintWidget;
00062 setCentralWidget(printWidget_);
00063
00064
00065 initHelp();
00066
00067 initMenu();
00068
00069
00070 connect( printWidget_, SIGNAL(reconnect()), this, SLOT(getPrinters()));
00071 connect( printWidget_, SIGNAL(print(QString,QString)), this, SLOT(print(QString,QString)));
00072
00073
00074
00075
00076 printerListJob_ = new PrinterListJob( settings_);
00077
00078
00079
00080 connect( printerListJob_, SIGNAL(finished(bool,QString)), this, SLOT(printersReceived(bool,QString)));
00081
00082
00083 printJob_ = new PrintJob(settings_);
00084 connect( printJob_, SIGNAL(finished(bool,QString)), this, SLOT(printFinished(bool,QString)));
00085
00086 if( settings_->getHost().isEmpty())
00087
00088 settings();
00089 else
00090
00091 getPrinters();
00092
00093
00094 }
00095
00096 UrpoMainWindow::~UrpoMainWindow()
00097 {
00098
00099 }
00100
00101 void UrpoMainWindow::getPrinters()
00102 {
00103
00104 printWidget_->setStatus(tr("Connecting..."),true);
00105 connect(printWidget_, SIGNAL(cancel()), printerListJob_, SLOT(cancel()));
00106 printerListJob_->start();
00107
00108 }
00109
00110
00111 void UrpoMainWindow::initMenu()
00112 {
00113
00114 QAction* settingsAction = new QAction( tr("Settings"), this);
00115 connect(settingsAction, SIGNAL(triggered()), this, SLOT(settings()) );
00116 menuBar()->addAction(settingsAction);
00117
00118 QAction* debugAction = new QAction( tr("Debug"), this);
00119 debugAction->setStatusTip(tr("Open debug console"));
00120 connect(debugAction, SIGNAL(triggered()), this, SLOT(debugWindow() ));
00121 menuBar()->addAction(debugAction);
00122
00123 QAction* aboutAction = new QAction( tr("About"), this);
00124 connect(aboutAction, SIGNAL(triggered()), this, SLOT(about()));
00125 menuBar()->addAction(aboutAction);
00126
00127 QAction* aboutQtAction = new QAction( tr("About Qt"), this );
00128 connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
00129 menuBar()->addAction(aboutQtAction);
00130
00131
00132 QAction* helpAction = new QAction( tr("Help"), this );
00133 connect( helpAction, SIGNAL(triggered()), this, SLOT(helpWindow()));
00134 menuBar()->addAction(helpAction);
00135
00136 }
00137
00138 void UrpoMainWindow::initHelp()
00139 {
00140
00141
00142
00143
00144 helpBrowser_ = new QTextBrowser();
00145 helpBrowser_->setWindowTitle(tr("Urpo Help"));
00146
00147
00148
00149
00150
00151
00152 QString language = std::getenv("LANG");
00153
00154 QString helpfilename = QString(":/help/index_") + language.left(2).toLower() + QString(".html");
00155
00156 QFile helpfile( helpfilename );
00157 if( helpfile.exists() )
00158 helpBrowser_->setSource(QUrl( QString("qrc") + helpfilename ));
00159 else
00160
00161 helpBrowser_->setSource(QUrl("qrc:/help/index.html"));
00162
00163 helpBrowser_->setOpenExternalLinks(true);
00164
00165 }
00166
00167 void UrpoMainWindow::printersReceived(bool success, QString error)
00168 {
00169
00170 disconnect(printWidget_, SIGNAL(cancel()), printerListJob_, SLOT(cancel()));
00171 if(success)
00172 {
00173
00174 printWidget_->setPrinters( printerListJob_->getPrinters());
00175 if( printerListJob_->getPrinters().isEmpty())
00176 {
00177
00178 printWidget_->setStatus( QString("<font color=red>") + tr("No printers found") + QString("</font>"),false);
00179 printWidget_->setReady(false);
00180 }
00181 else
00182 {
00183
00184 printWidget_->setReady( true );
00185 }
00186
00187 }
00188 else
00189 {
00190
00191 printWidget_->setStatus( QString("<font color=red>") + error + QString("</font>") );
00192 printWidget_->setReady(false);
00193 }
00194 }
00195
00196 void UrpoMainWindow::about()
00197 {
00198 QMessageBox::about(this, tr("About Urpo"),
00199 tr("<b>Unix Remote Printing Operation %1 </b>"
00200 "<p>Copyright © Arto Hyvättinen 2010"
00201 "<p>License: General Public License v3"
00202 ).arg(VERSION));
00203 }
00204
00205 void UrpoMainWindow::settings()
00206 {
00207 printWidget_->doCancel();
00208
00209 SettingsDialog* dialog = new SettingsDialog(this);
00210 dialog->setSettings(settings_);
00211 dialog->setHelp(helpBrowser_);
00212 dialog->show();
00213
00214
00215 connect( dialog, SIGNAL(accepted()), this, SLOT(getPrinters()));
00216
00217 }
00218
00219 void UrpoMainWindow::debugWindow()
00220 {
00221 monitor_->show();
00222 monitor_->raise();
00223 monitor_->activateWindow();
00224 }
00225
00226 void UrpoMainWindow::helpWindow()
00227 {
00228
00229
00230 helpBrowser_->home();
00231 helpBrowser_->show();
00232 helpBrowser_->raise();
00233 helpBrowser_->activateWindow();
00234 }
00235
00236 void UrpoMainWindow::print(QString file, QString options)
00237 {
00238 printWidget_->setStatus( tr("Printing..."), true );
00239 connect( printWidget_, SIGNAL(cancel()), printJob_, SLOT(cancel()));
00240 printJob_->printFile(file,options);
00241 }
00242
00243 void UrpoMainWindow::printFinished(bool success, QString errorStr)
00244 {
00245 disconnect( printWidget_, SIGNAL(cancel()), printJob_, SLOT(cancel()));
00246 printWidget_->setReady(true);
00247 if( success == false )
00248 {
00249 printWidget_->setReady(true);
00250 printWidget_->setStatus( QString("<font color=red>") + errorStr + QString("</font>"));
00251 }
00252 }