X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/e710a6431160aee57b1eab34b11dfe64e341898c..954e8c47906c12edaaf6e6aebdd41516eceb0d44:/src/panels/places/placesitemmodel.cpp diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 66bdbd57a..de858389b 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -1,25 +1,12 @@ -/*************************************************************************** - * Copyright (C) 2012 by Peter Penz * - * * - * Based on KFilePlacesModel from kdelibs: * - * Copyright (C) 2007 Kevin Ottens * - * Copyright (C) 2007 David Faure * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2012 Peter Penz + * + * Based on KFilePlacesModel from kdelibs: + * SPDX-FileCopyrightText: 2007 Kevin Ottens + * SPDX-FileCopyrightText: 2007 David Faure + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "placesitemmodel.h" @@ -36,25 +23,14 @@ #include #include #include +#include +#include #include #include #include #include -namespace { - static QList 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 +54,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 +329,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 urls = KUrlMimeData::urlsFromMimeData(mimeData); @@ -369,7 +350,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,7 +450,29 @@ 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 \"%2\".", + "One or more files on this device are opened in following applications: %2.", + blockingApps.count(), blockingApps.join(i18nc("separator in list of apps blocking device unmount", ", "))); + } + emit errorMessage(errorString); + }); + listOpenFilesJob->start(); + } else { + emit errorMessage(errorData.toString()); + } } disconnect(m_deviceToTearDown, &Solid::StorageAccess::teardownDone, this, &PlacesItemModel::slotStorageTearDownDone); @@ -480,7 +483,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); @@ -524,8 +527,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); @@ -536,8 +539,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; @@ -552,7 +555,7 @@ void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex &parent, int star void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { - Q_UNUSED(roles); + Q_UNUSED(roles) for (int r = topLeft.row(); r <= bottomRight.row(); r++) { const QModelIndex sourceIndex = m_sourceModel->index(r, 0); @@ -572,11 +575,6 @@ void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const } if (placeItem && !m_sourceModel->isDevice(sourceIndex)) { - placeItem->setText(bookmark.text()); - placeItem->setIcon(sourceIndex.data(KFilePlacesModel::IconNameRole).toString()); - placeItem->setUrl(m_sourceModel->url(sourceIndex)); - placeItem->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"), - bookmark.metaDataItem(QStringLiteral("OnlyInApp"))); // must update the bookmark object placeItem->setBookmark(bookmark); } @@ -598,6 +596,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 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); @@ -732,7 +742,7 @@ int PlacesItemModel::mapFromSource(const QModelIndex &index) const bool PlacesItemModel::isDir(int index) const { - Q_UNUSED(index); + Q_UNUSED(index) return true; }