Commit 2b9c762f authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

[Device Automounter] Load kded module only if enabled

There's no point in loading the entire module when automounting is disabled.
It does Solid device queries which can be quite expensive, albeit it delays initialization.

The AutomounterSettings::shouldAutomountDevice function allows force-mounting even if automounting as a whole is disabled
whereas the KCM UI does not. Not sure what the reason for that is.

Differential Revision: https://phabricator.kde.org/D13852
parent 20194c05
......@@ -11,6 +11,7 @@ kconfig_add_kcfg_files(kcm_device_automounter_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/.
add_library(kcm_device_automounter ${kcm_device_automounter_SRCS} ${device_automounter_lib_SRCS})
target_link_libraries(kcm_device_automounter
Qt5::DBus
KF5::CoreAddons
KF5::KCMUtils
KF5::ConfigWidgets
......
......@@ -20,6 +20,8 @@
#include "DeviceAutomounterKCM.h"
#include <QDBusConnection>
#include <QDBusMessage>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QItemSelectionModel>
......@@ -129,7 +131,8 @@ void DeviceAutomounterKCM::save()
{
saveLayout();
AutomounterSettings::setAutomountEnabled(automountEnabled->isChecked());
const bool enabled = automountEnabled->isChecked();
AutomounterSettings::setAutomountEnabled(enabled);
AutomounterSettings::setAutomountUnknownDevices(automountUnknownDevices->isChecked());
AutomounterSettings::setAutomountOnLogin(automountOnLogin->isChecked());
AutomounterSettings::setAutomountOnPlugin(automountOnPlugin->isChecked());
......@@ -166,6 +169,23 @@ void DeviceAutomounterKCM::save()
}
AutomounterSettings::self()->save();
// Now tell kded to automatically load the module if loaded
QDBusConnection dbus = QDBusConnection::sessionBus();
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"),
QStringLiteral("/kded"),
QStringLiteral("org.kde.kded5"),
QStringLiteral("setModuleAutoloading"));
msg.setArguments({QVariant(QStringLiteral("device_automounter")), QVariant(enabled)});
dbus.call(msg, QDBus::NoBlock);
// Load or unload right away
msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"),
QStringLiteral("/kded"),
QStringLiteral("org.kde.kded5"),
enabled ? QStringLiteral("loadModule") : QStringLiteral("unloadModule"));
msg.setArguments({QVariant(QStringLiteral("device_automounter"))});
dbus.call(msg, QDBus::NoBlock);
}
void DeviceAutomounterKCM::saveLayout()
......
......@@ -5,6 +5,6 @@ kconfig_add_kcfg_files(kded_device_automounter_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/
add_library(kded_device_automounter MODULE ${device_automounter_lib_SRCS} ${kded_device_automounter_SRCS})
set_target_properties(kded_device_automounter PROPERTIES OUTPUT_NAME device_automounter)
kcoreaddons_desktop_to_json(kded_device_automounter device_automounter.desktop)
target_link_libraries(kded_device_automounter KF5::CoreAddons KF5::Service KF5::ConfigCore KF5::ConfigGui KF5::DBusAddons KF5::Solid)
target_link_libraries(kded_device_automounter Qt5::DBus KF5::CoreAddons KF5::Service KF5::ConfigCore KF5::ConfigGui KF5::DBusAddons KF5::Solid)
install(TARGETS kded_device_automounter DESTINATION ${KDE_INSTALL_PLUGINDIR}/kf5/kded)
......@@ -26,6 +26,9 @@
#include <Solid/StorageAccess>
#include <Solid/StorageVolume>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QTimer>
K_PLUGIN_FACTORY_WITH_JSON(DeviceAutomounterFactory,
......@@ -45,6 +48,26 @@ DeviceAutomounter::~DeviceAutomounter()
void DeviceAutomounter::init()
{
if (!AutomounterSettings::automountEnabled()) {
// Automounting is disabled, no point in hanging around.
QDBusConnection dbus = QDBusConnection::sessionBus();
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"),
QStringLiteral("/kded"),
QStringLiteral("org.kde.kded5"),
QStringLiteral("setModuleAutoloading"));
msg.setArguments({QVariant(QStringLiteral("device_automounter")), QVariant(false)});
dbus.call(msg, QDBus::NoBlock);
// Unload right away
msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"),
QStringLiteral("/kded"),
QStringLiteral("org.kde.kded5"),
QStringLiteral("unloadModule"));
msg.setArguments({QVariant(QStringLiteral("device_automounter"))});
dbus.call(msg, QDBus::NoBlock);
return;
}
connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, &DeviceAutomounter::deviceAdded);
QList<Solid::Device> volumes = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume);
foreach(Solid::Device volume, volumes) {
......
[Desktop Entry]
Type=Service
X-KDE-ServiceTypes=KDEDModule
# Needs to stay this way for compatibility
# It will disable autoload on initialization when automounting is disabled
X-KDE-Kded-autoload=true
X-KDE-Kded-load-on-demand=false
X-KDE-Kded-phase=1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment