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>
74 #include <QPushButton>
76 #include <QStandardPaths>
78 #include <QToolButton>
79 #include <QWhatsThisClickedEvent>
82 // Used for GeneralSettings::version() to determine whether
83 // an updated version of Dolphin is running.
84 const int CurrentDolphinVersion
= 200;
85 // The maximum number of entries in the back/forward popup menu
86 const int MaxNumberOfNavigationentries
= 12;
87 // The maximum number of "Activate Tab" shortcuts
88 const int MaxActivateTabShortcuts
= 9;
91 DolphinMainWindow::DolphinMainWindow() :
92 KXmlGuiWindow(nullptr),
93 m_newFileMenu(nullptr),
96 m_activeViewContainer(nullptr),
97 m_actionHandler(nullptr),
98 m_remoteEncoding(nullptr),
100 m_bookmarkHandler(nullptr),
101 m_controlButton(nullptr),
102 m_updateToolBarTimer(nullptr),
103 m_lastHandleUrlOpenJob(nullptr),
104 m_terminalPanel(nullptr),
105 m_placesPanel(nullptr),
106 m_tearDownFromPlacesRequested(false),
107 m_backAction(nullptr),
108 m_forwardAction(nullptr)
110 Q_INIT_RESOURCE(dolphin
);
112 new MainWindowAdaptor(this);
115 setWindowFlags(Qt::WindowContextHelpButtonHint
);
117 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
118 setObjectName(QStringLiteral("Dolphin#"));
120 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
121 this, &DolphinMainWindow::showErrorMessage
);
123 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
124 undoManager
->setUiInterface(new UndoUiInterface());
126 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
127 this, &DolphinMainWindow::slotUndoAvailable
);
128 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
129 this, &DolphinMainWindow::slotUndoTextChanged
);
130 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
131 this, &DolphinMainWindow::clearStatusBar
);
132 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
133 this, &DolphinMainWindow::showCommand
);
135 GeneralSettings
* generalSettings
= GeneralSettings::self();
136 const bool firstRun
= (generalSettings
->version() < 200);
138 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
141 setAcceptDrops(true);
143 m_tabWidget
= new DolphinTabWidget(this);
144 m_tabWidget
->setObjectName("tabWidget");
145 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
146 this, &DolphinMainWindow::activeViewChanged
);
147 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
148 this, &DolphinMainWindow::tabCountChanged
);
149 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
150 this, &DolphinMainWindow::updateWindowTitle
);
151 setCentralWidget(m_tabWidget
);
155 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
156 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
157 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
159 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
160 connect(this, &DolphinMainWindow::urlChanged
,
161 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
165 setupGUI(Keys
| Save
| Create
| ToolBar
);
166 stateChanged(QStringLiteral("new_file"));
168 QClipboard
* clipboard
= QApplication::clipboard();
169 connect(clipboard
, &QClipboard::dataChanged
,
170 this, &DolphinMainWindow::updatePasteAction
);
172 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
173 showFilterBarAction
->setChecked(generalSettings
->filterBar());
176 menuBar()->setVisible(false);
177 // Assure a proper default size if Dolphin runs the first time
181 const bool showMenu
= !menuBar()->isHidden();
182 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
183 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
185 createControlButton();
188 // enable middle-click on back/forward/up to open in a new tab
189 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
190 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
191 toolBar()->installEventFilter(middleClickEventFilter
);
195 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
197 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
200 DolphinMainWindow::~DolphinMainWindow()
204 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
206 QVector
<DolphinViewContainer
*> viewContainers
;
207 viewContainers
.reserve(m_tabWidget
->count());
208 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
209 viewContainers
<< m_tabWidget
->tabPageAt(i
)->activeViewContainer();
211 return viewContainers
;
214 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
216 m_tabWidget
->openDirectories(dirs
, splitView
);
219 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
221 openDirectories(QUrl::fromStringList(dirs
), splitView
);
224 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
226 m_tabWidget
->openFiles(files
, splitView
);
229 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
231 openFiles(QUrl::fromStringList(files
), splitView
);
234 void DolphinMainWindow::activateWindow()
236 window()->setAttribute(Qt::WA_NativeWindow
, true);
237 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
238 KWindowSystem::activateWindow(window()->effectiveWinId());
241 void DolphinMainWindow::showCommand(CommandType command
)
243 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
245 case KIO::FileUndoManager::Copy
:
246 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
248 case KIO::FileUndoManager::Move
:
249 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
251 case KIO::FileUndoManager::Link
:
252 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
254 case KIO::FileUndoManager::Trash
:
255 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
257 case KIO::FileUndoManager::Rename
:
258 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
261 case KIO::FileUndoManager::Mkdir
:
262 statusBar
->setText(i18nc("@info:status", "Created folder."));
270 void DolphinMainWindow::pasteIntoFolder()
272 m_activeViewContainer
->view()->pasteIntoFolder();
275 void DolphinMainWindow::changeUrl(const QUrl
&url
)
277 if (!KProtocolManager::supportsListing(url
)) {
278 // The URL navigator only checks for validity, not
279 // if the URL can be listed. An error message is
280 // shown due to DolphinViewContainer::restoreView().
284 m_activeViewContainer
->setUrl(url
);
285 updateFileAndEditActions();
290 emit
urlChanged(url
);
293 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
295 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
296 m_placesPanel
->proceedWithTearDown();
297 m_tearDownFromPlacesRequested
= false;
300 m_activeViewContainer
->setAutoGrabFocus(false);
302 m_activeViewContainer
->setAutoGrabFocus(true);
305 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
307 KToggleAction
* editableLocationAction
=
308 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
309 editableLocationAction
->setChecked(editable
);
312 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
314 updateFileAndEditActions();
316 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
318 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
319 if (selectedUrlsCount
== 2) {
320 compareFilesAction
->setEnabled(isKompareInstalled());
322 compareFilesAction
->setEnabled(false);
325 emit
selectionChanged(selection
);
328 void DolphinMainWindow::updateHistory()
330 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
331 const int index
= urlNavigator
->historyIndex();
333 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
335 backAction
->setToolTip(i18nc("@info", "Go back"));
336 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
337 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
340 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
342 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
343 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
344 "This undoes a <interface>Go|Back</interface> action."));
345 forwardAction
->setEnabled(index
> 0);
349 void DolphinMainWindow::updateFilterBarAction(bool show
)
351 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
352 showFilterBarAction
->setChecked(show
);
355 void DolphinMainWindow::openNewMainWindow()
357 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
360 void DolphinMainWindow::openNewActivatedTab()
362 m_tabWidget
->openNewActivatedTab();
365 void DolphinMainWindow::addToPlaces()
370 // If nothing is selected, act on the current dir
371 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
372 url
= m_activeViewContainer
->url();
373 name
= m_activeViewContainer
->placesText();
375 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
376 url
= dirToAdd
.url();
377 name
= dirToAdd
.name();
380 PlacesItemModel model
;
382 if (m_activeViewContainer
->isSearchModeEnabled()) {
383 icon
= QStringLiteral("folder-saved-search-symbolic");
385 icon
= KIO::iconNameForUrl(url
);
387 model
.createPlacesItem(name
, url
, icon
);
391 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
393 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
396 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
398 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
401 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
403 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
406 void DolphinMainWindow::openInNewTab()
408 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
409 bool tabCreated
= false;
411 foreach (const KFileItem
& item
, list
) {
412 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
413 if (!url
.isEmpty()) {
414 openNewTabAfterCurrentTab(url
);
419 // if no new tab has been created from the selection
420 // open the current directory in a new tab
422 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
426 void DolphinMainWindow::openInNewWindow()
430 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
431 if (list
.isEmpty()) {
432 newWindowUrl
= m_activeViewContainer
->url();
433 } else if (list
.count() == 1) {
434 const KFileItem
& item
= list
.first();
435 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
438 if (!newWindowUrl
.isEmpty()) {
439 Dolphin::openNewWindow({newWindowUrl
}, this);
443 void DolphinMainWindow::showTarget()
445 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
446 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
447 auto linkDestination
= link
.linkDest();
448 if (QFileInfo(linkDestination
).isRelative()) {
449 linkDestination
= linkLocationDir
.filePath(linkDestination
);
451 if (QFileInfo::exists(linkDestination
)) {
452 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
454 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
455 DolphinViewContainer::Warning
);
459 void DolphinMainWindow::showEvent(QShowEvent
* event
)
461 KXmlGuiWindow::showEvent(event
);
463 if (!event
->spontaneous()) {
464 m_activeViewContainer
->view()->setFocus();
468 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
470 // Find out if Dolphin is closed directly by the user or
471 // by the session manager because the session is closed
472 bool closedByUser
= true;
473 if (qApp
->isSavingSession()) {
474 closedByUser
= false;
477 if (m_tabWidget
->count() > 1
478 && GeneralSettings::confirmClosingMultipleTabs()
479 && !GeneralSettings::rememberOpenedTabs()
481 // Ask the user if he really wants to quit and close all tabs.
482 // Open a confirmation dialog with 3 buttons:
483 // QDialogButtonBox::Yes -> Quit
484 // QDialogButtonBox::No -> Close only the current tab
485 // QDialogButtonBox::Cancel -> do nothing
486 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
487 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
488 dialog
->setModal(true);
489 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
490 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
491 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
492 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
493 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
495 bool doNotAskAgainCheckboxResult
= false;
497 const auto result
= KMessageBox::createKMessageBox(dialog
,
499 QMessageBox::Warning
,
500 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
502 i18n("Do not ask again"),
503 &doNotAskAgainCheckboxResult
,
504 KMessageBox::Notify
);
506 if (doNotAskAgainCheckboxResult
) {
507 GeneralSettings::setConfirmClosingMultipleTabs(false);
511 case QDialogButtonBox::Yes
:
514 case QDialogButtonBox::No
:
515 // Close only the current tab
516 m_tabWidget
->closeTab();
524 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
525 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
526 // Open a confirmation dialog with 3 buttons:
527 // QDialogButtonBox::Yes -> Quit
528 // QDialogButtonBox::No -> Show Terminal Panel
529 // QDialogButtonBox::Cancel -> do nothing
530 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
531 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
532 dialog
->setModal(true);
533 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
534 if (!m_terminalPanel
->isVisible()) {
535 standardButtons
|= QDialogButtonBox::No
;
537 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
538 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
539 if (!m_terminalPanel
->isVisible()) {
541 buttons
->button(QDialogButtonBox::No
),
542 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
544 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
546 bool doNotAskAgainCheckboxResult
= false;
548 const auto result
= KMessageBox::createKMessageBox(
551 QMessageBox::Warning
,
552 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
554 i18n("Do not ask again"),
555 &doNotAskAgainCheckboxResult
,
556 KMessageBox::Dangerous
);
558 if (doNotAskAgainCheckboxResult
) {
559 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
563 case QDialogButtonBox::Yes
:
566 case QDialogButtonBox::No
:
567 actionCollection()->action("show_terminal_panel")->trigger();
568 // Do not quit, ignore quit event
576 if (GeneralSettings::rememberOpenedTabs()) {
577 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
578 KConfig
*config
= KConfigGui::sessionConfig();
579 saveGlobalProperties(config
);
580 savePropertiesInternal(config
, 1);
584 GeneralSettings::setVersion(CurrentDolphinVersion
);
585 GeneralSettings::self()->save();
587 KXmlGuiWindow::closeEvent(event
);
590 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
592 m_tabWidget
->saveProperties(group
);
595 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
597 m_tabWidget
->readProperties(group
);
600 void DolphinMainWindow::updateNewMenu()
602 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
603 m_newFileMenu
->checkUpToDate();
604 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
607 void DolphinMainWindow::createDirectory()
609 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
610 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
611 m_newFileMenu
->createDirectory();
614 void DolphinMainWindow::quit()
619 void DolphinMainWindow::showErrorMessage(const QString
& message
)
621 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
624 void DolphinMainWindow::slotUndoAvailable(bool available
)
626 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
628 undoAction
->setEnabled(available
);
632 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
634 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
636 undoAction
->setText(text
);
640 void DolphinMainWindow::undo()
643 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
644 KIO::FileUndoManager::self()->undo();
647 void DolphinMainWindow::cut()
649 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
652 void DolphinMainWindow::copy()
654 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
657 void DolphinMainWindow::paste()
659 m_activeViewContainer
->view()->paste();
662 void DolphinMainWindow::find()
664 m_activeViewContainer
->setSearchModeEnabled(true);
667 void DolphinMainWindow::updateSearchAction()
669 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
670 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
673 void DolphinMainWindow::updatePasteAction()
675 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
676 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
677 pasteAction
->setEnabled(pasteInfo
.first
);
678 pasteAction
->setText(pasteInfo
.second
);
681 void DolphinMainWindow::slotDirectoryLoadingCompleted()
686 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
688 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
690 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
692 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
694 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
699 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
701 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
703 m_backAction
->menu()->clear();
704 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
705 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
707 m_backAction
->menu()->addAction(action
);
711 void DolphinMainWindow::slotGoBack(QAction
* action
)
713 int gotoIndex
= action
->data().value
<int>();
714 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
715 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
720 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
723 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
724 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
728 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
730 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
732 m_forwardAction
->menu()->clear();
733 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
734 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
736 m_forwardAction
->menu()->addAction(action
);
740 void DolphinMainWindow::slotGoForward(QAction
* action
)
742 int gotoIndex
= action
->data().value
<int>();
743 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
744 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
749 void DolphinMainWindow::selectAll()
753 // if the URL navigator is editable and focused, select the whole
754 // URL instead of all items of the view
756 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
757 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
758 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
759 lineEdit
->hasFocus();
761 lineEdit
->selectAll();
763 m_activeViewContainer
->view()->selectAll();
767 void DolphinMainWindow::invertSelection()
770 m_activeViewContainer
->view()->invertSelection();
773 void DolphinMainWindow::toggleSplitView()
775 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
776 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
781 void DolphinMainWindow::toggleSplitStash()
783 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
784 tabPage
->setSplitViewEnabled(false);
785 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
788 void DolphinMainWindow::reloadView()
791 m_activeViewContainer
->reload();
792 m_activeViewContainer
->statusBar()->updateSpaceInfo();
795 void DolphinMainWindow::stopLoading()
797 m_activeViewContainer
->view()->stopLoading();
800 void DolphinMainWindow::enableStopAction()
802 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
805 void DolphinMainWindow::disableStopAction()
807 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
810 void DolphinMainWindow::showFilterBar()
812 m_activeViewContainer
->setFilterBarVisible(true);
815 void DolphinMainWindow::toggleEditLocation()
819 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
820 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
821 urlNavigator
->setUrlEditable(action
->isChecked());
824 void DolphinMainWindow::replaceLocation()
826 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
827 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
829 // If the text field currently has focus and everything is selected,
830 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
831 if (navigator
->isUrlEditable()
832 && lineEdit
->hasFocus()
833 && lineEdit
->selectedText() == lineEdit
->text() ) {
834 navigator
->setUrlEditable(false);
836 navigator
->setUrlEditable(true);
837 navigator
->setFocus();
838 lineEdit
->selectAll();
842 void DolphinMainWindow::togglePanelLockState()
844 const bool newLockState
= !GeneralSettings::lockPanels();
845 foreach (QObject
* child
, children()) {
846 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
848 dock
->setLocked(newLockState
);
852 GeneralSettings::setLockPanels(newLockState
);
855 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
857 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
858 m_activeViewContainer
->view()->setFocus();
862 void DolphinMainWindow::goBack()
864 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
865 urlNavigator
->goBack();
867 if (urlNavigator
->locationState().isEmpty()) {
868 // An empty location state indicates a redirection URL,
869 // which must be skipped too
870 urlNavigator
->goBack();
874 void DolphinMainWindow::goForward()
876 m_activeViewContainer
->urlNavigator()->goForward();
879 void DolphinMainWindow::goUp()
881 m_activeViewContainer
->urlNavigator()->goUp();
884 void DolphinMainWindow::goHome()
886 m_activeViewContainer
->urlNavigator()->goHome();
889 void DolphinMainWindow::goBackInNewTab()
891 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
892 const int index
= urlNavigator
->historyIndex() + 1;
893 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
896 void DolphinMainWindow::goForwardInNewTab()
898 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
899 const int index
= urlNavigator
->historyIndex() - 1;
900 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
903 void DolphinMainWindow::goUpInNewTab()
905 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
906 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
909 void DolphinMainWindow::goHomeInNewTab()
911 openNewTabAfterCurrentTab(Dolphin::homeUrl());
914 void DolphinMainWindow::compareFiles()
916 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
917 if (items
.count() != 2) {
918 // The action is disabled in this case, but it could have been triggered
919 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
923 QUrl urlA
= items
.at(0).url();
924 QUrl urlB
= items
.at(1).url();
926 QString
command(QStringLiteral("kompare -c \""));
927 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
928 command
.append("\" \"");
929 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
930 command
.append('\"');
932 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
933 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
937 void DolphinMainWindow::toggleShowMenuBar()
939 const bool visible
= menuBar()->isVisible();
940 menuBar()->setVisible(!visible
);
942 createControlButton();
944 deleteControlButton();
948 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
950 m_searchTools
.clear();
951 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
952 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
954 QList
<QAction
*> actions
= m_searchTools
.actions();
955 if (actions
.isEmpty()) {
958 QAction
* action
= actions
.first();
959 if (action
->isSeparator()) {
965 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
967 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
968 if (!openPreferredSearchTool
) {
971 QPointer
<QAction
> tool
= preferredSearchTool();
973 openPreferredSearchTool
->setVisible(true);
974 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
975 openPreferredSearchTool
->setIcon(tool
->icon());
977 openPreferredSearchTool
->setVisible(false);
978 // still visible in Shortcuts configuration window
979 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
980 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
984 void DolphinMainWindow::openPreferredSearchTool()
986 QPointer
<QAction
> tool
= preferredSearchTool();
992 void DolphinMainWindow::openTerminal()
994 const QUrl url
= m_activeViewContainer
->url();
996 if (url
.isLocalFile()) {
997 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1001 // Not a local file, with protocol Class ":local", try stat'ing
1002 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1003 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1004 KJobWidgets::setWindow(job
, this);
1005 connect(job
, &KJob::result
, this, [job
]() {
1007 if (!job
->error()) {
1008 statUrl
= job
->mostLocalUrl();
1011 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1017 // Nothing worked, just use $HOME
1018 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1021 void DolphinMainWindow::editSettings()
1023 if (!m_settingsDialog
) {
1024 DolphinViewContainer
* container
= activeViewContainer();
1025 container
->view()->writeSettings();
1027 const QUrl url
= container
->url();
1028 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1029 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1030 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1031 settingsDialog
->show();
1032 m_settingsDialog
= settingsDialog
;
1034 m_settingsDialog
.data()->raise();
1038 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1040 delete m_lastHandleUrlOpenJob
;
1041 m_lastHandleUrlOpenJob
= nullptr;
1043 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1044 activeViewContainer()->setUrl(url
);
1046 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1047 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1048 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1050 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1051 [this, url
](const QString
&mimetype
) {
1052 if (mimetype
== QLatin1String("inode/directory")) {
1053 // If it's a dir, we'll take it from here
1054 m_lastHandleUrlOpenJob
->kill();
1055 m_lastHandleUrlOpenJob
= nullptr;
1056 activeViewContainer()->setUrl(url
);
1060 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1061 m_lastHandleUrlOpenJob
= nullptr;
1064 m_lastHandleUrlOpenJob
->start();
1068 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1070 // trash:/ is writable but we don't want to create new items in it.
1071 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1072 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1075 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1076 const KFileItem
& item
,
1078 const QList
<QAction
*>& customActions
)
1080 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1081 contextMenu
.data()->setCustomActions(customActions
);
1082 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1085 case DolphinContextMenu::OpenParentFolder
:
1086 changeUrl(KIO::upUrl(item
.url()));
1087 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1088 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1091 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1092 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1095 case DolphinContextMenu::OpenParentFolderInNewTab
:
1096 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1099 case DolphinContextMenu::None
:
1104 // Delete the menu, unless it has been deleted in its own nested event loop already.
1106 contextMenu
->deleteLater();
1110 void DolphinMainWindow::updateControlMenu()
1112 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1115 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1116 // because 'menu' is their parent.
1119 KActionCollection
* ac
= actionCollection();
1121 menu
->addMenu(m_newFileMenu
->menu());
1122 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1123 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1124 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1126 menu
->addSeparator();
1128 // Add "Edit" actions
1129 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1130 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1131 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1132 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1133 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1134 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1137 menu
->addSeparator();
1140 // Add "View" actions
1141 if (!GeneralSettings::showZoomSlider()) {
1142 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1143 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1144 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1145 menu
->addSeparator();
1148 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1149 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1150 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1151 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1152 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1155 menu
->addSeparator();
1158 // Add a curated assortment of items from the "Tools" menu
1159 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1160 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1161 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1163 menu
->addSeparator();
1165 // Add "Show Panels" menu
1166 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1168 // Add "Settings" menu entries
1169 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1170 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1171 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1172 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1175 auto helpMenu
= m_helpMenu
->menu();
1176 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1177 menu
->addMenu(helpMenu
);
1180 void DolphinMainWindow::updateToolBar()
1182 if (!menuBar()->isVisible()) {
1183 createControlButton();
1187 void DolphinMainWindow::slotControlButtonDeleted()
1189 m_controlButton
= nullptr;
1190 m_updateToolBarTimer
->start();
1193 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1195 DolphinViewContainer
* view
= activeViewContainer();
1197 if (view
->url() == url
) {
1198 // We can end up here if the user clicked a device in the Places Panel
1199 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1206 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1208 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1211 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1213 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1214 Q_ASSERT(viewContainer
);
1216 m_activeViewContainer
= viewContainer
;
1218 if (oldViewContainer
) {
1219 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1220 toggleSearchAction
->disconnect(oldViewContainer
);
1222 // Disconnect all signals between the old view container (container,
1223 // view and url navigator) and main window.
1224 oldViewContainer
->disconnect(this);
1225 oldViewContainer
->view()->disconnect(this);
1226 oldViewContainer
->urlNavigator()->disconnect(this);
1228 // except the requestItemInfo so that on hover the information panel can still be updated
1229 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1230 this, &DolphinMainWindow::requestItemInfo
);
1233 connectViewSignals(viewContainer
);
1235 m_actionHandler
->setCurrentView(viewContainer
->view());
1238 updateFileAndEditActions();
1239 updatePasteAction();
1240 updateViewActions();
1242 updateSearchAction();
1244 const QUrl url
= viewContainer
->url();
1245 emit
urlChanged(url
);
1248 void DolphinMainWindow::tabCountChanged(int count
)
1250 const bool enableTabActions
= (count
> 1);
1251 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1252 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1254 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1255 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1256 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1259 void DolphinMainWindow::updateWindowTitle()
1261 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1262 if (windowTitle() != newTitle
) {
1263 setWindowTitle(newTitle
);
1267 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1269 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1270 m_tearDownFromPlacesRequested
= true;
1271 m_terminalPanel
->goHome();
1272 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1274 m_placesPanel
->proceedWithTearDown();
1278 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1280 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1281 m_tearDownFromPlacesRequested
= false;
1282 m_terminalPanel
->goHome();
1286 void DolphinMainWindow::setupActions()
1288 // setup 'File' menu
1289 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1290 QMenu
* menu
= m_newFileMenu
->menu();
1291 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1292 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1293 m_newFileMenu
->setDelayed(false);
1294 connect(menu
, &QMenu::aboutToShow
,
1295 this, &DolphinMainWindow::updateNewMenu
);
1297 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1298 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1299 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1300 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1301 "window just like this one with the current location and view."
1302 "<nl/>You can drag and drop items between windows."));
1303 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1305 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1306 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1307 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1308 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1309 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1310 "A tab is an additional view within this window. "
1311 "You can drag and drop items between tabs."));
1312 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1313 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1315 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1316 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1317 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1318 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1319 "to the Places panel."));
1320 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1322 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1323 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1324 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1325 "currently viewed tab. If no more tabs are left this window "
1326 "will close instead."));
1328 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1329 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1331 // setup 'Edit' menu
1332 KStandardAction::undo(this,
1333 &DolphinMainWindow::undo
,
1334 actionCollection());
1336 // i18n: This will be the last paragraph for the whatsthis for all three:
1337 // Cut, Copy and Paste
1338 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1339 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1340 "applications and are among the most used commands. That's why their "
1341 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1342 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1343 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1344 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1345 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1346 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1347 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1348 "the clipboard to a new location. The items will be removed from their "
1349 "initial location.") + cutCopyPastePara
);
1350 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1351 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1352 "items in your current selection to the <emphasis>clipboard</emphasis>."
1353 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1354 "from the clipboard to a new location.") + cutCopyPastePara
);
1355 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1356 // The text of the paste-action is modified dynamically by Dolphin
1357 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1358 // due to the long text, the text "Paste" is used:
1359 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1360 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1361 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1362 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1363 "action they are removed from their old location.") + cutCopyPastePara
);
1365 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1366 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1367 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1368 "the <emphasis>active</emphasis> view to the inactive split view."));
1369 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1370 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1371 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1372 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1374 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1375 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1376 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1377 "the <emphasis>active</emphasis> view to the inactive split view."));
1378 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1379 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1380 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1381 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1383 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1384 searchAction
->setText(i18n("Search..."));
1385 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1386 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1387 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1388 "There you can enter search terms and specify settings to find the "
1389 "objects you are looking for.</para><para>Use this help again on "
1390 "the find bar so we can have a look at it while the settings are "
1391 "explained.</para>"));
1393 // toggle_search acts as a copy of the main searchAction to be used mainly
1394 // in the toolbar, with no default shortcut attached, to avoid messing with
1395 // existing workflows (search bar always open and Ctrl-F to focus)
1396 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1397 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1398 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1399 toggleSearchAction
->setIcon(searchAction
->icon());
1400 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1401 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1402 toggleSearchAction
->setCheckable(true);
1404 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1405 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1406 "files and folders in the current location."));
1408 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1409 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1410 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1411 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1412 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1413 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1414 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1416 // setup 'View' menu
1417 // (note that most of it is set up in DolphinViewActionHandler)
1419 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1420 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1421 "the folder view below into two autonomous views.</para><para>This "
1422 "way you can see two locations at once and move items between them "
1423 "quickly.</para>Click this again afterwards to recombine the views."));
1424 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1425 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1427 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1428 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1429 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1430 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1431 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1432 stashSplit
->setCheckable(false);
1433 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1434 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1436 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1438 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1439 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1440 stop
->setToolTip(i18nc("@info", "Stop loading"));
1441 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1442 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1443 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1445 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1446 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1447 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1448 "This toggles the <emphasis>Location Bar</emphasis> to be "
1449 "editable so you can directly enter a location you want to go to.<nl/>"
1450 "You can also switch to editing by clicking to the right of the "
1451 "location and switch back by confirming the edited location."));
1452 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1453 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1455 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1456 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1457 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1458 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1459 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1460 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1461 "This switches to editing the location and selects it "
1462 "so you can quickly enter a different location."));
1463 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1464 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1468 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1469 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1470 m_backAction
->setObjectName(backAction
->objectName());
1471 m_backAction
->setShortcuts(backAction
->shortcuts());
1473 m_backAction
->setDelayed(true);
1474 m_backAction
->setStickyMenu(false);
1475 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1476 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1477 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1478 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1480 auto backShortcuts
= m_backAction
->shortcuts();
1481 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1482 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1484 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1485 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1486 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1487 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1488 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1489 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1490 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1491 this, &DolphinMainWindow::closedTabsCountChanged
);
1493 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1494 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1495 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1496 "This returns you to the previously closed tab."));
1497 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1498 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1499 undoCloseTab
->setEnabled(false);
1500 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1502 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1503 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1504 "the last change you made to files or folders.<nl/>"
1505 "Such changes include <interface>creating, renaming</interface> "
1506 "and <interface>moving</interface> them to a different location "
1507 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1508 "be undone will ask for your confirmation."));
1509 undoAction
->setEnabled(false); // undo should be disabled by default
1512 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1513 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1514 m_forwardAction
->setObjectName(forwardAction
->objectName());
1515 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1517 m_forwardAction
->setDelayed(true);
1518 m_forwardAction
->setStickyMenu(false);
1519 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1520 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1521 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1522 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1523 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1525 // enable middle-click to open in a new tab
1526 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1527 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1528 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1529 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1530 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1531 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1532 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1533 "<filename>Home</filename> folder.<nl/>Every user account "
1534 "has their own <filename>Home</filename> that contains their data "
1535 "including folders that contain personal application data."));
1537 // setup 'Tools' menu
1538 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1539 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1540 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1541 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1542 "There you can enter a text to filter the files and folders currently displayed. "
1543 "Only those that contain the text in their name will be kept in view."));
1544 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1545 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1546 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1548 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1549 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1550 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1551 compareFiles
->setEnabled(false);
1552 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1554 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1555 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1556 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1557 "<para>This opens a preferred search tool for the viewed location.</para>"
1558 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1559 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1560 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1561 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1563 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1564 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1565 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1566 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1567 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1568 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1569 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1570 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1571 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1573 #ifdef HAVE_TERMINAL
1574 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1575 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1576 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1577 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1578 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1582 // setup 'Bookmarks' menu
1583 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1584 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1585 // Make the toolbar button version work properly on click
1586 bookmarkMenu
->setDelayed(false);
1587 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1588 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1590 // setup 'Settings' menu
1591 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1592 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1593 "This switches between having a <emphasis>Menubar</emphasis> "
1594 "and having a <interface>Control</interface> button. Both "
1595 "contain mostly the same commands and configuration options."));
1596 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1597 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1598 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1600 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1601 m_helpMenu
= new KHelpMenu(nullptr);
1602 m_helpMenu
->menu()->installEventFilter(this);
1603 // remove duplicate shortcuts
1604 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1605 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1607 // not in menu actions
1608 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1609 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1611 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1612 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1614 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1615 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1616 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1617 activateTab
->setEnabled(false);
1618 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1620 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1622 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1626 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1627 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1628 activateLastTab
->setEnabled(false);
1629 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1630 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1632 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1633 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1634 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1635 activateNextTab
->setEnabled(false);
1636 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1637 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1639 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1640 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1641 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1642 activatePrevTab
->setEnabled(false);
1643 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1644 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1647 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1648 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1649 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1650 showTarget
->setEnabled(false);
1651 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1653 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1654 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1655 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1656 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1658 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1659 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1660 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1661 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1663 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1664 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1665 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1666 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1669 void DolphinMainWindow::setupDockWidgets()
1671 const bool lock
= GeneralSettings::lockPanels();
1673 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1674 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1675 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1676 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1677 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1678 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1679 "switches between having panels <emphasis>locked</emphasis> or "
1680 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1681 "dragged to the other side of the window and have a close "
1682 "button.<nl/>Locked panels are embedded more cleanly."));
1683 lockLayoutAction
->setActive(lock
);
1684 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1686 // Setup "Information"
1687 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1688 infoDock
->setLocked(lock
);
1689 infoDock
->setObjectName(QStringLiteral("infoDock"));
1690 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1693 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1694 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1695 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1696 infoDock
->setWidget(infoPanel
);
1698 QAction
* infoAction
= infoDock
->toggleViewAction();
1699 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1701 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1702 connect(this, &DolphinMainWindow::urlChanged
,
1703 infoPanel
, &InformationPanel::setUrl
);
1704 connect(this, &DolphinMainWindow::selectionChanged
,
1705 infoPanel
, &InformationPanel::setSelection
);
1706 connect(this, &DolphinMainWindow::requestItemInfo
,
1707 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1710 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1711 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1712 "hide panels like this go to <interface>Control|Panels</interface> "
1713 "or <interface>View|Panels</interface>.</para>");
1715 actionCollection()->action(QStringLiteral("show_information_panel"))
1716 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1717 "<emphasis>information</emphasis> panel at the right side of the "
1718 "window.</para><para>The panel provides in-depth information "
1719 "about the items your mouse is hovering over or about the selected "
1720 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1721 "For single items a preview of their contents is provided.</para>"));
1723 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1724 "provides in-depth information about the items your mouse is "
1725 "hovering over or about the selected items. Otherwise it informs "
1726 "you about the currently viewed folder.<nl/>For single items a "
1727 "preview of their contents is provided.</para><para>You can configure "
1728 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1731 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1732 foldersDock
->setLocked(lock
);
1733 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1734 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1735 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1736 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1737 foldersDock
->setWidget(foldersPanel
);
1739 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1740 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1742 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1743 connect(this, &DolphinMainWindow::urlChanged
,
1744 foldersPanel
, &FoldersPanel::setUrl
);
1745 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1746 this, &DolphinMainWindow::changeUrl
);
1747 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1748 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1749 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1750 this, &DolphinMainWindow::showErrorMessage
);
1752 actionCollection()->action(QStringLiteral("show_folders_panel"))
1753 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1754 "<emphasis>folders</emphasis> panel at the left side of the window."
1755 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1756 "</emphasis> in a <emphasis>tree view</emphasis>."));
1757 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1758 "shows the folders of the <emphasis>file system</emphasis> in a "
1759 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1760 "there. Click the arrow to the left of a folder to see its subfolders. "
1761 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1764 #ifdef HAVE_TERMINAL
1765 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1766 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1767 terminalDock
->setLocked(lock
);
1768 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1769 m_terminalPanel
= new TerminalPanel(terminalDock
);
1770 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1771 terminalDock
->setWidget(m_terminalPanel
);
1773 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1774 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1775 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1776 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1777 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1778 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1780 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1781 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1783 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1784 connect(this, &DolphinMainWindow::urlChanged
,
1785 m_terminalPanel
, &TerminalPanel::setUrl
);
1787 if (GeneralSettings::version() < 200) {
1788 terminalDock
->hide();
1791 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1792 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1793 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1794 "<nl/>The location in the terminal will always match the folder "
1795 "view so you can navigate using either.</para><para>The terminal "
1796 "panel is not needed for basic computer usage but can be useful "
1797 "for advanced tasks. To learn more about terminals use the help "
1798 "in a standalone terminal application like Konsole.</para>"));
1799 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1800 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1801 "normal terminal but will match the location of the folder view "
1802 "so you can navigate using either.</para><para>The terminal panel "
1803 "is not needed for basic computer usage but can be useful for "
1804 "advanced tasks. To learn more about terminals use the help in a "
1805 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1809 if (GeneralSettings::version() < 200) {
1811 foldersDock
->hide();
1815 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1816 placesDock
->setLocked(lock
);
1817 placesDock
->setObjectName(QStringLiteral("placesDock"));
1818 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1820 m_placesPanel
= new PlacesPanel(placesDock
);
1821 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1822 placesDock
->setWidget(m_placesPanel
);
1824 QAction
*placesAction
= placesDock
->toggleViewAction();
1825 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1827 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1828 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1829 this, &DolphinMainWindow::slotPlaceActivated
);
1830 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1831 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1832 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1833 this, &DolphinMainWindow::showErrorMessage
);
1834 connect(this, &DolphinMainWindow::urlChanged
,
1835 m_placesPanel
, &PlacesPanel::setUrl
);
1836 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1837 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1838 connect(this, &DolphinMainWindow::settingsChanged
,
1839 m_placesPanel
, &PlacesPanel::readSettings
);
1840 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1841 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1842 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1843 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1844 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1846 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1847 actionShowAllPlaces
->setCheckable(true);
1848 actionShowAllPlaces
->setDisabled(true);
1849 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1850 "all places in the places panel that have been hidden. They will "
1851 "appear semi-transparent unless you uncheck their hide property."));
1853 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1854 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1855 m_placesPanel
->showHiddenEntries(checked
);
1858 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1859 actionShowAllPlaces
->setChecked(checked
);
1860 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1863 actionCollection()->action(QStringLiteral("show_places_panel"))
1864 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1865 "<emphasis>places</emphasis> panel at the left side of the window."
1866 "</para><para>It allows you to go to locations you have "
1867 "bookmarked and to access disk or media attached to the computer "
1868 "or to the network. It also contains sections to find recently "
1869 "saved files or files of a certain type.</para>"));
1870 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1871 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1872 "you have bookmarked and to access disk or media attached to the "
1873 "computer or to the network. It also contains sections to find "
1874 "recently saved files or files of a certain type.</para><para>"
1875 "Click on an entry to go there. Click with the right mouse button "
1876 "instead to open any entry in a new tab or new window.</para>"
1877 "<para>New entries can be added by dragging folders onto this panel. "
1878 "Right-click any section or entry to hide it. Right-click an empty "
1879 "space on this panel and select <interface>Show Hidden Places"
1880 "</interface> to display it again.</para>") + panelWhatsThis
);
1882 // Add actions into the "Panels" menu
1883 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1884 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1885 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1886 panelsMenu
->setDelayed(false);
1887 const KActionCollection
* ac
= actionCollection();
1888 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1890 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1892 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1893 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1894 panelsMenu
->addSeparator();
1895 panelsMenu
->addAction(actionShowAllPlaces
);
1896 panelsMenu
->addAction(lockLayoutAction
);
1898 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1899 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1904 void DolphinMainWindow::updateFileAndEditActions()
1906 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1907 const KActionCollection
* col
= actionCollection();
1908 KFileItemListProperties
capabilitiesSource(list
);
1910 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1911 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1912 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1913 QAction
* copyLocation
= col
->action(QString("copy_location"));
1915 if (list
.isEmpty()) {
1916 stateChanged(QStringLiteral("has_no_selection"));
1918 addToPlacesAction
->setEnabled(true);
1919 copyToOtherViewAction
->setEnabled(false);
1920 moveToOtherViewAction
->setEnabled(false);
1921 copyLocation
->setEnabled(false);
1923 stateChanged(QStringLiteral("has_selection"));
1925 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1926 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1927 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1928 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1929 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1930 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1931 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1933 if (list
.length() == 1 && list
.first().isDir()) {
1934 addToPlacesAction
->setEnabled(true);
1936 addToPlacesAction
->setEnabled(false);
1939 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
1940 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
1941 KFileItem capabilitiesDestination
;
1943 if (tabPage
->primaryViewActive()) {
1944 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
1946 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
1949 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
1950 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
1952 copyToOtherViewAction
->setEnabled(false);
1953 moveToOtherViewAction
->setEnabled(false);
1956 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
1958 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
1959 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1960 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
1961 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
1962 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
1963 copyLocation
->setEnabled(list
.length() == 1);
1964 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
1965 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
1969 void DolphinMainWindow::updateViewActions()
1971 m_actionHandler
->updateViewActions();
1973 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
1974 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1976 updateSplitAction();
1978 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
1979 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1980 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1983 void DolphinMainWindow::updateGoActions()
1985 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1986 const QUrl currentUrl
= m_activeViewContainer
->url();
1987 // I think this is one of the best places to firstly be confronted
1988 // with a file system and its hierarchy. Talking about the root
1989 // directory might seem too much here but it is the question that
1990 // naturally arises in this context.
1991 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
1992 "the folder that contains the currently viewed one.</para>"
1993 "<para>All files and folders are organized in a hierarchical "
1994 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
1995 "a directory that contains all data connected to this computer"
1996 "—the <emphasis>root directory</emphasis>.</para>"));
1997 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2000 void DolphinMainWindow::createControlButton()
2002 if (m_controlButton
) {
2005 Q_ASSERT(!m_controlButton
);
2007 m_controlButton
= new QToolButton(this);
2008 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2009 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2010 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2011 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2012 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2014 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2015 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2016 controlMenu
->installEventFilter(this);
2018 m_controlButton
->setMenu(controlMenu
);
2020 toolBar()->addWidget(m_controlButton
);
2021 connect(toolBar(), &KToolBar::iconSizeChanged
,
2022 m_controlButton
, &QToolButton::setIconSize
);
2024 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2025 // gets edited. In this case we must add them again. The adding is done asynchronously by
2026 // m_updateToolBarTimer.
2027 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2028 m_updateToolBarTimer
= new QTimer(this);
2029 m_updateToolBarTimer
->setInterval(500);
2030 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2033 void DolphinMainWindow::deleteControlButton()
2035 delete m_controlButton
;
2036 m_controlButton
= nullptr;
2038 delete m_updateToolBarTimer
;
2039 m_updateToolBarTimer
= nullptr;
2042 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2047 const KToolBar
* toolBarWidget
= toolBar();
2048 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2049 if (widget
== toolBarWidget
) {
2054 menu
->addAction(action
);
2058 void DolphinMainWindow::refreshViews()
2060 m_tabWidget
->refreshViews();
2062 if (GeneralSettings::modifiedStartupSettings()) {
2063 // The startup settings have been changed by the user (see bug #254947).
2064 // Synchronize the split-view setting with the active view:
2065 const bool splitView
= GeneralSettings::splitView();
2066 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2067 updateSplitAction();
2068 updateWindowTitle();
2071 emit
settingsChanged();
2074 void DolphinMainWindow::clearStatusBar()
2076 m_activeViewContainer
->statusBar()->resetToDefaultText();
2079 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2081 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2082 this, &DolphinMainWindow::updateFilterBarAction
);
2083 connect(container
, &DolphinViewContainer::writeStateChanged
,
2084 this, &DolphinMainWindow::slotWriteStateChanged
);
2085 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2086 this, &DolphinMainWindow::updateSearchAction
);
2088 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2089 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2091 const DolphinView
* view
= container
->view();
2092 connect(view
, &DolphinView::selectionChanged
,
2093 this, &DolphinMainWindow::slotSelectionChanged
);
2094 connect(view
, &DolphinView::requestItemInfo
,
2095 this, &DolphinMainWindow::requestItemInfo
);
2096 connect(view
, &DolphinView::tabRequested
,
2097 this, &DolphinMainWindow::openNewTab
);
2098 connect(view
, &DolphinView::requestContextMenu
,
2099 this, &DolphinMainWindow::openContextMenu
);
2100 connect(view
, &DolphinView::directoryLoadingStarted
,
2101 this, &DolphinMainWindow::enableStopAction
);
2102 connect(view
, &DolphinView::directoryLoadingCompleted
,
2103 this, &DolphinMainWindow::disableStopAction
);
2104 connect(view
, &DolphinView::directoryLoadingCompleted
,
2105 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2106 connect(view
, &DolphinView::goBackRequested
,
2107 this, &DolphinMainWindow::goBack
);
2108 connect(view
, &DolphinView::goForwardRequested
,
2109 this, &DolphinMainWindow::goForward
);
2110 connect(view
, &DolphinView::urlActivated
,
2111 this, &DolphinMainWindow::handleUrl
);
2112 connect(view
, &DolphinView::goUpRequested
,
2113 this, &DolphinMainWindow::goUp
);
2115 const KUrlNavigator
* navigator
= container
->urlNavigator();
2116 connect(navigator
, &KUrlNavigator::urlChanged
,
2117 this, &DolphinMainWindow::changeUrl
);
2118 connect(navigator
, &KUrlNavigator::historyChanged
,
2119 this, &DolphinMainWindow::updateHistory
);
2120 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2121 this, &DolphinMainWindow::slotEditableStateChanged
);
2122 connect(navigator
, &KUrlNavigator::tabRequested
,
2123 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2126 void DolphinMainWindow::updateSplitAction()
2128 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2129 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2130 if (tabPage
->splitViewEnabled()) {
2131 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2132 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2133 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2134 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2136 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2137 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2138 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2141 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2142 splitAction
->setToolTip(i18nc("@info", "Split view"));
2143 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2147 bool DolphinMainWindow::isKompareInstalled() const
2149 static bool initialized
= false;
2150 static bool installed
= false;
2152 // TODO: maybe replace this approach later by using a menu
2153 // plugin like kdiff3plugin.cpp
2154 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2160 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2161 const QKeySequence
& shortcut
,
2162 QAction
* dockAction
,
2163 const QString
& actionName
)
2165 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2166 panelAction
->setCheckable(true);
2167 panelAction
->setChecked(dockAction
->isChecked());
2168 panelAction
->setText(dockAction
->text());
2169 panelAction
->setIcon(icon
);
2170 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2172 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2173 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2176 void DolphinMainWindow::setupWhatsThis()
2179 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2180 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2181 "configuration options. Left-click on any of the menus on this "
2182 "bar to see its contents.</para><para>The Menubar can be hidden "
2183 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2184 "most of its contents become available through a <interface>Control"
2185 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2186 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2187 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2188 "frequently used actions.</para><para>It is highly customizable. "
2189 "All items you see in the <interface>Control</interface> menu or "
2190 "in the <interface>Menubar</interface> can be placed on the "
2191 "Toolbar. Just right-click on it and select <interface>Configure "
2192 "Toolbars…</interface> or find this action in the <interface>"
2193 "Control</interface> or <interface>Settings</interface> menu."
2194 "</para><para>The location of the bar and the style of its "
2195 "buttons can also be changed in the right-click menu. Right-click "
2196 "a button if you want to show or hide its text.</para>"));
2197 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2198 "<para>Here you can see the <emphasis>folders</emphasis> and "
2199 "<emphasis>files</emphasis> that are at the location described in "
2200 "the <interface>Location Bar</interface> above. This area is the "
2201 "central part of this application where you navigate to the files "
2202 "you want to use.</para><para>For an elaborate and general "
2203 "introduction to this application <link "
2204 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2205 "click here</link>. This will open an introductory article from "
2206 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2207 "explanations of all the features of this <emphasis>view</emphasis> "
2208 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2209 "instead. This will open a page from the <emphasis>Handbook"
2210 "</emphasis> that covers the basics.</para>"));
2213 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2214 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2215 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2216 "There you can set up key combinations to trigger an action when "
2217 "they are pressed simultaneously. All commands in this application can "
2218 "be triggered this way.</para>"));
2219 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2220 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2221 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2222 "<para>All items you see in the <interface>Control</interface> menu "
2223 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2224 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2225 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2226 "change a multitude of settings for this application. For an explanation "
2227 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2228 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2231 // The whatsthis has to be set for the m_helpMenu and for the
2232 // StandardAction separately because both are used in different locations.
2233 // m_helpMenu is only used for createControlButton() button.
2235 // Links do not work within the Menubar so texts without links are provided there.
2237 // i18n: If the external link isn't available in your language you should
2238 // probably state the external link language at least in brackets to not
2239 // frustrate the user. If there are multiple languages that the user might
2240 // know with a reasonable chance you might want to have 2 external links.
2241 // The same is in my opinion true for every external link you translate.
2242 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2243 "<para>This opens the Handbook for this application. It provides "
2244 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2245 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2246 ->setWhatsThis(whatsThisHelpContents
2247 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2248 "<para>If you want more elaborate introductions to the "
2249 "different features of <emphasis>Dolphin</emphasis> "
2250 "go to the KDE UserBase Wiki.</para>"));
2251 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2252 + xi18nc("@info:whatsthis second half of handbook text with link",
2253 "<para>If you want more elaborate introductions to the "
2254 "different features of <emphasis>Dolphin</emphasis> "
2255 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2256 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2258 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2259 "<para>This is the button that invokes the help feature you are "
2260 "using right now! Click it, then click any component of this "
2261 "application to ask \"What's this?\" about it. The mouse cursor "
2262 "will change appearance if no help is available for a spot.</para>");
2263 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2264 ->setWhatsThis(whatsThisWhatsThis
2265 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2266 "<para>There are two other ways to get help for this application: The "
2267 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2268 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2269 "article about <emphasis>File Management</emphasis> online."
2270 "</para><para>The \"What's this?\" help is "
2271 "missing in most other windows so don't get too used to this.</para>"));
2272 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2273 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2274 "<para>There are two other ways to get help: "
2275 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2276 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2277 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2278 "missing in most other windows so don't get too used to this.</para>"));
2280 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2281 "window that will guide you through reporting errors or flaws "
2282 "in this application or in other KDE software.</para>");
2283 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2284 ->setWhatsThis(whatsThisReportBug
);
2285 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2286 + xi18nc("@info:whatsthis second half of reportbug text with link",
2287 "<para>High-quality bug reports are much appreciated. To learn "
2288 "how to make your bug report as effective as possible "
2289 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2290 "click here</link>.</para>"));
2292 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2293 "<emphasis>web page</emphasis> where you can donate to "
2294 "support the continued work on this application and many "
2295 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2296 "<para>Donating is the easiest and fastest way to efficiently "
2297 "support KDE and its projects. KDE projects are available for "
2298 "free therefore your donation is needed to cover things that "
2299 "require money like servers, contributor meetings, etc.</para>"
2300 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2301 "organization behind the KDE community.</para>");
2302 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2303 ->setWhatsThis(whatsThisDonate
);
2304 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2306 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2307 "With this you can change the language this application uses."
2308 "<nl/>You can even set secondary languages which will be used "
2309 "if texts are not available in your preferred language.");
2310 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2311 ->setWhatsThis(whatsThisSwitchLanguage
);
2312 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2314 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2315 "window that informs you about the version, license, "
2316 "used libraries and maintainers of this application.");
2317 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2318 ->setWhatsThis(whatsThisAboutApp
);
2319 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2321 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2322 "window with information about <emphasis>KDE</emphasis>. "
2323 "The KDE community are the people behind this free software."
2324 "<nl/>If you like using this application but don't know "
2325 "about KDE or want to see a cute dragon have a look!");
2326 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2327 ->setWhatsThis(whatsThisAboutKDE
);
2328 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2331 bool DolphinMainWindow::event(QEvent
*event
)
2333 if (event
->type() == QEvent::WhatsThisClicked
) {
2335 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2336 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2339 return KXmlGuiWindow::event(event
);
2342 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2345 if (event
->type() == QEvent::WhatsThisClicked
) {
2347 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2348 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2354 void DolphinMainWindow::focusTerminalPanel()
2356 if (m_terminalPanel
->isVisible()) {
2357 if (m_terminalPanel
->terminalHasFocus()) {
2358 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2359 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2361 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2362 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2365 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2366 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2370 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2371 KIO::FileUndoManager::UiInterface()
2375 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2379 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2381 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2383 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2384 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2386 KIO::FileUndoManager::UiInterface::jobError(job
);
2390 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2392 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));