diff --git a/dataengines/hotplug/CMakeLists.txt b/dataengines/hotplug/CMakeLists.txt index cc3013824..7ad1f29f3 100644 --- a/dataengines/hotplug/CMakeLists.txt +++ b/dataengines/hotplug/CMakeLists.txt @@ -1,4 +1,8 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"plasma_engine_hotplug\") + set(hotplug_engine_SRCS + deviceaction.cpp + deviceserviceaction.cpp hotplugengine.cpp hotplugservice.cpp hotplugjob.cpp @@ -6,17 +10,17 @@ set(hotplug_engine_SRCS add_library(plasma_engine_hotplug MODULE ${hotplug_engine_SRCS}) target_link_libraries(plasma_engine_hotplug - Qt5::DBus - KF5::CoreAddons - KF5::Plasma - KF5::Solid - KF5::Service - KF5::KIOCore - KF5::KIOWidgets - ) + KF5::CoreAddons + KF5::Plasma + KF5::Solid + KF5::Service + KF5::KIOCore + KF5::KIOWidgets + KF5::I18n +) kcoreaddons_desktop_to_json(plasma_engine_hotplug plasma-dataengine-hotplug.desktop) install(TARGETS plasma_engine_hotplug DESTINATION ${KDE_INSTALL_PLUGINDIR}/plasma/dataengine) -install(FILES plasma-dataengine-hotplug.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} ) -install(FILES hotplug.operations DESTINATION ${PLASMA_DATA_INSTALL_DIR}/services ) +install(FILES plasma-dataengine-hotplug.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) +install(FILES hotplug.operations DESTINATION ${PLASMA_DATA_INSTALL_DIR}/services) diff --git a/dataengines/hotplug/Messages.sh b/dataengines/hotplug/Messages.sh new file mode 100755 index 000000000..86a6bcb74 --- /dev/null +++ b/dataengines/hotplug/Messages.sh @@ -0,0 +1,2 @@ +#! /usr/bin/env bash +$XGETTEXT *.cpp -o $podir/plasma_engine_hotplug.pot diff --git a/soliduiserver/deviceaction.cpp b/dataengines/hotplug/deviceaction.cpp similarity index 100% rename from soliduiserver/deviceaction.cpp rename to dataengines/hotplug/deviceaction.cpp diff --git a/soliduiserver/deviceaction.h b/dataengines/hotplug/deviceaction.h similarity index 100% rename from soliduiserver/deviceaction.h rename to dataengines/hotplug/deviceaction.h diff --git a/soliduiserver/deviceserviceaction.cpp b/dataengines/hotplug/deviceserviceaction.cpp similarity index 99% rename from soliduiserver/deviceserviceaction.cpp rename to dataengines/hotplug/deviceserviceaction.cpp index 1768380a2..7ec08e25e 100644 --- a/soliduiserver/deviceserviceaction.cpp +++ b/dataengines/hotplug/deviceserviceaction.cpp @@ -27,7 +27,6 @@ #include #include - class MacroExpander : public KMacroExpanderBase { public: diff --git a/soliduiserver/deviceserviceaction.h b/dataengines/hotplug/deviceserviceaction.h similarity index 100% rename from soliduiserver/deviceserviceaction.h rename to dataengines/hotplug/deviceserviceaction.h diff --git a/dataengines/hotplug/hotplugjob.cpp b/dataengines/hotplug/hotplugjob.cpp index ef22849f3..f5b8d18b3 100644 --- a/dataengines/hotplug/hotplugjob.cpp +++ b/dataengines/hotplug/hotplugjob.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 Viranch Mehta + * Copyright (C) 2019 Harald Sitter * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -19,29 +20,36 @@ #include "hotplugjob.h" #include "hotplugengine.h" -#include -#include +#include "deviceserviceaction.h" #include +#include +#include +#include void HotplugJob::start() { - QString udi (m_dest); - QString operation = operationName(); - - if (operation == QLatin1String("invokeAction")) { - QString action = parameters()[QStringLiteral("predicate")].toString(); - - QStringList desktopFiles; - desktopFiles << action; - - QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"), - QStringLiteral("/modules/soliduiserver"), - QStringLiteral("org.kde.SolidUiServer"), - QStringLiteral("showActionsDialog")); - - msg.setArguments(QList() << udi << desktopFiles); - QDBusConnection::sessionBus().call(msg, QDBus::NoBlock); + if (operationName() == QLatin1String("invokeAction")) { + const QString desktopFile = parameters()[QStringLiteral("predicate")].toString(); + const QString filePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "solid/actions/" + desktopFile); + + QList services = KDesktopFileActions::userDefinedServices(filePath, true); + if (services.size() < 1) { + qWarning() << "Failed to resolve hotplugjob action" << desktopFile << filePath; + setError(KJob::UserDefinedError); + setErrorText(i18nc("error; %1 is the desktop file name of the service", + "Failed to resolve service action for %1.", desktopFile)); + setResult(false); // calls emitResult internally. + return; + } + // Cannot be > 1, we only have one filePath, and < 1 was handled as error. + Q_ASSERT(services.size() == 1); + + DeviceServiceAction action; + action.setService(services.takeFirst()); + + Solid::Device device(m_dest); + action.execute(device); } emitResult(); diff --git a/soliduiserver/CMakeLists.txt b/soliduiserver/CMakeLists.txt index ef2ca5bad..8bbcf3782 100644 --- a/soliduiserver/CMakeLists.txt +++ b/soliduiserver/CMakeLists.txt @@ -3,17 +3,19 @@ add_definitions(-DTRANSLATION_DOMAIN=\"soliduiserver5\") set(kded_soliduiserver_SRCS soliduiserver.cpp - deviceactionsdialog.cpp - deviceaction.cpp - devicenothingaction.cpp - deviceserviceaction.cpp ) -ki18n_wrap_ui(kded_soliduiserver_SRCS deviceactionsdialogview.ui) - add_library(soliduiserver MODULE ${kded_soliduiserver_SRCS}) kcoreaddons_desktop_to_json(soliduiserver soliduiserver.desktop) -target_link_libraries(soliduiserver KF5::Solid KF5::DBusAddons KF5::Wallet KF5::KIOCore KF5::WindowSystem KF5::KDELibs4Support) +target_link_libraries(soliduiserver + KF5::Solid + KF5::DBusAddons + KF5::Wallet + KF5::KIOCore + KF5::WindowSystem + KF5::I18n + KF5::WidgetsAddons +) install(TARGETS soliduiserver DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded) diff --git a/soliduiserver/deviceactionsdialog.cpp b/soliduiserver/deviceactionsdialog.cpp deleted file mode 100644 index 6e15d74e3..000000000 --- a/soliduiserver/deviceactionsdialog.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* This file is part of the KDE Project - Copyright (c) 2005 Jean-Remy Falleri - Copyright (c) 2005-2007 Kevin Ottens - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - 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 - Library 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 "deviceactionsdialog.h" - -#include -#include -#include - -#include "deviceaction.h" -#include "ui_deviceactionsdialogview.h" - -DeviceActionsDialog::DeviceActionsDialog(QWidget *parent) - : KDialog(parent) -{ - qDebug() << Q_FUNC_INFO; - - setModal(false); - setButtons(Ok|Cancel); - setDefaultButton(Ok); - - QWidget *page = new QWidget(this); - m_view.setupUi(page); - setMainWidget(page); - updateActionsListBox(); - - resize(QSize(400,400).expandedTo(minimumSizeHint())); - - connect(this, &DeviceActionsDialog::okClicked, this, &DeviceActionsDialog::slotOk); - connect(m_view.actionsList, &QListWidget::doubleClicked, this, &DeviceActionsDialog::slotOk); - - connect(this, &DeviceActionsDialog::finished, this, &DeviceActionsDialog::delayedDestruct); -} - -DeviceActionsDialog::~DeviceActionsDialog() -{ -} - -void DeviceActionsDialog::setDevice(const Solid::Device &device) -{ - m_device = device; - - QString label = device.vendor(); - if (!label.isEmpty()) label+=' '; - label+= device.product(); - - setWindowTitle(label); - - m_view.iconLabel->setPixmap(QIcon::fromTheme(device.icon()).pixmap(64)); - m_view.descriptionLabel->setText(device.vendor()+' '+device.product()); - setWindowIcon(QIcon::fromTheme(device.icon())); -} - -Solid::Device DeviceActionsDialog::device() const -{ - return m_device; -} - -void DeviceActionsDialog::setActions(const QList &actions) -{ - qDeleteAll(m_actions); - m_actions.clear(); - - m_actions = actions; - - updateActionsListBox(); -} - -QList DeviceActionsDialog::actions() const -{ - return m_actions; -} - -void DeviceActionsDialog::updateActionsListBox() -{ - m_view.actionsList->clear(); - - foreach (DeviceAction *action, m_actions) { - QListWidgetItem *item = new QListWidgetItem(QIcon::fromTheme(action->iconName()), - action->label()); - item->setData(Qt::UserRole, action->id()); - m_view.actionsList->addItem(item); - } - - if (m_view.actionsList->count()>0) - m_view.actionsList->item(0)->setSelected(true); -} - -void DeviceActionsDialog::slotOk() -{ - QListWidgetItem *item = m_view.actionsList->selectedItems().value(0); - - if (item) { - const QString id = item->data(Qt::UserRole).toString(); - - foreach (DeviceAction *action, m_actions) { - if (action->id()==id) { - launchAction(action); - return; - } - } - } -} - -void DeviceActionsDialog::launchAction(DeviceAction *action) -{ - action->execute(m_device); - accept(); -} diff --git a/soliduiserver/deviceactionsdialog.h b/soliduiserver/deviceactionsdialog.h deleted file mode 100644 index 983cd21cf..000000000 --- a/soliduiserver/deviceactionsdialog.h +++ /dev/null @@ -1,57 +0,0 @@ -/* This file is part of the KDE Project - Copyright (c) 2005 Jean-Remy Falleri - Copyright (c) 2005-2007 Kevin Ottens - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - 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 - Library 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. -*/ - -#ifndef DEVICEACTIONSDIALOG_H -#define DEVICEACTIONSDIALOG_H - -#include -#include - -#include "ui_deviceactionsdialogview.h" - -class DeviceAction; - -class DeviceActionsDialog : public KDialog -{ - Q_OBJECT - -public: - explicit DeviceActionsDialog(QWidget *parent=nullptr); - ~DeviceActionsDialog() override; - - void setDevice(const Solid::Device &device); - Solid::Device device() const; - - void setActions(const QList &actions); - QList actions() const; - -private Q_SLOTS: - void slotOk(); - -private: - void launchAction(DeviceAction *action); - void updateActionsListBox(); - - Ui::DeviceActionsDialogView m_view; - - Solid::Device m_device; - QList m_actions; -}; - -#endif diff --git a/soliduiserver/deviceactionsdialogview.ui b/soliduiserver/deviceactionsdialogview.ui deleted file mode 100644 index da23d5dda..000000000 --- a/soliduiserver/deviceactionsdialogview.ui +++ /dev/null @@ -1,94 +0,0 @@ - - DeviceActionsDialogView - - - - 0 - 0 - 508 - 480 - - - - - 15 - - - - - 20 - - - - - - 0 - 0 - - - - - 64 - 64 - - - - - 64 - 64 - - - - true - - - false - - - - - - - A new device has been detected.<br><b>What do you want to do?</b> - - - Qt::RichText - - - false - - - - - - - - - - 0 - 0 - - - - ... - - - false - - - - - - - - 48 - 48 - - - - - - - - - diff --git a/soliduiserver/devicenothingaction.cpp b/soliduiserver/devicenothingaction.cpp deleted file mode 100644 index ea4da76cc..000000000 --- a/soliduiserver/devicenothingaction.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* This file is part of the KDE Project - Copyright (c) 2005 Jean-Remy Falleri - Copyright (c) 2005-2007 Kevin Ottens - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - 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 - Library 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 "devicenothingaction.h" - -#include - -DeviceNothingAction::DeviceNothingAction() - : DeviceAction() -{ - setIconName(QStringLiteral("dialog-cancel")); - setLabel(i18n("Do nothing")); -} - -QString DeviceNothingAction::id() const -{ - return QStringLiteral("#NothingAction"); -} - -void DeviceNothingAction::execute(Solid::Device &/*device*/) -{ -} diff --git a/soliduiserver/devicenothingaction.h b/soliduiserver/devicenothingaction.h deleted file mode 100644 index ddad3a7d2..000000000 --- a/soliduiserver/devicenothingaction.h +++ /dev/null @@ -1,34 +0,0 @@ -/* This file is part of the KDE Project - Copyright (c) 2005 Jean-Remy Falleri - Copyright (c) 2005-2007 Kevin Ottens - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - 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 - Library 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. -*/ - -#ifndef DEVICENOTHINGACTION_H -#define DEVICENOTHINGACTION_H - -#include "deviceaction.h" - -class DeviceNothingAction : public DeviceAction -{ -public: - DeviceNothingAction(); - QString id() const override; - void execute(Solid::Device &device) override; -}; - -#endif - diff --git a/soliduiserver/soliduiserver.cpp b/soliduiserver/soliduiserver.cpp index d06a1e6a5..ddd2f0c4d 100644 --- a/soliduiserver/soliduiserver.cpp +++ b/soliduiserver/soliduiserver.cpp @@ -22,24 +22,25 @@ #include "soliduiserver.h" #include "config-X11.h" -#include +#include #include #include +#include #include #include #include -#include #include #include #include -#include -#include "deviceactionsdialog.h" -#include "deviceaction.h" -#include "deviceserviceaction.h" -#include "devicenothingaction.h" +// solid specific includes +#include +#include +#include +#include +#include K_PLUGIN_CLASS_WITH_JSON(SolidUiServer, "soliduiserver.json") @@ -52,69 +53,6 @@ SolidUiServer::~SolidUiServer() { } -void SolidUiServer::showActionsDialog(const QString &udi, - const QStringList &desktopFiles) -{ - if (m_udiToActionsDialog.contains(udi)) { - DeviceActionsDialog *dialog = m_udiToActionsDialog[udi]; - dialog->activateWindow(); - return; - } - - - QList actions; - - foreach (const QString &desktop, desktopFiles) { - const QString filePath = QStandardPaths::locate(QStandardPaths::GenericDataLocation, "solid/actions/"+desktop); - - QList services = KDesktopFileActions::userDefinedServices(filePath, true); - - foreach (const KServiceAction &service, services) { - DeviceServiceAction *action = new DeviceServiceAction(); - action->setService(service); - actions << action; - } - } - - // Only one action, execute directly - if (actions.size()==1) { - DeviceAction *action = actions.takeFirst(); - Solid::Device device(udi); - action->execute(device); - delete action; - return; - } - - actions << new DeviceNothingAction(); - - DeviceActionsDialog *dialog = new DeviceActionsDialog(); - dialog->setDevice(Solid::Device(udi)); - dialog->setActions(actions); - - connect(dialog, &DeviceActionsDialog::finished, this, &SolidUiServer::onActionDialogFinished); - - m_udiToActionsDialog[udi] = dialog; - - // Update user activity timestamp, otherwise the notification dialog will be shown - // in the background due to focus stealing prevention. Entering a new media can - // be seen as a kind of user activity after all. It'd be better to update the timestamp - // as soon as the media is entered, but it apparently takes some time to get here. - KUserTimestamp::updateUserTimestamp(); - - dialog->show(); -} - -void SolidUiServer::onActionDialogFinished() -{ - DeviceActionsDialog *dialog = qobject_cast(sender()); - - if (dialog) { - QString udi = dialog->device().udi(); - m_udiToActionsDialog.remove(udi); - } -} - - void SolidUiServer::showPassphraseDialog(const QString &udi, const QString &returnService, const QString &returnObject, uint wId, const QString &appId) diff --git a/soliduiserver/soliduiserver.h b/soliduiserver/soliduiserver.h index 306e256b7..3785cb1c1 100644 --- a/soliduiserver/soliduiserver.h +++ b/soliduiserver/soliduiserver.h @@ -21,20 +21,13 @@ #define SOLIDUISERVER_H #include -#include -#include -#include +#include #include -//solid specific includes -#include -#include -#include -#include - class DeviceActionsDialog; class KPasswordDialog; +class QWidget; class SolidUiServer : public KDEDModule { @@ -46,23 +39,18 @@ public: ~SolidUiServer() override; public Q_SLOTS: - Q_SCRIPTABLE void showActionsDialog(const QString &udi, - const QStringList &desktopFiles); - Q_SCRIPTABLE void showPassphraseDialog(const QString &udi, const QString &returnService, const QString &returnObject, uint wId, const QString &appId); private Q_SLOTS: - void onActionDialogFinished(); void onPassphraseDialogCompleted(const QString &pass, bool keep); void onPassphraseDialogRejected(); private: void reparentDialog(QWidget *dialog, WId wId, const QString &appId, bool modal); - QMap m_udiToActionsDialog; QMap m_idToPassphraseDialog; }; #endif