diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,14 @@ TYPE OPTIONAL PURPOSE "For tracking which folders are frequently accessed on a Plasma desktop" ) +find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS + ActivitiesStats +) +set_package_properties(KF5ActivitiesStats PROPERTIES DESCRIPTION "KActivities Stats libraries" + URL "https://www.kde.org" + TYPE OPTIONAL + PURPOSE "For tracking which folders are frequently accessed on a Plasma desktop" + ) find_package(Phonon4Qt5 CONFIG REQUIRED) @@ -100,6 +108,9 @@ if (KF5Activities_FOUND) set(HAVE_KACTIVITIES TRUE) endif() +if (KF5ActivitiesStats_FOUND) + set(HAVE_KACTIVITIES_STATS TRUE) +endif() if (KF5Baloo_FOUND AND KF5BalooWidgets_FOUND AND KF5FileMetaData_FOUND) message(STATUS "Baloo packages are found") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ configure_file(config-baloo.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-baloo.h) configure_file(config-kactivities.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kactivities.h) +configure_file(config-kactivities-stats.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kactivities-stats.h) configure_file(config-terminal.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-terminal.h) @@ -289,6 +290,13 @@ ) endif() +if (HAVE_KACTIVITIES_STATS) + target_link_libraries( + dolphinstatic + KF5::ActivitiesStats + ) +endif() + set(dolphin_SRCS dbusinterface.cpp main.cpp diff --git a/src/config-kactivities-stats.h.cmake b/src/config-kactivities-stats.h.cmake new file mode 100644 --- /dev/null +++ b/src/config-kactivities-stats.h.cmake @@ -0,0 +1 @@ +#cmakedefine HAVE_KACTIVITIES_STATS diff --git a/src/dolphincontextmenu.h b/src/dolphincontextmenu.h --- a/src/dolphincontextmenu.h +++ b/src/dolphincontextmenu.h @@ -20,6 +20,8 @@ #ifndef DOLPHINCONTEXTMENU_H #define DOLPHINCONTEXTMENU_H +#include "config-kactivities-stats.h" + #include #include @@ -149,6 +151,7 @@ TrashContext = 2, TimelineContext = 4, SearchContext = 8, + RecenlyUsedContext = 16 }; QPoint m_pos; @@ -170,7 +173,8 @@ DolphinRemoveAction* m_removeAction; // Action that represents either 'Move To Trash' or 'Delete' void addDirectoryItemContextMenu(KFileItemActions &fileItemActions); - + void addOpenParentFolderActionsContextMenu(); + void addForgetRecentlyUsedAction(const KFileItem &item); }; #endif diff --git a/src/dolphincontextmenu.cpp b/src/dolphincontextmenu.cpp --- a/src/dolphincontextmenu.cpp +++ b/src/dolphincontextmenu.cpp @@ -54,6 +54,11 @@ #include #include +#ifdef HAVE_KACTIVITIES_STATS +#include +#include +#endif + DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, const KFileItem& fileInfo, @@ -101,6 +106,8 @@ m_context |= SearchContext; } else if (scheme == QLatin1String("timeline")) { m_context |= TimelineContext; + } else if (scheme == QLatin1String("recentlyused")) { + m_context |= RecenlyUsedContext; } if (!m_fileInfo.isNull() && !m_selectedItems.isEmpty()) { @@ -218,13 +225,61 @@ addSeparator(); } +void DolphinContextMenu::addForgetRecentlyUsedAction(const KFileItem &item) { + Q_UNUSED(item) +#ifdef HAVE_KACTIVITIES_STATS + const auto forgetAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-clear-history")), + i18nc("@action:inmenu", + "Forget item"), + this); + connect(forgetAction, &QAction::triggered, this, [=] (){ + KActivities::Stats::forgetResource(KActivities::Stats::Terms::Activity::any(), + KActivities::Stats::Terms::Agent::any(), + item.localPath() + ); + // refresh the recentlyused view + m_mainWindow->activeViewContainer()->reload(); + }); + addAction(forgetAction); +#endif +} + +void DolphinContextMenu::addOpenParentFolderActionsContextMenu() +{ + const auto openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), + i18nc("@action:inmenu", + "Open Path"), + this); + connect(openParentAction, &QAction::triggered, this, [=] (){ + m_command = OpenParentFolder; + }); + addAction(openParentAction); + + const auto openParentInNewWindowAction = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), + i18nc("@action:inmenu", + "Open Path in New Window"), + this); + connect(openParentInNewWindowAction, &QAction::triggered, this, [=] (){ + m_command = OpenParentFolderInNewWindow; + }); + addAction(openParentInNewWindowAction); + + const auto openParentInNewTabAction = new QAction(QIcon::fromTheme(QStringLiteral("tab-new")), + i18nc("@action:inmenu", + "Open Path in New Tab"), + this); + connect(openParentInNewTabAction, &QAction::triggered, this, [=] (){ + m_command = OpenParentFolderInNewTab; + }); + addAction(openParentInNewTabAction); + + addSeparator(); +} + void DolphinContextMenu::openItemContextMenu() { Q_ASSERT(!m_fileInfo.isNull()); - QAction* openParentAction = nullptr; - QAction* openParentInNewWindowAction = nullptr; - QAction* openParentInNewTabAction = nullptr; const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); KFileItemActions fileItemActions; @@ -235,35 +290,18 @@ // single files if (m_fileInfo.isDir()) { addDirectoryItemContextMenu(fileItemActions); - } else if (m_context & TimelineContext || m_context & SearchContext) { - addOpenWithActions(fileItemActions); - - openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), - i18nc("@action:inmenu", - "Open Path"), - this); - addAction(openParentAction); - - openParentInNewWindowAction = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), - i18nc("@action:inmenu", - "Open Path in New Window"), - this); - addAction(openParentInNewWindowAction); - - openParentInNewTabAction = new QAction(QIcon::fromTheme(QStringLiteral("tab-new")), - i18nc("@action:inmenu", - "Open Path in New Tab"), - this); - addAction(openParentInNewTabAction); - - addSeparator(); } else { + // Insert 'Open With" entries addOpenWithActions(fileItemActions); - } - if (m_fileInfo.isLink()) { - addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_target"))); - addSeparator(); + + if (m_context & TimelineContext || m_context & SearchContext || m_context & RecenlyUsedContext) { + addOpenParentFolderActionsContextMenu(); + } + if (m_fileInfo.isLink()) { + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("show_target"))); + addSeparator(); + } } } else { // multiple files @@ -286,6 +324,10 @@ insertDefaultItemActions(selectedItemsProps); + if (m_context & RecenlyUsedContext) { + addForgetRecentlyUsedAction(m_selectedItems.at(0)); + } + // insert 'Add to Places' entry if appropriate if (m_selectedItems.count() == 1) { if (m_fileInfo.isDir()) { @@ -316,15 +358,6 @@ addAction(propertiesAction); QAction* activatedAction = exec(m_pos); - if (activatedAction) { - if (activatedAction == openParentAction) { - m_command = OpenParentFolder; - } else if (activatedAction == openParentInNewWindowAction) { - m_command = OpenParentFolderInNewWindow; - } else if (activatedAction == openParentInNewTabAction) { - m_command = OpenParentFolderInNewTab; - } - } } void DolphinContextMenu::openViewportContextMenu()