Commit 4c715c4c authored by Boudewijn Rempt's avatar Boudewijn Rempt

Don't crash if remoteArguments is called when there isn't a mainwindow

This isn't perfect: if you're fast enough you can still start a
couple of Krita processes even if application process sharing is
enabled. That can't be helped, though.

BUG:415794
parent b4c44d39
......@@ -111,6 +111,7 @@ public:
KisAutoSaveRecoveryDialog *autosaveDialog {0};
QPointer<KisMainWindow> mainWindow; // The first mainwindow we create on startup
bool batchRun {false};
QVector<QByteArray> earlyRemoteArguments;
};
......@@ -615,6 +616,10 @@ bool KisApplication::start(const KisApplicationArguments &args)
d->splashScreen->displayRecentFiles(true);
}
Q_FOREACH(const QByteArray &message, d->earlyRemoteArguments) {
executeRemoteArguments(message, d->mainWindow);
}
// not calling this before since the program will quit there.
return true;
......@@ -662,20 +667,8 @@ bool KisApplication::notify(QObject *receiver, QEvent *event)
}
void KisApplication::remoteArguments(QByteArray message, QObject *socket)
void KisApplication::executeRemoteArguments(QByteArray message, KisMainWindow *mainWindow)
{
Q_UNUSED(socket);
// check if we have any mainwindow
KisMainWindow *mw = qobject_cast<KisMainWindow*>(qApp->activeWindow());
if (!mw) {
mw = KisPart::instance()->mainWindows().first();
}
if (!mw) {
return;
}
KisApplicationArguments args = KisApplicationArguments::deserialize(message);
const bool doTemplate = args.doTemplate();
const int argsCount = args.filenames().count();
......@@ -686,16 +679,30 @@ void KisApplication::remoteArguments(QByteArray message, QObject *socket)
QString filename = args.filenames().at(argNumber);
// are we just trying to open a template?
if (doTemplate) {
createNewDocFromTemplate(filename, mw);
createNewDocFromTemplate(filename, mainWindow);
}
else if (QFile(filename).exists()) {
KisMainWindow::OpenFlags flags = d->batchRun ? KisMainWindow::BatchMode : KisMainWindow::None;
mw->openDocument(QUrl::fromLocalFile(filename), flags);
mainWindow->openDocument(QUrl::fromLocalFile(filename), flags);
}
}
}
}
void KisApplication::remoteArguments(QByteArray message, QObject *socket)
{
Q_UNUSED(socket);
// check if we have any mainwindow
KisMainWindow *mw = qobject_cast<KisMainWindow*>(qApp->activeWindow());
if (!mw) {
d->earlyRemoteArguments << message;
return;
}
executeRemoteArguments(message, mw);
}
void KisApplication::fileOpenRequested(const QString &url)
{
KisMainWindow *mainWindow = KisPart::instance()->mainWindows().first();
......
......@@ -105,6 +105,7 @@ public:
public Q_SLOTS:
void executeRemoteArguments(QByteArray message, KisMainWindow *mainWindow);
void remoteArguments(QByteArray message, QObject*socket);
void fileOpenRequested(const QString & url);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment