]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinpart.cpp
Add Filelight menu to Tools menu
[dolphin.git] / src / dolphinpart.cpp
index f8da1c353dc02869fc379b99483474b56c47f70b..a7f0d85cd2e939c7d266699370b1ee7cc0514d17 100644 (file)
 #include <KLocalizedString>
 #include <KMessageBox>
 #include <KMimeTypeEditor>
-#include <KMoreToolsMenuFactory>
 #include <KPluginFactory>
 #include <KPluginMetaData>
 #include <KSharedConfig>
 #include <KTerminalLauncherJob>
-#include <kio_version.h>
 
 #include <QActionGroup>
 #include <QApplication>
 #include <QStandardPaths>
 #include <QTextDocument>
 
+#include <KPluginFactory>
+#include <QAction>
+
 K_PLUGIN_CLASS_WITH_JSON(DolphinPart, "dolphinpart.json")
 
 DolphinPart::DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
-    : KParts::ReadOnlyPart(parent)
+    : KParts::ReadOnlyPart(parent, metaData)
     , m_openTerminalAction(nullptr)
     , m_removeAction(nullptr)
 {
     Q_UNUSED(args)
-    setMetaData(metaData);
 
     m_extension = new DolphinPartBrowserExtension(this);
 
@@ -85,7 +85,7 @@ DolphinPart::DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMe
     });
     connect(m_view, &DolphinView::tabRequested, this, &DolphinPart::createNewWindow);
     connect(m_view, &DolphinView::requestContextMenu, this, &DolphinPart::slotOpenContextMenu);
-    connect(m_view, &DolphinView::selectionChanged, m_extension, &KParts::BrowserExtension::selectionInfo);
+    connect(m_view, &DolphinView::selectionChanged, m_extension, &KParts::NavigationExtension::selectionInfo);
     connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::slotSelectionChanged);
     connect(m_view, &DolphinView::requestItemInfo, this, &DolphinPart::slotRequestItemInfo);
     connect(m_view, &DolphinView::modeChanged, this, &DolphinPart::viewModeChanged); // relay signal
@@ -140,8 +140,9 @@ DolphinPart::~DolphinPart()
 void DolphinPart::createActions()
 {
     // Edit menu
-
-    m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
+    QAction *newDirAction = actionCollection()->action(QStringLiteral("create_dir"));
+    QAction *newFileAction = actionCollection()->action(QStringLiteral("create_file"));
+    m_newFileMenu = new DolphinNewFileMenu(newDirAction, newFileAction, this);
     m_newFileMenu->setParentWidget(widget());
     connect(m_newFileMenu->menu(), &QMenu::aboutToShow, this, &DolphinPart::updateNewMenu);
 
@@ -339,11 +340,7 @@ void DolphinPart::slotItemActivated(const KFileItem &item)
         args.setMimeType(item.mimetype());
     }
 
-    // Ideally, konqueror should be changed to not require trustedSource for directory views,
-    // since the idea was not to need BrowserArguments for non-browser stuff...
-    KParts::BrowserArguments browserArgs;
-    browserArgs.trustedSource = true;
-    Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args, browserArgs);
+    Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args);
 }
 
 void DolphinPart::slotItemsActivated(const KFileItemList &items)
@@ -362,8 +359,8 @@ void DolphinPart::createNewWindow(const QUrl &url)
 
 void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &)
 {
-    KParts::BrowserExtension::PopupFlags popupFlags =
-        KParts::BrowserExtension::DefaultPopupItems | KParts::BrowserExtension::ShowProperties | KParts::BrowserExtension::ShowUrlOperations;
+    KParts::NavigationExtension::PopupFlags popupFlags =
+        KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
 
     KFileItem item(_item);
 
@@ -384,7 +381,7 @@ void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item,
 
     KFileItemListProperties capabilities(items);
 
-    KParts::BrowserExtension::ActionGroupMap actionGroups;
+    KParts::NavigationExtension::ActionGroupMap actionGroups;
     QList<QAction *> editActions;
     editActions += m_view->versionControlActions(m_view->selectedItems());
 
@@ -392,7 +389,8 @@ void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item,
         const bool supportsMoving = capabilities.supportsMoving();
 
         if (capabilities.supportsDeleting()) {
-            const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
+            const bool showDeleteAction =
+                (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
             const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
 
             if (showDeleteAction && showMoveToTrashAction) {
@@ -409,7 +407,7 @@ void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item,
                 m_removeAction->update();
             }
         } else {
-            popupFlags |= KParts::BrowserExtension::NoDeletion;
+            popupFlags |= KParts::NavigationExtension::NoDeletion;
         }
 
         if (supportsMoving) {
@@ -420,12 +418,12 @@ void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item,
         // since otherwise the created file would not be visible.
         // But in treeview mode we should allow it.
         if (m_view->itemsExpandable())
-            popupFlags |= KParts::BrowserExtension::ShowCreateDirectory;
+            popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
     }
 
     actionGroups.insert(QStringLiteral("editactions"), editActions);
 
-    Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), KParts::BrowserArguments(), popupFlags, actionGroups);
+    Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), popupFlags, actionGroups);
 }
 
 void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
@@ -464,13 +462,13 @@ void DolphinPart::openSelectionDialog(const QString &title, const QString &text,
     dialog->setWindowTitle(title);
     dialog->setLabelText(text);
 
-    const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
+    const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
     dialog->setComboBoxEditable(true);
     dialog->setComboBoxItems(group.readEntry("History", QStringList()));
 
     dialog->setTextValue(QStringLiteral("*"));
 
-    connect(dialog, &QDialog::accepted, this, [=]() {
+    connect(dialog, &QDialog::accepted, this, [=, this]() {
         const QString pattern = dialog->textValue();
         if (!pattern.isEmpty()) {
             QStringList items = dialog->comboBoxItems();
@@ -479,7 +477,7 @@ void DolphinPart::openSelectionDialog(const QString &title, const QString &text,
 
             // Need to evaluate this again here, because the captured value is const
             // (even if the const were removed from 'const KConfigGroup group =' above).
-            KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
+            KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
             // Limit the size of the saved history.
             group.writeEntry("History", items.mid(0, 10));
             group.sync();
@@ -530,17 +528,10 @@ void DolphinPart::slotOpenTerminal()
 
 void DolphinPart::slotFindFile()
 {
-    QMenu searchTools;
-    KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&searchTools, {"files-find"}, QUrl::fromLocalFile(localFilePathOrHome()));
-    QList<QAction *> actions = searchTools.actions();
-    if (!(actions.isEmpty())) {
-        actions.first()->trigger();
-    } else {
-        KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
-        job->setDesktopName(QStringLiteral("org.kde.kfind"));
-        job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
-        job->start();
-    }
+    KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
+    job->setDesktopName(QStringLiteral("org.kde.kfind"));
+    job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
+    job->start();
 }
 
 void DolphinPart::updateNewMenu()
@@ -548,11 +539,7 @@ void DolphinPart::updateNewMenu()
     // As requested by KNewFileMenu :
     m_newFileMenu->checkUpToDate();
     // And set the files that the menu apply on :
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
     m_newFileMenu->setWorkingDirectory(url());
-#else
-    m_newFileMenu->setPopupFiles(QList<QUrl>() << url());
-#endif
 }
 
 void DolphinPart::updateStatusBar()
@@ -567,11 +554,7 @@ void DolphinPart::updateProgress(int percent)
 
 void DolphinPart::createDirectory()
 {
-#if KIO_VERSION >= QT_VERSION_CHECK(5, 97, 0)
     m_newFileMenu->setWorkingDirectory(url());
-#else
-    m_newFileMenu->setPopupFiles(QList<QUrl>() << url());
-#endif
     m_newFileMenu->createDirectory();
 }