X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/9f268f5f76a4a4f0c91abcc213e159c8bde4869c..9b83378c087a87cef537ba751b7713aff8bed84c:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 7ad136fe7..92d673a95 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -1,23 +1,10 @@ -/*************************************************************************** - * Copyright (C) 2006 by Peter Penz * - * Copyright (C) 2006 by Stefan Monov * - * Copyright (C) 2006 by Cvetoslav Ludmiloff * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - ***************************************************************************/ +/* + * SPDX-FileCopyrightText: 2006 Peter Penz + * SPDX-FileCopyrightText: 2006 Stefan Monov + * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ #include "dolphinmainwindow.h" @@ -50,21 +37,24 @@ #include #include #include +#include #include #include #include +#include #include #include +#include #include #include #include #include #include #include -#include #include #include #include +#include #include #include #include @@ -111,7 +101,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), @@ -203,7 +193,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() @@ -579,6 +571,14 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) } } + if (GeneralSettings::rememberOpenedTabs()) { + KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin")); + KConfig *config = KConfigGui::sessionConfig(); + saveGlobalProperties(config); + savePropertiesInternal(config, 1); + config->sync(); + } + GeneralSettings::setVersion(CurrentDolphinVersion); GeneralSettings::self()->save(); @@ -644,12 +644,12 @@ void DolphinMainWindow::undo() void DolphinMainWindow::cut() { - m_activeViewContainer->view()->cutSelectedItems(); + m_activeViewContainer->view()->cutSelectedItemsToClipboard(); } void DolphinMainWindow::copy() { - m_activeViewContainer->view()->copySelectedItems(); + m_activeViewContainer->view()->copySelectedItemsToClipboard(); } void DolphinMainWindow::paste() @@ -926,7 +926,10 @@ void DolphinMainWindow::compareFiles() command.append("\" \""); command.append(urlB.toDisplayString(QUrl::PreferLocalFile)); command.append('\"'); - KRun::runCommand(command, QStringLiteral("Kompare"), QStringLiteral("kompare"), this); + + KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this); + job->setDesktopName(QStringLiteral("org.kde.kompare")); + job->start(); } void DolphinMainWindow::toggleShowMenuBar() @@ -940,18 +943,6 @@ void DolphinMainWindow::toggleShowMenuBar() } } -QString DolphinMainWindow::activeContainerLocalPath() -{ - KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url()); - KJobWidgets::setWindow(statJob, this); - statJob->exec(); - QUrl url = statJob->mostLocalUrl(); - if (url.isLocalFile()) { - return url.toLocalFile(); - } - return QDir::homePath(); -} - QPointer DolphinMainWindow::preferredSearchTool() { m_searchTools.clear(); @@ -969,29 +960,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")); @@ -1021,7 +989,31 @@ void DolphinMainWindow::openPreferredSearchTool() void DolphinMainWindow::openTerminal() { - KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath()); + const QUrl url = m_activeViewContainer->url(); + + if (url.isLocalFile()) { + KToolInvocation::invokeTerminal(QString(), url.toLocalFile()); + return; + } + + // Not a local file, with protocol Class ":local", try stat'ing + if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) { + KIO::StatJob *job = KIO::mostLocalUrl(url); + KJobWidgets::setWindow(job, this); + connect(job, &KJob::result, this, [job]() { + QUrl statUrl; + if (!job->error()) { + statUrl = job->mostLocalUrl(); + } + + KToolInvocation::invokeTerminal(QString(), statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath()); + }); + + return; + } + + // Nothing worked, just use $HOME + KToolInvocation::invokeTerminal(QString(), QDir::homePath()); } void DolphinMainWindow::editSettings() @@ -1043,34 +1035,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(); } } @@ -1136,6 +1125,9 @@ 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) | addActionToMenu(ac->action(QStringLiteral("invert_selection")), menu); @@ -1165,7 +1157,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(); @@ -1265,7 +1256,7 @@ void DolphinMainWindow::tabCountChanged(int count) void DolphinMainWindow::updateWindowTitle() { - const QString newTitle = m_activeViewContainer->caption(); + const QString newTitle = m_activeViewContainer->captionWindowTitle(); if (windowTitle() != newTitle) { setWindowTitle(newTitle); } @@ -1369,6 +1360,24 @@ void DolphinMainWindow::setupActions() "If the items were added to the clipboard by the Cut " "action they are removed from their old location.") + cutCopyPastePara); + QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view")); + copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View")); + copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from " + "the active view to the inactive split view.")); + copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); + copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View")); + actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT + Qt::Key_F5 ); + connect(copyToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::copyToInactiveSplitView); + + QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view")); + moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View")); + moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from " + "the active view to the inactive split view.")); + moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut"))); + moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View")); + actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT + Qt::Key_F6 ); + connect(moveToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::moveToInactiveSplitView); + QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection()); searchAction->setText(i18n("Search...")); searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders")); @@ -1549,7 +1558,6 @@ void DolphinMainWindow::setupActions() actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL + Qt::SHIFT + Qt::Key_F); connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool); -#ifdef HAVE_TERMINAL if (KAuthorized::authorize(QStringLiteral("shell_access"))) { QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal")); openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal")); @@ -1560,13 +1568,14 @@ void DolphinMainWindow::setupActions() actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4); connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal); +#ifdef HAVE_TERMINAL QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel")); focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel")); focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels"))); actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL + Qt::SHIFT + Qt::Key_F4); connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel); - } #endif + } // setup 'Bookmarks' menu KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this); @@ -1894,12 +1903,20 @@ void DolphinMainWindow::updateFileAndEditActions() { const KFileItemList list = m_activeViewContainer->view()->selectedItems(); const KActionCollection* col = actionCollection(); + KFileItemListProperties capabilitiesSource(list); + 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")); addToPlacesAction->setEnabled(true); + copyToOtherViewAction->setEnabled(false); + moveToOtherViewAction->setEnabled(false); + copyLocation->setEnabled(false); } else { stateChanged(QStringLiteral("has_selection")); @@ -1917,16 +1934,33 @@ void DolphinMainWindow::updateFileAndEditActions() addToPlacesAction->setEnabled(false); } - KFileItemListProperties capabilities(list); - const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); + if (m_tabWidget->currentTabPage()->splitViewEnabled()) { + DolphinTabPage* tabPage = m_tabWidget->currentTabPage(); + KFileItem capabilitiesDestination; + + if (tabPage->primaryViewActive()) { + capabilitiesDestination = tabPage->secondaryViewContainer()->url(); + } else { + capabilitiesDestination = tabPage->primaryViewContainer()->url(); + } + + copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable()); + moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving() && capabilitiesDestination.isWritable()); + } else { + copyToOtherViewAction->setEnabled(false); + moveToOtherViewAction->setEnabled(false); + } + + const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving(); - renameAction->setEnabled(capabilities.supportsMoving()); + renameAction->setEnabled(capabilitiesSource.supportsMoving()); moveToTrashAction->setEnabled(enableMoveToTrash); - deleteAction->setEnabled(capabilities.supportsDeleting()); - deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash); - cutAction->setEnabled(capabilities.supportsMoving()); + 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(capabilities.supportsWriting()); + duplicateAction->setEnabled(capabilitiesSource.supportsWriting()); } } @@ -2073,6 +2107,8 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) this, &DolphinMainWindow::goForward); connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl); + connect(view, &DolphinView::goUpRequested, + this, &DolphinMainWindow::goUp); const KUrlNavigator* navigator = container->urlNavigator(); connect(navigator, &KUrlNavigator::urlChanged, @@ -2297,8 +2333,6 @@ bool DolphinMainWindow::event(QEvent *event) QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast(event); QDesktopServices::openUrl(QUrl(whatsThisEvent->href())); return true; - } else if (event->type() == QEvent::WindowActivate) { - updateOpenPreferredSearchToolAction(); } return KXmlGuiWindow::event(event); }