diff --git a/autotests/kfileplacesmodeltest.cpp b/autotests/kfileplacesmodeltest.cpp --- a/autotests/kfileplacesmodeltest.cpp +++ b/autotests/kfileplacesmodeltest.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -96,6 +97,7 @@ QMap m_interfacesMap; QTemporaryDir m_tmpHome; + bool m_hasRecentlyUsedKio; }; static QString bookmarksFile() @@ -128,6 +130,8 @@ qputenv("SOLID_FAKEHW", QFile::encodeName(fakeHw)); m_places = new KFilePlacesModel(); m_places2 = new KFilePlacesModel(); + + m_hasRecentlyUsedKio = qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")); } void KFilePlacesModelTest::cleanupTestCase() @@ -195,9 +199,10 @@ void KFilePlacesModelTest::testInitialState() { - QCOMPARE(m_places->rowCount(), 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items + QCOMPARE(m_places->rowCount(), m_hasRecentlyUsedKio ? 5 : 3); // when the xbel file is empty, KFilePlacesModel fills it with 3 default items + // 4 when ioslave recentlyused:/ is installed QCoreApplication::processEvents(); // Devices have a delayed loading - QCOMPARE(m_places->rowCount(), 8); + QCOMPARE(m_places->rowCount(), m_hasRecentlyUsedKio ? 10 : 8); } static const QStringList initialListOfPlaces() @@ -210,6 +215,16 @@ return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); } +static const QStringList initialListOfRecent() +{ + auto list = QStringList(); + if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused"))) { + list << QStringLiteral("recentlyused:/files"); + list << QStringLiteral("recentlyused:/locations"); + } + return list; +} + static const QStringList initialListOfDevices() { return QStringList() << QStringLiteral("/foreign"); @@ -224,6 +239,7 @@ { return QStringList() << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); } @@ -395,6 +411,7 @@ QStringList urls; urls << QStringLiteral("trash:/") << QDir::homePath() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); @@ -416,6 +433,7 @@ urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -452,6 +470,7 @@ QStringList urls; urls << QStringLiteral("trash:/") << QDir::homePath() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -474,6 +493,7 @@ urls.clear(); urls << QDir::homePath() << QStringLiteral("trash:/") << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -510,6 +530,7 @@ QStringList urls; urls << initialListOfPlaces() << QStringLiteral("/home/foo") << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -531,6 +552,7 @@ urls.clear(); urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -550,6 +572,7 @@ urls.clear(); urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -567,13 +590,14 @@ urls.clear(); urls << QDir::homePath() << QStringLiteral("/mnt/foo") << QStringLiteral("trash:/") << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 0); QCOMPARE(spy_removed.count(), 0); - QCOMPARE(spy_changed.count(), 9); + QCOMPARE(spy_changed.count(), m_hasRecentlyUsedKio ? 11 : 9); args = spy_changed[2]; QCOMPARE(args.at(0).toModelIndex(), m_places->index(2, 0)); QCOMPARE(args.at(1).toModelIndex(), m_places->index(2, 0)); @@ -584,6 +608,7 @@ urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -599,6 +624,7 @@ urls.clear(); urls << QDir::homePath() << QStringLiteral("/home/foo") << QStringLiteral("trash:/") << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); @@ -623,29 +649,31 @@ QStringList urls; urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 0); QCOMPARE(spy_removed.count(), 1); args = spy_removed.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 6); - QCOMPARE(args.at(2).toInt(), 6); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 1); args = spy_inserted.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 6); - QCOMPARE(args.at(2).toInt(), 6); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); QCOMPARE(spy_removed.count(), 0); // Move the device in the list, and check that it memorizes the position across plug/unplug @@ -655,7 +683,8 @@ KBookmark before_floppy; KBookmark device = root.first(); // The device we'll move is the 6th bookmark - for (int i = 0; i < 5; i++) { + const int count = m_hasRecentlyUsedKio ? 7 : 5; + for (int i = 0; i < count; i++) { if (i == 2) { // store item before to be able to move it back to original position device = before_floppy = root.next(device); @@ -670,73 +699,77 @@ urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 1); args = spy_inserted.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 6); - QCOMPARE(args.at(2).toInt(), 6); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); QCOMPARE(spy_removed.count(), 1); args = spy_removed.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 5); - QCOMPARE(args.at(2).toInt(), 5); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); fakeManager()->call(QStringLiteral("unplug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 0); QCOMPARE(spy_removed.count(), 1); args = spy_removed.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 5); - QCOMPARE(args.at(2).toInt(), 5); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); fakeManager()->call(QStringLiteral("plug"), "/org/kde/solid/fakehw/volume_part1_size_993284096"); urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/cdrom"); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 1); args = spy_inserted.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 5); - QCOMPARE(args.at(2).toInt(), 5); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); QCOMPARE(spy_removed.count(), 0); - KBookmark sixth = root.first(); - for (int i = 0; i < 5; i++) { - sixth = root.next(sixth); + KBookmark seventh = root.first(); + for (int i = 0; i < count; i++) { + seventh = root.next(seventh); } - root.moveBookmark(device, sixth); + root.moveBookmark(device, seventh); bookmarkManager->emitChanged(root); urls.clear(); urls << initialListOfPlaces() << initialListOfShared() + << initialListOfRecent() << initialListOfDevices() << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); QCOMPARE(spy_inserted.count(), 1); args = spy_inserted.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 6); - QCOMPARE(args.at(2).toInt(), 6); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8 : 6); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8 : 6); QCOMPARE(spy_removed.count(), 1); args = spy_removed.takeFirst(); QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); - QCOMPARE(args.at(1).toInt(), 5); - QCOMPARE(args.at(2).toInt(), 5); + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 7 : 5); + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 7 : 5); } void KFilePlacesModelTest::testDeviceSetupTeardown() @@ -748,15 +781,15 @@ QCOMPARE(spy_changed.count(), 1); args = spy_changed.takeFirst(); - QCOMPARE(args.at(0).toModelIndex().row(), 6); - QCOMPARE(args.at(1).toModelIndex().row(), 6); + QCOMPARE(args.at(0).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); + QCOMPARE(args.at(1).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); fakeDevice(QStringLiteral("/org/kde/solid/fakehw/volume_part1_size_993284096/StorageAccess"))->call(QStringLiteral("setup")); QCOMPARE(spy_changed.count(), 1); args = spy_changed.takeFirst(); - QCOMPARE(args.at(0).toModelIndex().row(), 6); - QCOMPARE(args.at(1).toModelIndex().row(), 6); + QCOMPARE(args.at(0).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); + QCOMPARE(args.at(1).toModelIndex().row(), m_hasRecentlyUsedKio ? 8 : 6); } void KFilePlacesModelTest::testEnableBaloo() @@ -811,7 +844,9 @@ QStringList urls; urls << QDir::homePath() << QStringLiteral("trash:/") // places << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") - << url.toString() << QStringLiteral("/foreign") + << url.toString() + << initialListOfRecent() + << QStringLiteral("/foreign") << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); CHECK_PLACES_URLS(urls); @@ -929,19 +964,27 @@ QTest::addColumn("expectedIconName"); // places - QTest::newRow("Places - Home") << m_places->index(0, 0) + int index = 0; + QTest::newRow("Places - Home") << m_places->index(index++, 0) << QStringLiteral("user-home"); - QTest::newRow("Places - Trash") << m_places->index(1, 0) + QTest::newRow("Places - Trash") << m_places->index(index++, 0) << QStringLiteral("user-trash"); - QTest::newRow("Remote - Network") << m_places->index(2, 0) + + QTest::newRow("Remote - Network") << m_places->index(index++, 0) << QStringLiteral("folder-network"); - QTest::newRow("Devices - Nfs") << m_places->index(3, 0) + QTest::newRow("Devices - Nfs") << m_places->index(index++, 0) << QStringLiteral("hwinfo"); - QTest::newRow("Devices - foreign") << m_places->index(4, 0) + if (m_hasRecentlyUsedKio) { + QTest::newRow("Recent Files") << m_places->index(index++, 0) + << QStringLiteral("document-open-recent"); + QTest::newRow("Recent Locations") << m_places->index(index++, 0) + << QStringLiteral("folder-open-recent"); + } + QTest::newRow("Devices - foreign") << m_places->index(index++, 0) << QStringLiteral("blockdevice"); - QTest::newRow("Devices - Floppy") << m_places->index(5, 0) + QTest::newRow("Devices - Floppy") << m_places->index(index++, 0) << QStringLiteral("blockdevice"); - QTest::newRow("Devices - cdrom") << m_places->index(6, 0) + QTest::newRow("Devices - cdrom") << m_places->index(index++, 0) << QStringLiteral("blockdevice"); } @@ -1004,24 +1047,24 @@ QCOMPARE(placesUrls(), urls); rowsMoved.clear(); - QVERIFY(m_places->movePlace(7, 5)); - urls.move(7, 5); + QVERIFY(m_places->movePlace(m_hasRecentlyUsedKio ? 8: 7, m_hasRecentlyUsedKio ? 6 : 5)); + urls.move(m_hasRecentlyUsedKio ? 8: 7, m_hasRecentlyUsedKio ? 6 : 5); QTRY_COMPARE(rowsMoved.count(), 1); args = rowsMoved.takeFirst(); - QCOMPARE(args.at(1).toInt(), 7); // start - QCOMPARE(args.at(2).toInt(), 7); // end - QCOMPARE(args.at(4).toInt(), 5); // row (destination) + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 8: 7); // start + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 8: 7); // end + QCOMPARE(args.at(4).toInt(), m_hasRecentlyUsedKio ? 6: 4); // row (destination) QCOMPARE(placesUrls(), urls); rowsMoved.clear(); // move it back - QVERIFY(m_places->movePlace(5, 8)); - urls.move(5, 7); + QVERIFY(m_places->movePlace(m_hasRecentlyUsedKio ? 6 : 5, m_hasRecentlyUsedKio ? 9 : 8)); + urls.move(m_hasRecentlyUsedKio ? 6 : 5, m_hasRecentlyUsedKio ? 8 : 7); QTRY_COMPARE(rowsMoved.count(), 1); args = rowsMoved.takeFirst(); - QCOMPARE(args.at(1).toInt(), 5); // start - QCOMPARE(args.at(2).toInt(), 5); // end - QCOMPARE(args.at(4).toInt(), 8); // row (destination) + QCOMPARE(args.at(1).toInt(), m_hasRecentlyUsedKio ? 6 : 5); // start + QCOMPARE(args.at(2).toInt(), m_hasRecentlyUsedKio ? 6 : 5); // end + QCOMPARE(args.at(4).toInt(), m_hasRecentlyUsedKio ? 9 : 8); // row (destination) QCOMPARE(placesUrls(), urls); rowsMoved.clear(); @@ -1040,7 +1083,11 @@ QCOMPARE(m_places->hiddenCount(), 0); QStringList urls; - urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); + urls << initialListOfPlaces() + << initialListOfShared() + << initialListOfRecent() + << initialListOfDevices() + << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); QVector indexesHidden; @@ -1107,7 +1154,11 @@ QCOMPARE(m_places->hiddenCount(), 0); QStringList urls; - urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); + urls << initialListOfPlaces() + << initialListOfShared() + << initialListOfRecent() + << initialListOfDevices() + << initialListOfRemovableDevices(); CHECK_PLACES_URLS(urls); QModelIndex firstIndexHidden = m_places->index(0,0); @@ -1145,7 +1196,7 @@ QVERIFY(m_places->groupIndexes(KFilePlacesModel::UnknownType).isEmpty()); QVERIFY(m_places->isGroupHidden(KFilePlacesModel::PlacesType)); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); - QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), 0); + QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), m_hasRecentlyUsedKio ? 2 : 0); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); @@ -1157,7 +1208,7 @@ // Make sure that hidden place group doesn't change model QVERIFY(!m_places->isGroupHidden(KFilePlacesModel::PlacesType)); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::PlacesType).count(), initialListOfPlaces().count()); - QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), 0); + QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RecentlySavedType).count(), m_hasRecentlyUsedKio ? 2 : 0); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::SearchForType).count(), 0); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::DevicesType).count(), initialListOfDevices().count()); QCOMPARE(m_places->groupIndexes(KFilePlacesModel::RemovableDevicesType).count(), initialListOfRemovableDevices().count()); diff --git a/autotests/kfileplacesviewtest.cpp b/autotests/kfileplacesviewtest.cpp --- a/autotests/kfileplacesviewtest.cpp +++ b/autotests/kfileplacesviewtest.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -76,19 +77,24 @@ QTest::addColumn("row"); QTest::addColumn("expectedUrl"); + int idx = 3; + if (KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused"))) { + QTest::newRow("Recently Used") << idx++ << QStringLiteral("recentlyused:/files"); + QTest::newRow("Recently Used") << idx++ << QStringLiteral("recentlyused:/locations"); + } const QDate currentDate = QDate::currentDate(); const QDate yesterdayDate = currentDate.addDays(-1); - QTest::newRow("Today") << 3 << QStringLiteral("timeline:/today"); - QTest::newRow("Yesterday") << 4 << QString("timeline:/%1-%2/%1-%2-%3") + QTest::newRow("Today") << idx++ << QStringLiteral("timeline:/today"); + QTest::newRow("Yesterday") << idx++ << QString("timeline:/%1-%2/%1-%2-%3") .arg(yesterdayDate.year()) .arg(yesterdayDate.month(), 2, 10, QChar('0')) .arg(yesterdayDate.day(), 2, 10, QChar('0')); // search - QTest::newRow("Documents") << 5 << QStringLiteral("baloosearch:/documents"); - QTest::newRow("Images") << 6 << QStringLiteral("baloosearch:/images"); - QTest::newRow("Audio Files") << 7 << QStringLiteral("baloosearch:/audio"); - QTest::newRow("Videos") << 8 << QStringLiteral("baloosearch:/videos"); + QTest::newRow("Documents") << idx++ << QStringLiteral("baloosearch:/documents"); + QTest::newRow("Images") << idx++ << QStringLiteral("baloosearch:/images"); + QTest::newRow("Audio Files") << idx++ << QStringLiteral("baloosearch:/audio"); + QTest::newRow("Videos") << idx++ << QStringLiteral("baloosearch:/videos"); } void KFilePlacesViewTest::testUrlChanged() diff --git a/src/filewidgets/kfileplacesitem.cpp b/src/filewidgets/kfileplacesitem.cpp --- a/src/filewidgets/kfileplacesitem.cpp +++ b/src/filewidgets/kfileplacesitem.cpp @@ -110,7 +110,7 @@ m_groupName = i18nc("@item", "Remote"); break; case KFilePlacesModel::RecentlySavedType: - m_groupName = i18nc("@item", "Recently Saved"); + m_groupName = i18nc("@item The place group section name for recent dynamic lists", "Recent"); break; case KFilePlacesModel::SearchForType: m_groupName = i18nc("@item", "Search For"); @@ -151,7 +151,8 @@ { if (!isDevice()) { const QString protocol = bookmark().url().scheme(); - if (protocol == QLatin1String("timeline")) { + if (protocol == QLatin1String("timeline") || + protocol == QLatin1String("recentlyused")) { return KFilePlacesModel::RecentlySavedType; } diff --git a/src/filewidgets/kfileplacesmodel.h b/src/filewidgets/kfileplacesmodel.h --- a/src/filewidgets/kfileplacesmodel.h +++ b/src/filewidgets/kfileplacesmodel.h @@ -130,6 +130,13 @@ * If the index is not valid, a default KBookmark instance is returned. */ KBookmark bookmarkForIndex(const QModelIndex &index) const; + + /** + * @return The KBookmark instance of the place with url @p searchUrl. + * If the bookmark corresponding to searchUrl is not found, a default KBookmark instance is returned. + * @since 5.63 + */ + KBookmark bookmarkForUrl(const QUrl &searchUrl) const; /** * @return The group type of the place at index @p index. diff --git a/src/filewidgets/kfileplacesmodel.cpp b/src/filewidgets/kfileplacesmodel.cpp --- a/src/filewidgets/kfileplacesmodel.cpp +++ b/src/filewidgets/kfileplacesmodel.cpp @@ -248,6 +248,19 @@ bool isBalooUrl(const QUrl &url) const; }; +KBookmark KFilePlacesModel::bookmarkForUrl(const QUrl &searchUrl) const +{ + KBookmarkGroup root = d->bookmarkManager->root(); + KBookmark current = root.first(); + while (!current.isNull()) { + if (current.url() == searchUrl) { + return current; + } + current = root.next(current); + } + return KBookmark(); +} + KFilePlacesModel::KFilePlacesModel(const QString &alternativeApplicationName, QObject *parent) : QAbstractItemModel(parent), d(new Private(this)) { @@ -317,16 +330,42 @@ d->bookmarkManager->saveAs(file); } + // Add a Recently Used entry if available (it comes from kio-extras) + if (qEnvironmentVariableIsSet("KDE_FULL_SESSION") && KProtocolInfo::isKnownProtocol(QStringLiteral("recentlyused")) && + root.metaDataItem(QStringLiteral("withRecentlyUsed")) != QLatin1String("true")) { + + root.setMetaDataItem(QStringLiteral("withRecentlyUsed"), QStringLiteral("true")); + + KBookmark recentFilesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, + QStringLiteral("Recent Files"), I18N_NOOP2("KFile System Bookmarks", "Recent Files"), + QUrl(QStringLiteral("recentlyused:/files")), QStringLiteral("document-open-recent")); + + KBookmark recentDirectoriesBookmark = KFilePlacesItem::createSystemBookmark(d->bookmarkManager, + QStringLiteral("Recent Locations"), I18N_NOOP2("KFile System Bookmarks", "Recent Locations"), + QUrl(QStringLiteral("recentlyused:/locations")), QStringLiteral("folder-open-recent")); + + setDefaultMetadataItemForGroup(RecentlySavedType); + + // Move The recently used bookmarks below the trash, making it the first element in the Recent group + KBookmark trashBookmark = bookmarkForUrl(QUrl("trash:/")); + if (!trashBookmark.isNull()) { + root.moveBookmark(recentFilesBookmark, trashBookmark); + root.moveBookmark(recentDirectoriesBookmark, recentFilesBookmark); + } + + d->bookmarkManager->save(); + } + // if baloo is enabled, add new urls even if the bookmark file is not empty if (d->fileIndexingEnabled && root.metaDataItem(QStringLiteral("withBaloo")) != QLatin1String("true")) { root.setMetaDataItem(QStringLiteral("withBaloo"), QStringLiteral("true")); KFilePlacesItem::createSystemBookmark(d->bookmarkManager, - QStringLiteral("Today"), I18N_NOOP2("KFile System Bookmarks", "Today"), + QStringLiteral("Modified Today"), I18N_NOOP2("KFile System Bookmarks", "Today"), QUrl(QStringLiteral("timeline:/today")), QStringLiteral("go-jump-today")); KFilePlacesItem::createSystemBookmark(d->bookmarkManager, - QStringLiteral("Yesterday"), I18N_NOOP2("KFile System Bookmarks", "Yesterday"), + QStringLiteral("Modified Yesterday"), I18N_NOOP2("KFile System Bookmarks", "Yesterday"), QUrl(QStringLiteral("timeline:/yesterday")), QStringLiteral("view-calendar-day")); KFilePlacesItem::createSystemBookmark(d->bookmarkManager, QStringLiteral("Documents"), I18N_NOOP2("KFile System Bookmarks", "Documents"),