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 | | |||
84 | class KoApplicationPrivate | 85 | class KoApplicationPrivate | ||
85 | { | 86 | { | ||
86 | public: | 87 | public: | ||
87 | KoApplicationPrivate() | 88 | KoApplicationPrivate() | ||
88 | : splashScreen(0) | 89 | : splashScreen(0) | ||
89 | {} | 90 | {} | ||
90 | QByteArray nativeMimeType; | 91 | QByteArray nativeMimeType; | ||
91 | QWidget *splashScreen; | 92 | QWidget *splashScreen; | ||
92 | QList<KoPart *> partList; | 93 | QList<KoPart *> partList; | ||
93 | QString roundtripFileName; | 94 | QString roundtripFileName; | ||
95 | QString pdfFileName; | ||||
94 | }; | 96 | }; | ||
95 | 97 | | |||
96 | class KoApplication::ResetStarting | 98 | class KoApplication::ResetStarting | ||
97 | { | 99 | { | ||
98 | public: | 100 | public: | ||
99 | ResetStarting(QWidget *splash = 0) | 101 | ResetStarting(QWidget *splash = 0) | ||
100 | : m_splash(splash) | 102 | : m_splash(splash) | ||
101 | { | 103 | { | ||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 183 | { | |||
197 | } | 199 | } | ||
198 | return bIsWow64; | 200 | return bIsWow64; | ||
199 | } | 201 | } | ||
200 | #endif | 202 | #endif | ||
201 | 203 | | |||
202 | bool KoApplication::start() | 204 | bool KoApplication::start() | ||
203 | { | 205 | { | ||
204 | KAboutData aboutData = KAboutData::applicationData(); | 206 | KAboutData aboutData = KAboutData::applicationData(); | ||
205 | | ||||
206 | // process commandline parameters | 207 | // process commandline parameters | ||
207 | QCommandLineParser parser; | 208 | QCommandLineParser parser; | ||
208 | aboutData.setupCommandLine(&parser); | 209 | aboutData.setupCommandLine(&parser); | ||
209 | parser.addHelpOption(); | 210 | parser.addHelpOption(); | ||
210 | parser.addVersionOption(); | 211 | parser.addVersionOption(); | ||
211 | 212 | | |||
212 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("print"), i18n("Only print and exit"))); | 213 | 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)"))); | 214 | parser.addOption(QCommandLineOption(QStringList() << QStringLiteral("template"), i18n("Open a new document based on the given template (desktopfile name)"))); | ||
▲ Show 20 Lines • Show All 227 Lines • ▼ Show 20 Line(s) | 371 | #endif | |||
441 | else { | 442 | else { | ||
442 | part->showStartUpWidget(mainWindow); | 443 | part->showStartUpWidget(mainWindow); | ||
443 | } | 444 | } | ||
444 | 445 | | |||
445 | } | 446 | } | ||
446 | else { | 447 | else { | ||
447 | const bool print = parser.isSet("print"); | 448 | const bool print = parser.isSet("print"); | ||
448 | const bool exportAsPdf = parser.isSet("export-pdf"); | 449 | const bool exportAsPdf = parser.isSet("export-pdf"); | ||
449 | const QString pdfFileName = parser.value("export-filename"); | 450 | d->pdfFileName = parser.value("export-filename"); | ||
450 | d->roundtripFileName = parser.value("roundtrip-filename"); | 451 | d->roundtripFileName = parser.value("roundtrip-filename"); | ||
451 | const bool doTemplate = parser.isSet("template"); | 452 | const bool doTemplate = parser.isSet("template"); | ||
452 | const bool doNew = parser.isSet("new"); | 453 | const bool doNew = parser.isSet("new"); | ||
453 | const bool benchmarkLoading = parser.isSet("benchmark-loading") | 454 | const bool benchmarkLoading = parser.isSet("benchmark-loading") | ||
454 | || parser.isSet("benchmark-loading-show-window") | 455 | || parser.isSet("benchmark-loading-show-window") | ||
455 | || !d->roundtripFileName.isEmpty(); | 456 | || !d->roundtripFileName.isEmpty(); | ||
456 | // only show the mainWindow when no command-line mode option is passed | 457 | // only show the mainWindow when no command-line mode option is passed | ||
457 | const bool showmainWindow = | 458 | const bool showmainWindow = | ||
458 | parser.isSet("benchmark-loading-show-window") || ( | 459 | parser.isSet("benchmark-loading-show-window") || ( | ||
459 | !parser.isSet("export-pdf") | 460 | parser.isSet("export-pdf") | ||
460 | && !parser.isSet("benchmark-loading") | 461 | && !parser.isSet("benchmark-loading") | ||
461 | && !parser.isSet("roundtrip-filename") | 462 | && !parser.isSet("roundtrip-filename") | ||
462 | && d->roundtripFileName.isEmpty()); | 463 | && d->roundtripFileName.isEmpty()); | ||
463 | const QString profileFileName = parser.value("profile-filename"); | 464 | const QString profileFileName = parser.value("profile-filename"); | ||
464 | 465 | | |||
465 | QTextStream profileoutput; | 466 | QTextStream profileoutput; | ||
466 | QFile profileFile(profileFileName); | 467 | QFile profileFile(profileFileName); | ||
467 | if (!profileFileName.isEmpty() | 468 | if (!profileFileName.isEmpty() | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 562 | if (mainWindow->openDocument(part, url)) { | |||
565 | debugMain << "Template loaded..."; | 566 | debugMain << "Template loaded..."; | ||
566 | numberOfOpenDocuments++; | 567 | numberOfOpenDocuments++; | ||
567 | } else { | 568 | } else { | ||
568 | KMessageBox::error(0, i18n("Template %1 failed to load.", url.toDisplayString())); | 569 | KMessageBox::error(0, i18n("Template %1 failed to load.", url.toDisplayString())); | ||
569 | delete mainWindow; | 570 | delete mainWindow; | ||
570 | } | 571 | } | ||
571 | } | 572 | } | ||
572 | } | 573 | } | ||
573 | else if (mainWindow->openDocument(part, url)) { | 574 | else { | ||
575 | if (print) { | ||||
576 | connect( | ||||
577 | mainWindow, SIGNAL(loadCompleted(KoMainWindow *)), | ||||
578 | this, SLOT(slotFilePrint(KoMainWindow *))); | ||||
579 | } else if (exportAsPdf) { | ||||
580 | connect(mainWindow, SIGNAL(loadCompleted(KoMainWindow*)), | ||||
581 | this, SLOT(slotExportToPdf(KoMainWindow*))); | ||||
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) | ||||
693 | { | ||||
694 | KoPrintJob *job = mainWindow->exportToPdf(d->pdfFileName); | ||||
695 | // TODO: exit if all jobs over | ||||
696 | } | ||||
697 | | ||||
685 | KoApplication *KoApplication::koApplication() | 698 | KoApplication *KoApplication::koApplication() | ||
686 | { | 699 | { | ||
687 | return KoApp; | 700 | return KoApp; | ||
688 | } | 701 | } |