File indexing completed on 2024-03-24 05:48:32
0001 /* 0002 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com> 0003 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com> 0004 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com> 0005 * 0006 * SPDX-License-Identifier: GPL-2.0-or-later 0007 */ 0008 0009 #include "dolphinmainwindow.h" 0010 0011 #include "dolphin_generalsettings.h" 0012 #include "dolphinbookmarkhandler.h" 0013 #include "dolphincontextmenu.h" 0014 #include "dolphindockwidget.h" 0015 #include "dolphinmainwindowadaptor.h" 0016 #include "dolphinnavigatorswidgetaction.h" 0017 #include "dolphinnewfilemenu.h" 0018 #include "dolphinplacesmodelsingleton.h" 0019 #include "dolphinrecenttabsmenu.h" 0020 #include "dolphintabpage.h" 0021 #include "dolphinurlnavigatorscontroller.h" 0022 #include "dolphinviewcontainer.h" 0023 #include "global.h" 0024 #include "middleclickactioneventfilter.h" 0025 #include "panels/folders/folderspanel.h" 0026 #include "panels/places/placespanel.h" 0027 #include "panels/terminal/terminalpanel.h" 0028 #include "selectionmode/actiontexthelper.h" 0029 #include "settings/dolphinsettingsdialog.h" 0030 #include "statusbar/dolphinstatusbar.h" 0031 #include "views/dolphinnewfilemenuobserver.h" 0032 #include "views/dolphinremoteencoding.h" 0033 #include "views/dolphinviewactionhandler.h" 0034 #include "views/draganddrophelper.h" 0035 #include "views/viewproperties.h" 0036 0037 #include <KActionCollection> 0038 #include <KActionMenu> 0039 #include <KAuthorized> 0040 #include <KConfig> 0041 #include <KConfigGui> 0042 #include <KDualAction> 0043 #include <KFileItemListProperties> 0044 #include <KIO/CommandLauncherJob> 0045 #include <KIO/JobUiDelegateFactory> 0046 #include <KIO/OpenFileManagerWindowJob> 0047 #include <KIO/OpenUrlJob> 0048 #include <KJobWidgets> 0049 #include <KLocalizedString> 0050 #include <KMessageBox> 0051 #include <KProtocolInfo> 0052 #include <KProtocolManager> 0053 #include <KShell> 0054 #include <KShortcutsDialog> 0055 #include <KStandardAction> 0056 #include <KSycoca> 0057 #include <KTerminalLauncherJob> 0058 #include <KToggleAction> 0059 #include <KToolBar> 0060 #include <KToolBarPopupAction> 0061 #include <KUrlComboBox> 0062 #include <KUrlNavigator> 0063 #include <KWindowSystem> 0064 #include <KXMLGUIFactory> 0065 0066 #include <kwidgetsaddons_version.h> 0067 0068 #include <QApplication> 0069 #include <QClipboard> 0070 #include <QCloseEvent> 0071 #include <QDesktopServices> 0072 #include <QDialog> 0073 #include <QDomDocument> 0074 #include <QFileInfo> 0075 #include <QLineEdit> 0076 #include <QMenuBar> 0077 #include <QPushButton> 0078 #include <QShowEvent> 0079 #include <QStandardPaths> 0080 #include <QTimer> 0081 #include <QToolButton> 0082 #include <QtConcurrentRun> 0083 0084 #include <algorithm> 0085 0086 #if HAVE_X11 0087 #include <KStartupInfo> 0088 #endif 0089 0090 namespace 0091 { 0092 // Used for GeneralSettings::version() to determine whether 0093 // an updated version of Dolphin is running, so as to migrate 0094 // removed/renamed ...etc config entries; increment it in such 0095 // cases 0096 const int CurrentDolphinVersion = 202; 0097 // The maximum number of entries in the back/forward popup menu 0098 const int MaxNumberOfNavigationentries = 12; 0099 // The maximum number of "Activate Tab" shortcuts 0100 const int MaxActivateTabShortcuts = 9; 0101 } 0102 0103 DolphinMainWindow::DolphinMainWindow() 0104 : KXmlGuiWindow(nullptr) 0105 , m_newFileMenu(nullptr) 0106 , m_tabWidget(nullptr) 0107 , m_activeViewContainer(nullptr) 0108 , m_actionHandler(nullptr) 0109 , m_remoteEncoding(nullptr) 0110 , m_settingsDialog() 0111 , m_bookmarkHandler(nullptr) 0112 , m_lastHandleUrlOpenJob(nullptr) 0113 , m_terminalPanel(nullptr) 0114 , m_placesPanel(nullptr) 0115 , m_tearDownFromPlacesRequested(false) 0116 , m_backAction(nullptr) 0117 , m_forwardAction(nullptr) 0118 , m_sessionSaveTimer(nullptr) 0119 , m_sessionSaveWatcher(nullptr) 0120 , m_sessionSaveScheduled(false) 0121 , m_splitViewAction(nullptr) 0122 , m_splitViewMenuAction(nullptr) 0123 { 0124 Q_INIT_RESOURCE(dolphin); 0125 0126 new MainWindowAdaptor(this); 0127 0128 #ifndef Q_OS_WIN 0129 setWindowFlags(Qt::WindowContextHelpButtonHint); 0130 #endif 0131 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName()); 0132 setObjectName(QStringLiteral("Dolphin#")); 0133 0134 setStateConfigGroup("State"); 0135 0136 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, this, &DolphinMainWindow::showErrorMessage); 0137 0138 KIO::FileUndoManager *undoManager = KIO::FileUndoManager::self(); 0139 undoManager->setUiInterface(new UndoUiInterface()); 0140 0141 connect(undoManager, &KIO::FileUndoManager::undoAvailable, this, &DolphinMainWindow::slotUndoAvailable); 0142 connect(undoManager, &KIO::FileUndoManager::undoTextChanged, this, &DolphinMainWindow::slotUndoTextChanged); 0143 connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted, this, &DolphinMainWindow::clearStatusBar); 0144 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished, this, &DolphinMainWindow::showCommand); 0145 0146 const bool firstRun = (GeneralSettings::version() < 200); 0147 if (firstRun) { 0148 GeneralSettings::setViewPropsTimestamp(QDateTime::currentDateTime()); 0149 } 0150 0151 setAcceptDrops(true); 0152 0153 auto *navigatorsWidgetAction = new DolphinNavigatorsWidgetAction(this); 0154 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction); 0155 m_tabWidget = new DolphinTabWidget(navigatorsWidgetAction, this); 0156 m_tabWidget->setObjectName("tabWidget"); 0157 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged, this, &DolphinMainWindow::activeViewChanged); 0158 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, this, &DolphinMainWindow::tabCountChanged); 0159 connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged, this, &DolphinMainWindow::updateWindowTitle); 0160 setCentralWidget(m_tabWidget); 0161 0162 m_actionTextHelper = new SelectionMode::ActionTextHelper(this); 0163 setupActions(); 0164 0165 m_actionHandler = new DolphinViewActionHandler(actionCollection(), m_actionTextHelper, this); 0166 connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar); 0167 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory); 0168 connect(m_actionHandler, &DolphinViewActionHandler::selectionModeChangeTriggered, this, &DolphinMainWindow::slotSetSelectionMode); 0169 0170 Q_CHECK_PTR(actionCollection()->action(QStringLiteral("create_dir"))); 0171 m_newFileMenu->setNewFolderShortcutAction(actionCollection()->action(QStringLiteral("create_dir"))); 0172 0173 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler); 0174 connect(this, &DolphinMainWindow::urlChanged, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl); 0175 0176 setupDockWidgets(); 0177 0178 setupGUI(Save | Create | ToolBar); 0179 stateChanged(QStringLiteral("new_file")); 0180 0181 QClipboard *clipboard = QApplication::clipboard(); 0182 connect(clipboard, &QClipboard::dataChanged, this, &DolphinMainWindow::updatePasteAction); 0183 0184 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); 0185 toggleFilterBarAction->setChecked(GeneralSettings::filterBar()); 0186 0187 if (firstRun) { 0188 menuBar()->setVisible(false); 0189 } 0190 0191 const bool showMenu = !menuBar()->isHidden(); 0192 QAction *showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar)); 0193 showMenuBarAction->setChecked(showMenu); // workaround for bug #171080 0194 0195 auto hamburgerMenu = static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu))); 0196 hamburgerMenu->setMenuBar(menuBar()); 0197 hamburgerMenu->setShowMenuBarAction(showMenuBarAction); 0198 connect(hamburgerMenu, &KHamburgerMenu::aboutToShowMenu, this, &DolphinMainWindow::updateHamburgerMenu); 0199 hamburgerMenu->hideActionsOf(toolBar()); 0200 if (GeneralSettings::version() < 201 && !toolBar()->actions().contains(hamburgerMenu)) { 0201 addHamburgerMenuToToolbar(); 0202 } 0203 0204 updateAllowedToolbarAreas(); 0205 0206 // enable middle-click on back/forward/up to open in a new tab 0207 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this); 0208 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked); 0209 toolBar()->installEventFilter(middleClickEventFilter); 0210 0211 setupWhatsThis(); 0212 0213 connect(KSycoca::self(), &KSycoca::databaseChanged, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); 0214 0215 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction); 0216 0217 m_fileItemActions.setParentWidget(this); 0218 connect(&m_fileItemActions, &KFileItemActions::error, this, [this](const QString &errorMessage) { 0219 showErrorMessage(errorMessage); 0220 }); 0221 0222 connect(GeneralSettings::self(), &GeneralSettings::splitViewChanged, this, &DolphinMainWindow::slotSplitViewChanged); 0223 } 0224 0225 DolphinMainWindow::~DolphinMainWindow() 0226 { 0227 // This fixes a crash on Wayland when closing the mainwindow while another dialog is open. 0228 disconnect(QGuiApplication::clipboard(), &QClipboard::dataChanged, this, &DolphinMainWindow::updatePasteAction); 0229 } 0230 0231 QVector<DolphinViewContainer *> DolphinMainWindow::viewContainers() const 0232 { 0233 QVector<DolphinViewContainer *> viewContainers; 0234 0235 for (int i = 0; i < m_tabWidget->count(); ++i) { 0236 DolphinTabPage *tabPage = m_tabWidget->tabPageAt(i); 0237 0238 viewContainers << tabPage->primaryViewContainer(); 0239 if (tabPage->splitViewEnabled()) { 0240 viewContainers << tabPage->secondaryViewContainer(); 0241 } 0242 } 0243 return viewContainers; 0244 } 0245 0246 void DolphinMainWindow::openDirectories(const QList<QUrl> &dirs, bool splitView) 0247 { 0248 m_tabWidget->openDirectories(dirs, splitView); 0249 } 0250 0251 void DolphinMainWindow::openDirectories(const QStringList &dirs, bool splitView) 0252 { 0253 openDirectories(QUrl::fromStringList(dirs), splitView); 0254 } 0255 0256 void DolphinMainWindow::openFiles(const QList<QUrl> &files, bool splitView) 0257 { 0258 m_tabWidget->openFiles(files, splitView); 0259 } 0260 0261 bool DolphinMainWindow::isFoldersPanelEnabled() const 0262 { 0263 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked(); 0264 } 0265 0266 bool DolphinMainWindow::isInformationPanelEnabled() const 0267 { 0268 #if HAVE_BALOO 0269 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked(); 0270 #else 0271 return false; 0272 #endif 0273 } 0274 0275 bool DolphinMainWindow::isSplitViewEnabledInCurrentTab() const 0276 { 0277 return m_tabWidget->currentTabPage()->splitViewEnabled(); 0278 } 0279 0280 void DolphinMainWindow::openFiles(const QStringList &files, bool splitView) 0281 { 0282 openFiles(QUrl::fromStringList(files), splitView); 0283 } 0284 0285 void DolphinMainWindow::activateWindow(const QString &activationToken) 0286 { 0287 window()->setAttribute(Qt::WA_NativeWindow, true); 0288 0289 if (KWindowSystem::isPlatformWayland()) { 0290 KWindowSystem::setCurrentXdgActivationToken(activationToken); 0291 } else if (KWindowSystem::isPlatformX11()) { 0292 #if HAVE_X11 0293 KStartupInfo::setNewStartupId(window()->windowHandle(), activationToken.toUtf8()); 0294 #endif 0295 } 0296 0297 KWindowSystem::activateWindow(window()->windowHandle()); 0298 } 0299 0300 bool DolphinMainWindow::isActiveWindow() 0301 { 0302 return window()->isActiveWindow(); 0303 } 0304 0305 void DolphinMainWindow::showCommand(CommandType command) 0306 { 0307 DolphinStatusBar *statusBar = m_activeViewContainer->statusBar(); 0308 switch (command) { 0309 case KIO::FileUndoManager::Copy: 0310 statusBar->setText(i18nc("@info:status", "Successfully copied.")); 0311 break; 0312 case KIO::FileUndoManager::Move: 0313 statusBar->setText(i18nc("@info:status", "Successfully moved.")); 0314 break; 0315 case KIO::FileUndoManager::Link: 0316 statusBar->setText(i18nc("@info:status", "Successfully linked.")); 0317 break; 0318 case KIO::FileUndoManager::Trash: 0319 statusBar->setText(i18nc("@info:status", "Successfully moved to trash.")); 0320 break; 0321 case KIO::FileUndoManager::Rename: 0322 statusBar->setText(i18nc("@info:status", "Successfully renamed.")); 0323 break; 0324 0325 case KIO::FileUndoManager::Mkdir: 0326 statusBar->setText(i18nc("@info:status", "Created folder.")); 0327 break; 0328 0329 default: 0330 break; 0331 } 0332 } 0333 0334 void DolphinMainWindow::pasteIntoFolder() 0335 { 0336 m_activeViewContainer->view()->pasteIntoFolder(); 0337 } 0338 0339 void DolphinMainWindow::changeUrl(const QUrl &url) 0340 { 0341 if (!KProtocolManager::supportsListing(url)) { 0342 // The URL navigator only checks for validity, not 0343 // if the URL can be listed. An error message is 0344 // shown due to DolphinViewContainer::restoreView(). 0345 return; 0346 } 0347 0348 m_activeViewContainer->setUrl(url); 0349 updateFileAndEditActions(); 0350 updatePasteAction(); 0351 updateViewActions(); 0352 updateGoActions(); 0353 0354 Q_EMIT urlChanged(url); 0355 } 0356 0357 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl &url) 0358 { 0359 if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) { 0360 m_placesPanel->proceedWithTearDown(); 0361 m_tearDownFromPlacesRequested = false; 0362 } 0363 0364 m_activeViewContainer->setAutoGrabFocus(false); 0365 changeUrl(url); 0366 m_activeViewContainer->setAutoGrabFocus(true); 0367 } 0368 0369 void DolphinMainWindow::slotEditableStateChanged(bool editable) 0370 { 0371 KToggleAction *editableLocationAction = static_cast<KToggleAction *>(actionCollection()->action(QStringLiteral("editable_location"))); 0372 editableLocationAction->setChecked(editable); 0373 } 0374 0375 void DolphinMainWindow::slotSelectionChanged(const KFileItemList &selection) 0376 { 0377 updateFileAndEditActions(); 0378 0379 const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount(); 0380 0381 QAction *compareFilesAction = actionCollection()->action(QStringLiteral("compare_files")); 0382 if (selectedUrlsCount == 2) { 0383 compareFilesAction->setEnabled(isKompareInstalled()); 0384 } else { 0385 compareFilesAction->setEnabled(false); 0386 } 0387 0388 Q_EMIT selectionChanged(selection); 0389 } 0390 0391 void DolphinMainWindow::updateHistory() 0392 { 0393 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory(); 0394 const int index = urlNavigator->historyIndex(); 0395 0396 QAction *backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back)); 0397 if (backAction) { 0398 backAction->setToolTip(i18nc("@info", "Go back")); 0399 backAction->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder.")); 0400 backAction->setEnabled(index < urlNavigator->historySize() - 1); 0401 } 0402 0403 QAction *forwardAction = actionCollection()->action(KStandardAction::name(KStandardAction::Forward)); 0404 if (forwardAction) { 0405 forwardAction->setToolTip(i18nc("@info", "Go forward")); 0406 forwardAction->setWhatsThis(xi18nc("@info:whatsthis go forward", "This undoes a <interface>Go|Back</interface> action.")); 0407 forwardAction->setEnabled(index > 0); 0408 } 0409 } 0410 0411 void DolphinMainWindow::updateFilterBarAction(bool show) 0412 { 0413 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); 0414 toggleFilterBarAction->setChecked(show); 0415 } 0416 0417 void DolphinMainWindow::openNewMainWindow() 0418 { 0419 Dolphin::openNewWindow({m_activeViewContainer->url()}, this); 0420 } 0421 0422 void DolphinMainWindow::openNewActivatedTab() 0423 { 0424 // keep browsers compatibility, new tab is always after last one 0425 auto openNewTabAfterLastTabConfigured = GeneralSettings::openNewTabAfterLastTab(); 0426 GeneralSettings::setOpenNewTabAfterLastTab(true); 0427 m_tabWidget->openNewActivatedTab(); 0428 GeneralSettings::setOpenNewTabAfterLastTab(openNewTabAfterLastTabConfigured); 0429 } 0430 0431 void DolphinMainWindow::addToPlaces() 0432 { 0433 QUrl url; 0434 QString name; 0435 0436 // If nothing is selected, act on the current dir 0437 if (m_activeViewContainer->view()->selectedItems().isEmpty()) { 0438 url = m_activeViewContainer->url(); 0439 name = m_activeViewContainer->placesText(); 0440 } else { 0441 const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first(); 0442 url = dirToAdd.url(); 0443 name = dirToAdd.name(); 0444 } 0445 if (url.isValid()) { 0446 QString icon; 0447 if (m_activeViewContainer->isSearchModeEnabled()) { 0448 icon = QStringLiteral("folder-saved-search-symbolic"); 0449 } else { 0450 icon = KIO::iconNameForUrl(url); 0451 } 0452 DolphinPlacesModelSingleton::instance().placesModel()->addPlace(name, url, icon); 0453 } 0454 } 0455 0456 void DolphinMainWindow::openNewTab(const QUrl &url) 0457 { 0458 m_tabWidget->openNewTab(url, QUrl()); 0459 } 0460 0461 void DolphinMainWindow::openNewTabAndActivate(const QUrl &url) 0462 { 0463 m_tabWidget->openNewActivatedTab(url, QUrl()); 0464 } 0465 0466 void DolphinMainWindow::openNewWindow(const QUrl &url) 0467 { 0468 Dolphin::openNewWindow({url}, this); 0469 } 0470 0471 void DolphinMainWindow::slotSplitViewChanged() 0472 { 0473 m_tabWidget->currentTabPage()->setSplitViewEnabled(GeneralSettings::splitView(), WithAnimation); 0474 updateSplitActions(); 0475 } 0476 0477 void DolphinMainWindow::openInNewTab() 0478 { 0479 const KFileItemList &list = m_activeViewContainer->view()->selectedItems(); 0480 bool tabCreated = false; 0481 0482 for (const KFileItem &item : list) { 0483 const QUrl &url = DolphinView::openItemAsFolderUrl(item); 0484 if (!url.isEmpty()) { 0485 openNewTab(url); 0486 tabCreated = true; 0487 } 0488 } 0489 0490 // if no new tab has been created from the selection 0491 // open the current directory in a new tab 0492 if (!tabCreated) { 0493 openNewTab(m_activeViewContainer->url()); 0494 } 0495 } 0496 0497 void DolphinMainWindow::openInNewWindow() 0498 { 0499 QUrl newWindowUrl; 0500 0501 const KFileItemList list = m_activeViewContainer->view()->selectedItems(); 0502 if (list.isEmpty()) { 0503 newWindowUrl = m_activeViewContainer->url(); 0504 } else if (list.count() == 1) { 0505 const KFileItem &item = list.first(); 0506 newWindowUrl = DolphinView::openItemAsFolderUrl(item); 0507 } 0508 0509 if (!newWindowUrl.isEmpty()) { 0510 Dolphin::openNewWindow({newWindowUrl}, this); 0511 } 0512 } 0513 0514 void DolphinMainWindow::openInSplitView(const QUrl &url) 0515 { 0516 QUrl newSplitViewUrl = url; 0517 0518 if (newSplitViewUrl.isEmpty()) { 0519 const KFileItemList list = m_activeViewContainer->view()->selectedItems(); 0520 if (list.count() == 1) { 0521 const KFileItem &item = list.first(); 0522 newSplitViewUrl = DolphinView::openItemAsFolderUrl(item); 0523 } 0524 } 0525 0526 if (newSplitViewUrl.isEmpty()) { 0527 return; 0528 } 0529 0530 DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); 0531 if (tabPage->splitViewEnabled()) { 0532 tabPage->switchActiveView(); 0533 tabPage->activeViewContainer()->setUrl(newSplitViewUrl); 0534 } else { 0535 tabPage->setSplitViewEnabled(true, WithAnimation, newSplitViewUrl); 0536 updateViewActions(); 0537 } 0538 } 0539 0540 void DolphinMainWindow::showTarget() 0541 { 0542 const KFileItem link = m_activeViewContainer->view()->selectedItems().at(0); 0543 const QUrl destinationUrl = link.url().resolved(QUrl(link.linkDest())); 0544 0545 auto job = KIO::stat(destinationUrl, KIO::StatJob::SourceSide, KIO::StatNoDetails); 0546 0547 connect(job, &KJob::finished, this, [this, destinationUrl](KJob *job) { 0548 KIO::StatJob *statJob = static_cast<KIO::StatJob *>(job); 0549 0550 if (statJob->error()) { 0551 m_activeViewContainer->showMessage(job->errorString(), DolphinViewContainer::Error); 0552 } else { 0553 KIO::highlightInFileManager({destinationUrl}); 0554 } 0555 }); 0556 } 0557 0558 bool DolphinMainWindow::event(QEvent *event) 0559 { 0560 if (event->type() == QEvent::ShortcutOverride) { 0561 const QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); 0562 if (keyEvent->key() == Qt::Key_Space && m_activeViewContainer->view()->handleSpaceAsNormalKey()) { 0563 event->accept(); 0564 return true; 0565 } 0566 } 0567 0568 return KXmlGuiWindow::event(event); 0569 } 0570 0571 void DolphinMainWindow::showEvent(QShowEvent *event) 0572 { 0573 KXmlGuiWindow::showEvent(event); 0574 0575 if (!event->spontaneous()) { 0576 m_activeViewContainer->view()->setFocus(); 0577 } 0578 } 0579 0580 void DolphinMainWindow::closeEvent(QCloseEvent *event) 0581 { 0582 // Find out if Dolphin is closed directly by the user or 0583 // by the session manager because the session is closed 0584 bool closedByUser = true; 0585 if (qApp->isSavingSession()) { 0586 closedByUser = false; 0587 } 0588 0589 if (m_tabWidget->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && !GeneralSettings::rememberOpenedTabs() && closedByUser) { 0590 // Ask the user if he really wants to quit and close all tabs. 0591 // Open a confirmation dialog with 3 buttons: 0592 // QDialogButtonBox::Yes -> Quit 0593 // QDialogButtonBox::No -> Close only the current tab 0594 // QDialogButtonBox::Cancel -> do nothing 0595 QDialog *dialog = new QDialog(this, Qt::Dialog); 0596 dialog->setWindowTitle(i18nc("@title:window", "Confirmation")); 0597 dialog->setModal(true); 0598 QDialogButtonBox *buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel); 0599 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), 0600 KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), 0601 QIcon::fromTheme(QStringLiteral("application-exit")))); 0602 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close")))); 0603 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); 0604 buttons->button(QDialogButtonBox::Yes)->setDefault(true); 0605 0606 bool doNotAskAgainCheckboxResult = false; 0607 0608 const auto result = KMessageBox::createKMessageBox(dialog, 0609 buttons, 0610 QMessageBox::Warning, 0611 i18n("You have multiple tabs open in this window, are you sure you want to quit?"), 0612 QStringList(), 0613 i18n("Do not ask again"), 0614 &doNotAskAgainCheckboxResult, 0615 KMessageBox::Notify); 0616 0617 if (doNotAskAgainCheckboxResult) { 0618 GeneralSettings::setConfirmClosingMultipleTabs(false); 0619 } 0620 0621 switch (result) { 0622 case QDialogButtonBox::Yes: 0623 // Quit 0624 break; 0625 case QDialogButtonBox::No: 0626 // Close only the current tab 0627 m_tabWidget->closeTab(); 0628 Q_FALLTHROUGH(); 0629 default: 0630 event->ignore(); 0631 return; 0632 } 0633 } 0634 0635 if (m_terminalPanel && m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) { 0636 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel 0637 // Open a confirmation dialog with 3 buttons: 0638 // QDialogButtonBox::Yes -> Quit 0639 // QDialogButtonBox::No -> Show Terminal Panel 0640 // QDialogButtonBox::Cancel -> do nothing 0641 QDialog *dialog = new QDialog(this, Qt::Dialog); 0642 dialog->setWindowTitle(i18nc("@title:window", "Confirmation")); 0643 dialog->setModal(true); 0644 auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel; 0645 if (!m_terminalPanel->isVisible()) { 0646 standardButtons |= QDialogButtonBox::No; 0647 } 0648 QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons); 0649 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit()); 0650 if (!m_terminalPanel->isVisible()) { 0651 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts")))); 0652 } 0653 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); 0654 0655 bool doNotAskAgainCheckboxResult = false; 0656 0657 const auto result = KMessageBox::createKMessageBox( 0658 dialog, 0659 buttons, 0660 QMessageBox::Warning, 0661 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()), 0662 QStringList(), 0663 i18n("Do not ask again"), 0664 &doNotAskAgainCheckboxResult, 0665 KMessageBox::Notify | KMessageBox::Dangerous); 0666 0667 if (doNotAskAgainCheckboxResult) { 0668 GeneralSettings::setConfirmClosingTerminalRunningProgram(false); 0669 } 0670 0671 switch (result) { 0672 case QDialogButtonBox::Yes: 0673 // Quit 0674 break; 0675 case QDialogButtonBox::No: 0676 actionCollection()->action("show_terminal_panel")->trigger(); 0677 // Do not quit, ignore quit event 0678 Q_FALLTHROUGH(); 0679 default: 0680 event->ignore(); 0681 return; 0682 } 0683 } 0684 0685 if (m_sessionSaveTimer && (m_sessionSaveTimer->isActive() || m_sessionSaveWatcher->isRunning())) { 0686 const bool sessionSaveTimerActive = m_sessionSaveTimer->isActive(); 0687 0688 m_sessionSaveTimer->stop(); 0689 m_sessionSaveWatcher->disconnect(); 0690 m_sessionSaveWatcher->waitForFinished(); 0691 0692 if (sessionSaveTimerActive || m_sessionSaveScheduled) { 0693 slotSaveSession(); 0694 } 0695 } 0696 0697 GeneralSettings::setVersion(CurrentDolphinVersion); 0698 GeneralSettings::self()->save(); 0699 0700 KXmlGuiWindow::closeEvent(event); 0701 } 0702 0703 void DolphinMainWindow::slotSaveSession() 0704 { 0705 m_sessionSaveScheduled = false; 0706 0707 if (m_sessionSaveWatcher->isRunning()) { 0708 // The previous session is still being saved - schedule another save. 0709 m_sessionSaveWatcher->disconnect(); 0710 connect(m_sessionSaveWatcher, &QFutureWatcher<void>::finished, this, &DolphinMainWindow::slotSaveSession, Qt::SingleShotConnection); 0711 m_sessionSaveScheduled = true; 0712 } else if (!m_sessionSaveTimer->isActive()) { 0713 // No point in saving the session if the timer is running (since it will save the session again when it times out). 0714 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin")); 0715 KConfig *config = KConfigGui::sessionConfig(); 0716 saveGlobalProperties(config); 0717 savePropertiesInternal(config, 1); 0718 0719 auto future = QtConcurrent::run([config]() { 0720 config->sync(); 0721 }); 0722 m_sessionSaveWatcher->setFuture(future); 0723 } 0724 } 0725 0726 void DolphinMainWindow::setSessionAutoSaveEnabled(bool enable) 0727 { 0728 if (enable) { 0729 if (!m_sessionSaveTimer) { 0730 m_sessionSaveTimer = new QTimer(this); 0731 m_sessionSaveWatcher = new QFutureWatcher<void>(this); 0732 m_sessionSaveTimer->setSingleShot(true); 0733 m_sessionSaveTimer->setInterval(22000); 0734 0735 connect(m_sessionSaveTimer, &QTimer::timeout, this, &DolphinMainWindow::slotSaveSession); 0736 } 0737 0738 connect(m_tabWidget, &DolphinTabWidget::urlChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection); 0739 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection); 0740 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged, m_sessionSaveTimer, qOverload<>(&QTimer::start), Qt::UniqueConnection); 0741 } else if (m_sessionSaveTimer) { 0742 m_sessionSaveTimer->stop(); 0743 m_sessionSaveWatcher->disconnect(); 0744 m_sessionSaveScheduled = false; 0745 0746 m_sessionSaveWatcher->waitForFinished(); 0747 0748 m_sessionSaveTimer->deleteLater(); 0749 m_sessionSaveWatcher->deleteLater(); 0750 m_sessionSaveTimer = nullptr; 0751 m_sessionSaveWatcher = nullptr; 0752 } 0753 } 0754 0755 void DolphinMainWindow::saveProperties(KConfigGroup &group) 0756 { 0757 m_tabWidget->saveProperties(group); 0758 } 0759 0760 void DolphinMainWindow::readProperties(const KConfigGroup &group) 0761 { 0762 m_tabWidget->readProperties(group); 0763 } 0764 0765 void DolphinMainWindow::updateNewMenu() 0766 { 0767 m_newFileMenu->checkUpToDate(); 0768 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url()); 0769 } 0770 0771 void DolphinMainWindow::createDirectory() 0772 { 0773 m_newFileMenu->setWorkingDirectory(activeViewContainer()->url()); 0774 m_newFileMenu->createDirectory(); 0775 } 0776 0777 void DolphinMainWindow::quit() 0778 { 0779 close(); 0780 } 0781 0782 void DolphinMainWindow::showErrorMessage(const QString &message) 0783 { 0784 m_activeViewContainer->showMessage(message, DolphinViewContainer::Error); 0785 } 0786 0787 void DolphinMainWindow::slotUndoAvailable(bool available) 0788 { 0789 QAction *undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); 0790 if (undoAction) { 0791 undoAction->setEnabled(available); 0792 } 0793 } 0794 0795 void DolphinMainWindow::slotUndoTextChanged(const QString &text) 0796 { 0797 QAction *undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); 0798 if (undoAction) { 0799 undoAction->setText(text); 0800 } 0801 } 0802 0803 void DolphinMainWindow::undo() 0804 { 0805 clearStatusBar(); 0806 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this); 0807 KIO::FileUndoManager::self()->undo(); 0808 } 0809 0810 void DolphinMainWindow::cut() 0811 { 0812 if (m_activeViewContainer->view()->selectedItems().isEmpty()) { 0813 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CutContents); 0814 } else { 0815 m_activeViewContainer->view()->cutSelectedItemsToClipboard(); 0816 m_activeViewContainer->setSelectionModeEnabled(false); 0817 } 0818 } 0819 0820 void DolphinMainWindow::copy() 0821 { 0822 if (m_activeViewContainer->view()->selectedItems().isEmpty()) { 0823 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyContents); 0824 } else { 0825 m_activeViewContainer->view()->copySelectedItemsToClipboard(); 0826 m_activeViewContainer->setSelectionModeEnabled(false); 0827 } 0828 } 0829 0830 void DolphinMainWindow::paste() 0831 { 0832 m_activeViewContainer->view()->paste(); 0833 } 0834 0835 void DolphinMainWindow::find() 0836 { 0837 m_activeViewContainer->setSearchModeEnabled(true); 0838 } 0839 0840 void DolphinMainWindow::updateSearchAction() 0841 { 0842 QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); 0843 toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled()); 0844 } 0845 0846 void DolphinMainWindow::updatePasteAction() 0847 { 0848 QAction *pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); 0849 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo(); 0850 pasteAction->setEnabled(pasteInfo.first); 0851 pasteAction->setText(pasteInfo.second); 0852 } 0853 0854 void DolphinMainWindow::slotDirectoryLoadingCompleted() 0855 { 0856 updatePasteAction(); 0857 } 0858 0859 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action) 0860 { 0861 if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) { 0862 goBackInNewTab(); 0863 } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) { 0864 goForwardInNewTab(); 0865 } else if (action == actionCollection()->action(QStringLiteral("go_up"))) { 0866 goUpInNewTab(); 0867 } else if (action == actionCollection()->action(QStringLiteral("go_home"))) { 0868 goHomeInNewTab(); 0869 } 0870 } 0871 0872 QAction *DolphinMainWindow::urlNavigatorHistoryAction(const KUrlNavigator *urlNavigator, int historyIndex, QObject *parent) 0873 { 0874 const QUrl url = urlNavigator->locationUrl(historyIndex); 0875 0876 QString text = url.toDisplayString(QUrl::PreferLocalFile); 0877 0878 if (!urlNavigator->showFullPath()) { 0879 const KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); 0880 0881 const QModelIndex closestIdx = placesModel->closestItem(url); 0882 if (closestIdx.isValid()) { 0883 const QUrl placeUrl = placesModel->url(closestIdx); 0884 0885 text = placesModel->text(closestIdx); 0886 0887 QString pathInsidePlace = url.path().mid(placeUrl.path().length()); 0888 0889 if (!pathInsidePlace.isEmpty() && !pathInsidePlace.startsWith(QLatin1Char('/'))) { 0890 pathInsidePlace.prepend(QLatin1Char('/')); 0891 } 0892 0893 if (pathInsidePlace != QLatin1Char('/')) { 0894 text.append(pathInsidePlace); 0895 } 0896 } 0897 } 0898 0899 QAction *action = new QAction(QIcon::fromTheme(KIO::iconNameForUrl(url)), text, parent); 0900 action->setData(historyIndex); 0901 return action; 0902 } 0903 0904 void DolphinMainWindow::slotAboutToShowBackPopupMenu() 0905 { 0906 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory(); 0907 int entries = 0; 0908 QMenu *menu = m_backAction->popupMenu(); 0909 menu->clear(); 0910 for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) { 0911 QAction *action = urlNavigatorHistoryAction(urlNavigator, i, menu); 0912 menu->addAction(action); 0913 } 0914 } 0915 0916 void DolphinMainWindow::slotGoBack(QAction *action) 0917 { 0918 int gotoIndex = action->data().value<int>(); 0919 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory(); 0920 for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) { 0921 goBack(); 0922 } 0923 } 0924 0925 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction *action) 0926 { 0927 if (action) { 0928 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory(); 0929 openNewTab(urlNavigator->locationUrl(action->data().value<int>())); 0930 } 0931 } 0932 0933 void DolphinMainWindow::slotAboutToShowForwardPopupMenu() 0934 { 0935 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory(); 0936 int entries = 0; 0937 QMenu *menu = m_forwardAction->popupMenu(); 0938 for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) { 0939 QAction *action = urlNavigatorHistoryAction(urlNavigator, i, menu); 0940 menu->addAction(action); 0941 } 0942 } 0943 0944 void DolphinMainWindow::slotGoForward(QAction *action) 0945 { 0946 int gotoIndex = action->data().value<int>(); 0947 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory(); 0948 for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) { 0949 goForward(); 0950 } 0951 } 0952 0953 void DolphinMainWindow::slotSetSelectionMode(bool enabled, SelectionMode::BottomBar::Contents bottomBarContents) 0954 { 0955 m_activeViewContainer->setSelectionModeEnabled(enabled, actionCollection(), bottomBarContents); 0956 } 0957 0958 void DolphinMainWindow::selectAll() 0959 { 0960 clearStatusBar(); 0961 0962 // if the URL navigator is editable and focused, select the whole 0963 // URL instead of all items of the view 0964 0965 KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigator(); 0966 QLineEdit *lineEdit = urlNavigator->editor()->lineEdit(); 0967 const bool selectUrl = urlNavigator->isUrlEditable() && lineEdit->hasFocus(); 0968 if (selectUrl) { 0969 lineEdit->selectAll(); 0970 } else { 0971 m_activeViewContainer->view()->selectAll(); 0972 } 0973 } 0974 0975 void DolphinMainWindow::invertSelection() 0976 { 0977 clearStatusBar(); 0978 m_activeViewContainer->view()->invertSelection(); 0979 } 0980 0981 void DolphinMainWindow::toggleSplitView() 0982 { 0983 DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); 0984 tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled(), WithAnimation); 0985 m_tabWidget->updateTabName(m_tabWidget->indexOf(tabPage)); 0986 updateViewActions(); 0987 } 0988 0989 void DolphinMainWindow::popoutSplitView() 0990 { 0991 DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); 0992 if (!tabPage->splitViewEnabled()) 0993 return; 0994 openNewWindow((GeneralSettings::closeActiveSplitView() ? tabPage->activeViewContainer() : tabPage->inactiveViewContainer())->url()); 0995 tabPage->setSplitViewEnabled(false, WithAnimation); 0996 updateSplitActions(); 0997 } 0998 0999 void DolphinMainWindow::toggleSplitStash() 1000 { 1001 DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); 1002 tabPage->setSplitViewEnabled(false, WithAnimation); 1003 tabPage->setSplitViewEnabled(true, WithAnimation, QUrl("stash:/")); 1004 } 1005 1006 void DolphinMainWindow::copyToInactiveSplitView() 1007 { 1008 if (m_activeViewContainer->view()->selectedItems().isEmpty()) { 1009 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::CopyToOtherViewContents); 1010 } else { 1011 m_tabWidget->copyToInactiveSplitView(); 1012 m_activeViewContainer->setSelectionModeEnabled(false); 1013 } 1014 } 1015 1016 void DolphinMainWindow::moveToInactiveSplitView() 1017 { 1018 if (m_activeViewContainer->view()->selectedItems().isEmpty()) { 1019 m_activeViewContainer->setSelectionModeEnabled(true, actionCollection(), SelectionMode::BottomBar::Contents::MoveToOtherViewContents); 1020 } else { 1021 m_tabWidget->moveToInactiveSplitView(); 1022 m_activeViewContainer->setSelectionModeEnabled(false); 1023 } 1024 } 1025 1026 void DolphinMainWindow::reloadView() 1027 { 1028 clearStatusBar(); 1029 m_activeViewContainer->reload(); 1030 m_activeViewContainer->statusBar()->updateSpaceInfo(); 1031 } 1032 1033 void DolphinMainWindow::stopLoading() 1034 { 1035 m_activeViewContainer->view()->stopLoading(); 1036 } 1037 1038 void DolphinMainWindow::enableStopAction() 1039 { 1040 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true); 1041 } 1042 1043 void DolphinMainWindow::disableStopAction() 1044 { 1045 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false); 1046 } 1047 1048 void DolphinMainWindow::toggleSelectionMode() 1049 { 1050 const bool checked = !m_activeViewContainer->isSelectionModeEnabled(); 1051 1052 m_activeViewContainer->setSelectionModeEnabled(checked, actionCollection(), SelectionMode::BottomBar::Contents::GeneralContents); 1053 actionCollection()->action(QStringLiteral("toggle_selection_mode"))->setChecked(checked); 1054 } 1055 1056 void DolphinMainWindow::showFilterBar() 1057 { 1058 m_activeViewContainer->setFilterBarVisible(true); 1059 } 1060 1061 void DolphinMainWindow::toggleFilterBar() 1062 { 1063 const bool checked = !m_activeViewContainer->isFilterBarVisible(); 1064 m_activeViewContainer->setFilterBarVisible(checked); 1065 1066 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); 1067 toggleFilterBarAction->setChecked(checked); 1068 } 1069 1070 void DolphinMainWindow::toggleEditLocation() 1071 { 1072 clearStatusBar(); 1073 1074 QAction *action = actionCollection()->action(QStringLiteral("editable_location")); 1075 KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigator(); 1076 urlNavigator->setUrlEditable(action->isChecked()); 1077 } 1078 1079 void DolphinMainWindow::replaceLocation() 1080 { 1081 KUrlNavigator *navigator = m_activeViewContainer->urlNavigator(); 1082 QLineEdit *lineEdit = navigator->editor()->lineEdit(); 1083 1084 // If the text field currently has focus and everything is selected, 1085 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode 1086 if (navigator->isUrlEditable() && lineEdit->hasFocus() && lineEdit->selectedText() == lineEdit->text()) { 1087 navigator->setUrlEditable(false); 1088 } else { 1089 navigator->setUrlEditable(true); 1090 navigator->setFocus(); 1091 lineEdit->selectAll(); 1092 } 1093 } 1094 1095 void DolphinMainWindow::togglePanelLockState() 1096 { 1097 const bool newLockState = !GeneralSettings::lockPanels(); 1098 const auto childrenObjects = children(); 1099 for (QObject *child : childrenObjects) { 1100 DolphinDockWidget *dock = qobject_cast<DolphinDockWidget *>(child); 1101 if (dock) { 1102 dock->setLocked(newLockState); 1103 } 1104 } 1105 1106 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(newLockState); 1107 1108 GeneralSettings::setLockPanels(newLockState); 1109 } 1110 1111 void DolphinMainWindow::slotTerminalPanelVisibilityChanged() 1112 { 1113 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) { 1114 m_activeViewContainer->view()->setFocus(); 1115 } 1116 } 1117 1118 void DolphinMainWindow::goBack() 1119 { 1120 DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory(); 1121 urlNavigator->goBack(); 1122 1123 if (urlNavigator->locationState().isEmpty()) { 1124 // An empty location state indicates a redirection URL, 1125 // which must be skipped too 1126 urlNavigator->goBack(); 1127 } 1128 } 1129 1130 void DolphinMainWindow::goForward() 1131 { 1132 m_activeViewContainer->urlNavigatorInternalWithHistory()->goForward(); 1133 } 1134 1135 void DolphinMainWindow::goUp() 1136 { 1137 m_activeViewContainer->urlNavigatorInternalWithHistory()->goUp(); 1138 } 1139 1140 void DolphinMainWindow::goHome() 1141 { 1142 m_activeViewContainer->urlNavigatorInternalWithHistory()->goHome(); 1143 } 1144 1145 void DolphinMainWindow::goBackInNewTab() 1146 { 1147 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory(); 1148 const int index = urlNavigator->historyIndex() + 1; 1149 openNewTab(urlNavigator->locationUrl(index)); 1150 } 1151 1152 void DolphinMainWindow::goForwardInNewTab() 1153 { 1154 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory(); 1155 const int index = urlNavigator->historyIndex() - 1; 1156 openNewTab(urlNavigator->locationUrl(index)); 1157 } 1158 1159 void DolphinMainWindow::goUpInNewTab() 1160 { 1161 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl(); 1162 openNewTab(KIO::upUrl(currentUrl)); 1163 } 1164 1165 void DolphinMainWindow::goHomeInNewTab() 1166 { 1167 openNewTab(Dolphin::homeUrl()); 1168 } 1169 1170 void DolphinMainWindow::compareFiles() 1171 { 1172 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems(); 1173 if (items.count() != 2) { 1174 // The action is disabled in this case, but it could have been triggered 1175 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517 1176 return; 1177 } 1178 1179 QUrl urlA = items.at(0).url(); 1180 QUrl urlB = items.at(1).url(); 1181 1182 QString command(QStringLiteral("kompare -c \"")); 1183 command.append(urlA.toDisplayString(QUrl::PreferLocalFile)); 1184 command.append("\" \""); 1185 command.append(urlB.toDisplayString(QUrl::PreferLocalFile)); 1186 command.append('\"'); 1187 1188 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this); 1189 job->setDesktopName(QStringLiteral("org.kde.kompare")); 1190 job->start(); 1191 } 1192 1193 void DolphinMainWindow::toggleShowMenuBar() 1194 { 1195 const bool visible = menuBar()->isVisible(); 1196 menuBar()->setVisible(!visible); 1197 } 1198 1199 QPointer<QAction> DolphinMainWindow::preferredSearchTool() 1200 { 1201 m_searchTools.clear(); 1202 1203 KService::Ptr kfind = KService::serviceByDesktopName(QStringLiteral("org.kde.kfind")); 1204 1205 if (!kfind) { 1206 return nullptr; 1207 } 1208 1209 auto *action = new QAction(QIcon::fromTheme(kfind->icon()), kfind->name(), this); 1210 1211 connect(action, &QAction::triggered, this, [kfind] { 1212 auto *job = new KIO::ApplicationLauncherJob(kfind); 1213 job->start(); 1214 }); 1215 1216 return action; 1217 } 1218 1219 void DolphinMainWindow::updateOpenPreferredSearchToolAction() 1220 { 1221 QAction *openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool")); 1222 if (!openPreferredSearchTool) { 1223 return; 1224 } 1225 QPointer<QAction> tool = preferredSearchTool(); 1226 if (tool) { 1227 openPreferredSearchTool->setVisible(true); 1228 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text())); 1229 // Only override with the app icon if it is the default, i.e. the user hasn't configured one manually 1230 // https://bugs.kde.org/show_bug.cgi?id=442815 1231 if (openPreferredSearchTool->icon().name() == QLatin1String("search")) { 1232 openPreferredSearchTool->setIcon(tool->icon()); 1233 } 1234 } else { 1235 openPreferredSearchTool->setVisible(false); 1236 // still visible in Shortcuts configuration window 1237 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool")); 1238 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search"))); 1239 } 1240 } 1241 1242 void DolphinMainWindow::openPreferredSearchTool() 1243 { 1244 QPointer<QAction> tool = preferredSearchTool(); 1245 if (tool) { 1246 tool->trigger(); 1247 } 1248 } 1249 1250 void DolphinMainWindow::openTerminal() 1251 { 1252 openTerminalJob(m_activeViewContainer->url()); 1253 } 1254 1255 void DolphinMainWindow::openTerminalHere() 1256 { 1257 QList<QUrl> urls = {}; 1258 1259 const auto selectedItems = m_activeViewContainer->view()->selectedItems(); 1260 for (const KFileItem &item : selectedItems) { 1261 QUrl url = item.targetUrl(); 1262 if (item.isFile()) { 1263 url.setPath(QFileInfo(url.path()).absolutePath()); 1264 } 1265 if (!urls.contains(url)) { 1266 urls << url; 1267 } 1268 } 1269 1270 // No items are selected. Open a terminal window for the current location. 1271 if (urls.count() == 0) { 1272 openTerminal(); 1273 return; 1274 } 1275 1276 if (urls.count() > 5) { 1277 QString question = i18np("Are you sure you want to open 1 terminal window?", "Are you sure you want to open %1 terminal windows?", urls.count()); 1278 const int answer = KMessageBox::warningContinueCancel( 1279 this, 1280 question, 1281 {}, 1282 KGuiItem(i18ncp("@action:button", "Open %1 Terminal", "Open %1 Terminals", urls.count()), QStringLiteral("utilities-terminal")), 1283 KStandardGuiItem::cancel(), 1284 QStringLiteral("ConfirmOpenManyTerminals")); 1285 if (answer != KMessageBox::PrimaryAction && answer != KMessageBox::Continue) { 1286 return; 1287 } 1288 } 1289 1290 for (const QUrl &url : std::as_const(urls)) { 1291 openTerminalJob(url); 1292 } 1293 } 1294 1295 void DolphinMainWindow::openTerminalJob(const QUrl &url) 1296 { 1297 if (url.isLocalFile()) { 1298 auto job = new KTerminalLauncherJob(QString()); 1299 job->setWorkingDirectory(url.toLocalFile()); 1300 job->start(); 1301 return; 1302 } 1303 1304 // Not a local file, with protocol Class ":local", try stat'ing 1305 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) { 1306 KIO::StatJob *job = KIO::mostLocalUrl(url); 1307 KJobWidgets::setWindow(job, this); 1308 connect(job, &KJob::result, this, [job]() { 1309 QUrl statUrl; 1310 if (!job->error()) { 1311 statUrl = job->mostLocalUrl(); 1312 } 1313 1314 auto job = new KTerminalLauncherJob(QString()); 1315 job->setWorkingDirectory(statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath()); 1316 job->start(); 1317 }); 1318 1319 return; 1320 } 1321 1322 // Nothing worked, just use $HOME 1323 auto job = new KTerminalLauncherJob(QString()); 1324 job->setWorkingDirectory(QDir::homePath()); 1325 job->start(); 1326 } 1327 1328 void DolphinMainWindow::editSettings() 1329 { 1330 if (!m_settingsDialog) { 1331 DolphinViewContainer *container = activeViewContainer(); 1332 container->view()->writeSettings(); 1333 1334 const QUrl url = container->url(); 1335 DolphinSettingsDialog *settingsDialog = new DolphinSettingsDialog(url, this, actionCollection()); 1336 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews); 1337 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, &DolphinUrlNavigatorsController::slotReadSettings); 1338 settingsDialog->setAttribute(Qt::WA_DeleteOnClose); 1339 settingsDialog->show(); 1340 m_settingsDialog = settingsDialog; 1341 } else { 1342 m_settingsDialog.data()->raise(); 1343 } 1344 } 1345 1346 void DolphinMainWindow::handleUrl(const QUrl &url) 1347 { 1348 delete m_lastHandleUrlOpenJob; 1349 m_lastHandleUrlOpenJob = nullptr; 1350 1351 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) { 1352 activeViewContainer()->setUrl(url); 1353 } else { 1354 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url); 1355 m_lastHandleUrlOpenJob->setUiDelegate(KIO::createDefaultJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this)); 1356 m_lastHandleUrlOpenJob->setShowOpenOrExecuteDialog(true); 1357 1358 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this, [this, url](const QString &mimetype) { 1359 if (mimetype == QLatin1String("inode/directory")) { 1360 // If it's a dir, we'll take it from here 1361 m_lastHandleUrlOpenJob->kill(); 1362 m_lastHandleUrlOpenJob = nullptr; 1363 activeViewContainer()->setUrl(url); 1364 } 1365 }); 1366 1367 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() { 1368 m_lastHandleUrlOpenJob = nullptr; 1369 }); 1370 1371 m_lastHandleUrlOpenJob->start(); 1372 } 1373 } 1374 1375 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) 1376 { 1377 // trash:/ is writable but we don't want to create new items in it. 1378 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented 1379 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash")); 1380 } 1381 1382 void DolphinMainWindow::openContextMenu(const QPoint &pos, const KFileItem &item, const KFileItemList &selectedItems, const QUrl &url) 1383 { 1384 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, item, selectedItems, url, &m_fileItemActions); 1385 contextMenu->exec(pos); 1386 1387 // Delete the menu, unless it has been deleted in its own nested event loop already. 1388 if (contextMenu) { 1389 contextMenu->deleteLater(); 1390 } 1391 } 1392 1393 QMenu *DolphinMainWindow::createPopupMenu() 1394 { 1395 QMenu *menu = KXmlGuiWindow::createPopupMenu(); 1396 1397 menu->addSeparator(); 1398 menu->addAction(actionCollection()->action(QStringLiteral("lock_panels"))); 1399 1400 return menu; 1401 } 1402 1403 void DolphinMainWindow::updateHamburgerMenu() 1404 { 1405 KActionCollection *ac = actionCollection(); 1406 auto hamburgerMenu = static_cast<KHamburgerMenu *>(ac->action(KStandardAction::name(KStandardAction::HamburgerMenu))); 1407 auto menu = hamburgerMenu->menu(); 1408 if (!menu) { 1409 menu = new QMenu(this); 1410 hamburgerMenu->setMenu(menu); 1411 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("basic_actions"))->menu()); 1412 hamburgerMenu->hideActionsOf(ac->action(QStringLiteral("zoom"))->menu()); 1413 } else { 1414 menu->clear(); 1415 } 1416 const QList<QAction *> toolbarActions = toolBar()->actions(); 1417 1418 if (!toolBar()->isVisible()) { 1419 // If neither the menu bar nor the toolbar are visible, these actions should be available. 1420 menu->addAction(ac->action(KStandardAction::name(KStandardAction::ShowMenubar))); 1421 menu->addAction(toolBarMenuAction()); 1422 menu->addSeparator(); 1423 } 1424 1425 // This group of actions (until the next separator) contains all the most basic actions 1426 // necessary to use Dolphin effectively. 1427 menu->addAction(ac->action(QStringLiteral("go_back"))); 1428 menu->addAction(ac->action(QStringLiteral("go_forward"))); 1429 1430 menu->addMenu(m_newFileMenu->menu()); 1431 if (!toolBar()->isVisible() || !toolbarActions.contains(ac->action(QStringLiteral("toggle_selection_mode_tool_bar")))) { 1432 menu->addAction(ac->action(QStringLiteral("toggle_selection_mode"))); 1433 } 1434 menu->addAction(ac->action(QStringLiteral("basic_actions"))); 1435 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Undo))); 1436 if (!toolBar()->isVisible() 1437 || (!toolbarActions.contains(ac->action(QStringLiteral("toggle_search"))) 1438 && !toolbarActions.contains(ac->action(QStringLiteral("open_preferred_search_tool"))))) { 1439 menu->addAction(ac->action(KStandardAction::name(KStandardAction::Find))); 1440 // This way a search action will only be added if none of the three available 1441 // search actions is present on the toolbar. 1442 } 1443 if (!toolBar()->isVisible() || !toolbarActions.contains(ac->action(QStringLiteral("toggle_filter")))) { 1444 menu->addAction(ac->action(QStringLiteral("show_filter_bar"))); 1445 // This way a filter action will only be added if none of the two available 1446 // filter actions is present on the toolbar. 1447 } 1448 menu->addSeparator(); 1449 1450 // The second group of actions (up until the next separator) contains actions for opening 1451 // additional views to interact with the file system. 1452 menu->addAction(ac->action(QStringLiteral("file_new"))); 1453 menu->addAction(ac->action(QStringLiteral("new_tab"))); 1454 if (ac->action(QStringLiteral("undo_close_tab"))->isEnabled()) { 1455 menu->addAction(ac->action(QStringLiteral("closed_tabs"))); 1456 } 1457 menu->addAction(ac->action(QStringLiteral("open_terminal"))); 1458 menu->addSeparator(); 1459 1460 // The third group contains actions to change what one sees in the view 1461 // and to change the more general UI. 1462 if (!toolBar()->isVisible() 1463 || (!toolbarActions.contains(ac->action(QStringLiteral("icons"))) && !toolbarActions.contains(ac->action(QStringLiteral("compact"))) 1464 && !toolbarActions.contains(ac->action(QStringLiteral("details"))) && !toolbarActions.contains(ac->action(QStringLiteral("view_mode"))))) { 1465 menu->addAction(ac->action(QStringLiteral("view_mode"))); 1466 } 1467 menu->addAction(ac->action(QStringLiteral("show_hidden_files"))); 1468 menu->addAction(ac->action(QStringLiteral("sort"))); 1469 menu->addAction(ac->action(QStringLiteral("additional_info"))); 1470 if (!GeneralSettings::showStatusBar() || !GeneralSettings::showZoomSlider()) { 1471 menu->addAction(ac->action(QStringLiteral("zoom"))); 1472 } 1473 menu->addAction(ac->action(QStringLiteral("panels"))); 1474 1475 // The "Configure" menu is not added to the actionCollection() because there is hardly 1476 // a good reason for users to put it on their toolbar. 1477 auto configureMenu = menu->addMenu(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu menu for configure actions", "Configure")); 1478 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))); 1479 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::KeyBindings))); 1480 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars))); 1481 configureMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Preferences))); 1482 hamburgerMenu->hideActionsOf(configureMenu); 1483 } 1484 1485 void DolphinMainWindow::slotPlaceActivated(const QUrl &url) 1486 { 1487 DolphinViewContainer *view = activeViewContainer(); 1488 1489 if (view->url() == url) { 1490 view->clearFilterBar(); // Fixes bug 259382. 1491 1492 // We can end up here if the user clicked a device in the Places Panel 1493 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385. 1494 reloadView(); 1495 } else { 1496 view->disableUrlNavigatorSelectionRequests(); 1497 changeUrl(url); 1498 view->enableUrlNavigatorSelectionRequests(); 1499 } 1500 } 1501 1502 void DolphinMainWindow::closedTabsCountChanged(unsigned int count) 1503 { 1504 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0); 1505 } 1506 1507 void DolphinMainWindow::activeViewChanged(DolphinViewContainer *viewContainer) 1508 { 1509 DolphinViewContainer *oldViewContainer = m_activeViewContainer; 1510 Q_ASSERT(viewContainer); 1511 1512 m_activeViewContainer = viewContainer; 1513 1514 if (oldViewContainer) { 1515 const QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); 1516 toggleSearchAction->disconnect(oldViewContainer); 1517 1518 // Disconnect all signals between the old view container (container, 1519 // view and url navigator) and main window. 1520 oldViewContainer->disconnect(this); 1521 oldViewContainer->view()->disconnect(this); 1522 oldViewContainer->urlNavigatorInternalWithHistory()->disconnect(this); 1523 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators"))); 1524 navigators->primaryUrlNavigator()->disconnect(this); 1525 if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) { 1526 secondaryUrlNavigator->disconnect(this); 1527 } 1528 1529 // except the requestItemInfo so that on hover the information panel can still be updated 1530 connect(oldViewContainer->view(), &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo); 1531 1532 // Disconnect other slots. 1533 disconnect(oldViewContainer, 1534 &DolphinViewContainer::selectionModeChanged, 1535 actionCollection()->action(QStringLiteral("toggle_selection_mode")), 1536 &QAction::setChecked); 1537 } 1538 1539 connectViewSignals(viewContainer); 1540 1541 m_actionHandler->setCurrentView(viewContainer->view()); 1542 1543 updateHistory(); 1544 updateFileAndEditActions(); 1545 updatePasteAction(); 1546 updateViewActions(); 1547 updateGoActions(); 1548 updateSearchAction(); 1549 1550 const QUrl url = viewContainer->url(); 1551 Q_EMIT urlChanged(url); 1552 } 1553 1554 void DolphinMainWindow::tabCountChanged(int count) 1555 { 1556 const bool enableTabActions = (count > 1); 1557 for (int i = 0; i < MaxActivateTabShortcuts; ++i) { 1558 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions); 1559 } 1560 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions); 1561 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); 1562 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); 1563 } 1564 1565 void DolphinMainWindow::updateWindowTitle() 1566 { 1567 const QString newTitle = m_activeViewContainer->captionWindowTitle(); 1568 if (windowTitle() != newTitle) { 1569 setWindowTitle(newTitle); 1570 } 1571 } 1572 1573 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString &mountPath) 1574 { 1575 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() { 1576 setViewsToHomeIfMountPathOpen(mountPath); 1577 }); 1578 1579 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) { 1580 m_tearDownFromPlacesRequested = true; 1581 m_terminalPanel->goHome(); 1582 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged 1583 } else { 1584 m_placesPanel->proceedWithTearDown(); 1585 } 1586 } 1587 1588 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString &mountPath) 1589 { 1590 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() { 1591 setViewsToHomeIfMountPathOpen(mountPath); 1592 }); 1593 1594 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectoryIsChildOf(mountPath)) { 1595 m_tearDownFromPlacesRequested = false; 1596 m_terminalPanel->goHome(); 1597 } 1598 } 1599 1600 void DolphinMainWindow::slotKeyBindings() 1601 { 1602 KShortcutsDialog dialog(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsAllowed, this); 1603 dialog.addCollection(actionCollection()); 1604 if (m_terminalPanel) { 1605 KActionCollection *konsolePartActionCollection = m_terminalPanel->actionCollection(); 1606 if (konsolePartActionCollection) { 1607 dialog.addCollection(konsolePartActionCollection, QStringLiteral("KonsolePart")); 1608 } 1609 } 1610 dialog.configure(); 1611 } 1612 1613 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString &mountPath) 1614 { 1615 const QVector<DolphinViewContainer *> theViewContainers = viewContainers(); 1616 for (DolphinViewContainer *viewContainer : theViewContainers) { 1617 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) { 1618 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath())); 1619 } 1620 } 1621 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr); 1622 } 1623 1624 void DolphinMainWindow::setupActions() 1625 { 1626 auto hamburgerMenuAction = KStandardAction::hamburgerMenu(nullptr, nullptr, actionCollection()); 1627 1628 // setup 'File' menu 1629 m_newFileMenu = new DolphinNewFileMenu(nullptr, this); 1630 actionCollection()->addAction(QStringLiteral("new_menu"), m_newFileMenu); 1631 QMenu *menu = m_newFileMenu->menu(); 1632 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); 1633 menu->setIcon(QIcon::fromTheme(QStringLiteral("list-add"))); 1634 m_newFileMenu->setPopupMode(QToolButton::InstantPopup); 1635 connect(menu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateNewMenu); 1636 1637 QAction *newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection()); 1638 newWindow->setText(i18nc("@action:inmenu File", "New &Window")); 1639 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window")); 1640 newWindow->setWhatsThis(xi18nc("@info:whatsthis", 1641 "This opens a new " 1642 "window just like this one with the current location and view." 1643 "<nl/>You can drag and drop items between windows.")); 1644 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); 1645 1646 QAction *newTab = actionCollection()->addAction(QStringLiteral("new_tab")); 1647 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); 1648 newTab->setText(i18nc("@action:inmenu File", "New Tab")); 1649 newTab->setWhatsThis(xi18nc("@info:whatsthis", 1650 "This opens a new " 1651 "<emphasis>Tab</emphasis> with the current location and view.<nl/>" 1652 "A tab is an additional view within this window. " 1653 "You can drag and drop items between tabs.")); 1654 actionCollection()->setDefaultShortcut(newTab, Qt::CTRL | Qt::Key_T); 1655 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab); 1656 1657 QAction *addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places")); 1658 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new"))); 1659 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places")); 1660 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", 1661 "This adds the selected folder " 1662 "to the Places panel.")); 1663 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces); 1664 1665 QAction *closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection()); 1666 closeTab->setText(i18nc("@action:inmenu File", "Close Tab")); 1667 closeTab->setWhatsThis(i18nc("@info:whatsthis", 1668 "This closes the " 1669 "currently viewed tab. If no more tabs are left this window " 1670 "will close instead.")); 1671 1672 QAction *quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection()); 1673 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window.")); 1674 1675 // setup 'Edit' menu 1676 KStandardAction::undo(this, &DolphinMainWindow::undo, actionCollection()); 1677 1678 // i18n: This will be the last paragraph for the whatsthis for all three: 1679 // Cut, Copy and Paste 1680 const QString cutCopyPastePara = xi18nc("@info:whatsthis", 1681 "<para><emphasis>Cut, " 1682 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many " 1683 "applications and are among the most used commands. That's why their " 1684 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right " 1685 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, " 1686 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>"); 1687 QAction *cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection()); 1688 m_actionTextHelper->registerTextWhenNothingIsSelected(cutAction, i18nc("@action", "Cut…")); 1689 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", 1690 "This copies the items " 1691 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>" 1692 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from " 1693 "the clipboard to a new location. The items will be removed from their " 1694 "initial location.") 1695 + cutCopyPastePara); 1696 QAction *copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection()); 1697 m_actionTextHelper->registerTextWhenNothingIsSelected(copyAction, i18nc("@action", "Copy…")); 1698 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", 1699 "This copies the " 1700 "items in your current selection to the <emphasis>clipboard</emphasis>." 1701 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them " 1702 "from the clipboard to a new location.") 1703 + cutCopyPastePara); 1704 QAction *paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection()); 1705 // The text of the paste-action is modified dynamically by Dolphin 1706 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes 1707 // due to the long text, the text "Paste" is used: 1708 paste->setIconText(i18nc("@action:inmenu Edit", "Paste")); 1709 paste->setWhatsThis(xi18nc("@info:whatsthis paste", 1710 "This copies the items from " 1711 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>" 1712 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> " 1713 "action they are removed from their old location.") 1714 + cutCopyPastePara); 1715 1716 QAction *copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view")); 1717 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Other View")); 1718 m_actionTextHelper->registerTextWhenNothingIsSelected(copyToOtherViewAction, i18nc("@action:inmenu", "Copy to Other View…")); 1719 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", 1720 "This copies the selected items from " 1721 "the <emphasis>active</emphasis> view to the inactive split view.")); 1722 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy"))); 1723 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View")); 1724 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT | Qt::Key_F5); 1725 connect(copyToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::copyToInactiveSplitView); 1726 1727 QAction *moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view")); 1728 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Other View")); 1729 m_actionTextHelper->registerTextWhenNothingIsSelected(moveToOtherViewAction, i18nc("@action:inmenu", "Move to Other View…")); 1730 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", 1731 "This moves the selected items from " 1732 "the <emphasis>active</emphasis> view to the inactive split view.")); 1733 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut"))); 1734 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View")); 1735 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT | Qt::Key_F6); 1736 connect(moveToOtherViewAction, &QAction::triggered, this, &DolphinMainWindow::moveToInactiveSplitView); 1737 1738 QAction *showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar")); 1739 showFilterBar->setText(i18nc("@action:inmenu Tools", "Filter…")); 1740 showFilterBar->setToolTip(i18nc("@info:tooltip", "Show Filter Bar")); 1741 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", 1742 "This opens the " 1743 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> " 1744 "There you can enter a text to filter the files and folders currently displayed. " 1745 "Only those that contain the text in their name will be kept in view.")); 1746 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter"))); 1747 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL | Qt::Key_I, Qt::Key_Slash}); 1748 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar); 1749 1750 // toggle_filter acts as a copy of the main showFilterBar to be used mainly 1751 // in the toolbar, with no default shortcut attached, to avoid messing with 1752 // existing workflows (filter bar always open and Ctrl-I to focus) 1753 QAction *toggleFilter = actionCollection()->addAction(QStringLiteral("toggle_filter")); 1754 toggleFilter->setText(i18nc("@action:inmenu", "Toggle Filter Bar")); 1755 toggleFilter->setIconText(i18nc("@action:intoolbar", "Filter")); 1756 toggleFilter->setIcon(showFilterBar->icon()); 1757 toggleFilter->setToolTip(showFilterBar->toolTip()); 1758 toggleFilter->setWhatsThis(showFilterBar->whatsThis()); 1759 toggleFilter->setCheckable(true); 1760 connect(toggleFilter, &QAction::triggered, this, &DolphinMainWindow::toggleFilterBar); 1761 1762 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection()); 1763 searchAction->setText(i18n("Search…")); 1764 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders")); 1765 searchAction->setWhatsThis(xi18nc("@info:whatsthis find", 1766 "<para>This helps you " 1767 "find files and folders by opening a <emphasis>find bar</emphasis>. " 1768 "There you can enter search terms and specify settings to find the " 1769 "objects you are looking for.</para><para>Use this help again on " 1770 "the find bar so we can have a look at it while the settings are " 1771 "explained.</para>")); 1772 1773 // toggle_search acts as a copy of the main searchAction to be used mainly 1774 // in the toolbar, with no default shortcut attached, to avoid messing with 1775 // existing workflows (search bar always open and Ctrl-F to focus) 1776 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search")); 1777 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar")); 1778 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search")); 1779 toggleSearchAction->setIcon(searchAction->icon()); 1780 toggleSearchAction->setToolTip(searchAction->toolTip()); 1781 toggleSearchAction->setWhatsThis(searchAction->whatsThis()); 1782 toggleSearchAction->setCheckable(true); 1783 1784 QAction *toggleSelectionModeAction = actionCollection()->addAction(QStringLiteral("toggle_selection_mode")); 1785 // i18n: This action toggles a selection mode. 1786 toggleSelectionModeAction->setText(i18nc("@action:inmenu", "Select Files and Folders")); 1787 // i18n: Opens a selection mode for selecting files/folders. 1788 // The text is kept so unspecific because it will be shown on the toolbar where space is at a premium. 1789 toggleSelectionModeAction->setIconText(i18nc("@action:intoolbar", "Select")); 1790 toggleSelectionModeAction->setWhatsThis(xi18nc( 1791 "@info:whatsthis", 1792 "<para>This application only knows which files or folders should be acted on if they are" 1793 " <emphasis>selected</emphasis> first. Press this to toggle a <emphasis>Selection Mode</emphasis> which makes selecting and deselecting as easy as " 1794 "pressing an item once.</para><para>While in this mode, a quick access bar at the bottom shows available actions for the currently selected items." 1795 "</para>")); 1796 toggleSelectionModeAction->setIcon(QIcon::fromTheme(QStringLiteral("quickwizard"))); 1797 toggleSelectionModeAction->setCheckable(true); 1798 actionCollection()->setDefaultShortcut(toggleSelectionModeAction, Qt::Key_Space); 1799 connect(toggleSelectionModeAction, &QAction::triggered, this, &DolphinMainWindow::toggleSelectionMode); 1800 1801 // A special version of the toggleSelectionModeAction for the toolbar that also contains a menu 1802 // with the selectAllAction and invertSelectionAction. 1803 auto *toggleSelectionModeToolBarAction = 1804 new KToolBarPopupAction(toggleSelectionModeAction->icon(), toggleSelectionModeAction->iconText(), actionCollection()); 1805 toggleSelectionModeToolBarAction->setToolTip(toggleSelectionModeAction->text()); 1806 toggleSelectionModeToolBarAction->setWhatsThis(toggleSelectionModeAction->whatsThis()); 1807 actionCollection()->addAction(QStringLiteral("toggle_selection_mode_tool_bar"), toggleSelectionModeToolBarAction); 1808 toggleSelectionModeToolBarAction->setCheckable(true); 1809 toggleSelectionModeToolBarAction->setPopupMode(KToolBarPopupAction::DelayedPopup); 1810 connect(toggleSelectionModeToolBarAction, &QAction::triggered, toggleSelectionModeAction, &QAction::trigger); 1811 connect(toggleSelectionModeAction, &QAction::toggled, toggleSelectionModeToolBarAction, &QAction::setChecked); 1812 1813 QAction *selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection()); 1814 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", 1815 "This selects all " 1816 "files and folders in the current location.")); 1817 1818 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection")); 1819 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection")); 1820 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", 1821 "This selects all " 1822 "objects that you have currently <emphasis>not</emphasis> selected instead.")); 1823 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert"))); 1824 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A); 1825 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection); 1826 1827 QMenu *toggleSelectionModeActionMenu = new QMenu(this); 1828 toggleSelectionModeActionMenu->addAction(selectAllAction); 1829 toggleSelectionModeActionMenu->addAction(invertSelection); 1830 toggleSelectionModeToolBarAction->setMenu(toggleSelectionModeActionMenu); 1831 1832 // setup 'View' menu 1833 // (note that most of it is set up in DolphinViewActionHandler) 1834 1835 m_splitViewAction = actionCollection()->add<KActionMenu>(QStringLiteral("split_view")); 1836 m_splitViewMenuAction = actionCollection()->addAction(QStringLiteral("split_view_menu")); 1837 1838 m_splitViewAction->setWhatsThis(xi18nc("@info:whatsthis find", 1839 "<para>This splits " 1840 "the folder view below into two autonomous views.</para><para>This " 1841 "way you can see two locations at once and move items between them " 1842 "quickly.</para>Click this again afterwards to recombine the views.")); 1843 m_splitViewMenuAction->setWhatsThis(m_splitViewAction->whatsThis()); 1844 1845 // only set it for the menu version 1846 actionCollection()->setDefaultShortcut(m_splitViewMenuAction, Qt::Key_F3); 1847 1848 connect(m_splitViewAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView); 1849 connect(m_splitViewMenuAction, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView); 1850 1851 QAction *popoutSplit = actionCollection()->addAction(QStringLiteral("popout_split_view")); 1852 popoutSplit->setWhatsThis(xi18nc("@info:whatsthis", 1853 "If the folder view has been split, this will pop the active folder " 1854 "view out into a new window.")); 1855 popoutSplit->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); 1856 actionCollection()->setDefaultShortcut(popoutSplit, Qt::SHIFT | Qt::Key_F3); 1857 connect(popoutSplit, &QAction::triggered, this, &DolphinMainWindow::popoutSplitView); 1858 1859 QAction *stashSplit = actionCollection()->addAction(QStringLiteral("split_stash")); 1860 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL | Qt::Key_S); 1861 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash")); 1862 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window")); 1863 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash"))); 1864 stashSplit->setCheckable(false); 1865 QDBusConnectionInterface *sessionInterface = QDBusConnection::sessionBus().interface(); 1866 stashSplit->setVisible(sessionInterface && sessionInterface->isServiceRegistered(QStringLiteral("org.kde.kio.StashNotifier"))); 1867 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash); 1868 1869 QAction *redisplay = KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection()); 1870 redisplay->setToolTip(i18nc("@info:tooltip", "Refresh view")); 1871 redisplay->setWhatsThis(xi18nc("@info:whatsthis refresh", 1872 "<para>This refreshes " 1873 "the folder view.</para>" 1874 "<para>If the contents of this folder have changed, refreshing will re-scan this folder " 1875 "and show you a newly-updated view of the files and folders contained here.</para>" 1876 "<para>If the view is split, this refreshes the one that is currently in focus.</para>")); 1877 1878 QAction *stop = actionCollection()->addAction(QStringLiteral("stop")); 1879 stop->setText(i18nc("@action:inmenu View", "Stop")); 1880 stop->setToolTip(i18nc("@info", "Stop loading")); 1881 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder.")); 1882 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop"))); 1883 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading); 1884 1885 KToggleAction *editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location")); 1886 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location")); 1887 editableLocation->setWhatsThis(xi18nc("@info:whatsthis", 1888 "This toggles the <emphasis>Location Bar</emphasis> to be " 1889 "editable so you can directly enter a location you want to go to.<nl/>" 1890 "You can also switch to editing by clicking to the right of the " 1891 "location and switch back by confirming the edited location.")); 1892 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6); 1893 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation); 1894 1895 QAction *replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location")); 1896 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location")); 1897 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here. 1898 // Both meanings are useful but not necessary to understand the use of "Replace Location". 1899 // So you might want to be more verbose in your language to convey the meaning but it's up to you. 1900 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis", 1901 "This switches to editing the location and selects it " 1902 "so you can quickly enter a different location.")); 1903 actionCollection()->setDefaultShortcuts(replaceLocation, {Qt::CTRL | Qt::Key_L, Qt::ALT | Qt::Key_D}); 1904 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation); 1905 1906 // setup 'Go' menu 1907 { 1908 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr)); 1909 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection()); 1910 m_backAction->setObjectName(backAction->objectName()); 1911 m_backAction->setShortcuts(backAction->shortcuts()); 1912 } 1913 m_backAction->setPopupMode(KToolBarPopupAction::DelayedPopup); 1914 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack); 1915 connect(m_backAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu); 1916 connect(m_backAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack); 1917 actionCollection()->addAction(m_backAction->objectName(), m_backAction); 1918 1919 auto backShortcuts = m_backAction->shortcuts(); 1920 // Prepend this shortcut, to avoid being hidden by the two-slot UI (#371130) 1921 backShortcuts.prepend(QKeySequence(Qt::Key_Backspace)); 1922 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts); 1923 1924 DolphinRecentTabsMenu *recentTabsMenu = new DolphinRecentTabsMenu(this); 1925 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu); 1926 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab, recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab); 1927 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab, m_tabWidget, &DolphinTabWidget::restoreClosedTab); 1928 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged, this, &DolphinMainWindow::closedTabsCountChanged); 1929 1930 QAction *undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab")); 1931 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab")); 1932 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab", "This returns you to the previously closed tab.")); 1933 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL | Qt::SHIFT | Qt::Key_T); 1934 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo"))); 1935 undoCloseTab->setEnabled(false); 1936 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab); 1937 1938 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo)); 1939 undoAction->setWhatsThis(xi18nc("@info:whatsthis", 1940 "This undoes " 1941 "the last change you made to files or folders.<nl/>" 1942 "Such changes include <interface>creating, renaming</interface> " 1943 "and <interface>moving</interface> them to a different location " 1944 "or to the <filename>Trash</filename>. <nl/>Changes that can't " 1945 "be undone will ask for your confirmation.")); 1946 undoAction->setEnabled(false); // undo should be disabled by default 1947 1948 { 1949 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr)); 1950 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection()); 1951 m_forwardAction->setObjectName(forwardAction->objectName()); 1952 m_forwardAction->setShortcuts(forwardAction->shortcuts()); 1953 } 1954 m_forwardAction->setPopupMode(KToolBarPopupAction::DelayedPopup); 1955 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward); 1956 connect(m_forwardAction->popupMenu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu); 1957 connect(m_forwardAction->popupMenu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward); 1958 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction); 1959 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts()); 1960 1961 // enable middle-click to open in a new tab 1962 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this); 1963 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked); 1964 m_backAction->popupMenu()->installEventFilter(middleClickEventFilter); 1965 m_forwardAction->popupMenu()->installEventFilter(middleClickEventFilter); 1966 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection()); 1967 QAction *homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection()); 1968 homeAction->setWhatsThis(xi18nc("@info:whatsthis", 1969 "Go to your " 1970 "<filename>Home</filename> folder.<nl/>Every user account " 1971 "has their own <filename>Home</filename> that contains their data " 1972 "including folders that contain personal application data.")); 1973 1974 // setup 'Tools' menu 1975 QAction *compareFiles = actionCollection()->addAction(QStringLiteral("compare_files")); 1976 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files")); 1977 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare"))); 1978 compareFiles->setEnabled(false); 1979 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles); 1980 1981 QAction *openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool")); 1982 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool")); 1983 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis", 1984 "<para>This opens a preferred search tool for the viewed location.</para>" 1985 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>")); 1986 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search"))); 1987 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL | Qt::SHIFT | Qt::Key_F); 1988 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool); 1989 1990 if (KAuthorized::authorize(QStringLiteral("shell_access"))) { 1991 QAction *openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal")); 1992 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal")); 1993 openTerminal->setWhatsThis(xi18nc("@info:whatsthis", 1994 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>" 1995 "<para>To learn more about terminals use the help in the terminal application.</para>")); 1996 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal"))); 1997 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT | Qt::Key_F4); 1998 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal); 1999 2000 QAction *openTerminalHere = actionCollection()->addAction(QStringLiteral("open_terminal_here")); 2001 // i18n: "Here" refers to the location(s) of the currently selected item(s) or the currently viewed location if nothing is selected. 2002 openTerminalHere->setText(i18nc("@action:inmenu Tools", "Open Terminal Here")); 2003 openTerminalHere->setWhatsThis(xi18nc("@info:whatsthis", 2004 "<para>This opens <emphasis>terminal</emphasis> applications for the selected items' locations.</para>" 2005 "<para>To learn more about terminals use the help in the terminal application.</para>")); 2006 openTerminalHere->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal"))); 2007 actionCollection()->setDefaultShortcut(openTerminalHere, Qt::SHIFT | Qt::ALT | Qt::Key_F4); 2008 connect(openTerminalHere, &QAction::triggered, this, &DolphinMainWindow::openTerminalHere); 2009 2010 #if HAVE_TERMINAL 2011 QAction *focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel")); 2012 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel")); 2013 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels"))); 2014 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL | Qt::SHIFT | Qt::Key_F4); 2015 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel); 2016 #endif 2017 } 2018 2019 // setup 'Bookmarks' menu 2020 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this); 2021 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks"))); 2022 // Make the toolbar button version work properly on click 2023 bookmarkMenu->setPopupMode(QToolButton::InstantPopup); 2024 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this); 2025 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu); 2026 2027 // setup 'Settings' menu 2028 KToggleAction *showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection()); 2029 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis", 2030 "<para>This switches between having a <emphasis>Menubar</emphasis> " 2031 "and having a <interface>%1</interface> button. Both " 2032 "contain mostly the same actions and configuration options.</para>" 2033 "<para>The Menubar takes up more space but allows for fast and organised access to all " 2034 "actions an application has to offer.</para><para>The <interface>%1</interface> button " 2035 "is simpler and small which makes triggering advanced actions more time consuming.</para>", 2036 hamburgerMenuAction->text().replace('&', ""))); 2037 connect(showMenuBar, 2038 &KToggleAction::triggered, // Fixes #286822 2039 this, 2040 &DolphinMainWindow::toggleShowMenuBar, 2041 Qt::QueuedConnection); 2042 2043 KToggleAction *showStatusBar = KStandardAction::showStatusbar(nullptr, nullptr, actionCollection()); 2044 showStatusBar->setChecked(GeneralSettings::showStatusBar()); 2045 connect(GeneralSettings::self(), &GeneralSettings::showStatusBarChanged, showStatusBar, &KToggleAction::setChecked); 2046 connect(showStatusBar, &KToggleAction::triggered, this, [this](bool checked) { 2047 GeneralSettings::setShowStatusBar(checked); 2048 refreshViews(); 2049 }); 2050 2051 KStandardAction::keyBindings(this, &DolphinMainWindow::slotKeyBindings, actionCollection()); 2052 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection()); 2053 2054 // not in menu actions 2055 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext(); 2056 nextTabKeys.append(QKeySequence(Qt::CTRL | Qt::Key_Tab)); 2057 2058 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev(); 2059 prevTabKeys.append(QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_Tab)); 2060 2061 for (int i = 0; i < MaxActivateTabShortcuts; ++i) { 2062 QAction *activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i)); 2063 activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1)); 2064 activateTab->setEnabled(false); 2065 connect(activateTab, &QAction::triggered, this, [this, i]() { 2066 m_tabWidget->activateTab(i); 2067 }); 2068 2069 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts 2070 if (i < 9) { 2071 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1)); 2072 } 2073 } 2074 2075 QAction *activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab")); 2076 activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab")); 2077 activateLastTab->setEnabled(false); 2078 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab); 2079 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT | Qt::Key_0); 2080 2081 QAction *activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab")); 2082 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab")); 2083 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab")); 2084 activateNextTab->setEnabled(false); 2085 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab); 2086 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys); 2087 2088 QAction *activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab")); 2089 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab")); 2090 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab")); 2091 activatePrevTab->setEnabled(false); 2092 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab); 2093 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys); 2094 2095 // for context menu 2096 QAction *showTarget = actionCollection()->addAction(QStringLiteral("show_target")); 2097 showTarget->setText(i18nc("@action:inmenu", "Show Target")); 2098 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder"))); 2099 showTarget->setEnabled(false); 2100 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget); 2101 2102 QAction *openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab")); 2103 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab")); 2104 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); 2105 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab); 2106 2107 QAction *openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs")); 2108 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs")); 2109 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); 2110 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab); 2111 2112 QAction *openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window")); 2113 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window")); 2114 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); 2115 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow); 2116 2117 QAction *openInSplitViewAction = actionCollection()->addAction(QStringLiteral("open_in_split_view")); 2118 openInSplitViewAction->setText(i18nc("@action:inmenu", "Open in Split View")); 2119 openInSplitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new"))); 2120 connect(openInSplitViewAction, &QAction::triggered, this, [this]() { 2121 openInSplitView(QUrl()); 2122 }); 2123 } 2124 2125 void DolphinMainWindow::setupDockWidgets() 2126 { 2127 const bool lock = GeneralSettings::lockPanels(); 2128 2129 DolphinPlacesModelSingleton::instance().placesModel()->setPanelsLocked(lock); 2130 2131 KDualAction *lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels")); 2132 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels")); 2133 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked"))); 2134 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels")); 2135 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked"))); 2136 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", 2137 "This " 2138 "switches between having panels <emphasis>locked</emphasis> or " 2139 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be " 2140 "dragged to the other side of the window and have a close " 2141 "button.<nl/>Locked panels are embedded more cleanly.")); 2142 lockLayoutAction->setActive(lock); 2143 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState); 2144 2145 // Setup "Information" 2146 DolphinDockWidget *infoDock = new DolphinDockWidget(i18nc("@title:window", "Information")); 2147 infoDock->setLocked(lock); 2148 infoDock->setObjectName(QStringLiteral("infoDock")); 2149 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 2150 2151 #if HAVE_BALOO 2152 InformationPanel *infoPanel = new InformationPanel(infoDock); 2153 infoPanel->setCustomContextMenuActions({lockLayoutAction}); 2154 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl); 2155 infoDock->setWidget(infoPanel); 2156 2157 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoDock, QStringLiteral("show_information_panel")); 2158 2159 addDockWidget(Qt::RightDockWidgetArea, infoDock); 2160 connect(this, &DolphinMainWindow::urlChanged, infoPanel, &InformationPanel::setUrl); 2161 connect(this, &DolphinMainWindow::selectionChanged, infoPanel, &InformationPanel::setSelection); 2162 connect(this, &DolphinMainWindow::requestItemInfo, infoPanel, &InformationPanel::requestDelayedItemInfo); 2163 connect(this, &DolphinMainWindow::fileItemsChanged, infoPanel, &InformationPanel::slotFilesItemChanged); 2164 #endif 2165 2166 // i18n: This is the last paragraph for the "What's This"-texts of all four panels. 2167 const QString panelWhatsThis = xi18nc("@info:whatsthis", 2168 "<para>To show or " 2169 "hide panels like this go to <interface>Menu|Panels</interface> " 2170 "or <interface>View|Panels</interface>.</para>"); 2171 #if HAVE_BALOO 2172 actionCollection() 2173 ->action(QStringLiteral("show_information_panel")) 2174 ->setWhatsThis(xi18nc("@info:whatsthis", 2175 "<para> This toggles the " 2176 "<emphasis>information</emphasis> panel at the right side of the " 2177 "window.</para><para>The panel provides in-depth information " 2178 "about the items your mouse is hovering over or about the selected " 2179 "items. Otherwise it informs you about the currently viewed folder.<nl/>" 2180 "For single items a preview of their contents is provided.</para>")); 2181 #endif 2182 infoDock->setWhatsThis(xi18nc("@info:whatsthis", 2183 "<para>This panel " 2184 "provides in-depth information about the items your mouse is " 2185 "hovering over or about the selected items. Otherwise it informs " 2186 "you about the currently viewed folder.<nl/>For single items a " 2187 "preview of their contents is provided.</para><para>You can configure " 2188 "which and how details are given here by right-clicking.</para>") 2189 + panelWhatsThis); 2190 2191 // Setup "Folders" 2192 DolphinDockWidget *foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders")); 2193 foldersDock->setLocked(lock); 2194 foldersDock->setObjectName(QStringLiteral("foldersDock")); 2195 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 2196 FoldersPanel *foldersPanel = new FoldersPanel(foldersDock); 2197 foldersPanel->setCustomContextMenuActions({lockLayoutAction}); 2198 foldersDock->setWidget(foldersPanel); 2199 2200 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersDock, QStringLiteral("show_folders_panel")); 2201 2202 addDockWidget(Qt::LeftDockWidgetArea, foldersDock); 2203 connect(this, &DolphinMainWindow::urlChanged, foldersPanel, &FoldersPanel::setUrl); 2204 connect(foldersPanel, &FoldersPanel::folderActivated, this, &DolphinMainWindow::changeUrl); 2205 connect(foldersPanel, &FoldersPanel::folderInNewTab, this, &DolphinMainWindow::openNewTab); 2206 connect(foldersPanel, &FoldersPanel::folderInNewActiveTab, this, &DolphinMainWindow::openNewTabAndActivate); 2207 connect(foldersPanel, &FoldersPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage); 2208 2209 actionCollection() 2210 ->action(QStringLiteral("show_folders_panel")) 2211 ->setWhatsThis(xi18nc("@info:whatsthis", 2212 "This toggles the " 2213 "<emphasis>folders</emphasis> panel at the left side of the window." 2214 "<nl/><nl/>It shows the folders of the <emphasis>file system" 2215 "</emphasis> in a <emphasis>tree view</emphasis>.")); 2216 foldersDock->setWhatsThis(xi18nc("@info:whatsthis", 2217 "<para>This panel " 2218 "shows the folders of the <emphasis>file system</emphasis> in a " 2219 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go " 2220 "there. Click the arrow to the left of a folder to see its subfolders. " 2221 "This allows quick switching between any folders.</para>") 2222 + panelWhatsThis); 2223 2224 // Setup "Terminal" 2225 #if HAVE_TERMINAL 2226 if (KAuthorized::authorize(QStringLiteral("shell_access"))) { 2227 DolphinDockWidget *terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal")); 2228 terminalDock->setLocked(lock); 2229 terminalDock->setObjectName(QStringLiteral("terminalDock")); 2230 terminalDock->setContentsMargins(0, 0, 0, 0); 2231 m_terminalPanel = new TerminalPanel(terminalDock); 2232 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction}); 2233 terminalDock->setWidget(m_terminalPanel); 2234 2235 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide); 2236 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged); 2237 connect(terminalDock, &DolphinDockWidget::visibilityChanged, m_terminalPanel, &TerminalPanel::dockVisibilityChanged); 2238 connect(terminalDock, &DolphinDockWidget::visibilityChanged, this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged); 2239 2240 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalDock, QStringLiteral("show_terminal_panel")); 2241 2242 addDockWidget(Qt::BottomDockWidgetArea, terminalDock); 2243 connect(this, &DolphinMainWindow::urlChanged, m_terminalPanel, &TerminalPanel::setUrl); 2244 2245 if (GeneralSettings::version() < 200) { 2246 terminalDock->hide(); 2247 } 2248 2249 actionCollection() 2250 ->action(QStringLiteral("show_terminal_panel")) 2251 ->setWhatsThis(xi18nc("@info:whatsthis", 2252 "<para>This toggles the " 2253 "<emphasis>terminal</emphasis> panel at the bottom of the window." 2254 "<nl/>The location in the terminal will always match the folder " 2255 "view so you can navigate using either.</para><para>The terminal " 2256 "panel is not needed for basic computer usage but can be useful " 2257 "for advanced tasks. To learn more about terminals use the help " 2258 "in a standalone terminal application like Konsole.</para>")); 2259 terminalDock->setWhatsThis(xi18nc("@info:whatsthis", 2260 "<para>This is " 2261 "the <emphasis>terminal</emphasis> panel. It behaves like a " 2262 "normal terminal but will match the location of the folder view " 2263 "so you can navigate using either.</para><para>The terminal panel " 2264 "is not needed for basic computer usage but can be useful for " 2265 "advanced tasks. To learn more about terminals use the help in a " 2266 "standalone terminal application like Konsole.</para>") 2267 + panelWhatsThis); 2268 } 2269 #endif 2270 2271 if (GeneralSettings::version() < 200) { 2272 infoDock->hide(); 2273 foldersDock->hide(); 2274 } 2275 2276 // Setup "Places" 2277 DolphinDockWidget *placesDock = new DolphinDockWidget(i18nc("@title:window", "Places")); 2278 placesDock->setLocked(lock); 2279 placesDock->setObjectName(QStringLiteral("placesDock")); 2280 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); 2281 2282 m_placesPanel = new PlacesPanel(placesDock); 2283 m_placesPanel->setCustomContextMenuActions({lockLayoutAction}); 2284 placesDock->setWidget(m_placesPanel); 2285 2286 createPanelAction(QIcon::fromTheme(QStringLiteral("compass")), Qt::Key_F9, placesDock, QStringLiteral("show_places_panel")); 2287 2288 addDockWidget(Qt::LeftDockWidgetArea, placesDock); 2289 connect(m_placesPanel, &PlacesPanel::placeActivated, this, &DolphinMainWindow::slotPlaceActivated); 2290 connect(m_placesPanel, &PlacesPanel::tabRequested, this, &DolphinMainWindow::openNewTab); 2291 connect(m_placesPanel, &PlacesPanel::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate); 2292 connect(m_placesPanel, &PlacesPanel::newWindowRequested, this, [this](const QUrl &url) { 2293 Dolphin::openNewWindow({url}, this); 2294 }); 2295 connect(m_placesPanel, &PlacesPanel::openInSplitViewRequested, this, &DolphinMainWindow::openInSplitView); 2296 connect(m_placesPanel, &PlacesPanel::errorMessage, this, &DolphinMainWindow::showErrorMessage); 2297 connect(this, &DolphinMainWindow::urlChanged, m_placesPanel, &PlacesPanel::setUrl); 2298 connect(placesDock, &DolphinDockWidget::visibilityChanged, &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged); 2299 connect(this, &DolphinMainWindow::settingsChanged, m_placesPanel, &PlacesPanel::readSettings); 2300 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested, this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested); 2301 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested, this, &DolphinMainWindow::slotStorageTearDownExternallyRequested); 2302 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible()); 2303 2304 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this); 2305 actionShowAllPlaces->setCheckable(true); 2306 actionShowAllPlaces->setDisabled(true); 2307 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", 2308 "This displays " 2309 "all places in the places panel that have been hidden. They will " 2310 "appear semi-transparent unless you uncheck their hide property.")); 2311 2312 connect(actionShowAllPlaces, &QAction::triggered, this, [this](bool checked) { 2313 m_placesPanel->setShowAll(checked); 2314 }); 2315 connect(m_placesPanel, &PlacesPanel::allPlacesShownChanged, actionShowAllPlaces, &QAction::setChecked); 2316 2317 actionCollection() 2318 ->action(QStringLiteral("show_places_panel")) 2319 ->setWhatsThis(xi18nc("@info:whatsthis", 2320 "<para>This toggles the " 2321 "<emphasis>places</emphasis> panel at the left side of the window." 2322 "</para><para>It allows you to go to locations you have " 2323 "bookmarked and to access disk or media attached to the computer " 2324 "or to the network. It also contains sections to find recently " 2325 "saved files or files of a certain type.</para>")); 2326 placesDock->setWhatsThis(xi18nc("@info:whatsthis", 2327 "<para>This is the " 2328 "<emphasis>Places</emphasis> panel. It allows you to go to locations " 2329 "you have bookmarked and to access disk or media attached to the " 2330 "computer or to the network. It also contains sections to find " 2331 "recently saved files or files of a certain type.</para><para>" 2332 "Click on an entry to go there. Click with the right mouse button " 2333 "instead to open any entry in a new tab or new window.</para>" 2334 "<para>New entries can be added by dragging folders onto this panel. " 2335 "Right-click any section or entry to hide it. Right-click an empty " 2336 "space on this panel and select <interface>Show Hidden Places" 2337 "</interface> to display it again.</para>") 2338 + panelWhatsThis); 2339 2340 // Add actions into the "Panels" menu 2341 KActionMenu *panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this); 2342 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu); 2343 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree"))); 2344 panelsMenu->setPopupMode(QToolButton::InstantPopup); 2345 const KActionCollection *ac = actionCollection(); 2346 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel"))); 2347 #if HAVE_BALOO 2348 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel"))); 2349 #endif 2350 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel"))); 2351 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel"))); 2352 panelsMenu->addSeparator(); 2353 panelsMenu->addAction(actionShowAllPlaces); 2354 panelsMenu->addAction(lockLayoutAction); 2355 2356 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces] { 2357 actionShowAllPlaces->setEnabled(DolphinPlacesModelSingleton::instance().placesModel()->hiddenCount()); 2358 }); 2359 } 2360 2361 void DolphinMainWindow::updateFileAndEditActions() 2362 { 2363 const KFileItemList list = m_activeViewContainer->view()->selectedItems(); 2364 const KActionCollection *col = actionCollection(); 2365 KFileItemListProperties capabilitiesSource(list); 2366 2367 QAction *renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile)); 2368 QAction *moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash)); 2369 QAction *deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile)); 2370 QAction *cutAction = col->action(KStandardAction::name(KStandardAction::Cut)); 2371 QAction *duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler 2372 QAction *addToPlacesAction = col->action(QStringLiteral("add_to_places")); 2373 QAction *copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view")); 2374 QAction *moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view")); 2375 QAction *copyLocation = col->action(QString("copy_location")); 2376 2377 if (list.isEmpty()) { 2378 stateChanged(QStringLiteral("has_no_selection")); 2379 2380 // All actions that need a selection to function can be enabled because they should trigger selection mode. 2381 renameAction->setEnabled(true); 2382 moveToTrashAction->setEnabled(true); 2383 deleteAction->setEnabled(true); 2384 cutAction->setEnabled(true); 2385 duplicateAction->setEnabled(true); 2386 addToPlacesAction->setEnabled(true); 2387 copyLocation->setEnabled(true); 2388 // Them triggering selection mode and not directly acting on selected items is signified by adding "…" to their text. 2389 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(true); 2390 2391 } else { 2392 m_actionTextHelper->textsWhenNothingIsSelectedEnabled(false); 2393 stateChanged(QStringLiteral("has_selection")); 2394 2395 QAction *deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler 2396 QAction *showTarget = col->action(QStringLiteral("show_target")); 2397 2398 if (list.length() == 1 && list.first().isDir()) { 2399 addToPlacesAction->setEnabled(true); 2400 } else { 2401 addToPlacesAction->setEnabled(false); 2402 } 2403 2404 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving(); 2405 2406 renameAction->setEnabled(capabilitiesSource.supportsMoving()); 2407 moveToTrashAction->setEnabled(enableMoveToTrash); 2408 deleteAction->setEnabled(capabilitiesSource.supportsDeleting()); 2409 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash); 2410 cutAction->setEnabled(capabilitiesSource.supportsMoving()); 2411 copyLocation->setEnabled(list.length() == 1); 2412 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink()); 2413 duplicateAction->setEnabled(capabilitiesSource.supportsWriting()); 2414 } 2415 2416 if (m_tabWidget->currentTabPage()->splitViewEnabled() && !list.isEmpty()) { 2417 DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); 2418 KFileItem capabilitiesDestination; 2419 2420 if (tabPage->primaryViewActive()) { 2421 capabilitiesDestination = tabPage->secondaryViewContainer()->rootItem(); 2422 } else { 2423 capabilitiesDestination = tabPage->primaryViewContainer()->rootItem(); 2424 } 2425 2426 const auto destUrl = capabilitiesDestination.url(); 2427 const bool allNotTargetOrigin = std::all_of(list.cbegin(), list.cend(), [destUrl](const KFileItem &item) { 2428 return item.url().adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash) != destUrl; 2429 }); 2430 2431 copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable() && allNotTargetOrigin); 2432 moveToOtherViewAction->setEnabled((list.isEmpty() || capabilitiesSource.supportsMoving()) && capabilitiesDestination.isWritable() 2433 && allNotTargetOrigin); 2434 } else { 2435 copyToOtherViewAction->setEnabled(false); 2436 moveToOtherViewAction->setEnabled(false); 2437 } 2438 } 2439 2440 void DolphinMainWindow::updateViewActions() 2441 { 2442 m_actionHandler->updateViewActions(); 2443 2444 QAction *toggleFilterBarAction = actionCollection()->action(QStringLiteral("toggle_filter")); 2445 toggleFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible()); 2446 2447 updateSplitActions(); 2448 } 2449 2450 void DolphinMainWindow::updateGoActions() 2451 { 2452 QAction *goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up)); 2453 const QUrl currentUrl = m_activeViewContainer->url(); 2454 // I think this is one of the best places to firstly be confronted 2455 // with a file system and its hierarchy. Talking about the root 2456 // directory might seem too much here but it is the question that 2457 // naturally arises in this context. 2458 goUpAction->setWhatsThis(xi18nc("@info:whatsthis", 2459 "<para>Go to " 2460 "the folder that contains the currently viewed one.</para>" 2461 "<para>All files and folders are organized in a hierarchical " 2462 "<emphasis>file system</emphasis>. At the top of this hierarchy is " 2463 "a directory that contains all data connected to this computer" 2464 "—the <emphasis>root directory</emphasis>.</para>")); 2465 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl); 2466 } 2467 2468 void DolphinMainWindow::refreshViews() 2469 { 2470 m_tabWidget->refreshViews(); 2471 2472 if (GeneralSettings::modifiedStartupSettings()) { 2473 updateWindowTitle(); 2474 } 2475 2476 updateSplitActions(); 2477 2478 Q_EMIT settingsChanged(); 2479 } 2480 2481 void DolphinMainWindow::clearStatusBar() 2482 { 2483 m_activeViewContainer->statusBar()->resetToDefaultText(); 2484 } 2485 2486 void DolphinMainWindow::connectViewSignals(DolphinViewContainer *container) 2487 { 2488 connect(container, &DolphinViewContainer::showFilterBarChanged, this, &DolphinMainWindow::updateFilterBarAction); 2489 connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged); 2490 slotWriteStateChanged(container->view()->isFolderWritable()); 2491 connect(container, &DolphinViewContainer::searchModeEnabledChanged, this, &DolphinMainWindow::updateSearchAction); 2492 connect(container, &DolphinViewContainer::captionChanged, this, &DolphinMainWindow::updateWindowTitle); 2493 connect(container, &DolphinViewContainer::tabRequested, this, &DolphinMainWindow::openNewTab); 2494 connect(container, &DolphinViewContainer::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate); 2495 2496 const QAction *toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); 2497 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled); 2498 2499 // Make the toggled state of the selection mode actions visually follow the selection mode state of the view. 2500 auto toggleSelectionModeAction = actionCollection()->action(QStringLiteral("toggle_selection_mode")); 2501 toggleSelectionModeAction->setChecked(m_activeViewContainer->isSelectionModeEnabled()); 2502 connect(m_activeViewContainer, &DolphinViewContainer::selectionModeChanged, toggleSelectionModeAction, &QAction::setChecked); 2503 2504 const DolphinView *view = container->view(); 2505 connect(view, &DolphinView::selectionChanged, this, &DolphinMainWindow::slotSelectionChanged); 2506 connect(view, &DolphinView::requestItemInfo, this, &DolphinMainWindow::requestItemInfo); 2507 connect(view, &DolphinView::fileItemsChanged, this, &DolphinMainWindow::fileItemsChanged); 2508 connect(view, &DolphinView::tabRequested, this, &DolphinMainWindow::openNewTab); 2509 connect(view, &DolphinView::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate); 2510 connect(view, &DolphinView::windowRequested, this, &DolphinMainWindow::openNewWindow); 2511 connect(view, &DolphinView::requestContextMenu, this, &DolphinMainWindow::openContextMenu); 2512 connect(view, &DolphinView::directoryLoadingStarted, this, &DolphinMainWindow::enableStopAction); 2513 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::disableStopAction); 2514 connect(view, &DolphinView::directoryLoadingCompleted, this, &DolphinMainWindow::slotDirectoryLoadingCompleted); 2515 connect(view, &DolphinView::goBackRequested, this, &DolphinMainWindow::goBack); 2516 connect(view, &DolphinView::goForwardRequested, this, &DolphinMainWindow::goForward); 2517 connect(view, &DolphinView::urlActivated, this, &DolphinMainWindow::handleUrl); 2518 connect(view, &DolphinView::goUpRequested, this, &DolphinMainWindow::goUp); 2519 2520 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::urlChanged, this, &DolphinMainWindow::changeUrl); 2521 connect(container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged, this, &DolphinMainWindow::updateHistory); 2522 2523 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators"))); 2524 const KUrlNavigator *navigator = 2525 m_tabWidget->currentTabPage()->primaryViewActive() ? navigators->primaryUrlNavigator() : navigators->secondaryUrlNavigator(); 2526 2527 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location")); 2528 editableLocactionAction->setChecked(navigator->isUrlEditable()); 2529 connect(navigator, &KUrlNavigator::editableStateChanged, this, &DolphinMainWindow::slotEditableStateChanged); 2530 connect(navigator, &KUrlNavigator::tabRequested, this, &DolphinMainWindow::openNewTab); 2531 connect(navigator, &KUrlNavigator::activeTabRequested, this, &DolphinMainWindow::openNewTabAndActivate); 2532 connect(navigator, &KUrlNavigator::newWindowRequested, this, &DolphinMainWindow::openNewWindow); 2533 } 2534 2535 void DolphinMainWindow::updateSplitActions() 2536 { 2537 QAction *popoutSplitAction = actionCollection()->action(QStringLiteral("popout_split_view")); 2538 2539 auto setActionPopupMode = [this](KActionMenu *action, QToolButton::ToolButtonPopupMode popupMode) { 2540 action->setPopupMode(popupMode); 2541 if (auto *buttonForAction = qobject_cast<QToolButton *>(toolBar()->widgetForAction(action))) { 2542 buttonForAction->setPopupMode(popupMode); 2543 } 2544 }; 2545 2546 const DolphinTabPage *tabPage = m_tabWidget->currentTabPage(); 2547 if (tabPage->splitViewEnabled()) { 2548 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) { 2549 m_splitViewAction->setText(i18nc("@action:intoolbar Close left view", "Close")); 2550 m_splitViewAction->setToolTip(i18nc("@info", "Close left view")); 2551 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close"))); 2552 popoutSplitAction->setText(i18nc("@action:intoolbar Move left split view to a new window", "Pop out")); 2553 popoutSplitAction->setToolTip(i18nc("@info", "Move left split view to a new window")); 2554 } else { 2555 m_splitViewAction->setText(i18nc("@action:intoolbar Close right view", "Close")); 2556 m_splitViewAction->setToolTip(i18nc("@info", "Close right view")); 2557 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close"))); 2558 popoutSplitAction->setText(i18nc("@action:intoolbar Move right split view to a new window", "Pop out")); 2559 popoutSplitAction->setToolTip(i18nc("@info", "Move right split view to a new window")); 2560 } 2561 popoutSplitAction->setEnabled(true); 2562 if (!m_splitViewAction->menu()) { 2563 setActionPopupMode(m_splitViewAction, QToolButton::MenuButtonPopup); 2564 m_splitViewAction->setMenu(new QMenu); 2565 m_splitViewAction->addAction(popoutSplitAction); 2566 } 2567 } else { 2568 m_splitViewAction->setText(i18nc("@action:intoolbar Split view", "Split")); 2569 m_splitViewAction->setToolTip(i18nc("@info", "Split view")); 2570 m_splitViewAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new"))); 2571 popoutSplitAction->setText(i18nc("@action:intoolbar Move active split view to a new window", "Pop out")); 2572 popoutSplitAction->setEnabled(false); 2573 if (m_splitViewAction->menu()) { 2574 m_splitViewAction->removeAction(popoutSplitAction); 2575 m_splitViewAction->menu()->deleteLater(); 2576 m_splitViewAction->setMenu(nullptr); 2577 setActionPopupMode(m_splitViewAction, QToolButton::DelayedPopup); 2578 } 2579 } 2580 2581 // Update state from toolbar action 2582 m_splitViewMenuAction->setText(m_splitViewAction->text()); 2583 m_splitViewMenuAction->setToolTip(m_splitViewAction->toolTip()); 2584 m_splitViewMenuAction->setIcon(m_splitViewAction->icon()); 2585 } 2586 2587 void DolphinMainWindow::updateAllowedToolbarAreas() 2588 { 2589 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators"))); 2590 if (toolBar()->actions().contains(navigators)) { 2591 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea); 2592 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea || toolBarArea(toolBar()) == Qt::RightToolBarArea) { 2593 addToolBar(Qt::TopToolBarArea, toolBar()); 2594 } 2595 } else { 2596 toolBar()->setAllowedAreas(Qt::AllToolBarAreas); 2597 } 2598 } 2599 2600 bool DolphinMainWindow::isKompareInstalled() const 2601 { 2602 static bool initialized = false; 2603 static bool installed = false; 2604 if (!initialized) { 2605 // TODO: maybe replace this approach later by using a menu 2606 // plugin like kdiff3plugin.cpp 2607 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty(); 2608 initialized = true; 2609 } 2610 return installed; 2611 } 2612 2613 void DolphinMainWindow::createPanelAction(const QIcon &icon, const QKeySequence &shortcut, QDockWidget *dockWidget, const QString &actionName) 2614 { 2615 auto dockAction = dockWidget->toggleViewAction(); 2616 dockAction->setIcon(icon); 2617 dockAction->setEnabled(true); 2618 2619 QAction *panelAction = actionCollection()->addAction(actionName, dockAction); 2620 actionCollection()->setDefaultShortcut(panelAction, shortcut); 2621 2622 connect(panelAction, &QAction::toggled, dockWidget, &QWidget::setVisible); 2623 } 2624 // clang-format off 2625 void DolphinMainWindow::setupWhatsThis() 2626 { 2627 // main widgets 2628 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the " 2629 "<emphasis>Menubar</emphasis>. It provides access to commands and " 2630 "configuration options. Left-click on any of the menus on this " 2631 "bar to see its contents.</para><para>The Menubar can be hidden " 2632 "by unchecking <interface>Settings|Show Menubar</interface>. Then " 2633 "most of its contents become available through a <interface>Menu" 2634 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>")); 2635 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the " 2636 "<emphasis>Toolbar</emphasis>. It allows quick access to " 2637 "frequently used actions.</para><para>It is highly customizable. " 2638 "All items you see in the <interface>Menu</interface> or " 2639 "in the <interface>Menubar</interface> can be placed on the " 2640 "Toolbar. Just right-click on it and select <interface>Configure " 2641 "Toolbars…</interface> or find this action within the <interface>" 2642 "menu</interface>." 2643 "</para><para>The location of the bar and the style of its " 2644 "buttons can also be changed in the right-click menu. Right-click " 2645 "a button if you want to show or hide its text.</para>")); 2646 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view", 2647 "<para>Here you can see the <emphasis>folders</emphasis> and " 2648 "<emphasis>files</emphasis> that are at the location described in " 2649 "the <interface>Location Bar</interface> above. This area is the " 2650 "central part of this application where you navigate to the files " 2651 "you want to use.</para><para>For an elaborate and general " 2652 "introduction to this application <link " 2653 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>" 2654 "click here</link>. This will open an introductory article from " 2655 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief " 2656 "explanations of all the features of this <emphasis>view</emphasis> " 2657 "<link url='help:/dolphin/dolphin-view.html'>click here</link> " 2658 "instead. This will open a page from the <emphasis>Handbook" 2659 "</emphasis> that covers the basics.</para>")); 2660 2661 // Settings menu 2662 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings)) 2663 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window " 2664 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>" 2665 "There you can set up key combinations to trigger an action when " 2666 "they are pressed simultaneously. All commands in this application can " 2667 "be triggered this way.</para>")); 2668 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars)) 2669 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which " 2670 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>" 2671 "<para>All items you see in the <interface>Menu</interface> can also be placed on the Toolbar.</para>")); 2672 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences)) 2673 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can " 2674 "change a multitude of settings for this application. For an explanation " 2675 "of the various settings go to the chapter <emphasis>Configuring Dolphin" 2676 "</emphasis> in <interface>Help|Dolphin Handbook</interface>.")); 2677 2678 // Help menu 2679 2680 auto setStandardActionWhatsThis = [this](KStandardAction::StandardAction actionId, 2681 const QString &whatsThis) { 2682 // Check for the existence of an action since it can be restricted through the Kiosk system 2683 if (auto *action = actionCollection()->action(KStandardAction::name(actionId))) { 2684 action->setWhatsThis(whatsThis); 2685 } 2686 }; 2687 2688 // i18n: If the external link isn't available in your language it might make 2689 // sense to state the external link's language in brackets to not 2690 // frustrate the user. If there are multiple languages that the user might 2691 // know with a reasonable chance you might want to have 2 external links. 2692 // The same might be true for any external link you translate. 2693 setStandardActionWhatsThis(KStandardAction::HelpContents, xi18nc("@info:whatsthis handbook", "<para>This opens the Handbook for this application. It provides explanations for every part of <emphasis>Dolphin</emphasis>.</para><para>If you want more elaborate introductions to the different features of <emphasis>Dolphin</emphasis> <link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. It will open the dedicated page in the KDE UserBase Wiki.</para>")); 2694 // (The i18n call should be completely in the line following the i18n: comment without any line breaks within the i18n call or the comment might not be correctly extracted. See: https://commits.kde.org/kxmlgui/a31135046e1b3335b5d7bbbe6aa9a883ce3284c1 ) 2695 2696 setStandardActionWhatsThis(KStandardAction::WhatsThis, 2697 xi18nc("@info:whatsthis whatsthis button", 2698 "<para>This is the button that invokes the help feature you are " 2699 "using right now! Click it, then click any component of this " 2700 "application to ask \"What's this?\" about it. The mouse cursor " 2701 "will change appearance if no help is available for a spot.</para>" 2702 "<para>There are two other ways to get help: " 2703 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and " 2704 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE " 2705 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is " 2706 "missing in most other windows so don't get too used to this.</para>")); 2707 2708 setStandardActionWhatsThis(KStandardAction::ReportBug, 2709 xi18nc("@info:whatsthis","<para>This opens a " 2710 "window that will guide you through reporting errors or flaws " 2711 "in this application or in other KDE software.</para>" 2712 "<para>High-quality bug reports are much appreciated. To learn " 2713 "how to make your bug report as effective as possible " 2714 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>" 2715 "click here</link>.</para>")); 2716 2717 setStandardActionWhatsThis(KStandardAction::Donate, 2718 xi18nc("@info:whatsthis", "<para>This opens a " 2719 "<emphasis>web page</emphasis> where you can donate to " 2720 "support the continued work on this application and many " 2721 "other projects by the <emphasis>KDE</emphasis> community.</para>" 2722 "<para>Donating is the easiest and fastest way to efficiently " 2723 "support KDE and its projects. KDE projects are available for " 2724 "free therefore your donation is needed to cover things that " 2725 "require money like servers, contributor meetings, etc.</para>" 2726 "<para><emphasis>KDE e.V.</emphasis> is the non-profit " 2727 "organization behind the KDE community.</para>")); 2728 2729 setStandardActionWhatsThis(KStandardAction::SwitchApplicationLanguage, 2730 xi18nc("@info:whatsthis", 2731 "With this you can change the language this application uses." 2732 "<nl/>You can even set secondary languages which will be used " 2733 "if texts are not available in your preferred language.")); 2734 2735 setStandardActionWhatsThis(KStandardAction::AboutApp, 2736 xi18nc("@info:whatsthis","This opens a " 2737 "window that informs you about the version, license, " 2738 "used libraries and maintainers of this application.")); 2739 2740 setStandardActionWhatsThis(KStandardAction::AboutKDE, 2741 xi18nc("@info:whatsthis","This opens a " 2742 "window with information about <emphasis>KDE</emphasis>. " 2743 "The KDE community are the people behind this free software." 2744 "<nl/>If you like using this application but don't know " 2745 "about KDE or want to see a cute dragon have a look!")); 2746 } 2747 // clang-format on 2748 2749 bool DolphinMainWindow::addHamburgerMenuToToolbar() 2750 { 2751 QDomDocument domDocument = KXMLGUIClient::domDocument(); 2752 if (domDocument.isNull()) { 2753 return false; 2754 } 2755 QDomNode toolbar = domDocument.elementsByTagName(QStringLiteral("ToolBar")).at(0); 2756 if (toolbar.isNull()) { 2757 return false; 2758 } 2759 2760 QDomElement hamburgerMenuElement = domDocument.createElement(QStringLiteral("Action")); 2761 hamburgerMenuElement.setAttribute(QStringLiteral("name"), QStringLiteral("hamburger_menu")); 2762 toolbar.appendChild(hamburgerMenuElement); 2763 2764 KXMLGUIFactory::saveConfigFile(domDocument, xmlFile()); 2765 reloadXML(); 2766 createGUI(); 2767 return true; 2768 // Make sure to also remove the <KXMLGUIFactory> and <QDomDocument> include 2769 // whenever this method is removed (maybe in the year ~2026). 2770 } 2771 2772 // Set a sane initial window size 2773 QSize DolphinMainWindow::sizeHint() const 2774 { 2775 return KXmlGuiWindow::sizeHint().expandedTo(QSize(760, 550)); 2776 } 2777 2778 void DolphinMainWindow::saveNewToolbarConfig() 2779 { 2780 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first 2781 // because the rest of this method decides things 2782 // based on the new config. 2783 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>(actionCollection()->action(QStringLiteral("url_navigators"))); 2784 if (!toolBar()->actions().contains(navigators)) { 2785 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators); 2786 } 2787 updateAllowedToolbarAreas(); 2788 (static_cast<KHamburgerMenu *>(actionCollection()->action(KStandardAction::name(KStandardAction::HamburgerMenu))))->hideActionsOf(toolBar()); 2789 } 2790 2791 void DolphinMainWindow::focusTerminalPanel() 2792 { 2793 if (m_terminalPanel->isVisible()) { 2794 if (m_terminalPanel->terminalHasFocus()) { 2795 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason); 2796 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel")); 2797 } else { 2798 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason); 2799 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel")); 2800 } 2801 } else { 2802 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger(); 2803 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel")); 2804 } 2805 } 2806 2807 DolphinMainWindow::UndoUiInterface::UndoUiInterface() 2808 : KIO::FileUndoManager::UiInterface() 2809 { 2810 } 2811 2812 DolphinMainWindow::UndoUiInterface::~UndoUiInterface() 2813 { 2814 } 2815 2816 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job *job) 2817 { 2818 DolphinMainWindow *mainWin = qobject_cast<DolphinMainWindow *>(parentWidget()); 2819 if (mainWin) { 2820 DolphinViewContainer *container = mainWin->activeViewContainer(); 2821 container->showMessage(job->errorString(), DolphinViewContainer::Error); 2822 } else { 2823 KIO::FileUndoManager::UiInterface::jobError(job); 2824 } 2825 } 2826 2827 bool DolphinMainWindow::isUrlOpen(const QString &url) 2828 { 2829 return m_tabWidget->isUrlOpen(QUrl::fromUserInput(url)); 2830 } 2831 2832 bool DolphinMainWindow::isItemVisibleInAnyView(const QString &urlOfItem) 2833 { 2834 return m_tabWidget->isItemVisibleInAnyView(QUrl::fromUserInput(urlOfItem)); 2835 } 2836 2837 #include "moc_dolphinmainwindow.cpp"