Changeset View
Changeset View
Standalone View
Standalone View
src/fileitemactionplugin/sharefileitemaction.cpp
| Show All 28 Lines | |||||
| 29 | #include <QIcon> | 29 | #include <QIcon> | ||
| 30 | #include <QJsonArray> | 30 | #include <QJsonArray> | ||
| 31 | #include <QDesktopServices> | 31 | #include <QDesktopServices> | ||
| 32 | 32 | | |||
| 33 | #include <KPluginFactory> | 33 | #include <KPluginFactory> | ||
| 34 | #include <KPluginLoader> | 34 | #include <KPluginLoader> | ||
| 35 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
| 36 | #include <KNotification> | 36 | #include <KNotification> | ||
| 37 | #include <kio/global.h> | ||||
| 37 | 38 | | |||
| 38 | #include "menu.h" | 39 | #include "menu.h" | ||
| 39 | #include "alternativesmodel.h" | 40 | #include "alternativesmodel.h" | ||
| 40 | 41 | | |||
| 41 | K_PLUGIN_CLASS_WITH_JSON(ShareFileItemAction, "sharefileitemaction.json") | 42 | K_PLUGIN_CLASS_WITH_JSON(ShareFileItemAction, "sharefileitemaction.json") | ||
| 42 | 43 | | |||
| 43 | Q_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION, "purpose.fileitemaction") | 44 | Q_LOGGING_CATEGORY(PURPOSE_FILEITEMACTION, "purpose.fileitemaction") | ||
| 44 | 45 | | |||
| 45 | ShareFileItemAction::ShareFileItemAction(QObject* parent, const QVariantList& ) | 46 | ShareFileItemAction::ShareFileItemAction(QObject* parent, const QVariantList& ) | ||
| 46 | : KAbstractFileItemActionPlugin(parent), | 47 | : KAbstractFileItemActionPlugin(parent), | ||
| 47 | m_menu(new Purpose::Menu()) | 48 | m_menu(new Purpose::Menu()) | ||
| 48 | { | 49 | { | ||
| 49 | m_menu->setTitle(i18n("Share")); | 50 | m_menu->setTitle(i18n("Share")); | ||
| 50 | m_menu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); | 51 | m_menu->setIcon(QIcon::fromTheme(QStringLiteral("document-share"))); | ||
| 51 | m_menu->model()->setPluginType(QStringLiteral("Export")); | 52 | m_menu->model()->setPluginType(QStringLiteral("Export")); | ||
| 52 | 53 | | |||
| 53 | QObject::connect(m_menu, &Purpose::Menu::finished, [](const QJsonObject &output, int error, const QString &errorMessage) { | 54 | QObject::connect(m_menu, &Purpose::Menu::finished, [](const QJsonObject &output, int error, const QString &errorMessage) { | ||
| 54 | if (error == 0) { | 55 | if (error == 0 || error == KIO::ERR_USER_CANCELED) { | ||
| 55 | if (output.contains(QLatin1String("url"))) | 56 | if (output.contains(QLatin1String("url"))) | ||
broulik: If possible use `KIO::ERR_USER_CANCELED`, otherwise don't bother, comment's fine | |||||
| 56 | QDesktopServices::openUrl(QUrl(output.value(QLatin1String("url")).toString())); | 57 | QDesktopServices::openUrl(QUrl(output.value(QLatin1String("url")).toString())); | ||
| 57 | } else { | 58 | } else { | ||
| 58 | KNotification::event(KNotification::Error, i18n("Error sharing"), errorMessage); | 59 | KNotification::event(KNotification::Error, i18n("Error sharing"), errorMessage); | ||
| 59 | qWarning() << "job failed with error" << error << errorMessage << output; | 60 | qWarning() << "job failed with error" << error << errorMessage << output; | ||
| 60 | } | 61 | } | ||
| 61 | }); | 62 | }); | ||
| 62 | } | 63 | } | ||
| 63 | 64 | | |||
| Show All 20 Lines | |||||
If possible use KIO::ERR_USER_CANCELED, otherwise don't bother, comment's fine