X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/a291c5999035bb17fe764c1910c3e78ba041f8ac..438620f2b77f4da62c682729bc6e1c0ce8bfc2c6:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 668f511ee..0aafe3ad6 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -57,16 +57,17 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include #include +#include #include #include #include @@ -113,7 +114,7 @@ DolphinMainWindow::DolphinMainWindow() : m_bookmarkHandler(nullptr), m_controlButton(nullptr), m_updateToolBarTimer(nullptr), - m_lastHandleUrlStatJob(nullptr), + m_lastHandleUrlOpenJob(nullptr), m_terminalPanel(nullptr), m_placesPanel(nullptr), m_tearDownFromPlacesRequested(false), @@ -205,7 +206,9 @@ DolphinMainWindow::DolphinMainWindow() : setupWhatsThis(); - QTimer::singleShot(0, this, &DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction); + connect(KSycoca::self(), QOverload<>::of(&KSycoca::databaseChanged), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); + + QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); } DolphinMainWindow::~DolphinMainWindow() @@ -982,29 +985,6 @@ QPointer DolphinMainWindow::preferredSearchTool() return action; } -void DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction() -{ - QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool")); - const QList widgets = openPreferredSearchTool->associatedWidgets(); - for (QWidget* widget : widgets) { - QMenu* menu = qobject_cast(widget); - if (menu) { - connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); - } - } - - // Update the open_preferred_search_tool action *before* the Configure Shortcuts window is shown, - // since this action is then listed in that window and it should be up-to-date when it is displayed. - // This update is instantaneous if user made no changes to the search tools in the meantime. - // Maybe all KStandardActions should defer calls to their slots, so that we could simply connect() to trigger()? - connect( - actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings)), &QAction::hovered, - this, &DolphinMainWindow::updateOpenPreferredSearchToolAction - ); - - updateOpenPreferredSearchToolAction(); -} - void DolphinMainWindow::updateOpenPreferredSearchToolAction() { QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool")); @@ -1056,34 +1036,31 @@ void DolphinMainWindow::editSettings() void DolphinMainWindow::handleUrl(const QUrl& url) { - delete m_lastHandleUrlStatJob; - m_lastHandleUrlStatJob = nullptr; + delete m_lastHandleUrlOpenJob; + m_lastHandleUrlOpenJob = nullptr; if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) { activeViewContainer()->setUrl(url); - } else if (KProtocolManager::supportsListing(url)) { - // stat the URL to see if it is a dir or not - m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo); - if (m_lastHandleUrlStatJob->uiDelegate()) { - KJobWidgets::setWindow(m_lastHandleUrlStatJob, this); - } - connect(m_lastHandleUrlStatJob, &KIO::Job::result, - this, &DolphinMainWindow::slotHandleUrlStatFinished); - } else { - new KRun(url, this); // Automatically deletes itself after being finished - } -} + m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url); + m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); + m_lastHandleUrlOpenJob->setRunExecutables(true); -void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job) -{ - m_lastHandleUrlStatJob = nullptr; - const KIO::UDSEntry entry = static_cast(job)->statResult(); - const QUrl url = static_cast(job)->url(); - if (entry.isDir()) { - activeViewContainer()->setUrl(url); - } else { - new KRun(url, this); // Automatically deletes itself after being finished + connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, + [this, url](const QString &mimetype) { + if (mimetype == QLatin1String("inode/directory")) { + // If it's a dir, we'll take it from here + m_lastHandleUrlOpenJob->kill(); + m_lastHandleUrlOpenJob = nullptr; + activeViewContainer()->setUrl(url); + } + }); + + connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() { + m_lastHandleUrlOpenJob = nullptr; + }); + + m_lastHandleUrlOpenJob->start(); } } @@ -1149,6 +1126,7 @@ void DolphinMainWindow::updateControlMenu() // Add "Edit" actions bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) | + addActionToMenu(ac->action(QString("copy_location")), menu) | addActionToMenu(ac->action(QStringLiteral("copy_to_inactive_split_view")), menu) | addActionToMenu(ac->action(QStringLiteral("move_to_inactive_split_view")), menu) | addActionToMenu(ac->action(KStandardAction::name(KStandardAction::SelectAll)), menu) | @@ -1180,7 +1158,6 @@ void DolphinMainWindow::updateControlMenu() addActionToMenu(ac->action(QStringLiteral("show_filter_bar")), menu); addActionToMenu(ac->action(QStringLiteral("open_preferred_search_tool")), menu); addActionToMenu(ac->action(QStringLiteral("open_terminal")), menu); - connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); menu->addSeparator(); @@ -1932,6 +1909,7 @@ void DolphinMainWindow::updateFileAndEditActions() QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places")); QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view")); QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view")); + QAction* copyLocation = col->action(QString("copy_location")); if (list.isEmpty()) { stateChanged(QStringLiteral("has_no_selection")); @@ -1939,6 +1917,7 @@ void DolphinMainWindow::updateFileAndEditActions() addToPlacesAction->setEnabled(true); copyToOtherViewAction->setEnabled(false); moveToOtherViewAction->setEnabled(false); + copyLocation->setEnabled(false); } else { stateChanged(QStringLiteral("has_selection")); @@ -1980,6 +1959,7 @@ void DolphinMainWindow::updateFileAndEditActions() deleteAction->setEnabled(capabilitiesSource.supportsDeleting()); deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash); cutAction->setEnabled(capabilitiesSource.supportsMoving()); + copyLocation->setEnabled(list.length() == 1); showTarget->setEnabled(list.length() == 1 && list.at(0).isLink()); duplicateAction->setEnabled(capabilitiesSource.supportsWriting()); }