diff --git a/solid-device-automounter/kcm/CMakeLists.txt b/solid-device-automounter/kcm/CMakeLists.txt index 66b59b2d7..89cc2df27 100644 --- a/solid-device-automounter/kcm/CMakeLists.txt +++ b/solid-device-automounter/kcm/CMakeLists.txt @@ -1,23 +1,24 @@ add_definitions(-DTRANSLATION_DOMAIN=\"kcm5_device_automounter\") set(kcm_device_automounter_SRCS DeviceAutomounterKCM.cpp DeviceModel.cpp) include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) ki18n_wrap_ui(kcm_device_automounter_SRCS DeviceAutomounterKCM.ui) kconfig_add_kcfg_files(kcm_device_automounter_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../lib/AutomounterSettingsBase.kcfgc ${CMAKE_CURRENT_SOURCE_DIR}/LayoutSettings.kcfgc) 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 KF5::Service KF5::I18n KF5::Solid) install(TARGETS kcm_device_automounter DESTINATION ${KDE_INSTALL_PLUGINDIR}) install(FILES device_automounter_kcm.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR}) diff --git a/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp b/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp index 45ce11c17..2a4b1ba8c 100644 --- a/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp +++ b/solid-device-automounter/kcm/DeviceAutomounterKCM.cpp @@ -1,207 +1,227 @@ /************************************************************************** * Copyright (C) 2009-2010 Trever Fischer * * Copyright (C) 2015 Kai UWe Broulik * * * * 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 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 . * ***************************************************************************/ #include "DeviceAutomounterKCM.h" +#include +#include #include #include #include #include #include #include #include #include #include "AutomounterSettings.h" #include "LayoutSettings.h" #include "DeviceModel.h" K_PLUGIN_FACTORY(DeviceAutomounterKCMFactory, registerPlugin();) K_EXPORT_PLUGIN(DeviceAutomounterKCMFactory("kcm_device_automounter")) DeviceAutomounterKCM::DeviceAutomounterKCM(QWidget *parent, const QVariantList &args) : KCModule(parent, args)//DeviceAutomounterKCMFactory::componentData(), parent) { KAboutData *about = new KAboutData("kcm_device_automounter", i18n("Device Automounter"), "2.0", QString(), KAboutLicense::GPL_V2, i18n("(c) 2009 Trever Fischer, (c) 2015 Kai Uwe Broulik")); about->addAuthor(i18n("Trever Fischer"), i18n("Original Author")); about->addAuthor(i18n("Kai Uwe Broulik"), i18n("Plasma 5 Port"), "kde@privat.broulik.de"); setAboutData(about); setupUi(this); m_devices = new DeviceModel(this); deviceView->setModel(m_devices); auto emitChanged = [this] { emit changed(); }; connect(automountOnLogin, &QCheckBox::stateChanged, this, emitChanged); connect(automountOnPlugin, &QCheckBox::stateChanged, this, emitChanged); connect(automountEnabled, &QCheckBox::stateChanged, this, emitChanged); connect(automountUnknownDevices, &QCheckBox::stateChanged, this, emitChanged); connect(m_devices, &DeviceModel::dataChanged, this, emitChanged); connect(automountEnabled, &QCheckBox::stateChanged, this, &DeviceAutomounterKCM::enabledChanged); connect(deviceView->selectionModel(), &QItemSelectionModel::selectionChanged, this, &DeviceAutomounterKCM::updateForgetDeviceButton); connect(forgetDevice, &QAbstractButton::clicked, this, &DeviceAutomounterKCM::forgetSelectedDevices); forgetDevice->setEnabled(false); } DeviceAutomounterKCM::~DeviceAutomounterKCM() { saveLayout(); } void DeviceAutomounterKCM::updateForgetDeviceButton() { foreach (const QModelIndex &idx, deviceView->selectionModel()->selectedIndexes()) { if (idx.data(DeviceModel::TypeRole) == DeviceModel::Detatched) { forgetDevice->setEnabled(true); return; } } forgetDevice->setEnabled(false); } void DeviceAutomounterKCM::forgetSelectedDevices() { QItemSelectionModel *selected = deviceView->selectionModel(); int offset = 0; while (!selected->selectedIndexes().isEmpty() && selected->selectedIndexes().size() > offset) { if (selected->selectedIndexes()[offset].data(DeviceModel::TypeRole) == DeviceModel::Attached) { offset++; } else { m_devices->forgetDevice(selected->selectedIndexes()[offset].data(DeviceModel::UdiRole).toString()); } } changed(); } void DeviceAutomounterKCM::enabledChanged() { automountOnLogin->setEnabled(automountEnabled->isChecked()); automountOnPlugin->setEnabled(automountEnabled->isChecked()); automountUnknownDevices->setEnabled(automountEnabled->isChecked()); deviceView->setEnabled(automountEnabled->isChecked()); } void DeviceAutomounterKCM::load() { automountEnabled->setChecked(AutomounterSettings::automountEnabled()); automountUnknownDevices->setChecked(AutomounterSettings::automountUnknownDevices()); automountOnLogin->setChecked(AutomounterSettings::automountOnLogin()); automountOnPlugin->setChecked(AutomounterSettings::automountOnPlugin()); m_devices->reload(); enabledChanged(); loadLayout(); } 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()); QStringList validDevices; for (int i = 0; i < m_devices->rowCount(); ++i) { const QModelIndex &idx = m_devices->index(i, 0); for (int j = 0; j < m_devices->rowCount(idx); ++j) { QModelIndex dev = m_devices->index(j, 1, idx); const QString device = dev.data(DeviceModel::UdiRole).toString(); validDevices << device; if (dev.data(Qt::CheckStateRole).toInt() == Qt::Checked) { AutomounterSettings::deviceSettings(device).writeEntry("ForceLoginAutomount", true); } else { AutomounterSettings::deviceSettings(device).writeEntry("ForceLoginAutomount", false); } dev = dev.sibling(j, 2); if (dev.data(Qt::CheckStateRole).toInt() == Qt::Checked) { AutomounterSettings::deviceSettings(device).writeEntry("ForceAttachAutomount", true); } else { AutomounterSettings::deviceSettings(device).writeEntry("ForceAttachAutomount", false); } } } foreach (const QString &possibleDevice, AutomounterSettings::knownDevices()) { if (!validDevices.contains(possibleDevice)) { AutomounterSettings::deviceSettings(possibleDevice).deleteGroup(); } } 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() { QList widths; const int nbColumn = m_devices->columnCount(); widths.reserve(nbColumn); for (int i = 0; i < nbColumn; ++i) { widths << deviceView->columnWidth(i); } LayoutSettings::setHeaderWidths(widths); //Check DeviceModel.cpp, thats where the magic row numbers come from. LayoutSettings::setAttachedExpanded(deviceView->isExpanded(m_devices->index(0,0))); LayoutSettings::setDetatchedExpanded(deviceView->isExpanded(m_devices->index(1,0))); LayoutSettings::self()->save(); } void DeviceAutomounterKCM::loadLayout() { LayoutSettings::self()->load(); //Reset it first, just in case there isn't any layout saved for a particular column. int nbColumn = m_devices->columnCount(); for (int i = 0; i < nbColumn; ++i) { deviceView->resizeColumnToContents(i); } QList widths = LayoutSettings::headerWidths(); nbColumn = m_devices->columnCount(); for (int i = 0; i < nbColumn && i < widths.size(); ++i) { deviceView->setColumnWidth(i, widths[i]); } deviceView->setExpanded(m_devices->index(0,0), LayoutSettings::attachedExpanded()); deviceView->setExpanded(m_devices->index(1,0), LayoutSettings::detatchedExpanded()); } #include "DeviceAutomounterKCM.moc" diff --git a/solid-device-automounter/kded/CMakeLists.txt b/solid-device-automounter/kded/CMakeLists.txt index 7ba3cb47d..e14d6e337 100644 --- a/solid-device-automounter/kded/CMakeLists.txt +++ b/solid-device-automounter/kded/CMakeLists.txt @@ -1,10 +1,10 @@ set(kded_device_automounter_SRCS DeviceAutomounter.cpp) kconfig_add_kcfg_files(kded_device_automounter_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/../lib/AutomounterSettingsBase.kcfgc) 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) diff --git a/solid-device-automounter/kded/DeviceAutomounter.cpp b/solid-device-automounter/kded/DeviceAutomounter.cpp index f1bc19d19..818987880 100644 --- a/solid-device-automounter/kded/DeviceAutomounter.cpp +++ b/solid-device-automounter/kded/DeviceAutomounter.cpp @@ -1,99 +1,122 @@ /*************************************************************************** * Copyright (C) 2009 by Trever Fischer * * * * 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 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 . * ***************************************************************************/ #include "DeviceAutomounter.h" #include #include #include #include #include +#include +#include + #include K_PLUGIN_FACTORY_WITH_JSON(DeviceAutomounterFactory, "device_automounter.json", registerPlugin();) DeviceAutomounter::DeviceAutomounter(QObject *parent, const QVariantList &args) : KDEDModule(parent) { Q_UNUSED(args); QTimer::singleShot(0, this, &DeviceAutomounter::init); } 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 volumes = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume); foreach(Solid::Device volume, volumes) { // sa can be 0 (e.g. for the swap partition) if (Solid::StorageAccess *sa = volume.as()) { connect(sa, &Solid::StorageAccess::accessibilityChanged, this, &DeviceAutomounter::deviceMountChanged); } automountDevice(volume, AutomounterSettings::Login); } AutomounterSettings::self()->save(); } void DeviceAutomounter::deviceMountChanged(bool accessible, const QString &udi) { AutomounterSettings::setDeviceLastSeenMounted(udi, accessible); AutomounterSettings::self()->save(); } void DeviceAutomounter::automountDevice(Solid::Device &dev, AutomounterSettings::AutomountType type) { if (dev.is() && dev.is()) { Solid::StorageAccess *sa = dev.as(); AutomounterSettings::setDeviceLastSeenMounted(dev.udi(), sa->isAccessible()); AutomounterSettings::saveDevice(dev); if (AutomounterSettings::shouldAutomountDevice(dev.udi(), type)) { Solid::StorageVolume *sv = dev.as(); if (!sv->isIgnored()) { sa->setup(); } } } } void DeviceAutomounter::deviceAdded(const QString &udi) { AutomounterSettings::self()->load(); Solid::Device dev(udi); automountDevice(dev, AutomounterSettings::Attach); AutomounterSettings::self()->save(); if (dev.is()) { Solid::StorageAccess *sa = dev.as(); if (sa) { connect(sa, &Solid::StorageAccess::accessibilityChanged, this, &DeviceAutomounter::deviceMountChanged); } } } #include "DeviceAutomounter.moc" diff --git a/solid-device-automounter/kded/device_automounter.desktop b/solid-device-automounter/kded/device_automounter.desktop index da629bff1..6aec22995 100644 --- a/solid-device-automounter/kded/device_automounter.desktop +++ b/solid-device-automounter/kded/device_automounter.desktop @@ -1,87 +1,89 @@ [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 X-KDE-Library=device_automounter Name=Removable Device Automounter Name[ar]=الضّامّ الآليّ للأجهزة القابلة للإزالة Name[ca]=Muntador automàtic de dispositius extraïbles Name[ca@valencia]=Muntador automàtic de dispositius extraïbles Name[cs]=Automatické připojování odpojitelných zařízení Name[da]=Automontering af flytbare enheder Name[de]=Automatisches Einhängen von Wechselmedien Name[el]=Αυτόματη προσάρτηση αφαιρούμενων συσκευών Name[en_GB]=Removable Device Automounter Name[es]=Montador automático de dispositivos extraíbles Name[et]=Eemaldatavate seadmete automaatne ühendaja Name[eu]=Gailu aldagarrien automuntatzailea Name[fi]=Irrotettavan laitteen automaattiasentaja Name[fr]=Monteur automatique de périphériques Name[gl]=Montador automático de dispositivos extraíbeis Name[he]=מציב התקנים ניידים Name[hu]=Automatikus csatolás Name[id]=Removable Device Automounter Name[it]=Montaggio automatico dei dispositivi rimovibili Name[ko]=이동식 장치 자동 마운터 Name[lt]=Keičiamųjų įrenginių automatinis prijungimas Name[nl]=Automatische aankoppelaar voor verwijderbare apparaten Name[nn]=Automontering av flyttbare einingar Name[pa]=ਹਟਾਉਣਯੋਗ ਜੰਤਰ ਆਟੋ-ਮਾਊਂਟਰ Name[pl]=Samoczynne podpinanie urządzeń wymiennych Name[pt]=Auto-Montagem de Dispositivos Removíveis Name[pt_BR]=Montagem automática de dispositivos removíveis Name[ru]=Подключение внешних носителей Name[sk]=Automatické pripájanie vymeniteľných zariadení Name[sl]=Samodejno priklapljanje odstranljivih naprav Name[sr]=Аутоматско монтирање уклоњивих уређаја Name[sr@ijekavian]=Аутоматско монтирање уклоњивих уређаја Name[sr@ijekavianlatin]=Automatsko montiranje uklonjivih uređaja Name[sr@latin]=Automatsko montiranje uklonjivih uređaja Name[sv]=Automatisk montering av flyttbara enheter Name[tr]=Çıkarılabilir Aygıt Otomatik Bağlayıcı Name[uk]=Автоматичне монтування портативних пристроїв Name[x-test]=xxRemovable Device Automounterxx Name[zh_CN]=移动设备自动挂载器 Name[zh_TW]=可移除裝置自動掛載器 Comment=Automatically mounts devices as needed Comment[ar]=يضمّ الأجهزة آليًّا عند الحاجة Comment[ca]=Munta automàticament els dispositius quan es necessita Comment[ca@valencia]=Munta automàticament els dispositius quan es necessita Comment[cs]=Automaticky připojí zařízení dle potřeby Comment[da]=Monterer automatisk enheder efter behov Comment[de]=Hängt Geräte bei Bedarf automatisch ein Comment[el]=Αυτόματη προσάρτηση συσκευών όταν χρειάζεται Comment[en_GB]=Automatically mounts devices as needed Comment[es]=Monta automáticamente dispositivos cuando es necesario Comment[et]=Seadmete automaatne ühendamine vajaduse korral Comment[eu]=Automatikoki muntatzen ditu gailuak behar bezala Comment[fi]=Liittää laitteet automaattisesti tarpeen mukaan Comment[fr]=Monte automatiquement les périphériques lorsque cela est nécessaire Comment[gl]=Monta automaticamente os dispositivos cando sexa preciso Comment[he]=הצב אוטומטית אם צריך Comment[hu]=Eszközök automatikus csatolása szükség szerint Comment[id]=Mount perangkat secara otomatis ketika diperlukan Comment[it]=Monta automaticamente i dispositivi quando servono Comment[ko]=필요할 때 자동으로 장치를 마운트합니다 Comment[lt]=Prireikus automatiškai prijungia įrenginius Comment[nl]=Koppelt automatisch apparaten aan zoals nodig is Comment[nn]=Monter einingar automatisk når dei trengst Comment[pa]=ਜਦੋਂ ਲੋੜ ਹੋਵੇ ਤਾਂ ਜੰਤਰ ਆਟੋਮੈਟਿਕ ਮਾਊਂਟ ਕਰੋ Comment[pl]=Podpina urządzenia, gdy są potrzebne Comment[pt]=Monta automaticamente os dispositivos, se necessário Comment[pt_BR]=Monta automaticamente os dispositivos quando necessário Comment[ru]=Автоматически подключает внешние носители информации Comment[sk]=Automaticky pripojí zariadenia podľa potreby Comment[sl]=Samodejno po potrebi priklopi naprave Comment[sr]=Аутоматско монтирање уклоњивих уређаја по потреби Comment[sr@ijekavian]=Аутоматско монтирање уклоњивих уређаја по потреби Comment[sr@ijekavianlatin]=Automatsko montiranje uklonjivih uređaja po potrebi Comment[sr@latin]=Automatsko montiranje uklonjivih uređaja po potrebi Comment[sv]=Monterar automatiskt enheter efter behov Comment[tr]=Aygıtları gerektiğinde otomatik olarak bağlar Comment[uk]=Автоматичне монтування пристроїв за вимогою Comment[x-test]=xxAutomatically mounts devices as neededxx Comment[zh_CN]=按需自动挂载设备 Comment[zh_TW]=需要時自動掛載