diff --git a/src/fileitemactionplugin/sharefileitemaction.cpp b/src/fileitemactionplugin/sharefileitemaction.cpp index 73002b5..27978e6 100644 --- a/src/fileitemactionplugin/sharefileitemaction.cpp +++ b/src/fileitemactionplugin/sharefileitemaction.cpp @@ -1,83 +1,84 @@ /* * Copyright (C) 2011 Alejandro Fiestas Olivares * Copyright (C) 2014 Aleix Pol Gonzalez * Copyright (C) 2018 Nicolas Fella * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU 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 Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ #include "sharefileitemaction.h" #include #include #include #include #include #include #include #include #include #include #include #include +#include #include "menu.h" #include "alternativesmodel.h" K_PLUGIN_CLASS_WITH_JSON(ShareFileItemAction, "sharefileitemaction.json") Q_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION, "purpose.fileitemaction") ShareFileItemAction::ShareFileItemAction(QObject* parent, const QVariantList& ) : KAbstractFileItemActionPlugin(parent), m_menu(new Purpose::Menu()) { m_menu->setTitle(i18n("Share")); m_menu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); m_menu->model()->setPluginType(QStringLiteral("Export")); QObject::connect(m_menu, &Purpose::Menu::finished, [](const QJsonObject &output, int error, const QString &errorMessage) { - if (error == 0) { + if (error == 0 || error == KIO::ERR_USER_CANCELED) { if (output.contains(QLatin1String("url"))) QDesktopServices::openUrl(QUrl(output.value(QLatin1String("url")).toString())); } else { KNotification::event(KNotification::Error, i18n("Error sharing"), errorMessage); qWarning() << "job failed with error" << error << errorMessage << output; } }); } QList ShareFileItemAction::actions(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) { Q_UNUSED(parentWidget); QJsonArray urlsJson; for (const QUrl& url : fileItemInfos.urlList()) { urlsJson.append(url.toString()); } m_menu->model()->setInputData(QJsonObject{ { QStringLiteral("mimeType"), QJsonValue{!fileItemInfos.mimeType().isEmpty() ? fileItemInfos.mimeType() : QStringLiteral("*/*")} }, { QStringLiteral("urls"), urlsJson } }); m_menu->reload(); return {m_menu->menuAction()}; } #include "sharefileitemaction.moc" diff --git a/src/widgets/JobDialog.qml b/src/widgets/JobDialog.qml index 5215799..1c90ea3 100644 --- a/src/widgets/JobDialog.qml +++ b/src/widgets/JobDialog.qml @@ -1,115 +1,115 @@ /* Copyright 2015 Aleix Pol Gonzalez This library 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.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ import QtQuick 2.4 import QtQuick.Controls 2.2 import QtQuick.Layouts 1.1 import org.kde.purpose 1.0 ApplicationWindow { id: window flags: Qt.Dialog title: configuration.pluginName width: Math.max(screen.width/3, 200) height: Math.max(screen.height/2, 300) property bool finished: false property var configuration property QtObject q Component.onCompleted: adoptJob() onConfigurationChanged: adoptJob() minimumHeight: view.Layout.minimumHeight minimumWidth: view.Layout.minimumWidth onClosing: { - q.finished(null, 1, i18n("Configuration cancelled")); + q.finished(null, 1 /* KIO::ERR_USER_CANCELED */, i18n("Configuration cancelled")); } function adoptJob() { if (configuration == null) return; if (configuration.isReady) { startJob() } else { view.push(configWizardComponent) } } function startJob() { var job = window.configuration.createJob(); job.start() view.push(runningJobComponent, { job: job }) } StackView { id: view anchors { fill: parent margins: 5 } Layout.minimumWidth: (currentItem ? currentItem.Layout.minimumWidth : 0) + 2*anchors.margins Layout.minimumHeight: (currentItem ? currentItem.Layout.minimumHeight : 0) + 2*anchors.margins } Component { id: configWizardComponent Page { PurposeWizard { id: wiz configuration: window.configuration focus: true anchors.fill: parent } footer: RowLayout { Button { text: i18n("Run") enabled: window.configuration && window.configuration.isReady onClicked: { view.pop(); window.startJob(); } } Button { text: i18n("Cancel") onClicked: { - window.q.finished(null, 1, i18n("Configuration cancelled")); + window.q.finished(null, 1 /* KIO::ERR_USER_CANCELED */, i18n("Configuration cancelled")); window.visible = false; } } Item { Layout.fillWidth: true } } } } Component { id: runningJobComponent RunningJob { onResult: { window.q.finished(job.output, job.error, job.errorString); window.visible = false } } } } diff --git a/src/widgets/menu.h b/src/widgets/menu.h index 803e62b..ab9cd0d 100644 --- a/src/widgets/menu.h +++ b/src/widgets/menu.h @@ -1,67 +1,67 @@ /* Copyright 2015 Aleix Pol Gonzalez This library 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.1 of the License, or (at your option) any later version. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PURPOSEMENU_H #define PURPOSEMENU_H #include "purposewidgets_export.h" #include namespace Purpose { class MenuPrivate; class AlternativesModel; class PURPOSEWIDGETS_EXPORT Menu : public QMenu { Q_OBJECT public: explicit Menu(QWidget* parent = nullptr); /** * Exposes the used AlternativesModel so that it can be configured to suit * the application needs */ AlternativesModel* model() const; /** * Forces a reload of the menu in case something changed in the model */ void reload(); Q_SIGNALS: /** * Emitted when a triggered job finishes * * @p output contains the information offered by the plugin. The information offered will depend on the plugin type. - * @p error will be 0 if the execution was successful, otherwise it will provide an error message + * @p error will be 0 if the execution was successful, KIO::ERR_USER_CANCELED if cancelled by the user, otherwise it will provide an error message * @p errorMessage the error message * * @see Purpose::Job */ void finished(const QJsonObject &output, int error, const QString &errorMessage); private: Q_DECLARE_PRIVATE(Menu) MenuPrivate *const d_ptr; }; } #endif