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 bool DolphinMainWindow::isFoldersPanelEnabled() const
250 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
253 bool DolphinMainWindow::isInformationPanelEnabled() const
255 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
258 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
260 openFiles(QUrl::fromStringList(files
), splitView
);
263 void DolphinMainWindow::activateWindow()
265 window()->setAttribute(Qt::WA_NativeWindow
, true);
266 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
267 KWindowSystem::activateWindow(window()->effectiveWinId());
270 void DolphinMainWindow::showCommand(CommandType command
)
272 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
274 case KIO::FileUndoManager::Copy
:
275 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
277 case KIO::FileUndoManager::Move
:
278 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
280 case KIO::FileUndoManager::Link
:
281 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
283 case KIO::FileUndoManager::Trash
:
284 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
286 case KIO::FileUndoManager::Rename
:
287 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
290 case KIO::FileUndoManager::Mkdir
:
291 statusBar
->setText(i18nc("@info:status", "Created folder."));
299 void DolphinMainWindow::pasteIntoFolder()
301 m_activeViewContainer
->view()->pasteIntoFolder();
304 void DolphinMainWindow::changeUrl(const QUrl
&url
)
306 if (!KProtocolManager::supportsListing(url
)) {
307 // The URL navigator only checks for validity, not
308 // if the URL can be listed. An error message is
309 // shown due to DolphinViewContainer::restoreView().
313 m_activeViewContainer
->setUrl(url
);
314 updateFileAndEditActions();
319 Q_EMIT
urlChanged(url
);
322 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
324 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
325 m_placesPanel
->proceedWithTearDown();
326 m_tearDownFromPlacesRequested
= false;
329 m_activeViewContainer
->setAutoGrabFocus(false);
331 m_activeViewContainer
->setAutoGrabFocus(true);
334 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
336 KToggleAction
* editableLocationAction
=
337 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
338 editableLocationAction
->setChecked(editable
);
341 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
343 updateFileAndEditActions();
345 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
347 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
348 if (selectedUrlsCount
== 2) {
349 compareFilesAction
->setEnabled(isKompareInstalled());
351 compareFilesAction
->setEnabled(false);
354 Q_EMIT
selectionChanged(selection
);
357 void DolphinMainWindow::updateHistory()
359 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
360 const int index
= urlNavigator
->historyIndex();
362 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
364 backAction
->setToolTip(i18nc("@info", "Go back"));
365 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
366 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
369 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
371 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
372 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
373 "This undoes a <interface>Go|Back</interface> action."));
374 forwardAction
->setEnabled(index
> 0);
378 void DolphinMainWindow::updateFilterBarAction(bool show
)
380 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
381 showFilterBarAction
->setChecked(show
);
384 void DolphinMainWindow::openNewMainWindow()
386 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
389 void DolphinMainWindow::openNewActivatedTab()
391 m_tabWidget
->openNewActivatedTab();
394 void DolphinMainWindow::addToPlaces()
399 // If nothing is selected, act on the current dir
400 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
401 url
= m_activeViewContainer
->url();
402 name
= m_activeViewContainer
->placesText();
404 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
405 url
= dirToAdd
.url();
406 name
= dirToAdd
.name();
409 PlacesItemModel model
;
411 if (m_activeViewContainer
->isSearchModeEnabled()) {
412 icon
= QStringLiteral("folder-saved-search-symbolic");
414 icon
= KIO::iconNameForUrl(url
);
416 model
.createPlacesItem(name
, url
, icon
);
420 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
422 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
425 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
427 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
430 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
432 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
435 void DolphinMainWindow::openInNewTab()
437 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
438 bool tabCreated
= false;
440 for (const KFileItem
& item
: list
) {
441 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
442 if (!url
.isEmpty()) {
443 openNewTabAfterCurrentTab(url
);
448 // if no new tab has been created from the selection
449 // open the current directory in a new tab
451 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
455 void DolphinMainWindow::openInNewWindow()
459 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
460 if (list
.isEmpty()) {
461 newWindowUrl
= m_activeViewContainer
->url();
462 } else if (list
.count() == 1) {
463 const KFileItem
& item
= list
.first();
464 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
467 if (!newWindowUrl
.isEmpty()) {
468 Dolphin::openNewWindow({newWindowUrl
}, this);
472 void DolphinMainWindow::showTarget()
474 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
475 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
476 auto linkDestination
= link
.linkDest();
477 if (QFileInfo(linkDestination
).isRelative()) {
478 linkDestination
= linkLocationDir
.filePath(linkDestination
);
480 if (QFileInfo::exists(linkDestination
)) {
481 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
483 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
484 DolphinViewContainer::Warning
);
488 void DolphinMainWindow::showEvent(QShowEvent
* event
)
490 KXmlGuiWindow::showEvent(event
);
492 if (!event
->spontaneous()) {
493 m_activeViewContainer
->view()->setFocus();
497 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
499 // Find out if Dolphin is closed directly by the user or
500 // by the session manager because the session is closed
501 bool closedByUser
= true;
502 if (qApp
->isSavingSession()) {
503 closedByUser
= false;
506 if (m_tabWidget
->count() > 1
507 && GeneralSettings::confirmClosingMultipleTabs()
508 && !GeneralSettings::rememberOpenedTabs()
510 // Ask the user if he really wants to quit and close all tabs.
511 // Open a confirmation dialog with 3 buttons:
512 // QDialogButtonBox::Yes -> Quit
513 // QDialogButtonBox::No -> Close only the current tab
514 // QDialogButtonBox::Cancel -> do nothing
515 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
516 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
517 dialog
->setModal(true);
518 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
519 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
520 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
521 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
522 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
524 bool doNotAskAgainCheckboxResult
= false;
526 const auto result
= KMessageBox::createKMessageBox(dialog
,
528 QMessageBox::Warning
,
529 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
531 i18n("Do not ask again"),
532 &doNotAskAgainCheckboxResult
,
533 KMessageBox::Notify
);
535 if (doNotAskAgainCheckboxResult
) {
536 GeneralSettings::setConfirmClosingMultipleTabs(false);
540 case QDialogButtonBox::Yes
:
543 case QDialogButtonBox::No
:
544 // Close only the current tab
545 m_tabWidget
->closeTab();
553 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
554 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
555 // Open a confirmation dialog with 3 buttons:
556 // QDialogButtonBox::Yes -> Quit
557 // QDialogButtonBox::No -> Show Terminal Panel
558 // QDialogButtonBox::Cancel -> do nothing
559 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
560 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
561 dialog
->setModal(true);
562 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
563 if (!m_terminalPanel
->isVisible()) {
564 standardButtons
|= QDialogButtonBox::No
;
566 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
567 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
568 if (!m_terminalPanel
->isVisible()) {
570 buttons
->button(QDialogButtonBox::No
),
571 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
573 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
575 bool doNotAskAgainCheckboxResult
= false;
577 const auto result
= KMessageBox::createKMessageBox(
580 QMessageBox::Warning
,
581 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
583 i18n("Do not ask again"),
584 &doNotAskAgainCheckboxResult
,
585 KMessageBox::Dangerous
);
587 if (doNotAskAgainCheckboxResult
) {
588 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
592 case QDialogButtonBox::Yes
:
595 case QDialogButtonBox::No
:
596 actionCollection()->action("show_terminal_panel")->trigger();
597 // Do not quit, ignore quit event
605 if (GeneralSettings::rememberOpenedTabs()) {
606 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
607 KConfig
*config
= KConfigGui::sessionConfig();
608 saveGlobalProperties(config
);
609 savePropertiesInternal(config
, 1);
613 GeneralSettings::setVersion(CurrentDolphinVersion
);
614 GeneralSettings::self()->save();
616 KXmlGuiWindow::closeEvent(event
);
619 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
621 m_tabWidget
->saveProperties(group
);
624 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
626 m_tabWidget
->readProperties(group
);
629 void DolphinMainWindow::updateNewMenu()
631 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
632 m_newFileMenu
->checkUpToDate();
633 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
636 void DolphinMainWindow::createDirectory()
638 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
639 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
640 m_newFileMenu
->createDirectory();
643 void DolphinMainWindow::quit()
648 void DolphinMainWindow::showErrorMessage(const QString
& message
)
650 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
653 void DolphinMainWindow::slotUndoAvailable(bool available
)
655 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
657 undoAction
->setEnabled(available
);
661 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
663 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
665 undoAction
->setText(text
);
669 void DolphinMainWindow::undo()
672 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
673 KIO::FileUndoManager::self()->undo();
676 void DolphinMainWindow::cut()
678 m_activeViewContainer
->view()->cutSelectedItemsToClipboard();
681 void DolphinMainWindow::copy()
683 m_activeViewContainer
->view()->copySelectedItemsToClipboard();
686 void DolphinMainWindow::paste()
688 m_activeViewContainer
->view()->paste();
691 void DolphinMainWindow::find()
693 m_activeViewContainer
->setSearchModeEnabled(true);
696 void DolphinMainWindow::updateSearchAction()
698 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
699 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
702 void DolphinMainWindow::updatePasteAction()
704 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
705 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
706 pasteAction
->setEnabled(pasteInfo
.first
);
707 pasteAction
->setText(pasteInfo
.second
);
710 void DolphinMainWindow::slotDirectoryLoadingCompleted()
715 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
717 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
719 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
721 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
723 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
728 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
730 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
732 m_backAction
->menu()->clear();
733 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
734 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
736 m_backAction
->menu()->addAction(action
);
740 void DolphinMainWindow::slotGoBack(QAction
* action
)
742 int gotoIndex
= action
->data().value
<int>();
743 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
744 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
749 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
752 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
753 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
757 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
759 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
761 m_forwardAction
->menu()->clear();
762 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
763 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
765 m_forwardAction
->menu()->addAction(action
);
769 void DolphinMainWindow::slotGoForward(QAction
* action
)
771 int gotoIndex
= action
->data().value
<int>();
772 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
773 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
778 void DolphinMainWindow::selectAll()
782 // if the URL navigator is editable and focused, select the whole
783 // URL instead of all items of the view
785 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
786 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
787 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
788 lineEdit
->hasFocus();
790 lineEdit
->selectAll();
792 m_activeViewContainer
->view()->selectAll();
796 void DolphinMainWindow::invertSelection()
799 m_activeViewContainer
->view()->invertSelection();
802 void DolphinMainWindow::toggleSplitView()
804 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
805 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
810 void DolphinMainWindow::toggleSplitStash()
812 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
813 tabPage
->setSplitViewEnabled(false);
814 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
817 void DolphinMainWindow::reloadView()
820 m_activeViewContainer
->reload();
821 m_activeViewContainer
->statusBar()->updateSpaceInfo();
824 void DolphinMainWindow::stopLoading()
826 m_activeViewContainer
->view()->stopLoading();
829 void DolphinMainWindow::enableStopAction()
831 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
834 void DolphinMainWindow::disableStopAction()
836 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
839 void DolphinMainWindow::showFilterBar()
841 m_activeViewContainer
->setFilterBarVisible(true);
844 void DolphinMainWindow::toggleEditLocation()
848 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
849 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
850 urlNavigator
->setUrlEditable(action
->isChecked());
853 void DolphinMainWindow::replaceLocation()
855 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
856 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
858 // If the text field currently has focus and everything is selected,
859 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
860 if (navigator
->isUrlEditable()
861 && lineEdit
->hasFocus()
862 && lineEdit
->selectedText() == lineEdit
->text() ) {
863 navigator
->setUrlEditable(false);
865 navigator
->setUrlEditable(true);
866 navigator
->setFocus();
867 lineEdit
->selectAll();
871 void DolphinMainWindow::togglePanelLockState()
873 const bool newLockState
= !GeneralSettings::lockPanels();
874 const auto childrenObjects
= children();
875 for (QObject
* child
: childrenObjects
) {
876 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
878 dock
->setLocked(newLockState
);
882 GeneralSettings::setLockPanels(newLockState
);
885 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
887 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
888 m_activeViewContainer
->view()->setFocus();
892 void DolphinMainWindow::goBack()
894 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
895 urlNavigator
->goBack();
897 if (urlNavigator
->locationState().isEmpty()) {
898 // An empty location state indicates a redirection URL,
899 // which must be skipped too
900 urlNavigator
->goBack();
904 void DolphinMainWindow::goForward()
906 m_activeViewContainer
->urlNavigator()->goForward();
909 void DolphinMainWindow::goUp()
911 m_activeViewContainer
->urlNavigator()->goUp();
914 void DolphinMainWindow::goHome()
916 m_activeViewContainer
->urlNavigator()->goHome();
919 void DolphinMainWindow::goBackInNewTab()
921 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
922 const int index
= urlNavigator
->historyIndex() + 1;
923 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
926 void DolphinMainWindow::goForwardInNewTab()
928 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
929 const int index
= urlNavigator
->historyIndex() - 1;
930 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
933 void DolphinMainWindow::goUpInNewTab()
935 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
936 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
939 void DolphinMainWindow::goHomeInNewTab()
941 openNewTabAfterCurrentTab(Dolphin::homeUrl());
944 void DolphinMainWindow::compareFiles()
946 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
947 if (items
.count() != 2) {
948 // The action is disabled in this case, but it could have been triggered
949 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
953 QUrl urlA
= items
.at(0).url();
954 QUrl urlB
= items
.at(1).url();
956 QString
command(QStringLiteral("kompare -c \""));
957 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
958 command
.append("\" \"");
959 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
960 command
.append('\"');
962 KIO::CommandLauncherJob
*job
= new KIO::CommandLauncherJob(command
, this);
963 job
->setDesktopName(QStringLiteral("org.kde.kompare"));
967 void DolphinMainWindow::toggleShowMenuBar()
969 const bool visible
= menuBar()->isVisible();
970 menuBar()->setVisible(!visible
);
972 createControlButton();
974 deleteControlButton();
978 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
980 m_searchTools
.clear();
981 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
982 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
984 QList
<QAction
*> actions
= m_searchTools
.actions();
985 if (actions
.isEmpty()) {
988 QAction
* action
= actions
.first();
989 if (action
->isSeparator()) {
995 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
997 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
998 if (!openPreferredSearchTool
) {
1001 QPointer
<QAction
> tool
= preferredSearchTool();
1003 openPreferredSearchTool
->setVisible(true);
1004 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1005 openPreferredSearchTool
->setIcon(tool
->icon());
1007 openPreferredSearchTool
->setVisible(false);
1008 // still visible in Shortcuts configuration window
1009 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1010 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1014 void DolphinMainWindow::openPreferredSearchTool()
1016 QPointer
<QAction
> tool
= preferredSearchTool();
1022 void DolphinMainWindow::openTerminal()
1024 const QUrl url
= m_activeViewContainer
->url();
1026 if (url
.isLocalFile()) {
1027 KToolInvocation::invokeTerminal(QString(), url
.toLocalFile());
1031 // Not a local file, with protocol Class ":local", try stat'ing
1032 if (KProtocolInfo::protocolClass(url
.scheme()) == QLatin1String(":local")) {
1033 KIO::StatJob
*job
= KIO::mostLocalUrl(url
);
1034 KJobWidgets::setWindow(job
, this);
1035 connect(job
, &KJob::result
, this, [job
]() {
1037 if (!job
->error()) {
1038 statUrl
= job
->mostLocalUrl();
1041 KToolInvocation::invokeTerminal(QString(), statUrl
.isLocalFile() ? statUrl
.toLocalFile() : QDir::homePath());
1047 // Nothing worked, just use $HOME
1048 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1051 void DolphinMainWindow::editSettings()
1053 if (!m_settingsDialog
) {
1054 DolphinViewContainer
* container
= activeViewContainer();
1055 container
->view()->writeSettings();
1057 const QUrl url
= container
->url();
1058 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1059 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1060 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1061 settingsDialog
->show();
1062 m_settingsDialog
= settingsDialog
;
1064 m_settingsDialog
.data()->raise();
1068 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1070 delete m_lastHandleUrlOpenJob
;
1071 m_lastHandleUrlOpenJob
= nullptr;
1073 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1074 activeViewContainer()->setUrl(url
);
1076 m_lastHandleUrlOpenJob
= new KIO::OpenUrlJob(url
);
1077 m_lastHandleUrlOpenJob
->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled
, this));
1078 m_lastHandleUrlOpenJob
->setRunExecutables(true);
1080 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::mimeTypeFound
, this,
1081 [this, url
](const QString
&mimetype
) {
1082 if (mimetype
== QLatin1String("inode/directory")) {
1083 // If it's a dir, we'll take it from here
1084 m_lastHandleUrlOpenJob
->kill();
1085 m_lastHandleUrlOpenJob
= nullptr;
1086 activeViewContainer()->setUrl(url
);
1090 connect(m_lastHandleUrlOpenJob
, &KIO::OpenUrlJob::result
, this, [this]() {
1091 m_lastHandleUrlOpenJob
= nullptr;
1094 m_lastHandleUrlOpenJob
->start();
1098 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1100 // trash:/ is writable but we don't want to create new items in it.
1101 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1102 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1105 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1106 const KFileItem
& item
,
1108 const QList
<QAction
*>& customActions
)
1110 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1111 contextMenu
.data()->setCustomActions(customActions
);
1112 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1115 case DolphinContextMenu::OpenParentFolder
:
1116 changeUrl(KIO::upUrl(item
.url()));
1117 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1118 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1121 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1122 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1125 case DolphinContextMenu::OpenParentFolderInNewTab
:
1126 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1129 case DolphinContextMenu::None
:
1134 // Delete the menu, unless it has been deleted in its own nested event loop already.
1136 contextMenu
->deleteLater();
1140 void DolphinMainWindow::updateControlMenu()
1142 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1145 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1146 // because 'menu' is their parent.
1149 KActionCollection
* ac
= actionCollection();
1151 menu
->addMenu(m_newFileMenu
->menu());
1152 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1153 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1154 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1156 menu
->addSeparator();
1158 // Add "Edit" actions
1159 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1160 addActionToMenu(ac
->action(QString("copy_location")), menu
) |
1161 addActionToMenu(ac
->action(QStringLiteral("copy_to_inactive_split_view")), menu
) |
1162 addActionToMenu(ac
->action(QStringLiteral("move_to_inactive_split_view")), menu
) |
1163 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1164 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1167 menu
->addSeparator();
1170 // Add "View" actions
1171 if (!GeneralSettings::showZoomSlider()) {
1172 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1173 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1174 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1175 menu
->addSeparator();
1178 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1179 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1180 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1181 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1182 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1185 menu
->addSeparator();
1188 // Add a curated assortment of items from the "Tools" menu
1189 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1190 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1191 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1193 menu
->addSeparator();
1195 // Add "Show Panels" menu
1196 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1198 // Add "Settings" menu entries
1199 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1200 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1201 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1202 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1205 auto helpMenu
= m_helpMenu
->menu();
1206 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1207 menu
->addMenu(helpMenu
);
1210 void DolphinMainWindow::updateToolBar()
1212 if (!menuBar()->isVisible()) {
1213 createControlButton();
1217 void DolphinMainWindow::slotControlButtonDeleted()
1219 m_controlButton
= nullptr;
1220 m_updateToolBarTimer
->start();
1223 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1225 DolphinViewContainer
* view
= activeViewContainer();
1227 if (view
->url() == url
) {
1228 // We can end up here if the user clicked a device in the Places Panel
1229 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1236 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1238 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1241 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1243 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1244 Q_ASSERT(viewContainer
);
1246 m_activeViewContainer
= viewContainer
;
1248 if (oldViewContainer
) {
1249 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1250 toggleSearchAction
->disconnect(oldViewContainer
);
1252 // Disconnect all signals between the old view container (container,
1253 // view and url navigator) and main window.
1254 oldViewContainer
->disconnect(this);
1255 oldViewContainer
->view()->disconnect(this);
1256 oldViewContainer
->urlNavigator()->disconnect(this);
1258 // except the requestItemInfo so that on hover the information panel can still be updated
1259 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1260 this, &DolphinMainWindow::requestItemInfo
);
1263 connectViewSignals(viewContainer
);
1265 m_actionHandler
->setCurrentView(viewContainer
->view());
1268 updateFileAndEditActions();
1269 updatePasteAction();
1270 updateViewActions();
1272 updateSearchAction();
1274 const QUrl url
= viewContainer
->url();
1275 Q_EMIT
urlChanged(url
);
1278 void DolphinMainWindow::tabCountChanged(int count
)
1280 const bool enableTabActions
= (count
> 1);
1281 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1282 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1284 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1285 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1286 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1289 void DolphinMainWindow::updateWindowTitle()
1291 const QString newTitle
= m_activeViewContainer
->captionWindowTitle();
1292 if (windowTitle() != newTitle
) {
1293 setWindowTitle(newTitle
);
1297 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1299 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1300 setViewsToHomeIfMountPathOpen(mountPath
);
1303 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1304 m_tearDownFromPlacesRequested
= true;
1305 m_terminalPanel
->goHome();
1306 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1308 m_placesPanel
->proceedWithTearDown();
1312 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1314 connect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, this, [this, mountPath
]() {
1315 setViewsToHomeIfMountPathOpen(mountPath
);
1318 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1319 m_tearDownFromPlacesRequested
= false;
1320 m_terminalPanel
->goHome();
1324 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString
& mountPath
)
1326 const QVector
<DolphinViewContainer
*> theViewContainers
= viewContainers();
1327 for (DolphinViewContainer
*viewContainer
: theViewContainers
) {
1328 if (viewContainer
&& viewContainer
->url().toLocalFile().startsWith(mountPath
)) {
1329 viewContainer
->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1332 disconnect(m_placesPanel
, &PlacesPanel::storageTearDownSuccessful
, nullptr, nullptr);
1335 void DolphinMainWindow::setupActions()
1337 // setup 'File' menu
1338 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1339 QMenu
* menu
= m_newFileMenu
->menu();
1340 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1341 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1342 m_newFileMenu
->setDelayed(false);
1343 connect(menu
, &QMenu::aboutToShow
,
1344 this, &DolphinMainWindow::updateNewMenu
);
1346 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1347 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1348 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1349 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1350 "window just like this one with the current location and view."
1351 "<nl/>You can drag and drop items between windows."));
1352 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1354 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1355 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1356 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1357 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1358 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1359 "A tab is an additional view within this window. "
1360 "You can drag and drop items between tabs."));
1361 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1362 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1364 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1365 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1366 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1367 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1368 "to the Places panel."));
1369 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1371 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1372 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1373 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1374 "currently viewed tab. If no more tabs are left this window "
1375 "will close instead."));
1377 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1378 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1380 // setup 'Edit' menu
1381 KStandardAction::undo(this,
1382 &DolphinMainWindow::undo
,
1383 actionCollection());
1385 // i18n: This will be the last paragraph for the whatsthis for all three:
1386 // Cut, Copy and Paste
1387 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1388 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1389 "applications and are among the most used commands. That's why their "
1390 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1391 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1392 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1393 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1394 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1395 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1396 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1397 "the clipboard to a new location. The items will be removed from their "
1398 "initial location.") + cutCopyPastePara
);
1399 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1400 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1401 "items in your current selection to the <emphasis>clipboard</emphasis>."
1402 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1403 "from the clipboard to a new location.") + cutCopyPastePara
);
1404 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1405 // The text of the paste-action is modified dynamically by Dolphin
1406 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1407 // due to the long text, the text "Paste" is used:
1408 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1409 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1410 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1411 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1412 "action they are removed from their old location.") + cutCopyPastePara
);
1414 QAction
* copyToOtherViewAction
= actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1415 copyToOtherViewAction
->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1416 copyToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1417 "the <emphasis>active</emphasis> view to the inactive split view."));
1418 copyToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1419 copyToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1420 actionCollection()->setDefaultShortcut(copyToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F5
);
1421 connect(copyToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::copyToInactiveSplitView
);
1423 QAction
* moveToOtherViewAction
= actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1424 moveToOtherViewAction
->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1425 moveToOtherViewAction
->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1426 "the <emphasis>active</emphasis> view to the inactive split view."));
1427 moveToOtherViewAction
->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1428 moveToOtherViewAction
->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1429 actionCollection()->setDefaultShortcut(moveToOtherViewAction
, Qt::SHIFT
+ Qt::Key_F6
);
1430 connect(moveToOtherViewAction
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::moveToInactiveSplitView
);
1432 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1433 searchAction
->setText(i18n("Search..."));
1434 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1435 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1436 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1437 "There you can enter search terms and specify settings to find the "
1438 "objects you are looking for.</para><para>Use this help again on "
1439 "the find bar so we can have a look at it while the settings are "
1440 "explained.</para>"));
1442 // toggle_search acts as a copy of the main searchAction to be used mainly
1443 // in the toolbar, with no default shortcut attached, to avoid messing with
1444 // existing workflows (search bar always open and Ctrl-F to focus)
1445 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1446 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1447 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1448 toggleSearchAction
->setIcon(searchAction
->icon());
1449 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1450 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1451 toggleSearchAction
->setCheckable(true);
1453 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1454 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1455 "files and folders in the current location."));
1457 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1458 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1459 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1460 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1461 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1462 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1463 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1465 // setup 'View' menu
1466 // (note that most of it is set up in DolphinViewActionHandler)
1468 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1469 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1470 "the folder view below into two autonomous views.</para><para>This "
1471 "way you can see two locations at once and move items between them "
1472 "quickly.</para>Click this again afterwards to recombine the views."));
1473 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1474 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1476 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1477 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1478 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1479 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1480 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1481 stashSplit
->setCheckable(false);
1482 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1483 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1485 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1487 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1488 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1489 stop
->setToolTip(i18nc("@info", "Stop loading"));
1490 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1491 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1492 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1494 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1495 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1496 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1497 "This toggles the <emphasis>Location Bar</emphasis> to be "
1498 "editable so you can directly enter a location you want to go to.<nl/>"
1499 "You can also switch to editing by clicking to the right of the "
1500 "location and switch back by confirming the edited location."));
1501 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1502 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1504 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1505 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1506 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1507 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1508 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1509 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1510 "This switches to editing the location and selects it "
1511 "so you can quickly enter a different location."));
1512 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1513 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1517 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1518 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1519 m_backAction
->setObjectName(backAction
->objectName());
1520 m_backAction
->setShortcuts(backAction
->shortcuts());
1522 m_backAction
->setDelayed(true);
1523 m_backAction
->setStickyMenu(false);
1524 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1525 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1526 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1527 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1529 auto backShortcuts
= m_backAction
->shortcuts();
1530 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1531 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1533 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1534 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1535 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1536 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1537 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1538 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1539 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1540 this, &DolphinMainWindow::closedTabsCountChanged
);
1542 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1543 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1544 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1545 "This returns you to the previously closed tab."));
1546 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1547 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1548 undoCloseTab
->setEnabled(false);
1549 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1551 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1552 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1553 "the last change you made to files or folders.<nl/>"
1554 "Such changes include <interface>creating, renaming</interface> "
1555 "and <interface>moving</interface> them to a different location "
1556 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1557 "be undone will ask for your confirmation."));
1558 undoAction
->setEnabled(false); // undo should be disabled by default
1561 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1562 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1563 m_forwardAction
->setObjectName(forwardAction
->objectName());
1564 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1566 m_forwardAction
->setDelayed(true);
1567 m_forwardAction
->setStickyMenu(false);
1568 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1569 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1570 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1571 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1572 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1574 // enable middle-click to open in a new tab
1575 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1576 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1577 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1578 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1579 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1580 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1581 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1582 "<filename>Home</filename> folder.<nl/>Every user account "
1583 "has their own <filename>Home</filename> that contains their data "
1584 "including folders that contain personal application data."));
1586 // setup 'Tools' menu
1587 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1588 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1589 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1590 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1591 "There you can enter a text to filter the files and folders currently displayed. "
1592 "Only those that contain the text in their name will be kept in view."));
1593 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1594 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1595 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1597 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1598 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1599 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1600 compareFiles
->setEnabled(false);
1601 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1603 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1604 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1605 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1606 "<para>This opens a preferred search tool for the viewed location.</para>"
1607 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1608 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1609 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1610 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1612 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1613 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1614 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1615 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1616 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1617 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1618 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1619 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1620 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1622 #ifdef HAVE_TERMINAL
1623 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1624 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1625 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1626 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1627 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1631 // setup 'Bookmarks' menu
1632 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1633 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1634 // Make the toolbar button version work properly on click
1635 bookmarkMenu
->setDelayed(false);
1636 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1637 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1639 // setup 'Settings' menu
1640 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1641 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1642 "This switches between having a <emphasis>Menubar</emphasis> "
1643 "and having a <interface>Control</interface> button. Both "
1644 "contain mostly the same commands and configuration options."));
1645 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1646 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1647 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1649 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1650 m_helpMenu
= new KHelpMenu(nullptr);
1651 m_helpMenu
->menu()->installEventFilter(this);
1652 // remove duplicate shortcuts
1653 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1654 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1656 // not in menu actions
1657 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1658 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1660 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1661 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1663 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1664 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1665 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1666 activateTab
->setEnabled(false);
1667 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1669 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1671 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1675 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1676 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1677 activateLastTab
->setEnabled(false);
1678 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1679 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1681 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1682 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1683 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1684 activateNextTab
->setEnabled(false);
1685 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1686 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1688 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1689 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1690 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1691 activatePrevTab
->setEnabled(false);
1692 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1693 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1696 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1697 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1698 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1699 showTarget
->setEnabled(false);
1700 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1702 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1703 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1704 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1705 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1707 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1708 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1709 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1710 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1712 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1713 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1714 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1715 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1718 void DolphinMainWindow::setupDockWidgets()
1720 const bool lock
= GeneralSettings::lockPanels();
1722 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1723 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1724 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1725 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1726 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1727 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1728 "switches between having panels <emphasis>locked</emphasis> or "
1729 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1730 "dragged to the other side of the window and have a close "
1731 "button.<nl/>Locked panels are embedded more cleanly."));
1732 lockLayoutAction
->setActive(lock
);
1733 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1735 // Setup "Information"
1736 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1737 infoDock
->setLocked(lock
);
1738 infoDock
->setObjectName(QStringLiteral("infoDock"));
1739 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1742 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1743 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1744 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1745 infoDock
->setWidget(infoPanel
);
1747 QAction
* infoAction
= infoDock
->toggleViewAction();
1748 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1750 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1751 connect(this, &DolphinMainWindow::urlChanged
,
1752 infoPanel
, &InformationPanel::setUrl
);
1753 connect(this, &DolphinMainWindow::selectionChanged
,
1754 infoPanel
, &InformationPanel::setSelection
);
1755 connect(this, &DolphinMainWindow::requestItemInfo
,
1756 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1759 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1760 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1761 "hide panels like this go to <interface>Control|Panels</interface> "
1762 "or <interface>View|Panels</interface>.</para>");
1764 actionCollection()->action(QStringLiteral("show_information_panel"))
1765 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1766 "<emphasis>information</emphasis> panel at the right side of the "
1767 "window.</para><para>The panel provides in-depth information "
1768 "about the items your mouse is hovering over or about the selected "
1769 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1770 "For single items a preview of their contents is provided.</para>"));
1772 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1773 "provides in-depth information about the items your mouse is "
1774 "hovering over or about the selected items. Otherwise it informs "
1775 "you about the currently viewed folder.<nl/>For single items a "
1776 "preview of their contents is provided.</para><para>You can configure "
1777 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1780 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1781 foldersDock
->setLocked(lock
);
1782 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1783 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1784 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1785 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1786 foldersDock
->setWidget(foldersPanel
);
1788 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1789 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1791 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1792 connect(this, &DolphinMainWindow::urlChanged
,
1793 foldersPanel
, &FoldersPanel::setUrl
);
1794 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1795 this, &DolphinMainWindow::changeUrl
);
1796 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1797 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1798 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1799 this, &DolphinMainWindow::showErrorMessage
);
1801 actionCollection()->action(QStringLiteral("show_folders_panel"))
1802 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1803 "<emphasis>folders</emphasis> panel at the left side of the window."
1804 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1805 "</emphasis> in a <emphasis>tree view</emphasis>."));
1806 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1807 "shows the folders of the <emphasis>file system</emphasis> in a "
1808 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1809 "there. Click the arrow to the left of a folder to see its subfolders. "
1810 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1813 #ifdef HAVE_TERMINAL
1814 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1815 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1816 terminalDock
->setLocked(lock
);
1817 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1818 m_terminalPanel
= new TerminalPanel(terminalDock
);
1819 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1820 terminalDock
->setWidget(m_terminalPanel
);
1822 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1823 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1824 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1825 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1826 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1827 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1829 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1830 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1832 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1833 connect(this, &DolphinMainWindow::urlChanged
,
1834 m_terminalPanel
, &TerminalPanel::setUrl
);
1836 if (GeneralSettings::version() < 200) {
1837 terminalDock
->hide();
1840 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1841 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1842 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1843 "<nl/>The location in the terminal will always match the folder "
1844 "view so you can navigate using either.</para><para>The terminal "
1845 "panel is not needed for basic computer usage but can be useful "
1846 "for advanced tasks. To learn more about terminals use the help "
1847 "in a standalone terminal application like Konsole.</para>"));
1848 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1849 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1850 "normal terminal but will match the location of the folder view "
1851 "so you can navigate using either.</para><para>The terminal panel "
1852 "is not needed for basic computer usage but can be useful for "
1853 "advanced tasks. To learn more about terminals use the help in a "
1854 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1858 if (GeneralSettings::version() < 200) {
1860 foldersDock
->hide();
1864 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1865 placesDock
->setLocked(lock
);
1866 placesDock
->setObjectName(QStringLiteral("placesDock"));
1867 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1869 m_placesPanel
= new PlacesPanel(placesDock
);
1870 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1871 placesDock
->setWidget(m_placesPanel
);
1873 QAction
*placesAction
= placesDock
->toggleViewAction();
1874 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1876 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1877 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1878 this, &DolphinMainWindow::slotPlaceActivated
);
1879 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1880 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1881 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1882 this, &DolphinMainWindow::showErrorMessage
);
1883 connect(this, &DolphinMainWindow::urlChanged
,
1884 m_placesPanel
, &PlacesPanel::setUrl
);
1885 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1886 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1887 connect(this, &DolphinMainWindow::settingsChanged
,
1888 m_placesPanel
, &PlacesPanel::readSettings
);
1889 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1890 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1891 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1892 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1893 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1895 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1896 actionShowAllPlaces
->setCheckable(true);
1897 actionShowAllPlaces
->setDisabled(true);
1898 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1899 "all places in the places panel that have been hidden. They will "
1900 "appear semi-transparent unless you uncheck their hide property."));
1902 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1903 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1904 m_placesPanel
->showHiddenEntries(checked
);
1907 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1908 actionShowAllPlaces
->setChecked(checked
);
1909 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1912 actionCollection()->action(QStringLiteral("show_places_panel"))
1913 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1914 "<emphasis>places</emphasis> panel at the left side of the window."
1915 "</para><para>It allows you to go to locations you have "
1916 "bookmarked and to access disk or media attached to the computer "
1917 "or to the network. It also contains sections to find recently "
1918 "saved files or files of a certain type.</para>"));
1919 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1920 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1921 "you have bookmarked and to access disk or media attached to the "
1922 "computer or to the network. It also contains sections to find "
1923 "recently saved files or files of a certain type.</para><para>"
1924 "Click on an entry to go there. Click with the right mouse button "
1925 "instead to open any entry in a new tab or new window.</para>"
1926 "<para>New entries can be added by dragging folders onto this panel. "
1927 "Right-click any section or entry to hide it. Right-click an empty "
1928 "space on this panel and select <interface>Show Hidden Places"
1929 "</interface> to display it again.</para>") + panelWhatsThis
);
1931 // Add actions into the "Panels" menu
1932 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1933 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1934 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1935 panelsMenu
->setDelayed(false);
1936 const KActionCollection
* ac
= actionCollection();
1937 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1939 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1941 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1942 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1943 panelsMenu
->addSeparator();
1944 panelsMenu
->addAction(actionShowAllPlaces
);
1945 panelsMenu
->addAction(lockLayoutAction
);
1947 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1948 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1953 void DolphinMainWindow::updateFileAndEditActions()
1955 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1956 const KActionCollection
* col
= actionCollection();
1957 KFileItemListProperties
capabilitiesSource(list
);
1959 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1960 QAction
* copyToOtherViewAction
= col
->action(QStringLiteral("copy_to_inactive_split_view"));
1961 QAction
* moveToOtherViewAction
= col
->action(QStringLiteral("move_to_inactive_split_view"));
1962 QAction
* copyLocation
= col
->action(QString("copy_location"));
1964 if (list
.isEmpty()) {
1965 stateChanged(QStringLiteral("has_no_selection"));
1967 addToPlacesAction
->setEnabled(true);
1968 copyToOtherViewAction
->setEnabled(false);
1969 moveToOtherViewAction
->setEnabled(false);
1970 copyLocation
->setEnabled(false);
1972 stateChanged(QStringLiteral("has_selection"));
1974 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1975 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1976 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1977 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1978 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1979 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1980 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1982 if (list
.length() == 1 && list
.first().isDir()) {
1983 addToPlacesAction
->setEnabled(true);
1985 addToPlacesAction
->setEnabled(false);
1988 if (m_tabWidget
->currentTabPage()->splitViewEnabled()) {
1989 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
1990 KFileItem capabilitiesDestination
;
1992 if (tabPage
->primaryViewActive()) {
1993 capabilitiesDestination
= tabPage
->secondaryViewContainer()->url();
1995 capabilitiesDestination
= tabPage
->primaryViewContainer()->url();
1998 copyToOtherViewAction
->setEnabled(capabilitiesDestination
.isWritable());
1999 moveToOtherViewAction
->setEnabled(capabilitiesSource
.supportsMoving() && capabilitiesDestination
.isWritable());
2001 copyToOtherViewAction
->setEnabled(false);
2002 moveToOtherViewAction
->setEnabled(false);
2005 const bool enableMoveToTrash
= capabilitiesSource
.isLocal() && capabilitiesSource
.supportsMoving();
2007 renameAction
->setEnabled(capabilitiesSource
.supportsMoving());
2008 moveToTrashAction
->setEnabled(enableMoveToTrash
);
2009 deleteAction
->setEnabled(capabilitiesSource
.supportsDeleting());
2010 deleteWithTrashShortcut
->setEnabled(capabilitiesSource
.supportsDeleting() && !enableMoveToTrash
);
2011 cutAction
->setEnabled(capabilitiesSource
.supportsMoving());
2012 copyLocation
->setEnabled(list
.length() == 1);
2013 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
2014 duplicateAction
->setEnabled(capabilitiesSource
.supportsWriting());
2018 void DolphinMainWindow::updateViewActions()
2020 m_actionHandler
->updateViewActions();
2022 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
2023 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
2025 updateSplitAction();
2027 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
2028 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
2029 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
2032 void DolphinMainWindow::updateGoActions()
2034 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
2035 const QUrl currentUrl
= m_activeViewContainer
->url();
2036 // I think this is one of the best places to firstly be confronted
2037 // with a file system and its hierarchy. Talking about the root
2038 // directory might seem too much here but it is the question that
2039 // naturally arises in this context.
2040 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2041 "the folder that contains the currently viewed one.</para>"
2042 "<para>All files and folders are organized in a hierarchical "
2043 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2044 "a directory that contains all data connected to this computer"
2045 "—the <emphasis>root directory</emphasis>.</para>"));
2046 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
2049 void DolphinMainWindow::createControlButton()
2051 if (m_controlButton
) {
2054 Q_ASSERT(!m_controlButton
);
2056 m_controlButton
= new QToolButton(this);
2057 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2058 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2059 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
2060 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
2061 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
2063 QMenu
* controlMenu
= new QMenu(m_controlButton
);
2064 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
2065 controlMenu
->installEventFilter(this);
2067 m_controlButton
->setMenu(controlMenu
);
2069 toolBar()->addWidget(m_controlButton
);
2070 connect(toolBar(), &KToolBar::iconSizeChanged
,
2071 m_controlButton
, &QToolButton::setIconSize
);
2073 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2074 // gets edited. In this case we must add them again. The adding is done asynchronously by
2075 // m_updateToolBarTimer.
2076 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
2077 m_updateToolBarTimer
= new QTimer(this);
2078 m_updateToolBarTimer
->setInterval(500);
2079 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
2082 void DolphinMainWindow::deleteControlButton()
2084 delete m_controlButton
;
2085 m_controlButton
= nullptr;
2087 delete m_updateToolBarTimer
;
2088 m_updateToolBarTimer
= nullptr;
2091 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2096 const KToolBar
* toolBarWidget
= toolBar();
2097 const auto associatedWidgets
= action
->associatedWidgets();
2098 for (const QWidget
* widget
: associatedWidgets
) {
2099 if (widget
== toolBarWidget
) {
2104 menu
->addAction(action
);
2108 void DolphinMainWindow::refreshViews()
2110 m_tabWidget
->refreshViews();
2112 if (GeneralSettings::modifiedStartupSettings()) {
2113 // The startup settings have been changed by the user (see bug #254947).
2114 // Synchronize the split-view setting with the active view:
2115 const bool splitView
= GeneralSettings::splitView();
2116 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2117 updateSplitAction();
2118 updateWindowTitle();
2121 Q_EMIT
settingsChanged();
2124 void DolphinMainWindow::clearStatusBar()
2126 m_activeViewContainer
->statusBar()->resetToDefaultText();
2129 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2131 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2132 this, &DolphinMainWindow::updateFilterBarAction
);
2133 connect(container
, &DolphinViewContainer::writeStateChanged
,
2134 this, &DolphinMainWindow::slotWriteStateChanged
);
2135 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2136 this, &DolphinMainWindow::updateSearchAction
);
2138 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2139 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2141 const DolphinView
* view
= container
->view();
2142 connect(view
, &DolphinView::selectionChanged
,
2143 this, &DolphinMainWindow::slotSelectionChanged
);
2144 connect(view
, &DolphinView::requestItemInfo
,
2145 this, &DolphinMainWindow::requestItemInfo
);
2146 connect(view
, &DolphinView::tabRequested
,
2147 this, &DolphinMainWindow::openNewTab
);
2148 connect(view
, &DolphinView::requestContextMenu
,
2149 this, &DolphinMainWindow::openContextMenu
);
2150 connect(view
, &DolphinView::directoryLoadingStarted
,
2151 this, &DolphinMainWindow::enableStopAction
);
2152 connect(view
, &DolphinView::directoryLoadingCompleted
,
2153 this, &DolphinMainWindow::disableStopAction
);
2154 connect(view
, &DolphinView::directoryLoadingCompleted
,
2155 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2156 connect(view
, &DolphinView::goBackRequested
,
2157 this, &DolphinMainWindow::goBack
);
2158 connect(view
, &DolphinView::goForwardRequested
,
2159 this, &DolphinMainWindow::goForward
);
2160 connect(view
, &DolphinView::urlActivated
,
2161 this, &DolphinMainWindow::handleUrl
);
2162 connect(view
, &DolphinView::goUpRequested
,
2163 this, &DolphinMainWindow::goUp
);
2165 const KUrlNavigator
* navigator
= container
->urlNavigator();
2166 connect(navigator
, &KUrlNavigator::urlChanged
,
2167 this, &DolphinMainWindow::changeUrl
);
2168 connect(navigator
, &KUrlNavigator::historyChanged
,
2169 this, &DolphinMainWindow::updateHistory
);
2170 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2171 this, &DolphinMainWindow::slotEditableStateChanged
);
2172 connect(navigator
, &KUrlNavigator::tabRequested
,
2173 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2176 void DolphinMainWindow::updateSplitAction()
2178 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2179 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2180 if (tabPage
->splitViewEnabled()) {
2181 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2182 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2183 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2184 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2186 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2187 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2188 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2191 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2192 splitAction
->setToolTip(i18nc("@info", "Split view"));
2193 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2197 bool DolphinMainWindow::isKompareInstalled() const
2199 static bool initialized
= false;
2200 static bool installed
= false;
2202 // TODO: maybe replace this approach later by using a menu
2203 // plugin like kdiff3plugin.cpp
2204 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2210 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2211 const QKeySequence
& shortcut
,
2212 QAction
* dockAction
,
2213 const QString
& actionName
)
2215 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2216 panelAction
->setCheckable(true);
2217 panelAction
->setChecked(dockAction
->isChecked());
2218 panelAction
->setText(dockAction
->text());
2219 panelAction
->setIcon(icon
);
2220 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2222 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2223 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2226 void DolphinMainWindow::setupWhatsThis()
2229 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2230 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2231 "configuration options. Left-click on any of the menus on this "
2232 "bar to see its contents.</para><para>The Menubar can be hidden "
2233 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2234 "most of its contents become available through a <interface>Control"
2235 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2236 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2237 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2238 "frequently used actions.</para><para>It is highly customizable. "
2239 "All items you see in the <interface>Control</interface> menu or "
2240 "in the <interface>Menubar</interface> can be placed on the "
2241 "Toolbar. Just right-click on it and select <interface>Configure "
2242 "Toolbars…</interface> or find this action in the <interface>"
2243 "Control</interface> or <interface>Settings</interface> menu."
2244 "</para><para>The location of the bar and the style of its "
2245 "buttons can also be changed in the right-click menu. Right-click "
2246 "a button if you want to show or hide its text.</para>"));
2247 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2248 "<para>Here you can see the <emphasis>folders</emphasis> and "
2249 "<emphasis>files</emphasis> that are at the location described in "
2250 "the <interface>Location Bar</interface> above. This area is the "
2251 "central part of this application where you navigate to the files "
2252 "you want to use.</para><para>For an elaborate and general "
2253 "introduction to this application <link "
2254 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2255 "click here</link>. This will open an introductory article from "
2256 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2257 "explanations of all the features of this <emphasis>view</emphasis> "
2258 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2259 "instead. This will open a page from the <emphasis>Handbook"
2260 "</emphasis> that covers the basics.</para>"));
2263 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2264 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2265 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2266 "There you can set up key combinations to trigger an action when "
2267 "they are pressed simultaneously. All commands in this application can "
2268 "be triggered this way.</para>"));
2269 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2270 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2271 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2272 "<para>All items you see in the <interface>Control</interface> menu "
2273 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2274 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2275 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2276 "change a multitude of settings for this application. For an explanation "
2277 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2278 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2281 // The whatsthis has to be set for the m_helpMenu and for the
2282 // StandardAction separately because both are used in different locations.
2283 // m_helpMenu is only used for createControlButton() button.
2285 // Links do not work within the Menubar so texts without links are provided there.
2287 // i18n: If the external link isn't available in your language you should
2288 // probably state the external link language at least in brackets to not
2289 // frustrate the user. If there are multiple languages that the user might
2290 // know with a reasonable chance you might want to have 2 external links.
2291 // The same is in my opinion true for every external link you translate.
2292 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2293 "<para>This opens the Handbook for this application. It provides "
2294 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2295 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2296 ->setWhatsThis(whatsThisHelpContents
2297 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2298 "<para>If you want more elaborate introductions to the "
2299 "different features of <emphasis>Dolphin</emphasis> "
2300 "go to the KDE UserBase Wiki.</para>"));
2301 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2302 + xi18nc("@info:whatsthis second half of handbook text with link",
2303 "<para>If you want more elaborate introductions to the "
2304 "different features of <emphasis>Dolphin</emphasis> "
2305 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2306 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2308 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2309 "<para>This is the button that invokes the help feature you are "
2310 "using right now! Click it, then click any component of this "
2311 "application to ask \"What's this?\" about it. The mouse cursor "
2312 "will change appearance if no help is available for a spot.</para>");
2313 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2314 ->setWhatsThis(whatsThisWhatsThis
2315 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2316 "<para>There are two other ways to get help for this application: The "
2317 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2318 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2319 "article about <emphasis>File Management</emphasis> online."
2320 "</para><para>The \"What's this?\" help is "
2321 "missing in most other windows so don't get too used to this.</para>"));
2322 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2323 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2324 "<para>There are two other ways to get help: "
2325 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2326 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2327 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2328 "missing in most other windows so don't get too used to this.</para>"));
2330 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2331 "window that will guide you through reporting errors or flaws "
2332 "in this application or in other KDE software.</para>");
2333 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2334 ->setWhatsThis(whatsThisReportBug
);
2335 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2336 + xi18nc("@info:whatsthis second half of reportbug text with link",
2337 "<para>High-quality bug reports are much appreciated. To learn "
2338 "how to make your bug report as effective as possible "
2339 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2340 "click here</link>.</para>"));
2342 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2343 "<emphasis>web page</emphasis> where you can donate to "
2344 "support the continued work on this application and many "
2345 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2346 "<para>Donating is the easiest and fastest way to efficiently "
2347 "support KDE and its projects. KDE projects are available for "
2348 "free therefore your donation is needed to cover things that "
2349 "require money like servers, contributor meetings, etc.</para>"
2350 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2351 "organization behind the KDE community.</para>");
2352 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2353 ->setWhatsThis(whatsThisDonate
);
2354 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2356 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2357 "With this you can change the language this application uses."
2358 "<nl/>You can even set secondary languages which will be used "
2359 "if texts are not available in your preferred language.");
2360 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2361 ->setWhatsThis(whatsThisSwitchLanguage
);
2362 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2364 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2365 "window that informs you about the version, license, "
2366 "used libraries and maintainers of this application.");
2367 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2368 ->setWhatsThis(whatsThisAboutApp
);
2369 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2371 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2372 "window with information about <emphasis>KDE</emphasis>. "
2373 "The KDE community are the people behind this free software."
2374 "<nl/>If you like using this application but don't know "
2375 "about KDE or want to see a cute dragon have a look!");
2376 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2377 ->setWhatsThis(whatsThisAboutKDE
);
2378 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2381 bool DolphinMainWindow::event(QEvent
*event
)
2383 if (event
->type() == QEvent::WhatsThisClicked
) {
2385 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2386 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2389 return KXmlGuiWindow::event(event
);
2392 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2395 if (event
->type() == QEvent::WhatsThisClicked
) {
2397 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2398 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2404 void DolphinMainWindow::focusTerminalPanel()
2406 if (m_terminalPanel
->isVisible()) {
2407 if (m_terminalPanel
->terminalHasFocus()) {
2408 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2409 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2411 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2412 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2415 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2416 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2420 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2421 KIO::FileUndoManager::UiInterface()
2425 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2429 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2431 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2433 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2434 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2436 KIO::FileUndoManager::UiInterface::jobError(job
);
2440 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2442 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));