PageRenderTime 75ms CodeModel.GetById 28ms app.highlight 41ms RepoModel.GetById 2ms app.codeStats 0ms

/vp_plugins/print_monitor/mainwindow.cpp

http://cupsfilter.googlecode.com/
C++ | 536 lines | 424 code | 75 blank | 37 comment | 33 complexity | 1ccfe9c381fad8ff3501aaf9a55bfa1a MD5 | raw file
  1#include <QtCore/QVariant>
  2#include <QtCore/QDebug>
  3#include <QtCore/QFile>
  4#include <QtCore/QSettings>
  5
  6#include <QtGui/QAction>
  7#include <QtGui/QApplication>
  8#include <QtGui/QComboBox>
  9#include <QtGui/QFrame>
 10#include <QtGui/QHBoxLayout>
 11#include <QtGui/QLabel>
 12#include <QtGui/QPushButton>
 13#include <QtGui/QSpacerItem>
 14#include <QtGui/QVBoxLayout>
 15#include <QtGui/QWidget>
 16#include <QtGui/QAction>
 17#include <QtGui/QStackedWidget>
 18
 19#include <QtGui/QErrorMessage>
 20
 21#include <QTableView>
 22
 23
 24#include "mainwindow.h"
 25#include "mytypes.h"
 26#include "engine.h"
 27#include "getusernamemandatdlg.h"
 28
 29using namespace VPrn;
 30
 31MainWindow::MainWindow(QWidget *parent)
 32        : QWidget(parent)
 33        , pageId(0)
 34
 35{
 36    //??????? ?????? ??????
 37    desktop_avail = desktop.availableGeometry(desktop.primaryScreen());
 38
 39    this->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::MinimumExpanding);
 40    //this->setMinimumSize(320,240);
 41    this->setMaximumSize(desktop_avail.width()-5,desktop_avail.height()-5);
 42    this->move( calcDeskTopCenter(this->width(),this->height() ));
 43    mainLayout = new QVBoxLayout(this);
 44
 45    //------------------------------- ??????????? ?????    -------------------------------
 46    stackedWidget = new QStackedWidget();
 47    introPage     = new IntroPage();
 48    selectPage    = new SelectPage();
 49    printDataPage = new PrintDataPage();
 50    checkDataPage = new CheckDataPage();
 51    preViewPage   = new PreViewPage();
 52    finishPage    = new FinishPage();
 53
 54    stackedWidget->addWidget(introPage);
 55    stackedWidget->addWidget(selectPage);
 56    stackedWidget->addWidget(printDataPage);
 57    stackedWidget->addWidget(checkDataPage);
 58    stackedWidget->addWidget(preViewPage);
 59    stackedWidget->addWidget(finishPage);
 60    //????????? ???? ????????
 61    printDataPage->setMaximumSize(desktop_avail.width()-5,desktop_avail.height()-5);
 62
 63
 64    line = new QFrame(this);
 65    line->setObjectName(QString::fromUtf8("line"));
 66    line->setFrameShape(QFrame::HLine);
 67    line->setFrameShadow(QFrame::Sunken);
 68
 69    //------------------------------- ?????? ???? - ?????? -------------------------------
 70
 71    horizontalLayout = new QHBoxLayout();
 72    horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
 73    horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
 74    helpButton       = new QPushButton(this);
 75    prevButton       = new QPushButton(this);
 76    nextButton       = new QPushButton(this);
 77    restartButton    = new QPushButton(this);
 78    exitButton       = new QPushButton(this);
 79    helpButton->setText(QObject::trUtf8("???????"));
 80    prevButton->setText(QObject::trUtf8("< ?????"));
 81    nextButton->setText(QObject::trUtf8("?????? >"));
 82    restartButton->setText(QObject::trUtf8("? ??????"));
 83    exitButton->setText(QObject::trUtf8("?????"));
 84
 85    horizontalLayout->addWidget(helpButton);
 86    horizontalLayout->addItem(horizontalSpacer);
 87    horizontalLayout->addWidget(prevButton);
 88    horizontalLayout->addWidget(nextButton);
 89    horizontalLayout->addWidget(restartButton);
 90    horizontalLayout->addItem(horizontalSpacer_2);
 91    horizontalLayout->addWidget(exitButton);
 92    //-------------------------------------- ?????????? ----------------------------------------------------
 93
 94    mainLayout->addWidget(stackedWidget);
 95    mainLayout->addWidget(line);
 96    mainLayout->addLayout(horizontalLayout);
 97
 98    if (stackedWidget->currentIndex () != -1 ){
 99        this->setWindowTitle(stackedWidget->currentWidget()->windowTitle() );
100    }else{
101        this->setWindowTitle( QObject::trUtf8("?????? ???????? ???? ???????") );
102    }
103}
104
105void MainWindow::init(const QString &app_dir,const QString &input_file)
106{
107    this->readConfig(app_dir);
108    //???????? ??????????? ??????
109    myEMsgBox = new QErrorMessage(this);
110
111    //????????? ????????? ??????
112    data_module = new DataModule(this);
113
114    //?????? ????
115    engine = new Engine(this,link_name,gatekeeper_bin);
116
117    createConnection();
118
119    if ( data_module->setWorkFile(input_file)){
120        introPage->setInputFile();
121    }
122
123    engine->setDocCardModel    ( data_module->getDocCardModel()   );
124    engine->setPrintersModel   ( data_module->getPrintersModel()  );
125    engine->setStampsModel     ( data_module->getStampsModel()    );
126    engine->setTemplatesModel  ( data_module->getTemplatesModel() );
127    engine->setMandatsModel    ( data_module->getMandatsModel()   );
128    engine->launchAndConnect();
129
130    selectPage->setPrintersModel     ( data_module->getPrintersModel()  );
131    printDataPage->setSecListModel   ( data_module->getStampsModel()    );
132    printDataPage->setCardDocModel   ( data_module->getDocCardModel()   );
133    printDataPage->setTemplatesModel ( data_module->getTemplatesModel() );
134
135}
136
137void MainWindow::appendStartMsg(const QString &txt_msg)
138{
139    myEMsgBox->showMessage(txt_msg);
140}
141
142MainWindow::~MainWindow()
143{
144
145}
146
147//------------------------------------PRIVATE SLOTS ------------------------------------
148void MainWindow::do_next()
149{
150    switch (pageId +1){
151    case VPrn::Page_Intro:
152    case VPrn::Page_Select:
153        break;
154    case VPrn::Page_PrintData:
155        //???????? ????
156        this->resize(800,600);
157        break;
158    case VPrn::Page_CheckData:
159        //???????? ????        
160        this->resize(320,240);
161        break;
162    case VPrn::Page_Preview:
163        this->resize(800,600);
164        break;
165    case VPrn::Page_Finish:
166        break;
167    case VPrn::Page_SetBrak:
168        break;
169    }
170    if (lastCheck(pageId)){
171        pageId++;
172        if ( ( pageId > VPrn::Page_Finish ) || ( pageId > stackedWidget->count()-1 ) ){
173            pageId = VPrn::Page_Finish;
174        }
175        if (pageId == VPrn::Page_Preview){
176            // ???????? ??????
177            nextButton->setText(QObject::trUtf8("??????"));
178        }
179        stackedWidget->setCurrentIndex(pageId);
180        this->setWindowTitle(stackedWidget->currentWidget()->windowTitle() );
181    }
182}
183
184void MainWindow::do_prev()
185{
186    switch (pageId - 1){
187    case VPrn::Page_Intro:
188    case VPrn::Page_Select:
189        //???????? ????
190        this->resize(320,240);
191        break;
192    case VPrn::Page_PrintData:
193        //???????? ????
194        this->resize(800,600);
195        break;
196    case VPrn::Page_CheckData:
197        //???????? ????
198        this->resize(320,240);
199        nextButton->setText(QObject::trUtf8("?????? >"));
200        break;
201    case VPrn::Page_Preview:
202        //???????? ????
203        this->resize(800,600);        
204        break;
205    case VPrn::Page_Finish:
206        break;
207    case VPrn::Page_SetBrak:
208        break;
209    }
210    pageId--;
211    if (pageId < VPrn::Page_Intro) {
212        pageId = VPrn::Page_Intro;
213    }    
214    stackedWidget->setCurrentIndex(pageId);
215    this->setWindowTitle(stackedWidget->currentWidget()->windowTitle() );
216}
217
218void MainWindow::do_restart()
219{
220    pageId =0;
221    stackedWidget->setCurrentIndex(pageId);
222    this->setWindowTitle(stackedWidget->currentWidget()->windowTitle() );
223    this->resize(320,240);
224    selectPage->needRestart();
225    printDataPage->needRestart();
226    checkDataPage->needRestart();
227    preViewPage->needRestart();
228    engine->needRestart();
229    nextButton->setText(QObject::trUtf8("?????? >"));
230
231}
232
233void MainWindow::do_needAuthUser(const QString &login_mandat_list)
234{
235    QRegExp rx("\\[(.+)\\];:;(.+)");
236    //rx.setMinimal(true);
237    if(rx.indexIn(login_mandat_list) != -1){
238        QString m_login  = rx.cap(1);
239        QString m_list  = rx.cap(2);
240
241        // ?????? ?????? ???????????
242        getUserNameMandatDlg *UMDlg = new getUserNameMandatDlg(this);
243        UMDlg->move(this->calcDeskTopCenter(UMDlg->width(),UMDlg->height()));
244        UMDlg->setUserName(m_login);
245        UMDlg->setMandatList(QStringList() << m_list.split(";:;"));
246        connect(UMDlg,SIGNAL(setAuthData(const QString &,const QString &)),
247                engine, SLOT(setAuthData(const QString &,const QString &))
248                );
249
250        UMDlg->exec();
251    }else{
252        myEMsgBox->showMessage(QObject::trUtf8("?????? ??????? ????????? ???????."));
253    }
254}
255
256void MainWindow::sendFileToConvertor()
257{
258    engine->prepareFileToPrint(data_module->getWorkFile());
259}
260
261void MainWindow::errorInfo(VPrn::AppErrorType eCode,QString e_msg)
262{
263    QString extMsg = QString("eCode %1. AppsError:%2\n%3")
264                     .arg(eCode,0,10)
265                     .arg(e_msg)
266                     .arg(QString(Q_FUNC_INFO));
267    myEMsgBox->showMessage(extMsg);
268    qDebug() << extMsg;
269}
270
271
272void MainWindow::do_UserNeedFlipPages()
273{
274    QMessageBox msgBox;
275    msgBox.setText(QObject::trUtf8("????????? ?????? ??????? ???????? ?????????."));
276    msgBox.setInformativeText(QObject::trUtf8("??? ??????????? ?????? ??????????? ????? ? ??????? ?????? ?????? ??? ??????"));
277    msgBox.setDetailedText(QObject::trUtf8("???????? ? ?????? ?????? ?????? ?????????, ??????? ????????? ????????? ????? ???????, ??? ????"));
278
279    QPushButton *printButton = msgBox.addButton(QObject::trUtf8("??????"), QMessageBox::ActionRole);
280    QPushButton *abortButton = msgBox.addButton(QObject::trUtf8("??????"), QMessageBox::RejectRole);
281
282    msgBox.exec();
283
284    if (msgBox.clickedButton() == printButton) {
285        // connect
286        engine->do_printCurrentDoc();
287    } else if (msgBox.clickedButton() == abortButton) {
288        // abort
289        engine->markCurrentDocBrack();
290    }
291
292}
293
294void MainWindow::do_UserNeedCheckLastPage()
295{
296    QMessageBox msgBox;
297    msgBox.setText(QObject::trUtf8("????????? ?????? ???????? ??????? ?????????."));
298    msgBox.setInformativeText(QObject::trUtf8("??? ??????????? ?????? ?????????? ????????? ???? ????????? ? ??????? ?????? ?????? ??? ??????"));
299    msgBox.setDetailedText(QObject::trUtf8("???????? ? ?????? ?????? ?????? ?????????, ??????? ????????? ????????? ????? ???????, ??? ????"));
300
301    QPushButton *printButton = msgBox.addButton(QObject::trUtf8("??????"), QMessageBox::ActionRole);
302    QPushButton *abortButton = msgBox.addButton(QObject::trUtf8("??????"), QMessageBox::RejectRole);
303
304    msgBox.exec();
305
306    if (msgBox.clickedButton() == printButton) {
307        // connect
308        engine->do_printCurrentDoc();
309    } else if (msgBox.clickedButton() == abortButton) {
310        // abort
311        engine->markCurrentDocBrack();
312    }
313
314}
315
316void MainWindow::do_UserNeedMarkCopies(const QString &detail_data)
317{
318    // ???????? ? ????? ?????
319    qDebug() << "detail_data " << detail_data;
320    if (!detail_data.isEmpty() && detail_data.contains(";:;")){
321        QStringList d_list =  detail_data.split(";:;");
322
323        QMessageBox msgBox;
324        msgBox.setText(QObject::trUtf8("????????? ?????? ????????? %1").arg(d_list.at(0)));
325        msgBox.setInformativeText(QObject::trUtf8("?????????? ???????? ??????? ???????? ??? ???????? ??? ????"));
326        msgBox.setDetailedText(QObject::trUtf8("???????? %1 ??? ?????????? ?? ???????? %2.\n????? ?? - %3\n????????? - %4\n????? ??????? %5")
327                               .arg(d_list.at(0))
328                               .arg(d_list.at(1))
329                               .arg(d_list.at(2))
330                               .arg(d_list.at(3))
331                               .arg(d_list.at(4))
332                               );
333
334        QPushButton *clearButton = msgBox.addButton(QObject::trUtf8("????????"), QMessageBox::ActionRole);
335        QPushButton *brakButton = msgBox.addButton(QObject::trUtf8("????"), QMessageBox::RejectRole);
336
337        msgBox.exec();
338
339        if (msgBox.clickedButton() == clearButton) {
340            // connect
341            engine->markCurrentDocClear();
342        } else if (msgBox.clickedButton() == brakButton) {
343            // abort
344            engine->markCurrentDocBrack();
345        }
346    }
347}
348
349
350//------------------------------------ PRIVATE ---------------------------------------------
351void MainWindow::createConnection()
352{
353    connect (helpButton, SIGNAL(clicked()),
354             this, SLOT( showHelp() )
355             );
356    connect (exitButton,SIGNAL(clicked()),
357             this,      SLOT(close())
358             );
359    connect (nextButton,SIGNAL(clicked()),
360             this,      SLOT(do_next())
361             );
362    connect (prevButton,SIGNAL(clicked()),
363             this,      SLOT(do_prev())
364             );
365    connect (restartButton,SIGNAL(clicked()),
366             this,      SLOT(do_restart())
367             );
368
369    connect (data_module,SIGNAL(error(VPrn::AppErrorType,QString)),
370             this,       SLOT (errorInfo(VPrn::AppErrorType,QString))
371             );
372    connect (engine,   SIGNAL( error(VPrn::AppErrorType,QString) ),
373             this,     SLOT (errorInfo(VPrn::AppErrorType,QString))
374             );
375    connect(engine,    SIGNAL( LocalSrvRegistr() ),
376            introPage, SLOT  ( setLocalSrvRegistr() )
377            );
378    connect(engine,    SIGNAL( RemoteDemonRegistr() ),
379            introPage, SLOT  ( setRemoteDemonRegistr() )
380            );
381    connect(engine,    SIGNAL(ReciveUserName()  ),
382            introPage, SLOT  (setReciveUserName() )
383            );
384    connect(engine,    SIGNAL( ReciveUserMandat() ),
385            introPage, SLOT  ( setReciveUserMandat() )
386            );
387
388    /** @short ??? ??? ?????? ??? ??????? ????????? ????:
389      * @li ??????????? ?? ????????? ??????? (?????? ?? ?????????? ? ????????)
390      * @li ??????????? ?? ????????? ??????? (?????? ?? ?????????? ? ????????)
391      * ????? ????????? ?????? ?? ???????????, ? ?????? ????? ? ???? ???? ?????
392      * ????? ????????? ?????????????? ? ????????
393      */
394    connect(engine,    SIGNAL( RemoteDemonRegistr()  ),
395            this,      SLOT  ( sendFileToConvertor() )
396            );
397    connect(engine,    SIGNAL( needAuthUser(const QString&) ),
398            this,      SLOT  ( do_needAuthUser(const QString&) )
399            );
400    connect(engine,       SIGNAL( ReciveSecLevelList() ),
401            introPage,    SLOT  ( setReciveSecLevelList() )
402            );
403    connect(engine,       SIGNAL( RecivePrintersList() ),
404            introPage,    SLOT  ( setRecivePrintersList() )
405            );
406    connect(printDataPage, SIGNAL ( field_checked() ),
407            engine,        SLOT   ( authUserToPrinter() )
408            );
409
410    connect(engine, 	   SIGNAL ( doc_converted() ),
411            printDataPage, SLOT   ( setDocConverted() )
412           );
413
414    connect(printDataPage, SIGNAL ( field_checked() ),
415            engine,        SLOT   ( checkMB() )
416            );
417
418    connect (engine,       SIGNAL ( authToDevice(bool,QString) ),
419             checkDataPage,SLOT   ( setAuthCheck(bool,QString) )
420             );
421
422    connect(engine,        SIGNAL ( RegisterDocInBase(bool,QString) ),
423            checkDataPage, SLOT   ( setMbCheck(bool,QString) )
424            );
425
426    connect(checkDataPage, SIGNAL (select_mode(int)),
427            engine,        SLOT   (do_select_mode(int))
428            );
429
430    connect(engine,        SIGNAL ( MergeDocWithTemplates(bool,QString) ),
431            checkDataPage, SLOT   ( setCheckMergeDocWithTemplates(bool,QString))
432            );
433    connect (engine,       SIGNAL ( PicturesList(QStringList ) ),
434             preViewPage,  SLOT   ( showPicturesList(QStringList ))
435             );
436    connect (preViewPage,  SIGNAL (printCurrentDoc()),
437             engine,       SLOT   (do_printCurrentDoc())
438             );
439
440    connect (engine,       SIGNAL (showInfoMsg(QString)),
441             finishPage,   SLOT   (addInfoMsg(QString))
442             );
443    connect (engine,       SIGNAL (UserNeedFlipPages()),
444             this,   SLOT   (do_UserNeedFlipPages())
445             );
446    connect (engine, SIGNAL (UserNeedCheckLastPage()),
447             this,   SLOT   (do_UserNeedCheckLastPage())
448             );
449
450    connect (engine,       SIGNAL (UserNeedMarkCopies(const QString&)),
451             this,   SLOT   (do_UserNeedMarkCopies(const QString&))
452             );
453
454    connect (finishPage,       SIGNAL (saveCopiesState(bool)),
455             engine,   SLOT   (do_saveCopiesState(bool))
456             );
457
458}
459
460QPoint MainWindow::calcDeskTopCenter(int width,int height)
461{
462    QPoint centerWindow;
463    //???????? ????????????? ? ????????? ??? ? ??????
464    centerWindow = desktop_avail.center(); //???????? ?????????? ?????? ??????
465    centerWindow.setX(centerWindow.x() - (width/2));
466    centerWindow.setY(centerWindow.y() - (height/2));
467    return centerWindow;
468}
469
470void MainWindow::readConfig(const QString &app_dir)
471{
472    QString ini_file =QString("%1/Technoserv/safe_printer.ini").arg(app_dir);
473    if (QFile::exists(ini_file)){
474        QSettings settings (ini_file,QSettings::IniFormat);
475
476#if QT_VERSION >= 0x040500
477        settings.setIniCodec("UTF-8");
478#endif
479
480        settings.beginGroup("SERVICE");
481        link_name      = settings.value("link_name").toString();
482        settings.endGroup();
483
484        settings.beginGroup("USED_DIR_FILE");
485        //spoolDir       = settings.value("spool_dir").toString();
486        gatekeeper_bin = settings.value("gatekeeper_bin").toString();
487        settings.endGroup();
488    }else{
489        myEMsgBox->showMessage(QObject::trUtf8("???? ? ??????????? ????????? %1 ?? ??????!\n%2")
490                               .arg(ini_file)
491                               .arg(QString(Q_FUNC_INFO))
492                               );
493    }
494}
495
496bool MainWindow::lastCheck(int page)
497{
498    bool Ok = false;
499    {
500        switch (page +1){
501        case VPrn::Page_Intro:
502            break;
503        case VPrn::Page_Select:
504            Ok = introPage->enableNext();
505            break;
506        case VPrn::Page_PrintData:
507            Ok = selectPage->enableNext();
508            break;
509        case VPrn::Page_CheckData:
510            Ok = printDataPage->enableNext();
511            break;
512        case VPrn::Page_Preview:
513            Ok = checkDataPage->enableNext();
514            break;
515        case VPrn::Page_Finish:
516            Ok = preViewPage->enableNext();
517            break;
518        case VPrn::Page_SetBrak:
519            break;
520        }
521    }
522    return Ok;
523}
524
525//------------------------------------- PROTECTED ----------------------------------------
526void MainWindow::changeEvent(QEvent *e)
527{
528    QWidget::changeEvent(e);
529    switch (e->type()) {
530    case QEvent::LanguageChange:
531        //ui->retranslateUi(this);
532        break;
533    default:
534        break;
535    }
536}