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