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>
69 #include <KToggleAction>
71 #include <KToolBarPopupAction>
72 #include <KToolInvocation>
73 #include <KUrlComboBox>
74 #include <KUrlNavigator>
75 #include <KWindowSystem>
77 #include <QApplication>
79 #include <QCloseEvent>
80 #include <QDesktopServices>
86 #include <QPushButton>
88 #include <QStandardPaths>
90 #include <QToolButton>
91 #include <QWhatsThisClickedEvent>
94 // Used for GeneralSettings::version() to determine whether
95 // an updated version of Dolphin is running.
96 const int CurrentDolphinVersion
= 200;
97 // The maximum number of entries in the back/forward popup menu
98 const int MaxNumberOfNavigationentries
= 12;
99 // The maximum number of "Activate Tab" shortcuts
100 const int MaxActivateTabShortcuts
= 9;
103 DolphinMainWindow::DolphinMainWindow() :
104 KXmlGuiWindow(nullptr),
105 m_newFileMenu(nullptr),
107 m_tabWidget(nullptr),
108 m_activeViewContainer(nullptr),
109 m_actionHandler(nullptr),
110 m_remoteEncoding(nullptr),
112 m_bookmarkHandler(nullptr),
113 m_controlButton(nullptr),
114 m_updateToolBarTimer(nullptr),
115 m_lastHandleUrlStatJob(nullptr),
116 m_terminalPanel(nullptr),
117 m_placesPanel(nullptr),
118 m_tearDownFromPlacesRequested(false),
119 m_backAction(nullptr),
120 m_forwardAction(nullptr)
122 Q_INIT_RESOURCE(dolphin
);
124 new MainWindowAdaptor(this);
127 setWindowFlags(Qt::WindowContextHelpButtonHint
);
129 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
130 setObjectName(QStringLiteral("Dolphin#"));
132 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
133 this, &DolphinMainWindow::showErrorMessage
);
135 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
136 undoManager
->setUiInterface(new UndoUiInterface());
138 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
139 this, &DolphinMainWindow::slotUndoAvailable
);
140 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
141 this, &DolphinMainWindow::slotUndoTextChanged
);
142 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
143 this, &DolphinMainWindow::clearStatusBar
);
144 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
145 this, &DolphinMainWindow::showCommand
);
147 GeneralSettings
* generalSettings
= GeneralSettings::self();
148 const bool firstRun
= (generalSettings
->version() < 200);
150 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
153 setAcceptDrops(true);
155 m_tabWidget
= new DolphinTabWidget(this);
156 m_tabWidget
->setObjectName("tabWidget");
157 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
158 this, &DolphinMainWindow::activeViewChanged
);
159 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
160 this, &DolphinMainWindow::tabCountChanged
);
161 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
162 this, &DolphinMainWindow::updateWindowTitle
);
163 setCentralWidget(m_tabWidget
);
167 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
168 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
169 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
171 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
172 connect(this, &DolphinMainWindow::urlChanged
,
173 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
177 setupGUI(Keys
| Save
| Create
| ToolBar
);
178 stateChanged(QStringLiteral("new_file"));
180 QClipboard
* clipboard
= QApplication::clipboard();
181 connect(clipboard
, &QClipboard::dataChanged
,
182 this, &DolphinMainWindow::updatePasteAction
);
184 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
185 showFilterBarAction
->setChecked(generalSettings
->filterBar());
188 menuBar()->setVisible(false);
189 // Assure a proper default size if Dolphin runs the first time
193 const bool showMenu
= !menuBar()->isHidden();
194 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
195 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
197 createControlButton();
200 // enable middle-click on back/forward/up to open in a new tab
201 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
202 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
203 toolBar()->installEventFilter(middleClickEventFilter
);
207 connect(KSycoca::self(), QOverload
<>::of(&KSycoca::databaseChanged
), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
209 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
212 DolphinMainWindow::~DolphinMainWindow()
216 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
218 QVector
<DolphinViewContainer
*> viewContainers
;
219 viewContainers
.reserve(m_tabWidget
->count());
220 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
221 viewContainers
<< m_tabWidget
->tabPageAt(i
)->activeViewContainer();
223 return viewContainers
;
226 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
228 m_tabWidget
->openDirectories(dirs
, splitView
);
231 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
233 openDirectories(QUrl::fromStringList(dirs
), splitView
);
236 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
238 m_tabWidget
->openFiles(files
, splitView
);
241 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
243 openFiles(QUrl::fromStringList(files
), splitView
);
246 void DolphinMainWindow::activateWindow()
248 window()->setAttribute(Qt::WA_NativeWindow
, true);
249 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
250 KWindowSystem::activateWindow(window()->effectiveWinId());
253 void DolphinMainWindow::showCommand(CommandType command
)
255 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
257 case KIO::FileUndoManager::Copy
:
258 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
260 case KIO::FileUndoManager::Move
:
261 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
263 case KIO::FileUndoManager::Link
:
264 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
266 case KIO::FileUndoManager::Trash
:
267 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
269 case KIO::FileUndoManager::Rename
:
270 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
273 case KIO::FileUndoManager::Mkdir
:
274 statusBar
->setText(i18nc("@info:status", "Created folder."));
282 void DolphinMainWindow::pasteIntoFolder()
284 m_activeViewContainer
->view()->pasteIntoFolder();
287 void DolphinMainWindow::changeUrl(const QUrl
&url
)
289 if (!KProtocolManager::supportsListing(url
)) {
290 // The URL navigator only checks for validity, not
291 // if the URL can be listed. An error message is
292 // shown due to DolphinViewContainer::restoreView().
296 m_activeViewContainer
->setUrl(url
);
297 updateFileAndEditActions();
302 emit
urlChanged(url
);
305 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
307 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
308 m_placesPanel
->proceedWithTearDown();
309 m_tearDownFromPlacesRequested
= false;
312 m_activeViewContainer
->setAutoGrabFocus(false);
314 m_activeViewContainer
->setAutoGrabFocus(true);
317 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
319 KToggleAction
* editableLocationAction
=
320 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
321 editableLocationAction
->setChecked(editable
);
324 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
326 updateFileAndEditActions();
328 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
330 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
331 if (selectedUrlsCount
== 2) {
332 compareFilesAction
->setEnabled(isKompareInstalled());
334 compareFilesAction
->setEnabled(false);
337 emit
selectionChanged(selection
);
340 void DolphinMainWindow::updateHistory()
342 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
343 const int index
= urlNavigator
->historyIndex();
345 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
347 backAction
->setToolTip(i18nc("@info", "Go back"));
348 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
349 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
352 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
354 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
355 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
356 "This undoes a <interface>Go|Back</interface> action."));
357 forwardAction
->setEnabled(index
> 0);
361 void DolphinMainWindow::updateFilterBarAction(bool show
)
363 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
364 showFilterBarAction
->setChecked(show
);
367 void DolphinMainWindow::openNewMainWindow()
369 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
372 void DolphinMainWindow::openNewActivatedTab()
374 m_tabWidget
->openNewActivatedTab();
377 void DolphinMainWindow::addToPlaces()
382 // If nothing is selected, act on the current dir
383 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
384 url
= m_activeViewContainer
->url();
385 name
= m_activeViewContainer
->placesText();
387 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
388 url
= dirToAdd
.url();
389 name
= dirToAdd
.name();
392 PlacesItemModel model
;
394 if (m_activeViewContainer
->isSearchModeEnabled()) {
395 icon
= QStringLiteral("folder-saved-search-symbolic");
397 icon
= KIO::iconNameForUrl(url
);
399 model
.createPlacesItem(name
, url
, icon
);
403 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
405 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
408 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
410 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
413 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
415 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
418 void DolphinMainWindow::openInNewTab()
420 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
421 bool tabCreated
= false;
423 foreach (const KFileItem
& item
, list
) {
424 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
425 if (!url
.isEmpty()) {
426 openNewTabAfterCurrentTab(url
);
431 // if no new tab has been created from the selection
432 // open the current directory in a new tab
434 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
438 void DolphinMainWindow::openInNewWindow()
442 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
443 if (list
.isEmpty()) {
444 newWindowUrl
= m_activeViewContainer
->url();
445 } else if (list
.count() == 1) {
446 const KFileItem
& item
= list
.first();
447 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
450 if (!newWindowUrl
.isEmpty()) {
451 Dolphin::openNewWindow({newWindowUrl
}, this);
455 void DolphinMainWindow::showTarget()
457 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
458 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
459 auto linkDestination
= link
.linkDest();
460 if (QFileInfo(linkDestination
).isRelative()) {
461 linkDestination
= linkLocationDir
.filePath(linkDestination
);
463 if (QFileInfo::exists(linkDestination
)) {
464 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
466 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
467 DolphinViewContainer::Warning
);
471 void DolphinMainWindow::showEvent(QShowEvent
* event
)
473 KXmlGuiWindow::showEvent(event
);
475 if (!event
->spontaneous()) {
476 m_activeViewContainer
->view()->setFocus();
480 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
482 // Find out if Dolphin is closed directly by the user or
483 // by the session manager because the session is closed
484 bool closedByUser
= true;
485 if (qApp
->isSavingSession()) {
486 closedByUser
= false;
489 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
490 // Ask the user if he really wants to quit and close all tabs.
491 // Open a confirmation dialog with 3 buttons:
492 // QDialogButtonBox::Yes -> Quit
493 // QDialogButtonBox::No -> Close only the current tab
494 // QDialogButtonBox::Cancel -> do nothing
495 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
496 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
497 dialog
->setModal(true);
498 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
499 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
500 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
501 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
502 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
504 bool doNotAskAgainCheckboxResult
= false;
506 const auto result
= KMessageBox::createKMessageBox(dialog
,
508 QMessageBox::Warning
,
509 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
511 i18n("Do not ask again"),
512 &doNotAskAgainCheckboxResult
,
513 KMessageBox::Notify
);
515 if (doNotAskAgainCheckboxResult
) {
516 GeneralSettings::setConfirmClosingMultipleTabs(false);
520 case QDialogButtonBox::Yes
:
523 case QDialogButtonBox::No
:
524 // Close only the current tab
525 m_tabWidget
->closeTab();
533 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
534 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
535 // Open a confirmation dialog with 3 buttons:
536 // QDialogButtonBox::Yes -> Quit
537 // QDialogButtonBox::No -> Show Terminal Panel
538 // QDialogButtonBox::Cancel -> do nothing
539 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
540 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
541 dialog
->setModal(true);
542 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
543 if (!m_terminalPanel
->isVisible()) {
544 standardButtons
|= QDialogButtonBox::No
;
546 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
547 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
548 if (!m_terminalPanel
->isVisible()) {
550 buttons
->button(QDialogButtonBox::No
),
551 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
553 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
555 bool doNotAskAgainCheckboxResult
= false;
557 const auto result
= KMessageBox::createKMessageBox(
560 QMessageBox::Warning
,
561 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
563 i18n("Do not ask again"),
564 &doNotAskAgainCheckboxResult
,
565 KMessageBox::Dangerous
);
567 if (doNotAskAgainCheckboxResult
) {
568 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
572 case QDialogButtonBox::Yes
:
575 case QDialogButtonBox::No
:
576 actionCollection()->action("show_terminal_panel")->trigger();
577 // Do not quit, ignore quit event
585 GeneralSettings::setVersion(CurrentDolphinVersion
);
586 GeneralSettings::self()->save();
588 KXmlGuiWindow::closeEvent(event
);
591 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
593 m_tabWidget
->saveProperties(group
);
596 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
598 m_tabWidget
->readProperties(group
);
601 void DolphinMainWindow::updateNewMenu()
603 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
604 m_newFileMenu
->checkUpToDate();
605 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
608 void DolphinMainWindow::createDirectory()
610 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
611 m_newFileMenu
->setPopupFiles(QList
<QUrl
>() << activeViewContainer()->url());
612 m_newFileMenu
->createDirectory();
615 void DolphinMainWindow::quit()
620 void DolphinMainWindow::showErrorMessage(const QString
& message
)
622 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
625 void DolphinMainWindow::slotUndoAvailable(bool available
)
627 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
629 undoAction
->setEnabled(available
);
633 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
635 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
637 undoAction
->setText(text
);
641 void DolphinMainWindow::undo()
644 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
645 KIO::FileUndoManager::self()->undo();
648 void DolphinMainWindow::cut()
650 m_activeViewContainer
->view()->cutSelectedItems();
653 void DolphinMainWindow::copy()
655 m_activeViewContainer
->view()->copySelectedItems();
658 void DolphinMainWindow::paste()
660 m_activeViewContainer
->view()->paste();
663 void DolphinMainWindow::find()
665 m_activeViewContainer
->setSearchModeEnabled(true);
668 void DolphinMainWindow::updateSearchAction()
670 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
671 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
674 void DolphinMainWindow::updatePasteAction()
676 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
677 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
678 pasteAction
->setEnabled(pasteInfo
.first
);
679 pasteAction
->setText(pasteInfo
.second
);
682 void DolphinMainWindow::slotDirectoryLoadingCompleted()
687 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
689 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
691 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
693 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
695 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
700 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
702 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
704 m_backAction
->menu()->clear();
705 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
706 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
708 m_backAction
->menu()->addAction(action
);
712 void DolphinMainWindow::slotGoBack(QAction
* action
)
714 int gotoIndex
= action
->data().value
<int>();
715 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
716 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
721 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
724 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
725 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
729 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
731 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
733 m_forwardAction
->menu()->clear();
734 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
735 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
737 m_forwardAction
->menu()->addAction(action
);
741 void DolphinMainWindow::slotGoForward(QAction
* action
)
743 int gotoIndex
= action
->data().value
<int>();
744 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
745 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
750 void DolphinMainWindow::selectAll()
754 // if the URL navigator is editable and focused, select the whole
755 // URL instead of all items of the view
757 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
758 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
759 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
760 lineEdit
->hasFocus();
762 lineEdit
->selectAll();
764 m_activeViewContainer
->view()->selectAll();
768 void DolphinMainWindow::invertSelection()
771 m_activeViewContainer
->view()->invertSelection();
774 void DolphinMainWindow::toggleSplitView()
776 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
777 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
782 void DolphinMainWindow::toggleSplitStash()
784 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
785 tabPage
->setSplitViewEnabled(false);
786 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
789 void DolphinMainWindow::reloadView()
792 m_activeViewContainer
->reload();
793 m_activeViewContainer
->statusBar()->updateSpaceInfo();
796 void DolphinMainWindow::stopLoading()
798 m_activeViewContainer
->view()->stopLoading();
801 void DolphinMainWindow::enableStopAction()
803 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
806 void DolphinMainWindow::disableStopAction()
808 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
811 void DolphinMainWindow::showFilterBar()
813 m_activeViewContainer
->setFilterBarVisible(true);
816 void DolphinMainWindow::toggleEditLocation()
820 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
821 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
822 urlNavigator
->setUrlEditable(action
->isChecked());
825 void DolphinMainWindow::replaceLocation()
827 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
828 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
830 // If the text field currently has focus and everything is selected,
831 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
832 if (navigator
->isUrlEditable()
833 && lineEdit
->hasFocus()
834 && lineEdit
->selectedText() == lineEdit
->text() ) {
835 navigator
->setUrlEditable(false);
837 navigator
->setUrlEditable(true);
838 navigator
->setFocus();
839 lineEdit
->selectAll();
843 void DolphinMainWindow::togglePanelLockState()
845 const bool newLockState
= !GeneralSettings::lockPanels();
846 foreach (QObject
* child
, children()) {
847 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
849 dock
->setLocked(newLockState
);
853 GeneralSettings::setLockPanels(newLockState
);
856 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
858 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
859 m_activeViewContainer
->view()->setFocus();
863 void DolphinMainWindow::goBack()
865 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
866 urlNavigator
->goBack();
868 if (urlNavigator
->locationState().isEmpty()) {
869 // An empty location state indicates a redirection URL,
870 // which must be skipped too
871 urlNavigator
->goBack();
875 void DolphinMainWindow::goForward()
877 m_activeViewContainer
->urlNavigator()->goForward();
880 void DolphinMainWindow::goUp()
882 m_activeViewContainer
->urlNavigator()->goUp();
885 void DolphinMainWindow::goHome()
887 m_activeViewContainer
->urlNavigator()->goHome();
890 void DolphinMainWindow::goBackInNewTab()
892 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
893 const int index
= urlNavigator
->historyIndex() + 1;
894 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
897 void DolphinMainWindow::goForwardInNewTab()
899 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
900 const int index
= urlNavigator
->historyIndex() - 1;
901 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
904 void DolphinMainWindow::goUpInNewTab()
906 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
907 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
910 void DolphinMainWindow::goHomeInNewTab()
912 openNewTabAfterCurrentTab(Dolphin::homeUrl());
915 void DolphinMainWindow::compareFiles()
917 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
918 if (items
.count() != 2) {
919 // The action is disabled in this case, but it could have been triggered
920 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
924 QUrl urlA
= items
.at(0).url();
925 QUrl urlB
= items
.at(1).url();
927 QString
command(QStringLiteral("kompare -c \""));
928 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
929 command
.append("\" \"");
930 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
931 command
.append('\"');
932 KRun::runCommand(command
, QStringLiteral("Kompare"), QStringLiteral("kompare"), this);
935 void DolphinMainWindow::toggleShowMenuBar()
937 const bool visible
= menuBar()->isVisible();
938 menuBar()->setVisible(!visible
);
940 createControlButton();
942 deleteControlButton();
946 QString
DolphinMainWindow::activeContainerLocalPath()
948 KIO::StatJob
* statJob
= KIO::mostLocalUrl(m_activeViewContainer
->url());
949 KJobWidgets::setWindow(statJob
, this);
951 QUrl url
= statJob
->mostLocalUrl();
952 if (url
.isLocalFile()) {
953 return url
.toLocalFile();
955 return QDir::homePath();
958 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
960 m_searchTools
.clear();
961 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
962 &m_searchTools
, { "files-find" }, m_activeViewContainer
->url()
964 QList
<QAction
*> actions
= m_searchTools
.actions();
965 if (actions
.isEmpty()) {
968 QAction
* action
= actions
.first();
969 if (action
->isSeparator()) {
975 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
977 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
978 if (!openPreferredSearchTool
) {
981 QPointer
<QAction
> tool
= preferredSearchTool();
983 openPreferredSearchTool
->setVisible(true);
984 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
985 openPreferredSearchTool
->setIcon(tool
->icon());
987 openPreferredSearchTool
->setVisible(false);
988 // still visible in Shortcuts configuration window
989 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
990 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
994 void DolphinMainWindow::openPreferredSearchTool()
996 QPointer
<QAction
> tool
= preferredSearchTool();
1002 void DolphinMainWindow::openTerminal()
1004 KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath());
1007 void DolphinMainWindow::editSettings()
1009 if (!m_settingsDialog
) {
1010 DolphinViewContainer
* container
= activeViewContainer();
1011 container
->view()->writeSettings();
1013 const QUrl url
= container
->url();
1014 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1015 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1016 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1017 settingsDialog
->show();
1018 m_settingsDialog
= settingsDialog
;
1020 m_settingsDialog
.data()->raise();
1024 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1026 delete m_lastHandleUrlStatJob
;
1027 m_lastHandleUrlStatJob
= nullptr;
1029 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1030 activeViewContainer()->setUrl(url
);
1031 } else if (KProtocolManager::supportsListing(url
)) {
1032 // stat the URL to see if it is a dir or not
1033 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1034 if (m_lastHandleUrlStatJob
->uiDelegate()) {
1035 KJobWidgets::setWindow(m_lastHandleUrlStatJob
, this);
1037 connect(m_lastHandleUrlStatJob
, &KIO::Job::result
,
1038 this, &DolphinMainWindow::slotHandleUrlStatFinished
);
1041 new KRun(url
, this); // Automatically deletes itself after being finished
1045 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1047 m_lastHandleUrlStatJob
= nullptr;
1048 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1049 const QUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1050 if (entry
.isDir()) {
1051 activeViewContainer()->setUrl(url
);
1053 new KRun(url
, this); // Automatically deletes itself after being finished
1057 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1059 // trash:/ is writable but we don't want to create new items in it.
1060 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1061 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1064 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1065 const KFileItem
& item
,
1067 const QList
<QAction
*>& customActions
)
1069 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1070 contextMenu
.data()->setCustomActions(customActions
);
1071 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1074 case DolphinContextMenu::OpenParentFolder
:
1075 changeUrl(KIO::upUrl(item
.url()));
1076 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1077 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1080 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1081 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1084 case DolphinContextMenu::OpenParentFolderInNewTab
:
1085 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1088 case DolphinContextMenu::None
:
1093 // Delete the menu, unless it has been deleted in its own nested event loop already.
1095 contextMenu
->deleteLater();
1099 void DolphinMainWindow::updateControlMenu()
1101 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1104 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1105 // because 'menu' is their parent.
1108 KActionCollection
* ac
= actionCollection();
1110 menu
->addMenu(m_newFileMenu
->menu());
1111 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1112 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1113 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1115 menu
->addSeparator();
1117 // Add "Edit" actions
1118 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1119 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1120 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1123 menu
->addSeparator();
1126 // Add "View" actions
1127 if (!GeneralSettings::showZoomSlider()) {
1128 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1129 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1130 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1131 menu
->addSeparator();
1134 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1135 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1136 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1137 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1138 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1141 menu
->addSeparator();
1144 // Add a curated assortment of items from the "Tools" menu
1145 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1146 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1147 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1149 menu
->addSeparator();
1151 // Add "Show Panels" menu
1152 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1154 // Add "Settings" menu entries
1155 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1156 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1157 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1158 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1161 auto helpMenu
= m_helpMenu
->menu();
1162 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1163 menu
->addMenu(helpMenu
);
1166 void DolphinMainWindow::updateToolBar()
1168 if (!menuBar()->isVisible()) {
1169 createControlButton();
1173 void DolphinMainWindow::slotControlButtonDeleted()
1175 m_controlButton
= nullptr;
1176 m_updateToolBarTimer
->start();
1179 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1181 DolphinViewContainer
* view
= activeViewContainer();
1183 if (view
->url() == url
) {
1184 // We can end up here if the user clicked a device in the Places Panel
1185 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1192 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1194 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1197 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1199 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1200 Q_ASSERT(viewContainer
);
1202 m_activeViewContainer
= viewContainer
;
1204 if (oldViewContainer
) {
1205 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1206 toggleSearchAction
->disconnect(oldViewContainer
);
1208 // Disconnect all signals between the old view container (container,
1209 // view and url navigator) and main window.
1210 oldViewContainer
->disconnect(this);
1211 oldViewContainer
->view()->disconnect(this);
1212 oldViewContainer
->urlNavigator()->disconnect(this);
1214 // except the requestItemInfo so that on hover the information panel can still be updated
1215 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1216 this, &DolphinMainWindow::requestItemInfo
);
1219 connectViewSignals(viewContainer
);
1221 m_actionHandler
->setCurrentView(viewContainer
->view());
1224 updateFileAndEditActions();
1225 updatePasteAction();
1226 updateViewActions();
1228 updateSearchAction();
1230 const QUrl url
= viewContainer
->url();
1231 emit
urlChanged(url
);
1234 void DolphinMainWindow::tabCountChanged(int count
)
1236 const bool enableTabActions
= (count
> 1);
1237 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1238 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1240 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1241 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1242 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1245 void DolphinMainWindow::updateWindowTitle()
1247 const QString newTitle
= m_activeViewContainer
->caption();
1248 if (windowTitle() != newTitle
) {
1249 setWindowTitle(newTitle
);
1253 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1255 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1256 m_tearDownFromPlacesRequested
= true;
1257 m_terminalPanel
->goHome();
1258 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1260 m_placesPanel
->proceedWithTearDown();
1264 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1266 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1267 m_tearDownFromPlacesRequested
= false;
1268 m_terminalPanel
->goHome();
1272 void DolphinMainWindow::setupActions()
1274 // setup 'File' menu
1275 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1276 QMenu
* menu
= m_newFileMenu
->menu();
1277 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1278 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1279 m_newFileMenu
->setDelayed(false);
1280 connect(menu
, &QMenu::aboutToShow
,
1281 this, &DolphinMainWindow::updateNewMenu
);
1283 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1284 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1285 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1286 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1287 "window just like this one with the current location and view."
1288 "<nl/>You can drag and drop items between windows."));
1289 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1291 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1292 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1293 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1294 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1295 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1296 "A tab is an additional view within this window. "
1297 "You can drag and drop items between tabs."));
1298 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1299 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1301 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1302 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1303 addToPlaces
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1304 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1305 "to the Places panel."));
1306 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1308 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1309 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1310 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1311 "currently viewed tab. If no more tabs are left this window "
1312 "will close instead."));
1314 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1315 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1317 // setup 'Edit' menu
1318 KStandardAction::undo(this,
1319 &DolphinMainWindow::undo
,
1320 actionCollection());
1322 // i18n: This will be the last paragraph for the whatsthis for all three:
1323 // Cut, Copy and Paste
1324 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1325 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1326 "applications and are among the most used commands. That's why their "
1327 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1328 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1329 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1330 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1331 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1332 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1333 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1334 "the clipboard to a new location. The items will be removed from their "
1335 "initial location.") + cutCopyPastePara
);
1336 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1337 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1338 "items in your current selection to the <emphasis>clipboard</emphasis>."
1339 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1340 "from the clipboard to a new location.") + cutCopyPastePara
);
1341 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1342 // The text of the paste-action is modified dynamically by Dolphin
1343 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1344 // due to the long text, the text "Paste" is used:
1345 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1346 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1347 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1348 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1349 "action they are removed from their old location.") + cutCopyPastePara
);
1351 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1352 searchAction
->setText(i18n("Search..."));
1353 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1354 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1355 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1356 "There you can enter search terms and specify settings to find the "
1357 "objects you are looking for.</para><para>Use this help again on "
1358 "the find bar so we can have a look at it while the settings are "
1359 "explained.</para>"));
1361 // toggle_search acts as a copy of the main searchAction to be used mainly
1362 // in the toolbar, with no default shortcut attached, to avoid messing with
1363 // existing workflows (search bar always open and Ctrl-F to focus)
1364 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1365 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1366 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1367 toggleSearchAction
->setIcon(searchAction
->icon());
1368 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1369 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1370 toggleSearchAction
->setCheckable(true);
1372 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1373 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1374 "files and folders in the current location."));
1376 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1377 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1378 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1379 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1380 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1381 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1382 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1384 // setup 'View' menu
1385 // (note that most of it is set up in DolphinViewActionHandler)
1387 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1388 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1389 "the folder view below into two autonomous views.</para><para>This "
1390 "way you can see two locations at once and move items between them "
1391 "quickly.</para>Click this again afterwards to recombine the views."));
1392 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1393 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1395 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1396 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1397 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1398 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1399 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1400 stashSplit
->setCheckable(false);
1401 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1402 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1404 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1406 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1407 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1408 stop
->setToolTip(i18nc("@info", "Stop loading"));
1409 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1410 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1411 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1413 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1414 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1415 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1416 "This toggles the <emphasis>Location Bar</emphasis> to be "
1417 "editable so you can directly enter a location you want to go to.<nl/>"
1418 "You can also switch to editing by clicking to the right of the "
1419 "location and switch back by confirming the edited location."));
1420 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1421 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1423 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1424 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1425 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1426 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1427 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1428 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1429 "This switches to editing the location and selects it "
1430 "so you can quickly enter a different location."));
1431 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1432 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1436 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1437 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1438 m_backAction
->setObjectName(backAction
->objectName());
1439 m_backAction
->setShortcuts(backAction
->shortcuts());
1441 m_backAction
->setDelayed(true);
1442 m_backAction
->setStickyMenu(false);
1443 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1444 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1445 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1446 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1448 auto backShortcuts
= m_backAction
->shortcuts();
1449 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1450 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1452 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1453 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1454 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1455 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1456 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1457 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1458 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1459 this, &DolphinMainWindow::closedTabsCountChanged
);
1461 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1462 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1463 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1464 "This returns you to the previously closed tab."));
1465 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1466 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1467 undoCloseTab
->setEnabled(false);
1468 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1470 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1471 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1472 "the last change you made to files or folders.<nl/>"
1473 "Such changes include <interface>creating, renaming</interface> "
1474 "and <interface>moving</interface> them to a different location "
1475 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1476 "be undone will ask for your confirmation."));
1477 undoAction
->setEnabled(false); // undo should be disabled by default
1480 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1481 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1482 m_forwardAction
->setObjectName(forwardAction
->objectName());
1483 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1485 m_forwardAction
->setDelayed(true);
1486 m_forwardAction
->setStickyMenu(false);
1487 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1488 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1489 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1490 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1491 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1493 // enable middle-click to open in a new tab
1494 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1495 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1496 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1497 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1498 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1499 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1500 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1501 "<filename>Home</filename> folder.<nl/>Every user account "
1502 "has their own <filename>Home</filename> that contains their data "
1503 "including folders that contain personal application data."));
1505 // setup 'Tools' menu
1506 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1507 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1508 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1509 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1510 "There you can enter a text to filter the files and folders currently displayed. "
1511 "Only those that contain the text in their name will be kept in view."));
1512 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1513 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1514 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1516 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1517 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1518 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1519 compareFiles
->setEnabled(false);
1520 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1522 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1523 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1524 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1525 "<para>This opens a preferred search tool for the viewed location.</para>"
1526 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1527 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1528 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1529 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1531 #ifdef HAVE_TERMINAL
1532 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1533 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1534 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1535 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1536 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1537 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1538 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1539 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1540 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1542 QAction
* focusTerminalPanel
= actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1543 focusTerminalPanel
->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1544 focusTerminalPanel
->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1545 actionCollection()->setDefaultShortcut(focusTerminalPanel
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F4
);
1546 connect(focusTerminalPanel
, &QAction::triggered
, this, &DolphinMainWindow::focusTerminalPanel
);
1550 // setup 'Bookmarks' menu
1551 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1552 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1553 // Make the toolbar button version work properly on click
1554 bookmarkMenu
->setDelayed(false);
1555 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1556 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1558 // setup 'Settings' menu
1559 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1560 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1561 "This switches between having a <emphasis>Menubar</emphasis> "
1562 "and having a <interface>Control</interface> button. Both "
1563 "contain mostly the same commands and configuration options."));
1564 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1565 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1566 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1568 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1569 m_helpMenu
= new KHelpMenu(nullptr);
1570 m_helpMenu
->menu()->installEventFilter(this);
1571 // remove duplicate shortcuts
1572 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1573 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1575 // not in menu actions
1576 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1577 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1579 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1580 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1582 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1583 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1584 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1585 activateTab
->setEnabled(false);
1586 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1588 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1590 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1594 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1595 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1596 activateLastTab
->setEnabled(false);
1597 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1598 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1600 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1601 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1602 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1603 activateNextTab
->setEnabled(false);
1604 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1605 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1607 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1608 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1609 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1610 activatePrevTab
->setEnabled(false);
1611 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1612 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1615 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1616 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1617 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1618 showTarget
->setEnabled(false);
1619 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1621 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1622 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1623 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1624 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1626 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1627 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1628 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1629 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1631 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1632 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1633 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1634 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1637 void DolphinMainWindow::setupDockWidgets()
1639 const bool lock
= GeneralSettings::lockPanels();
1641 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1642 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1643 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1644 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1645 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1646 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1647 "switches between having panels <emphasis>locked</emphasis> or "
1648 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1649 "dragged to the other side of the window and have a close "
1650 "button.<nl/>Locked panels are embedded more cleanly."));
1651 lockLayoutAction
->setActive(lock
);
1652 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1654 // Setup "Information"
1655 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1656 infoDock
->setLocked(lock
);
1657 infoDock
->setObjectName(QStringLiteral("infoDock"));
1658 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1661 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1662 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1663 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1664 infoDock
->setWidget(infoPanel
);
1666 QAction
* infoAction
= infoDock
->toggleViewAction();
1667 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1669 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1670 connect(this, &DolphinMainWindow::urlChanged
,
1671 infoPanel
, &InformationPanel::setUrl
);
1672 connect(this, &DolphinMainWindow::selectionChanged
,
1673 infoPanel
, &InformationPanel::setSelection
);
1674 connect(this, &DolphinMainWindow::requestItemInfo
,
1675 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1678 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1679 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1680 "hide panels like this go to <interface>Control|Panels</interface> "
1681 "or <interface>View|Panels</interface>.</para>");
1683 actionCollection()->action(QStringLiteral("show_information_panel"))
1684 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1685 "<emphasis>information</emphasis> panel at the right side of the "
1686 "window.</para><para>The panel provides in-depth information "
1687 "about the items your mouse is hovering over or about the selected "
1688 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1689 "For single items a preview of their contents is provided.</para>"));
1691 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1692 "provides in-depth information about the items your mouse is "
1693 "hovering over or about the selected items. Otherwise it informs "
1694 "you about the currently viewed folder.<nl/>For single items a "
1695 "preview of their contents is provided.</para><para>You can configure "
1696 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1699 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1700 foldersDock
->setLocked(lock
);
1701 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1702 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1703 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1704 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1705 foldersDock
->setWidget(foldersPanel
);
1707 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1708 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1710 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1711 connect(this, &DolphinMainWindow::urlChanged
,
1712 foldersPanel
, &FoldersPanel::setUrl
);
1713 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1714 this, &DolphinMainWindow::changeUrl
);
1715 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1716 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1717 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1718 this, &DolphinMainWindow::showErrorMessage
);
1720 actionCollection()->action(QStringLiteral("show_folders_panel"))
1721 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1722 "<emphasis>folders</emphasis> panel at the left side of the window."
1723 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1724 "</emphasis> in a <emphasis>tree view</emphasis>."));
1725 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1726 "shows the folders of the <emphasis>file system</emphasis> in a "
1727 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1728 "there. Click the arrow to the left of a folder to see its subfolders. "
1729 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1732 #ifdef HAVE_TERMINAL
1733 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1734 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1735 terminalDock
->setLocked(lock
);
1736 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1737 m_terminalPanel
= new TerminalPanel(terminalDock
);
1738 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1739 terminalDock
->setWidget(m_terminalPanel
);
1741 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1742 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1743 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1744 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1745 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1746 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1748 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1749 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1751 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1752 connect(this, &DolphinMainWindow::urlChanged
,
1753 m_terminalPanel
, &TerminalPanel::setUrl
);
1755 if (GeneralSettings::version() < 200) {
1756 terminalDock
->hide();
1759 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1760 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1761 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1762 "<nl/>The location in the terminal will always match the folder "
1763 "view so you can navigate using either.</para><para>The terminal "
1764 "panel is not needed for basic computer usage but can be useful "
1765 "for advanced tasks. To learn more about terminals use the help "
1766 "in a standalone terminal application like Konsole.</para>"));
1767 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1768 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1769 "normal terminal but will match the location of the folder view "
1770 "so you can navigate using either.</para><para>The terminal panel "
1771 "is not needed for basic computer usage but can be useful for "
1772 "advanced tasks. To learn more about terminals use the help in a "
1773 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1777 if (GeneralSettings::version() < 200) {
1779 foldersDock
->hide();
1783 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1784 placesDock
->setLocked(lock
);
1785 placesDock
->setObjectName(QStringLiteral("placesDock"));
1786 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1788 m_placesPanel
= new PlacesPanel(placesDock
);
1789 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1790 placesDock
->setWidget(m_placesPanel
);
1792 QAction
*placesAction
= placesDock
->toggleViewAction();
1793 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1795 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1796 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1797 this, &DolphinMainWindow::slotPlaceActivated
);
1798 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1799 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1800 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1801 this, &DolphinMainWindow::showErrorMessage
);
1802 connect(this, &DolphinMainWindow::urlChanged
,
1803 m_placesPanel
, &PlacesPanel::setUrl
);
1804 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1805 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1806 connect(this, &DolphinMainWindow::settingsChanged
,
1807 m_placesPanel
, &PlacesPanel::readSettings
);
1808 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1809 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1810 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1811 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1812 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1814 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1815 actionShowAllPlaces
->setCheckable(true);
1816 actionShowAllPlaces
->setDisabled(true);
1817 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1818 "all places in the places panel that have been hidden. They will "
1819 "appear semi-transparent unless you uncheck their hide property."));
1821 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1822 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1823 m_placesPanel
->showHiddenEntries(checked
);
1826 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1827 actionShowAllPlaces
->setChecked(checked
);
1828 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1831 actionCollection()->action(QStringLiteral("show_places_panel"))
1832 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1833 "<emphasis>places</emphasis> panel at the left side of the window."
1834 "</para><para>It allows you to go to locations you have "
1835 "bookmarked and to access disk or media attached to the computer "
1836 "or to the network. It also contains sections to find recently "
1837 "saved files or files of a certain type.</para>"));
1838 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1839 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1840 "you have bookmarked and to access disk or media attached to the "
1841 "computer or to the network. It also contains sections to find "
1842 "recently saved files or files of a certain type.</para><para>"
1843 "Click on an entry to go there. Click with the right mouse button "
1844 "instead to open any entry in a new tab or new window.</para>"
1845 "<para>New entries can be added by dragging folders onto this panel. "
1846 "Right-click any section or entry to hide it. Right-click an empty "
1847 "space on this panel and select <interface>Show Hidden Places"
1848 "</interface> to display it again.</para>") + panelWhatsThis
);
1850 // Add actions into the "Panels" menu
1851 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1852 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1853 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1854 panelsMenu
->setDelayed(false);
1855 const KActionCollection
* ac
= actionCollection();
1856 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1858 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1860 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1861 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1862 panelsMenu
->addSeparator();
1863 panelsMenu
->addAction(actionShowAllPlaces
);
1864 panelsMenu
->addAction(lockLayoutAction
);
1866 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1867 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1872 void DolphinMainWindow::updateFileAndEditActions()
1874 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1875 const KActionCollection
* col
= actionCollection();
1876 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1878 if (list
.isEmpty()) {
1879 stateChanged(QStringLiteral("has_no_selection"));
1881 addToPlacesAction
->setEnabled(true);
1883 stateChanged(QStringLiteral("has_selection"));
1885 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1886 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1887 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1888 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1889 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1890 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1891 QAction
* duplicateAction
= col
->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1893 if (list
.length() == 1 && list
.first().isDir()) {
1894 addToPlacesAction
->setEnabled(true);
1896 addToPlacesAction
->setEnabled(false);
1899 KFileItemListProperties
capabilities(list
);
1900 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1902 renameAction
->setEnabled(capabilities
.supportsMoving());
1903 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1904 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1905 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1906 cutAction
->setEnabled(capabilities
.supportsMoving());
1907 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
1908 duplicateAction
->setEnabled(capabilities
.supportsWriting());
1912 void DolphinMainWindow::updateViewActions()
1914 m_actionHandler
->updateViewActions();
1916 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
1917 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1919 updateSplitAction();
1921 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
1922 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1923 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1926 void DolphinMainWindow::updateGoActions()
1928 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1929 const QUrl currentUrl
= m_activeViewContainer
->url();
1930 // I think this is one of the best places to firstly be confronted
1931 // with a file system and its hierarchy. Talking about the root
1932 // directory might seem too much here but it is the question that
1933 // naturally arises in this context.
1934 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
1935 "the folder that contains the currently viewed one.</para>"
1936 "<para>All files and folders are organized in a hierarchical "
1937 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
1938 "a directory that contains all data connected to this computer"
1939 "—the <emphasis>root directory</emphasis>.</para>"));
1940 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
1943 void DolphinMainWindow::createControlButton()
1945 if (m_controlButton
) {
1948 Q_ASSERT(!m_controlButton
);
1950 m_controlButton
= new QToolButton(this);
1951 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
1952 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
1953 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
1954 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
1955 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1957 QMenu
* controlMenu
= new QMenu(m_controlButton
);
1958 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
1959 controlMenu
->installEventFilter(this);
1961 m_controlButton
->setMenu(controlMenu
);
1963 toolBar()->addWidget(m_controlButton
);
1964 connect(toolBar(), &KToolBar::iconSizeChanged
,
1965 m_controlButton
, &QToolButton::setIconSize
);
1967 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1968 // gets edited. In this case we must add them again. The adding is done asynchronously by
1969 // m_updateToolBarTimer.
1970 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
1971 m_updateToolBarTimer
= new QTimer(this);
1972 m_updateToolBarTimer
->setInterval(500);
1973 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
1976 void DolphinMainWindow::deleteControlButton()
1978 delete m_controlButton
;
1979 m_controlButton
= nullptr;
1981 delete m_updateToolBarTimer
;
1982 m_updateToolBarTimer
= nullptr;
1985 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
1990 const KToolBar
* toolBarWidget
= toolBar();
1991 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
1992 if (widget
== toolBarWidget
) {
1997 menu
->addAction(action
);
2001 void DolphinMainWindow::refreshViews()
2003 m_tabWidget
->refreshViews();
2005 if (GeneralSettings::modifiedStartupSettings()) {
2006 // The startup settings have been changed by the user (see bug #254947).
2007 // Synchronize the split-view setting with the active view:
2008 const bool splitView
= GeneralSettings::splitView();
2009 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2010 updateSplitAction();
2011 updateWindowTitle();
2014 emit
settingsChanged();
2017 void DolphinMainWindow::clearStatusBar()
2019 m_activeViewContainer
->statusBar()->resetToDefaultText();
2022 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2024 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2025 this, &DolphinMainWindow::updateFilterBarAction
);
2026 connect(container
, &DolphinViewContainer::writeStateChanged
,
2027 this, &DolphinMainWindow::slotWriteStateChanged
);
2028 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2029 this, &DolphinMainWindow::updateSearchAction
);
2031 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2032 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2034 const DolphinView
* view
= container
->view();
2035 connect(view
, &DolphinView::selectionChanged
,
2036 this, &DolphinMainWindow::slotSelectionChanged
);
2037 connect(view
, &DolphinView::requestItemInfo
,
2038 this, &DolphinMainWindow::requestItemInfo
);
2039 connect(view
, &DolphinView::tabRequested
,
2040 this, &DolphinMainWindow::openNewTab
);
2041 connect(view
, &DolphinView::requestContextMenu
,
2042 this, &DolphinMainWindow::openContextMenu
);
2043 connect(view
, &DolphinView::directoryLoadingStarted
,
2044 this, &DolphinMainWindow::enableStopAction
);
2045 connect(view
, &DolphinView::directoryLoadingCompleted
,
2046 this, &DolphinMainWindow::disableStopAction
);
2047 connect(view
, &DolphinView::directoryLoadingCompleted
,
2048 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2049 connect(view
, &DolphinView::goBackRequested
,
2050 this, &DolphinMainWindow::goBack
);
2051 connect(view
, &DolphinView::goForwardRequested
,
2052 this, &DolphinMainWindow::goForward
);
2053 connect(view
, &DolphinView::urlActivated
,
2054 this, &DolphinMainWindow::handleUrl
);
2056 const KUrlNavigator
* navigator
= container
->urlNavigator();
2057 connect(navigator
, &KUrlNavigator::urlChanged
,
2058 this, &DolphinMainWindow::changeUrl
);
2059 connect(navigator
, &KUrlNavigator::historyChanged
,
2060 this, &DolphinMainWindow::updateHistory
);
2061 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2062 this, &DolphinMainWindow::slotEditableStateChanged
);
2063 connect(navigator
, &KUrlNavigator::tabRequested
,
2064 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2067 void DolphinMainWindow::updateSplitAction()
2069 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2070 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2071 if (tabPage
->splitViewEnabled()) {
2072 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2073 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2074 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2075 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2077 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2078 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2079 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2082 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2083 splitAction
->setToolTip(i18nc("@info", "Split view"));
2084 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2088 bool DolphinMainWindow::isKompareInstalled() const
2090 static bool initialized
= false;
2091 static bool installed
= false;
2093 // TODO: maybe replace this approach later by using a menu
2094 // plugin like kdiff3plugin.cpp
2095 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2101 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2102 const QKeySequence
& shortcut
,
2103 QAction
* dockAction
,
2104 const QString
& actionName
)
2106 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2107 panelAction
->setCheckable(true);
2108 panelAction
->setChecked(dockAction
->isChecked());
2109 panelAction
->setText(dockAction
->text());
2110 panelAction
->setIcon(icon
);
2111 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2113 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2114 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2117 void DolphinMainWindow::setupWhatsThis()
2120 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2121 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2122 "configuration options. Left-click on any of the menus on this "
2123 "bar to see its contents.</para><para>The Menubar can be hidden "
2124 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2125 "most of its contents become available through a <interface>Control"
2126 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2127 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2128 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2129 "frequently used actions.</para><para>It is highly customizable. "
2130 "All items you see in the <interface>Control</interface> menu or "
2131 "in the <interface>Menubar</interface> can be placed on the "
2132 "Toolbar. Just right-click on it and select <interface>Configure "
2133 "Toolbars…</interface> or find this action in the <interface>"
2134 "Control</interface> or <interface>Settings</interface> menu."
2135 "</para><para>The location of the bar and the style of its "
2136 "buttons can also be changed in the right-click menu. Right-click "
2137 "a button if you want to show or hide its text.</para>"));
2138 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2139 "<para>Here you can see the <emphasis>folders</emphasis> and "
2140 "<emphasis>files</emphasis> that are at the location described in "
2141 "the <interface>Location Bar</interface> above. This area is the "
2142 "central part of this application where you navigate to the files "
2143 "you want to use.</para><para>For an elaborate and general "
2144 "introduction to this application <link "
2145 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2146 "click here</link>. This will open an introductory article from "
2147 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2148 "explanations of all the features of this <emphasis>view</emphasis> "
2149 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2150 "instead. This will open a page from the <emphasis>Handbook"
2151 "</emphasis> that covers the basics.</para>"));
2154 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2155 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2156 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2157 "There you can set up key combinations to trigger an action when "
2158 "they are pressed simultaneously. All commands in this application can "
2159 "be triggered this way.</para>"));
2160 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2161 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2162 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2163 "<para>All items you see in the <interface>Control</interface> menu "
2164 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2165 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2166 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2167 "change a multitude of settings for this application. For an explanation "
2168 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2169 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2172 // The whatsthis has to be set for the m_helpMenu and for the
2173 // StandardAction separately because both are used in different locations.
2174 // m_helpMenu is only used for createControlButton() button.
2176 // Links do not work within the Menubar so texts without links are provided there.
2178 // i18n: If the external link isn't available in your language you should
2179 // probably state the external link language at least in brackets to not
2180 // frustrate the user. If there are multiple languages that the user might
2181 // know with a reasonable chance you might want to have 2 external links.
2182 // The same is in my opinion true for every external link you translate.
2183 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2184 "<para>This opens the Handbook for this application. It provides "
2185 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2186 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2187 ->setWhatsThis(whatsThisHelpContents
2188 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2189 "<para>If you want more elaborate introductions to the "
2190 "different features of <emphasis>Dolphin</emphasis> "
2191 "go to the KDE UserBase Wiki.</para>"));
2192 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2193 + xi18nc("@info:whatsthis second half of handbook text with link",
2194 "<para>If you want more elaborate introductions to the "
2195 "different features of <emphasis>Dolphin</emphasis> "
2196 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2197 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2199 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2200 "<para>This is the button that invokes the help feature you are "
2201 "using right now! Click it, then click any component of this "
2202 "application to ask \"What's this?\" about it. The mouse cursor "
2203 "will change appearance if no help is available for a spot.</para>");
2204 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2205 ->setWhatsThis(whatsThisWhatsThis
2206 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2207 "<para>There are two other ways to get help for this application: The "
2208 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2209 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2210 "article about <emphasis>File Management</emphasis> online."
2211 "</para><para>The \"What's this?\" help is "
2212 "missing in most other windows so don't get too used to this.</para>"));
2213 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2214 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2215 "<para>There are two other ways to get help: "
2216 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2217 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2218 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2219 "missing in most other windows so don't get too used to this.</para>"));
2221 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2222 "window that will guide you through reporting errors or flaws "
2223 "in this application or in other KDE software.</para>");
2224 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2225 ->setWhatsThis(whatsThisReportBug
);
2226 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2227 + xi18nc("@info:whatsthis second half of reportbug text with link",
2228 "<para>High-quality bug reports are much appreciated. To learn "
2229 "how to make your bug report as effective as possible "
2230 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2231 "click here</link>.</para>"));
2233 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2234 "<emphasis>web page</emphasis> where you can donate to "
2235 "support the continued work on this application and many "
2236 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2237 "<para>Donating is the easiest and fastest way to efficiently "
2238 "support KDE and its projects. KDE projects are available for "
2239 "free therefore your donation is needed to cover things that "
2240 "require money like servers, contributor meetings, etc.</para>"
2241 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2242 "organization behind the KDE community.</para>");
2243 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2244 ->setWhatsThis(whatsThisDonate
);
2245 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2247 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2248 "With this you can change the language this application uses."
2249 "<nl/>You can even set secondary languages which will be used "
2250 "if texts are not available in your preferred language.");
2251 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2252 ->setWhatsThis(whatsThisSwitchLanguage
);
2253 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2255 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2256 "window that informs you about the version, license, "
2257 "used libraries and maintainers of this application.");
2258 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2259 ->setWhatsThis(whatsThisAboutApp
);
2260 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2262 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2263 "window with information about <emphasis>KDE</emphasis>. "
2264 "The KDE community are the people behind this free software."
2265 "<nl/>If you like using this application but don't know "
2266 "about KDE or want to see a cute dragon have a look!");
2267 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2268 ->setWhatsThis(whatsThisAboutKDE
);
2269 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2272 bool DolphinMainWindow::event(QEvent
*event
)
2274 if (event
->type() == QEvent::WhatsThisClicked
) {
2276 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2277 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2280 return KXmlGuiWindow::event(event
);
2283 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2286 if (event
->type() == QEvent::WhatsThisClicked
) {
2288 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2289 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2295 void DolphinMainWindow::focusTerminalPanel()
2297 if (m_terminalPanel
->isVisible()) {
2298 if (m_terminalPanel
->terminalHasFocus()) {
2299 m_activeViewContainer
->view()->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2300 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2302 m_terminalPanel
->setFocus(Qt::FocusReason::ShortcutFocusReason
);
2303 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2306 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2307 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2311 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2312 KIO::FileUndoManager::UiInterface()
2316 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2320 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2322 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2324 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2325 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2327 KIO::FileUndoManager::UiInterface::jobError(job
);
2331 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2333 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));