]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinpart.cpp
Use KDirLister directly now that it emits a jobError() signal
[dolphin.git] / src / dolphinpart.cpp
index 75784b522dbc4a2fb45884b80276cd527f849c17..9c551d67abf797cbc6883cb31fb860773c9b9a07 100644 (file)
 #include "dolphinpart_ext.h"
 #include "dolphinremoveaction.h"
 #include "kitemviews/kfileitemmodel.h"
-#include "kitemviews/private/kfileitemmodeldirlister.h"
 #include "views/dolphinnewfilemenuobserver.h"
 #include "views/dolphinremoteencoding.h"
 #include "views/dolphinview.h"
 #include "views/dolphinviewactionhandler.h"
 
-#include <KAboutData>
+#include <KPluginMetaData>
 #include <KActionCollection>
 #include <KAuthorized>
 #include <KConfigGroup>
 #include <KDialogJobUiDelegate>
+#include <KDirLister>
 #include <KFileItemListProperties>
 #include <KIconLoader>
 #include <KJobWidgets>
 #include <QStandardPaths>
 #include <QTextDocument>
 
-K_PLUGIN_FACTORY(DolphinPartFactory, registerPlugin<DolphinPart>();)
+K_PLUGIN_CLASS_WITH_JSON(DolphinPart, "dolphinpart.json")
 
-DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantList& args)
+DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent,
+                         const KPluginMetaData& metaData, const QVariantList& args)
     : KParts::ReadOnlyPart(parent)
       ,m_openTerminalAction(nullptr)
       ,m_removeAction(nullptr)
 {
     Q_UNUSED(args)
-    setComponentData(*createAboutData(), false);
+    setMetaData(metaData);
+
     m_extension = new DolphinPartBrowserExtension(this);
 
     // make sure that other apps using this part find Dolphin's view-file-columns icons
@@ -83,6 +85,10 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL
             this, &DolphinPart::slotItemActivated);
     connect(m_view, &DolphinView::itemsActivated,
             this, &DolphinPart::slotItemsActivated);
+    connect(m_view, &DolphinView::statusBarTextChanged, this, [this](const QString &text) {
+        const QString escapedText = Qt::convertFromPlainText(text);
+        Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
+    });
     connect(m_view, &DolphinView::tabRequested,
             this, &DolphinPart::createNewWindow);
     connect(m_view, &DolphinView::requestContextMenu,
@@ -141,7 +147,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantL
     // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
     // (sort of spacial navigation)
 
-    loadPlugins(this, this, componentData());
+    loadPlugins(this, this, componentName());
 }
 
 DolphinPart::~DolphinPart()
@@ -163,7 +169,7 @@ void DolphinPart::createActions()
 
     QAction* selectItemsMatching = actionCollection()->addAction(QStringLiteral("select_items_matching"));
     selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching..."));
-    actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL + Qt::Key_S);
+    actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL | Qt::Key_S);
     connect(selectItemsMatching, &QAction::triggered, this, &DolphinPart::slotSelectItemsMatchingPattern);
 
     QAction* unselectItemsMatching = actionCollection()->addAction(QStringLiteral("unselect_items_matching"));
@@ -178,7 +184,7 @@ void DolphinPart::createActions()
 
     QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
     invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
-    actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A);
+    actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
     connect(invertSelection, &QAction::triggered, m_view, &DolphinView::invertSelection);
 
     // View menu: all done by DolphinViewActionHandler
@@ -195,9 +201,6 @@ void DolphinPart::createActions()
     createGoAction("go_network_folders", "folder-remote",
                    i18nc("@action:inmenu Go", "&Network Folders"), QStringLiteral("remote:/"),
                    goActionGroup);
-    createGoAction("go_settings", "preferences-system",
-                   i18nc("@action:inmenu Go", "Sett&ings"), QStringLiteral("settings:/"),
-                   goActionGroup);
     createGoAction("go_trash", "user-trash",
                    i18nc("@action:inmenu Go", "Trash"), QStringLiteral("trash:/"),
                    goActionGroup);
@@ -281,9 +284,16 @@ void DolphinPart::updatePasteAction()
     Q_EMIT m_extension->setActionText( "paste", pasteInfo.second );
 }
 
-KAboutData* DolphinPart::createAboutData()
+QString DolphinPart::urlToLocalFilePath(const QUrl &url)
 {
-    return new KAboutData(QStringLiteral("dolphinpart"), i18nc("@title", "Dolphin Part"), QStringLiteral("0.1"));
+    KIO::StatJob* statJob = KIO::mostLocalUrl(url);
+    KJobWidgets::setWindow(statJob, widget());
+    statJob->exec();
+    QUrl localUrl = statJob->mostLocalUrl();
+    if (localUrl.isLocalFile()) {
+        return localUrl.toLocalFile();
+    }
+    return QString();
 }
 
 bool DolphinPart::openUrl(const QUrl &url)
@@ -296,7 +306,8 @@ bool DolphinPart::openUrl(const QUrl &url)
     if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
         return true;
     }
-    setUrl(url); // remember it at the KParts level
+    setUrl(url); // remember url at the KParts level
+    setLocalFilePath(urlToLocalFilePath(url)); // remember local path at the KParts level
     QUrl visibleUrl(url);
     if (!m_nameFilter.isEmpty()) {
         visibleUrl.setPath(visibleUrl.path() + '/' + m_nameFilter);
@@ -313,7 +324,7 @@ bool DolphinPart::openUrl(const QUrl &url)
         m_view->reload();
     // Disable "Find File" and "Open Terminal" actions for non-file URLs,
     // e.g. ftp, smb, etc. #279283
-    const bool isLocalUrl = url.isLocalFile();
+    const bool isLocalUrl = !(localFilePath().isEmpty());
     m_findFileAction->setEnabled(isLocalUrl);
     if (m_openTerminalAction) {
         m_openTerminalAction->setEnabled(isLocalUrl);
@@ -545,16 +556,25 @@ void DolphinPart::setNameFilter(const QString& nameFilter)
     // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
 }
 
+QString DolphinPart::localFilePathOrHome() const
+{
+    const QString localPath = localFilePath();
+    if (!localPath.isEmpty()) {
+        return localPath;
+    }
+    return QDir::homePath();
+}
+
 void DolphinPart::slotOpenTerminal()
 {
-    KToolInvocation::invokeTerminal(QString(), KParts::ReadOnlyPart::localFilePath());
+    KToolInvocation::invokeTerminal(QString(), {}, localFilePathOrHome());
 }
 
 void DolphinPart::slotFindFile()
 {
     QMenu searchTools;
     KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
-        &searchTools, { "files-find" }, QUrl::fromLocalFile(KParts::ReadOnlyPart::localFilePath())
+        &searchTools, { "files-find" }, QUrl::fromLocalFile(localFilePathOrHome())
     );
     QList<QAction*> actions = searchTools.actions();
     if (!(actions.isEmpty())) {
@@ -578,8 +598,7 @@ void DolphinPart::updateNewMenu()
 
 void DolphinPart::updateStatusBar()
 {
-    const QString escapedText = Qt::convertFromPlainText(m_view->statusBarText());
-    Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
+    m_view->requestStatusBarText();
 }
 
 void DolphinPart::updateProgress(int percent)