diff --git a/autotests/kfileplacesmodeltest.cpp b/autotests/kfileplacesmodeltest.cpp --- a/autotests/kfileplacesmodeltest.cpp +++ b/autotests/kfileplacesmodeltest.cpp @@ -68,6 +68,7 @@ void testDevicePlugging(); void testDragAndDrop(); void testDeviceSetupTeardown(); + void testPlaceGroupHidden(); private: QStringList placesUrls() const; @@ -79,6 +80,7 @@ // actually supposed to work across processes, // but much harder to test + bool isFileIndexingEnabled; QMap m_interfacesMap; }; @@ -96,9 +98,10 @@ QFile::remove(bookmarksFile()); // disable baloo + isFileIndexingEnabled = true; KConfig config(QStringLiteral("baloofilerc")); KConfigGroup basicSettings = config.group("Basic Settings"); - basicSettings.writeEntry("Indexing-Enabled", false); + basicSettings.writeEntry("Indexing-Enabled", isFileIndexingEnabled); config.sync(); qRegisterMetaType(); @@ -189,6 +192,18 @@ return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); } +static const QStringList fileIndexingEnabledGroupLists() +{ + return QStringList() << QStringLiteral("timeline:/today") << QStringLiteral("timeline:/yesterday") << QStringLiteral("timeline:/thismonth") << QStringLiteral("timeline:/lastmonth") + << QStringLiteral("search:/documents") << QStringLiteral("search:/images") << QStringLiteral("search:/audio") << QStringLiteral("search:/videos"); +} + + +static const QStringList fileIndexingEnabledGroupStateLists() +{ + return QStringList() << QStringLiteral("groupstate:/places") << QStringLiteral("groupstate:/search") << QStringLiteral("groupstate:/timeline"); +} + static const QStringList initialListOfUrls() { return QStringList() << initalListOfPlaces() @@ -743,6 +758,49 @@ QCOMPARE(args.at(1).toModelIndex().row(), 7); } +void KFilePlacesModelTest::testPlaceGroupHidden() +{ + if (!isFileIndexingEnabled) + return; + + // GIVEN + for (int row = 0; row < m_places->rowCount(); ++row) { + QModelIndex index = m_places->index(row, 0); + QVERIFY(!m_places->isHidden(index)); + } + + QStringList urls; + urls << QDir::homePath() << QStringLiteral("remote:/") << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/") + << fileIndexingEnabledGroupLists() << initalListOfRemovableDevices() + << initalListOfDevices() << fileIndexingEnabledGroupStateLists(); + CHECK_PLACES_URLS(urls); + + QVector indexesHidden; + QList args; + QSignalSpy spy(m_places, SIGNAL(dataChanged(QModelIndex,QModelIndex))); + + // WHEN + m_places->setPlaceGroupHidden(KFilePlacesItem::RecentlySavedType, true); + + // THEN + for (int row = 0; row < m_places->rowCount(); ++row) { + QModelIndex index = m_places->index(row, 0); + + if (m_places->groupType(index) == KFilePlacesItem::RecentlySavedType) { + QVERIFY(m_places->isHidden(index)); + indexesHidden << index; + } + } + + QCOMPARE(spy.count(), 4); + QCOMPARE(indexesHidden.count(), 4); + for (int i = 0; i< spy.count(); ++i) { + args = spy.takeFirst(); + QCOMPARE(args.at(0).toModelIndex(), indexesHidden.at(i)); + QCOMPARE(args.at(1).toModelIndex(), indexesHidden.at(i)); + } +} + QTEST_MAIN(KFilePlacesModelTest) #include "kfileplacesmodeltest.moc" diff --git a/src/filewidgets/kfileplacesitem.cpp b/src/filewidgets/kfileplacesitem.cpp --- a/src/filewidgets/kfileplacesitem.cpp +++ b/src/filewidgets/kfileplacesitem.cpp @@ -117,6 +117,11 @@ break; case RemovableDeviceType: m_groupName = i18nc("@item", "Removable Devices"); + case GroupStateType: + m_groupName = i18nc("@item", "GroupState"); + break; + case UnknownType: + Q_ASSERT(false); break; default: Q_UNREACHABLE(); @@ -159,6 +164,10 @@ return DevicesType; } + if (protocol == (QLatin1String("groupstate"))) { + return GroupStateType; + } + return PlacesType; } diff --git a/src/filewidgets/kfileplacesitem_p.h b/src/filewidgets/kfileplacesitem_p.h --- a/src/filewidgets/kfileplacesitem_p.h +++ b/src/filewidgets/kfileplacesitem_p.h @@ -45,10 +45,12 @@ enum GroupType { PlacesType, - SearchForType, RecentlySavedType, + SearchForType, DevicesType, - RemovableDeviceType + RemovableDeviceType, + GroupStateType, + UnknownType }; KFilePlacesItem(KBookmarkManager *manager, diff --git a/src/filewidgets/kfileplacesmodel.h b/src/filewidgets/kfileplacesmodel.h --- a/src/filewidgets/kfileplacesmodel.h +++ b/src/filewidgets/kfileplacesmodel.h @@ -21,6 +21,7 @@ #define KFILEPLACESMODEL_H #include "kiofilewidgets_export.h" +#include "kfileplacesitem_p.h" #include #include @@ -62,6 +63,7 @@ bool isDevice(const QModelIndex &index) const; Solid::Device deviceForIndex(const QModelIndex &index) const; KBookmark bookmarkForIndex(const QModelIndex &index) const; + KFilePlacesItem::GroupType groupType(const QModelIndex &index) const; QAction *teardownActionForIndex(const QModelIndex &index) const; QAction *ejectActionForIndex(const QModelIndex &index) const; @@ -74,6 +76,7 @@ void editPlace(const QModelIndex &index, const QString &text, const QUrl &url, const QString &iconName = QString(), const QString &appName = QString()); void removePlace(const QModelIndex &index) const; void setPlaceHidden(const QModelIndex &index, bool hidden); + void setPlaceGroupHidden(const KFilePlacesItem::GroupType type, bool hidden); int hiddenCount() const; diff --git a/src/filewidgets/kfileplacesmodel.cpp b/src/filewidgets/kfileplacesmodel.cpp --- a/src/filewidgets/kfileplacesmodel.cpp +++ b/src/filewidgets/kfileplacesmodel.cpp @@ -178,6 +178,27 @@ QStringLiteral("Videos"), I18N_NOOP2("KFile System Bookmarks", "Videos"), QUrl(QStringLiteral("search:/videos")), QStringLiteral("folder-videos")); + // We add the bookmarks representing the group states which holds the hidden state + KBookmark placesGroup = KFilePlacesItem::createSystemBookmark( + d->bookmarkManager, + QStringLiteral("Places"), I18N_NOOP2("KFile System Bookmarks", "Places"), + QUrl(QStringLiteral("groupstate:/places")), QStringLiteral("user-places")); + + KBookmark searchForGroup = KFilePlacesItem::createSystemBookmark( + d->bookmarkManager, + QStringLiteral("Search For"), I18N_NOOP2("KFile System Bookmarks", "Search For"), + QUrl("groupstate:/search"), QStringLiteral("user-search-for")); + + KBookmark recentlySavedGroup = KFilePlacesItem::createSystemBookmark( + d->bookmarkManager, + QStringLiteral("Recently Saved"), I18N_NOOP2("KFile System Bookmarks", "Recently Saved"), + QUrl("groupstate:/timeline"), QStringLiteral("user-recently-saved")); + + const bool areGroupHiddenByDefault = false; + placesGroup.setMetaDataItem(QStringLiteral("IsHidden"), (areGroupHiddenByDefault ? QStringLiteral("true") : QStringLiteral("false"))); + searchForGroup.setMetaDataItem(QStringLiteral("IsHidden"), (areGroupHiddenByDefault ? QStringLiteral("true") : QStringLiteral("false"))); + recentlySavedGroup.setMetaDataItem(QStringLiteral("IsHidden"), (areGroupHiddenByDefault ? QStringLiteral("true") : QStringLiteral("false"))); + d->bookmarkManager->save(); } @@ -278,6 +299,16 @@ } } +KFilePlacesItem::GroupType KFilePlacesModel::groupType(const QModelIndex &index) const +{ + if (!index.isValid()) { + return KFilePlacesItem::UnknownType; + } + + KFilePlacesItem *item = static_cast(index.internalPointer()); + return item->groupType(); +} + QVariant KFilePlacesModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) { @@ -810,6 +841,19 @@ emit dataChanged(index, index); } +void KFilePlacesModel::setPlaceGroupHidden(const KFilePlacesItem::GroupType type, bool hidden) +{ + for (int row = 0; row < rowCount(); ++row) { + const QModelIndex current = index(row, 0); + + if (groupType(current) == type) { + if ( (hidden && !isHidden(current)) || (!hidden && isHidden(current)) ) { + setPlaceHidden(current, hidden); + } + } + } +} + int KFilePlacesModel::hiddenCount() const { int rows = rowCount();