]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/settings/contextmenu/contextmenusettingspage.cpp
Revert "Revert "Disable Hidden Files Last sort by default""
[dolphin.git] / src / settings / contextmenu / contextmenusettingspage.cpp
index 4f126d3e2a29f7725a707d8f4f6fc8e193ce79d1..c92bad43e61b70cc7925c9a8fd928f5b9135c3b6 100644 (file)
@@ -21,6 +21,8 @@
 #include <KServiceTypeTrader>
 #include <KDesktopFileActions>
 
+#include <kio_version.h>
+
 #include <QGridLayout>
 #include <QLabel>
 #include <QListWidget>
@@ -35,22 +37,19 @@ namespace
     const char VersionControlServicePrefix[] = "_version_control_";
     const char DeleteService[] = "_delete";
     const char CopyToMoveToService[] ="_copy_to_move_to";
-    const char AddToPlacesService[] = "_add_to_places";
-    const char SortByService[] = "_sort_by";
-    const char ViewModeService[] = "_view_mode";
-    const char OpenInNewTabService[] = "_open_in_new_tab";
-    const char OpenInNewWindowService[] = "_open_in_new_window";
-    const char CopyLocationService[] = "_copy_location";
-    const char DuplicateHereService[] = "_duplicate_here";
 }
 
-ContextMenuSettingsPage::ContextMenuSettingsPage(QWidget* parent) :
+ContextMenuSettingsPage::ContextMenuSettingsPage(QWidget* parent,
+                                                 const KActionCollection* actions,
+                                                 const QStringList& actionIds) :
     SettingsPageBase(parent),
     m_initialized(false),
     m_serviceModel(nullptr),
     m_sortModel(nullptr),
     m_listView(nullptr),
-    m_enabledVcsPlugins()
+    m_enabledVcsPlugins(),
+    m_actions(actions),
+    m_actionIds(actionIds)
 {
     QVBoxLayout* topLayout = new QVBoxLayout(this);
 
@@ -107,6 +106,49 @@ ContextMenuSettingsPage::ContextMenuSettingsPage(QWidget* parent) :
 ContextMenuSettingsPage::~ContextMenuSettingsPage() {
 }
 
+bool ContextMenuSettingsPage::entryVisible(const QString& id)
+{
+    if (id == "add_to_places") {
+        return ContextMenuSettings::showAddToPlaces();
+    } else if (id == "sort") {
+        return ContextMenuSettings::showSortBy();
+    } else if (id == "view_mode") {
+        return ContextMenuSettings::showViewMode();
+    } else if (id == "open_in_new_tab") {
+        return ContextMenuSettings::showOpenInNewTab();
+    } else if (id == "open_in_new_window") {
+        return ContextMenuSettings::showOpenInNewWindow();
+    } else if (id == "copy_location") {
+        return ContextMenuSettings::showCopyLocation();
+    } else if (id == "duplicate") {
+        return ContextMenuSettings::showDuplicateHere();
+    } else if (id == "open_terminal") {
+        return ContextMenuSettings::showOpenTerminal();
+    }
+    return false;
+}
+
+void ContextMenuSettingsPage::setEntryVisible(const QString& id, bool visible)
+{
+    if (id == "add_to_places") {
+        ContextMenuSettings::setShowAddToPlaces(visible);
+    } else if (id == "sort") {
+        ContextMenuSettings::setShowSortBy(visible);
+    } else if (id == "view_mode") {
+        ContextMenuSettings::setShowViewMode(visible);
+    } else if (id == "open_in_new_tab") {
+        ContextMenuSettings::setShowOpenInNewTab(visible);
+    } else if (id == "open_in_new_window") {
+        ContextMenuSettings::setShowOpenInNewWindow(visible);
+    } else if (id == "copy_location") {
+        ContextMenuSettings::setShowCopyLocation(visible);
+    } else if (id == "duplicate") {
+        ContextMenuSettings::setShowDuplicateHere(visible);
+    } else if (id == "open_terminal") {
+        ContextMenuSettings::setShowOpenTerminal(visible);
+    }
+}
+
 void ContextMenuSettingsPage::applySettings()
 {
     if (!m_initialized) {
@@ -136,26 +178,8 @@ void ContextMenuSettingsPage::applySettings()
         } else if (service == QLatin1String(CopyToMoveToService)) {
             ContextMenuSettings::setShowCopyMoveMenu(checked);
             ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(AddToPlacesService)) {
-            ContextMenuSettings::setShowAddToPlaces(checked);
-            ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(SortByService)) {
-            ContextMenuSettings::setShowSortBy(checked);
-            ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(ViewModeService)) {
-            ContextMenuSettings::setShowViewMode(checked);
-            ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(OpenInNewTabService)) {
-            ContextMenuSettings::setShowOpenInNewTab(checked);
-            ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(OpenInNewWindowService)) {
-            ContextMenuSettings::setShowOpenInNewWindow(checked);
-            ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(CopyLocationService)) {
-            ContextMenuSettings::setShowCopyLocation(checked);
-            ContextMenuSettings::self()->save();
-        } else if (service == QLatin1String(DuplicateHereService)) {
-            ContextMenuSettings::setShowDuplicateHere(checked);
+        } else if (m_actionIds.contains(service)) {
+            setEntryVisible(service, checked);
             ContextMenuSettings::self()->save();
         } else {
             showGroup.writeEntry(service, checked);
@@ -211,35 +235,15 @@ void ContextMenuSettingsPage::showEvent(QShowEvent* event)
                CopyToMoveToService,
                ContextMenuSettings::showCopyMoveMenu());
 
-        // Add other built-in actions
-        addRow(QStringLiteral("bookmark-new"),
-               i18nc("@option:check", "Add to Places"),
-               AddToPlacesService,
-               ContextMenuSettings::showAddToPlaces());
-        addRow(QStringLiteral("view-sort"),
-               i18nc("@option:check", "Sort By"),
-               SortByService,
-               ContextMenuSettings::showSortBy());
-        addRow(QStringLiteral("view-list-icons"),
-               i18nc("@option:check", "View Mode"),
-               ViewModeService,
-               ContextMenuSettings::showViewMode());
-        addRow(QStringLiteral("folder-new"),
-               i18nc("@option:check", "'Open in New Tab' and 'Open in New Tabs'"),
-               OpenInNewTabService,
-               ContextMenuSettings::showOpenInNewTab());
-        addRow(QStringLiteral("window-new"),
-               i18nc("@option:check", "Open in New Window"),
-               OpenInNewWindowService,
-               ContextMenuSettings::showOpenInNewWindow());
-        addRow(QStringLiteral("edit-copy"),
-               i18nc("@option:check", "Copy Location"),
-               CopyLocationService,
-               ContextMenuSettings::showCopyLocation());
-        addRow(QStringLiteral("edit-copy"),
-               i18nc("@option:check", "Duplicate Here"),
-               DuplicateHereService,
-               ContextMenuSettings::showDuplicateHere());
+        if (m_actions){
+            // Add other built-in actions
+            for (const QString& id : m_actionIds) {
+                const QAction* action = m_actions->action(id);
+                if (action) {
+                    addRow(action->icon().name(), action->text(), id, entryVisible(id));
+                }
+            }
+        }
 
         m_sortModel->sort(Qt::DisplayRole);
 
@@ -276,7 +280,8 @@ void ContextMenuSettingsPage::loadServices()
         }
     }
 
-    // Load service plugins that implement the KFileItemActionPlugin interface
+    // Load service plugins, this is deprecated in KIO 5.82
+#if KIO_VERSION < QT_VERSION_CHECK(6, 0, 0)
     const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("KFileItemAction/Plugin"));
     for (const KService::Ptr &service : pluginServices) {
         const QString desktopEntryName = service->desktopEntryName();
@@ -285,11 +290,10 @@ void ContextMenuSettingsPage::loadServices()
             addRow(service->icon(), service->name(), desktopEntryName, checked);
         }
     }
+#endif
 
     // Load JSON-based plugins that implement the KFileItemActionPlugin interface
-    const auto jsonPlugins = KPluginLoader::findPlugins(QStringLiteral("kf5/kfileitemaction"), [](const KPluginMetaData& metaData) {
-        return metaData.serviceTypes().contains(QLatin1String("KFileItemAction/Plugin"));
-    });
+    const auto jsonPlugins = KPluginLoader::findPlugins(QStringLiteral("kf5/kfileitemaction"));
 
     for (const auto &jsonMetadata : jsonPlugins) {
         const QString desktopEntryName = jsonMetadata.pluginId();
@@ -308,9 +312,24 @@ void ContextMenuSettingsPage::loadVersionControlSystems()
     const QStringList enabledPlugins = VersionControlSettings::enabledPlugins();
 
     // Create a checkbox for each available version control plugin
+    QSet<QString> loadedPlugins;
+
+    const QVector<KPluginMetaData> plugins = KPluginLoader::findPlugins(QStringLiteral("dolphin/vcs"));
+    for (const auto &plugin : plugins) {
+        const QString pluginName = plugin.name();
+        addRow(QStringLiteral("code-class"),
+               pluginName,
+               VersionControlServicePrefix + pluginName,
+               enabledPlugins.contains(pluginName));
+        loadedPlugins += pluginName;
+    }
+
     const KService::List pluginServices = KServiceTypeTrader::self()->query(QStringLiteral("FileViewVersionControlPlugin"));
     for (const auto &plugin : pluginServices) {
         const QString pluginName = plugin->name();
+        if (loadedPlugins.contains(pluginName)) {
+            continue;
+        }
         addRow(QStringLiteral("code-class"),
                pluginName,
                VersionControlServicePrefix + pluginName,