Changeset View
Changeset View
Standalone View
Standalone View
src/panels/places/placesitemmodel.cpp
Show All 30 Lines | |||||
31 | #include "views/dolphinview.h" | 31 | #include "views/dolphinview.h" | ||
32 | #include "views/viewproperties.h" | 32 | #include "views/viewproperties.h" | ||
33 | 33 | | |||
34 | #include <KAboutData> | 34 | #include <KAboutData> | ||
35 | #include <KLocalizedString> | 35 | #include <KLocalizedString> | ||
36 | #include <KUrlMimeData> | 36 | #include <KUrlMimeData> | ||
37 | #include <Solid/DeviceNotifier> | 37 | #include <Solid/DeviceNotifier> | ||
38 | #include <Solid/OpticalDrive> | 38 | #include <Solid/OpticalDrive> | ||
39 | #include <Solid/Block> | ||||
39 | 40 | | |||
40 | #include <QAction> | 41 | #include <QAction> | ||
41 | #include <QIcon> | 42 | #include <QIcon> | ||
42 | #include <QMimeData> | 43 | #include <QMimeData> | ||
43 | #include <QTimer> | 44 | #include <QTimer> | ||
44 | 45 | | |||
46 | #include <QInputDialog> | ||||
47 | #include <QDBusMessage> | ||||
48 | #include <QDBusConnection> | ||||
49 | #include <QDBusPendingReply> | ||||
50 | #include <QDBusPendingCallWatcher> | ||||
51 | | ||||
45 | namespace { | 52 | namespace { | ||
46 | static QList<QUrl> balooURLs = { | 53 | static QList<QUrl> balooURLs = { | ||
47 | QUrl(QStringLiteral("timeline:/today")), | 54 | QUrl(QStringLiteral("timeline:/today")), | ||
48 | QUrl(QStringLiteral("timeline:/yesterday")), | 55 | QUrl(QStringLiteral("timeline:/yesterday")), | ||
49 | QUrl(QStringLiteral("timeline:/thismonth")), | 56 | QUrl(QStringLiteral("timeline:/thismonth")), | ||
50 | QUrl(QStringLiteral("timeline:/lastmonth")), | 57 | QUrl(QStringLiteral("timeline:/lastmonth")), | ||
51 | QUrl(QStringLiteral("search:/documents")), | 58 | QUrl(QStringLiteral("search:/documents")), | ||
52 | QUrl(QStringLiteral("search:/images")), | 59 | QUrl(QStringLiteral("search:/images")), | ||
▲ Show 20 Lines • Show All 191 Lines • ▼ Show 20 Line(s) | 215 | { | |||
244 | 251 | | |||
245 | if (iconName.isEmpty()) { | 252 | if (iconName.isEmpty()) { | ||
246 | return new QAction(text, nullptr); | 253 | return new QAction(text, nullptr); | ||
247 | } | 254 | } | ||
248 | 255 | | |||
249 | return new QAction(QIcon::fromTheme(iconName), text, nullptr); | 256 | return new QAction(QIcon::fromTheme(iconName), text, nullptr); | ||
250 | } | 257 | } | ||
251 | 258 | | |||
259 | QAction* PlacesItemModel::changeLabelAction(int index) const | ||||
260 | { | ||||
261 | const PlacesItem* item = placesItem(index); | ||||
262 | if (item && item->device().is<Solid::StorageVolume>() && item->device().as<Solid::StorageVolume>()->usage() == Solid::StorageVolume::FileSystem) { | ||||
263 | return new QAction(QIcon::fromTheme(QStringLiteral("edit-entry")), i18nc("@item", "Change Label"), nullptr); | ||||
264 | } | ||||
265 | | ||||
266 | return nullptr; | ||||
267 | } | ||||
268 | | ||||
252 | void PlacesItemModel::requestEject(int index) | 269 | void PlacesItemModel::requestEject(int index) | ||
253 | { | 270 | { | ||
254 | const PlacesItem* item = placesItem(index); | 271 | const PlacesItem* item = placesItem(index); | ||
255 | if (item) { | 272 | if (item) { | ||
256 | Solid::OpticalDrive* drive = item->device().parent().as<Solid::OpticalDrive>(); | 273 | Solid::OpticalDrive* drive = item->device().parent().as<Solid::OpticalDrive>(); | ||
257 | if (drive) { | 274 | if (drive) { | ||
258 | connect(drive, &Solid::OpticalDrive::ejectDone, | 275 | connect(drive, &Solid::OpticalDrive::ejectDone, | ||
259 | this, &PlacesItemModel::slotStorageTearDownDone); | 276 | this, &PlacesItemModel::slotStorageTearDownDone); | ||
Show All 18 Lines | 291 | if (tmp) { | |||
278 | // after we have emitted PlacesItemModel::storageTearDownRequested | 295 | // after we have emitted PlacesItemModel::storageTearDownRequested | ||
279 | disconnect(tmp, &Solid::StorageAccess::teardownRequested, | 296 | disconnect(tmp, &Solid::StorageAccess::teardownRequested, | ||
280 | item->signalHandler(), &PlacesItemSignalHandler::onTearDownRequested); | 297 | item->signalHandler(), &PlacesItemSignalHandler::onTearDownRequested); | ||
281 | emit storageTearDownRequested(tmp->filePath()); | 298 | emit storageTearDownRequested(tmp->filePath()); | ||
282 | } | 299 | } | ||
283 | } | 300 | } | ||
284 | } | 301 | } | ||
285 | 302 | | |||
303 | void PlacesItemModel::requestChangeLabel(int index) | ||||
304 | { | ||||
305 | PlacesItem* item = placesItem(index); | ||||
306 | if (item) { | ||||
307 | Solid::Block *blk = item->device().as<Solid::Block>(); | ||||
308 | if (blk) { | ||||
309 | bool ok; | ||||
310 | const QString oldLabel = item->text(); | ||||
311 | const QString newLabel = QInputDialog::getText(nullptr, i18n("Enter filesystem label"), | ||||
312 | i18n("Label:"), QLineEdit::Normal, | ||||
313 | oldLabel, &ok); | ||||
314 | | ||||
315 | if (newLabel == oldLabel || !ok || newLabel.isEmpty()) { | ||||
316 | return; | ||||
317 | } | ||||
318 | | ||||
319 | const QString devFile = blk->device().split('/').last(); | ||||
320 | QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.UDisks2"), | ||||
321 | QStringLiteral("/org/freedesktop/UDisks2/block_devices/%1").arg(devFile), | ||||
322 | QStringLiteral("org.freedesktop.UDisks2.Filesystem"), | ||||
323 | QStringLiteral("SetLabel")); | ||||
324 | QVariantList argList; | ||||
325 | argList << newLabel << QVariantMap(); | ||||
326 | msg.setArguments(argList); | ||||
327 | QDBusPendingCall async = QDBusConnection::systemBus().asyncCall(msg); | ||||
328 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(async, this); | ||||
329 | connect(watcher, &QDBusPendingCallWatcher::finished, | ||||
330 | this, [this, item, oldLabel, newLabel](QDBusPendingCallWatcher* watcher) { | ||||
331 | if (!(*watcher).isError()) { | ||||
332 | item->setText(newLabel); | ||||
333 | refresh(); | ||||
334 | } else { | ||||
335 | emit errorMessage(i18nc("@info", "An error occurred while renaming '%1' to '%2', the system responded: %3", | ||||
336 | oldLabel, newLabel, | ||||
337 | (*watcher).error().message())); | ||||
338 | } | ||||
339 | watcher->deleteLater(); | ||||
340 | }); | ||||
341 | } | ||||
342 | } | ||||
343 | } | ||||
344 | | ||||
286 | bool PlacesItemModel::storageSetupNeeded(int index) const | 345 | bool PlacesItemModel::storageSetupNeeded(int index) const | ||
287 | { | 346 | { | ||
288 | const PlacesItem* item = placesItem(index); | 347 | const PlacesItem* item = placesItem(index); | ||
289 | return item ? item->storageSetupNeeded() : false; | 348 | return item ? item->storageSetupNeeded() : false; | ||
290 | } | 349 | } | ||
291 | 350 | | |||
292 | void PlacesItemModel::requestStorageSetup(int index) | 351 | void PlacesItemModel::requestStorageSetup(int index) | ||
293 | { | 352 | { | ||
▲ Show 20 Lines • Show All 480 Lines • Show Last 20 Lines |