diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -39,6 +39,7 @@ Gui/SettingsDialog/SettingsDialog.cpp Gui/SettingsDialog/GeneralOptionsPage.cpp Gui/SettingsDialog/ShortcutsOptionsPage.cpp + Gui/SettingsDialog/TaskOptionsPage.cpp QuickEditor/QuickEditor.cpp ) @@ -68,7 +69,7 @@ ${SPECTACLE_SRCS_ALL} ) -ki18n_wrap_ui(spectacle Gui/SettingsDialog/GeneralOptions.ui Gui/SettingsDialog/SaveOptions.ui) +ki18n_wrap_ui(spectacle Gui/SettingsDialog/GeneralOptions.ui Gui/SettingsDialog/SaveOptions.ui Gui/SettingsDialog/TaskOptions.ui) # link libraries diff --git a/src/Gui/SettingsDialog/SettingsDialog.cpp b/src/Gui/SettingsDialog/SettingsDialog.cpp --- a/src/Gui/SettingsDialog/SettingsDialog.cpp +++ b/src/Gui/SettingsDialog/SettingsDialog.cpp @@ -24,6 +24,7 @@ #include "SaveOptionsPage.h" #include "settings.h" #include "ShortcutsOptionsPage.h" +#include "TaskOptionsPage.h" #include #include @@ -43,6 +44,9 @@ connect(mShortcutsPage, &ShortcutsOptionsPage::shortCutsChanged, this, [this] { updateButtons(); }); + addPage(new TaskOptionsPage(this), Settings::self(), + i18n("Task"), QStringLiteral("task-new")); + resize(600, 590); connect(this, &KConfigDialog::currentPageChanged, this, &SettingsDialog::updateButtons); } @@ -74,8 +78,3 @@ KConfigDialog::updateWidgetsDefault(); mShortcutsPage->defaults(); } - - - - - diff --git a/src/Gui/SettingsDialog/TaskOptions.ui b/src/Gui/SettingsDialog/TaskOptions.ui new file mode 100644 --- /dev/null +++ b/src/Gui/SettingsDialog/TaskOptions.ui @@ -0,0 +1,168 @@ + + + TaskOptions + + + + 0 + 0 + 598 + 446 + + + + Task + + + + + 10 + 20 + 570 + 201 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 104 + 20 + + + + + + + + Run script/program after an image has been saved + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 568 + 8 + + + + + + + + + + Program/script: + + + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 568 + 8 + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 0 + 20 + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 104 + 20 + + + + + + + + + 0 + 0 + + + + Spectacle passes the location of the saved image as an argument to your script/program. +Supported files: executables without extension, .sh, .py (requires Python). +The working directory is the one where the image is saved + + + Qt::AlignJustify|Qt::AlignTop + + + true + + + + + + + + + + + KUrlRequester + QWidget +
kurlrequester.h
+
+
+ + +
diff --git a/src/Gui/SettingsDialog/TaskOptionsPage.h b/src/Gui/SettingsDialog/TaskOptionsPage.h new file mode 100644 --- /dev/null +++ b/src/Gui/SettingsDialog/TaskOptionsPage.h @@ -0,0 +1,44 @@ +/* This file is part of Spectacle, the KDE screenshot utility + * Copyright (C) 2020 Antonio Prcela + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#ifndef TASKOPTIONSPAGE_H +#define TASKOPTIONSPAGE_H + +#include +#include + +class Ui_TaskOptions; + +class TaskOptionsPage : public QWidget +{ + Q_OBJECT + + public: + + explicit TaskOptionsPage(QWidget *parent = nullptr); + ~TaskOptionsPage() override; + + private: + + QScopedPointer m_ui; +}; + +#endif // TASKOPTIONSPAGE_H diff --git a/src/Gui/SettingsDialog/TaskOptionsPage.cpp b/src/Gui/SettingsDialog/TaskOptionsPage.cpp new file mode 100644 --- /dev/null +++ b/src/Gui/SettingsDialog/TaskOptionsPage.cpp @@ -0,0 +1,46 @@ +/* This file is part of Spectacle, the KDE screenshot utility + * Copyright (C) 2020 Antonio Prcela + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +#include "TaskOptionsPage.h" + +#include "SpectacleCommon.h" +#include "ui_TaskOptions.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +TaskOptionsPage::TaskOptionsPage(QWidget *parent) + : QWidget(parent) + , m_ui(new Ui_TaskOptions) +{ + m_ui->setupUi(this); +} + +TaskOptionsPage::~TaskOptionsPage() = default; diff --git a/src/Gui/SettingsDialog/spectacle.kcfg b/src/Gui/SettingsDialog/spectacle.kcfg --- a/src/Gui/SettingsDialog/spectacle.kcfg +++ b/src/Gui/SettingsDialog/spectacle.kcfg @@ -120,4 +120,13 @@ SaveAs + + + + false + + + + + diff --git a/src/SpectacleCore.h b/src/SpectacleCore.h --- a/src/SpectacleCore.h +++ b/src/SpectacleCore.h @@ -80,6 +80,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 @@ -89,6 +89,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); // Needed so the QuickEditor can go fullscreen on wayland @@ -379,6 +381,31 @@ } } +void SpectacleCore::doTask(const QUrl &savedAt) +{ + if (Settings::runTask()) { + QUrl taskLocationUrl = Settings::urlProgramLocation(); + if (!taskLocationUrl.isValid() || !taskLocationUrl.isLocalFile()) { + return; + } + 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();