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 @@ -146,7 +148,10 @@ { NoContext = 0, ItemContext = 1, - TrashContext = 2 + TrashContext = 2, + TimelineContext = 4, + SearchContext = 8, + RecenlyUsedContext = 16 }; QPoint m_pos; @@ -167,6 +172,9 @@ Command m_command; 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 @@ -55,6 +55,11 @@ #include #include +#ifdef HAVE_KACTIVITIES_STATS +#include +#include +#endif + DolphinContextMenu::DolphinContextMenu(DolphinMainWindow* parent, const QPoint& pos, const KFileItem& fileInfo, @@ -95,8 +100,15 @@ DolphinContextMenu::Command DolphinContextMenu::open() { // get the context information - if (m_baseUrl.scheme() == QLatin1String("trash")) { + const auto scheme = m_baseUrl.scheme(); + if (scheme == QLatin1String("trash")) { m_context |= TrashContext; + } else if (scheme == QLatin1String("search")) { + 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()) { @@ -184,77 +196,118 @@ } } -void DolphinContextMenu::openItemContextMenu() +void DolphinContextMenu::addDirectoryItemContextMenu(KFileItemActions &fileItemActions) { - Q_ASSERT(!m_fileInfo.isNull()); + // insert 'Open in new window' and 'Open in new tab' entries - QAction* openParentAction = nullptr; - QAction* openParentInNewWindowAction = nullptr; - QAction* openParentInNewTabAction = nullptr; const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); - KFileItemActions fileItemActions; - fileItemActions.setParentWidget(m_mainWindow); - fileItemActions.setItemListProperties(selectedItemsProps); - - if (m_selectedItems.count() == 1) { - if (m_fileInfo.isDir()) { - // insert 'Open in new window' and 'Open in new tab' entries - addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); - addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_window"))); + addAction(m_mainWindow->actionCollection()->action(QStringLiteral("open_in_new_tab"))); - // Insert 'Open With' entries - addOpenWithActions(fileItemActions); + // Insert 'Open With' entries + addOpenWithActions(fileItemActions); + + // set up 'Create New' menu + DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); + const DolphinView* view = m_mainWindow->activeViewContainer()->view(); + newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); + newFileMenu->checkUpToDate(); + newFileMenu->setPopupFiles(m_fileInfo.url()); + newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); + connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); + connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); + + QMenu* menu = newFileMenu->menu(); + menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); + menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); + addMenu(menu); + + addSeparator(); +} - // set up 'Create New' menu - DolphinNewFileMenu* newFileMenu = new DolphinNewFileMenu(m_mainWindow->actionCollection(), m_mainWindow); - const DolphinView* view = m_mainWindow->activeViewContainer()->view(); - newFileMenu->setViewShowsHiddenFiles(view->hiddenFilesShown()); - newFileMenu->checkUpToDate(); - newFileMenu->setPopupFiles(m_fileInfo.url()); - newFileMenu->setEnabled(selectedItemsProps.supportsWriting()); - connect(newFileMenu, &DolphinNewFileMenu::fileCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); - connect(newFileMenu, &DolphinNewFileMenu::directoryCreated, newFileMenu, &DolphinNewFileMenu::deleteLater); - - QMenu* menu = newFileMenu->menu(); - menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); - menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); - addMenu(menu); - - addSeparator(); - } else if (m_baseUrl.scheme().contains(QLatin1String("search")) || m_baseUrl.scheme().contains(QLatin1String("timeline"))) { - addOpenWithActions(fileItemActions); +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 +} - openParentAction = new QAction(QIcon::fromTheme(QStringLiteral("document-open-folder")), +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"), + "Open Path in New Tab"), this); - addAction(openParentAction); + connect(openParentInNewTabAction, &QAction::triggered, this, [=] (){ + m_command = OpenParentFolderInNewTab; + }); + addAction(openParentInNewTabAction); - openParentInNewWindowAction = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), - i18nc("@action:inmenu", - "Open Path in New Window"), - this); - addAction(openParentInNewWindowAction); + addSeparator(); +} - openParentInNewTabAction = new QAction(QIcon::fromTheme(QStringLiteral("tab-new")), - i18nc("@action:inmenu", - "Open Path in New Tab"), - this); - addAction(openParentInNewTabAction); +void DolphinContextMenu::openItemContextMenu() +{ + Q_ASSERT(!m_fileInfo.isNull()); + + const KFileItemListProperties& selectedItemsProps = selectedItemsProperties(); - addSeparator(); + KFileItemActions fileItemActions; + fileItemActions.setParentWidget(m_mainWindow); + fileItemActions.setItemListProperties(selectedItemsProps); + + if (m_selectedItems.count() == 1) { + // single files + if (m_fileInfo.isDir()) { + addDirectoryItemContextMenu(fileItemActions); } 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 bool selectionHasOnlyDirs = true; - foreach (const KFileItem& item, m_selectedItems) { + for (const auto &item : qAsConst(m_selectedItems)) { const QUrl& url = DolphinView::openItemAsFolderUrl(item); if (url.isEmpty()) { selectionHasOnlyDirs = false; @@ -272,6 +325,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()) { @@ -302,15 +359,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()