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