Changeset View
Changeset View
Standalone View
Standalone View
libs/main/KoApplication.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | |||||
68 | #include <stdlib.h> | 68 | #include <stdlib.h> | ||
69 | 69 | | |||
70 | #ifdef Q_OS_WIN | 70 | #ifdef Q_OS_WIN | ||
71 | #include <windows.h> | 71 | #include <windows.h> | ||
72 | #include <tchar.h> | 72 | #include <tchar.h> | ||
73 | #endif | 73 | #endif | ||
74 | 74 | | |||
75 | 75 | | |||
76 | #include "MainDebug.h" | ||||
76 | #include <QDesktopWidget> | 77 | #include <QDesktopWidget> | ||
77 | 78 | | |||
78 | KoApplication* KoApplication::KoApp = 0; | 79 | KoApplication* KoApplication::KoApp = 0; | ||
79 | 80 | | |||
80 | namespace { | 81 | namespace { | ||
81 | const QTime appStartTime(QTime::currentTime()); | 82 | const QTime appStartTime(QTime::currentTime()); | ||
82 | } | 83 | } | ||
83 | 84 | | |||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 182 | { | |||
197 | } | 198 | } | ||
198 | return bIsWow64; | 199 | return bIsWow64; | ||
199 | } | 200 | } | ||
200 | #endif | 201 | #endif | ||
201 | 202 | | |||
202 | bool KoApplication::start() | 203 | bool KoApplication::start() | ||
203 | { | 204 | { | ||
204 | KAboutData aboutData = KAboutData::applicationData(); | 205 | KAboutData aboutData = KAboutData::applicationData(); | ||
205 | | ||||
206 | // process commandline parameters | 206 | // process commandline parameters | ||
207 | QCommandLineParser parser; | 207 | QCommandLineParser parser; | ||
208 | aboutData.setupCommandLine(&parser); | 208 | aboutData.setupCommandLine(&parser); | ||
209 | parser.addHelpOption(); | 209 | parser.addHelpOption(); | ||
210 | parser.addVersionOption(); | 210 | parser.addVersionOption(); | ||
211 | 211 | | |||
212 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("print"), i18n("Only print and exit"))); | 212 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("print"), i18n("Only print and exit"))); | ||
213 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("template"), i18n("Open a new document based on the given template (desktopfile name)"))); | 213 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("template"), i18n("Open a new document based on the given template (desktopfile name)"))); | ||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Line(s) | 561 | if (mainWindow->openDocument(part, url)) { | |||
565 | debugMain << "Template loaded..."; | 565 | debugMain << "Template loaded..."; | ||
566 | numberOfOpenDocuments++; | 566 | numberOfOpenDocuments++; | ||
567 | } else { | 567 | } else { | ||
568 | KMessageBox::error(0, i18n("Template %1 failed to load.", url.toDisplayString())); | 568 | KMessageBox::error(0, i18n("Template %1 failed to load.", url.toDisplayString())); | ||
569 | delete mainWindow; | 569 | delete mainWindow; | ||
570 | } | 570 | } | ||
571 | } | 571 | } | ||
572 | } | 572 | } | ||
573 | else if (mainWindow->openDocument(part, url)) { | 573 | else { | ||
574 | if (print) { | ||||
575 | connect( | ||||
576 | mainWindow, SIGNAL(loadCompleted(KoMainWindow *)), | ||||
577 | this, SLOT(slotFilePrint(KoMainWindow *))); | ||||
578 | } else if (exportAsPdf) { | ||||
579 | connect( | ||||
580 | mainWindow, &KoMainWindow::loadCompleted, | ||||
581 | this, [=](KoMainWindow *mainWindow){slotExportToPdf(mainWindow, pdfFileName);}); | ||||
582 | } | ||||
583 | if (mainWindow->openDocument(part, url)) { | ||||
574 | if (benchmarkLoading) { | 584 | if (benchmarkLoading) { | ||
575 | if (profileoutput.device()) { | 585 | if (profileoutput.device()) { | ||
576 | profileoutput << "KoApplication::start\t" | 586 | profileoutput << "KoApplication::start\t" | ||
577 | << appStartTime.msecsTo(QTime::currentTime()) | 587 | << appStartTime.msecsTo(QTime::currentTime()) | ||
578 | <<"\t100" << endl; | 588 | <<"\t100" << endl; | ||
579 | } | 589 | } | ||
580 | QTimer::singleShot(0, this, SLOT(benchmarkLoadingFinished())); | 590 | QTimer::singleShot(0, this, SLOT(benchmarkLoadingFinished())); | ||
581 | return true; // only load one document! | 591 | return true; // only load one document! | ||
582 | } | 592 | } | ||
583 | else if (print) { | 593 | if (print || exportAsPdf) | ||
584 | mainWindow->slotFilePrint(); | | |||
585 | // delete mainWindow; done by ~KoDocument | | |||
586 | nPrinted++; | | |||
587 | } else if (exportAsPdf) { | | |||
588 | KoPrintJob *job = mainWindow->exportToPdf(pdfFileName); | | |||
589 | if (job) | | |||
590 | connect (job, SIGNAL(destroyed(QObject*)), mainWindow, | | |||
591 | SLOT(slotFileQuit()), Qt::QueuedConnection); | | |||
592 | nPrinted++; | 594 | nPrinted++; | ||
593 | } else { | 595 | else | ||
594 | // Normal case, success | | |||
595 | numberOfOpenDocuments++; | 596 | numberOfOpenDocuments++; | ||
596 | } | | |||
597 | } else { | 597 | } else { | ||
598 | // .... if failed | 598 | // .... if failed | ||
599 | // delete doc; done by openDocument | 599 | // delete doc; done by openDocument | ||
600 | // delete mainWindow; done by ~KoDocument | 600 | // delete mainWindow; done by ~KoDocument | ||
601 | } | 601 | } | ||
602 | } | ||||
602 | 603 | | |||
603 | if (profileoutput.device()) { | 604 | if (profileoutput.device()) { | ||
604 | profileoutput << "KoApplication::start\t" | 605 | profileoutput << "KoApplication::start\t" | ||
605 | << appStartTime.msecsTo(QTime::currentTime()) | 606 | << appStartTime.msecsTo(QTime::currentTime()) | ||
606 | <<"\t100" << endl; | 607 | <<"\t100" << endl; | ||
607 | } | 608 | } | ||
608 | 609 | | |||
609 | } | 610 | } | ||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Line(s) | 672 | { | |||
677 | } catch (...) { | 678 | } catch (...) { | ||
678 | qWarning("Error <unknown> sending event %i to object %s", | 679 | qWarning("Error <unknown> sending event %i to object %s", | ||
679 | event->type(), qPrintable(receiver->objectName())); | 680 | event->type(), qPrintable(receiver->objectName())); | ||
680 | } | 681 | } | ||
681 | return false; | 682 | return false; | ||
682 | 683 | | |||
683 | } | 684 | } | ||
684 | 685 | | |||
686 | void KoApplication::slotFilePrint(KoMainWindow *mainWindow) | ||||
687 | { | ||||
688 | mainWindow->slotFilePrint(); | ||||
689 | //delete mainWindow; done by ~KoDocument | ||||
690 | } | ||||
691 | | ||||
692 | void KoApplication::slotExportToPdf(KoMainWindow *mainWindow, QString pdfFileName) | ||||
693 | { | ||||
694 | KoPrintJob *job = mainWindow->exportToPdf(pdfFileName); | ||||
695 | if (job) | ||||
696 | connect (job, SIGNAL(destroyed(QObject*)), mainWindow, | ||||
697 | SLOT(slotFileQuit()), Qt::QueuedConnection); | ||||
698 | } | ||||
699 | | ||||
685 | KoApplication *KoApplication::koApplication() | 700 | KoApplication *KoApplication::koApplication() | ||
686 | { | 701 | { | ||
687 | return KoApp; | 702 | return KoApp; | ||
688 | } | 703 | } |