X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/abd114f710b9d1247ecea4a82fb338492e9caf78..d1a70c0b629b:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index b51389fd4..ab41e2d7f 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -21,17 +21,22 @@ #include "dolphinmainwindow.h" -#include "dolphinapplication.h" +#include "dolphinmainwindowadaptor.h" +#include "config-terminal.h" +#include "global.h" +#include "dolphinbookmarkhandler.h" #include "dolphindockwidget.h" #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" #include "dolphinrecenttabsmenu.h" -#include "dolphintabbar.h" #include "dolphinviewcontainer.h" #include "dolphintabpage.h" +#include "middleclickactioneventfilter.h" #include "panels/folders/folderspanel.h" +#include "panels/places/placesitemmodel.h" #include "panels/places/placespanel.h" #include "panels/information/informationpanel.h" +#include "panels/terminal/terminalpanel.h" #include "settings/dolphinsettingsdialog.h" #include "statusbar/dolphinstatusbar.h" #include "views/dolphinviewactionhandler.h" @@ -39,92 +44,106 @@ #include "views/draganddrophelper.h" #include "views/viewproperties.h" #include "views/dolphinnewfilemenuobserver.h" - -#ifndef Q_OS_WIN -#include "panels/terminal/terminalpanel.h" -#endif - #include "dolphin_generalsettings.h" -#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 -#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 +#include +#include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include namespace { // Used for GeneralSettings::version() to determine whether // an updated version of Dolphin is running. const int CurrentDolphinVersion = 200; -}; + // The maximum number of entries in the back/forward popup menu + const int MaxNumberOfNavigationentries = 12; + // The maximum number of "Activate Tab" shortcuts + const int MaxActivateTabShortcuts = 9; +} DolphinMainWindow::DolphinMainWindow() : - KXmlGuiWindow(0), - m_newFileMenu(0), - m_tabBar(0), - m_activeViewContainer(0), - m_centralWidgetLayout(0), - m_tabIndex(-1), - m_viewTab(), - m_actionHandler(0), - m_remoteEncoding(0), + KXmlGuiWindow(nullptr), + m_newFileMenu(nullptr), + m_helpMenu(nullptr), + m_tabWidget(nullptr), + m_activeViewContainer(nullptr), + m_actionHandler(nullptr), + m_remoteEncoding(nullptr), m_settingsDialog(), - m_controlButton(0), - m_updateToolBarTimer(0), - m_lastHandleUrlStatJob(0) + m_bookmarkHandler(nullptr), + m_controlButton(nullptr), + m_updateToolBarTimer(nullptr), + m_lastHandleUrlStatJob(nullptr), + m_terminalPanel(nullptr), + m_placesPanel(nullptr), + m_tearDownFromPlacesRequested(false), + m_backAction(nullptr), + m_forwardAction(nullptr) { - setObjectName("Dolphin#"); + Q_INIT_RESOURCE(dolphin); - connect(&DolphinNewFileMenuObserver::instance(), SIGNAL(errorMessage(QString)), - this, SLOT(showErrorMessage(QString))); + new MainWindowAdaptor(this); + +#ifndef Q_OS_WIN + setWindowFlags(Qt::WindowContextHelpButtonHint); +#endif + setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName()); + setObjectName(QStringLiteral("Dolphin#")); + + connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, + this, &DolphinMainWindow::showErrorMessage); KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self(); undoManager->setUiInterface(new UndoUiInterface()); - connect(undoManager, SIGNAL(undoAvailable(bool)), - this, SLOT(slotUndoAvailable(bool))); - connect(undoManager, SIGNAL(undoTextChanged(QString)), - this, SLOT(slotUndoTextChanged(QString))); - connect(undoManager, SIGNAL(jobRecordingStarted(CommandType)), - this, SLOT(clearStatusBar())); - connect(undoManager, SIGNAL(jobRecordingFinished(CommandType)), - this, SLOT(showCommand(CommandType))); + connect(undoManager, QOverload::of(&KIO::FileUndoManager::undoAvailable), + this, &DolphinMainWindow::slotUndoAvailable); + connect(undoManager, &KIO::FileUndoManager::undoTextChanged, + this, &DolphinMainWindow::slotUndoTextChanged); + connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted, + this, &DolphinMainWindow::clearStatusBar); + connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished, + this, &DolphinMainWindow::showCommand); GeneralSettings* generalSettings = GeneralSettings::self(); const bool firstRun = (generalSettings->version() < 200); @@ -134,50 +153,36 @@ DolphinMainWindow::DolphinMainWindow() : setAcceptDrops(true); + m_tabWidget = new DolphinTabWidget(this); + m_tabWidget->setObjectName("tabWidget"); + connect(m_tabWidget, &DolphinTabWidget::activeViewChanged, + this, &DolphinMainWindow::activeViewChanged); + connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, + this, &DolphinMainWindow::tabCountChanged); + connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged, + this, &DolphinMainWindow::updateWindowTitle); + setCentralWidget(m_tabWidget); + setupActions(); m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); - connect(m_actionHandler, SIGNAL(actionBeingHandled()), SLOT(clearStatusBar())); - connect(m_actionHandler, SIGNAL(createDirectory()), SLOT(createDirectory())); + connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar); + connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory); m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler); - connect(this, SIGNAL(urlChanged(KUrl)), - m_remoteEncoding, SLOT(slotAboutToOpenUrl())); - - m_tabBar = new DolphinTabBar(this); - connect(m_tabBar, SIGNAL(currentChanged(int)), - this, SLOT(setActiveTab(int))); - connect(m_tabBar, SIGNAL(tabCloseRequested(int)), - this, SLOT(closeTab(int))); - connect(m_tabBar, SIGNAL(openNewActivatedTab(int)), - this, SLOT(openNewActivatedTab(int))); - connect(m_tabBar, SIGNAL(tabMoved(int,int)), - this, SLOT(slotTabMoved(int,int))); - connect(m_tabBar, SIGNAL(tabDropEvent(int,QDropEvent*)), - this, SLOT(tabDropEvent(int,QDropEvent*))); - connect(m_tabBar, SIGNAL(tabDetachRequested(int)), - this, SLOT(detachTab(int))); - - m_tabBar->blockSignals(true); // signals get unblocked after at least 2 tabs are open - m_tabBar->hide(); - - QWidget* centralWidget = new QWidget(this); - m_centralWidgetLayout = new QVBoxLayout(centralWidget); - m_centralWidgetLayout->setSpacing(0); - m_centralWidgetLayout->setMargin(0); - m_centralWidgetLayout->addWidget(m_tabBar); - - setCentralWidget(centralWidget); + connect(this, &DolphinMainWindow::urlChanged, + m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl); + setupDockWidgets(); setupGUI(Keys | Save | Create | ToolBar); - stateChanged("new_file"); + stateChanged(QStringLiteral("new_file")); QClipboard* clipboard = QApplication::clipboard(); - connect(clipboard, SIGNAL(dataChanged()), - this, SLOT(updatePasteAction())); + connect(clipboard, &QClipboard::dataChanged, + this, &DolphinMainWindow::updatePasteAction); - QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); + QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar")); showFilterBarAction->setChecked(generalSettings->filterBar()); if (firstRun) { @@ -192,56 +197,56 @@ DolphinMainWindow::DolphinMainWindow() : if (!showMenu) { createControlButton(); } + + // enable middle-click on back/forward/up to open in a new tab + auto *middleClickEventFilter = new MiddleClickActionEventFilter(this); + connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked); + toolBar()->installEventFilter(middleClickEventFilter); + + setupWhatsThis(); + + QTimer::singleShot(0, this, &DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction); } DolphinMainWindow::~DolphinMainWindow() { } -void DolphinMainWindow::openDirectories(const QList& dirs) +QVector DolphinMainWindow::viewContainers() const { - const bool hasSplitView = GeneralSettings::splitView(); - - // Open each directory inside a new tab. If the "split view" option has been enabled, - // always show two directories within one tab. - QList::const_iterator it = dirs.constBegin(); - while (it != dirs.constEnd()) { - const KUrl& primaryUrl = *(it++); - if (hasSplitView && (it != dirs.constEnd())) { - const KUrl& secondaryUrl = *(it++); - openNewTab(primaryUrl, secondaryUrl); - } else { - openNewTab(primaryUrl); - } + QVector viewContainers; + viewContainers.reserve(m_tabWidget->count()); + for (int i = 0; i < m_tabWidget->count(); ++i) { + viewContainers << m_tabWidget->tabPageAt(i)->activeViewContainer(); } + return viewContainers; } -void DolphinMainWindow::openFiles(const QList& files) +void DolphinMainWindow::openDirectories(const QList& dirs, bool splitView) { - if (files.isEmpty()) { - return; - } + m_tabWidget->openDirectories(dirs, splitView); +} - // Get all distinct directories from 'files' and open a tab - // for each directory. If the "split view" option is enabled, two - // directories are shown inside one tab (see openDirectories()). - QList dirs; - foreach (const KUrl& url, files) { - const KUrl dir(url.directory()); - if (!dirs.contains(dir)) { - dirs.append(dir); - } - } +void DolphinMainWindow::openDirectories(const QStringList& dirs, bool splitView) +{ + openDirectories(QUrl::fromStringList(dirs), splitView); +} - openDirectories(dirs); +void DolphinMainWindow::openFiles(const QList& files, bool splitView) +{ + m_tabWidget->openFiles(files, splitView); +} - // Select the files. Although the files can be split between several - // tabs, there is no need to split 'files' accordingly, as - // the DolphinView will just ignore invalid selections. - foreach (DolphinTabPage* tabPage, m_viewTab) { - tabPage->markUrlsAsSelected(files); - tabPage->markUrlAsCurrent(files.first()); - } +void DolphinMainWindow::openFiles(const QStringList& files, bool splitView) +{ + openFiles(QUrl::fromStringList(files), splitView); +} + +void DolphinMainWindow::activateWindow() +{ + window()->setAttribute(Qt::WA_NativeWindow, true); + KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId()); + KWindowSystem::activateWindow(window()->effectiveWinId()); } void DolphinMainWindow::showCommand(CommandType command) @@ -278,7 +283,7 @@ void DolphinMainWindow::pasteIntoFolder() m_activeViewContainer->view()->pasteIntoFolder(); } -void DolphinMainWindow::changeUrl(const KUrl& url) +void DolphinMainWindow::changeUrl(const QUrl &url) { if (!KProtocolManager::supportsListing(url)) { // The URL navigator only checks for validity, not @@ -287,25 +292,22 @@ void DolphinMainWindow::changeUrl(const KUrl& url) return; } - DolphinViewContainer* view = activeViewContainer(); - if (view) { - view->setUrl(url); - updateEditActions(); - updatePasteAction(); - updateViewActions(); - updateGoActions(); - setUrlAsCaption(url); - - const QString iconName = KMimeType::iconNameForUrl(url); - m_tabBar->setTabIcon(m_tabIndex, KIcon(iconName)); - m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(view->url()))); + m_activeViewContainer->setUrl(url); + updateFileAndEditActions(); + updatePasteAction(); + updateViewActions(); + updateGoActions(); - emit urlChanged(url); - } + emit urlChanged(url); } -void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl& url) +void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url) { + if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) { + m_placesPanel->proceedWithTearDown(); + m_tearDownFromPlacesRequested = false; + } + m_activeViewContainer->setAutoGrabFocus(false); changeUrl(url); m_activeViewContainer->setAutoGrabFocus(true); @@ -314,17 +316,17 @@ void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl& url) void DolphinMainWindow::slotEditableStateChanged(bool editable) { KToggleAction* editableLocationAction = - static_cast(actionCollection()->action("editable_location")); + static_cast(actionCollection()->action(QStringLiteral("editable_location"))); editableLocationAction->setChecked(editable); } void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) { - updateEditActions(); + updateFileAndEditActions(); - const int selectedUrlsCount = m_viewTab.at(m_tabIndex)->selectedItemsCount(); + const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount(); - QAction* compareFilesAction = actionCollection()->action("compare_files"); + QAction* compareFilesAction = actionCollection()->action(QStringLiteral("compare_files")); if (selectedUrlsCount == 2) { compareFilesAction->setEnabled(isKompareInstalled()); } else { @@ -334,153 +336,107 @@ void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) emit selectionChanged(selection); } -void DolphinMainWindow::slotRequestItemInfo(const KFileItem& item) -{ - emit requestItemInfo(item); -} - void DolphinMainWindow::updateHistory() { const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); const int index = urlNavigator->historyIndex(); - QAction* backAction = actionCollection()->action("go_back"); + QAction* backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back)); if (backAction) { backAction->setToolTip(i18nc("@info", "Go back")); + backAction->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder.")); backAction->setEnabled(index < urlNavigator->historySize() - 1); } - QAction* forwardAction = actionCollection()->action("go_forward"); + QAction* forwardAction = actionCollection()->action(KStandardAction::name(KStandardAction::Forward)); if (forwardAction) { forwardAction->setToolTip(i18nc("@info", "Go forward")); + forwardAction->setWhatsThis(xi18nc("@info:whatsthis go forward", + "This undoes a Go|Back action.")); forwardAction->setEnabled(index > 0); } } void DolphinMainWindow::updateFilterBarAction(bool show) { - QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); + QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar")); showFilterBarAction->setChecked(show); } void DolphinMainWindow::openNewMainWindow() { - KRun::run("dolphin %u", KUrl::List(), this); + Dolphin::openNewWindow({m_activeViewContainer->url()}, this); } -void DolphinMainWindow::openNewTab() +void DolphinMainWindow::openNewActivatedTab() { - const bool isUrlEditable = m_activeViewContainer->urlNavigator()->isUrlEditable(); - - openNewTab(m_activeViewContainer->url()); - m_tabBar->setCurrentIndex(m_viewTab.count() - 1); - - // The URL navigator of the new tab should have the same editable state - // as the current tab - KUrlNavigator* navigator = m_activeViewContainer->urlNavigator(); - navigator->setUrlEditable(isUrlEditable); - - if (isUrlEditable) { - // If a new tab is opened and the URL is editable, assure that - // the user can edit the URL without manually setting the focus - navigator->setFocus(); - } + m_tabWidget->openNewActivatedTab(); } -void DolphinMainWindow::openNewTab(const KUrl& primaryUrl, const KUrl& secondaryUrl) +void DolphinMainWindow::addToPlaces() { - QWidget* focusWidget = QApplication::focusWidget(); - - DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this); - m_viewTab.append(tabPage); - - connect(tabPage, SIGNAL(activeViewChanged()), - this, SLOT(activeViewChanged())); - - // The places-selector from the URL navigator should only be shown - // if the places dock is invisible - QDockWidget* placesDock = findChild("placesDock"); - const bool placesSelectorVisible = !placesDock || !placesDock->isVisible(); - tabPage->setPlacesSelectorVisible(placesSelectorVisible); - - DolphinViewContainer* primaryContainer = tabPage->primaryViewContainer(); - connectViewSignals(primaryContainer); - - if (tabPage->splitViewEnabled()) { - DolphinViewContainer* secondaryContainer = tabPage->secondaryViewContainer(); - connectViewSignals(secondaryContainer); - } - - tabPage->hide(); - - m_tabBar->addTab(KIcon(KMimeType::iconNameForUrl(primaryUrl)), - squeezedText(tabName(primaryUrl))); - - if (m_viewTab.count() > 1) { - actionCollection()->action("close_tab")->setEnabled(true); - actionCollection()->action("activate_prev_tab")->setEnabled(true); - actionCollection()->action("activate_next_tab")->setEnabled(true); - m_tabBar->show(); - m_tabBar->blockSignals(false); - } + QUrl url; + QString name; - if (focusWidget) { - // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened - // in background, assure that the previous focused widget gets the focus back. - focusWidget->setFocus(); + // If nothing is selected, act on the current dir + if (m_activeViewContainer->view()->selectedItems().isEmpty()) { + url = m_activeViewContainer->url(); + name = m_activeViewContainer->placesText(); + } else { + const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first(); + url = dirToAdd.url(); + name = dirToAdd.name(); + } + if (url.isValid()) { + PlacesItemModel model; + QString icon; + if (m_activeViewContainer->isSearchModeEnabled()) { + icon = QStringLiteral("folder-saved-search-symbolic"); + } else { + icon = KIO::iconNameForUrl(url); + } + model.createPlacesItem(name, url, icon); } } -void DolphinMainWindow::openNewActivatedTab(const KUrl& primaryUrl, const KUrl& secondaryUrl) -{ - openNewTab(primaryUrl, secondaryUrl); - setActiveTab(m_viewTab.count() - 1); -} - -void DolphinMainWindow::openNewActivatedTab(int index) +void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement) { - Q_ASSERT(index >= 0); - const DolphinTabPage* tabPage = m_viewTab.at(index); - openNewActivatedTab(tabPage->activeViewContainer()->url()); + m_tabWidget->openNewTab(url, QUrl(), tabPlacement); } -void DolphinMainWindow::activateNextTab() +void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl& url) { - if (m_viewTab.count() >= 2) { - const int tabIndex = (m_tabBar->currentIndex() + 1) % m_tabBar->count(); - setActiveTab(tabIndex); - } + m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterCurrentTab); } -void DolphinMainWindow::activatePrevTab() +void DolphinMainWindow::openNewTabAfterLastTab(const QUrl& url) { - if (m_viewTab.count() >= 2) { - int tabIndex = m_tabBar->currentIndex() - 1; - if (tabIndex == -1) { - tabIndex = m_tabBar->count() - 1; - } - setActiveTab(tabIndex); - } + m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterLastTab); } void DolphinMainWindow::openInNewTab() { const KFileItemList& list = m_activeViewContainer->view()->selectedItems(); - if (list.isEmpty()) { - openNewTab(m_activeViewContainer->url()); - } else { - foreach (const KFileItem& item, list) { - const KUrl& url = DolphinView::openItemAsFolderUrl(item); - if (!url.isEmpty()) { - openNewTab(url); - } + bool tabCreated = false; + + foreach (const KFileItem& item, list) { + const QUrl& url = DolphinView::openItemAsFolderUrl(item); + if (!url.isEmpty()) { + openNewTabAfterCurrentTab(url); + tabCreated = true; } } + + // if no new tab has been created from the selection + // open the current directory in a new tab + if (!tabCreated) { + openNewTabAfterCurrentTab(m_activeViewContainer->url()); + } } void DolphinMainWindow::openInNewWindow() { - KUrl newWindowUrl; + QUrl newWindowUrl; const KFileItemList list = m_activeViewContainer->view()->selectedItems(); if (list.isEmpty()) { @@ -491,7 +447,23 @@ void DolphinMainWindow::openInNewWindow() } if (!newWindowUrl.isEmpty()) { - KRun::run("dolphin %u", KUrl::List() << newWindowUrl, this); + Dolphin::openNewWindow({newWindowUrl}, this); + } +} + +void DolphinMainWindow::showTarget() +{ + const auto link = m_activeViewContainer->view()->selectedItems().at(0); + const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir(); + auto linkDestination = link.linkDest(); + if (QFileInfo(linkDestination).isRelative()) { + linkDestination = linkLocationDir.filePath(linkDestination); + } + if (QFileInfo::exists(linkDestination)) { + KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)}); + } else { + m_activeViewContainer->showMessage(xi18nc("@info", "Could not access %1.", linkDestination), + DolphinViewContainer::Warning); } } @@ -499,12 +471,6 @@ void DolphinMainWindow::showEvent(QShowEvent* event) { KXmlGuiWindow::showEvent(event); - if (!m_activeViewContainer && m_viewTab.count() > 0) { - // If we have no active view container yet, we set the primary view container - // of the first tab as active view container. - setActiveTab(0); - } - if (!event->spontaneous()) { m_activeViewContainer->view()->setFocus(); } @@ -515,29 +481,29 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) // Find out if Dolphin is closed directly by the user or // by the session manager because the session is closed bool closedByUser = true; - DolphinApplication *application = qobject_cast(qApp); - if (application && application->sessionSaving()) { + if (qApp->isSavingSession()) { closedByUser = false; } - if (m_viewTab.count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser) { + if (m_tabWidget->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser) { // Ask the user if he really wants to quit and close all tabs. // Open a confirmation dialog with 3 buttons: - // KDialog::Yes -> Quit - // KDialog::No -> Close only the current tab - // KDialog::Cancel -> do nothing - KDialog *dialog = new KDialog(this, Qt::Dialog); - dialog->setCaption(i18nc("@title:window", "Confirmation")); - dialog->setButtons(KDialog::Yes | KDialog::No | KDialog::Cancel); + // QDialogButtonBox::Yes -> Quit + // QDialogButtonBox::No -> Close only the current tab + // QDialogButtonBox::Cancel -> do nothing + QDialog *dialog = new QDialog(this, Qt::Dialog); + dialog->setWindowTitle(i18nc("@title:window", "Confirmation")); dialog->setModal(true); - dialog->setButtonGuiItem(KDialog::Yes, KStandardGuiItem::quit()); - dialog->setButtonGuiItem(KDialog::No, KGuiItem(i18n("C&lose Current Tab"), KIcon("tab-close"))); - dialog->setButtonGuiItem(KDialog::Cancel, KStandardGuiItem::cancel()); - dialog->setDefaultButton(KDialog::Yes); + QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel); + KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit")))); + KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close")))); + KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); + buttons->button(QDialogButtonBox::Yes)->setDefault(true); bool doNotAskAgainCheckboxResult = false; - const int result = KMessageBox::createKMessageBox(dialog, + const auto result = KMessageBox::createKMessageBox(dialog, + buttons, QMessageBox::Warning, i18n("You have multiple tabs open in this window, are you sure you want to quit?"), QStringList(), @@ -550,65 +516,106 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) } switch (result) { - case KDialog::Yes: + case QDialogButtonBox::Yes: // Quit break; - case KDialog::No: + case QDialogButtonBox::No: // Close only the current tab - closeTab(); + m_tabWidget->closeTab(); + Q_FALLTHROUGH(); + default: + event->ignore(); + return; + } + } + + if (m_terminalPanel && m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) { + // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel + // Open a confirmation dialog with 3 buttons: + // QDialogButtonBox::Yes -> Quit + // QDialogButtonBox::No -> Show Terminal Panel + // QDialogButtonBox::Cancel -> do nothing + QDialog *dialog = new QDialog(this, Qt::Dialog); + dialog->setWindowTitle(i18nc("@title:window", "Confirmation")); + dialog->setModal(true); + auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel; + if (!m_terminalPanel->isVisible()) { + standardButtons |= QDialogButtonBox::No; + } + QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons); + KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit()); + if (!m_terminalPanel->isVisible()) { + KGuiItem::assign( + buttons->button(QDialogButtonBox::No), + KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts")))); + } + KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); + + bool doNotAskAgainCheckboxResult = false; + + const auto result = KMessageBox::createKMessageBox( + dialog, + buttons, + QMessageBox::Warning, + i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()), + QStringList(), + i18n("Do not ask again"), + &doNotAskAgainCheckboxResult, + KMessageBox::Dangerous); + + if (doNotAskAgainCheckboxResult) { + GeneralSettings::setConfirmClosingTerminalRunningProgram(false); + } + + switch (result) { + case QDialogButtonBox::Yes: + // Quit + break; + case QDialogButtonBox::No: + actionCollection()->action("show_terminal_panel")->trigger(); + // Do not quit, ignore quit event + Q_FALLTHROUGH(); default: event->ignore(); return; } } + 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()->writeConfig(); + GeneralSettings::self()->save(); KXmlGuiWindow::closeEvent(event); } void DolphinMainWindow::saveProperties(KConfigGroup& group) { - const int tabCount = m_viewTab.count(); - group.writeEntry("Tab Count", tabCount); - group.writeEntry("Active Tab Index", m_tabBar->currentIndex()); - - for (int i = 0; i < tabCount; ++i) { - const DolphinTabPage* tabPage = m_viewTab.at(i); - group.writeEntry("Tab " % QString::number(i), tabPage->saveState()); - } + m_tabWidget->saveProperties(group); } void DolphinMainWindow::readProperties(const KConfigGroup& group) { - const int tabCount = group.readEntry("Tab Count", 1); - for (int i = 0; i < tabCount; ++i) { - const QByteArray state = group.readEntry("Tab " % QString::number(i), QByteArray()); - DolphinTabPage* tabPage = m_viewTab.at(i); - tabPage->restoreState(state); - - // openNewTab() needs to be called only tabCount - 1 times - if (i != tabCount - 1) { - openNewTab(); - } - } - - const int index = group.readEntry("Active Tab Index", 0); - m_tabBar->setCurrentIndex(index); + m_tabWidget->readProperties(group); } void DolphinMainWindow::updateNewMenu() { m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown()); m_newFileMenu->checkUpToDate(); - m_newFileMenu->setPopupFiles(activeViewContainer()->url()); + m_newFileMenu->setPopupFiles(QList() << activeViewContainer()->url()); } void DolphinMainWindow::createDirectory() { m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown()); - m_newFileMenu->setPopupFiles(activeViewContainer()->url()); + m_newFileMenu->setPopupFiles(QList() << activeViewContainer()->url()); m_newFileMenu->createDirectory(); } @@ -652,7 +659,7 @@ void DolphinMainWindow::cut() void DolphinMainWindow::copy() { - m_activeViewContainer->view()->copySelectedItems(); + m_activeViewContainer->view()->copySelectedItemsToClipboard(); } void DolphinMainWindow::paste() @@ -665,6 +672,12 @@ void DolphinMainWindow::find() m_activeViewContainer->setSearchModeEnabled(true); } +void DolphinMainWindow::updateSearchAction() +{ + QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled()); +} + void DolphinMainWindow::updatePasteAction() { QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); @@ -673,6 +686,74 @@ void DolphinMainWindow::updatePasteAction() pasteAction->setText(pasteInfo.second); } +void DolphinMainWindow::slotDirectoryLoadingCompleted() +{ + updatePasteAction(); +} + +void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action) +{ + if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) { + goBackInNewTab(); + } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) { + goForwardInNewTab(); + } else if (action == actionCollection()->action(QStringLiteral("go_up"))) { + goUpInNewTab(); + } else if (action == actionCollection()->action(QStringLiteral("go_home"))) { + goHomeInNewTab(); + } +} + +void DolphinMainWindow::slotAboutToShowBackPopupMenu() +{ + KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); + int entries = 0; + m_backAction->menu()->clear(); + for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) { + QAction* action = new QAction(urlNavigator->locationUrl(i).toString(QUrl::PreferLocalFile), m_backAction->menu()); + action->setData(i); + m_backAction->menu()->addAction(action); + } +} + +void DolphinMainWindow::slotGoBack(QAction* action) +{ + int gotoIndex = action->data().value(); + KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); + for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) { + goBack(); + } +} + +void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction* action) +{ + if (action) { + KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); + openNewTabAfterCurrentTab(urlNavigator->locationUrl(action->data().value())); + } +} + +void DolphinMainWindow::slotAboutToShowForwardPopupMenu() +{ + KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); + int entries = 0; + m_forwardAction->menu()->clear(); + for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) { + QAction* action = new QAction(urlNavigator->locationUrl(i).toString(QUrl::PreferLocalFile), m_forwardAction->menu()); + action->setData(i); + m_forwardAction->menu()->addAction(action); + } +} + +void DolphinMainWindow::slotGoForward(QAction* action) +{ + int gotoIndex = action->data().value(); + KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); + for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) { + goForward(); + } +} + void DolphinMainWindow::selectAll() { clearStatusBar(); @@ -681,7 +762,7 @@ void DolphinMainWindow::selectAll() // URL instead of all items of the view KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); - QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses + QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); const bool selectUrl = urlNavigator->isUrlEditable() && lineEdit->hasFocus(); if (selectUrl) { @@ -699,20 +780,24 @@ void DolphinMainWindow::invertSelection() void DolphinMainWindow::toggleSplitView() { - DolphinTabPage* tabPage = m_viewTab.at(m_tabIndex); + DolphinTabPage* tabPage = m_tabWidget->currentTabPage(); tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled()); - if (tabPage->splitViewEnabled()) { - connectViewSignals(tabPage->secondaryViewContainer()); - } - updateViewActions(); } +void DolphinMainWindow::toggleSplitStash() +{ + DolphinTabPage* tabPage = m_tabWidget->currentTabPage(); + tabPage->setSplitViewEnabled(false); + tabPage->setSplitViewEnabled(true, QUrl("stash:/")); +} + void DolphinMainWindow::reloadView() { clearStatusBar(); - m_activeViewContainer->view()->reload(); + m_activeViewContainer->reload(); + m_activeViewContainer->statusBar()->updateSpaceInfo(); } void DolphinMainWindow::stopLoading() @@ -722,12 +807,12 @@ void DolphinMainWindow::stopLoading() void DolphinMainWindow::enableStopAction() { - actionCollection()->action("stop")->setEnabled(true); + actionCollection()->action(QStringLiteral("stop"))->setEnabled(true); } void DolphinMainWindow::disableStopAction() { - actionCollection()->action("stop")->setEnabled(false); + actionCollection()->action(QStringLiteral("stop"))->setEnabled(false); } void DolphinMainWindow::showFilterBar() @@ -739,7 +824,7 @@ void DolphinMainWindow::toggleEditLocation() { clearStatusBar(); - QAction* action = actionCollection()->action("editable_location"); + QAction* action = actionCollection()->action(QStringLiteral("editable_location")); KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); urlNavigator->setUrlEditable(action->isChecked()); } @@ -747,12 +832,19 @@ void DolphinMainWindow::toggleEditLocation() void DolphinMainWindow::replaceLocation() { KUrlNavigator* navigator = m_activeViewContainer->urlNavigator(); - navigator->setUrlEditable(true); - navigator->setFocus(); - - // select the whole text of the combo box editor - QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses - lineEdit->selectAll(); + QLineEdit* lineEdit = navigator->editor()->lineEdit(); + + // If the text field currently has focus and everything is selected, + // pressing the keyboard shortcut returns the whole thing to breadcrumb mode + if (navigator->isUrlEditable() + && lineEdit->hasFocus() + && lineEdit->selectedText() == lineEdit->text() ) { + navigator->setUrlEditable(false); + } else { + navigator->setUrlEditable(true); + navigator->setFocus(); + lineEdit->selectAll(); + } } void DolphinMainWindow::togglePanelLockState() @@ -768,11 +860,10 @@ void DolphinMainWindow::togglePanelLockState() GeneralSettings::setLockPanels(newLockState); } -void DolphinMainWindow::slotPlacesPanelVisibilityChanged(bool visible) +void DolphinMainWindow::slotTerminalPanelVisibilityChanged() { - foreach (DolphinTabPage* tabPage, m_viewTab) { - // The Places selector in the location bar should be shown if and only if the Places panel is hidden. - tabPage->setPlacesSelectorVisible(!visible); + if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) { + m_activeViewContainer->view()->setFocus(); } } @@ -803,60 +894,52 @@ void DolphinMainWindow::goHome() m_activeViewContainer->urlNavigator()->goHome(); } -void DolphinMainWindow::goBack(Qt::MouseButtons buttons) +void DolphinMainWindow::goBackInNewTab() { - // The default case (left button pressed) is handled in goBack(). - if (buttons == Qt::MidButton) { - KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); - const int index = urlNavigator->historyIndex() + 1; - openNewTab(urlNavigator->locationUrl(index)); - } + KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); + const int index = urlNavigator->historyIndex() + 1; + openNewTabAfterCurrentTab(urlNavigator->locationUrl(index)); } -void DolphinMainWindow::goForward(Qt::MouseButtons buttons) +void DolphinMainWindow::goForwardInNewTab() { - // The default case (left button pressed) is handled in goForward(). - if (buttons == Qt::MidButton) { - KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); - const int index = urlNavigator->historyIndex() - 1; - openNewTab(urlNavigator->locationUrl(index)); - } + KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator(); + const int index = urlNavigator->historyIndex() - 1; + openNewTabAfterCurrentTab(urlNavigator->locationUrl(index)); } -void DolphinMainWindow::goUp(Qt::MouseButtons buttons) +void DolphinMainWindow::goUpInNewTab() { - // The default case (left button pressed) is handled in goUp(). - if (buttons == Qt::MidButton) { - openNewTab(activeViewContainer()->url().upUrl()); - } + const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl(); + openNewTabAfterCurrentTab(KIO::upUrl(currentUrl)); } -void DolphinMainWindow::goHome(Qt::MouseButtons buttons) +void DolphinMainWindow::goHomeInNewTab() { - // The default case (left button pressed) is handled in goHome(). - if (buttons == Qt::MidButton) { - openNewTab(GeneralSettings::self()->homeUrl()); - } + openNewTabAfterCurrentTab(Dolphin::homeUrl()); } void DolphinMainWindow::compareFiles() { - const KFileItemList items = m_viewTab.at(m_tabIndex)->selectedItems(); + const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems(); if (items.count() != 2) { // The action is disabled in this case, but it could have been triggered // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517 return; } - KUrl urlA = items.at(0).url(); - KUrl urlB = items.at(1).url(); + QUrl urlA = items.at(0).url(); + QUrl urlB = items.at(1).url(); - QString command("kompare -c \""); - command.append(urlA.pathOrUrl()); + QString command(QStringLiteral("kompare -c \"")); + command.append(urlA.toDisplayString(QUrl::PreferLocalFile)); command.append("\" \""); - command.append(urlB.pathOrUrl()); + command.append(urlB.toDisplayString(QUrl::PreferLocalFile)); command.append('\"'); - KRun::runCommand(command, "Kompare", "kompare", this); + + KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this); + job->setDesktopName(QStringLiteral("org.kde.kompare")); + job->start(); } void DolphinMainWindow::toggleShowMenuBar() @@ -870,159 +953,122 @@ void DolphinMainWindow::toggleShowMenuBar() } } -void DolphinMainWindow::openTerminal() +QString DolphinMainWindow::activeContainerLocalPath() { - QString dir(QDir::homePath()); - - // If the given directory is not local, it can still be the URL of an - // ioslave using UDS_LOCAL_PATH which to be converted first. - KUrl url = KIO::NetAccess::mostLocalUrl(m_activeViewContainer->url(), this); - - //If the URL is local after the above conversion, set the directory. + KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url()); + KJobWidgets::setWindow(statJob, this); + statJob->exec(); + QUrl url = statJob->mostLocalUrl(); if (url.isLocalFile()) { - dir = url.toLocalFile(); + return url.toLocalFile(); } - - KToolInvocation::invokeTerminal(QString(), dir); + return QDir::homePath(); } -void DolphinMainWindow::editSettings() +QPointer DolphinMainWindow::preferredSearchTool() { - if (!m_settingsDialog) { - DolphinViewContainer* container = activeViewContainer(); - container->view()->writeSettings(); - - const KUrl url = container->url(); - DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this); - connect(settingsDialog, SIGNAL(settingsChanged()), this, SLOT(refreshViews())); - settingsDialog->setAttribute(Qt::WA_DeleteOnClose); - settingsDialog->show(); - m_settingsDialog = settingsDialog; - } else { - m_settingsDialog.data()->raise(); + m_searchTools.clear(); + KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames( + &m_searchTools, { "files-find" }, m_activeViewContainer->url() + ); + QList actions = m_searchTools.actions(); + if (actions.isEmpty()) { + return nullptr; + } + QAction* action = actions.first(); + if (action->isSeparator()) { + return nullptr; } + return action; } -void DolphinMainWindow::setActiveTab(int index) +void DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction() { - Q_ASSERT(index >= 0); - Q_ASSERT(index < m_viewTab.count()); - if (index == m_tabIndex) { - return; - } - - m_tabBar->setCurrentIndex(index); - - // hide current tab content - if (m_tabIndex >= 0) { - DolphinTabPage* hiddenTabPage = m_viewTab.at(m_tabIndex); - hiddenTabPage->hide(); - m_centralWidgetLayout->removeWidget(hiddenTabPage); + 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); + } } - // show active tab content - m_tabIndex = index; - - DolphinTabPage* tabPage = m_viewTab.at(index); - m_centralWidgetLayout->addWidget(tabPage, 1); - tabPage->show(); + // 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 + ); - setActiveViewContainer(tabPage->activeViewContainer()); -} - -void DolphinMainWindow::closeTab() -{ - closeTab(m_tabBar->currentIndex()); + updateOpenPreferredSearchToolAction(); } -void DolphinMainWindow::closeTab(int index) +void DolphinMainWindow::updateOpenPreferredSearchToolAction() { - Q_ASSERT(index >= 0); - Q_ASSERT(index < m_viewTab.count()); - if (m_viewTab.count() == 1) { - // the last tab may never get closed + QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool")); + if (!openPreferredSearchTool) { return; } - - if (index == m_tabIndex) { - // The tab that should be closed is the active tab. Activate the - // previous tab before closing the tab. - m_tabBar->setCurrentIndex((index > 0) ? index - 1 : 1); - } - - DolphinTabPage* tabPage = m_viewTab.at(index); - - if (tabPage->splitViewEnabled()) { - emit rememberClosedTab(tabPage->primaryViewContainer()->url(), - tabPage->secondaryViewContainer()->url()); - } else { - emit rememberClosedTab(tabPage->primaryViewContainer()->url(), KUrl()); - } - - // delete tab - m_viewTab.removeAt(index); - tabPage->deleteLater(); - - m_tabBar->blockSignals(true); - m_tabBar->removeTab(index); - - if (m_tabIndex > index) { - m_tabIndex--; - Q_ASSERT(m_tabIndex >= 0); - } - - // if only one tab is left, also remove the tab entry so that - // closing the last tab is not possible - if (m_viewTab.count() < 2) { - actionCollection()->action("close_tab")->setEnabled(false); - actionCollection()->action("activate_prev_tab")->setEnabled(false); - actionCollection()->action("activate_next_tab")->setEnabled(false); - m_tabBar->hide(); + QPointer tool = preferredSearchTool(); + if (tool) { + openPreferredSearchTool->setVisible(true); + openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text())); + openPreferredSearchTool->setIcon(tool->icon()); } else { - m_tabBar->blockSignals(false); + openPreferredSearchTool->setVisible(false); + // still visible in Shortcuts configuration window + openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool")); + openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search"))); } } -void DolphinMainWindow::detachTab(int index) +void DolphinMainWindow::openPreferredSearchTool() { - Q_ASSERT(index >= 0); - - const QString separator(QLatin1Char(' ')); - QString command = QLatin1String("dolphin"); - - const DolphinTabPage* tabPage = m_viewTab.at(index); - command += separator + tabPage->primaryViewContainer()->url().url(); - if (tabPage->splitViewEnabled()) { - command += separator + tabPage->secondaryViewContainer()->url().url(); - command += separator + QLatin1String("-split"); + QPointer tool = preferredSearchTool(); + if (tool) { + tool->trigger(); } +} - KRun::runCommand(command, this); - - closeTab(index); +void DolphinMainWindow::openTerminal() +{ + KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath()); } -void DolphinMainWindow::slotTabMoved(int from, int to) +void DolphinMainWindow::editSettings() { - m_viewTab.move(from, to); - m_tabIndex = m_tabBar->currentIndex(); + if (!m_settingsDialog) { + DolphinViewContainer* container = activeViewContainer(); + container->view()->writeSettings(); + + const QUrl url = container->url(); + DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this); + connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews); + settingsDialog->setAttribute(Qt::WA_DeleteOnClose); + settingsDialog->show(); + m_settingsDialog = settingsDialog; + } else { + m_settingsDialog.data()->raise(); + } } -void DolphinMainWindow::handleUrl(const KUrl& url) +void DolphinMainWindow::handleUrl(const QUrl& url) { delete m_lastHandleUrlStatJob; - m_lastHandleUrlStatJob = 0; + m_lastHandleUrlStatJob = 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->ui()) { - m_lastHandleUrlStatJob->ui()->setWindow(this); + if (m_lastHandleUrlStatJob->uiDelegate()) { + KJobWidgets::setWindow(m_lastHandleUrlStatJob, this); } - connect(m_lastHandleUrlStatJob, SIGNAL(result(KJob*)), - this, SLOT(slotHandleUrlStatFinished(KJob*))); + connect(m_lastHandleUrlStatJob, &KIO::Job::result, + this, &DolphinMainWindow::slotHandleUrlStatFinished); } else { new KRun(url, this); // Automatically deletes itself after being finished @@ -1031,9 +1077,9 @@ void DolphinMainWindow::handleUrl(const KUrl& url) void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job) { - m_lastHandleUrlStatJob = 0; + m_lastHandleUrlStatJob = nullptr; const KIO::UDSEntry entry = static_cast(job)->statResult(); - const KUrl url = static_cast(job)->url(); + const QUrl url = static_cast(job)->url(); if (entry.isDir()) { activeViewContainer()->setUrl(url); } else { @@ -1041,42 +1087,35 @@ void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job) } } -void DolphinMainWindow::tabDropEvent(int tab, QDropEvent* event) -{ - const KUrl::List urls = KUrl::List::fromMimeData(event->mimeData()); - if (!urls.isEmpty() && tab != -1) { - const DolphinView* view = m_viewTab.at(tab)->activeViewContainer()->view(); - - QString error; - DragAndDropHelper::dropUrls(view->rootItem(), view->url(), event, error); - if (!error.isEmpty()) { - activeViewContainer()->showMessage(error, DolphinViewContainer::Error); - } - } -} - void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) { - newFileMenu()->setEnabled(isFolderWritable); + // trash:/ is writable but we don't want to create new items in it. + // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented + newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash")); } void DolphinMainWindow::openContextMenu(const QPoint& pos, const KFileItem& item, - const KUrl& url, + const QUrl& url, const QList& customActions) { - QWeakPointer contextMenu = new DolphinContextMenu(this, pos, item, url); + QPointer contextMenu = new DolphinContextMenu(this, pos, item, url); contextMenu.data()->setCustomActions(customActions); const DolphinContextMenu::Command command = contextMenu.data()->open(); switch (command) { - case DolphinContextMenu::OpenParentFolderInNewWindow: { - KRun::run("dolphin %u", KUrl::List() << item.url().upUrl(), this); + case DolphinContextMenu::OpenParentFolder: + changeUrl(KIO::upUrl(item.url())); + m_activeViewContainer->view()->markUrlsAsSelected({item.url()}); + m_activeViewContainer->view()->markUrlAsCurrent(item.url()); + break; + + case DolphinContextMenu::OpenParentFolderInNewWindow: + Dolphin::openNewWindow({item.url()}, this, Dolphin::OpenNewWindowFlag::Select); break; - } case DolphinContextMenu::OpenParentFolderInNewTab: - openNewTab(item.url().upUrl()); + openNewTabAfterLastTab(KIO::upUrl(item.url())); break; case DolphinContextMenu::None: @@ -1084,25 +1123,34 @@ void DolphinMainWindow::openContextMenu(const QPoint& pos, break; } - delete contextMenu.data(); + // Delete the menu, unless it has been deleted in its own nested event loop already. + if (contextMenu) { + contextMenu->deleteLater(); + } } void DolphinMainWindow::updateControlMenu() { - KMenu* menu = qobject_cast(sender()); + QMenu* menu = qobject_cast(sender()); Q_ASSERT(menu); - // All actions get cleared by KMenu::clear(). The sub-menus are deleted - // by connecting to the aboutToHide() signal from the parent-menu. + // All actions get cleared by QMenu::clear(). This includes the sub-menus + // because 'menu' is their parent. menu->clear(); KActionCollection* ac = actionCollection(); + menu->addMenu(m_newFileMenu->menu()); + addActionToMenu(ac->action(QStringLiteral("file_new")), menu); + addActionToMenu(ac->action(QStringLiteral("new_tab")), menu); + addActionToMenu(ac->action(QStringLiteral("closed_tabs")), menu); + + menu->addSeparator(); + // Add "Edit" actions bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) | - addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Find)), menu) | - addActionToMenu(ac->action("select_all"), menu) | - addActionToMenu(ac->action("invert_selection"), menu); + addActionToMenu(ac->action(KStandardAction::name(KStandardAction::SelectAll)), menu) | + addActionToMenu(ac->action(QStringLiteral("invert_selection")), menu); if (added) { menu->addSeparator(); @@ -1111,76 +1159,42 @@ void DolphinMainWindow::updateControlMenu() // Add "View" actions if (!GeneralSettings::showZoomSlider()) { addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu); + addActionToMenu(ac->action(QStringLiteral("view_zoom_reset")), menu); addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu); menu->addSeparator(); } - added = addActionToMenu(ac->action("view_mode"), menu) | - addActionToMenu(ac->action("sort"), menu) | - addActionToMenu(ac->action("additional_info"), menu) | - addActionToMenu(ac->action("show_preview"), menu) | - addActionToMenu(ac->action("show_in_groups"), menu) | - addActionToMenu(ac->action("show_hidden_files"), menu); + added = addActionToMenu(ac->action(QStringLiteral("show_preview")), menu) | + addActionToMenu(ac->action(QStringLiteral("show_in_groups")), menu) | + addActionToMenu(ac->action(QStringLiteral("show_hidden_files")), menu) | + addActionToMenu(ac->action(QStringLiteral("additional_info")), menu) | + addActionToMenu(ac->action(QStringLiteral("view_properties")), menu); if (added) { menu->addSeparator(); } - added = addActionToMenu(ac->action("split_view"), menu) | - addActionToMenu(ac->action("reload"), menu) | - addActionToMenu(ac->action("view_properties"), menu); - if (added) { - menu->addSeparator(); - } - - addActionToMenu(ac->action("panels"), menu); - KMenu* locationBarMenu = new KMenu(i18nc("@action:inmenu", "Location Bar"), menu); - locationBarMenu->addAction(ac->action("editable_location")); - locationBarMenu->addAction(ac->action("replace_location")); - menu->addMenu(locationBarMenu); + // Add a curated assortment of items from the "Tools" menu + 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(); - // Add "Go" menu - KMenu* goMenu = new KMenu(i18nc("@action:inmenu", "Go"), menu); - connect(menu, SIGNAL(aboutToHide()), goMenu, SLOT(deleteLater())); - goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Back))); - goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Forward))); - goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Up))); - goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Home))); - goMenu->addAction(ac->action("closed_tabs")); - menu->addMenu(goMenu); - - // Add "Tool" menu - KMenu* toolsMenu = new KMenu(i18nc("@action:inmenu", "Tools"), menu); - connect(menu, SIGNAL(aboutToHide()), toolsMenu, SLOT(deleteLater())); - toolsMenu->addAction(ac->action("show_filter_bar")); - toolsMenu->addAction(ac->action("compare_files")); - toolsMenu->addAction(ac->action("open_terminal")); - toolsMenu->addAction(ac->action("change_remote_encoding")); - menu->addMenu(toolsMenu); + // Add "Show Panels" menu + addActionToMenu(ac->action(QStringLiteral("panels")), menu); // Add "Settings" menu entries addActionToMenu(ac->action(KStandardAction::name(KStandardAction::KeyBindings)), menu); addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)), menu); addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Preferences)), menu); + addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu); // Add "Help" menu - KMenu* helpMenu = new KMenu(i18nc("@action:inmenu", "Help"), menu); - connect(menu, SIGNAL(aboutToHide()), helpMenu, SLOT(deleteLater())); - helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::HelpContents))); - helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::WhatsThis))); - helpMenu->addSeparator(); - helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ReportBug))); - helpMenu->addSeparator(); - helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))); - helpMenu->addSeparator(); - helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutApp))); - helpMenu->addAction(ac->action(KStandardAction::name(KStandardAction::AboutKDE))); + auto helpMenu = m_helpMenu->menu(); + helpMenu->setIcon(QIcon::fromTheme(QStringLiteral("system-help"))); menu->addMenu(helpMenu); - - menu->addSeparator(); - addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu); } void DolphinMainWindow::updateToolBar() @@ -1192,16 +1206,11 @@ void DolphinMainWindow::updateToolBar() void DolphinMainWindow::slotControlButtonDeleted() { - m_controlButton = 0; + m_controlButton = nullptr; m_updateToolBarTimer->start(); } -void DolphinMainWindow::slotPanelErrorMessage(const QString& error) -{ - activeViewContainer()->showMessage(error, DolphinViewContainer::Error); -} - -void DolphinMainWindow::slotPlaceActivated(const KUrl& url) +void DolphinMainWindow::slotPlaceActivated(const QUrl& url) { DolphinViewContainer* view = activeViewContainer(); @@ -1214,359 +1223,712 @@ void DolphinMainWindow::slotPlaceActivated(const KUrl& url) } } -void DolphinMainWindow::activeViewChanged() +void DolphinMainWindow::closedTabsCountChanged(unsigned int count) { - const DolphinTabPage* tabPage = m_viewTab.at(m_tabIndex); - setActiveViewContainer(tabPage->activeViewContainer()); + actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0); } -void DolphinMainWindow::setActiveViewContainer(DolphinViewContainer* viewContainer) +void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) { + DolphinViewContainer* oldViewContainer = m_activeViewContainer; Q_ASSERT(viewContainer); - Q_ASSERT((viewContainer == m_viewTab.at(m_tabIndex)->primaryViewContainer()) || - (viewContainer == m_viewTab.at(m_tabIndex)->secondaryViewContainer())); - if (m_activeViewContainer == viewContainer) { - return; - } m_activeViewContainer = viewContainer; + + if (oldViewContainer) { + const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + toggleSearchAction->disconnect(oldViewContainer); + + // Disconnect all signals between the old view container (container, + // view and url navigator) and main window. + oldViewContainer->disconnect(this); + oldViewContainer->view()->disconnect(this); + oldViewContainer->urlNavigator()->disconnect(this); + + // except the requestItemInfo so that on hover the information panel can still be updated + connect(oldViewContainer->view(), &DolphinView::requestItemInfo, + this, &DolphinMainWindow::requestItemInfo); + } + + connectViewSignals(viewContainer); + m_actionHandler->setCurrentView(viewContainer->view()); updateHistory(); - updateEditActions(); + updateFileAndEditActions(); updatePasteAction(); updateViewActions(); updateGoActions(); + updateSearchAction(); - const KUrl url = m_activeViewContainer->url(); - setUrlAsCaption(url); - m_tabBar->setTabText(m_tabIndex, squeezedText(tabName(url))); - m_tabBar->setTabIcon(m_tabIndex, KIcon(KMimeType::iconNameForUrl(url))); - + const QUrl url = viewContainer->url(); emit urlChanged(url); } +void DolphinMainWindow::tabCountChanged(int count) +{ + const bool enableTabActions = (count > 1); + for (int i = 0; i < MaxActivateTabShortcuts; ++i) { + actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions); + } + actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions); + actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); + actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); +} + +void DolphinMainWindow::updateWindowTitle() +{ + const QString newTitle = m_activeViewContainer->captionWindowTitle(); + if (windowTitle() != newTitle) { + setWindowTitle(newTitle); + } +} + +void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) +{ + if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) { + m_tearDownFromPlacesRequested = true; + m_terminalPanel->goHome(); + // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged + } else { + m_placesPanel->proceedWithTearDown(); + } +} + +void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath) +{ + if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) { + m_tearDownFromPlacesRequested = false; + m_terminalPanel->goHome(); + } +} + void DolphinMainWindow::setupActions() { // setup 'File' menu m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this); - KMenu* menu = m_newFileMenu->menu(); + QMenu* menu = m_newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); - menu->setIcon(KIcon("document-new")); + menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); m_newFileMenu->setDelayed(false); - connect(menu, SIGNAL(aboutToShow()), - this, SLOT(updateNewMenu())); + connect(menu, &QMenu::aboutToShow, + this, &DolphinMainWindow::updateNewMenu); - KAction* newWindow = actionCollection()->addAction("new_window"); - newWindow->setIcon(KIcon("window-new")); + QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection()); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); - newWindow->setShortcut(Qt::CTRL | Qt::Key_N); - connect(newWindow, SIGNAL(triggered()), this, SLOT(openNewMainWindow())); - - KAction* newTab = actionCollection()->addAction("new_tab"); - newTab->setIcon(KIcon("tab-new")); + newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window")); + newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new " + "window just like this one with the current location and view." + "You can drag and drop items between windows.")); + newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); + + QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab")); + newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); newTab->setText(i18nc("@action:inmenu File", "New Tab")); - newTab->setShortcut(KShortcut(Qt::CTRL | Qt::Key_T, Qt::CTRL | Qt::SHIFT | Qt::Key_N)); - connect(newTab, SIGNAL(triggered()), this, SLOT(openNewTab())); - - KAction* closeTab = actionCollection()->addAction("close_tab"); - closeTab->setIcon(KIcon("tab-close")); + newTab->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new " + "Tab with the current location and view." + "A tab is an additional view within this window. " + "You can drag and drop items between tabs.")); + actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N}); + connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab); + + QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places")); + addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new"))); + addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places")); + addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder " + "to the Places panel.")); + connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces); + + QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection()); closeTab->setText(i18nc("@action:inmenu File", "Close Tab")); - closeTab->setShortcut(Qt::CTRL | Qt::Key_W); - closeTab->setEnabled(false); - connect(closeTab, SIGNAL(triggered()), this, SLOT(closeTab())); + closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the " + "currently viewed tab. If no more tabs are left this window " + "will close instead.")); - KStandardAction::quit(this, SLOT(quit()), actionCollection()); + QAction* quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection()); + quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window.")); // setup 'Edit' menu KStandardAction::undo(this, - SLOT(undo()), + &DolphinMainWindow::undo, actionCollection()); - // need to remove shift+del from cut action, else the shortcut for deletejob - // doesn't work - KAction* cut = KStandardAction::cut(this, SLOT(cut()), actionCollection()); - KShortcut cutShortcut = cut->shortcut(); - cutShortcut.remove(Qt::SHIFT | Qt::Key_Delete, KShortcut::KeepEmpty); - cut->setShortcut(cutShortcut); - KStandardAction::copy(this, SLOT(copy()), actionCollection()); - KAction* paste = KStandardAction::paste(this, SLOT(paste()), actionCollection()); + // i18n: This will be the last paragraph for the whatsthis for all three: + // Cut, Copy and Paste + const QString cutCopyPastePara = xi18nc("@info:whatsthis", "Cut, " + "Copy and Paste work between many " + "applications and are among the most used commands. That's why their " + "keyboard shortcuts are prominently placed right " + "next to each other on the keyboard: Ctrl+X, " + "Ctrl+C and Ctrl+V."); + QAction* cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection()); + cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items " + "in your current selection to the clipboard." + "Use the Paste action afterwards to copy them from " + "the clipboard to a new location. The items will be removed from their " + "initial location.") + cutCopyPastePara); + QAction* copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection()); + copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the " + "items in your current selection to the clipboard." + "Use the Paste action afterwards to copy them " + "from the clipboard to a new location.") + cutCopyPastePara); + QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection()); // The text of the paste-action is modified dynamically by Dolphin // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes // due to the long text, the text "Paste" is used: paste->setIconText(i18nc("@action:inmenu Edit", "Paste")); - - KStandardAction::find(this, SLOT(find()), actionCollection()); - - KAction* selectAll = actionCollection()->addAction("select_all"); - selectAll->setText(i18nc("@action:inmenu Edit", "Select All")); - selectAll->setShortcut(Qt::CTRL | Qt::Key_A); - connect(selectAll, SIGNAL(triggered()), this, SLOT(selectAll())); - - KAction* invertSelection = actionCollection()->addAction("invert_selection"); + paste->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from " + "your clipboard to the currently viewed folder." + "If the items were added to the clipboard by the Cut " + "action they are removed from their old location.") + cutCopyPastePara); + + QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection()); + searchAction->setText(i18n("Search...")); + searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders")); + searchAction->setWhatsThis(xi18nc("@info:whatsthis find", "This helps you " + "find files and folders by opening a find bar. " + "There you can enter search terms and specify settings to find the " + "objects you are looking for.Use this help again on " + "the find bar so we can have a look at it while the settings are " + "explained.")); + + // toggle_search acts as a copy of the main searchAction to be used mainly + // in the toolbar, with no default shortcut attached, to avoid messing with + // existing workflows (search bar always open and Ctrl-F to focus) + QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search")); + toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar")); + toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search")); + toggleSearchAction->setIcon(searchAction->icon()); + toggleSearchAction->setToolTip(searchAction->toolTip()); + toggleSearchAction->setWhatsThis(searchAction->whatsThis()); + toggleSearchAction->setCheckable(true); + + QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection()); + selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all " + "files and folders in the current location.")); + + QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection")); invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection")); - invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A); - connect(invertSelection, SIGNAL(triggered()), this, SLOT(invertSelection())); + invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all " + "objects that you have currently not selected instead.")); + invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert"))); + actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A); + connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection); // setup 'View' menu // (note that most of it is set up in DolphinViewActionHandler) - KAction* split = actionCollection()->addAction("split_view"); - split->setShortcut(Qt::Key_F3); - connect(split, SIGNAL(triggered()), this, SLOT(toggleSplitView())); - - KAction* reload = actionCollection()->addAction("reload"); - reload->setText(i18nc("@action:inmenu View", "Reload")); - reload->setShortcut(Qt::Key_F5); - reload->setIcon(KIcon("view-refresh")); - connect(reload, SIGNAL(triggered()), this, SLOT(reloadView())); - - KAction* stop = actionCollection()->addAction("stop"); + QAction* split = actionCollection()->addAction(QStringLiteral("split_view")); + split->setWhatsThis(xi18nc("@info:whatsthis find", "This splits " + "the folder view below into two autonomous views.This " + "way you can see two locations at once and move items between them " + "quickly.Click this again afterwards to recombine the views.")); + actionCollection()->setDefaultShortcut(split, Qt::Key_F3); + connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView); + + QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash")); + actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL + Qt::Key_S); + stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash")); + stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window")); + stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash"))); + stashSplit->setCheckable(false); + stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash")); + connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash); + + KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection()); + + QAction* stop = actionCollection()->addAction(QStringLiteral("stop")); stop->setText(i18nc("@action:inmenu View", "Stop")); stop->setToolTip(i18nc("@info", "Stop loading")); - stop->setIcon(KIcon("process-stop")); - connect(stop, SIGNAL(triggered()), this, SLOT(stopLoading())); + stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder.")); + stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop"))); + connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading); - KToggleAction* editableLocation = actionCollection()->add("editable_location"); + KToggleAction* editableLocation = actionCollection()->add(QStringLiteral("editable_location")); editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location")); - editableLocation->setShortcut(Qt::Key_F6); - connect(editableLocation, SIGNAL(triggered()), this, SLOT(toggleEditLocation())); - - KAction* replaceLocation = actionCollection()->addAction("replace_location"); + editableLocation->setWhatsThis(xi18nc("@info:whatsthis", + "This toggles the Location Bar to be " + "editable so you can directly enter a location you want to go to." + "You can also switch to editing by clicking to the right of the " + "location and switch back by confirming the edited location.")); + actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6); + connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation); + + QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location")); replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location")); - replaceLocation->setShortcut(Qt::CTRL | Qt::Key_L); - connect(replaceLocation, SIGNAL(triggered()), this, SLOT(replaceLocation())); + // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here. + // Both meanings are useful but not necessary to understand the use of "Replace Location". + // So you might want to be more verbose in your language to convey the meaning but it's up to you. + replaceLocation->setWhatsThis(xi18nc("@info:whatsthis", + "This switches to editing the location and selects it " + "so you can quickly enter a different location.")); + actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL + Qt::Key_L); + connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation); // setup 'Go' menu - KAction* backAction = KStandardAction::back(this, SLOT(goBack()), actionCollection()); - connect(backAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goBack(Qt::MouseButtons))); - KShortcut backShortcut = backAction->shortcut(); - backShortcut.setAlternate(Qt::Key_Backspace); - backAction->setShortcut(backShortcut); + { + QScopedPointer backAction(KStandardAction::back(nullptr, nullptr, nullptr)); + m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection()); + m_backAction->setObjectName(backAction->objectName()); + m_backAction->setShortcuts(backAction->shortcuts()); + } + m_backAction->setDelayed(true); + m_backAction->setStickyMenu(false); + connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack); + connect(m_backAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu); + connect(m_backAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack); + actionCollection()->addAction(m_backAction->objectName(), m_backAction); + + auto backShortcuts = m_backAction->shortcuts(); + backShortcuts.append(QKeySequence(Qt::Key_Backspace)); + actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts); DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this); - actionCollection()->addAction("closed_tabs", recentTabsMenu); - connect(this, SIGNAL(rememberClosedTab(KUrl,KUrl)), - recentTabsMenu, SLOT(rememberClosedTab(KUrl,KUrl))); - connect(recentTabsMenu, SIGNAL(restoreClosedTab(KUrl,KUrl)), - this, SLOT(openNewActivatedTab(KUrl,KUrl))); - - KAction* forwardAction = KStandardAction::forward(this, SLOT(goForward()), actionCollection()); - connect(forwardAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goForward(Qt::MouseButtons))); - - KAction* upAction = KStandardAction::up(this, SLOT(goUp()), actionCollection()); - connect(upAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goUp(Qt::MouseButtons))); - - KAction* homeAction = KStandardAction::home(this, SLOT(goHome()), actionCollection()); - connect(homeAction, SIGNAL(triggered(Qt::MouseButtons,Qt::KeyboardModifiers)), this, SLOT(goHome(Qt::MouseButtons))); + actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu); + connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab, + recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab); + connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab, + m_tabWidget, &DolphinTabWidget::restoreClosedTab); + connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged, + this, &DolphinMainWindow::closedTabsCountChanged); + + QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab")); + undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab")); + undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab", + "This returns you to the previously closed tab.")); + actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL + Qt::SHIFT + Qt::Key_T); + undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo"))); + undoCloseTab->setEnabled(false); + connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab); + + auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); + undoAction->setWhatsThis(xi18nc("@info:whatsthis", "This undoes " + "the last change you made to files or folders." + "Such changes include creating, renaming " + "and moving them to a different location " + "or to the Trash. Changes that can't " + "be undone will ask for your confirmation.")); + undoAction->setEnabled(false); // undo should be disabled by default + + { + QScopedPointer forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr)); + m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection()); + m_forwardAction->setObjectName(forwardAction->objectName()); + m_forwardAction->setShortcuts(forwardAction->shortcuts()); + } + m_forwardAction->setDelayed(true); + m_forwardAction->setStickyMenu(false); + connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward); + connect(m_forwardAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu); + connect(m_forwardAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward); + actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction); + actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts()); + + // enable middle-click to open in a new tab + auto *middleClickEventFilter = new MiddleClickActionEventFilter(this); + connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked); + m_backAction->menu()->installEventFilter(middleClickEventFilter); + m_forwardAction->menu()->installEventFilter(middleClickEventFilter); + KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection()); + QAction* homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection()); + homeAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to your " + "Home folder.Every user account " + "has their own Home that contains their data " + "including folders that contain personal application data.")); // setup 'Tools' menu - KAction* showFilterBar = actionCollection()->addAction("show_filter_bar"); + QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar")); showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar")); - showFilterBar->setIcon(KIcon("view-filter")); - showFilterBar->setShortcut(Qt::CTRL | Qt::Key_I); - connect(showFilterBar, SIGNAL(triggered()), this, SLOT(showFilterBar())); - - KAction* compareFiles = actionCollection()->addAction("compare_files"); + showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", "This opens the " + "Filter Bar at the bottom of the window. " + "There you can enter a text to filter the files and folders currently displayed. " + "Only those that contain the text in their name will be kept in view.")); + showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter"))); + actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL + Qt::Key_I, Qt::Key_Slash}); + connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar); + + QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files")); compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files")); - compareFiles->setIcon(KIcon("kompare")); + compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare"))); compareFiles->setEnabled(false); - connect(compareFiles, SIGNAL(triggered()), this, SLOT(compareFiles())); + connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles); + + QAction* openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool")); + openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool")); + openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis", + "This opens a preferred search tool for the viewed location." + "Use More Search Tools menu to configure it.")); + openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search"))); + 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")); + openTerminal->setWhatsThis(xi18nc("@info:whatsthis", + "This opens a terminal application for the viewed location." + "To learn more about terminals use the help in the terminal application.")); + openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts"))); + actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4); + connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal); + + 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 - KAction* openTerminal = actionCollection()->addAction("open_terminal"); - openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal")); - openTerminal->setIcon(KIcon("utilities-terminal")); - openTerminal->setShortcut(Qt::SHIFT | Qt::Key_F4); - connect(openTerminal, SIGNAL(triggered()), this, SLOT(openTerminal())); + // setup 'Bookmarks' menu + KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this); + bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks"))); + // Make the toolbar button version work properly on click + bookmarkMenu->setDelayed(false); + m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this); + actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu); // setup 'Settings' menu - KToggleAction* showMenuBar = KStandardAction::showMenubar(0, 0, actionCollection()); - connect(showMenuBar, SIGNAL(triggered(bool)), // Fixes #286822 - this, SLOT(toggleShowMenuBar()), Qt::QueuedConnection); - KStandardAction::preferences(this, SLOT(editSettings()), actionCollection()); + KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection()); + showMenuBar->setWhatsThis(xi18nc("@info:whatsthis", + "This switches between having a Menubar " + "and having a Control button. Both " + "contain mostly the same commands and configuration options.")); + connect(showMenuBar, &KToggleAction::triggered, // Fixes #286822 + this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection); + KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection()); + + // setup 'Help' menu for the m_controlButton. The other one is set up in the base class. + m_helpMenu = new KHelpMenu(nullptr); + m_helpMenu->menu()->installEventFilter(this); + // remove duplicate shortcuts + m_helpMenu->action(KHelpMenu::menuHelpContents)->setShortcut(QKeySequence()); + m_helpMenu->action(KHelpMenu::menuWhatsThis)->setShortcut(QKeySequence()); // not in menu actions - QList nextTabKeys; - nextTabKeys.append(KStandardShortcut::tabNext().primary()); - nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab)); + QList nextTabKeys = KStandardShortcut::tabNext(); + nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab)); + + QList prevTabKeys = KStandardShortcut::tabPrev(); + prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab)); - QList prevTabKeys; - prevTabKeys.append(KStandardShortcut::tabPrev().primary()); - prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab)); + for (int i = 0; i < MaxActivateTabShortcuts; ++i) { + QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i)); + activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1)); + activateTab->setEnabled(false); + connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); }); + + // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts + if (i < 9) { + actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1)); + } + } - KAction* activateNextTab = actionCollection()->addAction("activate_next_tab"); + QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab")); + activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab")); + activateLastTab->setEnabled(false); + connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab); + actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT + Qt::Key_0); + + QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); activateNextTab->setEnabled(false); - connect(activateNextTab, SIGNAL(triggered()), SLOT(activateNextTab())); - activateNextTab->setShortcuts(QApplication::isRightToLeft() ? prevTabKeys : nextTabKeys); + connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab); + actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys); - KAction* activatePrevTab = actionCollection()->addAction("activate_prev_tab"); + QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab")); activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab")); activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab")); activatePrevTab->setEnabled(false); - connect(activatePrevTab, SIGNAL(triggered()), SLOT(activatePrevTab())); - activatePrevTab->setShortcuts(QApplication::isRightToLeft() ? nextTabKeys : prevTabKeys); + connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab); + actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys); // for context menu - KAction* openInNewTab = actionCollection()->addAction("open_in_new_tab"); + QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target")); + showTarget->setText(i18nc("@action:inmenu", "Show Target")); + showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder"))); + showTarget->setEnabled(false); + connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget); + + QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab")); openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab")); - openInNewTab->setIcon(KIcon("tab-new")); - connect(openInNewTab, SIGNAL(triggered()), this, SLOT(openInNewTab())); + openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); + connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab); - KAction* openInNewTabs = actionCollection()->addAction("open_in_new_tabs"); + QAction* openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs")); openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs")); - openInNewTabs->setIcon(KIcon("tab-new")); - connect(openInNewTabs, SIGNAL(triggered()), this, SLOT(openInNewTab())); + openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); + connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab); - KAction* openInNewWindow = actionCollection()->addAction("open_in_new_window"); + QAction* openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window")); openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window")); - openInNewWindow->setIcon(KIcon("window-new")); - connect(openInNewWindow, SIGNAL(triggered()), this, SLOT(openInNewWindow())); + openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); + connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow); } void DolphinMainWindow::setupDockWidgets() { const bool lock = GeneralSettings::lockPanels(); - KDualAction* lockLayoutAction = actionCollection()->add("lock_panels"); + KDualAction* lockLayoutAction = actionCollection()->add(QStringLiteral("lock_panels")); lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels")); - lockLayoutAction->setActiveIcon(KIcon("object-unlocked")); + lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels")); - lockLayoutAction->setInactiveIcon(KIcon("object-locked")); + lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked"))); + lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", "This " + "switches between having panels locked or " + "unlocked.Unlocked panels can be " + "dragged to the other side of the window and have a close " + "button.Locked panels are embedded more cleanly.")); lockLayoutAction->setActive(lock); - connect(lockLayoutAction, SIGNAL(triggered()), this, SLOT(togglePanelLockState())); + connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState); // Setup "Information" DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information")); infoDock->setLocked(lock); - infoDock->setObjectName("infoDock"); + infoDock->setObjectName(QStringLiteral("infoDock")); infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - Panel* infoPanel = new InformationPanel(infoDock); - infoPanel->setCustomContextMenuActions(QList() << lockLayoutAction); - connect(infoPanel, SIGNAL(urlActivated(KUrl)), this, SLOT(handleUrl(KUrl))); + +#ifdef HAVE_BALOO + InformationPanel* infoPanel = new InformationPanel(infoDock); + infoPanel->setCustomContextMenuActions({lockLayoutAction}); + connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl); infoDock->setWidget(infoPanel); QAction* infoAction = infoDock->toggleViewAction(); - createPanelAction(KIcon("dialog-information"), Qt::Key_F11, infoAction, "show_information_panel"); + createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel")); addDockWidget(Qt::RightDockWidgetArea, infoDock); - connect(this, SIGNAL(urlChanged(KUrl)), - infoPanel, SLOT(setUrl(KUrl))); - connect(this, SIGNAL(selectionChanged(KFileItemList)), - infoPanel, SLOT(setSelection(KFileItemList))); - connect(this, SIGNAL(requestItemInfo(KFileItem)), - infoPanel, SLOT(requestDelayedItemInfo(KFileItem))); + connect(this, &DolphinMainWindow::urlChanged, + infoPanel, &InformationPanel::setUrl); + connect(this, &DolphinMainWindow::selectionChanged, + infoPanel, &InformationPanel::setSelection); + connect(this, &DolphinMainWindow::requestItemInfo, + infoPanel, &InformationPanel::requestDelayedItemInfo); +#endif + + // i18n: This is the last paragraph for the "What's This"-texts of all four panels. + const QString panelWhatsThis = xi18nc("@info:whatsthis", "To show or " + "hide panels like this go to Control|Panels " + "or View|Panels."); +#ifdef HAVE_BALOO + actionCollection()->action(QStringLiteral("show_information_panel")) + ->setWhatsThis(xi18nc("@info:whatsthis", " This toggles the " + "information panel at the right side of the " + "window.The panel provides in-depth information " + "about the items your mouse is hovering over or about the selected " + "items. Otherwise it informs you about the currently viewed folder." + "For single items a preview of their contents is provided.")); +#endif + infoDock->setWhatsThis(xi18nc("@info:whatsthis", "This panel " + "provides in-depth information about the items your mouse is " + "hovering over or about the selected items. Otherwise it informs " + "you about the currently viewed folder.For single items a " + "preview of their contents is provided.You can configure " + "which and how details are given here by right-clicking.") + panelWhatsThis); // Setup "Folders" DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders")); foldersDock->setLocked(lock); - foldersDock->setObjectName("foldersDock"); + foldersDock->setObjectName(QStringLiteral("foldersDock")); foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); FoldersPanel* foldersPanel = new FoldersPanel(foldersDock); - foldersPanel->setCustomContextMenuActions(QList() << lockLayoutAction); + foldersPanel->setCustomContextMenuActions({lockLayoutAction}); foldersDock->setWidget(foldersPanel); QAction* foldersAction = foldersDock->toggleViewAction(); - createPanelAction(KIcon("folder"), Qt::Key_F7, foldersAction, "show_folders_panel"); + createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel")); addDockWidget(Qt::LeftDockWidgetArea, foldersDock); - connect(this, SIGNAL(urlChanged(KUrl)), - foldersPanel, SLOT(setUrl(KUrl))); - connect(foldersPanel, SIGNAL(folderActivated(KUrl)), - this, SLOT(changeUrl(KUrl))); - connect(foldersPanel, SIGNAL(folderMiddleClicked(KUrl)), - this, SLOT(openNewTab(KUrl))); - connect(foldersPanel, SIGNAL(errorMessage(QString)), - this, SLOT(slotPanelErrorMessage(QString))); + connect(this, &DolphinMainWindow::urlChanged, + foldersPanel, &FoldersPanel::setUrl); + connect(foldersPanel, &FoldersPanel::folderActivated, + this, &DolphinMainWindow::changeUrl); + connect(foldersPanel, &FoldersPanel::folderMiddleClicked, + this, &DolphinMainWindow::openNewTabAfterCurrentTab); + connect(foldersPanel, &FoldersPanel::errorMessage, + this, &DolphinMainWindow::showErrorMessage); + + actionCollection()->action(QStringLiteral("show_folders_panel")) + ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the " + "folders panel at the left side of the window." + "It shows the folders of the file system" + " in a tree view.")); + foldersDock->setWhatsThis(xi18nc("@info:whatsthis", "This panel " + "shows the folders of the file system in a " + "tree view.Click a folder to go " + "there. Click the arrow to the left of a folder to see its subfolders. " + "This allows quick switching between any folders.") + panelWhatsThis); // Setup "Terminal" -#ifndef Q_OS_WIN - DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal")); - terminalDock->setLocked(lock); - terminalDock->setObjectName("terminalDock"); - terminalDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea); - Panel* terminalPanel = new TerminalPanel(terminalDock); - terminalPanel->setCustomContextMenuActions(QList() << lockLayoutAction); - terminalDock->setWidget(terminalPanel); - - connect(terminalPanel, SIGNAL(hideTerminalPanel()), terminalDock, SLOT(hide())); - connect(terminalPanel, SIGNAL(changeUrl(KUrl)), this, SLOT(slotTerminalDirectoryChanged(KUrl))); - connect(terminalDock, SIGNAL(visibilityChanged(bool)), - terminalPanel, SLOT(dockVisibilityChanged())); - - QAction* terminalAction = terminalDock->toggleViewAction(); - createPanelAction(KIcon("utilities-terminal"), Qt::Key_F4, terminalAction, "show_terminal_panel"); - - addDockWidget(Qt::BottomDockWidgetArea, terminalDock); - connect(this, SIGNAL(urlChanged(KUrl)), - terminalPanel, SLOT(setUrl(KUrl))); +#ifdef HAVE_TERMINAL + if (KAuthorized::authorize(QStringLiteral("shell_access"))) { + DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal")); + terminalDock->setLocked(lock); + terminalDock->setObjectName(QStringLiteral("terminalDock")); + m_terminalPanel = new TerminalPanel(terminalDock); + m_terminalPanel->setCustomContextMenuActions({lockLayoutAction}); + terminalDock->setWidget(m_terminalPanel); + + connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide); + connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged); + connect(terminalDock, &DolphinDockWidget::visibilityChanged, + m_terminalPanel, &TerminalPanel::dockVisibilityChanged); + connect(terminalDock, &DolphinDockWidget::visibilityChanged, + this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged); + + QAction* terminalAction = terminalDock->toggleViewAction(); + createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel")); + + addDockWidget(Qt::BottomDockWidgetArea, terminalDock); + connect(this, &DolphinMainWindow::urlChanged, + m_terminalPanel, &TerminalPanel::setUrl); + + if (GeneralSettings::version() < 200) { + terminalDock->hide(); + } + + actionCollection()->action(QStringLiteral("show_terminal_panel")) + ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the " + "terminal panel at the bottom of the window." + "The location in the terminal will always match the folder " + "view so you can navigate using either.The terminal " + "panel is not needed for basic computer usage but can be useful " + "for advanced tasks. To learn more about terminals use the help " + "in a standalone terminal application like Konsole.")); + terminalDock->setWhatsThis(xi18nc("@info:whatsthis", "This is " + "the terminal panel. It behaves like a " + "normal terminal but will match the location of the folder view " + "so you can navigate using either.The terminal panel " + "is not needed for basic computer usage but can be useful for " + "advanced tasks. To learn more about terminals use the help in a " + "standalone terminal application like Konsole.") + panelWhatsThis); + } #endif if (GeneralSettings::version() < 200) { infoDock->hide(); foldersDock->hide(); -#ifndef Q_OS_WIN - terminalDock->hide(); -#endif } // Setup "Places" DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places")); placesDock->setLocked(lock); - placesDock->setObjectName("placesDock"); + placesDock->setObjectName(QStringLiteral("placesDock")); placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); - PlacesPanel* placesPanel = new PlacesPanel(placesDock); - placesPanel->setCustomContextMenuActions(QList() << lockLayoutAction); - placesDock->setWidget(placesPanel); + m_placesPanel = new PlacesPanel(placesDock); + m_placesPanel->setCustomContextMenuActions({lockLayoutAction}); + placesDock->setWidget(m_placesPanel); - QAction* placesAction = placesDock->toggleViewAction(); - createPanelAction(KIcon("bookmarks"), Qt::Key_F9, placesAction, "show_places_panel"); + QAction *placesAction = placesDock->toggleViewAction(); + createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel")); addDockWidget(Qt::LeftDockWidgetArea, placesDock); - connect(placesPanel, SIGNAL(placeActivated(KUrl)), - this, SLOT(slotPlaceActivated(KUrl))); - connect(placesPanel, SIGNAL(placeMiddleClicked(KUrl)), - this, SLOT(openNewTab(KUrl))); - connect(placesPanel, SIGNAL(errorMessage(QString)), - this, SLOT(slotPanelErrorMessage(QString))); - connect(this, SIGNAL(urlChanged(KUrl)), - placesPanel, SLOT(setUrl(KUrl))); - connect(placesDock, SIGNAL(visibilityChanged(bool)), - this, SLOT(slotPlacesPanelVisibilityChanged(bool))); - connect(this, SIGNAL(settingsChanged()), - placesPanel, SLOT(readSettings())); + connect(m_placesPanel, &PlacesPanel::placeActivated, + this, &DolphinMainWindow::slotPlaceActivated); + connect(m_placesPanel, &PlacesPanel::placeMiddleClicked, + this, &DolphinMainWindow::openNewTabAfterCurrentTab); + connect(m_placesPanel, &PlacesPanel::errorMessage, + this, &DolphinMainWindow::showErrorMessage); + connect(this, &DolphinMainWindow::urlChanged, + m_placesPanel, &PlacesPanel::setUrl); + connect(placesDock, &DolphinDockWidget::visibilityChanged, + m_tabWidget, &DolphinTabWidget::slotPlacesPanelVisibilityChanged); + connect(this, &DolphinMainWindow::settingsChanged, + m_placesPanel, &PlacesPanel::readSettings); + connect(m_placesPanel, &PlacesPanel::storageTearDownRequested, + this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested); + connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested, + this, &DolphinMainWindow::slotStorageTearDownExternallyRequested); + m_tabWidget->slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible()); + + auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this); + actionShowAllPlaces->setCheckable(true); + actionShowAllPlaces->setDisabled(true); + actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays " + "all places in the places panel that have been hidden. They will " + "appear semi-transparent unless you uncheck their hide property.")); + + connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){ + actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden"))); + m_placesPanel->showHiddenEntries(checked); + }); + + connect(m_placesPanel, &PlacesPanel::showHiddenEntriesChanged, this, [actionShowAllPlaces] (bool checked){ + actionShowAllPlaces->setChecked(checked); + actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden"))); + }); + + actionCollection()->action(QStringLiteral("show_places_panel")) + ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the " + "places panel at the left side of the window." + "It allows you to go to locations you have " + "bookmarked and to access disk or media attached to the computer " + "or to the network. It also contains sections to find recently " + "saved files or files of a certain type.")); + placesDock->setWhatsThis(xi18nc("@info:whatsthis", "This is the " + "Places panel. It allows you to go to locations " + "you have bookmarked and to access disk or media attached to the " + "computer or to the network. It also contains sections to find " + "recently saved files or files of a certain type." + "Click on an entry to go there. Click with the right mouse button " + "instead to open any entry in a new tab or new window." + "New entries can be added by dragging folders onto this panel. " + "Right-click any section or entry to hide it. Right-click an empty " + "space on this panel and select Show Hidden Places" + " to display it again.") + panelWhatsThis); // Add actions into the "Panels" menu - KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this); - actionCollection()->addAction("panels", panelsMenu); + KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this); + actionCollection()->addAction(QStringLiteral("panels"), panelsMenu); + panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree"))); panelsMenu->setDelayed(false); const KActionCollection* ac = actionCollection(); - panelsMenu->addAction(ac->action("show_places_panel")); - panelsMenu->addAction(ac->action("show_information_panel")); - panelsMenu->addAction(ac->action("show_folders_panel")); -#ifndef Q_OS_WIN - panelsMenu->addAction(ac->action("show_terminal_panel")); + panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel"))); +#ifdef HAVE_BALOO + panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel"))); #endif + panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel"))); + panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel"))); panelsMenu->addSeparator(); + panelsMenu->addAction(actionShowAllPlaces); panelsMenu->addAction(lockLayoutAction); + + connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{ + actionShowAllPlaces->setEnabled(m_placesPanel->hiddenListCount()); + }); } -void DolphinMainWindow::updateEditActions() + +void DolphinMainWindow::updateFileAndEditActions() { const KFileItemList list = m_activeViewContainer->view()->selectedItems(); + const KActionCollection* col = actionCollection(); + QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places")); + if (list.isEmpty()) { - stateChanged("has_no_selection"); - } else { - stateChanged("has_selection"); + stateChanged(QStringLiteral("has_no_selection")); - KActionCollection* col = actionCollection(); - QAction* renameAction = col->action("rename"); - QAction* moveToTrashAction = col->action("move_to_trash"); - QAction* deleteAction = col->action("delete"); - QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut)); - QAction* deleteWithTrashShortcut = col->action("delete_shortcut"); // see DolphinViewActionHandler + addToPlacesAction->setEnabled(true); + } else { + stateChanged(QStringLiteral("has_selection")); + + QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile)); + QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash)); + QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile)); + QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut)); + QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler + QAction* showTarget = col->action(QStringLiteral("show_target")); + QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler + + if (list.length() == 1 && list.first().isDir()) { + addToPlacesAction->setEnabled(true); + } else { + addToPlacesAction->setEnabled(false); + } KFileItemListProperties capabilities(list); const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); @@ -1576,6 +1938,8 @@ void DolphinMainWindow::updateEditActions() deleteAction->setEnabled(capabilities.supportsDeleting()); deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash); cutAction->setEnabled(capabilities.supportsMoving()); + showTarget->setEnabled(list.length() == 1 && list.at(0).isLink()); + duplicateAction->setEnabled(capabilities.supportsWriting()); } } @@ -1583,12 +1947,12 @@ void DolphinMainWindow::updateViewActions() { m_actionHandler->updateViewActions(); - QAction* showFilterBarAction = actionCollection()->action("show_filter_bar"); + QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar")); showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); updateSplitAction(); - QAction* editableLocactionAction = actionCollection()->action("editable_location"); + QAction* editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location")); const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); editableLocactionAction->setChecked(urlNavigator->isUrlEditable()); } @@ -1596,8 +1960,18 @@ void DolphinMainWindow::updateViewActions() void DolphinMainWindow::updateGoActions() { QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up)); - const KUrl currentUrl = m_activeViewContainer->url(); - goUpAction->setEnabled(currentUrl.upUrl() != currentUrl); + const QUrl currentUrl = m_activeViewContainer->url(); + // I think this is one of the best places to firstly be confronted + // with a file system and its hierarchy. Talking about the root + // directory might seem too much here but it is the question that + // naturally arises in this context. + goUpAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to " + "the folder that contains the currently viewed one." + "All files and folders are organized in a hierarchical " + "file system. At the top of this hierarchy is " + "a directory that contains all data connected to this computer" + "—the root directory.")); + goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl); } void DolphinMainWindow::createControlButton() @@ -1608,41 +1982,41 @@ void DolphinMainWindow::createControlButton() Q_ASSERT(!m_controlButton); m_controlButton = new QToolButton(this); - m_controlButton->setIcon(KIcon("applications-system")); - m_controlButton->setText(i18nc("@action", "Control")); + m_controlButton->setAccessibleName(i18nc("@action:intoolbar", "Control")); + m_controlButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu"))); + m_controlButton->setToolTip(i18nc("@action", "Show menu")); + m_controlButton->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis); m_controlButton->setPopupMode(QToolButton::InstantPopup); - m_controlButton->setToolButtonStyle(toolBar()->toolButtonStyle()); - KMenu* controlMenu = new KMenu(m_controlButton); - connect(controlMenu, SIGNAL(aboutToShow()), this, SLOT(updateControlMenu())); + QMenu* controlMenu = new QMenu(m_controlButton); + connect(controlMenu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateControlMenu); + controlMenu->installEventFilter(this); m_controlButton->setMenu(controlMenu); toolBar()->addWidget(m_controlButton); - connect(toolBar(), SIGNAL(iconSizeChanged(QSize)), - m_controlButton, SLOT(setIconSize(QSize))); - connect(toolBar(), SIGNAL(toolButtonStyleChanged(Qt::ToolButtonStyle)), - m_controlButton, SLOT(setToolButtonStyle(Qt::ToolButtonStyle))); + connect(toolBar(), &KToolBar::iconSizeChanged, + m_controlButton, &QToolButton::setIconSize); // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar // gets edited. In this case we must add them again. The adding is done asynchronously by // m_updateToolBarTimer. - connect(m_controlButton, SIGNAL(destroyed()), this, SLOT(slotControlButtonDeleted())); + connect(m_controlButton, &QToolButton::destroyed, this, &DolphinMainWindow::slotControlButtonDeleted); m_updateToolBarTimer = new QTimer(this); m_updateToolBarTimer->setInterval(500); - connect(m_updateToolBarTimer, SIGNAL(timeout()), this, SLOT(updateToolBar())); + connect(m_updateToolBarTimer, &QTimer::timeout, this, &DolphinMainWindow::updateToolBar); } void DolphinMainWindow::deleteControlButton() { delete m_controlButton; - m_controlButton = 0; + m_controlButton = nullptr; delete m_updateToolBarTimer; - m_updateToolBarTimer = 0; + m_updateToolBarTimer = nullptr; } -bool DolphinMainWindow::addActionToMenu(QAction* action, KMenu* menu) +bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu) { Q_ASSERT(action); Q_ASSERT(menu); @@ -1660,16 +2034,15 @@ bool DolphinMainWindow::addActionToMenu(QAction* action, KMenu* menu) void DolphinMainWindow::refreshViews() { - foreach (DolphinTabPage* tabPage, m_viewTab) { - tabPage->refreshViews(); - } + m_tabWidget->refreshViews(); if (GeneralSettings::modifiedStartupSettings()) { // The startup settings have been changed by the user (see bug #254947). // Synchronize the split-view setting with the active view: const bool splitView = GeneralSettings::splitView(); - m_viewTab.at(m_tabIndex)->setSplitViewEnabled(splitView); + m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView); updateSplitAction(); + updateWindowTitle(); } emit settingsChanged(); @@ -1682,79 +2055,70 @@ void DolphinMainWindow::clearStatusBar() void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) { - connect(container, SIGNAL(showFilterBarChanged(bool)), - this, SLOT(updateFilterBarAction(bool))); - connect(container, SIGNAL(writeStateChanged(bool)), - this, SLOT(slotWriteStateChanged(bool))); + connect(container, &DolphinViewContainer::showFilterBarChanged, + this, &DolphinMainWindow::updateFilterBarAction); + connect(container, &DolphinViewContainer::writeStateChanged, + this, &DolphinMainWindow::slotWriteStateChanged); + connect(container, &DolphinViewContainer::searchModeEnabledChanged, + this, &DolphinMainWindow::updateSearchAction); + + const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled); const DolphinView* view = container->view(); - connect(view, SIGNAL(selectionChanged(KFileItemList)), - this, SLOT(slotSelectionChanged(KFileItemList))); - connect(view, SIGNAL(requestItemInfo(KFileItem)), - this, SLOT(slotRequestItemInfo(KFileItem))); - connect(view, SIGNAL(tabRequested(KUrl)), - this, SLOT(openNewTab(KUrl))); - connect(view, SIGNAL(requestContextMenu(QPoint,KFileItem,KUrl,QList)), - this, SLOT(openContextMenu(QPoint,KFileItem,KUrl,QList))); - connect(view, SIGNAL(directoryLoadingStarted()), - this, SLOT(enableStopAction())); - connect(view, SIGNAL(directoryLoadingCompleted()), - this, SLOT(disableStopAction())); - connect(view, SIGNAL(goBackRequested()), - this, SLOT(goBack())); - connect(view, SIGNAL(goForwardRequested()), - this, SLOT(goForward())); + connect(view, &DolphinView::selectionChanged, + this, &DolphinMainWindow::slotSelectionChanged); + connect(view, &DolphinView::requestItemInfo, + this, &DolphinMainWindow::requestItemInfo); + connect(view, &DolphinView::tabRequested, + this, &DolphinMainWindow::openNewTab); + connect(view, &DolphinView::requestContextMenu, + this, &DolphinMainWindow::openContextMenu); + connect(view, &DolphinView::directoryLoadingStarted, + this, &DolphinMainWindow::enableStopAction); + connect(view, &DolphinView::directoryLoadingCompleted, + this, &DolphinMainWindow::disableStopAction); + connect(view, &DolphinView::directoryLoadingCompleted, + this, &DolphinMainWindow::slotDirectoryLoadingCompleted); + connect(view, &DolphinView::goBackRequested, + this, &DolphinMainWindow::goBack); + connect(view, &DolphinView::goForwardRequested, + this, &DolphinMainWindow::goForward); + connect(view, &DolphinView::urlActivated, + this, &DolphinMainWindow::handleUrl); const KUrlNavigator* navigator = container->urlNavigator(); - connect(navigator, SIGNAL(urlChanged(KUrl)), - this, SLOT(changeUrl(KUrl))); - connect(navigator, SIGNAL(historyChanged()), - this, SLOT(updateHistory())); - connect(navigator, SIGNAL(editableStateChanged(bool)), - this, SLOT(slotEditableStateChanged(bool))); - connect(navigator, SIGNAL(tabRequested(KUrl)), - this, SLOT(openNewTab(KUrl))); + connect(navigator, &KUrlNavigator::urlChanged, + this, &DolphinMainWindow::changeUrl); + connect(navigator, &KUrlNavigator::historyChanged, + this, &DolphinMainWindow::updateHistory); + connect(navigator, &KUrlNavigator::editableStateChanged, + this, &DolphinMainWindow::slotEditableStateChanged); + connect(navigator, &KUrlNavigator::tabRequested, + this, &DolphinMainWindow::openNewTabAfterLastTab); } void DolphinMainWindow::updateSplitAction() { - QAction* splitAction = actionCollection()->action("split_view"); - const DolphinTabPage* tabPage = m_viewTab.at(m_tabIndex); + QAction* splitAction = actionCollection()->action(QStringLiteral("split_view")); + const DolphinTabPage* tabPage = m_tabWidget->currentTabPage(); if (tabPage->splitViewEnabled()) { - if (tabPage->primaryViewActive()) { + if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) { splitAction->setText(i18nc("@action:intoolbar Close left view", "Close")); splitAction->setToolTip(i18nc("@info", "Close left view")); - splitAction->setIcon(KIcon("view-left-close")); + splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close"))); } else { splitAction->setText(i18nc("@action:intoolbar Close right view", "Close")); splitAction->setToolTip(i18nc("@info", "Close right view")); - splitAction->setIcon(KIcon("view-right-close")); + splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close"))); } } else { splitAction->setText(i18nc("@action:intoolbar Split view", "Split")); splitAction->setToolTip(i18nc("@info", "Split view")); - splitAction->setIcon(KIcon("view-right-new")); + splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new"))); } } -QString DolphinMainWindow::tabName(const KUrl& url) const -{ - QString name; - if (url.equals(KUrl("file:///"))) { - name = '/'; - } else { - name = url.fileName(); - if (name.isEmpty()) { - name = url.protocol(); - } else { - // Make sure that a '&' inside the directory name is displayed correctly - // and not misinterpreted as a keyboard shortcut in QTabBar::setTabText() - name.replace('&', "&&"); - } - } - return name; -} - bool DolphinMainWindow::isKompareInstalled() const { static bool initialized = false; @@ -1762,48 +2126,220 @@ bool DolphinMainWindow::isKompareInstalled() const if (!initialized) { // TODO: maybe replace this approach later by using a menu // plugin like kdiff3plugin.cpp - installed = !KGlobal::dirs()->findExe("kompare").isEmpty(); + installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty(); initialized = true; } return installed; } -void DolphinMainWindow::setUrlAsCaption(const KUrl& url) -{ - QString caption; - if (!url.isLocalFile()) { - caption.append(url.protocol() + " - "); - if (url.hasHost()) { - caption.append(url.host() + " - "); - } - } - - const QString fileName = url.fileName().isEmpty() ? "/" : url.fileName(); - caption.append(fileName); - - setCaption(caption); -} - -QString DolphinMainWindow::squeezedText(const QString& text) const -{ - const QFontMetrics fm = fontMetrics(); - return fm.elidedText(text, Qt::ElideMiddle, fm.maxWidth() * 10); -} - -void DolphinMainWindow::createPanelAction(const KIcon& icon, +void DolphinMainWindow::createPanelAction(const QIcon& icon, const QKeySequence& shortcut, QAction* dockAction, const QString& actionName) { - KAction* panelAction = actionCollection()->addAction(actionName); + QAction* panelAction = actionCollection()->addAction(actionName); panelAction->setCheckable(true); panelAction->setChecked(dockAction->isChecked()); panelAction->setText(dockAction->text()); panelAction->setIcon(icon); - panelAction->setShortcut(shortcut); - - connect(panelAction, SIGNAL(triggered()), dockAction, SLOT(trigger())); - connect(dockAction, SIGNAL(toggled(bool)), panelAction, SLOT(setChecked(bool))); + actionCollection()->setDefaultShortcut(panelAction, shortcut); + + connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger); + connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked); +} + +void DolphinMainWindow::setupWhatsThis() +{ + // main widgets + menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "This is the " + "Menubar. It provides access to commands and " + "configuration options. Left-click on any of the menus on this " + "bar to see its contents.The Menubar can be hidden " + "by unchecking Settings|Show Menubar. Then " + "most of its contents become available through a Control" + " button on the Toolbar.")); + toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "This is the " + "Toolbar. It allows quick access to " + "frequently used actions.It is highly customizable. " + "All items you see in the Control menu or " + "in the Menubar can be placed on the " + "Toolbar. Just right-click on it and select Configure " + "Toolbars… or find this action in the " + "Control or Settings menu." + "The location of the bar and the style of its " + "buttons can also be changed in the right-click menu. Right-click " + "a button if you want to show or hide its text.")); + m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view", + "Here you can see the folders and " + "files that are at the location described in " + "the Location Bar above. This area is the " + "central part of this application where you navigate to the files " + "you want to use.For an elaborate and general " + "introduction to this application " + "click here. This will open an introductory article from " + "the KDE UserBase Wiki.For brief " + "explanations of all the features of this view " + "click here " + "instead. This will open a page from the Handbook" + " that covers the basics.")); + + // Settings menu + actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings)) + ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window " + "that lists the keyboard shortcuts." + "There you can set up key combinations to trigger an action when " + "they are pressed simultaneously. All commands in this application can " + "be triggered this way.")); + actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars)) + ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window in which " + "you can change which buttons appear on the Toolbar." + "All items you see in the Control menu " + "or in the Menubar can also be placed on the Toolbar.")); + actionCollection()->action(KStandardAction::name(KStandardAction::Preferences)) + ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can " + "change a multitude of settings for this application. For an explanation " + "of the various settings go to the chapter Configuring Dolphin" + " in Help|Dolphin Handbook.")); + + // Help menu + // The whatsthis has to be set for the m_helpMenu and for the + // StandardAction separately because both are used in different locations. + // m_helpMenu is only used for createControlButton() button. + + // Links do not work within the Menubar so texts without links are provided there. + + // i18n: If the external link isn't available in your language you should + // probably state the external link language at least in brackets to not + // frustrate the user. If there are multiple languages that the user might + // know with a reasonable chance you might want to have 2 external links. + // The same is in my opinion true for every external link you translate. + const QString whatsThisHelpContents = xi18nc("@info:whatsthis handbook", + "This opens the Handbook for this application. It provides " + "explanations for every part of Dolphin."); + actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents)) + ->setWhatsThis(whatsThisHelpContents + + xi18nc("@info:whatsthis second half of handbook hb text without link", + "If you want more elaborate introductions to the " + "different features of Dolphin " + "go to the KDE UserBase Wiki.")); + m_helpMenu->action(KHelpMenu::menuHelpContents)->setWhatsThis(whatsThisHelpContents + + xi18nc("@info:whatsthis second half of handbook text with link", + "If you want more elaborate introductions to the " + "different features of Dolphin " + "click here. " + "It will open the dedicated page in the KDE UserBase Wiki.")); + + const QString whatsThisWhatsThis = xi18nc("@info:whatsthis whatsthis button", + "This is the button that invokes the help feature you are " + "using right now! Click it, then click any component of this " + "application to ask \"What's this?\" about it. The mouse cursor " + "will change appearance if no help is available for a spot."); + actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis)) + ->setWhatsThis(whatsThisWhatsThis + + xi18nc("@info:whatsthis second half of whatsthis button text without link", + "There are two other ways to get help for this application: The " + "Dolphin Handbook in the Help" + " menu and the KDE UserBase Wiki " + "article about File Management online." + "The \"What's this?\" help is " + "missing in most other windows so don't get too used to this.")); + m_helpMenu->action(KHelpMenu::menuWhatsThis)->setWhatsThis(whatsThisWhatsThis + + xi18nc("@info:whatsthis second half of whatsthis button text with link", + "There are two other ways to get help: " + "The Dolphin Handbook and " + "the KDE " + "UserBase Wiki.The \"What's this?\" help is " + "missing in most other windows so don't get too used to this.")); + + const QString whatsThisReportBug = xi18nc("@info:whatsthis","This opens a " + "window that will guide you through reporting errors or flaws " + "in this application or in other KDE software."); + actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug)) + ->setWhatsThis(whatsThisReportBug); + m_helpMenu->action(KHelpMenu::menuReportBug)->setWhatsThis(whatsThisReportBug + + xi18nc("@info:whatsthis second half of reportbug text with link", + "High-quality bug reports are much appreciated. To learn " + "how to make your bug report as effective as possible " + "" + "click here.")); + + const QString whatsThisDonate = xi18nc("@info:whatsthis","This opens a " + "web page where you can donate to " + "support the continued work on this application and many " + "other projects by the KDE community." + "Donating is the easiest and fastest way to efficiently " + "support KDE and its projects. KDE projects are available for " + "free therefore your donation is needed to cover things that " + "require money like servers, contributor meetings, etc." + "KDE e.V. is the non-profit " + "organization behind the KDE community."); + actionCollection()->action(KStandardAction::name(KStandardAction::Donate)) + ->setWhatsThis(whatsThisDonate); + m_helpMenu->action(KHelpMenu::menuDonate)->setWhatsThis(whatsThisDonate); + + const QString whatsThisSwitchLanguage = xi18nc("@info:whatsthis", + "With this you can change the language this application uses." + "You can even set secondary languages which will be used " + "if texts are not available in your preferred language."); + actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage)) + ->setWhatsThis(whatsThisSwitchLanguage); + m_helpMenu->action(KHelpMenu::menuSwitchLanguage)->setWhatsThis(whatsThisSwitchLanguage); + + const QString whatsThisAboutApp = xi18nc("@info:whatsthis","This opens a " + "window that informs you about the version, license, " + "used libraries and maintainers of this application."); + actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp)) + ->setWhatsThis(whatsThisAboutApp); + m_helpMenu->action(KHelpMenu::menuAboutApp)->setWhatsThis(whatsThisAboutApp); + + const QString whatsThisAboutKDE = xi18nc("@info:whatsthis","This opens a " + "window with information about KDE. " + "The KDE community are the people behind this free software." + "If you like using this application but don't know " + "about KDE or want to see a cute dragon have a look!"); + actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE)) + ->setWhatsThis(whatsThisAboutKDE); + m_helpMenu->action(KHelpMenu::menuAboutKDE)->setWhatsThis(whatsThisAboutKDE); +} + +bool DolphinMainWindow::event(QEvent *event) +{ + if (event->type() == QEvent::WhatsThisClicked) { + event->accept(); + QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast(event); + QDesktopServices::openUrl(QUrl(whatsThisEvent->href())); + return true; + } + return KXmlGuiWindow::event(event); +} + +bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event) +{ + Q_UNUSED(obj) + if (event->type() == QEvent::WhatsThisClicked) { + event->accept(); + QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast(event); + QDesktopServices::openUrl(QUrl(whatsThisEvent->href())); + return true; + } + return false; +} + +void DolphinMainWindow::focusTerminalPanel() +{ + if (m_terminalPanel->isVisible()) { + if (m_terminalPanel->terminalHasFocus()) { + m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason); + actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel")); + } else { + m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason); + actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel")); + } + } else { + actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); + actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel")); + } } DolphinMainWindow::UndoUiInterface::UndoUiInterface() : @@ -1826,4 +2362,8 @@ void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) } } -#include "dolphinmainwindow.moc" +bool DolphinMainWindow::isUrlOpen(const QString& url) +{ + return m_tabWidget->isUrlOpen(QUrl::fromUserInput((url))); +} +