Changeset View
Changeset View
Standalone View
Standalone View
solid-device-automounter/kcm/DeviceModel.cpp
Show First 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | |||||
133 | void DeviceModel::reload() | 133 | void DeviceModel::reload() | ||
134 | { | 134 | { | ||
135 | beginResetModel(); | 135 | beginResetModel(); | ||
136 | m_loginForced.clear(); | 136 | m_loginForced.clear(); | ||
137 | m_attachedForced.clear(); | 137 | m_attachedForced.clear(); | ||
138 | m_attached.clear(); | 138 | m_attached.clear(); | ||
139 | m_disconnected.clear(); | 139 | m_disconnected.clear(); | ||
140 | 140 | | |||
141 | m_automaticLogin = AutomounterSettings::automountOnLogin(); | ||||
142 | m_automaticAttached = AutomounterSettings::automountOnPlugin(); | ||||
143 | | ||||
141 | foreach (const QString &dev, AutomounterSettings::knownDevices()) { | 144 | foreach (const QString &dev, AutomounterSettings::knownDevices()) { | ||
142 | addNewDevice(dev); | 145 | addNewDevice(dev); | ||
143 | } | 146 | } | ||
144 | foreach (const QString &udi, m_loginForced.keys()) { | 147 | foreach (const QString &udi, m_loginForced.keys()) { | ||
145 | m_loginForced[udi] = AutomounterSettings::deviceAutomountIsForced(udi, AutomounterSettings::Login); | 148 | m_loginForced[udi] = AutomounterSettings::deviceAutomountIsForced(udi, AutomounterSettings::Login); | ||
146 | m_attachedForced[udi] = AutomounterSettings::deviceAutomountIsForced(udi, AutomounterSettings::Attach); | 149 | m_attachedForced[udi] = AutomounterSettings::deviceAutomountIsForced(udi, AutomounterSettings::Attach); | ||
147 | } | 150 | } | ||
148 | endResetModel(); | 151 | endResetModel(); | ||
Show All 29 Lines | 180 | if (index.isValid()) { | |||
178 | if (index.internalId() == 3) | 181 | if (index.internalId() == 3) | ||
179 | return QModelIndex(); | 182 | return QModelIndex(); | ||
180 | return createIndex(index.internalId(), 0, 3); | 183 | return createIndex(index.internalId(), 0, 3); | ||
181 | } | 184 | } | ||
182 | return QModelIndex(); | 185 | return QModelIndex(); | ||
183 | } | 186 | } | ||
184 | 187 | | |||
185 | Qt::ItemFlags DeviceModel::flags(const QModelIndex &index) const | 188 | Qt::ItemFlags DeviceModel::flags(const QModelIndex &index) const | ||
186 | { | 189 | { | ||
187 | if (index.isValid()) { | 190 | if (!index.isValid()) { | ||
ervin: This logic is becoming harder to read than necessary. I think I would go for something… | |||||
188 | if (index.parent().isValid()) { | 191 | return Qt::NoItemFlags; | ||
189 | if (index.column() > 0) { | | |||
190 | return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; | | |||
191 | } else if (index.column() == 0) { | | |||
192 | return Qt::ItemIsSelectable | Qt::ItemIsEnabled; | | |||
193 | } | 192 | } | ||
193 | | ||||
194 | if (!index.parent().isValid()) { | ||||
195 | // first child section elements | ||||
196 | if (m_automaticLogin && m_automaticAttached) { | ||||
197 | return Qt::NoItemFlags; | ||||
194 | } else { | 198 | } else { | ||
195 | return Qt::ItemIsEnabled; | 199 | return Qt::ItemIsEnabled; | ||
196 | } | 200 | } | ||
197 | } | 201 | } | ||
198 | 202 | | |||
203 | switch (index.column()) { | ||||
204 | case 0: | ||||
205 | // first column | ||||
206 | if (m_automaticLogin && m_automaticAttached) { | ||||
199 | return Qt::NoItemFlags; | 207 | return Qt::NoItemFlags; | ||
208 | } else { | ||||
209 | return Qt::ItemIsEnabled; | ||||
210 | } | ||||
211 | case 1: | ||||
212 | // on login column | ||||
213 | if (m_automaticLogin) { | ||||
214 | // automount on login was checked | ||||
215 | return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; | ||||
216 | } | ||||
217 | return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; | ||||
218 | case 2: | ||||
219 | // on attached column | ||||
220 | if (m_automaticAttached) { | ||||
221 | // automount on attach was checked | ||||
222 | return Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; | ||||
223 | } | ||||
224 | return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsUserCheckable; | ||||
225 | default: | ||||
226 | Q_UNREACHABLE(); | ||||
227 | } | ||||
200 | } | 228 | } | ||
201 | 229 | | |||
202 | bool DeviceModel::setData(const QModelIndex &index, const QVariant &value, int role) | 230 | bool DeviceModel::setData(const QModelIndex &index, const QVariant &value, int role) | ||
203 | { | 231 | { | ||
204 | if (index.isValid() && role == Qt::CheckStateRole && index.column() > 0) { | 232 | if (index.isValid() && role == Qt::CheckStateRole && index.column() > 0) { | ||
205 | const QString &udi = index.data(Qt::UserRole).toString(); | 233 | const QString &udi = index.data(Qt::UserRole).toString(); | ||
206 | switch(index.column()) { | 234 | switch(index.column()) { | ||
207 | case 1: | 235 | case 1: | ||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 345 | { | |||
329 | return 2; | 357 | return 2; | ||
330 | } | 358 | } | ||
331 | 359 | | |||
332 | int DeviceModel::columnCount(const QModelIndex &parent) const | 360 | int DeviceModel::columnCount(const QModelIndex &parent) const | ||
333 | { | 361 | { | ||
334 | Q_UNUSED(parent); | 362 | Q_UNUSED(parent); | ||
335 | return 3; | 363 | return 3; | ||
336 | } | 364 | } | ||
365 | | ||||
366 | void DeviceModel::setAutomaticMountOnLogin(bool automaticLogin) | ||||
ervin: { Should be on its own line | |||||
367 | { | ||||
368 | if (m_automaticLogin != automaticLogin) { | ||||
369 | m_automaticLogin = automaticLogin; | ||||
370 | for (int parent = 0; parent < rowCount(); parent++) { | ||||
371 | const auto parentIndex = index(parent, 0); | ||||
372 | emit dataChanged(index(0, 1, parentIndex), index(rowCount(parentIndex), 1, parentIndex)); | ||||
373 | } | ||||
374 | } | ||||
375 | } | ||||
ervin: Ditto + needs an empty line before that one. | |||||
376 | | ||||
377 | void DeviceModel::setAutomaticMountOnPlugin(bool automaticAttached) | ||||
378 | { | ||||
379 | if (m_automaticAttached != automaticAttached) { | ||||
380 | m_automaticAttached = automaticAttached; | ||||
381 | for (int parent = 0; parent < rowCount(); parent++) { | ||||
382 | const auto parentIndex = index(parent, 0); | ||||
383 | emit dataChanged(index(0, 2, parentIndex), index(rowCount(parentIndex), 2, parentIndex)); | ||||
384 | } | ||||
385 | } | ||||
386 | } |
This logic is becoming harder to read than necessary. I think I would go for something structured along those lines: