X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/d2f044b32d34023fbf4755b95dcafe71ed00b55f..f386f848dee5b895e859857af68dd5b170e639e1:/src/dolphinpart.cpp diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 00c99efd0..059508778 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -11,7 +11,6 @@ #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" @@ -22,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -68,7 +68,7 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, this, &DolphinPart::slotErrorMessage); - connect(m_view, &DolphinView::directoryLoadingCompleted, this, QOverload<>::of(&KParts::ReadOnlyPart::completed)); + connect(m_view, &DolphinView::directoryLoadingCompleted, this, &KParts::ReadOnlyPart::completed); connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinPart::updatePasteAction); connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinPart::updateProgress); connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage); @@ -85,12 +85,16 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, 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("%1").arg(escapedText)); + }); connect(m_view, &DolphinView::tabRequested, this, &DolphinPart::createNewWindow); connect(m_view, &DolphinView::requestContextMenu, this, &DolphinPart::slotOpenContextMenu); connect(m_view, &DolphinView::selectionChanged, - m_extension, QOverload::of(&KParts::BrowserExtension::selectionInfo)); + m_extension, &KParts::BrowserExtension::selectionInfo); connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::slotSelectionChanged); connect(m_view, &DolphinView::requestItemInfo, @@ -142,8 +146,6 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror // (sort of spacial navigation) - - loadPlugins(this, this, componentName()); } DolphinPart::~DolphinPart() @@ -197,9 +199,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); @@ -283,6 +282,18 @@ void DolphinPart::updatePasteAction() Q_EMIT m_extension->setActionText( "paste", pasteInfo.second ); } +QString DolphinPart::urlToLocalFilePath(const QUrl &url) +{ + 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) { bool reload = arguments().reload(); @@ -293,7 +304,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); @@ -310,7 +322,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); @@ -542,16 +554,27 @@ 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()); + auto job = new KTerminalLauncherJob(QString()); + job->setWorkingDirectory(localFilePathOrHome()); + job->start(); } 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 actions = searchTools.actions(); if (!(actions.isEmpty())) { @@ -568,15 +591,13 @@ void DolphinPart::updateNewMenu() { // As requested by KNewFileMenu : m_newFileMenu->checkUpToDate(); - m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown()); // And set the files that the menu apply on : m_newFileMenu->setPopupFiles(QList() << url()); } void DolphinPart::updateStatusBar() { - const QString escapedText = Qt::convertFromPlainText(m_view->statusBarText()); - Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("%1").arg(escapedText)); + m_view->requestStatusBarText(); } void DolphinPart::updateProgress(int percent) @@ -586,7 +607,6 @@ void DolphinPart::updateProgress(int percent) void DolphinPart::createDirectory() { - m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown()); m_newFileMenu->setPopupFiles(QList() << url()); m_newFileMenu->createDirectory(); }