1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz19@gmail.com> *
3 * Copyright (C) 2006 by Stefan Monov <logixoul@gmail.com> *
4 * Copyright (C) 2006 by Cvetoslav Ludmiloff <ludmiloff@gmail.com> *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20 ***************************************************************************/
22 #include "dolphinmainwindow.h"
24 #include "dolphinmainwindowadaptor.h"
25 #include "config-terminal.h"
27 #include "dolphinbookmarkhandler.h"
28 #include "dolphindockwidget.h"
29 #include "dolphincontextmenu.h"
30 #include "dolphinnewfilemenu.h"
31 #include "dolphinrecenttabsmenu.h"
32 #include "dolphinviewcontainer.h"
33 #include "dolphintabpage.h"
34 #include "middleclickactioneventfilter.h"
35 #include "panels/folders/folderspanel.h"
36 #include "panels/places/placesitemmodel.h"
37 #include "panels/places/placespanel.h"
38 #include "panels/information/informationpanel.h"
39 #include "panels/terminal/terminalpanel.h"
40 #include "settings/dolphinsettingsdialog.h"
41 #include "statusbar/dolphinstatusbar.h"
42 #include "views/dolphinviewactionhandler.h"
43 #include "views/dolphinremoteencoding.h"
44 #include "views/draganddrophelper.h"
45 #include "views/viewproperties.h"
46 #include "views/dolphinnewfilemenuobserver.h"
47 #include "dolphin_generalsettings.h"
49 #include <KActionCollection>
50 #include <KActionMenu>
51 #include <KAuthorized>
53 #include <KDualAction>
54 #include <KFileItemListProperties>
56 #include <KIO/JobUiDelegate>
57 #include <KIO/OpenFileManagerWindowJob>
58 #include <KJobWidgets>
59 #include <KLocalizedString>
60 #include <KMessageBox>
61 #include <KNS3/KMoreToolsMenuFactory>
62 #include <KProtocolInfo>
63 #include <KProtocolManager>
66 #include <KStandardAction>
67 #include <KStartupInfo>
68 #include <KToggleAction>
70 #include <KToolBarPopupAction>
71 #include <KToolInvocation>
72 #include <KUrlComboBox>
73 #include <KUrlNavigator>
74 #include <KWindowSystem>
76 #include <QApplication>
78 #include <QCloseEvent>
79 #include <QDesktopServices>
85 #include <QPushButton>
87 #include <QStandardPaths>
89 #include <QToolButton>
90 #include <QWhatsThisClickedEvent>
93 // Used for GeneralSettings::version() to determine whether
94 // an updated version of Dolphin is running.
95 const int CurrentDolphinVersion
= 200;
96 // The maximum number of entries in the back/forward popup menu
97 const int MaxNumberOfNavigationentries
= 12;
98 // The maximum number of "Activate Tab" shortcuts
99 const int MaxActivateTabShortcuts
= 9;
102 DolphinMainWindow::DolphinMainWindow() :
103 KXmlGuiWindow(nullptr),
104 m_newFileMenu(nullptr),
106 m_tabWidget(nullptr),
107 m_activeViewContainer(nullptr),
108 m_actionHandler(nullptr),
109 m_remoteEncoding(nullptr),
111 m_bookmarkHandler(nullptr),
112 m_controlButton(nullptr),
113 m_updateToolBarTimer(nullptr),
114 m_lastHandleUrlStatJob(nullptr),
115 m_terminalPanel(nullptr),
116 m_placesPanel(nullptr),
117 m_tearDownFromPlacesRequested(false),
118 m_backAction(nullptr),
119 m_forwardAction(nullptr)
121 Q_INIT_RESOURCE(dolphin
);
123 new MainWindowAdaptor(this);
126 setWindowFlags(Qt::WindowContextHelpButtonHint
);
128 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
129 setObjectName(QStringLiteral("Dolphin#"));
131 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
132 this, &DolphinMainWindow::showErrorMessage
);
134 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
135 undoManager
->setUiInterface(new UndoUiInterface());
137 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
138 this, &DolphinMainWindow::slotUndoAvailable
);
139 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
140 this, &DolphinMainWindow::slotUndoTextChanged
);
141 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
142 this, &DolphinMainWindow::clearStatusBar
);
143 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
144 this, &DolphinMainWindow::showCommand
);
146 GeneralSettings
* generalSettings
= GeneralSettings::self();
147 const bool firstRun
= (generalSettings
->version() < 200);
149 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
152 setAcceptDrops(true);
154 m_tabWidget
= new DolphinTabWidget(this);
155 m_tabWidget
->setObjectName("tabWidget");
156 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
157 this, &DolphinMainWindow::activeViewChanged
);
158 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
159 this, &DolphinMainWindow::tabCountChanged
);
160 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
161 this, &DolphinMainWindow::updateWindowTitle
);
162 setCentralWidget(m_tabWidget
);
166 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
167 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
168 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
170 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
171 connect(this, &DolphinMainWindow::urlChanged
,
172 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
176 setupGUI(Keys
| Save
| Create
| ToolBar
);
177 stateChanged(QStringLiteral("new_file"));
179 QClipboard
* clipboard
= QApplication::clipboard();
180 connect(clipboard
, &QClipboard::dataChanged
,
181 this, &DolphinMainWindow::updatePasteAction
);
183 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
184 showFilterBarAction
->setChecked(generalSettings
->filterBar());
187 menuBar()->setVisible(false);
188 // Assure a proper default size if Dolphin runs the first time
192 const bool showMenu
= !menuBar()->isHidden();
193 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
194 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
196 createControlButton();
199 // enable middle-click on back/forward/up to open in a new tab
200 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
201 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
202 toolBar()->installEventFilter(middleClickEventFilter
);
206 QTimer::singleShot(0, this, &DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction
);
209 DolphinMainWindow::~DolphinMainWindow()
213 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
215 QVector
<DolphinViewContainer
*> viewContainers
;
216 viewContainers
.reserve(m_tabWidget
->count());
217 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
218 viewContainers
<< m_tabWidget
->tabPageAt(i
)->activeViewContainer();
220 return viewContainers
;
223 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
225 m_tabWidget
->openDirectories(dirs
, splitView
);
228 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
230 openDirectories(QUrl::fromStringList(dirs
), splitView
);
233 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
235 m_tabWidget
->openFiles(files
, splitView
);
238 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
240 openFiles(QUrl::fromStringList(files
), splitView
);
243 void DolphinMainWindow::activateWindow()
245 window()->setAttribute(Qt::WA_NativeWindow
, true);
246 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
247 KWindowSystem::activateWindow(window()->effectiveWinId());
250 void DolphinMainWindow::showCommand(CommandType command
)
252 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
254 case KIO::FileUndoManager::Copy
:
255 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
257 case KIO::FileUndoManager::Move
:
258 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
260 case KIO::FileUndoManager::Link
:
261 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
263 case KIO::FileUndoManager::Trash
:
264 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
266 case KIO::FileUndoManager::Rename
:
267 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
270 case KIO::FileUndoManager::Mkdir
:
271 statusBar
->setText(i18nc("@info:status", "Created folder."));
279 void DolphinMainWindow::pasteIntoFolder()
281 m_activeViewContainer
->view()->pasteIntoFolder();
284 void DolphinMainWindow::changeUrl(const QUrl
&url
)
286 if (!KProtocolManager::supportsListing(url
)) {
287 // The URL navigator only checks for validity, not
288 // if the URL can be listed. An error message is
289 // shown due to DolphinViewContainer::restoreView().
293 m_activeViewContainer
->setUrl(url
);
294 updateFileAndEditActions();
299 emit
urlChanged(url
);
302 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
304 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
305 m_placesPanel
->proceedWithTearDown();
306 m_tearDownFromPlacesRequested
= false;
309 m_activeViewContainer
->setAutoGrabFocus(false);
311 m_activeViewContainer
->setAutoGrabFocus(true);
314 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
316 KToggleAction
* editableLocationAction
=
317 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
318 editableLocationAction
->setChecked(editable
);
321 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
323 updateFileAndEditActions();
325 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
327 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
328 if (selectedUrlsCount
== 2) {
329 compareFilesAction
->setEnabled(isKompareInstalled());
331 compareFilesAction
->setEnabled(false);
334 emit
selectionChanged(selection
);
337 void DolphinMainWindow::updateHistory()
339 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
340 const int index
= urlNavigator
->historyIndex();
342 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
344 backAction
->setToolTip(i18nc("@info", "Go back"));
345 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
346 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
349 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
351 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
352 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
353 "This undoes a <interface>Go|Back</interface> action."));
354 forwardAction
->setEnabled(index
> 0);
358 void DolphinMainWindow::updateFilterBarAction(bool show
)
360 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
361 showFilterBarAction
->setChecked(show
);
364 void DolphinMainWindow::openNewMainWindow()
366 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
369 void DolphinMainWindow::openNewActivatedTab()
371 m_tabWidget
->openNewActivatedTab();
374 void DolphinMainWindow::addToPlaces()
379 // If nothing is selected, act on the current dir
380 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
381 url
= m_activeViewContainer
->url();
382 name
= m_activeViewContainer
->placesText();
384 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
385 url
= dirToAdd
.url();
386 name
= dirToAdd
.name();
389 PlacesItemModel model
;
391 if (m_activeViewContainer
->isSearchModeEnabled()) {
392 icon
= QStringLiteral("folder-saved-search-symbolic");
394 icon
= KIO::iconNameForUrl(url
);
396 model
.createPlacesItem(name
, url
, icon
);
400 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
402 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
405 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
407 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
410 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
412 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
415 void DolphinMainWindow::openInNewTab()
417 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
418 bool tabCreated
= false;
420 foreach (const KFileItem
& item
, list
) {
421 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
422 if (!url
.isEmpty()) {
423 openNewTabAfterCurrentTab(url
);
428 // if no new tab has been created from the selection
429 // open the current directory in a new tab
431 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
435 void DolphinMainWindow::openInNewWindow()
439 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
440 if (list
.isEmpty()) {
441 newWindowUrl
= m_activeViewContainer
->url();
442 } else if (list
.count() == 1) {
443 const KFileItem
& item
= list
.first();
444 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
447 if (!newWindowUrl
.isEmpty()) {
448 Dolphin::openNewWindow({newWindowUrl
}, this);
452 void DolphinMainWindow::showTarget()
454 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
455 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
456 auto linkDestination
= link
.linkDest();
457 if (QFileInfo(linkDestination
).isRelative()) {
458 linkDestination
= linkLocationDir
.filePath(linkDestination
);
460 if (QFileInfo::exists(linkDestination
)) {
461 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
463 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
464 DolphinViewContainer::Warning
);
468 void DolphinMainWindow::showEvent(QShowEvent
* event
)
470 KXmlGuiWindow::showEvent(event
);
472 if (!event
->spontaneous()) {
473 m_activeViewContainer
->view()->setFocus();
477 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
479 // Find out if Dolphin is closed directly by the user or
480 // by the session manager because the session is closed
481 bool closedByUser
= true;
482 if (qApp
->isSavingSession()) {
483 closedByUser
= false;
486 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
487 // Ask the user if he really wants to quit and close all tabs.
488 // Open a confirmation dialog with 3 buttons:
489 // QDialogButtonBox::Yes -> Quit
490 // QDialogButtonBox::No -> Close only the current tab
491 // QDialogButtonBox::Cancel -> do nothing
492 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
493 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
494 dialog
->setModal(true);
495 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
496 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
497 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
498 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
499 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
501 bool doNotAskAgainCheckboxResult
= false;
503 const auto result
= KMessageBox::createKMessageBox(dialog
,
505 QMessageBox::Warning
,
506 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
508 i18n("Do not ask again"),
509 &doNotAskAgainCheckboxResult
,
510 KMessageBox::Notify
);
512 if (doNotAskAgainCheckboxResult
) {
513 GeneralSettings::setConfirmClosingMultipleTabs(false);
517 case QDialogButtonBox::Yes
:
520 case QDialogButtonBox::No
:
521 // Close only the current tab
522 m_tabWidget
->closeTab();
530 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
531 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
532 // Open a confirmation dialog with 3 buttons:
533 // QDialogButtonBox::Yes -> Quit
534 // QDialogButtonBox::No -> Show Terminal Panel
535 // QDialogButtonBox::Cancel -> do nothing
536 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
537 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
538 dialog
->setModal(true);
539 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
540 if (!m_terminalPanel
->isVisible()) {
541 standardButtons
|= QDialogButtonBox::No
;
543 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
544 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
545 if (!m_terminalPanel
->isVisible()) {
547 buttons
->button(QDialogButtonBox::No
),
548 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
550 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
552 bool doNotAskAgainCheckboxResult
= false;
554 const auto result
= KMessageBox::createKMessageBox(
557 QMessageBox::Warning
,
558 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
560 i18n("Do not ask again"),
561 &doNotAskAgainCheckboxResult
,
562 KMessageBox::Dangerous
);
564 if (doNotAskAgainCheckboxResult
) {
565 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
569 case QDialogButtonBox::Yes
:
572 case QDialogButtonBox::No
:
573 actionCollection()->action("show_terminal_panel")->trigger();
574 // Do not quit, ignore quit event
582 GeneralSettings::setVersion(CurrentDolphinVersion
);
583 GeneralSettings::self()->save();
585 KXmlGuiWindow::closeEvent(event
);
588 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
590 m_tabWidget
->saveProperties(group
);
593 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
595 m_tabWidget
->readProperties(group
);
598 void DolphinMainWindow::updateNewMenu()
600 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
601 m_newFileMenu
->checkUpToDate();
602 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
605 void DolphinMainWindow::createDirectory()
607 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
608 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
609 m_newFileMenu
->createDirectory();
612 void DolphinMainWindow::quit()
617 void DolphinMainWindow::showErrorMessage(const QString
& message
)
619 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
622 void DolphinMainWindow::slotUndoAvailable(bool available
)
624 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
626 undoAction
->setEnabled(available
);
630 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
632 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
634 undoAction
->setText(text
);
638 void DolphinMainWindow::undo()
641 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
642 KIO::FileUndoManager::self()->undo();
645 void DolphinMainWindow::cut()
647 m_activeViewContainer
->view()->cutSelectedItems();
650 void DolphinMainWindow::copy()
652 m_activeViewContainer
->view()->copySelectedItems();
655 void DolphinMainWindow::paste()
657 m_activeViewContainer
->view()->paste();
660 void DolphinMainWindow::find()
662 m_activeViewContainer
->setSearchModeEnabled(true);
665 void DolphinMainWindow::updateSearchAction()
667 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
668 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
671 void DolphinMainWindow::updatePasteAction()
673 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
674 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
675 pasteAction
->setEnabled(pasteInfo
.first
);
676 pasteAction
->setText(pasteInfo
.second
);
679 void DolphinMainWindow::slotDirectoryLoadingCompleted()
684 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
686 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
688 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
690 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
692 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
697 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
699 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
701 m_backAction
->menu()->clear();
702 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
703 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
705 m_backAction
->menu()->addAction(action
);
709 void DolphinMainWindow::slotGoBack(QAction
* action
)
711 int gotoIndex
= action
->data().value
<int>();
712 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
713 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
718 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
721 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
722 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
726 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
728 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
730 m_forwardAction
->menu()->clear();
731 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
732 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
734 m_forwardAction
->menu()->addAction(action
);
738 void DolphinMainWindow::slotGoForward(QAction
* action
)
740 int gotoIndex
= action
->data().value
<int>();
741 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
742 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
747 void DolphinMainWindow::selectAll()
751 // if the URL navigator is editable and focused, select the whole
752 // URL instead of all items of the view
754 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
755 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
756 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
757 lineEdit
->hasFocus();
759 lineEdit
->selectAll();
761 m_activeViewContainer
->view()->selectAll();
765 void DolphinMainWindow::invertSelection()
768 m_activeViewContainer
->view()->invertSelection();
771 void DolphinMainWindow::toggleSplitView()
773 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
774 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
779 void DolphinMainWindow::toggleSplitStash()
781 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
782 tabPage
->setSplitViewEnabled(false);
783 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
786 void DolphinMainWindow::reloadView()
789 m_activeViewContainer
->reload();
790 m_activeViewContainer
->statusBar()->updateSpaceInfo();
793 void DolphinMainWindow::stopLoading()
795 m_activeViewContainer
->view()->stopLoading();
798 void DolphinMainWindow::enableStopAction()
800 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
803 void DolphinMainWindow::disableStopAction()
805 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
808 void DolphinMainWindow::showFilterBar()
810 m_activeViewContainer
->setFilterBarVisible(true);
813 void DolphinMainWindow::toggleEditLocation()
817 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
818 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
819 urlNavigator
->setUrlEditable(action
->isChecked());
822 void DolphinMainWindow::replaceLocation()
824 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
825 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
827 // If the text field currently has focus and everything is selected,
828 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
829 if (navigator
->isUrlEditable()
830 && lineEdit
->hasFocus()
831 && lineEdit
->selectedText() == lineEdit
->text() ) {
832 navigator
->setUrlEditable(false);
834 navigator
->setUrlEditable(true);
835 navigator
->setFocus();
836 lineEdit
->selectAll();
840 void DolphinMainWindow::togglePanelLockState()
842 const bool newLockState
= !GeneralSettings::lockPanels();
843 foreach (QObject
* child
, children()) {
844 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
846 dock
->setLocked(newLockState
);
850 GeneralSettings::setLockPanels(newLockState
);
853 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
855 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
856 m_activeViewContainer
->view()->setFocus();
860 void DolphinMainWindow::goBack()
862 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
863 urlNavigator
->goBack();
865 if (urlNavigator
->locationState().isEmpty()) {
866 // An empty location state indicates a redirection URL,
867 // which must be skipped too
868 urlNavigator
->goBack();
872 void DolphinMainWindow::goForward()
874 m_activeViewContainer
->urlNavigator()->goForward();
877 void DolphinMainWindow::goUp()
879 m_activeViewContainer
->urlNavigator()->goUp();
882 void DolphinMainWindow::goHome()
884 m_activeViewContainer
->urlNavigator()->goHome();
887 void DolphinMainWindow::goBackInNewTab()
889 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
890 const int index
= urlNavigator
->historyIndex() + 1;
891 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
894 void DolphinMainWindow::goForwardInNewTab()
896 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
897 const int index
= urlNavigator
->historyIndex() - 1;
898 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
901 void DolphinMainWindow::goUpInNewTab()
903 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
904 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
907 void DolphinMainWindow::goHomeInNewTab()
909 openNewTabAfterCurrentTab(Dolphin::homeUrl());
912 void DolphinMainWindow::compareFiles()
914 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
915 if (items
.count() != 2) {
916 // The action is disabled in this case, but it could have been triggered
917 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
921 QUrl urlA
= items
.at(0).url();
922 QUrl urlB
= items
.at(1).url();
924 QString
command(QStringLiteral("kompare -c \""));
925 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
926 command
.append("\" \"");
927 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
928 command
.append('\"');
929 KRun::runCommand(command
, QStringLiteral("Kompare"), QStringLiteral("kompare"), this);
932 void DolphinMainWindow::toggleShowMenuBar()
934 const bool visible
= menuBar()->isVisible();
935 menuBar()->setVisible(!visible
);
937 createControlButton();
939 deleteControlButton();
943 QString
DolphinMainWindow::activeContainerLocalPath()
945 KIO::StatJob
* statJob
= KIO::mostLocalUrl(m_activeViewContainer
->url());
946 KJobWidgets::setWindow(statJob
, this);
948 QUrl url
= statJob
->mostLocalUrl();
949 if (url
.isLocalFile()) {
950 return url
.toLocalFile();
952 return QDir::homePath();
955 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
957 m_searchTools
.clear();
958 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
959 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
961 QList
<QAction
*> actions
= m_searchTools
.actions();
962 if (actions
.isEmpty()) {
965 QAction
* action
= actions
.first();
966 if (action
->isSeparator()) {
972 void DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction()
974 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
975 const QList
<QWidget
*> widgets
= openPreferredSearchTool
->associatedWidgets();
976 for (QWidget
* widget
: widgets
) {
977 QMenu
* menu
= qobject_cast
<QMenu
*>(widget
);
979 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
983 // Update the open_preferred_search_tool action *before* the Configure Shortcuts window is shown,
984 // since this action is then listed in that window and it should be up-to-date when it is displayed.
985 // This update is instantaneous if user made no changes to the search tools in the meantime.
986 // Maybe all KStandardActions should defer calls to their slots, so that we could simply connect() to trigger()?
988 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
)), &QAction::hovered
,
989 this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
992 updateOpenPreferredSearchToolAction();
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 KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath());
1027 void DolphinMainWindow::editSettings()
1029 if (!m_settingsDialog
) {
1030 DolphinViewContainer
* container
= activeViewContainer();
1031 container
->view()->writeSettings();
1033 const QUrl url
= container
->url();
1034 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1035 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1036 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1037 settingsDialog
->show();
1038 m_settingsDialog
= settingsDialog
;
1040 m_settingsDialog
.data()->raise();
1044 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1046 delete m_lastHandleUrlStatJob
;
1047 m_lastHandleUrlStatJob
= nullptr;
1049 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1050 activeViewContainer()->setUrl(url
);
1051 } else if (KProtocolManager::supportsListing(url
)) {
1052 // stat the URL to see if it is a dir or not
1053 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1054 if (m_lastHandleUrlStatJob
->uiDelegate()) {
1055 KJobWidgets::setWindow(m_lastHandleUrlStatJob
, this);
1057 connect(m_lastHandleUrlStatJob
, &KIO::Job::result
,
1058 this, &DolphinMainWindow::slotHandleUrlStatFinished
);
1061 new KRun(url
, this); // Automatically deletes itself after being finished
1065 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1067 m_lastHandleUrlStatJob
= nullptr;
1068 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1069 const QUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1070 if (entry
.isDir()) {
1071 activeViewContainer()->setUrl(url
);
1073 new KRun(url
, this); // Automatically deletes itself after being finished
1077 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1079 // trash:/ is writable but we don't want to create new items in it.
1080 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1081 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1084 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1085 const KFileItem
& item
,
1087 const QList
<QAction
*>& customActions
)
1089 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1090 contextMenu
.data()->setCustomActions(customActions
);
1091 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1094 case DolphinContextMenu::OpenParentFolder
:
1095 changeUrl(KIO::upUrl(item
.url()));
1096 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1097 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1100 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1101 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1104 case DolphinContextMenu::OpenParentFolderInNewTab
:
1105 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1108 case DolphinContextMenu::None
:
1113 // Delete the menu, unless it has been deleted in its own nested event loop already.
1115 contextMenu
->deleteLater();
1119 void DolphinMainWindow::updateControlMenu()
1121 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1124 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1125 // because 'menu' is their parent.
1128 KActionCollection
* ac
= actionCollection();
1130 menu
->addMenu(m_newFileMenu
->menu());
1131 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1132 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1133 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1135 menu
->addSeparator();
1137 // Add "Edit" actions
1138 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1139 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1140 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1143 menu
->addSeparator();
1146 // Add "View" actions
1147 if (!GeneralSettings::showZoomSlider()) {
1148 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1149 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1150 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1151 menu
->addSeparator();
1154 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1155 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1156 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1157 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1158 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1161 menu
->addSeparator();
1164 // Add a curated assortment of items from the "Tools" menu
1165 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1166 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1167 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1168 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
1170 menu
->addSeparator();
1172 // Add "Show Panels" menu
1173 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1175 // Add "Settings" menu entries
1176 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1177 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1178 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1179 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1182 auto helpMenu
= m_helpMenu
->menu();
1183 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1184 menu
->addMenu(helpMenu
);
1187 void DolphinMainWindow::updateToolBar()
1189 if (!menuBar()->isVisible()) {
1190 createControlButton();
1194 void DolphinMainWindow::slotControlButtonDeleted()
1196 m_controlButton
= nullptr;
1197 m_updateToolBarTimer
->start();
1200 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1202 DolphinViewContainer
* view
= activeViewContainer();
1204 if (view
->url() == url
) {
1205 // We can end up here if the user clicked a device in the Places Panel
1206 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1213 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1215 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1218 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1220 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1221 Q_ASSERT(viewContainer
);
1223 m_activeViewContainer
= viewContainer
;
1225 if (oldViewContainer
) {
1226 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1227 toggleSearchAction
->disconnect(oldViewContainer
);
1229 // Disconnect all signals between the old view container (container,
1230 // view and url navigator) and main window.
1231 oldViewContainer
->disconnect(this);
1232 oldViewContainer
->view()->disconnect(this);
1233 oldViewContainer
->urlNavigator()->disconnect(this);
1235 // except the requestItemInfo so that on hover the information panel can still be updated
1236 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1237 this, &DolphinMainWindow::requestItemInfo
);
1240 connectViewSignals(viewContainer
);
1242 m_actionHandler
->setCurrentView(viewContainer
->view());
1245 updateFileAndEditActions();
1246 updatePasteAction();
1247 updateViewActions();
1249 updateSearchAction();
1251 const QUrl url
= viewContainer
->url();
1252 emit
urlChanged(url
);
1255 void DolphinMainWindow::tabCountChanged(int count
)
1257 const bool enableTabActions
= (count
> 1);
1258 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1259 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1261 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1262 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1263 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1266 void DolphinMainWindow::updateWindowTitle()
1268 const QString newTitle
= m_activeViewContainer
->caption();
1269 if (windowTitle() != newTitle
) {
1270 setWindowTitle(newTitle
);
1274 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1276 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1277 m_tearDownFromPlacesRequested
= true;
1278 m_terminalPanel
->goHome();
1279 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1281 m_placesPanel
->proceedWithTearDown();
1285 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1287 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1288 m_tearDownFromPlacesRequested
= false;
1289 m_terminalPanel
->goHome();
1293 void DolphinMainWindow::setupActions()
1295 // setup 'File' menu
1296 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1297 QMenu
* menu
= m_newFileMenu
->menu();
1298 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1299 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1300 m_newFileMenu
->setDelayed(false);
1301 connect(menu
, &QMenu::aboutToShow
,
1302 this, &DolphinMainWindow::updateNewMenu
);
1304 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1305 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1306 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1307 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1308 "window just like this one with the current location and view."
1309 "<nl/>You can drag and drop items between windows."));
1310 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1312 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1313 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1314 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1315 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1316 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1317 "A tab is an additional view within this window. "
1318 "You can drag and drop items between tabs."));
1319 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1320 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1322 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1323 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1324 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1325 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1326 "to the Places panel."));
1327 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1329 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1330 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1331 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1332 "currently viewed tab. If no more tabs are left this window "
1333 "will close instead."));
1335 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1336 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1338 // setup 'Edit' menu
1339 KStandardAction::undo(this,
1340 &DolphinMainWindow::undo
,
1341 actionCollection());
1343 // i18n: This will be the last paragraph for the whatsthis for all three:
1344 // Cut, Copy and Paste
1345 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1346 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1347 "applications and are among the most used commands. That's why their "
1348 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1349 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1350 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1351 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1352 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1353 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1354 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1355 "the clipboard to a new location. The items will be removed from their "
1356 "initial location.") + cutCopyPastePara
);
1357 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1358 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1359 "items in your current selection to the <emphasis>clipboard</emphasis>."
1360 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1361 "from the clipboard to a new location.") + cutCopyPastePara
);
1362 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1363 // The text of the paste-action is modified dynamically by Dolphin
1364 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1365 // due to the long text, the text "Paste" is used:
1366 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1367 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1368 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1369 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1370 "action they are removed from their old location.") + cutCopyPastePara
);
1372 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1373 searchAction
->setText(i18n("Search..."));
1374 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1375 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1376 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1377 "There you can enter search terms and specify settings to find the "
1378 "objects you are looking for.</para><para>Use this help again on "
1379 "the find bar so we can have a look at it while the settings are "
1380 "explained.</para>"));
1382 // toggle_search acts as a copy of the main searchAction to be used mainly
1383 // in the toolbar, with no default shortcut attached, to avoid messing with
1384 // existing workflows (search bar always open and Ctrl-F to focus)
1385 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1386 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1387 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1388 toggleSearchAction
->setIcon(searchAction
->icon());
1389 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1390 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1391 toggleSearchAction
->setCheckable(true);
1393 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1394 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1395 "files and folders in the current location."));
1397 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1398 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1399 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1400 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1401 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1402 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1403 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1405 // setup 'View' menu
1406 // (note that most of it is set up in DolphinViewActionHandler)
1408 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1409 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1410 "the folder view below into two autonomous views.</para><para>This "
1411 "way you can see two locations at once and move items between them "
1412 "quickly.</para>Click this again afterwards to recombine the views."));
1413 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1414 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1416 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1417 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1418 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1419 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1420 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1421 stashSplit
->setCheckable(false);
1422 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1423 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1425 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1427 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1428 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1429 stop
->setToolTip(i18nc("@info", "Stop loading"));
1430 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1431 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1432 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1434 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1435 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1436 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1437 "This toggles the <emphasis>Location Bar</emphasis> to be "
1438 "editable so you can directly enter a location you want to go to.<nl/>"
1439 "You can also switch to editing by clicking to the right of the "
1440 "location and switch back by confirming the edited location."));
1441 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1442 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1444 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1445 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1446 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1447 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1448 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1449 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1450 "This switches to editing the location and selects it "
1451 "so you can quickly enter a different location."));
1452 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1453 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1457 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1458 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1459 m_backAction
->setObjectName(backAction
->objectName());
1460 m_backAction
->setShortcuts(backAction
->shortcuts());
1462 m_backAction
->setDelayed(true);
1463 m_backAction
->setStickyMenu(false);
1464 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1465 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1466 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1467 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1469 auto backShortcuts
= m_backAction
->shortcuts();
1470 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1471 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1473 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1474 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1475 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1476 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1477 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1478 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1479 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1480 this, &DolphinMainWindow::closedTabsCountChanged
);
1482 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1483 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1484 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1485 "This returns you to the previously closed tab."));
1486 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1487 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1488 undoCloseTab
->setEnabled(false);
1489 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1491 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1492 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1493 "the last change you made to files or folders.<nl/>"
1494 "Such changes include <interface>creating, renaming</interface> "
1495 "and <interface>moving</interface> them to a different location "
1496 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1497 "be undone will ask for your confirmation."));
1498 undoAction
->setEnabled(false); // undo should be disabled by default
1501 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1502 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1503 m_forwardAction
->setObjectName(forwardAction
->objectName());
1504 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1506 m_forwardAction
->setDelayed(true);
1507 m_forwardAction
->setStickyMenu(false);
1508 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1509 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1510 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1511 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1512 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1514 // enable middle-click to open in a new tab
1515 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1516 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1517 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1518 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1519 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1520 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1521 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1522 "<filename>Home</filename> folder.<nl/>Every user account "
1523 "has their own <filename>Home</filename> that contains their data "
1524 "including folders that contain personal application data."));
1526 // setup 'Tools' menu
1527 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1528 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1529 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1530 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1531 "There you can enter a text to filter the files and folders currently displayed. "
1532 "Only those that contain the text in their name will be kept in view."));
1533 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1534 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1535 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1537 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1538 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1539 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1540 compareFiles
->setEnabled(false);
1541 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1543 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1544 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1545 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1546 "<para>This opens a preferred search tool for the viewed location.</para>"
1547 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1548 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1549 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1550 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1552 #ifdef HAVE_TERMINAL
1553 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1554 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1555 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1556 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1557 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1558 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1559 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1560 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1561 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1563 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1564 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1565 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1566 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1567 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1571 // setup 'Bookmarks' menu
1572 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1573 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1574 // Make the toolbar button version work properly on click
1575 bookmarkMenu
->setDelayed(false);
1576 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1577 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1579 // setup 'Settings' menu
1580 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1581 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1582 "This switches between having a <emphasis>Menubar</emphasis> "
1583 "and having a <interface>Control</interface> button. Both "
1584 "contain mostly the same commands and configuration options."));
1585 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1586 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1587 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1589 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1590 m_helpMenu
= new KHelpMenu(nullptr);
1591 m_helpMenu
->menu()->installEventFilter(this);
1592 // remove duplicate shortcuts
1593 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1594 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1596 // not in menu actions
1597 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1598 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1600 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1601 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1603 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1604 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1605 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1606 activateTab
->setEnabled(false);
1607 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1609 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1611 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1615 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1616 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1617 activateLastTab
->setEnabled(false);
1618 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1619 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1621 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1622 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1623 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1624 activateNextTab
->setEnabled(false);
1625 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1626 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1628 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1629 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1630 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1631 activatePrevTab
->setEnabled(false);
1632 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1633 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1636 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1637 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1638 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1639 showTarget
->setEnabled(false);
1640 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1642 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1643 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1644 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1645 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1647 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1648 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1649 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1650 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1652 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1653 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1654 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1655 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1658 void DolphinMainWindow::setupDockWidgets()
1660 const bool lock
= GeneralSettings::lockPanels();
1662 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1663 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1664 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1665 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1666 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1667 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1668 "switches between having panels <emphasis>locked</emphasis> or "
1669 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1670 "dragged to the other side of the window and have a close "
1671 "button.<nl/>Locked panels are embedded more cleanly."));
1672 lockLayoutAction
->setActive(lock
);
1673 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1675 // Setup "Information"
1676 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1677 infoDock
->setLocked(lock
);
1678 infoDock
->setObjectName(QStringLiteral("infoDock"));
1679 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1682 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1683 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1684 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1685 infoDock
->setWidget(infoPanel
);
1687 QAction
* infoAction
= infoDock
->toggleViewAction();
1688 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1690 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1691 connect(this, &DolphinMainWindow::urlChanged
,
1692 infoPanel
, &InformationPanel::setUrl
);
1693 connect(this, &DolphinMainWindow::selectionChanged
,
1694 infoPanel
, &InformationPanel::setSelection
);
1695 connect(this, &DolphinMainWindow::requestItemInfo
,
1696 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1699 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1700 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1701 "hide panels like this go to <interface>Control|Panels</interface> "
1702 "or <interface>View|Panels</interface>.</para>");
1704 actionCollection()->action(QStringLiteral("show_information_panel"))
1705 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1706 "<emphasis>information</emphasis> panel at the right side of the "
1707 "window.</para><para>The panel provides in-depth information "
1708 "about the items your mouse is hovering over or about the selected "
1709 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1710 "For single items a preview of their contents is provided.</para>"));
1712 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1713 "provides in-depth information about the items your mouse is "
1714 "hovering over or about the selected items. Otherwise it informs "
1715 "you about the currently viewed folder.<nl/>For single items a "
1716 "preview of their contents is provided.</para><para>You can configure "
1717 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1720 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1721 foldersDock
->setLocked(lock
);
1722 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1723 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1724 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1725 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1726 foldersDock
->setWidget(foldersPanel
);
1728 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1729 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1731 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1732 connect(this, &DolphinMainWindow::urlChanged
,
1733 foldersPanel
, &FoldersPanel::setUrl
);
1734 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1735 this, &DolphinMainWindow::changeUrl
);
1736 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1737 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1738 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1739 this, &DolphinMainWindow::showErrorMessage
);
1741 actionCollection()->action(QStringLiteral("show_folders_panel"))
1742 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1743 "<emphasis>folders</emphasis> panel at the left side of the window."
1744 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1745 "</emphasis> in a <emphasis>tree view</emphasis>."));
1746 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1747 "shows the folders of the <emphasis>file system</emphasis> in a "
1748 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1749 "there. Click the arrow to the left of a folder to see its subfolders. "
1750 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1753 #ifdef HAVE_TERMINAL
1754 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1755 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1756 terminalDock
->setLocked(lock
);
1757 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1758 m_terminalPanel
= new TerminalPanel(terminalDock
);
1759 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1760 terminalDock
->setWidget(m_terminalPanel
);
1762 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1763 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1764 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1765 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1766 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1767 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1769 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1770 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1772 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1773 connect(this, &DolphinMainWindow::urlChanged
,
1774 m_terminalPanel
, &TerminalPanel::setUrl
);
1776 if (GeneralSettings::version() < 200) {
1777 terminalDock
->hide();
1780 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1781 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1782 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1783 "<nl/>The location in the terminal will always match the folder "
1784 "view so you can navigate using either.</para><para>The terminal "
1785 "panel is not needed for basic computer usage but can be useful "
1786 "for advanced tasks. To learn more about terminals use the help "
1787 "in a standalone terminal application like Konsole.</para>"));
1788 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1789 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1790 "normal terminal but will match the location of the folder view "
1791 "so you can navigate using either.</para><para>The terminal panel "
1792 "is not needed for basic computer usage but can be useful for "
1793 "advanced tasks. To learn more about terminals use the help in a "
1794 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1798 if (GeneralSettings::version() < 200) {
1800 foldersDock
->hide();
1804 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1805 placesDock
->setLocked(lock
);
1806 placesDock
->setObjectName(QStringLiteral("placesDock"));
1807 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1809 m_placesPanel
= new PlacesPanel(placesDock
);
1810 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1811 placesDock
->setWidget(m_placesPanel
);
1813 QAction
*placesAction
= placesDock
->toggleViewAction();
1814 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1816 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1817 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1818 this, &DolphinMainWindow::slotPlaceActivated
);
1819 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1820 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1821 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1822 this, &DolphinMainWindow::showErrorMessage
);
1823 connect(this, &DolphinMainWindow::urlChanged
,
1824 m_placesPanel
, &PlacesPanel::setUrl
);
1825 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1826 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1827 connect(this, &DolphinMainWindow::settingsChanged
,
1828 m_placesPanel
, &PlacesPanel::readSettings
);
1829 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1830 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1831 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1832 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1833 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1835 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1836 actionShowAllPlaces
->setCheckable(true);
1837 actionShowAllPlaces
->setDisabled(true);
1838 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1839 "all places in the places panel that have been hidden. They will "
1840 "appear semi-transparent unless you uncheck their hide property."));
1842 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1843 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1844 m_placesPanel
->showHiddenEntries(checked
);
1847 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1848 actionShowAllPlaces
->setChecked(checked
);
1849 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1852 actionCollection()->action(QStringLiteral("show_places_panel"))
1853 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1854 "<emphasis>places</emphasis> panel at the left side of the window."
1855 "</para><para>It allows you to go to locations you have "
1856 "bookmarked and to access disk or media attached to the computer "
1857 "or to the network. It also contains sections to find recently "
1858 "saved files or files of a certain type.</para>"));
1859 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1860 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1861 "you have bookmarked and to access disk or media attached to the "
1862 "computer or to the network. It also contains sections to find "
1863 "recently saved files or files of a certain type.</para><para>"
1864 "Click on an entry to go there. Click with the right mouse button "
1865 "instead to open any entry in a new tab or new window.</para>"
1866 "<para>New entries can be added by dragging folders onto this panel. "
1867 "Right-click any section or entry to hide it. Right-click an empty "
1868 "space on this panel and select <interface>Show Hidden Places"
1869 "</interface> to display it again.</para>") + panelWhatsThis
);
1871 // Add actions into the "Panels" menu
1872 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1873 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1874 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1875 panelsMenu
->setDelayed(false);
1876 const KActionCollection
* ac
= actionCollection();
1877 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1879 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1881 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1882 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1883 panelsMenu
->addSeparator();
1884 panelsMenu
->addAction(actionShowAllPlaces
);
1885 panelsMenu
->addAction(lockLayoutAction
);
1887 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1888 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1893 void DolphinMainWindow::updateFileAndEditActions()
1895 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1896 const KActionCollection
* col
= actionCollection();
1897 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1899 if (list
.isEmpty()) {
1900 stateChanged(QStringLiteral("has_no_selection"));
1902 addToPlacesAction
->setEnabled(true);
1904 stateChanged(QStringLiteral("has_selection"));
1906 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1907 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1908 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1909 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1910 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1911 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1912 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1914 if (list
.length() == 1 && list
.first().isDir()) {
1915 addToPlacesAction
->setEnabled(true);
1917 addToPlacesAction
->setEnabled(false);
1920 KFileItemListProperties
capabilities(list
);
1921 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1923 renameAction
->setEnabled(capabilities
.supportsMoving());
1924 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1925 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1926 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1927 cutAction
->setEnabled(capabilities
.supportsMoving());
1928 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
1929 duplicateAction
->setEnabled(capabilities
.supportsWriting());
1933 void DolphinMainWindow::updateViewActions()
1935 m_actionHandler
->updateViewActions();
1937 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
1938 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1940 updateSplitAction();
1942 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
1943 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1944 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1947 void DolphinMainWindow::updateGoActions()
1949 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1950 const QUrl currentUrl
= m_activeViewContainer
->url();
1951 // I think this is one of the best places to firstly be confronted
1952 // with a file system and its hierarchy. Talking about the root
1953 // directory might seem too much here but it is the question that
1954 // naturally arises in this context.
1955 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
1956 "the folder that contains the currently viewed one.</para>"
1957 "<para>All files and folders are organized in a hierarchical "
1958 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
1959 "a directory that contains all data connected to this computer"
1960 "—the <emphasis>root directory</emphasis>.</para>"));
1961 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
1964 void DolphinMainWindow::createControlButton()
1966 if (m_controlButton
) {
1969 Q_ASSERT(!m_controlButton
);
1971 m_controlButton
= new QToolButton(this);
1972 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
1973 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
1974 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
1975 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
1976 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1978 QMenu
* controlMenu
= new QMenu(m_controlButton
);
1979 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
1980 controlMenu
->installEventFilter(this);
1982 m_controlButton
->setMenu(controlMenu
);
1984 toolBar()->addWidget(m_controlButton
);
1985 connect(toolBar(), &KToolBar::iconSizeChanged
,
1986 m_controlButton
, &QToolButton::setIconSize
);
1988 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1989 // gets edited. In this case we must add them again. The adding is done asynchronously by
1990 // m_updateToolBarTimer.
1991 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
1992 m_updateToolBarTimer
= new QTimer(this);
1993 m_updateToolBarTimer
->setInterval(500);
1994 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
1997 void DolphinMainWindow::deleteControlButton()
1999 delete m_controlButton
;
2000 m_controlButton
= nullptr;
2002 delete m_updateToolBarTimer
;
2003 m_updateToolBarTimer
= nullptr;
2006 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2011 const KToolBar
* toolBarWidget
= toolBar();
2012 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2013 if (widget
== toolBarWidget
) {
2018 menu
->addAction(action
);
2022 void DolphinMainWindow::refreshViews()
2024 m_tabWidget
->refreshViews();
2026 if (GeneralSettings::modifiedStartupSettings()) {
2027 // The startup settings have been changed by the user (see bug #254947).
2028 // Synchronize the split-view setting with the active view:
2029 const bool splitView
= GeneralSettings::splitView();
2030 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2031 updateSplitAction();
2032 updateWindowTitle();
2035 emit
settingsChanged();
2038 void DolphinMainWindow::clearStatusBar()
2040 m_activeViewContainer
->statusBar()->resetToDefaultText();
2043 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2045 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2046 this, &DolphinMainWindow::updateFilterBarAction
);
2047 connect(container
, &DolphinViewContainer::writeStateChanged
,
2048 this, &DolphinMainWindow::slotWriteStateChanged
);
2049 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2050 this, &DolphinMainWindow::updateSearchAction
);
2052 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2053 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2055 const DolphinView
* view
= container
->view();
2056 connect(view
, &DolphinView::selectionChanged
,
2057 this, &DolphinMainWindow::slotSelectionChanged
);
2058 connect(view
, &DolphinView::requestItemInfo
,
2059 this, &DolphinMainWindow::requestItemInfo
);
2060 connect(view
, &DolphinView::tabRequested
,
2061 this, &DolphinMainWindow::openNewTab
);
2062 connect(view
, &DolphinView::requestContextMenu
,
2063 this, &DolphinMainWindow::openContextMenu
);
2064 connect(view
, &DolphinView::directoryLoadingStarted
,
2065 this, &DolphinMainWindow::enableStopAction
);
2066 connect(view
, &DolphinView::directoryLoadingCompleted
,
2067 this, &DolphinMainWindow::disableStopAction
);
2068 connect(view
, &DolphinView::directoryLoadingCompleted
,
2069 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2070 connect(view
, &DolphinView::goBackRequested
,
2071 this, &DolphinMainWindow::goBack
);
2072 connect(view
, &DolphinView::goForwardRequested
,
2073 this, &DolphinMainWindow::goForward
);
2074 connect(view
, &DolphinView::urlActivated
,
2075 this, &DolphinMainWindow::handleUrl
);
2077 const KUrlNavigator
* navigator
= container
->urlNavigator();
2078 connect(navigator
, &KUrlNavigator::urlChanged
,
2079 this, &DolphinMainWindow::changeUrl
);
2080 connect(navigator
, &KUrlNavigator::historyChanged
,
2081 this, &DolphinMainWindow::updateHistory
);
2082 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2083 this, &DolphinMainWindow::slotEditableStateChanged
);
2084 connect(navigator
, &KUrlNavigator::tabRequested
,
2085 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2088 void DolphinMainWindow::updateSplitAction()
2090 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2091 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2092 if (tabPage
->splitViewEnabled()) {
2093 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2094 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2095 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2096 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2098 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2099 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2100 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2103 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2104 splitAction
->setToolTip(i18nc("@info", "Split view"));
2105 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2109 bool DolphinMainWindow::isKompareInstalled() const
2111 static bool initialized
= false;
2112 static bool installed
= false;
2114 // TODO: maybe replace this approach later by using a menu
2115 // plugin like kdiff3plugin.cpp
2116 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2122 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2123 const QKeySequence
& shortcut
,
2124 QAction
* dockAction
,
2125 const QString
& actionName
)
2127 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2128 panelAction
->setCheckable(true);
2129 panelAction
->setChecked(dockAction
->isChecked());
2130 panelAction
->setText(dockAction
->text());
2131 panelAction
->setIcon(icon
);
2132 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2134 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2135 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2138 void DolphinMainWindow::setupWhatsThis()
2141 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2142 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2143 "configuration options. Left-click on any of the menus on this "
2144 "bar to see its contents.</para><para>The Menubar can be hidden "
2145 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2146 "most of its contents become available through a <interface>Control"
2147 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2148 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2149 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2150 "frequently used actions.</para><para>It is highly customizable. "
2151 "All items you see in the <interface>Control</interface> menu or "
2152 "in the <interface>Menubar</interface> can be placed on the "
2153 "Toolbar. Just right-click on it and select <interface>Configure "
2154 "Toolbars…</interface> or find this action in the <interface>"
2155 "Control</interface> or <interface>Settings</interface> menu."
2156 "</para><para>The location of the bar and the style of its "
2157 "buttons can also be changed in the right-click menu. Right-click "
2158 "a button if you want to show or hide its text.</para>"));
2159 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2160 "<para>Here you can see the <emphasis>folders</emphasis> and "
2161 "<emphasis>files</emphasis> that are at the location described in "
2162 "the <interface>Location Bar</interface> above. This area is the "
2163 "central part of this application where you navigate to the files "
2164 "you want to use.</para><para>For an elaborate and general "
2165 "introduction to this application <link "
2166 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2167 "click here</link>. This will open an introductory article from "
2168 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2169 "explanations of all the features of this <emphasis>view</emphasis> "
2170 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2171 "instead. This will open a page from the <emphasis>Handbook"
2172 "</emphasis> that covers the basics.</para>"));
2175 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2176 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2177 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2178 "There you can set up key combinations to trigger an action when "
2179 "they are pressed simultaneously. All commands in this application can "
2180 "be triggered this way.</para>"));
2181 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2182 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2183 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2184 "<para>All items you see in the <interface>Control</interface> menu "
2185 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2186 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2187 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2188 "change a multitude of settings for this application. For an explanation "
2189 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2190 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2193 // The whatsthis has to be set for the m_helpMenu and for the
2194 // StandardAction separately because both are used in different locations.
2195 // m_helpMenu is only used for createControlButton() button.
2197 // Links do not work within the Menubar so texts without links are provided there.
2199 // i18n: If the external link isn't available in your language you should
2200 // probably state the external link language at least in brackets to not
2201 // frustrate the user. If there are multiple languages that the user might
2202 // know with a reasonable chance you might want to have 2 external links.
2203 // The same is in my opinion true for every external link you translate.
2204 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2205 "<para>This opens the Handbook for this application. It provides "
2206 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2207 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2208 ->setWhatsThis(whatsThisHelpContents
2209 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2210 "<para>If you want more elaborate introductions to the "
2211 "different features of <emphasis>Dolphin</emphasis> "
2212 "go to the KDE UserBase Wiki.</para>"));
2213 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2214 + xi18nc("@info:whatsthis second half of handbook text with link",
2215 "<para>If you want more elaborate introductions to the "
2216 "different features of <emphasis>Dolphin</emphasis> "
2217 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2218 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2220 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2221 "<para>This is the button that invokes the help feature you are "
2222 "using right now! Click it, then click any component of this "
2223 "application to ask \"What's this?\" about it. The mouse cursor "
2224 "will change appearance if no help is available for a spot.</para>");
2225 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2226 ->setWhatsThis(whatsThisWhatsThis
2227 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2228 "<para>There are two other ways to get help for this application: The "
2229 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2230 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2231 "article about <emphasis>File Management</emphasis> online."
2232 "</para><para>The \"What's this?\" help is "
2233 "missing in most other windows so don't get too used to this.</para>"));
2234 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2235 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2236 "<para>There are two other ways to get help: "
2237 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2238 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2239 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2240 "missing in most other windows so don't get too used to this.</para>"));
2242 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2243 "window that will guide you through reporting errors or flaws "
2244 "in this application or in other KDE software.</para>");
2245 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2246 ->setWhatsThis(whatsThisReportBug
);
2247 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2248 + xi18nc("@info:whatsthis second half of reportbug text with link",
2249 "<para>High-quality bug reports are much appreciated. To learn "
2250 "how to make your bug report as effective as possible "
2251 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2252 "click here</link>.</para>"));
2254 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2255 "<emphasis>web page</emphasis> where you can donate to "
2256 "support the continued work on this application and many "
2257 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2258 "<para>Donating is the easiest and fastest way to efficiently "
2259 "support KDE and its projects. KDE projects are available for "
2260 "free therefore your donation is needed to cover things that "
2261 "require money like servers, contributor meetings, etc.</para>"
2262 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2263 "organization behind the KDE community.</para>");
2264 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2265 ->setWhatsThis(whatsThisDonate
);
2266 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2268 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2269 "With this you can change the language this application uses."
2270 "<nl/>You can even set secondary languages which will be used "
2271 "if texts are not available in your preferred language.");
2272 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2273 ->setWhatsThis(whatsThisSwitchLanguage
);
2274 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2276 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2277 "window that informs you about the version, license, "
2278 "used libraries and maintainers of this application.");
2279 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2280 ->setWhatsThis(whatsThisAboutApp
);
2281 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2283 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2284 "window with information about <emphasis>KDE</emphasis>. "
2285 "The KDE community are the people behind this free software."
2286 "<nl/>If you like using this application but don't know "
2287 "about KDE or want to see a cute dragon have a look!");
2288 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2289 ->setWhatsThis(whatsThisAboutKDE
);
2290 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2293 bool DolphinMainWindow::event(QEvent
*event
)
2295 if (event
->type() == QEvent::WhatsThisClicked
) {
2297 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2298 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2300 } else if (event
->type() == QEvent::WindowActivate
) {
2301 updateOpenPreferredSearchToolAction();
2303 return KXmlGuiWindow::event(event
);
2306 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2309 if (event
->type() == QEvent::WhatsThisClicked
) {
2311 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2312 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2318 void DolphinMainWindow::focusTerminalPanel()
2320 if (m_terminalPanel
->isVisible()) {
2321 if (m_terminalPanel
->terminalHasFocus()) {
2322 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2323 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2325 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2326 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2329 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2330 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2334 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2335 KIO::FileUndoManager::UiInterface()
2339 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2343 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2345 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2347 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2348 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2350 KIO::FileUndoManager::UiInterface::jobError(job
);
2354 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2356 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));