Changeset View
Changeset View
Standalone View
Standalone View
src/filewidgets/kfileplacesitem.cpp
Show All 38 Lines | |||||
39 | static bool isTrash(const KBookmark &bk) { | 39 | static bool isTrash(const KBookmark &bk) { | ||
40 | return bk.url().toString() == QLatin1String("trash:/"); | 40 | return bk.url().toString() == QLatin1String("trash:/"); | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | KFilePlacesItem::KFilePlacesItem(KBookmarkManager *manager, | 43 | KFilePlacesItem::KFilePlacesItem(KBookmarkManager *manager, | ||
44 | const QString &address, | 44 | const QString &address, | ||
45 | const QString &udi) | 45 | const QString &udi) | ||
46 | : m_manager(manager), m_folderIsEmpty(true), m_isCdrom(false), | 46 | : m_manager(manager), m_folderIsEmpty(true), m_isCdrom(false), | ||
47 | m_isAccessible(false), m_device(udi) | 47 | m_isAccessible(false) | ||
48 | { | 48 | { | ||
49 | updateDeviceInfo(udi); | ||||
49 | setBookmark(m_manager->findByAddress(address)); | 50 | setBookmark(m_manager->findByAddress(address)); | ||
50 | 51 | | |||
51 | if (udi.isEmpty() && m_bookmark.metaDataItem(QStringLiteral("ID")).isEmpty()) { | 52 | if (udi.isEmpty() && m_bookmark.metaDataItem(QStringLiteral("ID")).isEmpty()) { | ||
52 | m_bookmark.setMetaDataItem(QStringLiteral("ID"), generateNewId()); | 53 | m_bookmark.setMetaDataItem(QStringLiteral("ID"), generateNewId()); | ||
53 | } else if (udi.isEmpty()) { | 54 | } else if (udi.isEmpty()) { | ||
54 | if (isTrash(m_bookmark)) { | 55 | if (isTrash(m_bookmark)) { | ||
55 | KConfig cfg(QStringLiteral("trashrc"), KConfig::SimpleConfig); | 56 | KConfig cfg(QStringLiteral("trashrc"), KConfig::SimpleConfig); | ||
56 | const KConfigGroup group = cfg.group("Status"); | 57 | const KConfigGroup group = cfg.group("Status"); | ||
57 | m_folderIsEmpty = group.readEntry("Empty", true); | 58 | m_folderIsEmpty = group.readEntry("Empty", true); | ||
58 | } | 59 | } | ||
59 | } else if (!udi.isEmpty() && m_device.isValid()) { | | |||
60 | m_access = m_device.as<Solid::StorageAccess>(); | | |||
61 | m_volume = m_device.as<Solid::StorageVolume>(); | | |||
62 | m_disc = m_device.as<Solid::OpticalDisc>(); | | |||
63 | m_mtp = m_device.as<Solid::PortableMediaPlayer>(); | | |||
64 | if (m_access) { | | |||
65 | connect(m_access, SIGNAL(accessibilityChanged(bool,QString)), | | |||
66 | this, SLOT(onAccessibilityChanged(bool))); | | |||
67 | onAccessibilityChanged(m_access->isAccessible()); | | |||
68 | } | | |||
69 | m_iconPath = m_device.icon(); | | |||
70 | m_emblems = m_device.emblems(); | | |||
71 | } | 60 | } | ||
72 | } | 61 | } | ||
73 | 62 | | |||
74 | KFilePlacesItem::~KFilePlacesItem() | 63 | KFilePlacesItem::~KFilePlacesItem() | ||
75 | { | 64 | { | ||
76 | } | 65 | } | ||
77 | 66 | | |||
78 | QString KFilePlacesItem::id() const | 67 | QString KFilePlacesItem::id() const | ||
Show All 14 Lines | |||||
93 | { | 82 | { | ||
94 | return m_bookmark; | 83 | return m_bookmark; | ||
95 | } | 84 | } | ||
96 | 85 | | |||
97 | void KFilePlacesItem::setBookmark(const KBookmark &bookmark) | 86 | void KFilePlacesItem::setBookmark(const KBookmark &bookmark) | ||
98 | { | 87 | { | ||
99 | m_bookmark = bookmark; | 88 | m_bookmark = bookmark; | ||
100 | 89 | | |||
90 | updateDeviceInfo(m_bookmark.metaDataItem(QStringLiteral("UDI"))); | ||||
anthonyfieroni: Braces even on one line block. | |||||
91 | | ||||
shouldn't this always be called? i.e. when the bookmark is changed to a different UDI, don't we need to update here, even when we had a valid device UDI before? I think this also means this path isn't unit tested yet mwolff: shouldn't this always be called? i.e. when the bookmark is changed to a different UDI, don't we… | |||||
Changed the code to always check for udi changes. renatoo: Changed the code to always check for udi changes.
I tried to implement a unit test for this… | |||||
101 | if (bookmark.metaDataItem(QStringLiteral("isSystemItem")) == QLatin1String("true")) { | 92 | if (bookmark.metaDataItem(QStringLiteral("isSystemItem")) == QLatin1String("true")) { | ||
102 | // This context must stay as it is - the translated system bookmark names | 93 | // This context must stay as it is - the translated system bookmark names | ||
103 | // are created with 'KFile System Bookmarks' as their context, so this | 94 | // are created with 'KFile System Bookmarks' as their context, so this | ||
104 | // ensures the right string is picked from the catalog. | 95 | // ensures the right string is picked from the catalog. | ||
105 | // (coles, 13th May 2009) | 96 | // (coles, 13th May 2009) | ||
106 | 97 | | |||
107 | m_text = i18nc("KFile System Bookmarks", bookmark.text().toUtf8().data()); | 98 | m_text = i18nc("KFile System Bookmarks", bookmark.text().toUtf8().data()); | ||
108 | } else { | 99 | } else { | ||
Show All 9 Lines | 108 | case RecentlySavedType: | |||
118 | m_groupName = i18nc("@item", "Recently Saved"); | 109 | m_groupName = i18nc("@item", "Recently Saved"); | ||
119 | break; | 110 | break; | ||
120 | case SearchForType: | 111 | case SearchForType: | ||
121 | m_groupName = i18nc("@item", "Search For"); | 112 | m_groupName = i18nc("@item", "Search For"); | ||
122 | break; | 113 | break; | ||
123 | case DevicesType: | 114 | case DevicesType: | ||
124 | m_groupName = i18nc("@item", "Devices"); | 115 | m_groupName = i18nc("@item", "Devices"); | ||
125 | break; | 116 | break; | ||
117 | case RemovableDevicesType: | ||||
118 | m_groupName = i18nc("@item", "Removable Devices"); | ||||
119 | break; | ||||
126 | default: | 120 | default: | ||
127 | Q_UNREACHABLE(); | 121 | Q_UNREACHABLE(); | ||
128 | break; | 122 | break; | ||
129 | } | 123 | } | ||
130 | } | 124 | } | ||
131 | 125 | | |||
132 | Solid::Device KFilePlacesItem::device() const | 126 | Solid::Device KFilePlacesItem::device() const | ||
133 | { | 127 | { | ||
134 | if (m_device.udi().isEmpty()) { | | |||
135 | m_device = Solid::Device(bookmark().metaDataItem(QStringLiteral("UDI"))); | | |||
136 | if (m_device.isValid()) { | | |||
137 | m_access = m_device.as<Solid::StorageAccess>(); | | |||
138 | m_volume = m_device.as<Solid::StorageVolume>(); | | |||
139 | m_disc = m_device.as<Solid::OpticalDisc>(); | | |||
140 | m_mtp = m_device.as<Solid::PortableMediaPlayer>(); | | |||
141 | } else { | | |||
142 | m_access = nullptr; | | |||
143 | m_volume = nullptr; | | |||
144 | m_disc = nullptr; | | |||
145 | m_mtp = nullptr; | | |||
146 | } | | |||
147 | } | | |||
148 | return m_device; | 128 | return m_device; | ||
149 | } | 129 | } | ||
150 | 130 | | |||
151 | QVariant KFilePlacesItem::data(int role) const | 131 | QVariant KFilePlacesItem::data(int role) const | ||
152 | { | 132 | { | ||
153 | if (role == KFilePlacesModel::GroupRole) { | 133 | if (role == KFilePlacesModel::GroupRole) { | ||
154 | return QVariant(m_groupName); | 134 | return QVariant(m_groupName); | ||
155 | } else if (role != KFilePlacesModel::HiddenRole && | 135 | } else if (role != KFilePlacesModel::HiddenRole && | ||
Show All 20 Lines | 155 | if (protocol == QLatin1String("bluetooth") || | |||
176 | protocol == QLatin1String("obexftp") || | 156 | protocol == QLatin1String("obexftp") || | ||
177 | protocol == QLatin1String("kdeconnect")) { | 157 | protocol == QLatin1String("kdeconnect")) { | ||
178 | return DevicesType; | 158 | return DevicesType; | ||
179 | } | 159 | } | ||
180 | 160 | | |||
181 | return PlacesType; | 161 | return PlacesType; | ||
182 | } | 162 | } | ||
183 | 163 | | |||
164 | if (m_drive && (m_drive->isHotpluggable() || m_drive->isRemovable())) { | ||||
165 | return RemovableDevicesType; | ||||
166 | } else { | ||||
184 | return DevicesType; | 167 | return DevicesType; | ||
185 | } | 168 | } | ||
169 | } | ||||
186 | 170 | | |||
187 | QVariant KFilePlacesItem::bookmarkData(int role) const | 171 | QVariant KFilePlacesItem::bookmarkData(int role) const | ||
188 | { | 172 | { | ||
189 | KBookmark b = bookmark(); | 173 | KBookmark b = bookmark(); | ||
190 | 174 | | |||
191 | if (b.isNull()) { | 175 | if (b.isNull()) { | ||
192 | return QVariant(); | 176 | return QVariant(); | ||
193 | } | 177 | } | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 205 | if (d.isValid()) { | |||
246 | case KFilePlacesModel::SetupNeededRole: | 230 | case KFilePlacesModel::SetupNeededRole: | ||
247 | if (m_access) { | 231 | if (m_access) { | ||
248 | return !m_isAccessible; | 232 | return !m_isAccessible; | ||
249 | } else { | 233 | } else { | ||
250 | return QVariant(); | 234 | return QVariant(); | ||
251 | } | 235 | } | ||
252 | 236 | | |||
253 | case KFilePlacesModel::FixedDeviceRole: { | 237 | case KFilePlacesModel::FixedDeviceRole: { | ||
254 | Solid::StorageDrive *drive = nullptr; | 238 | if (m_drive != nullptr) { | ||
255 | Solid::Device parentDevice = m_device; | 239 | return !m_drive->isHotpluggable() && !m_drive->isRemovable(); | ||
256 | while (parentDevice.isValid() && !drive) { | | |||
257 | drive = parentDevice.as<Solid::StorageDrive>(); | | |||
258 | parentDevice = parentDevice.parent(); | | |||
259 | } | | |||
260 | if (drive != nullptr) { | | |||
261 | return !drive->isHotpluggable() && !drive->isRemovable(); | | |||
262 | } | 240 | } | ||
263 | return true; | 241 | return true; | ||
264 | } | 242 | } | ||
265 | 243 | | |||
266 | case KFilePlacesModel::CapacityBarRecommendedRole: | 244 | case KFilePlacesModel::CapacityBarRecommendedRole: | ||
267 | return m_isAccessible && !m_isCdrom; | 245 | return m_isAccessible && !m_isCdrom; | ||
268 | 246 | | |||
269 | default: | 247 | default: | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 316 | // return QString::number(count++); | |||
339 | 317 | | |||
340 | return QString::number(QDateTime::currentDateTimeUtc().toTime_t()) | 318 | return QString::number(QDateTime::currentDateTimeUtc().toTime_t()) | ||
341 | + '/' + QString::number(count++); | 319 | + '/' + QString::number(count++); | ||
342 | 320 | | |||
343 | // return QString::number(QDateTime::currentDateTime().toTime_t()) | 321 | // return QString::number(QDateTime::currentDateTime().toTime_t()) | ||
344 | // + '/' + QString::number(qrand()); | 322 | // + '/' + QString::number(qrand()); | ||
345 | } | 323 | } | ||
346 | 324 | | |||
325 | bool KFilePlacesItem::updateDeviceInfo(const QString &udi) | ||||
326 | { | ||||
327 | if (m_device.udi() == udi) { | ||||
Early exit to not add unwanted indent. if (m_device.udi() == udi) { return false; } ` anthonyfieroni: Early exit to not add unwanted indent.
```
if (m_device.udi() == udi) {
return false;
}
```` | |||||
328 | return false; | ||||
329 | } | ||||
330 | | ||||
331 | if (m_access) { | ||||
332 | m_access->disconnect(this); | ||||
333 | } | ||||
334 | | ||||
335 | m_device = Solid::Device(udi); | ||||
336 | if (m_device.isValid()) { | ||||
337 | m_access = m_device.as<Solid::StorageAccess>(); | ||||
338 | m_volume = m_device.as<Solid::StorageVolume>(); | ||||
339 | m_disc = m_device.as<Solid::OpticalDisc>(); | ||||
340 | m_mtp = m_device.as<Solid::PortableMediaPlayer>(); | ||||
341 | m_iconPath = m_device.icon(); | ||||
342 | m_emblems = m_device.emblems(); | ||||
343 | | ||||
344 | m_drive = nullptr; | ||||
345 | Solid::Device parentDevice = m_device; | ||||
346 | while (parentDevice.isValid() && !m_drive) { | ||||
347 | m_drive = parentDevice.as<Solid::StorageDrive>(); | ||||
348 | parentDevice = parentDevice.parent(); | ||||
349 | } | ||||
350 | | ||||
351 | if (m_access) { | ||||
352 | connect(m_access, &Solid::StorageAccess::accessibilityChanged, | ||||
mlaurent: could you use new connect api please ? | |||||
353 | this, &KFilePlacesItem::onAccessibilityChanged); | ||||
354 | onAccessibilityChanged(m_access->isAccessible()); | ||||
355 | } | ||||
356 | } else { | ||||
357 | m_access = nullptr; | ||||
358 | m_volume = nullptr; | ||||
359 | m_disc = nullptr; | ||||
360 | m_mtp = nullptr; | ||||
361 | m_drive = nullptr; | ||||
362 | m_iconPath.clear(); | ||||
363 | m_emblems.clear(); | ||||
364 | } | ||||
365 | | ||||
366 | return true; | ||||
367 | } | ||||
368 | | ||||
347 | void KFilePlacesItem::onAccessibilityChanged(bool isAccessible) | 369 | void KFilePlacesItem::onAccessibilityChanged(bool isAccessible) | ||
348 | { | 370 | { | ||
349 | m_isAccessible = isAccessible; | 371 | m_isAccessible = isAccessible; | ||
350 | m_isCdrom = m_device.is<Solid::OpticalDrive>() || m_device.parent().is<Solid::OpticalDrive>(); | 372 | m_isCdrom = m_device.is<Solid::OpticalDrive>() || m_device.parent().is<Solid::OpticalDrive>(); | ||
351 | m_emblems = m_device.emblems(); | 373 | m_emblems = m_device.emblems(); | ||
352 | 374 | | |||
353 | emit itemChanged(id()); | 375 | emit itemChanged(id()); | ||
354 | } | 376 | } | ||
Show All 11 Lines |
Braces even on one line block.