diff --git a/src/Gui/SettingsDialog/TasksOptionsPage.cpp b/src/Gui/SettingsDialog/TasksOptionsPage.cpp --- a/src/Gui/SettingsDialog/TasksOptionsPage.cpp +++ b/src/Gui/SettingsDialog/TasksOptionsPage.cpp @@ -52,7 +52,8 @@ // Info text QString helpText = i18n( "Spectacle passes the location of the saved image as an argument to your script/program. " - "Supported files: executables without extension, .sh, .py (requires Python installed)." + "Supported files: executables without extension, .sh, .py (requires Python installed). " + "The working directory is the one where the image is saved." ); QLabel *fmtHelpText = new QLabel(helpText, this); fmtHelpText->setWordWrap(true); @@ -78,7 +79,7 @@ // save the data cfgManager->setTaskLocation(mTaskFileLocation->url()); - cfgManager->setEnableTask(mEnableTask->checkState() == Qt::Checked); + cfgManager->setRunTask(mEnableTask->checkState() == Qt::Checked); // done @@ -94,7 +95,7 @@ // read in the data mTaskFileLocation->setUrl(cfgManager->taskLocation()); - mEnableTask->setChecked(cfgManager->enableTask()); + mEnableTask->setChecked(cfgManager->runTask()); // done diff --git a/src/SpectacleConfig.h b/src/SpectacleConfig.h --- a/src/SpectacleConfig.h +++ b/src/SpectacleConfig.h @@ -138,8 +138,8 @@ QString saveImageFormat() const; void setSaveImageFormat(const QString &saveFmt); - bool enableTask() const; - void setEnableTask(bool enabled); + bool runTask() const; + void setRunTask(bool enabled); QUrl taskLocation() const; void setTaskLocation(const QUrl &location); diff --git a/src/SpectacleConfig.cpp b/src/SpectacleConfig.cpp --- a/src/SpectacleConfig.cpp +++ b/src/SpectacleConfig.cpp @@ -410,12 +410,12 @@ // enable task -bool SpectacleConfig::enableTask() const +bool SpectacleConfig::runTask() const { return mGeneralConfig.readEntry(QStringLiteral("runTask"), false); } -void SpectacleConfig::setEnableTask(bool enabled){ +void SpectacleConfig::setRunTask(bool enabled){ mGeneralConfig.writeEntry(QStringLiteral("runTask"), enabled); mGeneralConfig.sync(); } diff --git a/src/SpectacleCore.h b/src/SpectacleCore.h --- a/src/SpectacleCore.h +++ b/src/SpectacleCore.h @@ -74,6 +74,7 @@ void doStartDragAndDrop(); void doNotify(const QUrl &theSavedAt); void doCopyPath(const QUrl &savedAt); + void doTask(const QUrl &savedAt); private: diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -87,6 +87,8 @@ connect(lExportManager, &ExportManager::errorMessage, this, &SpectacleCore::showErrorMessage); connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); connect(lExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); + connect(lExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doTask); + connect(lExportManager, &ExportManager::imageSavedAndCopied, this, &SpectacleCore::doTask); connect(mPlatform.get(), &Platform::windowTitleChanged, lExportManager, &ExportManager::setWindowTitle); switch (theStartMode) { @@ -367,6 +369,28 @@ } } +void SpectacleCore::doTask(const QUrl &savedAt) +{ + if (SpectacleConfig::instance()->runTask()) { + QUrl taskLocationUrl = SpectacleConfig::instance()->taskLocation(); + QString taskLocationString = taskLocationUrl.toString(); + QProcess taskProcess; + taskProcess.setArguments(QStringList() << taskLocationUrl.path(QUrl::FullyEncoded) << savedAt.toString()); + taskProcess.setWorkingDirectory(savedAt.path(QUrl::FullyEncoded | QUrl::RemoveFilename)); + + if (taskLocationString.endsWith(QStringLiteral(".sh"))) { + QString userShell = QString::fromUtf8(qgetenv("SHELL")); + taskProcess.setProgram(userShell); + } else if (taskLocationString.endsWith(QStringLiteral(".py"))) { + taskProcess.setProgram(QStringLiteral("python")); + } else { + taskProcess.setProgram(taskLocationString); + } + + taskProcess.startDetached(); + } +} + void SpectacleCore::doStartDragAndDrop() { auto lExportManager = ExportManager::instance();