diff --git a/libs/main/KoApplication.h b/libs/main/KoApplication.h --- a/libs/main/KoApplication.h +++ b/libs/main/KoApplication.h @@ -23,6 +23,7 @@ #include #include "komain_export.h" +#include "KoMainWindow.h" class KoPart; @@ -137,6 +138,8 @@ private Q_SLOTS: void benchmarkLoadingFinished(); + void slotFilePrint(KoMainWindow *view); + void slotExportToPdf(KoMainWindow *view, QString pdfFileName); protected: diff --git a/libs/main/KoApplication.cpp b/libs/main/KoApplication.cpp --- a/libs/main/KoApplication.cpp +++ b/libs/main/KoApplication.cpp @@ -73,6 +73,7 @@ #endif +#include "MainDebug.h" #include KoApplication* KoApplication::KoApp = 0; @@ -202,7 +203,6 @@ bool KoApplication::start() { KAboutData aboutData = KAboutData::applicationData(); - // process commandline parameters QCommandLineParser parser; aboutData.setupCommandLine(&parser); @@ -570,34 +570,35 @@ } } } - else if (mainWindow->openDocument(part, url)) { - if (benchmarkLoading) { - if (profileoutput.device()) { - profileoutput << "KoApplication::start\t" - << appStartTime.msecsTo(QTime::currentTime()) - <<"\t100" << endl; - } - QTimer::singleShot(0, this, SLOT(benchmarkLoadingFinished())); - return true; // only load one document! - } - else if (print) { - mainWindow->slotFilePrint(); - // delete mainWindow; done by ~KoDocument - nPrinted++; + else { + if (print) { + connect( + mainWindow, SIGNAL(loadCompleted(KoMainWindow *)), + this, SLOT(slotFilePrint(KoMainWindow *))); } else if (exportAsPdf) { - KoPrintJob *job = mainWindow->exportToPdf(pdfFileName); - if (job) - connect (job, SIGNAL(destroyed(QObject*)), mainWindow, - SLOT(slotFileQuit()), Qt::QueuedConnection); - nPrinted++; + connect( + mainWindow, &KoMainWindow::loadCompleted, + this, [=](KoMainWindow *mainWindow){slotExportToPdf(mainWindow, pdfFileName);}); + } + if (mainWindow->openDocument(part, url)) { + if (benchmarkLoading) { + if (profileoutput.device()) { + profileoutput << "KoApplication::start\t" + << appStartTime.msecsTo(QTime::currentTime()) + <<"\t100" << endl; + } + QTimer::singleShot(0, this, SLOT(benchmarkLoadingFinished())); + return true; // only load one document! + } + if (print || exportAsPdf) + nPrinted++; + else + numberOfOpenDocuments++; } else { - // Normal case, success - numberOfOpenDocuments++; + // .... if failed + // delete doc; done by openDocument + // delete mainWindow; done by ~KoDocument } - } else { - // .... if failed - // delete doc; done by openDocument - // delete mainWindow; done by ~KoDocument } if (profileoutput.device()) { @@ -682,6 +683,20 @@ } +void KoApplication::slotFilePrint(KoMainWindow *mainWindow) +{ + mainWindow->slotFilePrint(); + //delete mainWindow; done by ~KoDocument +} + +void KoApplication::slotExportToPdf(KoMainWindow *mainWindow, QString pdfFileName) +{ + KoPrintJob *job = mainWindow->exportToPdf(pdfFileName); + if (job) + connect (job, SIGNAL(destroyed(QObject*)), mainWindow, + SLOT(slotFileQuit()), Qt::QueuedConnection); +} + KoApplication *KoApplication::koApplication() { return KoApp; diff --git a/libs/main/KoMainWindow.h b/libs/main/KoMainWindow.h --- a/libs/main/KoMainWindow.h +++ b/libs/main/KoMainWindow.h @@ -187,7 +187,7 @@ /// document. The document may be opened in another window in the end. /// In this case, the signal means there is no link between the window /// and the document anymore. - void loadCompleted(); + void loadCompleted(KoMainWindow *); /// This signal is emitted when this windows has canceled loading of a document. void loadCanceled(); diff --git a/libs/main/KoMainWindow.cpp b/libs/main/KoMainWindow.cpp --- a/libs/main/KoMainWindow.cpp +++ b/libs/main/KoMainWindow.cpp @@ -773,7 +773,7 @@ KFileItem file(url, newdoc->mimeType(), KFileItem::Unknown); if (!file.isWritable()) { setReadWrite(false); - } + } return true; } @@ -783,28 +783,31 @@ debugMain << "KoMainWindow::slotLoadCompleted"; KoDocument *newdoc = qobject_cast(sender()); KoPart *newpart = newdoc->documentPart(); - + if (d->rootDocument && d->rootDocument->isEmpty()) { // Replace current empty document setRootDocument(newdoc); + emit loadCompleted(this); } else if (d->rootDocument && !d->rootDocument->isEmpty()) { // Open in a new main window // (Note : could create the main window first and the doc next for this // particular case, that would give a better user feedback...) KoMainWindow *s = newpart->createMainWindow(); s->show(); newpart->removeMainWindow(this); s->setRootDocument(newdoc, newpart); + emit loadCompleted(s); } else { // We had no document, set the new one setRootDocument(newdoc); + emit loadCompleted(this); } + slotProgress(-1); disconnect(newdoc, SIGNAL(sigProgress(int)), this, SLOT(slotProgress(int))); disconnect(newdoc, SIGNAL(completed()), this, SLOT(slotLoadCompleted())); disconnect(newdoc, SIGNAL(canceled(QString)), this, SLOT(slotLoadCanceled(QString))); d->openingDocument = false; - emit loadCompleted(); } void KoMainWindow::slotLoadCanceled(const QString & errMsg)