X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/5593c252e8d9638c86dcc2bb9edd394ea14f8ba1..bd47eb2e6d:/src/panels/places/placesitemmodel.cpp diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index a42cb0403..abd6bc925 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -22,6 +22,7 @@ ***************************************************************************/ #include "placesitemmodel.h" +#include "placesitemsignalhandler.h" #include "dolphin_generalsettings.h" @@ -32,7 +33,6 @@ #include #include #include -#include #include #include "placesitem.h" #include @@ -78,6 +78,7 @@ PlacesItemModel::PlacesItemModel(QObject* parent) : m_systemBookmarksIndexes(), m_bookmarkedItems(), m_hiddenItemToRemove(-1), + m_deviceToTearDown(0), m_updateBookmarksTimer(0), m_storageSetupInProgress() { @@ -249,7 +250,7 @@ QAction* PlacesItemModel::ejectAction(int index) const { const PlacesItem* item = placesItem(index); if (item && item->device().is()) { - return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject '%1'", item->text()), 0); + return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject"), 0); } return 0; @@ -283,14 +284,13 @@ QAction* PlacesItemModel::teardownAction(int index) const QString iconName; QString text; - const QString label = item->text(); if (device.is()) { - text = i18nc("@item", "Release '%1'", label); + text = i18nc("@item", "Release"); } else if (removable || hotPluggable) { - text = i18nc("@item", "Safely Remove '%1'", label); + text = i18nc("@item", "Safely Remove"); iconName = QStringLiteral("media-eject"); } else { - text = i18nc("@item", "Unmount '%1'", label); + text = i18nc("@item", "Unmount"); iconName = QStringLiteral("media-eject"); } @@ -308,7 +308,7 @@ void PlacesItemModel::requestEject(int index) Solid::OpticalDrive* drive = item->device().parent().as(); if (drive) { connect(drive, &Solid::OpticalDrive::ejectDone, - this, &PlacesItemModel::slotStorageTeardownDone); + this, &PlacesItemModel::slotStorageTearDownDone); drive->eject(); } else { const QString label = item->text(); @@ -318,15 +318,19 @@ void PlacesItemModel::requestEject(int index) } } -void PlacesItemModel::requestTeardown(int index) +void PlacesItemModel::requestTearDown(int index) { const PlacesItem* item = placesItem(index); if (item) { - Solid::StorageAccess* access = item->device().as(); - if (access) { - connect(access, &Solid::StorageAccess::teardownDone, - this, &PlacesItemModel::slotStorageTeardownDone); - access->teardown(); + Solid::StorageAccess *tmp = item->device().as(); + if (tmp) { + m_deviceToTearDown = tmp; + // disconnect the Solid::StorageAccess::teardownRequested + // to prevent emitting PlacesItemModel::storageTearDownExternallyRequested + // after we have emitted PlacesItemModel::storageTearDownRequested + disconnect(tmp, &Solid::StorageAccess::teardownRequested, + item->signalHandler(), &PlacesItemSignalHandler::onTearDownRequested); + emit storageTearDownRequested(tmp->filePath()); } } } @@ -378,6 +382,9 @@ QMimeData* PlacesItemModel::createMimeData(const KItemSet& indexes) const QMimeData* mimeData = new QMimeData(); if (!urls.isEmpty()) { mimeData->setUrls(urls); + } else { + // #378954: prevent itemDropEvent() drops if there isn't a source url. + mimeData->setData(blacklistItemDropEventMimeType(), QByteArrayLiteral("true")); } mimeData->setData(internalMimeType(), itemData); @@ -549,7 +556,11 @@ void PlacesItemModel::slotDeviceAdded(const QString& udi) m_availableDevices << udi; const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); - appendItem(new PlacesItem(bookmark)); + + PlacesItem *item = new PlacesItem(bookmark); + appendItem(item); + connect(item->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested, + this, &PlacesItemModel::storageTearDownExternallyRequested); } void PlacesItemModel::slotDeviceRemoved(const QString& udi) @@ -575,11 +586,13 @@ void PlacesItemModel::slotDeviceRemoved(const QString& udi) } } -void PlacesItemModel::slotStorageTeardownDone(Solid::ErrorType error, const QVariant& errorData) +void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error, const QVariant& errorData) { if (error && errorData.isValid()) { emit errorMessage(errorData.toString()); } + m_deviceToTearDown->disconnect(); + m_deviceToTearDown = nullptr; } void PlacesItemModel::slotStorageSetupDone(Solid::ErrorType error, @@ -785,7 +798,10 @@ void PlacesItemModel::loadBookmarks() devicesItems.reserve(devicesItems.count() + devices.count()); foreach (const QString& udi, devices) { const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); - devicesItems.append(new PlacesItem(bookmark)); + PlacesItem *item = new PlacesItem(bookmark); + devicesItems.append(item); + connect(item->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested, + this, &PlacesItemModel::storageTearDownExternallyRequested); } QList items; @@ -872,7 +888,7 @@ PlacesItem* PlacesItemModel::createSystemPlacesItem(const SystemBookmarkData& da props.setVisibleRoles({"text"}); } else if (data.url.scheme() == QLatin1String("timeline")) { props.setViewMode(DolphinView::DetailsView); - props.setVisibleRoles({"text", "date"}); + props.setVisibleRoles({"text", "modificationtime"}); } } } @@ -889,7 +905,7 @@ void PlacesItemModel::createSystemBookmarks() // i18nc call is done after reading the bookmark. The reason why the i18nc call is not // done here is because otherwise switching the language would not result in retranslating the // bookmarks. - m_systemBookmarks.append(SystemBookmarkData(QUrl::fromLocalFile(KUser().homeDir()), + m_systemBookmarks.append(SystemBookmarkData(QUrl::fromLocalFile(QDir::homePath()), QStringLiteral("user-home"), I18N_NOOP2("KFile System Bookmarks", "Home"))); m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("remote:/")), @@ -939,6 +955,15 @@ void PlacesItemModel::clear() { KStandardItemModel::clear(); } +void PlacesItemModel::proceedWithTearDown() +{ + Q_ASSERT(m_deviceToTearDown); + + connect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone, + this, &PlacesItemModel::slotStorageTearDownDone); + m_deviceToTearDown->teardown(); +} + void PlacesItemModel::initializeAvailableDevices() { QString predicate(QStringLiteral("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]" @@ -1099,17 +1124,17 @@ QUrl PlacesItemModel::createTimelineUrl(const QUrl& url) const int year = date.year(); const int month = date.month(); const int day = date.day(); - timelineUrl = "timeline:/" + timelineDateString(year, month) + - '/' + timelineDateString(year, month, day); + timelineUrl = QUrl("timeline:/" + timelineDateString(year, month) + + '/' + timelineDateString(year, month, day)); } else if (path.endsWith(QLatin1String("thismonth"))) { const QDate date = QDate::currentDate(); - timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month()); + timelineUrl = QUrl("timeline:/" + timelineDateString(date.year(), date.month())); } else if (path.endsWith(QLatin1String("lastmonth"))) { const QDate date = QDate::currentDate().addMonths(-1); - timelineUrl = "timeline:/" + timelineDateString(date.year(), date.month()); + timelineUrl = QUrl("timeline:/" + timelineDateString(date.year(), date.month())); } else { Q_ASSERT(path.endsWith(QLatin1String("today"))); - timelineUrl= url; + timelineUrl = url; } return timelineUrl;