Changeset View
Changeset View
Standalone View
Standalone View
solid-device-automounter/kded/DeviceAutomounter.cpp
Show All 30 Lines | |||||
31 | 31 | | |||
32 | #include <QTimer> | 32 | #include <QTimer> | ||
33 | 33 | | |||
34 | K_PLUGIN_FACTORY_WITH_JSON(DeviceAutomounterFactory, | 34 | K_PLUGIN_FACTORY_WITH_JSON(DeviceAutomounterFactory, | ||
35 | "device_automounter.json", | 35 | "device_automounter.json", | ||
36 | registerPlugin<DeviceAutomounter>();) | 36 | registerPlugin<DeviceAutomounter>();) | ||
37 | 37 | | |||
38 | DeviceAutomounter::DeviceAutomounter(QObject *parent, const QVariantList &args) | 38 | DeviceAutomounter::DeviceAutomounter(QObject *parent, const QVariantList &args) | ||
39 | : KDEDModule(parent) | 39 | : KDEDModule(parent) | ||
40 | , m_settings(new AutomounterSettings(this)) | ||||
bport: m_settings need to go to the next line | |||||
40 | { | 41 | { | ||
41 | Q_UNUSED(args); | 42 | Q_UNUSED(args) | ||
42 | QTimer::singleShot(0, this, &DeviceAutomounter::init); | 43 | QTimer::singleShot(0, this, &DeviceAutomounter::init); | ||
43 | } | 44 | } | ||
44 | 45 | | |||
45 | DeviceAutomounter::~DeviceAutomounter() | 46 | DeviceAutomounter::~DeviceAutomounter() | ||
46 | { | 47 | { | ||
47 | } | 48 | } | ||
48 | 49 | | |||
49 | void DeviceAutomounter::init() | 50 | void DeviceAutomounter::init() | ||
50 | { | 51 | { | ||
51 | if (!AutomounterSettings::automountEnabled()) { | 52 | if (!m_settings->automountEnabled()) { | ||
52 | // Automounting is disabled, no point in hanging around. | 53 | // Automounting is disabled, no point in hanging around. | ||
53 | QDBusConnection dbus = QDBusConnection::sessionBus(); | 54 | QDBusConnection dbus = QDBusConnection::sessionBus(); | ||
54 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"), | 55 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"), | ||
55 | QStringLiteral("/kded"), | 56 | QStringLiteral("/kded"), | ||
56 | QStringLiteral("org.kde.kded5"), | 57 | QStringLiteral("org.kde.kded5"), | ||
57 | QStringLiteral("setModuleAutoloading")); | 58 | QStringLiteral("setModuleAutoloading")); | ||
58 | msg.setArguments({QVariant(QStringLiteral("device_automounter")), QVariant(false)}); | 59 | msg.setArguments({QVariant(QStringLiteral("device_automounter")), QVariant(false)}); | ||
59 | dbus.call(msg, QDBus::NoBlock); | 60 | dbus.call(msg, QDBus::NoBlock); | ||
Show All 10 Lines | |||||
70 | 71 | | |||
71 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, &DeviceAutomounter::deviceAdded); | 72 | connect(Solid::DeviceNotifier::instance(), &Solid::DeviceNotifier::deviceAdded, this, &DeviceAutomounter::deviceAdded); | ||
72 | const QList<Solid::Device> volumes = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume); | 73 | const QList<Solid::Device> volumes = Solid::Device::listFromType(Solid::DeviceInterface::StorageVolume); | ||
73 | for (Solid::Device volume : volumes) { | 74 | for (Solid::Device volume : volumes) { | ||
74 | // sa can be 0 (e.g. for the swap partition) | 75 | // sa can be 0 (e.g. for the swap partition) | ||
75 | if (const Solid::StorageAccess *sa = volume.as<Solid::StorageAccess>()) { | 76 | if (const Solid::StorageAccess *sa = volume.as<Solid::StorageAccess>()) { | ||
76 | connect(sa, &Solid::StorageAccess::accessibilityChanged, this, &DeviceAutomounter::deviceMountChanged); | 77 | connect(sa, &Solid::StorageAccess::accessibilityChanged, this, &DeviceAutomounter::deviceMountChanged); | ||
77 | } | 78 | } | ||
78 | automountDevice(volume, AutomounterSettings::Login); | 79 | automountDevice(volume, m_settings->Login); | ||
79 | } | 80 | } | ||
80 | AutomounterSettings::self()->save(); | 81 | m_settings->save(); | ||
81 | } | 82 | } | ||
82 | 83 | | |||
83 | void DeviceAutomounter::deviceMountChanged(bool accessible, const QString &udi) | 84 | void DeviceAutomounter::deviceMountChanged(bool accessible, const QString &udi) | ||
84 | { | 85 | { | ||
85 | AutomounterSettings::setDeviceLastSeenMounted(udi, accessible); | 86 | m_settings->setDeviceLastSeenMounted(udi, accessible); | ||
86 | AutomounterSettings::self()->save(); | 87 | m_settings->save(); | ||
87 | } | 88 | } | ||
88 | 89 | | |||
89 | void DeviceAutomounter::automountDevice(Solid::Device &dev, AutomounterSettings::AutomountType type) | 90 | void DeviceAutomounter::automountDevice(Solid::Device &dev, AutomounterSettings::AutomountType type) | ||
90 | { | 91 | { | ||
91 | if (dev.is<Solid::StorageVolume>() && dev.is<Solid::StorageAccess>()) { | 92 | if (dev.is<Solid::StorageVolume>() && dev.is<Solid::StorageAccess>()) { | ||
92 | Solid::StorageAccess *sa = dev.as<Solid::StorageAccess>(); | 93 | Solid::StorageAccess *sa = dev.as<Solid::StorageAccess>(); | ||
93 | 94 | | |||
94 | AutomounterSettings::setDeviceLastSeenMounted(dev.udi(), sa->isAccessible()); | 95 | m_settings->setDeviceLastSeenMounted(dev.udi(), sa->isAccessible()); | ||
95 | AutomounterSettings::saveDevice(dev); | 96 | m_settings->saveDevice(dev); | ||
96 | 97 | | |||
97 | if (AutomounterSettings::shouldAutomountDevice(dev.udi(), type)) { | 98 | if (m_settings->shouldAutomountDevice(dev.udi(), type)) { | ||
98 | Solid::StorageVolume *sv = dev.as<Solid::StorageVolume>(); | 99 | Solid::StorageVolume *sv = dev.as<Solid::StorageVolume>(); | ||
99 | if (!sa->isAccessible() && !sv->isIgnored()) { | 100 | if (!sa->isAccessible() && !sv->isIgnored()) { | ||
100 | sa->setup(); | 101 | sa->setup(); | ||
101 | } | 102 | } | ||
102 | } | 103 | } | ||
103 | } | 104 | } | ||
104 | } | 105 | } | ||
105 | 106 | | |||
106 | void DeviceAutomounter::deviceAdded(const QString &udi) | 107 | void DeviceAutomounter::deviceAdded(const QString &udi) | ||
107 | { | 108 | { | ||
108 | AutomounterSettings::self()->load(); | 109 | m_settings->load(); | ||
109 | 110 | | |||
110 | Solid::Device dev(udi); | 111 | Solid::Device dev(udi); | ||
111 | automountDevice(dev, AutomounterSettings::Attach); | 112 | automountDevice(dev, AutomounterSettings::Attach); | ||
112 | AutomounterSettings::self()->save(); | 113 | m_settings->save(); | ||
ervin: This is rather odd. A too eager search and replace? ;-) | |||||
meven: Thanks indeed | |||||
113 | 114 | | |||
114 | if (dev.is<Solid::StorageAccess>()) { | 115 | if (dev.is<Solid::StorageAccess>()) { | ||
115 | Solid::StorageAccess *sa = dev.as<Solid::StorageAccess>(); | 116 | Solid::StorageAccess *sa = dev.as<Solid::StorageAccess>(); | ||
116 | if (sa) { | 117 | if (sa) { | ||
117 | connect(sa, &Solid::StorageAccess::accessibilityChanged, this, &DeviceAutomounter::deviceMountChanged); | 118 | connect(sa, &Solid::StorageAccess::accessibilityChanged, this, &DeviceAutomounter::deviceMountChanged); | ||
118 | } | 119 | } | ||
119 | } | 120 | } | ||
120 | } | 121 | } | ||
121 | 122 | | |||
122 | #include "DeviceAutomounter.moc" | 123 | #include "DeviceAutomounter.moc" |
m_settings need to go to the next line