]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/places/placesitemmodel.cpp
Remove unnecessary semicolons after Q_UNUSED
[dolphin.git] / src / panels / places / placesitemmodel.cpp
index f7fe5587c7fa3cd2c5ce855982aad8e93fe83925..9dbfe7f91efd1cb61dae863ccead4c32cd04b89a 100644 (file)
 #include <KUrlMimeData>
 #include <Solid/DeviceNotifier>
 #include <Solid/OpticalDrive>
+#include <KCoreAddons/KProcessList>
+#include <KCoreAddons/KListOpenFilesJob>
 
 #include <QAction>
 #include <QIcon>
 #include <QMimeData>
 #include <QTimer>
 
-namespace {
-    static QList<QUrl> balooURLs = {
-        QUrl(QStringLiteral("timeline:/today")),
-        QUrl(QStringLiteral("timeline:/yesterday")),
-        QUrl(QStringLiteral("timeline:/thismonth")),
-        QUrl(QStringLiteral("timeline:/lastmonth")),
-        QUrl(QStringLiteral("search:/documents")),
-        QUrl(QStringLiteral("search:/images")),
-        QUrl(QStringLiteral("search:/audio")),
-        QUrl(QStringLiteral("search:/videos"))
-    };
-}
-
 PlacesItemModel::PlacesItemModel(QObject* parent) :
     KStandardItemModel(parent),
     m_hiddenItemsShown(false),
@@ -78,12 +67,14 @@ PlacesItemModel::~PlacesItemModel()
 {
 }
 
-void PlacesItemModel::createPlacesItem(const QString& text,
-                                       const QUrl& url,
-                                       const QString& iconName,
-                                       int after)
+void PlacesItemModel::createPlacesItem(const QString &text, const QUrl &url, const QString &iconName, const QString &appName)
 {
-    m_sourceModel->addPlace(text, url, iconName, {}, mapToSource(after));
+    createPlacesItem(text, url, iconName, appName, -1);
+}
+
+void PlacesItemModel::createPlacesItem(const QString &text, const QUrl &url, const QString &iconName, const QString &appName, int after)
+{
+    m_sourceModel->addPlace(text, url, iconName, appName, mapToSource(after));
 }
 
 PlacesItem* PlacesItemModel::placesItem(int index) const
@@ -351,7 +342,10 @@ void PlacesItemModel::dropMimeDataBefore(int index, const QMimeData* mimeData)
         int oldIndex;
         stream >> oldIndex;
 
-        m_sourceModel->movePlace(oldIndex, index);
+        QModelIndex sourceIndex = mapToSource(index);
+        QModelIndex oldSourceIndex = mapToSource(oldIndex);
+
+        m_sourceModel->movePlace(oldSourceIndex.row(), sourceIndex.row());
     } else if (mimeData->hasFormat(QStringLiteral("text/uri-list"))) {
         // One or more items must be added to the model
         const QList<QUrl> urls = KUrlMimeData::urlsFromMimeData(mimeData);
@@ -369,7 +363,7 @@ void PlacesItemModel::dropMimeDataBefore(int index, const QMimeData* mimeData)
                 continue;
             }
 
-            createPlacesItem(text, url, KIO::iconNameForUrl(url), qMax(0, index - 1));
+            createPlacesItem(text, url, KIO::iconNameForUrl(url), {}, qMax(0, index - 1));
         }
     }
     // will save bookmark alteration and fix sort if that is broken by the drag/drop operation
@@ -469,9 +463,32 @@ void PlacesItemModel::updateItem(PlacesItem *item, const QModelIndex &index)
 void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error, const QVariant& errorData)
 {
     if (error && errorData.isValid()) {
-        emit errorMessage(errorData.toString());
+        if (error == Solid::ErrorType::DeviceBusy) {
+            KListOpenFilesJob* listOpenFilesJob = new KListOpenFilesJob(m_deviceToTearDown->filePath());
+            connect(listOpenFilesJob, &KIO::Job::result, this, [this, listOpenFilesJob](KJob*) {
+                const KProcessList::KProcessInfoList blockingProcesses = listOpenFilesJob->processInfoList();
+                QString errorString;
+                if (blockingProcesses.isEmpty()) {
+                    errorString = i18n("One or more files on this device are open within an application.");
+                } else {
+                    QStringList blockingApps;
+                    for (const auto& process : blockingProcesses) {
+                        blockingApps << process.name();
+                    }
+                    blockingApps.removeDuplicates();
+                    errorString = xi18np("One or more files on this device are opened in application <application>\"%2\"</application>.",
+                            "One or more files on this device are opened in following applications: <application>%2</application>.",
+                            blockingApps.count(), blockingApps.join(i18nc("separator in list of apps blocking device unmount", ", ")));
+                }
+                emit errorMessage(errorString);
+            });
+            listOpenFilesJob->start();
+        } else {
+            emit errorMessage(errorData.toString());
+        }
     }
-    m_deviceToTearDown->disconnect();
+    disconnect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone,
+               this, &PlacesItemModel::slotStorageTearDownDone);
     m_deviceToTearDown = nullptr;
 }
 
@@ -479,7 +496,7 @@ void PlacesItemModel::slotStorageSetupDone(Solid::ErrorType error,
                                            const QVariant& errorData,
                                            const QString& udi)
 {
-    Q_UNUSED(udi);
+    Q_UNUSED(udi)
 
     const int index = m_storageSetupInProgress.take(sender());
     const PlacesItem*  item = placesItem(index);
@@ -523,8 +540,8 @@ void PlacesItemModel::onSourceModelRowsAboutToBeRemoved(const QModelIndex &paren
 
 void PlacesItemModel::onSourceModelRowsAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 {
-    Q_UNUSED(destination);
-    Q_UNUSED(row);
+    Q_UNUSED(destination)
+    Q_UNUSED(row)
 
     for(int r = start; r <= end; r++) {
         const QModelIndex sourceIndex = m_sourceModel->index(r, 0, parent);
@@ -535,8 +552,8 @@ void PlacesItemModel::onSourceModelRowsAboutToBeMoved(const QModelIndex &parent,
 
 void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row)
 {
-    Q_UNUSED(destination);
-    Q_UNUSED(parent);
+    Q_UNUSED(destination)
+    Q_UNUSED(parent)
 
     const int blockSize = (end - start) + 1;
 
@@ -551,7 +568,7 @@ void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex &parent, int star
 
 void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
 {
-    Q_UNUSED(roles);
+    Q_UNUSED(roles)
 
     for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
         const QModelIndex sourceIndex = m_sourceModel->index(r, 0);
@@ -597,6 +614,18 @@ void PlacesItemModel::cleanupBookmarks()
 {
     // KIO model now provides support for baloo urls, and because of that we
     // need to remove old URLs that were visible only in Dolphin to avoid duplication
+
+    static const QVector<QUrl> balooURLs = {
+        QUrl(QStringLiteral("timeline:/today")),
+        QUrl(QStringLiteral("timeline:/yesterday")),
+        QUrl(QStringLiteral("timeline:/thismonth")),
+        QUrl(QStringLiteral("timeline:/lastmonth")),
+        QUrl(QStringLiteral("search:/documents")),
+        QUrl(QStringLiteral("search:/images")),
+        QUrl(QStringLiteral("search:/audio")),
+        QUrl(QStringLiteral("search:/videos"))
+    };
+
     int row = 0;
     do {
         const QModelIndex sourceIndex = m_sourceModel->index(row, 0);
@@ -731,7 +760,7 @@ int PlacesItemModel::mapFromSource(const QModelIndex &index) const
 
 bool PlacesItemModel::isDir(int index) const
 {
-    Q_UNUSED(index);
+    Q_UNUSED(index)
     return true;
 }