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 | if (m_device.udi().isEmpty()) { | ||||
anthonyfieroni: Braces even on one line block. | |||||
91 | updateDeviceInfo(m_bookmark.metaDataItem(QStringLiteral("UDI"))); | ||||
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… | |||||
92 | } | ||||
93 | | ||||
101 | if (bookmark.metaDataItem(QStringLiteral("isSystemItem")) == QLatin1String("true")) { | 94 | if (bookmark.metaDataItem(QStringLiteral("isSystemItem")) == QLatin1String("true")) { | ||
102 | // This context must stay as it is - the translated system bookmark names | 95 | // This context must stay as it is - the translated system bookmark names | ||
103 | // are created with 'KFile System Bookmarks' as their context, so this | 96 | // are created with 'KFile System Bookmarks' as their context, so this | ||
104 | // ensures the right string is picked from the catalog. | 97 | // ensures the right string is picked from the catalog. | ||
105 | // (coles, 13th May 2009) | 98 | // (coles, 13th May 2009) | ||
106 | 99 | | |||
107 | m_text = i18nc("KFile System Bookmarks", bookmark.text().toUtf8().data()); | 100 | m_text = i18nc("KFile System Bookmarks", bookmark.text().toUtf8().data()); | ||
108 | } else { | 101 | } else { | ||
Show All 9 Lines | 110 | case RecentlySavedType: | |||
118 | m_groupName = i18nc("@item", "Recently Saved"); | 111 | m_groupName = i18nc("@item", "Recently Saved"); | ||
119 | break; | 112 | break; | ||
120 | case SearchForType: | 113 | case SearchForType: | ||
121 | m_groupName = i18nc("@item", "Search For"); | 114 | m_groupName = i18nc("@item", "Search For"); | ||
122 | break; | 115 | break; | ||
123 | case DevicesType: | 116 | case DevicesType: | ||
124 | m_groupName = i18nc("@item", "Devices"); | 117 | m_groupName = i18nc("@item", "Devices"); | ||
125 | break; | 118 | break; | ||
119 | case RemovableDeviceType: | ||||
120 | m_groupName = i18nc("@item", "Removable Devices"); | ||||
121 | break; | ||||
126 | default: | 122 | default: | ||
127 | Q_UNREACHABLE(); | 123 | Q_UNREACHABLE(); | ||
128 | break; | 124 | break; | ||
129 | } | 125 | } | ||
130 | } | 126 | } | ||
131 | 127 | | |||
132 | Solid::Device KFilePlacesItem::device() const | 128 | Solid::Device KFilePlacesItem::device() const | ||
133 | { | 129 | { | ||
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; | 130 | return m_device; | ||
149 | } | 131 | } | ||
150 | 132 | | |||
151 | QVariant KFilePlacesItem::data(int role) const | 133 | QVariant KFilePlacesItem::data(int role) const | ||
152 | { | 134 | { | ||
153 | if (role == KFilePlacesModel::GroupRole) { | 135 | if (role == KFilePlacesModel::GroupRole) { | ||
154 | return QVariant(m_groupName); | 136 | return QVariant(m_groupName); | ||
155 | } else if (role != KFilePlacesModel::HiddenRole && | 137 | } else if (role != KFilePlacesModel::HiddenRole && | ||
Show All 20 Lines | 157 | if (protocol == QLatin1String("bluetooth") || | |||
176 | protocol == QLatin1String("obexftp") || | 158 | protocol == QLatin1String("obexftp") || | ||
177 | protocol == QLatin1String("kdeconnect")) { | 159 | protocol == QLatin1String("kdeconnect")) { | ||
178 | return DevicesType; | 160 | return DevicesType; | ||
179 | } | 161 | } | ||
180 | 162 | | |||
181 | return PlacesType; | 163 | return PlacesType; | ||
182 | } | 164 | } | ||
183 | 165 | | |||
166 | if (m_drive && (m_drive->isHotpluggable() || m_drive->isRemovable())) { | ||||
167 | return RemovableDeviceType; | ||||
168 | } else { | ||||
184 | return DevicesType; | 169 | return DevicesType; | ||
185 | } | 170 | } | ||
171 | } | ||||
186 | 172 | | |||
187 | QVariant KFilePlacesItem::bookmarkData(int role) const | 173 | QVariant KFilePlacesItem::bookmarkData(int role) const | ||
188 | { | 174 | { | ||
189 | KBookmark b = bookmark(); | 175 | KBookmark b = bookmark(); | ||
190 | 176 | | |||
191 | if (b.isNull()) { | 177 | if (b.isNull()) { | ||
192 | return QVariant(); | 178 | return QVariant(); | ||
193 | } | 179 | } | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 207 | if (d.isValid()) { | |||
246 | case KFilePlacesModel::SetupNeededRole: | 232 | case KFilePlacesModel::SetupNeededRole: | ||
247 | if (m_access) { | 233 | if (m_access) { | ||
248 | return !m_isAccessible; | 234 | return !m_isAccessible; | ||
249 | } else { | 235 | } else { | ||
250 | return QVariant(); | 236 | return QVariant(); | ||
251 | } | 237 | } | ||
252 | 238 | | |||
253 | case KFilePlacesModel::FixedDeviceRole: { | 239 | case KFilePlacesModel::FixedDeviceRole: { | ||
254 | Solid::StorageDrive *drive = nullptr; | 240 | if (m_drive != nullptr) { | ||
255 | Solid::Device parentDevice = m_device; | 241 | 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 | } | 242 | } | ||
263 | return true; | 243 | return true; | ||
264 | } | 244 | } | ||
265 | 245 | | |||
266 | case KFilePlacesModel::CapacityBarRecommendedRole: | 246 | case KFilePlacesModel::CapacityBarRecommendedRole: | ||
267 | return m_isAccessible && !m_isCdrom; | 247 | return m_isAccessible && !m_isCdrom; | ||
268 | 248 | | |||
269 | default: | 249 | default: | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 318 | // return QString::number(count++); | |||
339 | 319 | | |||
340 | return QString::number(QDateTime::currentDateTimeUtc().toTime_t()) | 320 | return QString::number(QDateTime::currentDateTimeUtc().toTime_t()) | ||
341 | + '/' + QString::number(count++); | 321 | + '/' + QString::number(count++); | ||
342 | 322 | | |||
343 | // return QString::number(QDateTime::currentDateTime().toTime_t()) | 323 | // return QString::number(QDateTime::currentDateTime().toTime_t()) | ||
344 | // + '/' + QString::number(qrand()); | 324 | // + '/' + QString::number(qrand()); | ||
345 | } | 325 | } | ||
346 | 326 | | |||
327 | bool KFilePlacesItem::updateDeviceInfo(const QString &udi) | ||||
328 | { | ||||
329 | 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;
}
```` | |||||
330 | return false; | ||||
331 | } | ||||
332 | | ||||
333 | if (m_access) { | ||||
334 | m_access->disconnect(this); | ||||
335 | } | ||||
336 | | ||||
337 | m_device = Solid::Device(udi); | ||||
338 | if (m_device.isValid()) { | ||||
339 | m_access = m_device.as<Solid::StorageAccess>(); | ||||
340 | m_volume = m_device.as<Solid::StorageVolume>(); | ||||
341 | m_disc = m_device.as<Solid::OpticalDisc>(); | ||||
342 | m_mtp = m_device.as<Solid::PortableMediaPlayer>(); | ||||
343 | m_iconPath = m_device.icon(); | ||||
344 | m_emblems = m_device.emblems(); | ||||
345 | | ||||
346 | m_drive = nullptr; | ||||
347 | Solid::Device parentDevice = m_device; | ||||
348 | while (parentDevice.isValid() && !m_drive) { | ||||
349 | m_drive = parentDevice.as<Solid::StorageDrive>(); | ||||
350 | parentDevice = parentDevice.parent(); | ||||
351 | } | ||||
352 | | ||||
353 | if (m_access) { | ||||
354 | connect(m_access, SIGNAL(accessibilityChanged(bool,QString)), | ||||
mlaurent: could you use new connect api please ? | |||||
355 | this, SLOT(onAccessibilityChanged(bool))); | ||||
356 | onAccessibilityChanged(m_access->isAccessible()); | ||||
357 | } | ||||
358 | } else { | ||||
359 | m_access = nullptr; | ||||
360 | m_volume = nullptr; | ||||
361 | m_disc = nullptr; | ||||
362 | m_mtp = nullptr; | ||||
363 | m_drive = nullptr; | ||||
364 | m_iconPath.clear(); | ||||
365 | m_emblems.clear(); | ||||
366 | } | ||||
367 | | ||||
368 | return true; | ||||
369 | } | ||||
370 | | ||||
347 | void KFilePlacesItem::onAccessibilityChanged(bool isAccessible) | 371 | void KFilePlacesItem::onAccessibilityChanged(bool isAccessible) | ||
348 | { | 372 | { | ||
349 | m_isAccessible = isAccessible; | 373 | m_isAccessible = isAccessible; | ||
350 | m_isCdrom = m_device.is<Solid::OpticalDrive>() || m_device.parent().is<Solid::OpticalDrive>(); | 374 | m_isCdrom = m_device.is<Solid::OpticalDrive>() || m_device.parent().is<Solid::OpticalDrive>(); | ||
351 | m_emblems = m_device.emblems(); | 375 | m_emblems = m_device.emblems(); | ||
352 | 376 | | |||
353 | emit itemChanged(id()); | 377 | emit itemChanged(id()); | ||
354 | } | 378 | } | ||
Show All 11 Lines |
Braces even on one line block.