2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0-or-later
9 #include "dolphinmainwindow.h"
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinviewcontainer.h"
20 #include "dolphintabpage.h"
21 #include "middleclickactioneventfilter.h"
22 #include "panels/folders/folderspanel.h"
23 #include "panels/places/placesitemmodel.h"
24 #include "panels/places/placespanel.h"
25 #include "panels/information/informationpanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KNS3/KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
55 #include <KStandardAction>
56 #include <KStartupInfo>
58 #include <KToggleAction>
60 #include <KToolBarPopupAction>
61 #include <KToolInvocation>
62 #include <KUrlComboBox>
63 #include <KUrlNavigator>
64 #include <KWindowSystem>
66 #include <QApplication>
68 #include <QCloseEvent>
69 #include <QDesktopServices>
75 #include <QPushButton>
77 #include <QStandardPaths>
79 #include <QToolButton>
80 #include <QWhatsThisClickedEvent>
83 // Used for GeneralSettings::version() to determine whether
84 // an updated version of Dolphin is running.
85 const int CurrentDolphinVersion
= 200;
86 // The maximum number of entries in the back/forward popup menu
87 const int MaxNumberOfNavigationentries
= 12;
88 // The maximum number of "Activate Tab" shortcuts
89 const int MaxActivateTabShortcuts
= 9;
92 DolphinMainWindow::DolphinMainWindow() :
93 KXmlGuiWindow(nullptr),
94 m_newFileMenu(nullptr),
97 m_activeViewContainer(nullptr),
98 m_actionHandler(nullptr),
99 m_remoteEncoding(nullptr),
101 m_bookmarkHandler(nullptr),
102 m_controlButton(nullptr),
103 m_updateToolBarTimer(nullptr),
104 m_lastHandleUrlOpenJob(nullptr),
105 m_terminalPanel(nullptr),
106 m_placesPanel(nullptr),
107 m_tearDownFromPlacesRequested(false),
108 m_backAction(nullptr),
109 m_forwardAction(nullptr)
111 Q_INIT_RESOURCE(dolphin
);
113 new MainWindowAdaptor(this);
116 setWindowFlags(Qt::WindowContextHelpButtonHint
);
118 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
119 setObjectName(QStringLiteral("Dolphin#"));
121 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
122 this, &DolphinMainWindow::showErrorMessage
);
124 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
125 undoManager
->setUiInterface(new UndoUiInterface());
127 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
128 this, &DolphinMainWindow::slotUndoAvailable
);
129 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
130 this, &DolphinMainWindow::slotUndoTextChanged
);
131 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
132 this, &DolphinMainWindow::clearStatusBar
);
133 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
134 this, &DolphinMainWindow::showCommand
);
136 GeneralSettings
* generalSettings
= GeneralSettings::self();
137 const bool firstRun
= (generalSettings
->version() < 200);
139 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
142 setAcceptDrops(true);
144 m_tabWidget
= new DolphinTabWidget(this);
145 m_tabWidget
->setObjectName("tabWidget");
146 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
147 this, &DolphinMainWindow::activeViewChanged
);
148 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
149 this, &DolphinMainWindow::tabCountChanged
);
150 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
151 this, &DolphinMainWindow::updateWindowTitle
);
152 setCentralWidget(m_tabWidget
);
156 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
157 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
158 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
160 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
161 connect(this, &DolphinMainWindow::urlChanged
,
162 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
166 setupGUI(Keys
| Save
| Create
| ToolBar
);
167 stateChanged(QStringLiteral("new_file"));
169 QClipboard
* clipboard
= QApplication::clipboard();
170 connect(clipboard
, &QClipboard::dataChanged
,
171 this, &DolphinMainWindow::updatePasteAction
);
173 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
174 showFilterBarAction
->setChecked(generalSettings
->filterBar());
177 menuBar()->setVisible(false);
178 // Assure a proper default size if Dolphin runs the first time
182 const bool showMenu
= !menuBar()->isHidden();
183 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
184 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
186 createControlButton();
189 // enable middle-click on back/forward/up to open in a new tab
190 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
191 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
192 toolBar()->installEventFilter(middleClickEventFilter
);
196 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
198 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
201 DolphinMainWindow::~DolphinMainWindow()
205 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
207 QVector
<DolphinViewContainer
*> viewContainers
;
208 viewContainers
.reserve(m_tabWidget
->count());
209 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
210 viewContainers
<< m_tabWidget
->tabPageAt(i
)->activeViewContainer();
212 return viewContainers
;
215 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
217 m_tabWidget
->openDirectories(dirs
, splitView
);
220 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
222 openDirectories(QUrl::fromStringList(dirs
), splitView
);
225 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
227 m_tabWidget
->openFiles(files
, splitView
);
230 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
232 openFiles(QUrl::fromStringList(files
), splitView
);
235 void DolphinMainWindow::activateWindow()
237 window()->setAttribute(Qt::WA_NativeWindow
, true);
238 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
239 KWindowSystem::activateWindow(window()->effectiveWinId());
242 void DolphinMainWindow::showCommand(CommandType command
)
244 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
246 case KIO::FileUndoManager::Copy
:
247 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
249 case KIO::FileUndoManager::Move
:
250 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
252 case KIO::FileUndoManager::Link
:
253 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
255 case KIO::FileUndoManager::Trash
:
256 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
258 case KIO::FileUndoManager::Rename
:
259 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
262 case KIO::FileUndoManager::Mkdir
:
263 statusBar
->setText(i18nc("@info:status", "Created folder."));
271 void DolphinMainWindow::pasteIntoFolder()
273 m_activeViewContainer
->view()->pasteIntoFolder();
276 void DolphinMainWindow::changeUrl(const QUrl
&url
)
278 if (!KProtocolManager::supportsListing(url
)) {
279 // The URL navigator only checks for validity, not
280 // if the URL can be listed. An error message is
281 // shown due to DolphinViewContainer::restoreView().
285 m_activeViewContainer
->setUrl(url
);
286 updateFileAndEditActions();
291 emit
urlChanged(url
);
294 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
296 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
297 m_placesPanel
->proceedWithTearDown();
298 m_tearDownFromPlacesRequested
= false;
301 m_activeViewContainer
->setAutoGrabFocus(false);
303 m_activeViewContainer
->setAutoGrabFocus(true);
306 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
308 KToggleAction
* editableLocationAction
=
309 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
310 editableLocationAction
->setChecked(editable
);
313 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
315 updateFileAndEditActions();
317 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
319 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
320 if (selectedUrlsCount
== 2) {
321 compareFilesAction
->setEnabled(isKompareInstalled());
323 compareFilesAction
->setEnabled(false);
326 emit
selectionChanged(selection
);
329 void DolphinMainWindow::updateHistory()
331 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
332 const int index
= urlNavigator
->historyIndex();
334 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
336 backAction
->setToolTip(i18nc("@info", "Go back"));
337 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
338 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
341 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
343 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
344 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
345 "This undoes a <interface>Go|Back</interface> action."));
346 forwardAction
->setEnabled(index
> 0);
350 void DolphinMainWindow::updateFilterBarAction(bool show
)
352 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
353 showFilterBarAction
->setChecked(show
);
356 void DolphinMainWindow::openNewMainWindow()
358 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
361 void DolphinMainWindow::openNewActivatedTab()
363 m_tabWidget
->openNewActivatedTab();
366 void DolphinMainWindow::addToPlaces()
371 // If nothing is selected, act on the current dir
372 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
373 url
= m_activeViewContainer
->url();
374 name
= m_activeViewContainer
->placesText();
376 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
377 url
= dirToAdd
.url();
378 name
= dirToAdd
.name();
381 PlacesItemModel model
;
383 if (m_activeViewContainer
->isSearchModeEnabled()) {
384 icon
= QStringLiteral("folder-saved-search-symbolic");
386 icon
= KIO::iconNameForUrl(url
);
388 model
.createPlacesItem(name
, url
, icon
);
392 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
394 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
397 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
399 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
402 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
404 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
407 void DolphinMainWindow::openInNewTab()
409 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
410 bool tabCreated
= false;
412 foreach (const KFileItem
& item
, list
) {
413 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
414 if (!url
.isEmpty()) {
415 openNewTabAfterCurrentTab(url
);
420 // if no new tab has been created from the selection
421 // open the current directory in a new tab
423 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
427 void DolphinMainWindow::openInNewWindow()
431 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
432 if (list
.isEmpty()) {
433 newWindowUrl
= m_activeViewContainer
->url();
434 } else if (list
.count() == 1) {
435 const KFileItem
& item
= list
.first();
436 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
439 if (!newWindowUrl
.isEmpty()) {
440 Dolphin::openNewWindow({newWindowUrl
}, this);
444 void DolphinMainWindow::showTarget()
446 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
447 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
448 auto linkDestination
= link
.linkDest();
449 if (QFileInfo(linkDestination
).isRelative()) {
450 linkDestination
= linkLocationDir
.filePath(linkDestination
);
452 if (QFileInfo::exists(linkDestination
)) {
453 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
455 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
456 DolphinViewContainer::Warning
);
460 void DolphinMainWindow::showEvent(QShowEvent
* event
)
462 KXmlGuiWindow::showEvent(event
);
464 if (!event
->spontaneous()) {
465 m_activeViewContainer
->view()->setFocus();
469 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
471 // Find out if Dolphin is closed directly by the user or
472 // by the session manager because the session is closed
473 bool closedByUser
= true;
474 if (qApp
->isSavingSession()) {
475 closedByUser
= false;
478 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
479 // Ask the user if he really wants to quit and close all tabs.
480 // Open a confirmation dialog with 3 buttons:
481 // QDialogButtonBox::Yes -> Quit
482 // QDialogButtonBox::No -> Close only the current tab
483 // QDialogButtonBox::Cancel -> do nothing
484 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
485 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
486 dialog
->setModal(true);
487 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
488 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
489 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
490 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
491 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
493 bool doNotAskAgainCheckboxResult
= false;
495 const auto result
= KMessageBox::createKMessageBox(dialog
,
497 QMessageBox::Warning
,
498 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
500 i18n("Do not ask again"),
501 &doNotAskAgainCheckboxResult
,
502 KMessageBox::Notify
);
504 if (doNotAskAgainCheckboxResult
) {
505 GeneralSettings::setConfirmClosingMultipleTabs(false);
509 case QDialogButtonBox::Yes
:
512 case QDialogButtonBox::No
:
513 // Close only the current tab
514 m_tabWidget
->closeTab();
522 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
523 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
524 // Open a confirmation dialog with 3 buttons:
525 // QDialogButtonBox::Yes -> Quit
526 // QDialogButtonBox::No -> Show Terminal Panel
527 // QDialogButtonBox::Cancel -> do nothing
528 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
529 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
530 dialog
->setModal(true);
531 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
532 if (!m_terminalPanel
->isVisible()) {
533 standardButtons
|= QDialogButtonBox::No
;
535 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
536 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
537 if (!m_terminalPanel
->isVisible()) {
539 buttons
->button(QDialogButtonBox::No
),
540 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
542 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
544 bool doNotAskAgainCheckboxResult
= false;
546 const auto result
= KMessageBox::createKMessageBox(
549 QMessageBox::Warning
,
550 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
552 i18n("Do not ask again"),
553 &doNotAskAgainCheckboxResult
,
554 KMessageBox::Dangerous
);
556 if (doNotAskAgainCheckboxResult
) {
557 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
561 case QDialogButtonBox::Yes
:
564 case QDialogButtonBox::No
:
565 actionCollection()->action("show_terminal_panel")->trigger();
566 // Do not quit, ignore quit event
574 if (GeneralSettings::rememberOpenedTabs()) {
575 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
576 KConfig
*config
= KConfigGui::sessionConfig();
577 saveGlobalProperties(config
);
578 savePropertiesInternal(config
, 1);
582 GeneralSettings::setVersion(CurrentDolphinVersion
);
583 GeneralSettings::self()->save();
585 KXmlGuiWindow::closeEvent(event
);
588 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
590 m_tabWidget
->saveProperties(group
);
593 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
595 m_tabWidget
->readProperties(group
);
598 void DolphinMainWindow::updateNewMenu()
600 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
601 m_newFileMenu
->checkUpToDate();
602 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
605 void DolphinMainWindow::createDirectory()
607 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
608 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
609 m_newFileMenu
->createDirectory();
612 void DolphinMainWindow::quit()
617 void DolphinMainWindow::showErrorMessage(const QString
& message
)
619 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
622 void DolphinMainWindow::slotUndoAvailable(bool available
)
624 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
626 undoAction
->setEnabled(available
);
630 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
632 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
634 undoAction
->setText(text
);
638 void DolphinMainWindow::undo()
641 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
642 KIO::FileUndoManager::self()->undo();
645 void DolphinMainWindow::cut()
647 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
650 void DolphinMainWindow::copy()
652 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
655 void DolphinMainWindow::paste()
657 m_activeViewContainer
->view()->paste();
660 void DolphinMainWindow::find()
662 m_activeViewContainer
->setSearchModeEnabled(true);
665 void DolphinMainWindow::updateSearchAction()
667 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
668 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
671 void DolphinMainWindow::updatePasteAction()
673 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
674 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
675 pasteAction
->setEnabled(pasteInfo
.first
);
676 pasteAction
->setText(pasteInfo
.second
);
679 void DolphinMainWindow::slotDirectoryLoadingCompleted()
684 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
686 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
688 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
690 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
692 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
697 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
699 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
701 m_backAction
->menu()->clear();
702 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
703 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
705 m_backAction
->menu()->addAction(action
);
709 void DolphinMainWindow::slotGoBack(QAction
* action
)
711 int gotoIndex
= action
->data().value
<int>();
712 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
713 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
718 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
721 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
722 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
726 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
728 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
730 m_forwardAction
->menu()->clear();
731 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
732 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
734 m_forwardAction
->menu()->addAction(action
);
738 void DolphinMainWindow::slotGoForward(QAction
* action
)
740 int gotoIndex
= action
->data().value
<int>();
741 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
742 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
747 void DolphinMainWindow::selectAll()
751 // if the URL navigator is editable and focused, select the whole
752 // URL instead of all items of the view
754 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
755 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
756 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
757 lineEdit
->hasFocus();
759 lineEdit
->selectAll();
761 m_activeViewContainer
->view()->selectAll();
765 void DolphinMainWindow::invertSelection()
768 m_activeViewContainer
->view()->invertSelection();
771 void DolphinMainWindow::toggleSplitView()
773 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
774 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
779 void DolphinMainWindow::toggleSplitStash()
781 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
782 tabPage
->setSplitViewEnabled(false);
783 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
786 void DolphinMainWindow::reloadView()
789 m_activeViewContainer
->reload();
790 m_activeViewContainer
->statusBar()->updateSpaceInfo();
793 void DolphinMainWindow::stopLoading()
795 m_activeViewContainer
->view()->stopLoading();
798 void DolphinMainWindow::enableStopAction()
800 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
803 void DolphinMainWindow::disableStopAction()
805 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
808 void DolphinMainWindow::showFilterBar()
810 m_activeViewContainer
->setFilterBarVisible(true);
813 void DolphinMainWindow::toggleEditLocation()
817 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
818 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
819 urlNavigator
->setUrlEditable(action
->isChecked());
822 void DolphinMainWindow::replaceLocation()
824 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
825 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
827 // If the text field currently has focus and everything is selected,
828 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
829 if (navigator
->isUrlEditable()
830 && lineEdit
->hasFocus()
831 && lineEdit
->selectedText() == lineEdit
->text() ) {
832 navigator
->setUrlEditable(false);
834 navigator
->setUrlEditable(true);
835 navigator
->setFocus();
836 lineEdit
->selectAll();
840 void DolphinMainWindow::togglePanelLockState()
842 const bool newLockState
= !GeneralSettings::lockPanels();
843 foreach (QObject
* child
, children()) {
844 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
846 dock
->setLocked(newLockState
);
850 GeneralSettings::setLockPanels(newLockState
);
853 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
855 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
856 m_activeViewContainer
->view()->setFocus();
860 void DolphinMainWindow::goBack()
862 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
863 urlNavigator
->goBack();
865 if (urlNavigator
->locationState().isEmpty()) {
866 // An empty location state indicates a redirection URL,
867 // which must be skipped too
868 urlNavigator
->goBack();
872 void DolphinMainWindow::goForward()
874 m_activeViewContainer
->urlNavigator()->goForward();
877 void DolphinMainWindow::goUp()
879 m_activeViewContainer
->urlNavigator()->goUp();
882 void DolphinMainWindow::goHome()
884 m_activeViewContainer
->urlNavigator()->goHome();
887 void DolphinMainWindow::goBackInNewTab()
889 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
890 const int index
= urlNavigator
->historyIndex() + 1;
891 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
894 void DolphinMainWindow::goForwardInNewTab()
896 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
897 const int index
= urlNavigator
->historyIndex() - 1;
898 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
901 void DolphinMainWindow::goUpInNewTab()
903 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
904 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
907 void DolphinMainWindow::goHomeInNewTab()
909 openNewTabAfterCurrentTab(Dolphin::homeUrl());
912 void DolphinMainWindow::compareFiles()
914 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
915 if (items
.count() != 2) {
916 // The action is disabled in this case, but it could have been triggered
917 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
921 QUrl urlA
= items
.at(0).url();
922 QUrl urlB
= items
.at(1).url();
924 QString
command(QStringLiteral("kompare -c \""));
925 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
926 command
.append("\" \"");
927 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
928 command
.append('\"');
930 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
931 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
935 void DolphinMainWindow::toggleShowMenuBar()
937 const bool visible
= menuBar()->isVisible();
938 menuBar()->setVisible(!visible
);
940 createControlButton();
942 deleteControlButton();
946 QString
DolphinMainWindow::activeContainerLocalPath()
948 KIO::StatJob
* statJob
= KIO::mostLocalUrl(m_activeViewContainer
->url());
949 KJobWidgets::setWindow(statJob
, this);
951 QUrl url
= statJob
->mostLocalUrl();
952 if (url
.isLocalFile()) {
953 return url
.toLocalFile();
955 return QDir::homePath();
958 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
960 m_searchTools
.clear();
961 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
962 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
964 QList
<QAction
*> actions
= m_searchTools
.actions();
965 if (actions
.isEmpty()) {
968 QAction
* action
= actions
.first();
969 if (action
->isSeparator()) {
975 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
977 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
978 if (!openPreferredSearchTool
) {
981 QPointer
<QAction
> tool
= preferredSearchTool();
983 openPreferredSearchTool
->setVisible(true);
984 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
985 openPreferredSearchTool
->setIcon(tool
->icon());
987 openPreferredSearchTool
->setVisible(false);
988 // still visible in Shortcuts configuration window
989 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
990 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
994 void DolphinMainWindow::openPreferredSearchTool()
996 QPointer
<QAction
> tool
= preferredSearchTool();
1002 void DolphinMainWindow::openTerminal()
1004 KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath());
1007 void DolphinMainWindow::editSettings()
1009 if (!m_settingsDialog
) {
1010 DolphinViewContainer
* container
= activeViewContainer();
1011 container
->view()->writeSettings();
1013 const QUrl url
= container
->url();
1014 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1015 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1016 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1017 settingsDialog
->show();
1018 m_settingsDialog
= settingsDialog
;
1020 m_settingsDialog
.data()->raise();
1024 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1026 delete m_lastHandleUrlOpenJob
;
1027 m_lastHandleUrlOpenJob
= nullptr;
1029 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1030 activeViewContainer()->setUrl(url
);
1032 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1033 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1034 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1036 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1037 [this, url
](const QString
&mimetype
) {
1038 if (mimetype
== QLatin1String("inode/directory")) {
1039 // If it's a dir, we'll take it from here
1040 m_lastHandleUrlOpenJob
->kill();
1041 m_lastHandleUrlOpenJob
= nullptr;
1042 activeViewContainer()->setUrl(url
);
1046 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1047 m_lastHandleUrlOpenJob
= nullptr;
1050 m_lastHandleUrlOpenJob
->start();
1054 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1056 // trash:/ is writable but we don't want to create new items in it.
1057 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1058 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1061 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1062 const KFileItem
& item
,
1064 const QList
<QAction
*>& customActions
)
1066 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1067 contextMenu
.data()->setCustomActions(customActions
);
1068 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1071 case DolphinContextMenu::OpenParentFolder
:
1072 changeUrl(KIO::upUrl(item
.url()));
1073 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1074 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1077 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1078 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1081 case DolphinContextMenu::OpenParentFolderInNewTab
:
1082 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1085 case DolphinContextMenu::None
:
1090 // Delete the menu, unless it has been deleted in its own nested event loop already.
1092 contextMenu
->deleteLater();
1096 void DolphinMainWindow::updateControlMenu()
1098 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1101 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1102 // because 'menu' is their parent.
1105 KActionCollection
* ac
= actionCollection();
1107 menu
->addMenu(m_newFileMenu
->menu());
1108 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1109 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1110 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1112 menu
->addSeparator();
1114 // Add "Edit" actions
1115 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1116 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1117 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1118 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1119 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1120 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1123 menu
->addSeparator();
1126 // Add "View" actions
1127 if (!GeneralSettings::showZoomSlider()) {
1128 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1129 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1130 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1131 menu
->addSeparator();
1134 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1135 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1136 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1137 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1138 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1141 menu
->addSeparator();
1144 // Add a curated assortment of items from the "Tools" menu
1145 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1146 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1147 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1149 menu
->addSeparator();
1151 // Add "Show Panels" menu
1152 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1154 // Add "Settings" menu entries
1155 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1156 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1157 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1158 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1161 auto helpMenu
= m_helpMenu
->menu();
1162 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1163 menu
->addMenu(helpMenu
);
1166 void DolphinMainWindow::updateToolBar()
1168 if (!menuBar()->isVisible()) {
1169 createControlButton();
1173 void DolphinMainWindow::slotControlButtonDeleted()
1175 m_controlButton
= nullptr;
1176 m_updateToolBarTimer
->start();
1179 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1181 DolphinViewContainer
* view
= activeViewContainer();
1183 if (view
->url() == url
) {
1184 // We can end up here if the user clicked a device in the Places Panel
1185 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1192 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1194 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1197 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1199 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1200 Q_ASSERT(viewContainer
);
1202 m_activeViewContainer
= viewContainer
;
1204 if (oldViewContainer
) {
1205 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1206 toggleSearchAction
->disconnect(oldViewContainer
);
1208 // Disconnect all signals between the old view container (container,
1209 // view and url navigator) and main window.
1210 oldViewContainer
->disconnect(this);
1211 oldViewContainer
->view()->disconnect(this);
1212 oldViewContainer
->urlNavigator()->disconnect(this);
1214 // except the requestItemInfo so that on hover the information panel can still be updated
1215 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1216 this, &DolphinMainWindow::requestItemInfo
);
1219 connectViewSignals(viewContainer
);
1221 m_actionHandler
->setCurrentView(viewContainer
->view());
1224 updateFileAndEditActions();
1225 updatePasteAction();
1226 updateViewActions();
1228 updateSearchAction();
1230 const QUrl url
= viewContainer
->url();
1231 emit
urlChanged(url
);
1234 void DolphinMainWindow::tabCountChanged(int count
)
1236 const bool enableTabActions
= (count
> 1);
1237 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1238 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1240 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1241 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1242 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1245 void DolphinMainWindow::updateWindowTitle()
1247 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1248 if (windowTitle() != newTitle
) {
1249 setWindowTitle(newTitle
);
1253 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1255 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1256 m_tearDownFromPlacesRequested
= true;
1257 m_terminalPanel
->goHome();
1258 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1260 m_placesPanel
->proceedWithTearDown();
1264 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1266 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1267 m_tearDownFromPlacesRequested
= false;
1268 m_terminalPanel
->goHome();
1272 void DolphinMainWindow::setupActions()
1274 // setup 'File' menu
1275 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1276 QMenu
* menu
= m_newFileMenu
->menu();
1277 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1278 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1279 m_newFileMenu
->setDelayed(false);
1280 connect(menu
, &QMenu::aboutToShow
,
1281 this, &DolphinMainWindow::updateNewMenu
);
1283 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1284 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1285 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1286 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1287 "window just like this one with the current location and view."
1288 "<nl/>You can drag and drop items between windows."));
1289 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1291 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1292 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1293 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1294 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1295 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1296 "A tab is an additional view within this window. "
1297 "You can drag and drop items between tabs."));
1298 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1299 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1301 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1302 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1303 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1304 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1305 "to the Places panel."));
1306 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1308 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1309 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1310 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1311 "currently viewed tab. If no more tabs are left this window "
1312 "will close instead."));
1314 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1315 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1317 // setup 'Edit' menu
1318 KStandardAction::undo(this,
1319 &DolphinMainWindow::undo
,
1320 actionCollection());
1322 // i18n: This will be the last paragraph for the whatsthis for all three:
1323 // Cut, Copy and Paste
1324 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1325 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1326 "applications and are among the most used commands. That's why their "
1327 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1328 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1329 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1330 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1331 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1332 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1333 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1334 "the clipboard to a new location. The items will be removed from their "
1335 "initial location.") + cutCopyPastePara
);
1336 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1337 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1338 "items in your current selection to the <emphasis>clipboard</emphasis>."
1339 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1340 "from the clipboard to a new location.") + cutCopyPastePara
);
1341 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1342 // The text of the paste-action is modified dynamically by Dolphin
1343 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1344 // due to the long text, the text "Paste" is used:
1345 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1346 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1347 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1348 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1349 "action they are removed from their old location.") + cutCopyPastePara
);
1351 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1352 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to inactive split view"));
1353 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1354 "the <emphasis>active</emphasis> view to the inactive split view."));
1355 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1356 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to inactive split view"));
1357 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1358 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1360 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1361 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to inactive split view"));
1362 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1363 "the <emphasis>active</emphasis> view to the inactive split view."));
1364 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1365 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to inactive split view"));
1366 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1367 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1369 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1370 searchAction
->setText(i18n("Search..."));
1371 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1372 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1373 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1374 "There you can enter search terms and specify settings to find the "
1375 "objects you are looking for.</para><para>Use this help again on "
1376 "the find bar so we can have a look at it while the settings are "
1377 "explained.</para>"));
1379 // toggle_search acts as a copy of the main searchAction to be used mainly
1380 // in the toolbar, with no default shortcut attached, to avoid messing with
1381 // existing workflows (search bar always open and Ctrl-F to focus)
1382 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1383 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1384 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1385 toggleSearchAction
->setIcon(searchAction
->icon());
1386 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1387 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1388 toggleSearchAction
->setCheckable(true);
1390 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1391 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1392 "files and folders in the current location."));
1394 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1395 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1396 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1397 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1398 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1399 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1400 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1402 // setup 'View' menu
1403 // (note that most of it is set up in DolphinViewActionHandler)
1405 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1406 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1407 "the folder view below into two autonomous views.</para><para>This "
1408 "way you can see two locations at once and move items between them "
1409 "quickly.</para>Click this again afterwards to recombine the views."));
1410 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1411 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1413 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1414 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1415 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1416 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1417 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1418 stashSplit
->setCheckable(false);
1419 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1420 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1422 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1424 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1425 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1426 stop
->setToolTip(i18nc("@info", "Stop loading"));
1427 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1428 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1429 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1431 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1432 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1433 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1434 "This toggles the <emphasis>Location Bar</emphasis> to be "
1435 "editable so you can directly enter a location you want to go to.<nl/>"
1436 "You can also switch to editing by clicking to the right of the "
1437 "location and switch back by confirming the edited location."));
1438 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1439 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1441 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1442 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1443 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1444 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1445 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1446 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1447 "This switches to editing the location and selects it "
1448 "so you can quickly enter a different location."));
1449 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1450 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1454 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1455 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1456 m_backAction
->setObjectName(backAction
->objectName());
1457 m_backAction
->setShortcuts(backAction
->shortcuts());
1459 m_backAction
->setDelayed(true);
1460 m_backAction
->setStickyMenu(false);
1461 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1462 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1463 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1464 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1466 auto backShortcuts
= m_backAction
->shortcuts();
1467 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1468 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1470 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1471 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1472 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1473 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1474 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1475 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1476 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1477 this, &DolphinMainWindow::closedTabsCountChanged
);
1479 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1480 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1481 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1482 "This returns you to the previously closed tab."));
1483 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1484 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1485 undoCloseTab
->setEnabled(false);
1486 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1488 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1489 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1490 "the last change you made to files or folders.<nl/>"
1491 "Such changes include <interface>creating, renaming</interface> "
1492 "and <interface>moving</interface> them to a different location "
1493 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1494 "be undone will ask for your confirmation."));
1495 undoAction
->setEnabled(false); // undo should be disabled by default
1498 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1499 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1500 m_forwardAction
->setObjectName(forwardAction
->objectName());
1501 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1503 m_forwardAction
->setDelayed(true);
1504 m_forwardAction
->setStickyMenu(false);
1505 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1506 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1507 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1508 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1509 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1511 // enable middle-click to open in a new tab
1512 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1513 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1514 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1515 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1516 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1517 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1518 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1519 "<filename>Home</filename> folder.<nl/>Every user account "
1520 "has their own <filename>Home</filename> that contains their data "
1521 "including folders that contain personal application data."));
1523 // setup 'Tools' menu
1524 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1525 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1526 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1527 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1528 "There you can enter a text to filter the files and folders currently displayed. "
1529 "Only those that contain the text in their name will be kept in view."));
1530 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1531 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1532 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1534 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1535 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1536 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1537 compareFiles
->setEnabled(false);
1538 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1540 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1541 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1542 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1543 "<para>This opens a preferred search tool for the viewed location.</para>"
1544 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1545 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1546 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1547 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1549 #ifdef HAVE_TERMINAL
1550 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1551 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1552 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1553 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1554 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1555 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1556 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1557 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1558 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1560 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1561 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1562 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1563 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1564 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1568 // setup 'Bookmarks' menu
1569 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1570 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1571 // Make the toolbar button version work properly on click
1572 bookmarkMenu
->setDelayed(false);
1573 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1574 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1576 // setup 'Settings' menu
1577 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1578 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1579 "This switches between having a <emphasis>Menubar</emphasis> "
1580 "and having a <interface>Control</interface> button. Both "
1581 "contain mostly the same commands and configuration options."));
1582 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1583 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1584 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1586 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1587 m_helpMenu
= new KHelpMenu(nullptr);
1588 m_helpMenu
->menu()->installEventFilter(this);
1589 // remove duplicate shortcuts
1590 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1591 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1593 // not in menu actions
1594 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1595 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1597 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1598 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1600 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1601 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1602 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1603 activateTab
->setEnabled(false);
1604 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1606 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1608 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1612 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1613 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1614 activateLastTab
->setEnabled(false);
1615 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1616 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1618 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1619 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1620 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1621 activateNextTab
->setEnabled(false);
1622 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1623 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1625 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1626 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1627 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1628 activatePrevTab
->setEnabled(false);
1629 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1630 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1633 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1634 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1635 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1636 showTarget
->setEnabled(false);
1637 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1639 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1640 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1641 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1642 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1644 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1645 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1646 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1647 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1649 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1650 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1651 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1652 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1655 void DolphinMainWindow::setupDockWidgets()
1657 const bool lock
= GeneralSettings::lockPanels();
1659 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1660 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1661 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1662 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1663 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1664 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1665 "switches between having panels <emphasis>locked</emphasis> or "
1666 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1667 "dragged to the other side of the window and have a close "
1668 "button.<nl/>Locked panels are embedded more cleanly."));
1669 lockLayoutAction
->setActive(lock
);
1670 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1672 // Setup "Information"
1673 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1674 infoDock
->setLocked(lock
);
1675 infoDock
->setObjectName(QStringLiteral("infoDock"));
1676 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1679 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1680 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1681 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1682 infoDock
->setWidget(infoPanel
);
1684 QAction
* infoAction
= infoDock
->toggleViewAction();
1685 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1687 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1688 connect(this, &DolphinMainWindow::urlChanged
,
1689 infoPanel
, &InformationPanel::setUrl
);
1690 connect(this, &DolphinMainWindow::selectionChanged
,
1691 infoPanel
, &InformationPanel::setSelection
);
1692 connect(this, &DolphinMainWindow::requestItemInfo
,
1693 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1696 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1697 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1698 "hide panels like this go to <interface>Control|Panels</interface> "
1699 "or <interface>View|Panels</interface>.</para>");
1701 actionCollection()->action(QStringLiteral("show_information_panel"))
1702 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1703 "<emphasis>information</emphasis> panel at the right side of the "
1704 "window.</para><para>The panel provides in-depth information "
1705 "about the items your mouse is hovering over or about the selected "
1706 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1707 "For single items a preview of their contents is provided.</para>"));
1709 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1710 "provides in-depth information about the items your mouse is "
1711 "hovering over or about the selected items. Otherwise it informs "
1712 "you about the currently viewed folder.<nl/>For single items a "
1713 "preview of their contents is provided.</para><para>You can configure "
1714 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1717 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1718 foldersDock
->setLocked(lock
);
1719 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1720 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1721 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1722 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1723 foldersDock
->setWidget(foldersPanel
);
1725 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1726 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1728 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1729 connect(this, &DolphinMainWindow::urlChanged
,
1730 foldersPanel
, &FoldersPanel::setUrl
);
1731 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1732 this, &DolphinMainWindow::changeUrl
);
1733 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1734 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1735 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1736 this, &DolphinMainWindow::showErrorMessage
);
1738 actionCollection()->action(QStringLiteral("show_folders_panel"))
1739 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1740 "<emphasis>folders</emphasis> panel at the left side of the window."
1741 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1742 "</emphasis> in a <emphasis>tree view</emphasis>."));
1743 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1744 "shows the folders of the <emphasis>file system</emphasis> in a "
1745 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1746 "there. Click the arrow to the left of a folder to see its subfolders. "
1747 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1750 #ifdef HAVE_TERMINAL
1751 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1752 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1753 terminalDock
->setLocked(lock
);
1754 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1755 m_terminalPanel
= new TerminalPanel(terminalDock
);
1756 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1757 terminalDock
->setWidget(m_terminalPanel
);
1759 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1760 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1761 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1762 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1763 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1764 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1766 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1767 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1769 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1770 connect(this, &DolphinMainWindow::urlChanged
,
1771 m_terminalPanel
, &TerminalPanel::setUrl
);
1773 if (GeneralSettings::version() < 200) {
1774 terminalDock
->hide();
1777 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1778 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1779 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1780 "<nl/>The location in the terminal will always match the folder "
1781 "view so you can navigate using either.</para><para>The terminal "
1782 "panel is not needed for basic computer usage but can be useful "
1783 "for advanced tasks. To learn more about terminals use the help "
1784 "in a standalone terminal application like Konsole.</para>"));
1785 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1786 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1787 "normal terminal but will match the location of the folder view "
1788 "so you can navigate using either.</para><para>The terminal panel "
1789 "is not needed for basic computer usage but can be useful for "
1790 "advanced tasks. To learn more about terminals use the help in a "
1791 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1795 if (GeneralSettings::version() < 200) {
1797 foldersDock
->hide();
1801 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1802 placesDock
->setLocked(lock
);
1803 placesDock
->setObjectName(QStringLiteral("placesDock"));
1804 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1806 m_placesPanel
= new PlacesPanel(placesDock
);
1807 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1808 placesDock
->setWidget(m_placesPanel
);
1810 QAction
*placesAction
= placesDock
->toggleViewAction();
1811 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1813 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1814 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1815 this, &DolphinMainWindow::slotPlaceActivated
);
1816 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1817 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1818 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1819 this, &DolphinMainWindow::showErrorMessage
);
1820 connect(this, &DolphinMainWindow::urlChanged
,
1821 m_placesPanel
, &PlacesPanel::setUrl
);
1822 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1823 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1824 connect(this, &DolphinMainWindow::settingsChanged
,
1825 m_placesPanel
, &PlacesPanel::readSettings
);
1826 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1827 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1828 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1829 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1830 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1832 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1833 actionShowAllPlaces
->setCheckable(true);
1834 actionShowAllPlaces
->setDisabled(true);
1835 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1836 "all places in the places panel that have been hidden. They will "
1837 "appear semi-transparent unless you uncheck their hide property."));
1839 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1840 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1841 m_placesPanel
->showHiddenEntries(checked
);
1844 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1845 actionShowAllPlaces
->setChecked(checked
);
1846 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1849 actionCollection()->action(QStringLiteral("show_places_panel"))
1850 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1851 "<emphasis>places</emphasis> panel at the left side of the window."
1852 "</para><para>It allows you to go to locations you have "
1853 "bookmarked and to access disk or media attached to the computer "
1854 "or to the network. It also contains sections to find recently "
1855 "saved files or files of a certain type.</para>"));
1856 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1857 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1858 "you have bookmarked and to access disk or media attached to the "
1859 "computer or to the network. It also contains sections to find "
1860 "recently saved files or files of a certain type.</para><para>"
1861 "Click on an entry to go there. Click with the right mouse button "
1862 "instead to open any entry in a new tab or new window.</para>"
1863 "<para>New entries can be added by dragging folders onto this panel. "
1864 "Right-click any section or entry to hide it. Right-click an empty "
1865 "space on this panel and select <interface>Show Hidden Places"
1866 "</interface> to display it again.</para>") + panelWhatsThis
);
1868 // Add actions into the "Panels" menu
1869 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1870 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1871 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1872 panelsMenu
->setDelayed(false);
1873 const KActionCollection
* ac
= actionCollection();
1874 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1876 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1878 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1879 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1880 panelsMenu
->addSeparator();
1881 panelsMenu
->addAction(actionShowAllPlaces
);
1882 panelsMenu
->addAction(lockLayoutAction
);
1884 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1885 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1890 void DolphinMainWindow::updateFileAndEditActions()
1892 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1893 const KActionCollection
* col
= actionCollection();
1894 KFileItemListProperties
capabilitiesSource(list
);
1896 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1897 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1898 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1899 QAction
* copyLocation
= col
->action(QString("copy_location"));
1901 if (list
.isEmpty()) {
1902 stateChanged(QStringLiteral("has_no_selection"));
1904 addToPlacesAction
->setEnabled(true);
1905 copyToOtherViewAction
->setEnabled(false);
1906 moveToOtherViewAction
->setEnabled(false);
1907 copyLocation
->setEnabled(false);
1909 stateChanged(QStringLiteral("has_selection"));
1911 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1912 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1913 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1914 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1915 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1916 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1917 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1919 if (list
.length() == 1 && list
.first().isDir()) {
1920 addToPlacesAction
->setEnabled(true);
1922 addToPlacesAction
->setEnabled(false);
1925 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
1926 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
1927 KFileItem capabilitiesDestination
;
1929 if (tabPage
->primaryViewActive()) {
1930 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
1932 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
1935 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
1936 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
1938 copyToOtherViewAction
->setEnabled(false);
1939 moveToOtherViewAction
->setEnabled(false);
1942 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
1944 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
1945 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1946 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
1947 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
1948 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
1949 copyLocation
->setEnabled(list
.length() == 1);
1950 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
1951 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
1955 void DolphinMainWindow::updateViewActions()
1957 m_actionHandler
->updateViewActions();
1959 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
1960 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1962 updateSplitAction();
1964 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
1965 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1966 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1969 void DolphinMainWindow::updateGoActions()
1971 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1972 const QUrl currentUrl
= m_activeViewContainer
->url();
1973 // I think this is one of the best places to firstly be confronted
1974 // with a file system and its hierarchy. Talking about the root
1975 // directory might seem too much here but it is the question that
1976 // naturally arises in this context.
1977 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
1978 "the folder that contains the currently viewed one.</para>"
1979 "<para>All files and folders are organized in a hierarchical "
1980 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
1981 "a directory that contains all data connected to this computer"
1982 "—the <emphasis>root directory</emphasis>.</para>"));
1983 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
1986 void DolphinMainWindow::createControlButton()
1988 if (m_controlButton
) {
1991 Q_ASSERT(!m_controlButton
);
1993 m_controlButton
= new QToolButton(this);
1994 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
1995 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
1996 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
1997 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
1998 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2000 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2001 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2002 controlMenu
->installEventFilter(this);
2004 m_controlButton
->setMenu(controlMenu
);
2006 toolBar()->addWidget(m_controlButton
);
2007 connect(toolBar(), &KToolBar::iconSizeChanged
,
2008 m_controlButton
, &QToolButton::setIconSize
);
2010 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2011 // gets edited. In this case we must add them again. The adding is done asynchronously by
2012 // m_updateToolBarTimer.
2013 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2014 m_updateToolBarTimer
= new QTimer(this);
2015 m_updateToolBarTimer
->setInterval(500);
2016 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2019 void DolphinMainWindow::deleteControlButton()
2021 delete m_controlButton
;
2022 m_controlButton
= nullptr;
2024 delete m_updateToolBarTimer
;
2025 m_updateToolBarTimer
= nullptr;
2028 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2033 const KToolBar
* toolBarWidget
= toolBar();
2034 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2035 if (widget
== toolBarWidget
) {
2040 menu
->addAction(action
);
2044 void DolphinMainWindow::refreshViews()
2046 m_tabWidget
->refreshViews();
2048 if (GeneralSettings::modifiedStartupSettings()) {
2049 // The startup settings have been changed by the user (see bug #254947).
2050 // Synchronize the split-view setting with the active view:
2051 const bool splitView
= GeneralSettings::splitView();
2052 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2053 updateSplitAction();
2054 updateWindowTitle();
2057 emit
settingsChanged();
2060 void DolphinMainWindow::clearStatusBar()
2062 m_activeViewContainer
->statusBar()->resetToDefaultText();
2065 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2067 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2068 this, &DolphinMainWindow::updateFilterBarAction
);
2069 connect(container
, &DolphinViewContainer::writeStateChanged
,
2070 this, &DolphinMainWindow::slotWriteStateChanged
);
2071 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2072 this, &DolphinMainWindow::updateSearchAction
);
2074 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2075 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2077 const DolphinView
* view
= container
->view();
2078 connect(view
, &DolphinView::selectionChanged
,
2079 this, &DolphinMainWindow::slotSelectionChanged
);
2080 connect(view
, &DolphinView::requestItemInfo
,
2081 this, &DolphinMainWindow::requestItemInfo
);
2082 connect(view
, &DolphinView::tabRequested
,
2083 this, &DolphinMainWindow::openNewTab
);
2084 connect(view
, &DolphinView::requestContextMenu
,
2085 this, &DolphinMainWindow::openContextMenu
);
2086 connect(view
, &DolphinView::directoryLoadingStarted
,
2087 this, &DolphinMainWindow::enableStopAction
);
2088 connect(view
, &DolphinView::directoryLoadingCompleted
,
2089 this, &DolphinMainWindow::disableStopAction
);
2090 connect(view
, &DolphinView::directoryLoadingCompleted
,
2091 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2092 connect(view
, &DolphinView::goBackRequested
,
2093 this, &DolphinMainWindow::goBack
);
2094 connect(view
, &DolphinView::goForwardRequested
,
2095 this, &DolphinMainWindow::goForward
);
2096 connect(view
, &DolphinView::urlActivated
,
2097 this, &DolphinMainWindow::handleUrl
);
2099 const KUrlNavigator
* navigator
= container
->urlNavigator();
2100 connect(navigator
, &KUrlNavigator::urlChanged
,
2101 this, &DolphinMainWindow::changeUrl
);
2102 connect(navigator
, &KUrlNavigator::historyChanged
,
2103 this, &DolphinMainWindow::updateHistory
);
2104 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2105 this, &DolphinMainWindow::slotEditableStateChanged
);
2106 connect(navigator
, &KUrlNavigator::tabRequested
,
2107 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2110 void DolphinMainWindow::updateSplitAction()
2112 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2113 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2114 if (tabPage
->splitViewEnabled()) {
2115 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2116 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2117 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2118 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2120 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2121 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2122 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2125 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2126 splitAction
->setToolTip(i18nc("@info", "Split view"));
2127 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2131 bool DolphinMainWindow::isKompareInstalled() const
2133 static bool initialized
= false;
2134 static bool installed
= false;
2136 // TODO: maybe replace this approach later by using a menu
2137 // plugin like kdiff3plugin.cpp
2138 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2144 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2145 const QKeySequence
& shortcut
,
2146 QAction
* dockAction
,
2147 const QString
& actionName
)
2149 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2150 panelAction
->setCheckable(true);
2151 panelAction
->setChecked(dockAction
->isChecked());
2152 panelAction
->setText(dockAction
->text());
2153 panelAction
->setIcon(icon
);
2154 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2156 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2157 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2160 void DolphinMainWindow::setupWhatsThis()
2163 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2164 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2165 "configuration options. Left-click on any of the menus on this "
2166 "bar to see its contents.</para><para>The Menubar can be hidden "
2167 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2168 "most of its contents become available through a <interface>Control"
2169 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2170 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2171 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2172 "frequently used actions.</para><para>It is highly customizable. "
2173 "All items you see in the <interface>Control</interface> menu or "
2174 "in the <interface>Menubar</interface> can be placed on the "
2175 "Toolbar. Just right-click on it and select <interface>Configure "
2176 "Toolbars…</interface> or find this action in the <interface>"
2177 "Control</interface> or <interface>Settings</interface> menu."
2178 "</para><para>The location of the bar and the style of its "
2179 "buttons can also be changed in the right-click menu. Right-click "
2180 "a button if you want to show or hide its text.</para>"));
2181 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2182 "<para>Here you can see the <emphasis>folders</emphasis> and "
2183 "<emphasis>files</emphasis> that are at the location described in "
2184 "the <interface>Location Bar</interface> above. This area is the "
2185 "central part of this application where you navigate to the files "
2186 "you want to use.</para><para>For an elaborate and general "
2187 "introduction to this application <link "
2188 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2189 "click here</link>. This will open an introductory article from "
2190 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2191 "explanations of all the features of this <emphasis>view</emphasis> "
2192 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2193 "instead. This will open a page from the <emphasis>Handbook"
2194 "</emphasis> that covers the basics.</para>"));
2197 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2198 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2199 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2200 "There you can set up key combinations to trigger an action when "
2201 "they are pressed simultaneously. All commands in this application can "
2202 "be triggered this way.</para>"));
2203 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2204 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2205 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2206 "<para>All items you see in the <interface>Control</interface> menu "
2207 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2208 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2209 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2210 "change a multitude of settings for this application. For an explanation "
2211 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2212 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2215 // The whatsthis has to be set for the m_helpMenu and for the
2216 // StandardAction separately because both are used in different locations.
2217 // m_helpMenu is only used for createControlButton() button.
2219 // Links do not work within the Menubar so texts without links are provided there.
2221 // i18n: If the external link isn't available in your language you should
2222 // probably state the external link language at least in brackets to not
2223 // frustrate the user. If there are multiple languages that the user might
2224 // know with a reasonable chance you might want to have 2 external links.
2225 // The same is in my opinion true for every external link you translate.
2226 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2227 "<para>This opens the Handbook for this application. It provides "
2228 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2229 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2230 ->setWhatsThis(whatsThisHelpContents
2231 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2232 "<para>If you want more elaborate introductions to the "
2233 "different features of <emphasis>Dolphin</emphasis> "
2234 "go to the KDE UserBase Wiki.</para>"));
2235 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2236 + xi18nc("@info:whatsthis second half of handbook text with link",
2237 "<para>If you want more elaborate introductions to the "
2238 "different features of <emphasis>Dolphin</emphasis> "
2239 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2240 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2242 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2243 "<para>This is the button that invokes the help feature you are "
2244 "using right now! Click it, then click any component of this "
2245 "application to ask \"What's this?\" about it. The mouse cursor "
2246 "will change appearance if no help is available for a spot.</para>");
2247 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2248 ->setWhatsThis(whatsThisWhatsThis
2249 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2250 "<para>There are two other ways to get help for this application: The "
2251 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2252 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2253 "article about <emphasis>File Management</emphasis> online."
2254 "</para><para>The \"What's this?\" help is "
2255 "missing in most other windows so don't get too used to this.</para>"));
2256 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2257 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2258 "<para>There are two other ways to get help: "
2259 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2260 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2261 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2262 "missing in most other windows so don't get too used to this.</para>"));
2264 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2265 "window that will guide you through reporting errors or flaws "
2266 "in this application or in other KDE software.</para>");
2267 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2268 ->setWhatsThis(whatsThisReportBug
);
2269 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2270 + xi18nc("@info:whatsthis second half of reportbug text with link",
2271 "<para>High-quality bug reports are much appreciated. To learn "
2272 "how to make your bug report as effective as possible "
2273 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2274 "click here</link>.</para>"));
2276 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2277 "<emphasis>web page</emphasis> where you can donate to "
2278 "support the continued work on this application and many "
2279 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2280 "<para>Donating is the easiest and fastest way to efficiently "
2281 "support KDE and its projects. KDE projects are available for "
2282 "free therefore your donation is needed to cover things that "
2283 "require money like servers, contributor meetings, etc.</para>"
2284 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2285 "organization behind the KDE community.</para>");
2286 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2287 ->setWhatsThis(whatsThisDonate
);
2288 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2290 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2291 "With this you can change the language this application uses."
2292 "<nl/>You can even set secondary languages which will be used "
2293 "if texts are not available in your preferred language.");
2294 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2295 ->setWhatsThis(whatsThisSwitchLanguage
);
2296 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2298 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2299 "window that informs you about the version, license, "
2300 "used libraries and maintainers of this application.");
2301 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2302 ->setWhatsThis(whatsThisAboutApp
);
2303 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2305 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2306 "window with information about <emphasis>KDE</emphasis>. "
2307 "The KDE community are the people behind this free software."
2308 "<nl/>If you like using this application but don't know "
2309 "about KDE or want to see a cute dragon have a look!");
2310 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2311 ->setWhatsThis(whatsThisAboutKDE
);
2312 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2315 bool DolphinMainWindow::event(QEvent
*event
)
2317 if (event
->type() == QEvent::WhatsThisClicked
) {
2319 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2320 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2323 return KXmlGuiWindow::event(event
);
2326 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2329 if (event
->type() == QEvent::WhatsThisClicked
) {
2331 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2332 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2338 void DolphinMainWindow::focusTerminalPanel()
2340 if (m_terminalPanel
->isVisible()) {
2341 if (m_terminalPanel
->terminalHasFocus()) {
2342 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2343 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2345 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2346 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2349 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2350 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2354 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2355 KIO::FileUndoManager::UiInterface()
2359 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2363 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2365 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2367 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2368 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2370 KIO::FileUndoManager::UiInterface::jobError(job
);
2374 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2376 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));