From: Luca Beltrame Date: Thu, 18 Jan 2018 08:09:49 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/Applications/17.12' X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/commitdiff_plain/1a6b3c0a2baba955259d6083c0a3f25dfb44a682?hp=-c Merge remote-tracking branch 'origin/Applications/17.12' Conflicts: CMakeLists.txt [versions] src/panels/places/placesitemmodel.cpp --- 1a6b3c0a2baba955259d6083c0a3f25dfb44a682 diff --combined src/kitemviews/kfileitemmodel.cpp index 634e70399,5919e6427..3947d3707 --- a/src/kitemviews/kfileitemmodel.cpp +++ b/src/kitemviews/kfileitemmodel.cpp @@@ -42,7 -42,7 +42,7 @@@ KFileItemModel::KFileItemModel(QObject* parent) : KItemModelBase("text", parent), - m_dirLister(0), + m_dirLister(nullptr), m_sortDirsFirst(true), m_sortRole(NameRole), m_sortingProgressPercent(-1), @@@ -52,8 -52,8 +52,8 @@@ m_filter(), m_filteredItems(), m_requestRole(), - m_maximumUpdateIntervalTimer(0), - m_resortAllItemsTimer(0), + m_maximumUpdateIntervalTimer(nullptr), + m_resortAllItemsTimer(nullptr), m_pendingItemsToInsert(), m_groups(), m_expandedDirs(), @@@ -251,7 -251,7 +251,7 @@@ QMimeData* KFileItemModel::createMimeDa QList urls; QList mostLocalUrls; bool canUseMostLocalUrls = true; - const ItemData* lastAddedItem = 0; + const ItemData* lastAddedItem = nullptr; for (int index : indexes) { const ItemData* itemData = m_itemData.at(index); @@@ -629,20 -629,24 +629,24 @@@ void KFileItemModel::restoreExpandedDir void KFileItemModel::expandParentDirectories(const QUrl &url) { - const int pos = m_dirLister->url().path().length(); // Assure that each sub-path of the URL that should be // expanded is added to m_urlsToExpand. KDirLister // does not care whether the parent-URL has already been // expanded. QUrl urlToExpand = m_dirLister->url(); + const int pos = urlToExpand.path().length(); // first subdir can be empty, if m_dirLister->url().path() does not end with '/' // this happens if baseUrl is not root but a home directory, see FoldersPanel, // so using QString::SkipEmptyParts const QStringList subDirs = url.path().mid(pos).split(QDir::separator(), QString::SkipEmptyParts); for (int i = 0; i < subDirs.count() - 1; ++i) { - urlToExpand.setPath(urlToExpand.path() + '/' + subDirs.at(i)); + QString path = urlToExpand.path(); + if (!path.endsWith(QLatin1Char('/'))) { + path.append(QLatin1Char('/')); + } + urlToExpand.setPath(path + subDirs.at(i)); m_urlsToExpand.insert(urlToExpand); } @@@ -2295,16 -2299,16 +2299,16 @@@ const KFileItemModel::RoleInfoMap* KFil { static const RoleInfoMap rolesInfoMap[] = { // | role | roleType | role translation | group translation | requires Baloo | requires indexer - { 0, NoRole, 0, 0, 0, 0, false, false }, - { "text", NameRole, I18N_NOOP2_NOSTRIP("@label", "Name"), 0, 0, false, false }, - { "size", SizeRole, I18N_NOOP2_NOSTRIP("@label", "Size"), 0, 0, false, false }, - { "modificationtime", ModificationTimeRole, I18N_NOOP2_NOSTRIP("@label", "Modified"), 0, 0, false, false }, - { "creationtime", CreationTimeRole, I18N_NOOP2_NOSTRIP("@label", "Created"), 0, 0, false, false }, - { "accesstime", AccessTimeRole, I18N_NOOP2_NOSTRIP("@label", "Accessed"), 0, 0, false, false }, - { "type", TypeRole, I18N_NOOP2_NOSTRIP("@label", "Type"), 0, 0, false, false }, - { "rating", RatingRole, I18N_NOOP2_NOSTRIP("@label", "Rating"), 0, 0, true, false }, - { "tags", TagsRole, I18N_NOOP2_NOSTRIP("@label", "Tags"), 0, 0, true, false }, - { "comment", CommentRole, I18N_NOOP2_NOSTRIP("@label", "Comment"), 0, 0, true, false }, + { nullptr, NoRole, nullptr, nullptr, nullptr, nullptr, false, false }, + { "text", NameRole, I18N_NOOP2_NOSTRIP("@label", "Name"), nullptr, nullptr, false, false }, + { "size", SizeRole, I18N_NOOP2_NOSTRIP("@label", "Size"), nullptr, nullptr, false, false }, + { "modificationtime", ModificationTimeRole, I18N_NOOP2_NOSTRIP("@label", "Modified"), nullptr, nullptr, false, false }, + { "creationtime", CreationTimeRole, I18N_NOOP2_NOSTRIP("@label", "Created"), nullptr, nullptr, false, false }, + { "accesstime", AccessTimeRole, I18N_NOOP2_NOSTRIP("@label", "Accessed"), nullptr, nullptr, false, false }, + { "type", TypeRole, I18N_NOOP2_NOSTRIP("@label", "Type"), nullptr, nullptr, false, false }, + { "rating", RatingRole, I18N_NOOP2_NOSTRIP("@label", "Rating"), nullptr, nullptr, true, false }, + { "tags", TagsRole, I18N_NOOP2_NOSTRIP("@label", "Tags"), nullptr, nullptr, true, false }, + { "comment", CommentRole, I18N_NOOP2_NOSTRIP("@label", "Comment"), nullptr, nullptr, true, false }, { "title", TitleRole, I18N_NOOP2_NOSTRIP("@label", "Title"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, { "wordCount", WordCountRole, I18N_NOOP2_NOSTRIP("@label", "Word Count"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, { "lineCount", LineCountRole, I18N_NOOP2_NOSTRIP("@label", "Line Count"), I18N_NOOP2_NOSTRIP("@label", "Document"), true, true }, @@@ -2373,7 -2377,7 +2377,7 @@@ bool KFileItemModel::isConsistent() con return false; } - for (int i = 0; i < count(); ++i) { + for (int i = 0, iMax = count(); i < iMax; ++i) { // Check if m_items and m_itemData are consistent. const KFileItem item = fileItem(i); if (item.isNull()) { diff --combined src/panels/folders/folderspanel.h index 75a603681,3b27dd3dd..f67c19cbb --- a/src/panels/folders/folderspanel.h +++ b/src/panels/folders/folderspanel.h @@@ -40,7 -40,7 +40,7 @@@ class FoldersPanel : public Pane public: explicit FoldersPanel(QWidget* parent = nullptr); - virtual ~FoldersPanel(); + ~FoldersPanel() override; void setShowHiddenFiles(bool show); void setLimitFoldersPanelToHome(bool enable); @@@ -59,13 -59,13 +59,13 @@@ signals protected: /** @see Panel::urlChanged() */ - virtual bool urlChanged() Q_DECL_OVERRIDE; + bool urlChanged() override; /** @see QWidget::showEvent() */ - virtual void showEvent(QShowEvent* event) Q_DECL_OVERRIDE; + void showEvent(QShowEvent* event) override; /** @see QWidget::keyPressEvent() */ - virtual void keyPressEvent(QKeyEvent* event) Q_DECL_OVERRIDE; + void keyPressEvent(QKeyEvent* event) override; private slots: void slotItemActivated(int index); @@@ -85,12 -85,20 +85,20 @@@ private: + /** + * Indicate if it is allowed to leave current location. + */ + enum NavigationBehaviour { + StayWhereYouAre, ///< Don't leave current location. + AllowJumpHome ///< Go Home only when context menu option got checked. + }; /** * Initializes the base URL of the tree and expands all * directories until \a url. * @param url URL of the leaf directory that should get expanded. + * @param navigationBehaviour Navigation behaviour \see NavigationBehaviour */ - void loadTree(const QUrl& url); + void loadTree(const QUrl& url, NavigationBehaviour navigationBehaviour = StayWhereYouAre); void reloadTree(); diff --combined src/panels/information/informationpanelcontent.cpp index c1f547380,3c48a2296..2e279dc62 --- a/src/panels/information/informationpanelcontent.cpp +++ b/src/panels/information/informationpanelcontent.cpp @@@ -65,14 -65,14 +65,14 @@@ InformationPanelContent::InformationPanelContent(QWidget* parent) : QWidget(parent), m_item(), - m_previewJob(0), - m_outdatedPreviewTimer(0), - m_preview(0), - m_phononWidget(0), - m_nameLabel(0), - m_metaDataWidget(0), - m_metaDataArea(0), - m_placesItemModel(0) + m_previewJob(nullptr), + m_outdatedPreviewTimer(nullptr), + m_preview(nullptr), + m_phononWidget(nullptr), + m_nameLabel(nullptr), + m_metaDataWidget(nullptr), + m_metaDataArea(nullptr), + m_placesItemModel(nullptr) { parent->installEventFilter(this); @@@ -107,7 -107,7 +107,7 @@@ m_nameLabel->setFont(font); m_nameLabel->setTextFormat(Qt::PlainText); m_nameLabel->setAlignment(Qt::AlignHCenter); - m_nameLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + m_nameLabel->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed); const bool previewsShown = InformationPanelSettings::previewsShown(); m_preview->setVisible(previewsShown); diff --combined src/panels/places/placesitemmodel.cpp index 422db8fc3,abdd4c20b..ad01ea87e --- a/src/panels/places/placesitemmodel.cpp +++ b/src/panels/places/placesitemmodel.cpp @@@ -40,7 -40,6 +40,7 @@@ #include #include #include +#include #include #include @@@ -52,40 -51,82 +52,51 @@@ #include #include -#ifdef HAVE_BALOO - #include - #include -#endif - namespace { - // As long as KFilePlacesView from kdelibs is available in parallel, the - // system-bookmarks for "Recently Saved" and "Search For" should be - // shown only inside the Places Panel. This is necessary as the stored - // URLs needs to get translated to a Baloo-search-URL on-the-fly to - // be independent from changes in the Baloo-search-URL-syntax. // 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) : KStandardItemModel(parent), - m_fileIndexingEnabled(false), m_hiddenItemsShown(false), - m_availableDevices(), - m_predicate(), - m_bookmarkManager(0), - m_systemBookmarks(), - m_systemBookmarksIndexes(), - m_bookmarkedItems(), - m_hiddenItemToRemove(-1), - m_deviceToTearDown(0), - m_updateBookmarksTimer(0), - m_storageSetupInProgress() + m_deviceToTearDown(nullptr), + m_storageSetupInProgress(), + m_sourceModel(new KFilePlacesModel(this)) { -#ifdef HAVE_BALOO - Baloo::IndexerConfig config; - m_fileIndexingEnabled = config.fileIndexingEnabled(); -#endif - const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/user-places.xbel"; - m_bookmarkManager = KBookmarkManager::managerForExternalFile(file); - - createSystemBookmarks(); - initializeAvailableDevices(); loadBookmarks(); + initializeDefaultViewProperties(); - const int syncBookmarksTimeout = 100; - - m_updateBookmarksTimer = new QTimer(this); - m_updateBookmarksTimer->setInterval(syncBookmarksTimeout); - m_updateBookmarksTimer->setSingleShot(true); - connect(m_updateBookmarksTimer, &QTimer::timeout, this, &PlacesItemModel::updateBookmarks); - - connect(m_bookmarkManager, &KBookmarkManager::changed, - m_updateBookmarksTimer, static_cast(&QTimer::start)); + 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); } PlacesItemModel::~PlacesItemModel() { - qDeleteAll(m_bookmarkedItems); - m_bookmarkedItems.clear(); } -PlacesItem* PlacesItemModel::createPlacesItem(const QString& text, - const QUrl& url, - const QString& iconName) +void PlacesItemModel::createPlacesItem(const QString& text, + const QUrl& url, + const QString& iconName, + int after) { - const KBookmark bookmark = PlacesItem::createBookmark(m_bookmarkManager, text, url, iconName); - return new PlacesItem(bookmark); + m_sourceModel->addPlace(text, url, iconName, {}, mapToSource(after)); } PlacesItem* PlacesItemModel::placesItem(int index) const @@@ -95,7 -136,20 +106,7 @@@ int PlacesItemModel::hiddenCount() const { - int modelIndex = 0; - int hiddenItemCount = 0; - foreach (const PlacesItem* item, m_bookmarkedItems) { - if (item) { - ++hiddenItemCount; - } else { - if (placesItem(modelIndex)->isHidden()) { - ++hiddenItemCount; - } - ++modelIndex; - } - } - - return hiddenItemCount; + return m_sourceModel->hiddenCount(); } void PlacesItemModel::setHiddenItemsShown(bool show) @@@ -107,18 -161,38 +118,18 @@@ m_hiddenItemsShown = show; if (show) { - // Move all items that are part of m_bookmarkedItems to the model. - QList itemsToInsert; - QList insertPos; - int modelIndex = 0; - for (int i = 0; i < m_bookmarkedItems.count(); ++i) { - if (m_bookmarkedItems[i]) { - itemsToInsert.append(m_bookmarkedItems[i]); - m_bookmarkedItems[i] = 0; - insertPos.append(modelIndex); + for (int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) { + const QModelIndex index = m_sourceModel->index(r, 0); + if (!m_sourceModel->isHidden(index)) { + continue; } - ++modelIndex; + addItemFromSourceModel(index); } - - // Inserting the items will automatically insert an item - // to m_bookmarkedItems in PlacesItemModel::onItemsInserted(). - // The items are temporary saved in itemsToInsert, so - // m_bookmarkedItems can be shrinked now. - m_bookmarkedItems.erase(m_bookmarkedItems.begin(), - m_bookmarkedItems.begin() + itemsToInsert.count()); - - for (int i = 0; i < itemsToInsert.count(); ++i) { - insertItem(insertPos[i], itemsToInsert[i]); - } - - Q_ASSERT(m_bookmarkedItems.count() == count()); } else { - // Move all items of the model, where the "isHidden" property is true, to - // m_bookmarkedItems. - Q_ASSERT(m_bookmarkedItems.count() == count()); - for (int i = count() - 1; i >= 0; --i) { - if (placesItem(i)->isHidden()) { - hideItem(i); + for (int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) { + const QModelIndex index = m_sourceModel->index(r, 0); + if (m_sourceModel->isHidden(index)) { + removeItemByIndex(index); } } } @@@ -136,98 -210,75 +147,98 @@@ bool PlacesItemModel::hiddenItemsShown( int PlacesItemModel::closestItem(const QUrl& url) const { - int foundIndex = -1; - int maxLength = 0; - - for (int i = 0; i < count(); ++i) { - const QUrl itemUrl = placesItem(i)->url(); - if (url == itemUrl) { - // We can't find a closer one, so stop here. - foundIndex = i; - break; - } else if (itemUrl.isParentOf(url)) { - const int length = itemUrl.path().length(); - if (length > maxLength) { - foundIndex = i; - maxLength = length; - } - } - } - - return foundIndex; + return mapFromSource(m_sourceModel->closestItem(url)); } -void PlacesItemModel::appendItemToGroup(PlacesItem* item) +// look for the correct position for the item based on source model +void PlacesItemModel::insertSortedItem(PlacesItem* item) { if (!item) { return; } - int i = 0; - while (i < count() && placesItem(i)->group() != item->group()) { - ++i; - } + const KBookmark iBookmark = item->bookmark(); + const QString iBookmarkId = bookmarkId(iBookmark); + QModelIndex sourceIndex; + int pos = 0; - bool inserted = false; - while (!inserted && i < count()) { - if (placesItem(i)->group() != item->group()) { - insertItem(i, item); - inserted = true; + for(int r = 0, rMax = m_sourceModel->rowCount(); r < rMax; r++) { + sourceIndex = m_sourceModel->index(r, 0); + + if (bookmarkId(m_sourceModel->bookmarkForIndex(sourceIndex)) == iBookmarkId) { + break; } - ++i; - } - if (!inserted) { - appendItem(item); + if (!m_sourceModel->isHidden(sourceIndex)) { + pos++; + } } + + m_indexMap.insert(pos, sourceIndex); + insertItem(pos, 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) +{ + 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) +{ + const QModelIndex sourceIndex = mapToSource(index); + const PlacesItem *changedItem = placesItem(mapFromSource(sourceIndex)); + + if (!changedItem || !sourceIndex.isValid()) { + qWarning() << "invalid item changed signal"; + return; + } + if (changedRoles.contains("isHidden")) { + if (m_sourceModel->isHidden(sourceIndex) != changedItem->isHidden()) { + m_sourceModel->setPlaceHidden(sourceIndex, changedItem->isHidden()); + } else { + m_sourceModel->refresh(); + } + } + KStandardItemModel::onItemChanged(index, changedRoles); +} 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"), 0); + return new QAction(QIcon::fromTheme(QStringLiteral("media-eject")), i18nc("@item", "Eject"), nullptr); } - return 0; + return nullptr; } QAction* PlacesItemModel::teardownAction(int index) const { const PlacesItem* item = placesItem(index); if (!item) { - return 0; + return nullptr; } Solid::Device device = item->device(); const bool providesTearDown = device.is() && device.as()->isAccessible(); if (!providesTearDown) { - return 0; + return nullptr; } Solid::StorageDrive* drive = device.as(); @@@ -255,10 -306,10 +266,10 @@@ } if (iconName.isEmpty()) { - return new QAction(text, 0); + return new QAction(text, nullptr); } - return new QAction(QIcon::fromTheme(iconName), text, 0); + return new QAction(QIcon::fromTheme(iconName), text, nullptr); } void PlacesItemModel::requestEject(int index) @@@ -364,8 -415,25 +375,8 @@@ void PlacesItemModel::dropMimeDataBefor QDataStream stream(&itemData, QIODevice::ReadOnly); int oldIndex; stream >> oldIndex; - if (oldIndex == index || oldIndex == index - 1) { - // No moving has been done - return; - } - PlacesItem* oldItem = placesItem(oldIndex); - if (!oldItem) { - return; - } - - PlacesItem* newItem = new PlacesItem(oldItem->bookmark()); - removeItem(oldIndex); - - if (oldIndex < index) { - --index; - } - - const int dropIndex = groupedDropIndex(index, newItem); - insertItem(dropIndex, newItem); + m_sourceModel->movePlace(oldIndex, index); } else if (mimeData->hasFormat(QStringLiteral("text/uri-list"))) { // One or more items must be added to the model const QList urls = KUrlMimeData::urlsFromMimeData(mimeData); @@@ -383,101 -451,150 +394,101 @@@ continue; } - PlacesItem* newItem = createPlacesItem(text, url); - const int dropIndex = groupedDropIndex(index, newItem); - insertItem(dropIndex, newItem); + 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 + refresh(); } -QUrl PlacesItemModel::convertedUrl(const QUrl& url) +void PlacesItemModel::addItemFromSourceModel(const QModelIndex &index) { - QUrl newUrl = url; - if (url.scheme() == QLatin1String("timeline")) { - newUrl = createTimelineUrl(url); - } else if (url.scheme() == QLatin1String("search")) { - newUrl = createSearchUrl(url); - } - - return newUrl; -} - -void PlacesItemModel::onItemInserted(int index) -{ - const PlacesItem* insertedItem = placesItem(index); - if (insertedItem) { - // Take care to apply the PlacesItemModel-order of the inserted item - // also to the bookmark-manager. - const KBookmark insertedBookmark = insertedItem->bookmark(); - - const PlacesItem* previousItem = placesItem(index - 1); - KBookmark previousBookmark; - if (previousItem) { - previousBookmark = previousItem->bookmark(); - } - - m_bookmarkManager->root().moveBookmark(insertedBookmark, previousBookmark); - } - - if (index == count() - 1) { - // The item has been appended as last item to the list. In this - // case assure that it is also appended after the hidden items and - // not before (like done otherwise). - m_bookmarkedItems.append(0); - } else { - - int modelIndex = -1; - int bookmarkIndex = 0; - while (bookmarkIndex < m_bookmarkedItems.count()) { - if (!m_bookmarkedItems[bookmarkIndex]) { - ++modelIndex; - if (modelIndex + 1 == index) { - break; - } - } - ++bookmarkIndex; - } - m_bookmarkedItems.insert(bookmarkIndex, 0); + if (!m_hiddenItemsShown && m_sourceModel->isHidden(index)) { + return; } -#ifdef PLACESITEMMODEL_DEBUG - qCDebug(DolphinDebug) << "Inserted item" << index; - showModelState(); -#endif -} + const KBookmark bookmark = m_sourceModel->bookmarkForIndex(index); + Q_ASSERT(!bookmark.isNull()); + PlacesItem *item = new PlacesItem(bookmark); + updateItem(item, index); + insertSortedItem(item); -void PlacesItemModel::onItemRemoved(int index, KStandardItem* removedItem) -{ - PlacesItem* placesItem = dynamic_cast(removedItem); - if (placesItem) { - const KBookmark bookmark = placesItem->bookmark(); - m_bookmarkManager->root().deleteBookmark(bookmark); + if (m_sourceModel->isDevice(index)) { + connect(item->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested, + this, &PlacesItemModel::storageTearDownExternallyRequested); } - - const int boomarkIndex = bookmarkIndex(index); - Q_ASSERT(!m_bookmarkedItems[boomarkIndex]); - m_bookmarkedItems.removeAt(boomarkIndex); - -#ifdef PLACESITEMMODEL_DEBUG - qCDebug(DolphinDebug) << "Removed item" << index; - showModelState(); -#endif } -void PlacesItemModel::onItemChanged(int index, const QSet& changedRoles) +void PlacesItemModel::removeItemByIndex(const QModelIndex &sourceIndex) { - const PlacesItem* changedItem = placesItem(index); - if (changedItem) { - // Take care to apply the PlacesItemModel-order of the changed item - // also to the bookmark-manager. - const KBookmark insertedBookmark = changedItem->bookmark(); - - const PlacesItem* previousItem = placesItem(index - 1); - KBookmark previousBookmark; - if (previousItem) { - previousBookmark = previousItem->bookmark(); - } + QString id = bookmarkId(m_sourceModel->bookmarkForIndex(sourceIndex)); - m_bookmarkManager->root().moveBookmark(insertedBookmark, previousBookmark); - } - - if (changedRoles.contains("isHidden")) { - if (!m_hiddenItemsShown && changedItem->isHidden()) { - m_hiddenItemToRemove = index; - QTimer::singleShot(0, this, static_cast(&PlacesItemModel::hideItem)); + for (int i = 0, iMax = count(); i < iMax; ++i) { + if (bookmarkId(placesItem(i)->bookmark()) == id) { + removeItem(i); + return; } } } -void PlacesItemModel::slotDeviceAdded(const QString& udi) -{ - const Solid::Device device(udi); - - if (!m_predicate.matches(device)) { - return; +QString PlacesItemModel::bookmarkId(const KBookmark &bookmark) const +{ + QString id = bookmark.metaDataItem(QStringLiteral("UDI")); + if (id.isEmpty()) { + id = bookmark.metaDataItem(QStringLiteral("ID")); + } + return id; +} + +void PlacesItemModel::initializeDefaultViewProperties() const +{ + for(int i = 0, iMax = m_sourceModel->rowCount(); i < iMax; i++) { + const QModelIndex index = m_sourceModel->index(i, 0); + const PlacesItem *item = placesItem(mapFromSource(index)); + if (!item) { + continue; + } + + // Create default view-properties for all "Search For" and "Recently Saved" bookmarks + // in case the user has not already created custom view-properties for a corresponding + // query yet. + const bool createDefaultViewProperties = item->isSearchOrTimelineUrl() && !GeneralSettings::self()->globalViewProps(); + if (createDefaultViewProperties) { + const QUrl itemUrl = item->url(); + ViewProperties props(KFilePlacesModel::convertedUrl(itemUrl)); + if (!props.exist()) { + const QString path = itemUrl.path(); + if (path == QLatin1String("/documents")) { + props.setViewMode(DolphinView::DetailsView); + props.setPreviewsShown(false); + props.setVisibleRoles({"text", "path"}); + } else if (path == QLatin1String("/images")) { + props.setViewMode(DolphinView::IconsView); + props.setPreviewsShown(true); + props.setVisibleRoles({"text", "imageSize"}); + } else if (path == QLatin1String("/audio")) { + props.setViewMode(DolphinView::DetailsView); + props.setPreviewsShown(false); + props.setVisibleRoles({"text", "artist", "album"}); + } else if (path == QLatin1String("/videos")) { + props.setViewMode(DolphinView::IconsView); + props.setPreviewsShown(true); + props.setVisibleRoles({"text"}); + } else if (itemUrl.scheme() == QLatin1String("timeline")) { + props.setViewMode(DolphinView::DetailsView); + props.setVisibleRoles({"text", "modificationtime"}); + } + props.save(); + } + } } - - m_availableDevices << udi; - const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); - - PlacesItem *item = new PlacesItem(bookmark); - appendItem(item); - connect(item->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested, - this, &PlacesItemModel::storageTearDownExternallyRequested); } -void PlacesItemModel::slotDeviceRemoved(const QString& udi) +void PlacesItemModel::updateItem(PlacesItem *item, const QModelIndex &index) { - if (!m_availableDevices.contains(udi)) { - return; - } - - for (int i = 0; i < m_bookmarkedItems.count(); ++i) { - PlacesItem* item = m_bookmarkedItems[i]; - if (item && item->udi() == udi) { - m_bookmarkedItems.removeAt(i); - delete item; - return; - } - } - - for (int i = 0; i < count(); ++i) { - if (placesItem(i)->udi() == udi) { - removeItem(i); - return; - } - } + item->setGroup(index.data(KFilePlacesModel::GroupRole).toString()); + item->setIcon(index.data(KFilePlacesModel::IconNameRole).toString()); + item->setGroupHidden(index.data(KFilePlacesModel::GroupHiddenRole).toBool()); } void PlacesItemModel::slotStorageTearDownDone(Solid::ErrorType error, const QVariant& errorData) @@@ -516,106 -633,199 +527,106 @@@ void PlacesItemModel::slotStorageSetupD } } -void PlacesItemModel::hideItem() +void PlacesItemModel::onSourceModelRowsInserted(const QModelIndex &parent, int first, int last) { - hideItem(m_hiddenItemToRemove); - m_hiddenItemToRemove = -1; + for (int i = first; i <= last; i++) { + const QModelIndex index = m_sourceModel->index(i, 0, parent); + addItemFromSourceModel(index); + } } -void PlacesItemModel::updateBookmarks() +void PlacesItemModel::onSourceModelRowsAboutToBeRemoved(const QModelIndex &parent, int first, int last) { - // Verify whether new bookmarks have been added or existing - // bookmarks have been changed. - KBookmarkGroup root = m_bookmarkManager->root(); - KBookmark newBookmark = root.first(); - while (!newBookmark.isNull()) { - if (acceptBookmark(newBookmark, m_availableDevices)) { - bool found = false; - int modelIndex = 0; - for (int i = 0; i < m_bookmarkedItems.count(); ++i) { - PlacesItem* item = m_bookmarkedItems[i]; - if (!item) { - item = placesItem(modelIndex); - ++modelIndex; - } - - const KBookmark oldBookmark = item->bookmark(); - if (equalBookmarkIdentifiers(newBookmark, oldBookmark)) { - // The bookmark has been found in the model or as - // a hidden item. The content of the bookmark might - // have been changed, so an update is done. - found = true; - if (newBookmark.metaDataItem(QStringLiteral("UDI")).isEmpty()) { - item->setBookmark(newBookmark); - item->setText(i18nc("KFile System Bookmarks", newBookmark.text().toUtf8().constData())); - } - break; - } - } - - if (!found) { - const QString udi = newBookmark.metaDataItem(QStringLiteral("UDI")); - - /* - * See Bug 304878 - * Only add a new places item, if the item text is not empty - * and if the device is available. Fixes the strange behaviour - - * add a places item without text in the Places section - when you - * remove a device (e.g. a usb stick) without unmounting. - */ - if (udi.isEmpty() || Solid::Device(udi).isValid()) { - PlacesItem* item = new PlacesItem(newBookmark); - if (item->isHidden() && !m_hiddenItemsShown) { - m_bookmarkedItems.append(item); - } else { - appendItemToGroup(item); - } - } - } + for(int r = first; r <= last; r++) { + const QModelIndex index = m_sourceModel->index(r, 0, parent); + int oldIndex = mapFromSource(index); + if (oldIndex != -1) { + removeItem(oldIndex); } - - newBookmark = root.next(newBookmark); } +} - // Remove items that are not part of the bookmark-manager anymore - int modelIndex = 0; - for (int i = m_bookmarkedItems.count() - 1; i >= 0; --i) { - PlacesItem* item = m_bookmarkedItems[i]; - const bool itemIsPartOfModel = (item == 0); - if (itemIsPartOfModel) { - item = placesItem(modelIndex); - } - - bool hasBeenRemoved = true; - const KBookmark oldBookmark = item->bookmark(); - KBookmark newBookmark = root.first(); - while (!newBookmark.isNull()) { - if (equalBookmarkIdentifiers(newBookmark, oldBookmark)) { - hasBeenRemoved = false; - break; - } - newBookmark = root.next(newBookmark); - } - - if (hasBeenRemoved) { - if (m_bookmarkedItems[i]) { - delete m_bookmarkedItems[i]; - m_bookmarkedItems.removeAt(i); - } else { - removeItem(modelIndex); - --modelIndex; - } - } +void PlacesItemModel::onSourceModelRowsAboutToBeMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) +{ + Q_UNUSED(destination); + Q_UNUSED(row); - if (itemIsPartOfModel) { - ++modelIndex; - } + for(int r = start; r <= end; r++) { + const QModelIndex sourceIndex = m_sourceModel->index(r, 0, parent); + // remove moved item + removeItem(mapFromSource(sourceIndex)); } } -void PlacesItemModel::saveBookmarks() +void PlacesItemModel::onSourceModelRowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) { - m_bookmarkManager->emitChanged(m_bookmarkManager->root()); -} + Q_UNUSED(destination); + Q_UNUSED(parent); -void PlacesItemModel::loadBookmarks() -{ - KBookmarkGroup root = m_bookmarkManager->root(); - KBookmark bookmark = root.first(); - QSet devices = m_availableDevices; + const int blockSize = (end - start) + 1; + + for (int r = start; r <= end; r++) { + // insert the moved item in the new position + 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); - QSet missingSystemBookmarks; - foreach (const SystemBookmarkData& data, m_systemBookmarks) { - missingSystemBookmarks.insert(data.url); + insertSortedItem(item); } +} - // The bookmarks might have a mixed order of places, devices and search-groups due - // to the compatibility with the KFilePlacesPanel. In Dolphin's places panel the - // items should always be collected in one group so the items are collected first - // in separate lists before inserting them. - QList placesItems; - QList recentlySavedItems; - QList searchForItems; - QList devicesItems; - - while (!bookmark.isNull()) { - if (acceptBookmark(bookmark, devices)) { - PlacesItem* item = new PlacesItem(bookmark); - if (item->groupType() == PlacesItem::DevicesType) { - devices.remove(item->udi()); - devicesItems.append(item); - } else { - const QUrl url = bookmark.url(); - if (missingSystemBookmarks.contains(url)) { - missingSystemBookmarks.remove(url); - - // Try to retranslate the text of system bookmarks to have translated - // items when changing the language. In case if the user has applied a custom - // text, the retranslation will fail and the users custom text is still used. - // It is important to use "KFile System Bookmarks" as context (see - // createSystemBookmarks()). - item->setText(i18nc("KFile System Bookmarks", bookmark.text().toUtf8().constData())); - item->setSystemItem(true); - } +void PlacesItemModel::onSourceModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) +{ + Q_UNUSED(roles); - switch (item->groupType()) { - case PlacesItem::PlacesType: placesItems.append(item); break; - case PlacesItem::RecentlySavedType: recentlySavedItems.append(item); break; - case PlacesItem::SearchForType: searchForItems.append(item); break; - case PlacesItem::DevicesType: - default: Q_ASSERT(false); break; - } - } + for (int r = topLeft.row(); r <= bottomRight.row(); r++) { + const QModelIndex sourceIndex = m_sourceModel->index(r, 0); + const KBookmark bookmark = m_sourceModel->bookmarkForIndex(sourceIndex); + PlacesItem *placeItem = itemFromBookmark(bookmark); + + if (placeItem && (!m_hiddenItemsShown && m_sourceModel->isHidden(sourceIndex))) { + //hide item if it became invisible + removeItem(index(placeItem)); + return; } - bookmark = root.next(bookmark); - } + if (!placeItem && (m_hiddenItemsShown || !m_sourceModel->isHidden(sourceIndex))) { + //show item if it became visible + addItemFromSourceModel(sourceIndex); + return; + } - if (!missingSystemBookmarks.isEmpty()) { - // The current bookmarks don't contain all system-bookmarks. Add the missing - // bookmarks. - foreach (const SystemBookmarkData& data, m_systemBookmarks) { - if (missingSystemBookmarks.contains(data.url)) { - PlacesItem* item = createSystemPlacesItem(data); - switch (item->groupType()) { - case PlacesItem::PlacesType: placesItems.append(item); break; - case PlacesItem::RecentlySavedType: recentlySavedItems.append(item); break; - case PlacesItem::SearchForType: searchForItems.append(item); break; - case PlacesItem::DevicesType: - default: Q_ASSERT(false); break; - } - } + 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"))); } } +} - // Create items for devices that have not been stored as bookmark yet - devicesItems.reserve(devicesItems.count() + devices.count()); - foreach (const QString& udi, devices) { - const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); - PlacesItem *item = new PlacesItem(bookmark); - devicesItems.append(item); - connect(item->signalHandler(), &PlacesItemSignalHandler::tearDownExternallyRequested, - this, &PlacesItemModel::storageTearDownExternallyRequested); +void PlacesItemModel::onSourceModelGroupHiddenChanged(KFilePlacesModel::GroupType group, bool hidden) +{ + for(const QModelIndex &sourceIndex : m_sourceModel->groupIndexes(group)) { + PlacesItem *item = placesItem(mapFromSource(sourceIndex)); + if (item) { + item->setGroupHidden(hidden); + } } +} - QList items; - items.append(placesItems); - items.append(recentlySavedItems); - items.append(searchForItems); - items.append(devicesItems); - - foreach (PlacesItem* item, items) { - if (!m_hiddenItemsShown && item->isHidden()) { - m_bookmarkedItems.append(item); - } else { - appendItem(item); +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))) { + addItemFromSourceModel(sourceIndex); } } @@@ -625,19 -835,140 +636,25 @@@ #endif } -bool PlacesItemModel::acceptBookmark(const KBookmark& bookmark, - const QSet& availableDevices) const +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 deviceAvailable = availableDevices.contains(udi); + + if (balooURLs.contains(url) && appName.isEmpty()) { + // Does not accept baloo URLS with empty appName, this came from new KIO model and will cause duplications + qCWarning(DolphinDebug) << "Ignore KIO url:" << url; + return false; + } - const bool allowedHere = (appName.isEmpty() || appName == KAboutData::applicationData().componentName() - || appName == KAboutData::applicationData().componentName() + AppNamePrefix) - && (m_fileIndexingEnabled || (url.scheme() != QLatin1String("timeline") && - url.scheme() != QLatin1String("search"))); + || appName == KAboutData::applicationData().componentName() + AppNamePrefix); - return (udi.isEmpty() && allowedHere) || deviceAvailable; -} - -PlacesItem* PlacesItemModel::createSystemPlacesItem(const SystemBookmarkData& data) -{ - KBookmark bookmark = PlacesItem::createBookmark(m_bookmarkManager, - data.text, - data.url, - data.icon); - - const QString protocol = data.url.scheme(); - if (protocol == QLatin1String("timeline") || protocol == QLatin1String("search")) { - // As long as the KFilePlacesView from kdelibs is available, the system-bookmarks - // for "Recently Saved" and "Search For" should be a setting available only - // in the Places Panel (see description of AppNamePrefix for more details). - const QString appName = KAboutData::applicationData().componentName() + AppNamePrefix; - bookmark.setMetaDataItem(QStringLiteral("OnlyInApp"), appName); - } - - PlacesItem* item = new PlacesItem(bookmark); - item->setSystemItem(true); - - // Create default view-properties for all "Search For" and "Recently Saved" bookmarks - // in case if the user has not already created custom view-properties for a corresponding - // query yet. - const bool createDefaultViewProperties = (item->groupType() == PlacesItem::SearchForType || - item->groupType() == PlacesItem::RecentlySavedType) && - !GeneralSettings::self()->globalViewProps(); - if (createDefaultViewProperties) { - ViewProperties props(convertedUrl(data.url)); - if (!props.exist()) { - const QString path = data.url.path(); - if (path == QLatin1String("/documents")) { - props.setViewMode(DolphinView::DetailsView); - props.setPreviewsShown(false); - props.setVisibleRoles({"text", "path"}); - } else if (path == QLatin1String("/images")) { - props.setViewMode(DolphinView::IconsView); - props.setPreviewsShown(true); - props.setVisibleRoles({"text", "imageSize"}); - } else if (path == QLatin1String("/audio")) { - props.setViewMode(DolphinView::DetailsView); - props.setPreviewsShown(false); - props.setVisibleRoles({"text", "artist", "album"}); - } else if (path == QLatin1String("/videos")) { - props.setViewMode(DolphinView::IconsView); - props.setPreviewsShown(true); - props.setVisibleRoles({"text"}); - } else if (data.url.scheme() == QLatin1String("timeline")) { - props.setViewMode(DolphinView::DetailsView); - props.setVisibleRoles({"text", "modificationtime"}); - } - } - } - - return item; -} - -void PlacesItemModel::createSystemBookmarks() -{ - Q_ASSERT(m_systemBookmarks.isEmpty()); - Q_ASSERT(m_systemBookmarksIndexes.isEmpty()); - - // Note: The context of the I18N_NOOP2 must be "KFile System Bookmarks". The real - // 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(QDir::homePath()), - QStringLiteral("user-home"), - I18N_NOOP2("KFile System Bookmarks", "Home"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("remote:/")), - QStringLiteral("network-workgroup"), - I18N_NOOP2("KFile System Bookmarks", "Network"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl::fromLocalFile(QStringLiteral("/")), - QStringLiteral("folder-red"), - I18N_NOOP2("KFile System Bookmarks", "Root"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("trash:/")), - QStringLiteral("user-trash"), - I18N_NOOP2("KFile System Bookmarks", "Trash"))); - - if (m_fileIndexingEnabled) { - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/today")), - QStringLiteral("go-jump-today"), - I18N_NOOP2("KFile System Bookmarks", "Today"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/yesterday")), - QStringLiteral("view-calendar-day"), - I18N_NOOP2("KFile System Bookmarks", "Yesterday"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/thismonth")), - QStringLiteral("view-calendar-month"), - I18N_NOOP2("KFile System Bookmarks", "This Month"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("timeline:/lastmonth")), - QStringLiteral("view-calendar-month"), - I18N_NOOP2("KFile System Bookmarks", "Last Month"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/documents")), - QStringLiteral("folder-text"), - I18N_NOOP2("KFile System Bookmarks", "Documents"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/images")), - QStringLiteral("folder-images"), - I18N_NOOP2("KFile System Bookmarks", "Images"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/audio")), - QStringLiteral("folder-sound"), - I18N_NOOP2("KFile System Bookmarks", "Audio Files"))); - m_systemBookmarks.append(SystemBookmarkData(QUrl(QStringLiteral("search:/videos")), - QStringLiteral("folder-videos"), - I18N_NOOP2("KFile System Bookmarks", "Videos"))); - } - - for (int i = 0; i < m_systemBookmarks.count(); ++i) { - m_systemBookmarksIndexes.insert(m_systemBookmarks[i].url, i); - } + return (udi.isEmpty() && allowedHere); } void PlacesItemModel::clear() { - m_bookmarkedItems.clear(); KStandardItemModel::clear(); } @@@ -650,16 -981,50 +667,16 @@@ void PlacesItemModel::proceedWithTearDo m_deviceToTearDown->teardown(); } -void PlacesItemModel::initializeAvailableDevices() +void PlacesItemModel::deleteItem(int index) { - QString predicate(QStringLiteral("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]" - " OR " - "[ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]" - " OR " - "OpticalDisc.availableContent & 'Audio' ]" - " OR " - "StorageAccess.ignored == false ]")); - - - if (KProtocolInfo::isKnownProtocol(QStringLiteral("mtp"))) { - predicate.prepend("["); - predicate.append(" OR PortableMediaPlayer.supportedProtocols == 'mtp']"); - } - - m_predicate = Solid::Predicate::fromString(predicate); - Q_ASSERT(m_predicate.isValid()); - - Solid::DeviceNotifier* notifier = Solid::DeviceNotifier::instance(); - connect(notifier, &Solid::DeviceNotifier::deviceAdded, this, &PlacesItemModel::slotDeviceAdded); - connect(notifier, &Solid::DeviceNotifier::deviceRemoved, this, &PlacesItemModel::slotDeviceRemoved); - - const QList& deviceList = Solid::Device::listFromQuery(m_predicate); - foreach (const Solid::Device& device, deviceList) { - m_availableDevices << device.udi(); - } + QModelIndex sourceIndex = mapToSource(index); + Q_ASSERT(sourceIndex.isValid()); + m_sourceModel->removePlace(sourceIndex); } -int PlacesItemModel::bookmarkIndex(int index) const +void PlacesItemModel::refresh() { - int bookmarkIndex = 0; - int modelIndex = 0; - while (bookmarkIndex < m_bookmarkedItems.count()) { - if (!m_bookmarkedItems[bookmarkIndex]) { - if (modelIndex == index) { - break; - } - ++modelIndex; - } - ++bookmarkIndex; - } - - return bookmarkIndex >= m_bookmarkedItems.count() ? -1 : bookmarkIndex; + m_sourceModel->refresh(); } void PlacesItemModel::hideItem(int index) @@@ -670,6 -1035,36 +687,6 @@@ } shownItem->setHidden(true); - if (m_hiddenItemsShown) { - // Removing items from the model is not allowed if all hidden - // items should be shown. - return; - } - - const int newIndex = bookmarkIndex(index); - if (newIndex >= 0) { - const KBookmark hiddenBookmark = shownItem->bookmark(); - PlacesItem* hiddenItem = new PlacesItem(hiddenBookmark); - - const PlacesItem* previousItem = placesItem(index - 1); - KBookmark previousBookmark; - if (previousItem) { - previousBookmark = previousItem->bookmark(); - } - - const bool updateBookmark = (m_bookmarkManager->root().indexOf(hiddenBookmark) >= 0); - removeItem(index); - - if (updateBookmark) { - // removeItem() also removed the bookmark from m_bookmarkManager in - // PlacesItemModel::onItemRemoved(). However for hidden items the - // bookmark should still be remembered, so readd it again: - m_bookmarkManager->root().addBookmark(hiddenBookmark); - m_bookmarkManager->root().moveBookmark(hiddenBookmark, previousBookmark); - } - - m_bookmarkedItems.insert(newIndex, hiddenItem); - } } QString PlacesItemModel::internalMimeType() const @@@ -683,7 -1078,7 +700,7 @@@ int PlacesItemModel::groupedDropIndex(i Q_ASSERT(item); int dropIndex = index; - const PlacesItem::GroupType type = item->groupType(); + const QString group = item->group(); const int itemCount = count(); if (index < 0) { @@@ -693,7 -1088,7 +710,7 @@@ // Search nearest previous item with the same group int previousIndex = -1; for (int i = dropIndex - 1; i >= 0; --i) { - if (placesItem(i)->groupType() == type) { + if (placesItem(i)->group() == group) { previousIndex = i; break; } @@@ -702,7 -1097,7 +719,7 @@@ // Search nearest next item with the same group int nextIndex = -1; for (int i = dropIndex; i < count(); ++i) { - if (placesItem(i)->groupType() == type) { + if (placesItem(i)->group() == group) { nextIndex = i; break; } @@@ -733,13 -1128,52 +750,13 @@@ bool PlacesItemModel::equalBookmarkIden } } -QUrl PlacesItemModel::createTimelineUrl(const QUrl& url) +int PlacesItemModel::mapFromSource(const QModelIndex &index) const { - // TODO: Clarify with the Baloo-team whether it makes sense - // provide default-timeline-URLs like 'yesterday', 'this month' - // and 'last month'. - QUrl timelineUrl; - - const QString path = url.toDisplayString(QUrl::PreferLocalFile); - if (path.endsWith(QLatin1String("yesterday"))) { - const QDate date = QDate::currentDate().addDays(-1); - const int year = date.year(); - const int month = date.month(); - const int day = date.day(); - timelineUrl = QUrl("timeline:/" + timelineDateString(year, month) + - '/' + timelineDateString(year, month, day)); - } else if (path.endsWith(QLatin1String("thismonth"))) { - const QDate date = QDate::currentDate(); - timelineUrl = QUrl("timeline:/" + timelineDateString(date.year(), date.month())); - } else if (path.endsWith(QLatin1String("lastmonth"))) { - const QDate date = QDate::currentDate().addMonths(-1); - timelineUrl = QUrl("timeline:/" + timelineDateString(date.year(), date.month())); - } else { - Q_ASSERT(path.endsWith(QLatin1String("today"))); - timelineUrl = url; + if (!index.isValid()) { + return -1; } - return timelineUrl; -} - -QString PlacesItemModel::timelineDateString(int year, int month, int day) -{ - QString date = QString::number(year) + '-'; - if (month < 10) { - date += '0'; - } - date += QString::number(month); - - if (day >= 1) { - date += '-'; - if (day < 10) { - date += '0'; - } - date += QString::number(day); - } - - return date; + return m_indexMap.indexOf(index); } bool PlacesItemModel::isDir(int index) const @@@ -748,38 -1182,39 +765,38 @@@ return true; } -QUrl PlacesItemModel::createSearchUrl(const QUrl& url) +KFilePlacesModel::GroupType PlacesItemModel::groupType(int row) const { - QUrl searchUrl; - -#ifdef HAVE_BALOO - const QString path = url.toDisplayString(QUrl::PreferLocalFile); - if (path.endsWith(QLatin1String("documents"))) { - searchUrl = searchUrlForType(QStringLiteral("Document")); - } else if (path.endsWith(QLatin1String("images"))) { - searchUrl = searchUrlForType(QStringLiteral("Image")); - } else if (path.endsWith(QLatin1String("audio"))) { - searchUrl = searchUrlForType(QStringLiteral("Audio")); - } else if (path.endsWith(QLatin1String("videos"))) { - searchUrl = searchUrlForType(QStringLiteral("Video")); - } else { - Q_ASSERT(false); - } -#else - Q_UNUSED(url); -#endif + return m_sourceModel->groupType(mapToSource(row)); +} + +bool PlacesItemModel::isGroupHidden(KFilePlacesModel::GroupType type) const +{ + return m_sourceModel->isGroupHidden(type); +} - return searchUrl; +void PlacesItemModel::setGroupHidden(KFilePlacesModel::GroupType type, bool hidden) +{ + return m_sourceModel->setGroupHidden(type, hidden); } -#ifdef HAVE_BALOO -QUrl PlacesItemModel::searchUrlForType(const QString& type) +QModelIndex PlacesItemModel::mapToSource(int row) const { - Baloo::Query query; - query.addType(type); + return m_indexMap.value(row); +} - return query.toSearchUrl(); +PlacesItem *PlacesItemModel::itemFromBookmark(const KBookmark &bookmark) const +{ + const QString id = bookmarkId(bookmark); + for (int i = 0, iMax = count(); i < iMax; i++) { + PlacesItem *item = placesItem(i); + const KBookmark itemBookmark = item->bookmark(); + if (bookmarkId(itemBookmark) == id) { + return item; + } + } + return nullptr; } -#endif #ifdef PLACESITEMMODEL_DEBUG void PlacesItemModel::showModelState()