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
;
208 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
209 DolphinTabPage
*tabPage
= m_tabWidget
->tabPageAt(i
);
211 viewContainers
<< tabPage
->primaryViewContainer();
212 if (tabPage
->splitViewEnabled()) {
213 viewContainers
<< tabPage
->secondaryViewContainer();
216 return viewContainers
;
219 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
221 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
222 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
224 // Only consider local dirs, not remote locations and abstract protocols
225 if (viewContainer
->url().isLocalFile()) {
226 if (!QFileInfo::exists(viewContainer
->url().toLocalFile())) {
227 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
233 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
235 m_tabWidget
->openDirectories(dirs
, splitView
);
238 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
240 openDirectories(QUrl::fromStringList(dirs
), splitView
);
243 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
245 m_tabWidget
->openFiles(files
, splitView
);
248 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
250 openFiles(QUrl::fromStringList(files
), splitView
);
253 void DolphinMainWindow::activateWindow()
255 window()->setAttribute(Qt::WA_NativeWindow
, true);
256 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
257 KWindowSystem::activateWindow(window()->effectiveWinId());
260 void DolphinMainWindow::showCommand(CommandType command
)
262 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
264 case KIO::FileUndoManager::Copy
:
265 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
267 case KIO::FileUndoManager::Move
:
268 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
270 case KIO::FileUndoManager::Link
:
271 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
273 case KIO::FileUndoManager::Trash
:
274 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
276 case KIO::FileUndoManager::Rename
:
277 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
280 case KIO::FileUndoManager::Mkdir
:
281 statusBar
->setText(i18nc("@info:status", "Created folder."));
289 void DolphinMainWindow::pasteIntoFolder()
291 m_activeViewContainer
->view()->pasteIntoFolder();
294 void DolphinMainWindow::changeUrl(const QUrl
&url
)
296 if (!KProtocolManager::supportsListing(url
)) {
297 // The URL navigator only checks for validity, not
298 // if the URL can be listed. An error message is
299 // shown due to DolphinViewContainer::restoreView().
303 m_activeViewContainer
->setUrl(url
);
304 updateFileAndEditActions();
309 emit
urlChanged(url
);
312 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
314 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
315 m_placesPanel
->proceedWithTearDown();
316 m_tearDownFromPlacesRequested
= false;
319 m_activeViewContainer
->setAutoGrabFocus(false);
321 m_activeViewContainer
->setAutoGrabFocus(true);
324 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
326 KToggleAction
* editableLocationAction
=
327 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
328 editableLocationAction
->setChecked(editable
);
331 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
333 updateFileAndEditActions();
335 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
337 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
338 if (selectedUrlsCount
== 2) {
339 compareFilesAction
->setEnabled(isKompareInstalled());
341 compareFilesAction
->setEnabled(false);
344 emit
selectionChanged(selection
);
347 void DolphinMainWindow::updateHistory()
349 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
350 const int index
= urlNavigator
->historyIndex();
352 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
354 backAction
->setToolTip(i18nc("@info", "Go back"));
355 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
356 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
359 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
361 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
362 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
363 "This undoes a <interface>Go|Back</interface> action."));
364 forwardAction
->setEnabled(index
> 0);
368 void DolphinMainWindow::updateFilterBarAction(bool show
)
370 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
371 showFilterBarAction
->setChecked(show
);
374 void DolphinMainWindow::openNewMainWindow()
376 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
379 void DolphinMainWindow::openNewActivatedTab()
381 m_tabWidget
->openNewActivatedTab();
384 void DolphinMainWindow::addToPlaces()
389 // If nothing is selected, act on the current dir
390 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
391 url
= m_activeViewContainer
->url();
392 name
= m_activeViewContainer
->placesText();
394 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
395 url
= dirToAdd
.url();
396 name
= dirToAdd
.name();
399 PlacesItemModel model
;
401 if (m_activeViewContainer
->isSearchModeEnabled()) {
402 icon
= QStringLiteral("folder-saved-search-symbolic");
404 icon
= KIO::iconNameForUrl(url
);
406 model
.createPlacesItem(name
, url
, icon
);
410 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
412 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
415 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
417 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
420 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
422 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
425 void DolphinMainWindow::openInNewTab()
427 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
428 bool tabCreated
= false;
430 foreach (const KFileItem
& item
, list
) {
431 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
432 if (!url
.isEmpty()) {
433 openNewTabAfterCurrentTab(url
);
438 // if no new tab has been created from the selection
439 // open the current directory in a new tab
441 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
445 void DolphinMainWindow::openInNewWindow()
449 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
450 if (list
.isEmpty()) {
451 newWindowUrl
= m_activeViewContainer
->url();
452 } else if (list
.count() == 1) {
453 const KFileItem
& item
= list
.first();
454 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
457 if (!newWindowUrl
.isEmpty()) {
458 Dolphin::openNewWindow({newWindowUrl
}, this);
462 void DolphinMainWindow::showTarget()
464 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
465 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
466 auto linkDestination
= link
.linkDest();
467 if (QFileInfo(linkDestination
).isRelative()) {
468 linkDestination
= linkLocationDir
.filePath(linkDestination
);
470 if (QFileInfo::exists(linkDestination
)) {
471 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
473 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
474 DolphinViewContainer::Warning
);
478 void DolphinMainWindow::showEvent(QShowEvent
* event
)
480 KXmlGuiWindow::showEvent(event
);
482 if (!event
->spontaneous()) {
483 m_activeViewContainer
->view()->setFocus();
487 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
489 // Find out if Dolphin is closed directly by the user or
490 // by the session manager because the session is closed
491 bool closedByUser
= true;
492 if (qApp
->isSavingSession()) {
493 closedByUser
= false;
496 if (m_tabWidget
->count() > 1
497 && GeneralSettings::confirmClosingMultipleTabs()
498 && !GeneralSettings::rememberOpenedTabs()
500 // Ask the user if he really wants to quit and close all tabs.
501 // Open a confirmation dialog with 3 buttons:
502 // QDialogButtonBox::Yes -> Quit
503 // QDialogButtonBox::No -> Close only the current tab
504 // QDialogButtonBox::Cancel -> do nothing
505 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
506 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
507 dialog
->setModal(true);
508 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
509 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
510 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
511 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
512 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
514 bool doNotAskAgainCheckboxResult
= false;
516 const auto result
= KMessageBox::createKMessageBox(dialog
,
518 QMessageBox::Warning
,
519 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
521 i18n("Do not ask again"),
522 &doNotAskAgainCheckboxResult
,
523 KMessageBox::Notify
);
525 if (doNotAskAgainCheckboxResult
) {
526 GeneralSettings::setConfirmClosingMultipleTabs(false);
530 case QDialogButtonBox::Yes
:
533 case QDialogButtonBox::No
:
534 // Close only the current tab
535 m_tabWidget
->closeTab();
543 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
544 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
545 // Open a confirmation dialog with 3 buttons:
546 // QDialogButtonBox::Yes -> Quit
547 // QDialogButtonBox::No -> Show Terminal Panel
548 // QDialogButtonBox::Cancel -> do nothing
549 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
550 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
551 dialog
->setModal(true);
552 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
553 if (!m_terminalPanel
->isVisible()) {
554 standardButtons
|= QDialogButtonBox::No
;
556 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
557 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
558 if (!m_terminalPanel
->isVisible()) {
560 buttons
->button(QDialogButtonBox::No
),
561 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
563 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
565 bool doNotAskAgainCheckboxResult
= false;
567 const auto result
= KMessageBox::createKMessageBox(
570 QMessageBox::Warning
,
571 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
573 i18n("Do not ask again"),
574 &doNotAskAgainCheckboxResult
,
575 KMessageBox::Dangerous
);
577 if (doNotAskAgainCheckboxResult
) {
578 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
582 case QDialogButtonBox::Yes
:
585 case QDialogButtonBox::No
:
586 actionCollection()->action("show_terminal_panel")->trigger();
587 // Do not quit, ignore quit event
595 if (GeneralSettings::rememberOpenedTabs()) {
596 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
597 KConfig
*config
= KConfigGui::sessionConfig();
598 saveGlobalProperties(config
);
599 savePropertiesInternal(config
, 1);
603 GeneralSettings::setVersion(CurrentDolphinVersion
);
604 GeneralSettings::self()->save();
606 KXmlGuiWindow::closeEvent(event
);
609 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
611 m_tabWidget
->saveProperties(group
);
614 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
616 m_tabWidget
->readProperties(group
);
619 void DolphinMainWindow::updateNewMenu()
621 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
622 m_newFileMenu
->checkUpToDate();
623 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
626 void DolphinMainWindow::createDirectory()
628 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
629 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
630 m_newFileMenu
->createDirectory();
633 void DolphinMainWindow::quit()
638 void DolphinMainWindow::showErrorMessage(const QString
& message
)
640 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
643 void DolphinMainWindow::slotUndoAvailable(bool available
)
645 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
647 undoAction
->setEnabled(available
);
651 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
653 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
655 undoAction
->setText(text
);
659 void DolphinMainWindow::undo()
662 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
663 KIO::FileUndoManager::self()->undo();
666 void DolphinMainWindow::cut()
668 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
671 void DolphinMainWindow::copy()
673 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
676 void DolphinMainWindow::paste()
678 m_activeViewContainer
->view()->paste();
681 void DolphinMainWindow::find()
683 m_activeViewContainer
->setSearchModeEnabled(true);
686 void DolphinMainWindow::updateSearchAction()
688 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
689 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
692 void DolphinMainWindow::updatePasteAction()
694 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
695 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
696 pasteAction
->setEnabled(pasteInfo
.first
);
697 pasteAction
->setText(pasteInfo
.second
);
700 void DolphinMainWindow::slotDirectoryLoadingCompleted()
705 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
707 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
709 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
711 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
713 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
718 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
720 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
722 m_backAction
->menu()->clear();
723 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
724 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
726 m_backAction
->menu()->addAction(action
);
730 void DolphinMainWindow::slotGoBack(QAction
* action
)
732 int gotoIndex
= action
->data().value
<int>();
733 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
734 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
739 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
742 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
743 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
747 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
749 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
751 m_forwardAction
->menu()->clear();
752 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
753 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
755 m_forwardAction
->menu()->addAction(action
);
759 void DolphinMainWindow::slotGoForward(QAction
* action
)
761 int gotoIndex
= action
->data().value
<int>();
762 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
763 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
768 void DolphinMainWindow::selectAll()
772 // if the URL navigator is editable and focused, select the whole
773 // URL instead of all items of the view
775 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
776 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
777 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
778 lineEdit
->hasFocus();
780 lineEdit
->selectAll();
782 m_activeViewContainer
->view()->selectAll();
786 void DolphinMainWindow::invertSelection()
789 m_activeViewContainer
->view()->invertSelection();
792 void DolphinMainWindow::toggleSplitView()
794 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
795 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
800 void DolphinMainWindow::toggleSplitStash()
802 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
803 tabPage
->setSplitViewEnabled(false);
804 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
807 void DolphinMainWindow::reloadView()
810 m_activeViewContainer
->reload();
811 m_activeViewContainer
->statusBar()->updateSpaceInfo();
814 void DolphinMainWindow::stopLoading()
816 m_activeViewContainer
->view()->stopLoading();
819 void DolphinMainWindow::enableStopAction()
821 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
824 void DolphinMainWindow::disableStopAction()
826 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
829 void DolphinMainWindow::showFilterBar()
831 m_activeViewContainer
->setFilterBarVisible(true);
834 void DolphinMainWindow::toggleEditLocation()
838 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
839 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
840 urlNavigator
->setUrlEditable(action
->isChecked());
843 void DolphinMainWindow::replaceLocation()
845 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
846 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
848 // If the text field currently has focus and everything is selected,
849 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
850 if (navigator
->isUrlEditable()
851 && lineEdit
->hasFocus()
852 && lineEdit
->selectedText() == lineEdit
->text() ) {
853 navigator
->setUrlEditable(false);
855 navigator
->setUrlEditable(true);
856 navigator
->setFocus();
857 lineEdit
->selectAll();
861 void DolphinMainWindow::togglePanelLockState()
863 const bool newLockState
= !GeneralSettings::lockPanels();
864 foreach (QObject
* child
, children()) {
865 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
867 dock
->setLocked(newLockState
);
871 GeneralSettings::setLockPanels(newLockState
);
874 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
876 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
877 m_activeViewContainer
->view()->setFocus();
881 void DolphinMainWindow::goBack()
883 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
884 urlNavigator
->goBack();
886 if (urlNavigator
->locationState().isEmpty()) {
887 // An empty location state indicates a redirection URL,
888 // which must be skipped too
889 urlNavigator
->goBack();
893 void DolphinMainWindow::goForward()
895 m_activeViewContainer
->urlNavigator()->goForward();
898 void DolphinMainWindow::goUp()
900 m_activeViewContainer
->urlNavigator()->goUp();
903 void DolphinMainWindow::goHome()
905 m_activeViewContainer
->urlNavigator()->goHome();
908 void DolphinMainWindow::goBackInNewTab()
910 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
911 const int index
= urlNavigator
->historyIndex() + 1;
912 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
915 void DolphinMainWindow::goForwardInNewTab()
917 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
918 const int index
= urlNavigator
->historyIndex() - 1;
919 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
922 void DolphinMainWindow::goUpInNewTab()
924 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
925 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
928 void DolphinMainWindow::goHomeInNewTab()
930 openNewTabAfterCurrentTab(Dolphin::homeUrl());
933 void DolphinMainWindow::compareFiles()
935 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
936 if (items
.count() != 2) {
937 // The action is disabled in this case, but it could have been triggered
938 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
942 QUrl urlA
= items
.at(0).url();
943 QUrl urlB
= items
.at(1).url();
945 QString
command(QStringLiteral("kompare -c \""));
946 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
947 command
.append("\" \"");
948 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
949 command
.append('\"');
951 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
952 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
956 void DolphinMainWindow::toggleShowMenuBar()
958 const bool visible
= menuBar()->isVisible();
959 menuBar()->setVisible(!visible
);
961 createControlButton();
963 deleteControlButton();
967 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
969 m_searchTools
.clear();
970 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
971 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
973 QList
<QAction
*> actions
= m_searchTools
.actions();
974 if (actions
.isEmpty()) {
977 QAction
* action
= actions
.first();
978 if (action
->isSeparator()) {
984 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
986 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
987 if (!openPreferredSearchTool
) {
990 QPointer
<QAction
> tool
= preferredSearchTool();
992 openPreferredSearchTool
->setVisible(true);
993 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
994 openPreferredSearchTool
->setIcon(tool
->icon());
996 openPreferredSearchTool
->setVisible(false);
997 // still visible in Shortcuts configuration window
998 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
999 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1003 void DolphinMainWindow::openPreferredSearchTool()
1005 QPointer
<QAction
> tool
= preferredSearchTool();
1011 void DolphinMainWindow::openTerminal()
1013 const QUrl url
= m_activeViewContainer
->url();
1015 if (url
.isLocalFile()) {
1016 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1020 // Not a local file, with protocol Class ":local", try stat'ing
1021 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1022 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1023 KJobWidgets::setWindow(job
, this);
1024 connect(job
, &KJob::result
, this, [job
]() {
1026 if (!job
->error()) {
1027 statUrl
= job
->mostLocalUrl();
1030 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1036 // Nothing worked, just use $HOME
1037 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1040 void DolphinMainWindow::editSettings()
1042 if (!m_settingsDialog
) {
1043 DolphinViewContainer
* container
= activeViewContainer();
1044 container
->view()->writeSettings();
1046 const QUrl url
= container
->url();
1047 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1048 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1049 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1050 settingsDialog
->show();
1051 m_settingsDialog
= settingsDialog
;
1053 m_settingsDialog
.data()->raise();
1057 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1059 delete m_lastHandleUrlOpenJob
;
1060 m_lastHandleUrlOpenJob
= nullptr;
1062 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1063 activeViewContainer()->setUrl(url
);
1065 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1066 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1067 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1069 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1070 [this, url
](const QString
&mimetype
) {
1071 if (mimetype
== QLatin1String("inode/directory")) {
1072 // If it's a dir, we'll take it from here
1073 m_lastHandleUrlOpenJob
->kill();
1074 m_lastHandleUrlOpenJob
= nullptr;
1075 activeViewContainer()->setUrl(url
);
1079 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1080 m_lastHandleUrlOpenJob
= nullptr;
1083 m_lastHandleUrlOpenJob
->start();
1087 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1089 // trash:/ is writable but we don't want to create new items in it.
1090 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1091 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1094 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1095 const KFileItem
& item
,
1097 const QList
<QAction
*>& customActions
)
1099 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1100 contextMenu
.data()->setCustomActions(customActions
);
1101 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1104 case DolphinContextMenu::OpenParentFolder
:
1105 changeUrl(KIO::upUrl(item
.url()));
1106 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1107 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1110 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1111 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1114 case DolphinContextMenu::OpenParentFolderInNewTab
:
1115 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1118 case DolphinContextMenu::None
:
1123 // Delete the menu, unless it has been deleted in its own nested event loop already.
1125 contextMenu
->deleteLater();
1129 void DolphinMainWindow::updateControlMenu()
1131 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1134 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1135 // because 'menu' is their parent.
1138 KActionCollection
* ac
= actionCollection();
1140 menu
->addMenu(m_newFileMenu
->menu());
1141 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1142 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1143 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1145 menu
->addSeparator();
1147 // Add "Edit" actions
1148 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1149 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1150 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1151 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1152 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1153 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1156 menu
->addSeparator();
1159 // Add "View" actions
1160 if (!GeneralSettings::showZoomSlider()) {
1161 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1162 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1163 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1164 menu
->addSeparator();
1167 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1168 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1169 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1170 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1171 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1174 menu
->addSeparator();
1177 // Add a curated assortment of items from the "Tools" menu
1178 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1179 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1180 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1182 menu
->addSeparator();
1184 // Add "Show Panels" menu
1185 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1187 // Add "Settings" menu entries
1188 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1189 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1190 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1191 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1194 auto helpMenu
= m_helpMenu
->menu();
1195 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1196 menu
->addMenu(helpMenu
);
1199 void DolphinMainWindow::updateToolBar()
1201 if (!menuBar()->isVisible()) {
1202 createControlButton();
1206 void DolphinMainWindow::slotControlButtonDeleted()
1208 m_controlButton
= nullptr;
1209 m_updateToolBarTimer
->start();
1212 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1214 DolphinViewContainer
* view
= activeViewContainer();
1216 if (view
->url() == url
) {
1217 // We can end up here if the user clicked a device in the Places Panel
1218 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1225 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1227 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1230 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1232 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1233 Q_ASSERT(viewContainer
);
1235 m_activeViewContainer
= viewContainer
;
1237 if (oldViewContainer
) {
1238 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1239 toggleSearchAction
->disconnect(oldViewContainer
);
1241 // Disconnect all signals between the old view container (container,
1242 // view and url navigator) and main window.
1243 oldViewContainer
->disconnect(this);
1244 oldViewContainer
->view()->disconnect(this);
1245 oldViewContainer
->urlNavigator()->disconnect(this);
1247 // except the requestItemInfo so that on hover the information panel can still be updated
1248 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1249 this, &DolphinMainWindow::requestItemInfo
);
1252 connectViewSignals(viewContainer
);
1254 m_actionHandler
->setCurrentView(viewContainer
->view());
1257 updateFileAndEditActions();
1258 updatePasteAction();
1259 updateViewActions();
1261 updateSearchAction();
1263 const QUrl url
= viewContainer
->url();
1264 emit
urlChanged(url
);
1267 void DolphinMainWindow::tabCountChanged(int count
)
1269 const bool enableTabActions
= (count
> 1);
1270 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1271 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1273 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1274 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1275 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1278 void DolphinMainWindow::updateWindowTitle()
1280 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1281 if (windowTitle() != newTitle
) {
1282 setWindowTitle(newTitle
);
1286 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1288 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1289 setViewsToHomeIfMountPathOpen(mountPath
);
1292 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1293 m_tearDownFromPlacesRequested
= true;
1294 m_terminalPanel
->goHome();
1295 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1297 m_placesPanel
->proceedWithTearDown();
1301 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1303 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1304 setViewsToHomeIfMountPathOpen(mountPath
);
1307 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1308 m_tearDownFromPlacesRequested
= false;
1309 m_terminalPanel
->goHome();
1313 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1315 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1316 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1317 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1318 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1321 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1324 void DolphinMainWindow::setupActions()
1326 // setup 'File' menu
1327 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1328 QMenu
* menu
= m_newFileMenu
->menu();
1329 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1330 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1331 m_newFileMenu
->setDelayed(false);
1332 connect(menu
, &QMenu::aboutToShow
,
1333 this, &DolphinMainWindow::updateNewMenu
);
1335 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1336 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1337 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1338 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1339 "window just like this one with the current location and view."
1340 "<nl/>You can drag and drop items between windows."));
1341 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1343 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1344 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1345 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1346 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1347 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1348 "A tab is an additional view within this window. "
1349 "You can drag and drop items between tabs."));
1350 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1351 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1353 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1354 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1355 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1356 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1357 "to the Places panel."));
1358 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1360 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1361 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1362 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1363 "currently viewed tab. If no more tabs are left this window "
1364 "will close instead."));
1366 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1367 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1369 // setup 'Edit' menu
1370 KStandardAction::undo(this,
1371 &DolphinMainWindow::undo
,
1372 actionCollection());
1374 // i18n: This will be the last paragraph for the whatsthis for all three:
1375 // Cut, Copy and Paste
1376 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1377 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1378 "applications and are among the most used commands. That's why their "
1379 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1380 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1381 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1382 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1383 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1384 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1385 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1386 "the clipboard to a new location. The items will be removed from their "
1387 "initial location.") + cutCopyPastePara
);
1388 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1389 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1390 "items in your current selection to the <emphasis>clipboard</emphasis>."
1391 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1392 "from the clipboard to a new location.") + cutCopyPastePara
);
1393 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1394 // The text of the paste-action is modified dynamically by Dolphin
1395 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1396 // due to the long text, the text "Paste" is used:
1397 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1398 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1399 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1400 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1401 "action they are removed from their old location.") + cutCopyPastePara
);
1403 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1404 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1405 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1406 "the <emphasis>active</emphasis> view to the inactive split view."));
1407 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1408 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1409 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1410 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1412 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1413 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1414 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1415 "the <emphasis>active</emphasis> view to the inactive split view."));
1416 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1417 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1418 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1419 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1421 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1422 searchAction
->setText(i18n("Search..."));
1423 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1424 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1425 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1426 "There you can enter search terms and specify settings to find the "
1427 "objects you are looking for.</para><para>Use this help again on "
1428 "the find bar so we can have a look at it while the settings are "
1429 "explained.</para>"));
1431 // toggle_search acts as a copy of the main searchAction to be used mainly
1432 // in the toolbar, with no default shortcut attached, to avoid messing with
1433 // existing workflows (search bar always open and Ctrl-F to focus)
1434 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1435 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1436 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1437 toggleSearchAction
->setIcon(searchAction
->icon());
1438 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1439 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1440 toggleSearchAction
->setCheckable(true);
1442 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1443 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1444 "files and folders in the current location."));
1446 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1447 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1448 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1449 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1450 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1451 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1452 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1454 // setup 'View' menu
1455 // (note that most of it is set up in DolphinViewActionHandler)
1457 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1458 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1459 "the folder view below into two autonomous views.</para><para>This "
1460 "way you can see two locations at once and move items between them "
1461 "quickly.</para>Click this again afterwards to recombine the views."));
1462 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1463 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1465 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1466 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1467 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1468 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1469 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1470 stashSplit
->setCheckable(false);
1471 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1472 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1474 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1476 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1477 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1478 stop
->setToolTip(i18nc("@info", "Stop loading"));
1479 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1480 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1481 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1483 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1484 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1485 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1486 "This toggles the <emphasis>Location Bar</emphasis> to be "
1487 "editable so you can directly enter a location you want to go to.<nl/>"
1488 "You can also switch to editing by clicking to the right of the "
1489 "location and switch back by confirming the edited location."));
1490 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1491 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1493 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1494 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1495 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1496 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1497 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1498 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1499 "This switches to editing the location and selects it "
1500 "so you can quickly enter a different location."));
1501 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1502 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1506 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1507 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1508 m_backAction
->setObjectName(backAction
->objectName());
1509 m_backAction
->setShortcuts(backAction
->shortcuts());
1511 m_backAction
->setDelayed(true);
1512 m_backAction
->setStickyMenu(false);
1513 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1514 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1515 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1516 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1518 auto backShortcuts
= m_backAction
->shortcuts();
1519 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1520 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1522 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1523 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1524 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1525 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1526 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1527 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1528 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1529 this, &DolphinMainWindow::closedTabsCountChanged
);
1531 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1532 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1533 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1534 "This returns you to the previously closed tab."));
1535 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1536 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1537 undoCloseTab
->setEnabled(false);
1538 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1540 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1541 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1542 "the last change you made to files or folders.<nl/>"
1543 "Such changes include <interface>creating, renaming</interface> "
1544 "and <interface>moving</interface> them to a different location "
1545 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1546 "be undone will ask for your confirmation."));
1547 undoAction
->setEnabled(false); // undo should be disabled by default
1550 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1551 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1552 m_forwardAction
->setObjectName(forwardAction
->objectName());
1553 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1555 m_forwardAction
->setDelayed(true);
1556 m_forwardAction
->setStickyMenu(false);
1557 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1558 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1559 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1560 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1561 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1563 // enable middle-click to open in a new tab
1564 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1565 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1566 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1567 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1568 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1569 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1570 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1571 "<filename>Home</filename> folder.<nl/>Every user account "
1572 "has their own <filename>Home</filename> that contains their data "
1573 "including folders that contain personal application data."));
1575 // setup 'Tools' menu
1576 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1577 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1578 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1579 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1580 "There you can enter a text to filter the files and folders currently displayed. "
1581 "Only those that contain the text in their name will be kept in view."));
1582 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1583 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1584 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1586 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1587 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1588 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1589 compareFiles
->setEnabled(false);
1590 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1592 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1593 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1594 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1595 "<para>This opens a preferred search tool for the viewed location.</para>"
1596 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1597 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1598 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1599 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1601 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1602 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1603 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1604 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1605 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1606 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1607 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1608 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1609 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1611 #ifdef HAVE_TERMINAL
1612 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1613 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1614 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1615 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1616 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1620 // setup 'Bookmarks' menu
1621 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1622 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1623 // Make the toolbar button version work properly on click
1624 bookmarkMenu
->setDelayed(false);
1625 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1626 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1628 // setup 'Settings' menu
1629 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1630 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1631 "This switches between having a <emphasis>Menubar</emphasis> "
1632 "and having a <interface>Control</interface> button. Both "
1633 "contain mostly the same commands and configuration options."));
1634 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1635 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1636 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1638 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1639 m_helpMenu
= new KHelpMenu(nullptr);
1640 m_helpMenu
->menu()->installEventFilter(this);
1641 // remove duplicate shortcuts
1642 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1643 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1645 // not in menu actions
1646 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1647 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1649 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1650 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1652 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1653 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1654 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1655 activateTab
->setEnabled(false);
1656 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1658 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1660 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1664 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1665 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1666 activateLastTab
->setEnabled(false);
1667 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1668 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1670 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1671 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1672 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1673 activateNextTab
->setEnabled(false);
1674 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1675 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1677 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1678 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1679 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1680 activatePrevTab
->setEnabled(false);
1681 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1682 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1685 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1686 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1687 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1688 showTarget
->setEnabled(false);
1689 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1691 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1692 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1693 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1694 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1696 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1697 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1698 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1699 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1701 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1702 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1703 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1704 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1707 void DolphinMainWindow::setupDockWidgets()
1709 const bool lock
= GeneralSettings::lockPanels();
1711 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1712 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1713 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1714 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1715 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1716 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1717 "switches between having panels <emphasis>locked</emphasis> or "
1718 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1719 "dragged to the other side of the window and have a close "
1720 "button.<nl/>Locked panels are embedded more cleanly."));
1721 lockLayoutAction
->setActive(lock
);
1722 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1724 // Setup "Information"
1725 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1726 infoDock
->setLocked(lock
);
1727 infoDock
->setObjectName(QStringLiteral("infoDock"));
1728 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1731 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1732 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1733 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1734 infoDock
->setWidget(infoPanel
);
1736 QAction
* infoAction
= infoDock
->toggleViewAction();
1737 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1739 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1740 connect(this, &DolphinMainWindow::urlChanged
,
1741 infoPanel
, &InformationPanel::setUrl
);
1742 connect(this, &DolphinMainWindow::selectionChanged
,
1743 infoPanel
, &InformationPanel::setSelection
);
1744 connect(this, &DolphinMainWindow::requestItemInfo
,
1745 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1748 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1749 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1750 "hide panels like this go to <interface>Control|Panels</interface> "
1751 "or <interface>View|Panels</interface>.</para>");
1753 actionCollection()->action(QStringLiteral("show_information_panel"))
1754 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1755 "<emphasis>information</emphasis> panel at the right side of the "
1756 "window.</para><para>The panel provides in-depth information "
1757 "about the items your mouse is hovering over or about the selected "
1758 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1759 "For single items a preview of their contents is provided.</para>"));
1761 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1762 "provides in-depth information about the items your mouse is "
1763 "hovering over or about the selected items. Otherwise it informs "
1764 "you about the currently viewed folder.<nl/>For single items a "
1765 "preview of their contents is provided.</para><para>You can configure "
1766 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1769 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1770 foldersDock
->setLocked(lock
);
1771 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1772 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1773 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1774 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1775 foldersDock
->setWidget(foldersPanel
);
1777 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1778 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1780 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1781 connect(this, &DolphinMainWindow::urlChanged
,
1782 foldersPanel
, &FoldersPanel::setUrl
);
1783 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1784 this, &DolphinMainWindow::changeUrl
);
1785 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1786 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1787 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1788 this, &DolphinMainWindow::showErrorMessage
);
1790 actionCollection()->action(QStringLiteral("show_folders_panel"))
1791 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1792 "<emphasis>folders</emphasis> panel at the left side of the window."
1793 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1794 "</emphasis> in a <emphasis>tree view</emphasis>."));
1795 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1796 "shows the folders of the <emphasis>file system</emphasis> in a "
1797 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1798 "there. Click the arrow to the left of a folder to see its subfolders. "
1799 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1802 #ifdef HAVE_TERMINAL
1803 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1804 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1805 terminalDock
->setLocked(lock
);
1806 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1807 m_terminalPanel
= new TerminalPanel(terminalDock
);
1808 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1809 terminalDock
->setWidget(m_terminalPanel
);
1811 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1812 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1813 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1814 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1815 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1816 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1818 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1819 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1821 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1822 connect(this, &DolphinMainWindow::urlChanged
,
1823 m_terminalPanel
, &TerminalPanel::setUrl
);
1825 if (GeneralSettings::version() < 200) {
1826 terminalDock
->hide();
1829 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1830 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1831 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1832 "<nl/>The location in the terminal will always match the folder "
1833 "view so you can navigate using either.</para><para>The terminal "
1834 "panel is not needed for basic computer usage but can be useful "
1835 "for advanced tasks. To learn more about terminals use the help "
1836 "in a standalone terminal application like Konsole.</para>"));
1837 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1838 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1839 "normal terminal but will match the location of the folder view "
1840 "so you can navigate using either.</para><para>The terminal panel "
1841 "is not needed for basic computer usage but can be useful for "
1842 "advanced tasks. To learn more about terminals use the help in a "
1843 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1847 if (GeneralSettings::version() < 200) {
1849 foldersDock
->hide();
1853 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1854 placesDock
->setLocked(lock
);
1855 placesDock
->setObjectName(QStringLiteral("placesDock"));
1856 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1858 m_placesPanel
= new PlacesPanel(placesDock
);
1859 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1860 placesDock
->setWidget(m_placesPanel
);
1862 QAction
*placesAction
= placesDock
->toggleViewAction();
1863 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1865 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1866 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1867 this, &DolphinMainWindow::slotPlaceActivated
);
1868 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1869 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1870 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1871 this, &DolphinMainWindow::showErrorMessage
);
1872 connect(this, &DolphinMainWindow::urlChanged
,
1873 m_placesPanel
, &PlacesPanel::setUrl
);
1874 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1875 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1876 connect(this, &DolphinMainWindow::settingsChanged
,
1877 m_placesPanel
, &PlacesPanel::readSettings
);
1878 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1879 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1880 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1881 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1882 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1884 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1885 actionShowAllPlaces
->setCheckable(true);
1886 actionShowAllPlaces
->setDisabled(true);
1887 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1888 "all places in the places panel that have been hidden. They will "
1889 "appear semi-transparent unless you uncheck their hide property."));
1891 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1892 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1893 m_placesPanel
->showHiddenEntries(checked
);
1896 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1897 actionShowAllPlaces
->setChecked(checked
);
1898 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1901 actionCollection()->action(QStringLiteral("show_places_panel"))
1902 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1903 "<emphasis>places</emphasis> panel at the left side of the window."
1904 "</para><para>It allows you to go to locations you have "
1905 "bookmarked and to access disk or media attached to the computer "
1906 "or to the network. It also contains sections to find recently "
1907 "saved files or files of a certain type.</para>"));
1908 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1909 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1910 "you have bookmarked and to access disk or media attached to the "
1911 "computer or to the network. It also contains sections to find "
1912 "recently saved files or files of a certain type.</para><para>"
1913 "Click on an entry to go there. Click with the right mouse button "
1914 "instead to open any entry in a new tab or new window.</para>"
1915 "<para>New entries can be added by dragging folders onto this panel. "
1916 "Right-click any section or entry to hide it. Right-click an empty "
1917 "space on this panel and select <interface>Show Hidden Places"
1918 "</interface> to display it again.</para>") + panelWhatsThis
);
1920 // Add actions into the "Panels" menu
1921 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1922 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1923 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1924 panelsMenu
->setDelayed(false);
1925 const KActionCollection
* ac
= actionCollection();
1926 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1928 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1930 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1931 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1932 panelsMenu
->addSeparator();
1933 panelsMenu
->addAction(actionShowAllPlaces
);
1934 panelsMenu
->addAction(lockLayoutAction
);
1936 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1937 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1942 void DolphinMainWindow::updateFileAndEditActions()
1944 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1945 const KActionCollection
* col
= actionCollection();
1946 KFileItemListProperties
capabilitiesSource(list
);
1948 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1949 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1950 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1951 QAction
* copyLocation
= col
->action(QString("copy_location"));
1953 if (list
.isEmpty()) {
1954 stateChanged(QStringLiteral("has_no_selection"));
1956 addToPlacesAction
->setEnabled(true);
1957 copyToOtherViewAction
->setEnabled(false);
1958 moveToOtherViewAction
->setEnabled(false);
1959 copyLocation
->setEnabled(false);
1961 stateChanged(QStringLiteral("has_selection"));
1963 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1964 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1965 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1966 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1967 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1968 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1969 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1971 if (list
.length() == 1 && list
.first().isDir()) {
1972 addToPlacesAction
->setEnabled(true);
1974 addToPlacesAction
->setEnabled(false);
1977 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
1978 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
1979 KFileItem capabilitiesDestination
;
1981 if (tabPage
->primaryViewActive()) {
1982 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
1984 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
1987 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
1988 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
1990 copyToOtherViewAction
->setEnabled(false);
1991 moveToOtherViewAction
->setEnabled(false);
1994 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
1996 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
1997 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1998 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
1999 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2000 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2001 copyLocation
->setEnabled(list
.length() == 1);
2002 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2003 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2007 void DolphinMainWindow::updateViewActions()
2009 m_actionHandler
->updateViewActions();
2011 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
2012 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2014 updateSplitAction();
2016 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2017 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
2018 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
2021 void DolphinMainWindow::updateGoActions()
2023 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2024 const QUrl currentUrl
= m_activeViewContainer
->url();
2025 // I think this is one of the best places to firstly be confronted
2026 // with a file system and its hierarchy. Talking about the root
2027 // directory might seem too much here but it is the question that
2028 // naturally arises in this context.
2029 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2030 "the folder that contains the currently viewed one.</para>"
2031 "<para>All files and folders are organized in a hierarchical "
2032 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2033 "a directory that contains all data connected to this computer"
2034 "—the <emphasis>root directory</emphasis>.</para>"));
2035 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2038 void DolphinMainWindow::createControlButton()
2040 if (m_controlButton
) {
2043 Q_ASSERT(!m_controlButton
);
2045 m_controlButton
= new QToolButton(this);
2046 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2047 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2048 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2049 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2050 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2052 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2053 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2054 controlMenu
->installEventFilter(this);
2056 m_controlButton
->setMenu(controlMenu
);
2058 toolBar()->addWidget(m_controlButton
);
2059 connect(toolBar(), &KToolBar::iconSizeChanged
,
2060 m_controlButton
, &QToolButton::setIconSize
);
2062 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2063 // gets edited. In this case we must add them again. The adding is done asynchronously by
2064 // m_updateToolBarTimer.
2065 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2066 m_updateToolBarTimer
= new QTimer(this);
2067 m_updateToolBarTimer
->setInterval(500);
2068 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2071 void DolphinMainWindow::deleteControlButton()
2073 delete m_controlButton
;
2074 m_controlButton
= nullptr;
2076 delete m_updateToolBarTimer
;
2077 m_updateToolBarTimer
= nullptr;
2080 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2085 const KToolBar
* toolBarWidget
= toolBar();
2086 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2087 if (widget
== toolBarWidget
) {
2092 menu
->addAction(action
);
2096 void DolphinMainWindow::refreshViews()
2098 m_tabWidget
->refreshViews();
2100 if (GeneralSettings::modifiedStartupSettings()) {
2101 // The startup settings have been changed by the user (see bug #254947).
2102 // Synchronize the split-view setting with the active view:
2103 const bool splitView
= GeneralSettings::splitView();
2104 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2105 updateSplitAction();
2106 updateWindowTitle();
2109 emit
settingsChanged();
2112 void DolphinMainWindow::clearStatusBar()
2114 m_activeViewContainer
->statusBar()->resetToDefaultText();
2117 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2119 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2120 this, &DolphinMainWindow::updateFilterBarAction
);
2121 connect(container
, &DolphinViewContainer::writeStateChanged
,
2122 this, &DolphinMainWindow::slotWriteStateChanged
);
2123 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2124 this, &DolphinMainWindow::updateSearchAction
);
2126 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2127 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2129 const DolphinView
* view
= container
->view();
2130 connect(view
, &DolphinView::selectionChanged
,
2131 this, &DolphinMainWindow::slotSelectionChanged
);
2132 connect(view
, &DolphinView::requestItemInfo
,
2133 this, &DolphinMainWindow::requestItemInfo
);
2134 connect(view
, &DolphinView::tabRequested
,
2135 this, &DolphinMainWindow::openNewTab
);
2136 connect(view
, &DolphinView::requestContextMenu
,
2137 this, &DolphinMainWindow::openContextMenu
);
2138 connect(view
, &DolphinView::directoryLoadingStarted
,
2139 this, &DolphinMainWindow::enableStopAction
);
2140 connect(view
, &DolphinView::directoryLoadingCompleted
,
2141 this, &DolphinMainWindow::disableStopAction
);
2142 connect(view
, &DolphinView::directoryLoadingCompleted
,
2143 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2144 connect(view
, &DolphinView::goBackRequested
,
2145 this, &DolphinMainWindow::goBack
);
2146 connect(view
, &DolphinView::goForwardRequested
,
2147 this, &DolphinMainWindow::goForward
);
2148 connect(view
, &DolphinView::urlActivated
,
2149 this, &DolphinMainWindow::handleUrl
);
2150 connect(view
, &DolphinView::goUpRequested
,
2151 this, &DolphinMainWindow::goUp
);
2153 const KUrlNavigator
* navigator
= container
->urlNavigator();
2154 connect(navigator
, &KUrlNavigator::urlChanged
,
2155 this, &DolphinMainWindow::changeUrl
);
2156 connect(navigator
, &KUrlNavigator::historyChanged
,
2157 this, &DolphinMainWindow::updateHistory
);
2158 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2159 this, &DolphinMainWindow::slotEditableStateChanged
);
2160 connect(navigator
, &KUrlNavigator::tabRequested
,
2161 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2164 void DolphinMainWindow::updateSplitAction()
2166 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2167 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2168 if (tabPage
->splitViewEnabled()) {
2169 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2170 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2171 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2172 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2174 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2175 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2176 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2179 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2180 splitAction
->setToolTip(i18nc("@info", "Split view"));
2181 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2185 bool DolphinMainWindow::isKompareInstalled() const
2187 static bool initialized
= false;
2188 static bool installed
= false;
2190 // TODO: maybe replace this approach later by using a menu
2191 // plugin like kdiff3plugin.cpp
2192 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2198 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2199 const QKeySequence
& shortcut
,
2200 QAction
* dockAction
,
2201 const QString
& actionName
)
2203 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2204 panelAction
->setCheckable(true);
2205 panelAction
->setChecked(dockAction
->isChecked());
2206 panelAction
->setText(dockAction
->text());
2207 panelAction
->setIcon(icon
);
2208 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2210 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2211 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2214 void DolphinMainWindow::setupWhatsThis()
2217 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2218 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2219 "configuration options. Left-click on any of the menus on this "
2220 "bar to see its contents.</para><para>The Menubar can be hidden "
2221 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2222 "most of its contents become available through a <interface>Control"
2223 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2224 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2225 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2226 "frequently used actions.</para><para>It is highly customizable. "
2227 "All items you see in the <interface>Control</interface> menu or "
2228 "in the <interface>Menubar</interface> can be placed on the "
2229 "Toolbar. Just right-click on it and select <interface>Configure "
2230 "Toolbars…</interface> or find this action in the <interface>"
2231 "Control</interface> or <interface>Settings</interface> menu."
2232 "</para><para>The location of the bar and the style of its "
2233 "buttons can also be changed in the right-click menu. Right-click "
2234 "a button if you want to show or hide its text.</para>"));
2235 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2236 "<para>Here you can see the <emphasis>folders</emphasis> and "
2237 "<emphasis>files</emphasis> that are at the location described in "
2238 "the <interface>Location Bar</interface> above. This area is the "
2239 "central part of this application where you navigate to the files "
2240 "you want to use.</para><para>For an elaborate and general "
2241 "introduction to this application <link "
2242 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2243 "click here</link>. This will open an introductory article from "
2244 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2245 "explanations of all the features of this <emphasis>view</emphasis> "
2246 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2247 "instead. This will open a page from the <emphasis>Handbook"
2248 "</emphasis> that covers the basics.</para>"));
2251 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2252 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2253 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2254 "There you can set up key combinations to trigger an action when "
2255 "they are pressed simultaneously. All commands in this application can "
2256 "be triggered this way.</para>"));
2257 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2258 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2259 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2260 "<para>All items you see in the <interface>Control</interface> menu "
2261 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2262 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2263 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2264 "change a multitude of settings for this application. For an explanation "
2265 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2266 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2269 // The whatsthis has to be set for the m_helpMenu and for the
2270 // StandardAction separately because both are used in different locations.
2271 // m_helpMenu is only used for createControlButton() button.
2273 // Links do not work within the Menubar so texts without links are provided there.
2275 // i18n: If the external link isn't available in your language you should
2276 // probably state the external link language at least in brackets to not
2277 // frustrate the user. If there are multiple languages that the user might
2278 // know with a reasonable chance you might want to have 2 external links.
2279 // The same is in my opinion true for every external link you translate.
2280 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2281 "<para>This opens the Handbook for this application. It provides "
2282 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2283 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2284 ->setWhatsThis(whatsThisHelpContents
2285 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2286 "<para>If you want more elaborate introductions to the "
2287 "different features of <emphasis>Dolphin</emphasis> "
2288 "go to the KDE UserBase Wiki.</para>"));
2289 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2290 + xi18nc("@info:whatsthis second half of handbook text with link",
2291 "<para>If you want more elaborate introductions to the "
2292 "different features of <emphasis>Dolphin</emphasis> "
2293 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2294 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2296 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2297 "<para>This is the button that invokes the help feature you are "
2298 "using right now! Click it, then click any component of this "
2299 "application to ask \"What's this?\" about it. The mouse cursor "
2300 "will change appearance if no help is available for a spot.</para>");
2301 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2302 ->setWhatsThis(whatsThisWhatsThis
2303 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2304 "<para>There are two other ways to get help for this application: The "
2305 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2306 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2307 "article about <emphasis>File Management</emphasis> online."
2308 "</para><para>The \"What's this?\" help is "
2309 "missing in most other windows so don't get too used to this.</para>"));
2310 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2311 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2312 "<para>There are two other ways to get help: "
2313 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2314 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2315 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2316 "missing in most other windows so don't get too used to this.</para>"));
2318 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2319 "window that will guide you through reporting errors or flaws "
2320 "in this application or in other KDE software.</para>");
2321 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2322 ->setWhatsThis(whatsThisReportBug
);
2323 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2324 + xi18nc("@info:whatsthis second half of reportbug text with link",
2325 "<para>High-quality bug reports are much appreciated. To learn "
2326 "how to make your bug report as effective as possible "
2327 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2328 "click here</link>.</para>"));
2330 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2331 "<emphasis>web page</emphasis> where you can donate to "
2332 "support the continued work on this application and many "
2333 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2334 "<para>Donating is the easiest and fastest way to efficiently "
2335 "support KDE and its projects. KDE projects are available for "
2336 "free therefore your donation is needed to cover things that "
2337 "require money like servers, contributor meetings, etc.</para>"
2338 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2339 "organization behind the KDE community.</para>");
2340 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2341 ->setWhatsThis(whatsThisDonate
);
2342 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2344 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2345 "With this you can change the language this application uses."
2346 "<nl/>You can even set secondary languages which will be used "
2347 "if texts are not available in your preferred language.");
2348 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2349 ->setWhatsThis(whatsThisSwitchLanguage
);
2350 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2352 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2353 "window that informs you about the version, license, "
2354 "used libraries and maintainers of this application.");
2355 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2356 ->setWhatsThis(whatsThisAboutApp
);
2357 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2359 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2360 "window with information about <emphasis>KDE</emphasis>. "
2361 "The KDE community are the people behind this free software."
2362 "<nl/>If you like using this application but don't know "
2363 "about KDE or want to see a cute dragon have a look!");
2364 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2365 ->setWhatsThis(whatsThisAboutKDE
);
2366 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2369 bool DolphinMainWindow::event(QEvent
*event
)
2371 if (event
->type() == QEvent::WhatsThisClicked
) {
2373 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2374 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2377 return KXmlGuiWindow::event(event
);
2380 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2383 if (event
->type() == QEvent::WhatsThisClicked
) {
2385 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2386 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2392 void DolphinMainWindow::focusTerminalPanel()
2394 if (m_terminalPanel
->isVisible()) {
2395 if (m_terminalPanel
->terminalHasFocus()) {
2396 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2397 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2399 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2400 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2403 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2404 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2408 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2409 KIO::FileUndoManager::UiInterface()
2413 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2417 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2419 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2421 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2422 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2424 KIO::FileUndoManager::UiInterface::jobError(job
);
2428 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2430 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));