Changeset View
Changeset View
Standalone View
Standalone View
solid-device-automounter/kcm/DeviceAutomounterKCM.cpp
Show All 35 Lines | |||||
36 | #include "AutomounterSettings.h" | 36 | #include "AutomounterSettings.h" | ||
37 | #include "LayoutSettings.h" | 37 | #include "LayoutSettings.h" | ||
38 | #include "DeviceModel.h" | 38 | #include "DeviceModel.h" | ||
39 | 39 | | |||
40 | K_PLUGIN_FACTORY(DeviceAutomounterKCMFactory, registerPlugin<DeviceAutomounterKCM>();) | 40 | K_PLUGIN_FACTORY(DeviceAutomounterKCMFactory, registerPlugin<DeviceAutomounterKCM>();) | ||
41 | 41 | | |||
42 | DeviceAutomounterKCM::DeviceAutomounterKCM(QWidget *parent, const QVariantList &args) | 42 | DeviceAutomounterKCM::DeviceAutomounterKCM(QWidget *parent, const QVariantList &args) | ||
43 | : KCModule(parent, args)//DeviceAutomounterKCMFactory::componentData(), parent) | 43 | : KCModule(parent, args)//DeviceAutomounterKCMFactory::componentData(), parent) | ||
44 | , m_devices(new DeviceModel(this)) | 44 | , m_settings(new AutomounterSettings(this)) | ||
45 | , m_devices(new DeviceModel(m_settings, this)) | ||||
ervin: please break the line before ", m_devices" | |||||
45 | { | 46 | { | ||
46 | KAboutData *about = new KAboutData(QStringLiteral("kcm_device_automounter"), | 47 | KAboutData *about = new KAboutData(QStringLiteral("kcm_device_automounter"), | ||
47 | i18n("Device Automounter"), | 48 | i18n("Device Automounter"), | ||
48 | QStringLiteral("2.0"), | 49 | QStringLiteral("2.0"), | ||
49 | QString(), | 50 | QString(), | ||
50 | KAboutLicense::GPL_V2, | 51 | KAboutLicense::GPL_V2, | ||
51 | i18n("(c) 2009 Trever Fischer, (c) 2015 Kai Uwe Broulik")); | 52 | i18n("(c) 2009 Trever Fischer, (c) 2015 Kai Uwe Broulik")); | ||
52 | about->addAuthor(i18n("Trever Fischer"), i18n("Original Author")); | 53 | about->addAuthor(i18n("Trever Fischer"), i18n("Original Author")); | ||
53 | about->addAuthor(i18n("Kai Uwe Broulik"), i18n("Plasma 5 Port"), QStringLiteral("kde@privat.broulik.de")); | 54 | about->addAuthor(i18n("Kai Uwe Broulik"), i18n("Plasma 5 Port"), QStringLiteral("kde@privat.broulik.de")); | ||
54 | 55 | | |||
55 | setAboutData(about); | 56 | setAboutData(about); | ||
56 | setupUi(this); | 57 | setupUi(this); | ||
57 | 58 | | |||
58 | addConfig(AutomounterSettings::self(), this); | 59 | addConfig(m_settings, this); | ||
59 | 60 | | |||
60 | deviceView->setModel(m_devices); | 61 | deviceView->setModel(m_devices); | ||
61 | 62 | | |||
62 | deviceView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | 63 | deviceView->header()->setSectionResizeMode(QHeaderView::ResizeToContents); | ||
63 | deviceView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | 64 | deviceView->header()->setSectionResizeMode(0, QHeaderView::Stretch); | ||
64 | 65 | | |||
65 | auto emitChanged = [this] { | 66 | auto emitChanged = [this] { | ||
66 | m_devices->setAutomaticMountOnLogin(kcfg_AutomountOnLogin->isChecked()); | 67 | m_devices->setAutomaticMountOnLogin(kcfg_AutomountOnLogin->isChecked()); | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 101 | int offset = 0; | |||
108 | 109 | | |||
109 | emit markAsChanged(); | 110 | emit markAsChanged(); | ||
110 | } | 111 | } | ||
111 | 112 | | |||
112 | void DeviceAutomounterKCM::load() | 113 | void DeviceAutomounterKCM::load() | ||
113 | { | 114 | { | ||
114 | KCModule::load(); | 115 | KCModule::load(); | ||
115 | 116 | | |||
116 | bool automountEnabled = AutomounterSettings::self()->automountEnabled(); | 117 | bool automountEnabled = m_settings->automountEnabled(); | ||
117 | 118 | | |||
118 | kcfg_AutomountUnknownDevices->setEnabled(automountEnabled); | 119 | kcfg_AutomountUnknownDevices->setEnabled(m_settings->automountEnabled()); | ||
119 | kcfg_AutomountOnLogin->setEnabled(automountEnabled); | 120 | kcfg_AutomountOnLogin->setEnabled(m_settings->automountEnabled()); | ||
120 | kcfg_AutomountOnPlugin->setEnabled(automountEnabled); | 121 | kcfg_AutomountOnPlugin->setEnabled(m_settings->automountEnabled()); | ||
121 | 122 | | |||
122 | m_devices->reload(); | 123 | m_devices->reload(); | ||
123 | loadLayout(); | 124 | loadLayout(); | ||
124 | } | 125 | } | ||
125 | 126 | | |||
126 | void DeviceAutomounterKCM::save() | 127 | void DeviceAutomounterKCM::save() | ||
127 | { | 128 | { | ||
128 | KCModule::save(); | 129 | KCModule::save(); | ||
129 | saveLayout(); | 130 | saveLayout(); | ||
130 | 131 | | |||
131 | const bool enabled = kcfg_AutomountEnabled->isChecked(); | 132 | const bool enabled = kcfg_AutomountEnabled->isChecked(); | ||
132 | 133 | | |||
133 | QStringList validDevices; | 134 | QStringList validDevices; | ||
134 | for (int i = 0; i < m_devices->rowCount(); ++i) { | 135 | for (int i = 0; i < m_devices->rowCount(); ++i) { | ||
135 | const QModelIndex &idx = m_devices->index(i, 0); | 136 | const QModelIndex &idx = m_devices->index(i, 0); | ||
136 | 137 | | |||
137 | for (int j = 0; j < m_devices->rowCount(idx); ++j) { | 138 | for (int j = 0; j < m_devices->rowCount(idx); ++j) { | ||
138 | QModelIndex dev = m_devices->index(j, 1, idx); | 139 | QModelIndex dev = m_devices->index(j, 1, idx); | ||
139 | const QString device = dev.data(DeviceModel::UdiRole).toString(); | 140 | const QString device = dev.data(DeviceModel::UdiRole).toString(); | ||
140 | validDevices << device; | 141 | validDevices << device; | ||
141 | 142 | | |||
142 | if (dev.data(Qt::CheckStateRole).toInt() == Qt::Checked) { | 143 | if (dev.data(Qt::CheckStateRole).toInt() == Qt::Checked) { | ||
143 | AutomounterSettings::deviceSettings(device).writeEntry("ForceLoginAutomount", true); | 144 | m_settings->deviceSettings(device).writeEntry("ForceLoginAutomount", true); | ||
144 | } else { | 145 | } else { | ||
145 | AutomounterSettings::deviceSettings(device).writeEntry("ForceLoginAutomount", false); | 146 | m_settings->deviceSettings(device).writeEntry("ForceLoginAutomount", false); | ||
146 | } | 147 | } | ||
147 | 148 | | |||
148 | dev = dev.sibling(j, 2); | 149 | dev = dev.sibling(j, 2); | ||
149 | 150 | | |||
150 | if (dev.data(Qt::CheckStateRole).toInt() == Qt::Checked) { | 151 | if (dev.data(Qt::CheckStateRole).toInt() == Qt::Checked) { | ||
151 | AutomounterSettings::deviceSettings(device).writeEntry("ForceAttachAutomount", true); | 152 | m_settings->deviceSettings(device).writeEntry("ForceAttachAutomount", true); | ||
152 | } else { | 153 | } else { | ||
153 | AutomounterSettings::deviceSettings(device).writeEntry("ForceAttachAutomount", false); | 154 | m_settings->deviceSettings(device).writeEntry("ForceAttachAutomount", false); | ||
154 | } | 155 | } | ||
155 | } | 156 | } | ||
156 | } | 157 | } | ||
157 | 158 | | |||
158 | const auto knownDevices = AutomounterSettings::knownDevices(); | 159 | const auto knownDevices = m_settings->knownDevices(); | ||
159 | for (const QString &possibleDevice : knownDevices) { | 160 | for (const QString &possibleDevice : knownDevices) { | ||
160 | if (!validDevices.contains(possibleDevice)) { | 161 | if (!validDevices.contains(possibleDevice)) { | ||
161 | AutomounterSettings::deviceSettings(possibleDevice).deleteGroup(); | 162 | m_settings->deviceSettings(possibleDevice).deleteGroup(); | ||
162 | } | 163 | } | ||
163 | } | 164 | } | ||
164 | 165 | | |||
165 | AutomounterSettings::self()->save(); | 166 | m_settings->save(); | ||
166 | 167 | | |||
167 | // Now tell kded to automatically load the module if loaded | 168 | // Now tell kded to automatically load the module if loaded | ||
168 | QDBusConnection dbus = QDBusConnection::sessionBus(); | 169 | QDBusConnection dbus = QDBusConnection::sessionBus(); | ||
169 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"), | 170 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kded5"), | ||
170 | QStringLiteral("/kded"), | 171 | QStringLiteral("/kded"), | ||
171 | QStringLiteral("org.kde.kded5"), | 172 | QStringLiteral("org.kde.kded5"), | ||
172 | QStringLiteral("setModuleAutoloading")); | 173 | QStringLiteral("setModuleAutoloading")); | ||
173 | msg.setArguments({QVariant(QStringLiteral("device_automounter")), QVariant(enabled)}); | 174 | msg.setArguments({QVariant(QStringLiteral("device_automounter")), QVariant(enabled)}); | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |
please break the line before ", m_devices"