X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/d55b0875ffac78ba99ca63f774be17273d396137..d575e1e88409d819fb92456e8022e8e0322549af:/src/panels/places/placesitemmodel.cpp diff --git a/src/panels/places/placesitemmodel.cpp b/src/panels/places/placesitemmodel.cpp index 62d1e5d78..f7fe5587c 100644 --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@ -22,40 +22,37 @@ ***************************************************************************/ #include "placesitemmodel.h" -#include "placesitemsignalhandler.h" #include "dolphin_generalsettings.h" - -#include -#include #include "dolphindebug.h" -#include -#include -#include -#include -#include +#include "dolphinplacesmodelsingleton.h" #include "placesitem.h" -#include -#include -#include -#include -#include -#include +#include "placesitemsignalhandler.h" +#include "views/dolphinview.h" +#include "views/viewproperties.h" -#include +#include +#include +#include #include -#include #include -#include -#include -#include -#include +#include +#include +#include +#include namespace { - // Hence a prefix to the application-name of the stored bookmarks is - // added, which is only read by PlacesItemModel. - const char AppNamePrefix[] = "-places-panel"; + 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) : @@ -63,17 +60,18 @@ PlacesItemModel::PlacesItemModel(QObject* parent) : m_hiddenItemsShown(false), m_deviceToTearDown(nullptr), m_storageSetupInProgress(), - m_sourceModel(new KFilePlacesModel(this)) + m_sourceModel(DolphinPlacesModelSingleton::instance().placesModel()) { + cleanupBookmarks(); loadBookmarks(); initializeDefaultViewProperties(); - connect(m_sourceModel.data(), &KFilePlacesModel::rowsInserted, this, &PlacesItemModel::onSourceModelRowsInserted); - connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeRemoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved); - connect(m_sourceModel.data(), &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged); - connect(m_sourceModel.data(), &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved); - connect(m_sourceModel.data(), &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved); - connect(m_sourceModel.data(), &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged); + connect(m_sourceModel, &KFilePlacesModel::rowsInserted, this, &PlacesItemModel::onSourceModelRowsInserted); + connect(m_sourceModel, &KFilePlacesModel::rowsAboutToBeRemoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeRemoved); + connect(m_sourceModel, &KFilePlacesModel::dataChanged, this, &PlacesItemModel::onSourceModelDataChanged); + connect(m_sourceModel, &KFilePlacesModel::rowsAboutToBeMoved, this, &PlacesItemModel::onSourceModelRowsAboutToBeMoved); + connect(m_sourceModel, &KFilePlacesModel::rowsMoved, this, &PlacesItemModel::onSourceModelRowsMoved); + connect(m_sourceModel, &KFilePlacesModel::groupHiddenChanged, this, &PlacesItemModel::onSourceModelGroupHiddenChanged); } PlacesItemModel::~PlacesItemModel() @@ -122,11 +120,6 @@ void PlacesItemModel::setHiddenItemsShown(bool show) } } } - -#ifdef PLACESITEMMODEL_DEBUG - qCDebug(DolphinDebug) << "Changed visibility of hidden items"; - showModelState(); -#endif } bool PlacesItemModel::hiddenItemsShown() const @@ -153,12 +146,13 @@ void PlacesItemModel::insertSortedItem(PlacesItem* item) for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) { sourceIndex = m_sourceModel->index(r, 0); + const KBookmark sourceBookmark = m_sourceModel->bookmarkForIndex(sourceIndex); - if (bookmarkId(m_sourceModel->bookmarkForIndex(sourceIndex)) == iBookmarkId) { + if (bookmarkId(sourceBookmark) == iBookmarkId) { break; } - if (!m_sourceModel->isHidden(sourceIndex)) { + if (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex)) { pos++; } } @@ -170,10 +164,6 @@ void PlacesItemModel::insertSortedItem(PlacesItem* item) void PlacesItemModel::onItemInserted(int index) { KStandardItemModel::onItemInserted(index); -#ifdef PLACESITEMMODEL_DEBUG - qCDebug(DolphinDebug) << "Inserted item" << index; - showModelState(); -#endif } void PlacesItemModel::onItemRemoved(int index, KStandardItem* removedItem) @@ -181,10 +171,6 @@ void PlacesItemModel::onItemRemoved(int index, KStandardItem* removedItem) m_indexMap.removeAt(index); KStandardItemModel::onItemRemoved(index, removedItem); -#ifdef PLACESITEMMODEL_DEBUG - qCDebug(DolphinDebug) << "Removed item" << index; - showModelState(); -#endif } void PlacesItemModel::onItemChanged(int index, const QSet& changedRoles) @@ -454,7 +440,7 @@ void PlacesItemModel::initializeDefaultViewProperties() const } else if (path == QLatin1String("/images")) { props.setViewMode(DolphinView::IconsView); props.setPreviewsShown(true); - props.setVisibleRoles({"text", "imageSize"}); + props.setVisibleRoles({"text", "height", "width"}); } else if (path == QLatin1String("/audio")) { props.setViewMode(DolphinView::DetailsView); props.setPreviewsShown(false); @@ -559,11 +545,7 @@ void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex &parent, int star const int targetRow = row + (start - r) - (r < row ? blockSize : 0); const QModelIndex targetIndex = m_sourceModel->index(targetRow, 0, destination); - const KBookmark bookmark = m_sourceModel->bookmarkForIndex(targetIndex); - PlacesItem *item = new PlacesItem(bookmark); - updateItem(item, targetIndex); - - insertSortedItem(item); + addItemFromSourceModel(targetIndex); } } @@ -594,13 +576,16 @@ void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const placeItem->setUrl(m_sourceModel->url(sourceIndex)); placeItem->bookmark().setMetaDataItem(QStringLiteral("OnlyInApp"), bookmark.metaDataItem(QStringLiteral("OnlyInApp"))); + // must update the bookmark object + placeItem->setBookmark(bookmark); } } } void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden) { - for(const QModelIndex &sourceIndex : m_sourceModel->groupIndexes(group)) { + const auto groupIndexes = m_sourceModel->groupIndexes(group); + for (const QModelIndex &sourceIndex : groupIndexes) { PlacesItem *item = placesItem(mapFromSource(sourceIndex)); if (item) { item->setGroupHidden(hidden); @@ -608,34 +593,35 @@ void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupTyp } } +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 + int row = 0; + do { + const QModelIndex sourceIndex = m_sourceModel->index(row, 0); + const KBookmark bookmark = m_sourceModel->bookmarkForIndex(sourceIndex); + const QUrl url = bookmark.url(); + const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp")); + + if ((appName == KAboutData::applicationData().componentName() || + appName == KAboutData::applicationData().componentName() + DolphinPlacesModelSingleton::applicationNameSuffix()) && balooURLs.contains(url)) { + qCDebug(DolphinDebug) << "Removing old baloo url:" << url; + m_sourceModel->removePlace(sourceIndex); + } else { + row++; + } + } while (row < m_sourceModel->rowCount()); +} + void PlacesItemModel::loadBookmarks() { for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) { const QModelIndex sourceIndex = m_sourceModel->index(r, 0); - KBookmark bookmark = m_sourceModel->bookmarkForIndex(sourceIndex); - if (acceptBookmark(bookmark) && - (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex))) { + if (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex)) { addItemFromSourceModel(sourceIndex); } } - -#ifdef PLACESITEMMODEL_DEBUG - qCDebug(DolphinDebug) << "Loaded bookmarks"; - showModelState(); -#endif -} - -bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark) const -{ - const QString udi = bookmark.metaDataItem(QStringLiteral("UDI")); - const QUrl url = bookmark.url(); - const QString appName = bookmark.metaDataItem(QStringLiteral("OnlyInApp")); - - const bool allowedHere = (appName.isEmpty() - || appName == KAboutData::applicationData().componentName() - || appName == KAboutData::applicationData().componentName() + AppNamePrefix); - - return (udi.isEmpty() && allowedHere); } void PlacesItemModel::clear() { @@ -782,44 +768,3 @@ PlacesItem *PlacesItemModel::itemFromBookmark(const KBookmark &bookmark) const return nullptr; } -#ifdef PLACESITEMMODEL_DEBUG -void PlacesItemModel::showModelState() -{ - qCDebug(DolphinDebug) << "================================="; - qCDebug(DolphinDebug) << "Model:"; - qCDebug(DolphinDebug) << "hidden-index model-index text"; - int modelIndex = 0; - for (int i = 0; i < m_bookmarkedItems.count(); ++i) { - if (m_bookmarkedItems[i]) { - qCDebug(DolphinDebug) << i << "(Hidden) " << " " << m_bookmarkedItems[i]->dataValue("text").toString(); - } else { - if (item(modelIndex)) { - qCDebug(DolphinDebug) << i << " " << modelIndex << " " << item(modelIndex)->dataValue("text").toString(); - } else { - qCDebug(DolphinDebug) << i << " " << modelIndex << " " << "(not available yet)"; - } - ++modelIndex; - } - } - - qCDebug(DolphinDebug); - qCDebug(DolphinDebug) << "Bookmarks:"; - - int bookmarkIndex = 0; - KBookmarkGroup root = m_bookmarkManager->root(); - KBookmark bookmark = root.first(); - while (!bookmark.isNull()) { - const QString udi = bookmark.metaDataItem("UDI"); - const QString text = udi.isEmpty() ? bookmark.text() : udi; - if (bookmark.metaDataItem("IsHidden") == QLatin1String("true")) { - qCDebug(DolphinDebug) << bookmarkIndex << "(Hidden)" << text; - } else { - qCDebug(DolphinDebug) << bookmarkIndex << " " << text; - } - - bookmark = root.next(bookmark); - ++bookmarkIndex; - } -} -#endif -