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 "config-terminal.h"
26 #include "dolphinbookmarkhandler.h"
27 #include "dolphindockwidget.h"
28 #include "dolphincontextmenu.h"
29 #include "dolphinnewfilemenu.h"
30 #include "dolphinrecenttabsmenu.h"
31 #include "dolphinviewcontainer.h"
32 #include "dolphintabpage.h"
33 #include "middleclickactioneventfilter.h"
34 #include "panels/folders/folderspanel.h"
35 #include "panels/places/placesitemmodel.h"
36 #include "panels/places/placespanel.h"
37 #include "panels/information/informationpanel.h"
38 #include "panels/terminal/terminalpanel.h"
39 #include "settings/dolphinsettingsdialog.h"
40 #include "statusbar/dolphinstatusbar.h"
41 #include "views/dolphinviewactionhandler.h"
42 #include "views/dolphinremoteencoding.h"
43 #include "views/draganddrophelper.h"
44 #include "views/viewproperties.h"
45 #include "views/dolphinnewfilemenuobserver.h"
46 #include "dolphin_generalsettings.h"
48 #include <KActionCollection>
49 #include <KActionMenu>
50 #include <KAuthorized>
52 #include <KDualAction>
53 #include <KFileItemListProperties>
55 #include <KIO/JobUiDelegate>
56 #include <KIO/OpenFileManagerWindowJob>
57 #include <KJobWidgets>
58 #include <KLocalizedString>
59 #include <KMessageBox>
60 #include <KNS3/KMoreToolsMenuFactory>
61 #include <KProtocolInfo>
62 #include <KProtocolManager>
65 #include <KStandardAction>
66 #include <KStartupInfo>
67 #include <KToggleAction>
69 #include <KToolBarPopupAction>
70 #include <KToolInvocation>
71 #include <KUrlComboBox>
72 #include <KUrlNavigator>
73 #include <KWindowSystem>
75 #include <QApplication>
77 #include <QCloseEvent>
78 #include <QDesktopServices>
84 #include <QPushButton>
86 #include <QStandardPaths>
88 #include <QToolButton>
89 #include <QWhatsThisClickedEvent>
92 // Used for GeneralSettings::version() to determine whether
93 // an updated version of Dolphin is running.
94 const int CurrentDolphinVersion
= 200;
95 // The maximum number of entries in the back/forward popup menu
96 const int MaxNumberOfNavigationentries
= 12;
97 // The maximum number of "Activate Tab" shortcuts
98 const int MaxActivateTabShortcuts
= 9;
101 DolphinMainWindow::DolphinMainWindow() :
102 KXmlGuiWindow(nullptr),
103 m_newFileMenu(nullptr),
105 m_tabWidget(nullptr),
106 m_activeViewContainer(nullptr),
107 m_actionHandler(nullptr),
108 m_remoteEncoding(nullptr),
110 m_bookmarkHandler(nullptr),
111 m_controlButton(nullptr),
112 m_updateToolBarTimer(nullptr),
113 m_lastHandleUrlStatJob(nullptr),
114 m_terminalPanel(nullptr),
115 m_placesPanel(nullptr),
116 m_tearDownFromPlacesRequested(false),
117 m_backAction(nullptr),
118 m_forwardAction(nullptr)
120 Q_INIT_RESOURCE(dolphin
);
122 setWindowFlags(Qt::WindowContextHelpButtonHint
);
124 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
125 setObjectName(QStringLiteral("Dolphin#"));
127 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage
,
128 this, &DolphinMainWindow::showErrorMessage
);
130 KIO::FileUndoManager
* undoManager
= KIO::FileUndoManager::self();
131 undoManager
->setUiInterface(new UndoUiInterface());
133 connect(undoManager
, QOverload
<bool>::of(&KIO::FileUndoManager::undoAvailable
),
134 this, &DolphinMainWindow::slotUndoAvailable
);
135 connect(undoManager
, &KIO::FileUndoManager::undoTextChanged
,
136 this, &DolphinMainWindow::slotUndoTextChanged
);
137 connect(undoManager
, &KIO::FileUndoManager::jobRecordingStarted
,
138 this, &DolphinMainWindow::clearStatusBar
);
139 connect(undoManager
, &KIO::FileUndoManager::jobRecordingFinished
,
140 this, &DolphinMainWindow::showCommand
);
142 GeneralSettings
* generalSettings
= GeneralSettings::self();
143 const bool firstRun
= (generalSettings
->version() < 200);
145 generalSettings
->setViewPropsTimestamp(QDateTime::currentDateTime());
148 setAcceptDrops(true);
150 m_tabWidget
= new DolphinTabWidget(this);
151 m_tabWidget
->setObjectName("tabWidget");
152 connect(m_tabWidget
, &DolphinTabWidget::activeViewChanged
,
153 this, &DolphinMainWindow::activeViewChanged
);
154 connect(m_tabWidget
, &DolphinTabWidget::tabCountChanged
,
155 this, &DolphinMainWindow::tabCountChanged
);
156 connect(m_tabWidget
, &DolphinTabWidget::currentUrlChanged
,
157 this, &DolphinMainWindow::updateWindowTitle
);
158 setCentralWidget(m_tabWidget
);
162 m_actionHandler
= new DolphinViewActionHandler(actionCollection(), this);
163 connect(m_actionHandler
, &DolphinViewActionHandler::actionBeingHandled
, this, &DolphinMainWindow::clearStatusBar
);
164 connect(m_actionHandler
, &DolphinViewActionHandler::createDirectoryTriggered
, this, &DolphinMainWindow::createDirectory
);
166 m_remoteEncoding
= new DolphinRemoteEncoding(this, m_actionHandler
);
167 connect(this, &DolphinMainWindow::urlChanged
,
168 m_remoteEncoding
, &DolphinRemoteEncoding::slotAboutToOpenUrl
);
172 setupGUI(Keys
| Save
| Create
| ToolBar
);
173 stateChanged(QStringLiteral("new_file"));
175 QClipboard
* clipboard
= QApplication::clipboard();
176 connect(clipboard
, &QClipboard::dataChanged
,
177 this, &DolphinMainWindow::updatePasteAction
);
179 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
180 showFilterBarAction
->setChecked(generalSettings
->filterBar());
183 menuBar()->setVisible(false);
184 // Assure a proper default size if Dolphin runs the first time
188 const bool showMenu
= !menuBar()->isHidden();
189 QAction
* showMenuBarAction
= actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar
));
190 showMenuBarAction
->setChecked(showMenu
); // workaround for bug #171080
192 createControlButton();
195 // enable middle-click on back/forward/up to open in a new tab
196 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
197 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotToolBarActionMiddleClicked
);
198 toolBar()->installEventFilter(middleClickEventFilter
);
202 QTimer::singleShot(0, this, &DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction
);
205 DolphinMainWindow::~DolphinMainWindow()
209 QVector
<DolphinViewContainer
*> DolphinMainWindow::viewContainers() const
211 QVector
<DolphinViewContainer
*> viewContainers
;
212 viewContainers
.reserve(m_tabWidget
->count());
213 for (int i
= 0; i
< m_tabWidget
->count(); ++i
) {
214 viewContainers
<< m_tabWidget
->tabPageAt(i
)->activeViewContainer();
216 return viewContainers
;
219 void DolphinMainWindow::openDirectories(const QList
<QUrl
>& dirs
, bool splitView
)
221 m_tabWidget
->openDirectories(dirs
, splitView
);
224 void DolphinMainWindow::openDirectories(const QStringList
& dirs
, bool splitView
)
226 openDirectories(QUrl::fromStringList(dirs
), splitView
);
229 void DolphinMainWindow::openFiles(const QList
<QUrl
>& files
, bool splitView
)
231 m_tabWidget
->openFiles(files
, splitView
);
234 void DolphinMainWindow::openFiles(const QStringList
& files
, bool splitView
)
236 openFiles(QUrl::fromStringList(files
), splitView
);
239 void DolphinMainWindow::activateWindow()
241 window()->setAttribute(Qt::WA_NativeWindow
, true);
242 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
243 KWindowSystem::activateWindow(window()->effectiveWinId());
246 void DolphinMainWindow::showCommand(CommandType command
)
248 DolphinStatusBar
* statusBar
= m_activeViewContainer
->statusBar();
250 case KIO::FileUndoManager::Copy
:
251 statusBar
->setText(i18nc("@info:status", "Successfully copied."));
253 case KIO::FileUndoManager::Move
:
254 statusBar
->setText(i18nc("@info:status", "Successfully moved."));
256 case KIO::FileUndoManager::Link
:
257 statusBar
->setText(i18nc("@info:status", "Successfully linked."));
259 case KIO::FileUndoManager::Trash
:
260 statusBar
->setText(i18nc("@info:status", "Successfully moved to trash."));
262 case KIO::FileUndoManager::Rename
:
263 statusBar
->setText(i18nc("@info:status", "Successfully renamed."));
266 case KIO::FileUndoManager::Mkdir
:
267 statusBar
->setText(i18nc("@info:status", "Created folder."));
275 void DolphinMainWindow::pasteIntoFolder()
277 m_activeViewContainer
->view()->pasteIntoFolder();
280 void DolphinMainWindow::changeUrl(const QUrl
&url
)
282 if (!KProtocolManager::supportsListing(url
)) {
283 // The URL navigator only checks for validity, not
284 // if the URL can be listed. An error message is
285 // shown due to DolphinViewContainer::restoreView().
289 m_activeViewContainer
->setUrl(url
);
290 updateFileAndEditActions();
295 emit
urlChanged(url
);
298 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl
& url
)
300 if (m_tearDownFromPlacesRequested
&& url
== QUrl::fromLocalFile(QDir::homePath())) {
301 m_placesPanel
->proceedWithTearDown();
302 m_tearDownFromPlacesRequested
= false;
305 m_activeViewContainer
->setAutoGrabFocus(false);
307 m_activeViewContainer
->setAutoGrabFocus(true);
310 void DolphinMainWindow::slotEditableStateChanged(bool editable
)
312 KToggleAction
* editableLocationAction
=
313 static_cast<KToggleAction
*>(actionCollection()->action(QStringLiteral("editable_location")));
314 editableLocationAction
->setChecked(editable
);
317 void DolphinMainWindow::slotSelectionChanged(const KFileItemList
& selection
)
319 updateFileAndEditActions();
321 const int selectedUrlsCount
= m_tabWidget
->currentTabPage()->selectedItemsCount();
323 QAction
* compareFilesAction
= actionCollection()->action(QStringLiteral("compare_files"));
324 if (selectedUrlsCount
== 2) {
325 compareFilesAction
->setEnabled(isKompareInstalled());
327 compareFilesAction
->setEnabled(false);
330 emit
selectionChanged(selection
);
333 void DolphinMainWindow::updateHistory()
335 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
336 const int index
= urlNavigator
->historyIndex();
338 QAction
* backAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Back
));
340 backAction
->setToolTip(i18nc("@info", "Go back"));
341 backAction
->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
342 backAction
->setEnabled(index
< urlNavigator
->historySize() - 1);
345 QAction
* forwardAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Forward
));
347 forwardAction
->setToolTip(i18nc("@info", "Go forward"));
348 forwardAction
->setWhatsThis(xi18nc("@info:whatsthis go forward",
349 "This undoes a <interface>Go|Back</interface> action."));
350 forwardAction
->setEnabled(index
> 0);
354 void DolphinMainWindow::updateFilterBarAction(bool show
)
356 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
357 showFilterBarAction
->setChecked(show
);
360 void DolphinMainWindow::openNewMainWindow()
362 Dolphin::openNewWindow({m_activeViewContainer
->url()}, this);
365 void DolphinMainWindow::openNewActivatedTab()
367 m_tabWidget
->openNewActivatedTab();
370 void DolphinMainWindow::addToPlaces()
375 // If nothing is selected, act on the current dir
376 if (m_activeViewContainer
->view()->selectedItems().isEmpty()) {
377 url
= m_activeViewContainer
->url();
378 name
= m_activeViewContainer
->placesText();
380 const auto dirToAdd
= m_activeViewContainer
->view()->selectedItems().first();
381 url
= dirToAdd
.url();
382 name
= dirToAdd
.name();
385 PlacesItemModel model
;
387 if (m_activeViewContainer
->isSearchModeEnabled()) {
388 icon
= QStringLiteral("folder-saved-search-symbolic");
390 icon
= KIO::iconNameForUrl(url
);
392 model
.createPlacesItem(name
, url
, icon
);
396 void DolphinMainWindow::openNewTab(const QUrl
& url
, DolphinTabWidget::TabPlacement tabPlacement
)
398 m_tabWidget
->openNewTab(url
, QUrl(), tabPlacement
);
401 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl
& url
)
403 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterCurrentTab
);
406 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl
& url
)
408 m_tabWidget
->openNewTab(url
, QUrl(), DolphinTabWidget::AfterLastTab
);
411 void DolphinMainWindow::openInNewTab()
413 const KFileItemList
& list
= m_activeViewContainer
->view()->selectedItems();
414 bool tabCreated
= false;
416 foreach (const KFileItem
& item
, list
) {
417 const QUrl
& url
= DolphinView::openItemAsFolderUrl(item
);
418 if (!url
.isEmpty()) {
419 openNewTabAfterCurrentTab(url
);
424 // if no new tab has been created from the selection
425 // open the current directory in a new tab
427 openNewTabAfterCurrentTab(m_activeViewContainer
->url());
431 void DolphinMainWindow::openInNewWindow()
435 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
436 if (list
.isEmpty()) {
437 newWindowUrl
= m_activeViewContainer
->url();
438 } else if (list
.count() == 1) {
439 const KFileItem
& item
= list
.first();
440 newWindowUrl
= DolphinView::openItemAsFolderUrl(item
);
443 if (!newWindowUrl
.isEmpty()) {
444 Dolphin::openNewWindow({newWindowUrl
}, this);
448 void DolphinMainWindow::showTarget()
450 const auto link
= m_activeViewContainer
->view()->selectedItems().at(0);
451 const auto linkLocationDir
= QFileInfo(link
.localPath()).absoluteDir();
452 auto linkDestination
= link
.linkDest();
453 if (QFileInfo(linkDestination
).isRelative()) {
454 linkDestination
= linkLocationDir
.filePath(linkDestination
);
456 if (QFileInfo::exists(linkDestination
)) {
457 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination
).adjusted(QUrl::StripTrailingSlash
)});
459 m_activeViewContainer
->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination
),
460 DolphinViewContainer::Warning
);
464 void DolphinMainWindow::showEvent(QShowEvent
* event
)
466 KXmlGuiWindow::showEvent(event
);
468 if (!event
->spontaneous()) {
469 m_activeViewContainer
->view()->setFocus();
473 void DolphinMainWindow::closeEvent(QCloseEvent
* event
)
475 // Find out if Dolphin is closed directly by the user or
476 // by the session manager because the session is closed
477 bool closedByUser
= true;
478 if (qApp
->isSavingSession()) {
479 closedByUser
= false;
482 if (m_tabWidget
->count() > 1 && GeneralSettings::confirmClosingMultipleTabs() && closedByUser
) {
483 // Ask the user if he really wants to quit and close all tabs.
484 // Open a confirmation dialog with 3 buttons:
485 // QDialogButtonBox::Yes -> Quit
486 // QDialogButtonBox::No -> Close only the current tab
487 // QDialogButtonBox::Cancel -> do nothing
488 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
489 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
490 dialog
->setModal(true);
491 QDialogButtonBox
* buttons
= new QDialogButtonBox(QDialogButtonBox::Yes
| QDialogButtonBox::No
| QDialogButtonBox::Cancel
);
492 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
493 KGuiItem::assign(buttons
->button(QDialogButtonBox::No
), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
494 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
495 buttons
->button(QDialogButtonBox::Yes
)->setDefault(true);
497 bool doNotAskAgainCheckboxResult
= false;
499 const auto result
= KMessageBox::createKMessageBox(dialog
,
501 QMessageBox::Warning
,
502 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
504 i18n("Do not ask again"),
505 &doNotAskAgainCheckboxResult
,
506 KMessageBox::Notify
);
508 if (doNotAskAgainCheckboxResult
) {
509 GeneralSettings::setConfirmClosingMultipleTabs(false);
513 case QDialogButtonBox::Yes
:
516 case QDialogButtonBox::No
:
517 // Close only the current tab
518 m_tabWidget
->closeTab();
526 if (m_terminalPanel
&& m_terminalPanel
->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser
) {
527 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
528 // Open a confirmation dialog with 3 buttons:
529 // QDialogButtonBox::Yes -> Quit
530 // QDialogButtonBox::No -> Show Terminal Panel
531 // QDialogButtonBox::Cancel -> do nothing
532 QDialog
*dialog
= new QDialog(this, Qt::Dialog
);
533 dialog
->setWindowTitle(i18nc("@title:window", "Confirmation"));
534 dialog
->setModal(true);
535 auto standardButtons
= QDialogButtonBox::Yes
| QDialogButtonBox::Cancel
;
536 if (!m_terminalPanel
->isVisible()) {
537 standardButtons
|= QDialogButtonBox::No
;
539 QDialogButtonBox
*buttons
= new QDialogButtonBox(standardButtons
);
540 KGuiItem::assign(buttons
->button(QDialogButtonBox::Yes
), KStandardGuiItem::quit());
541 if (!m_terminalPanel
->isVisible()) {
543 buttons
->button(QDialogButtonBox::No
),
544 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
546 KGuiItem::assign(buttons
->button(QDialogButtonBox::Cancel
), KStandardGuiItem::cancel());
548 bool doNotAskAgainCheckboxResult
= false;
550 const auto result
= KMessageBox::createKMessageBox(
553 QMessageBox::Warning
,
554 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel
->runningProgramName()),
556 i18n("Do not ask again"),
557 &doNotAskAgainCheckboxResult
,
558 KMessageBox::Dangerous
);
560 if (doNotAskAgainCheckboxResult
) {
561 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
565 case QDialogButtonBox::Yes
:
568 case QDialogButtonBox::No
:
569 actionCollection()->action("show_terminal_panel")->trigger();
570 // Do not quit, ignore quit event
578 GeneralSettings::setVersion(CurrentDolphinVersion
);
579 GeneralSettings::self()->save();
581 KXmlGuiWindow::closeEvent(event
);
584 void DolphinMainWindow::saveProperties(KConfigGroup
& group
)
586 m_tabWidget
->saveProperties(group
);
589 void DolphinMainWindow::readProperties(const KConfigGroup
& group
)
591 m_tabWidget
->readProperties(group
);
594 void DolphinMainWindow::updateNewMenu()
596 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
597 m_newFileMenu
->checkUpToDate();
598 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
601 void DolphinMainWindow::createDirectory()
603 m_newFileMenu
->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
604 m_newFileMenu
->setPopupFiles(activeViewContainer()->url());
605 m_newFileMenu
->createDirectory();
608 void DolphinMainWindow::quit()
613 void DolphinMainWindow::showErrorMessage(const QString
& message
)
615 m_activeViewContainer
->showMessage(message
, DolphinViewContainer::Error
);
618 void DolphinMainWindow::slotUndoAvailable(bool available
)
620 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
622 undoAction
->setEnabled(available
);
626 void DolphinMainWindow::slotUndoTextChanged(const QString
& text
)
628 QAction
* undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
630 undoAction
->setText(text
);
634 void DolphinMainWindow::undo()
637 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
638 KIO::FileUndoManager::self()->undo();
641 void DolphinMainWindow::cut()
643 m_activeViewContainer
->view()->cutSelectedItems();
646 void DolphinMainWindow::copy()
648 m_activeViewContainer
->view()->copySelectedItems();
651 void DolphinMainWindow::paste()
653 m_activeViewContainer
->view()->paste();
656 void DolphinMainWindow::find()
658 m_activeViewContainer
->setSearchModeEnabled(true);
661 void DolphinMainWindow::updateSearchAction()
663 QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
664 toggleSearchAction
->setChecked(m_activeViewContainer
->isSearchModeEnabled());
667 void DolphinMainWindow::updatePasteAction()
669 QAction
* pasteAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Paste
));
670 QPair
<bool, QString
> pasteInfo
= m_activeViewContainer
->view()->pasteInfo();
671 pasteAction
->setEnabled(pasteInfo
.first
);
672 pasteAction
->setText(pasteInfo
.second
);
675 void DolphinMainWindow::slotDirectoryLoadingCompleted()
680 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction
*action
)
682 if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Back
))) {
684 } else if (action
== actionCollection()->action(KStandardAction::name(KStandardAction::Forward
))) {
686 } else if (action
== actionCollection()->action(QStringLiteral("go_up"))) {
688 } else if (action
== actionCollection()->action(QStringLiteral("go_home"))) {
693 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
695 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
697 m_backAction
->menu()->clear();
698 for (int i
= urlNavigator
->historyIndex() + 1; i
< urlNavigator
->historySize() && entries
< MaxNumberOfNavigationentries
; ++i
, ++entries
) {
699 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_backAction
->menu());
701 m_backAction
->menu()->addAction(action
);
705 void DolphinMainWindow::slotGoBack(QAction
* action
)
707 int gotoIndex
= action
->data().value
<int>();
708 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
709 for (int i
= gotoIndex
- urlNavigator
->historyIndex(); i
> 0; --i
) {
714 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction
* action
)
717 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
718 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(action
->data().value
<int>()));
722 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
724 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
726 m_forwardAction
->menu()->clear();
727 for (int i
= urlNavigator
->historyIndex() - 1; i
>= 0 && entries
< MaxNumberOfNavigationentries
; --i
, ++entries
) {
728 QAction
* action
= new QAction(urlNavigator
->locationUrl(i
).toString(QUrl::PreferLocalFile
), m_forwardAction
->menu());
730 m_forwardAction
->menu()->addAction(action
);
734 void DolphinMainWindow::slotGoForward(QAction
* action
)
736 int gotoIndex
= action
->data().value
<int>();
737 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
738 for (int i
= urlNavigator
->historyIndex() - gotoIndex
; i
> 0; --i
) {
743 void DolphinMainWindow::selectAll()
747 // if the URL navigator is editable and focused, select the whole
748 // URL instead of all items of the view
750 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
751 QLineEdit
* lineEdit
= urlNavigator
->editor()->lineEdit();
752 const bool selectUrl
= urlNavigator
->isUrlEditable() &&
753 lineEdit
->hasFocus();
755 lineEdit
->selectAll();
757 m_activeViewContainer
->view()->selectAll();
761 void DolphinMainWindow::invertSelection()
764 m_activeViewContainer
->view()->invertSelection();
767 void DolphinMainWindow::toggleSplitView()
769 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
770 tabPage
->setSplitViewEnabled(!tabPage
->splitViewEnabled());
775 void DolphinMainWindow::toggleSplitStash()
777 DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
778 tabPage
->setSplitViewEnabled(false);
779 tabPage
->setSplitViewEnabled(true, QUrl("stash:/"));
782 void DolphinMainWindow::reloadView()
785 m_activeViewContainer
->reload();
786 m_activeViewContainer
->statusBar()->updateSpaceInfo();
789 void DolphinMainWindow::stopLoading()
791 m_activeViewContainer
->view()->stopLoading();
794 void DolphinMainWindow::enableStopAction()
796 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
799 void DolphinMainWindow::disableStopAction()
801 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
804 void DolphinMainWindow::showFilterBar()
806 m_activeViewContainer
->setFilterBarVisible(true);
809 void DolphinMainWindow::toggleEditLocation()
813 QAction
* action
= actionCollection()->action(QStringLiteral("editable_location"));
814 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
815 urlNavigator
->setUrlEditable(action
->isChecked());
818 void DolphinMainWindow::replaceLocation()
820 KUrlNavigator
* navigator
= m_activeViewContainer
->urlNavigator();
821 QLineEdit
* lineEdit
= navigator
->editor()->lineEdit();
823 // If the text field currently has focus and everything is selected,
824 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
825 if (navigator
->isUrlEditable()
826 && lineEdit
->hasFocus()
827 && lineEdit
->selectedText() == lineEdit
->text() ) {
828 navigator
->setUrlEditable(false);
830 navigator
->setUrlEditable(true);
831 navigator
->setFocus();
832 lineEdit
->selectAll();
836 void DolphinMainWindow::togglePanelLockState()
838 const bool newLockState
= !GeneralSettings::lockPanels();
839 foreach (QObject
* child
, children()) {
840 DolphinDockWidget
* dock
= qobject_cast
<DolphinDockWidget
*>(child
);
842 dock
->setLocked(newLockState
);
846 GeneralSettings::setLockPanels(newLockState
);
849 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
851 if (m_terminalPanel
->isHiddenInVisibleWindow() && m_activeViewContainer
) {
852 m_activeViewContainer
->view()->setFocus();
856 void DolphinMainWindow::goBack()
858 KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
859 urlNavigator
->goBack();
861 if (urlNavigator
->locationState().isEmpty()) {
862 // An empty location state indicates a redirection URL,
863 // which must be skipped too
864 urlNavigator
->goBack();
868 void DolphinMainWindow::goForward()
870 m_activeViewContainer
->urlNavigator()->goForward();
873 void DolphinMainWindow::goUp()
875 m_activeViewContainer
->urlNavigator()->goUp();
878 void DolphinMainWindow::goHome()
880 m_activeViewContainer
->urlNavigator()->goHome();
883 void DolphinMainWindow::goBackInNewTab()
885 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
886 const int index
= urlNavigator
->historyIndex() + 1;
887 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
890 void DolphinMainWindow::goForwardInNewTab()
892 KUrlNavigator
* urlNavigator
= activeViewContainer()->urlNavigator();
893 const int index
= urlNavigator
->historyIndex() - 1;
894 openNewTabAfterCurrentTab(urlNavigator
->locationUrl(index
));
897 void DolphinMainWindow::goUpInNewTab()
899 const QUrl currentUrl
= activeViewContainer()->urlNavigator()->locationUrl();
900 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl
));
903 void DolphinMainWindow::goHomeInNewTab()
905 openNewTabAfterCurrentTab(Dolphin::homeUrl());
908 void DolphinMainWindow::compareFiles()
910 const KFileItemList items
= m_tabWidget
->currentTabPage()->selectedItems();
911 if (items
.count() != 2) {
912 // The action is disabled in this case, but it could have been triggered
913 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
917 QUrl urlA
= items
.at(0).url();
918 QUrl urlB
= items
.at(1).url();
920 QString
command(QStringLiteral("kompare -c \""));
921 command
.append(urlA
.toDisplayString(QUrl::PreferLocalFile
));
922 command
.append("\" \"");
923 command
.append(urlB
.toDisplayString(QUrl::PreferLocalFile
));
924 command
.append('\"');
925 KRun::runCommand(command
, QStringLiteral("Kompare"), QStringLiteral("kompare"), this);
928 void DolphinMainWindow::toggleShowMenuBar()
930 const bool visible
= menuBar()->isVisible();
931 menuBar()->setVisible(!visible
);
933 createControlButton();
935 deleteControlButton();
939 QString
DolphinMainWindow::activeContainerLocalPath()
941 KIO::StatJob
* statJob
= KIO::mostLocalUrl(m_activeViewContainer
->url());
942 KJobWidgets::setWindow(statJob
, this);
944 QUrl url
= statJob
->mostLocalUrl();
945 if (url
.isLocalFile()) {
946 return url
.toLocalFile();
948 return QDir::homePath();
951 QPointer
<QAction
> DolphinMainWindow::preferredSearchTool()
953 m_searchTools
.clear();
954 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
955 &m_searchTools
, { "files-find" }, QUrl::fromLocalFile(activeContainerLocalPath())
957 QList
<QAction
*> actions
= m_searchTools
.actions();
958 if (actions
.isEmpty()) {
961 QAction
* action
= actions
.first();
962 if (action
->isSeparator()) {
968 void DolphinMainWindow::setupUpdateOpenPreferredSearchToolAction()
970 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
971 const QList
<QWidget
*> widgets
= openPreferredSearchTool
->associatedWidgets();
972 for (QWidget
* widget
: widgets
) {
973 QMenu
* menu
= qobject_cast
<QMenu
*>(widget
);
975 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
979 // Update the open_preferred_search_tool action *before* the Configure Shortcuts window is shown,
980 // since this action is then listed in that window and it should be up-to-date when it is displayed.
981 // This update is instantaneous if user made no changes to the search tools in the meantime.
982 // Maybe all KStandardActions should defer calls to their slots, so that we could simply connect() to trigger()?
984 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
)), &QAction::hovered
,
985 this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
988 updateOpenPreferredSearchToolAction();
991 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
993 QAction
* openPreferredSearchTool
= actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
994 if (!openPreferredSearchTool
) {
997 QPointer
<QAction
> tool
= preferredSearchTool();
999 openPreferredSearchTool
->setVisible(true);
1000 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open %1", tool
->text()));
1001 openPreferredSearchTool
->setIcon(tool
->icon());
1003 openPreferredSearchTool
->setVisible(false);
1004 // still visible in Shortcuts configuration window
1005 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1006 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1010 void DolphinMainWindow::openPreferredSearchTool()
1012 QPointer
<QAction
> tool
= preferredSearchTool();
1018 void DolphinMainWindow::openTerminal()
1020 KToolInvocation::invokeTerminal(QString(), activeContainerLocalPath());
1023 void DolphinMainWindow::editSettings()
1025 if (!m_settingsDialog
) {
1026 DolphinViewContainer
* container
= activeViewContainer();
1027 container
->view()->writeSettings();
1029 const QUrl url
= container
->url();
1030 DolphinSettingsDialog
* settingsDialog
= new DolphinSettingsDialog(url
, this);
1031 connect(settingsDialog
, &DolphinSettingsDialog::settingsChanged
, this, &DolphinMainWindow::refreshViews
);
1032 settingsDialog
->setAttribute(Qt::WA_DeleteOnClose
);
1033 settingsDialog
->show();
1034 m_settingsDialog
= settingsDialog
;
1036 m_settingsDialog
.data()->raise();
1040 void DolphinMainWindow::handleUrl(const QUrl
& url
)
1042 delete m_lastHandleUrlStatJob
;
1043 m_lastHandleUrlStatJob
= nullptr;
1045 if (url
.isLocalFile() && QFileInfo(url
.toLocalFile()).isDir()) {
1046 activeViewContainer()->setUrl(url
);
1047 } else if (KProtocolManager::supportsListing(url
)) {
1048 // stat the URL to see if it is a dir or not
1049 m_lastHandleUrlStatJob
= KIO::stat(url
, KIO::HideProgressInfo
);
1050 if (m_lastHandleUrlStatJob
->uiDelegate()) {
1051 KJobWidgets::setWindow(m_lastHandleUrlStatJob
, this);
1053 connect(m_lastHandleUrlStatJob
, &KIO::Job::result
,
1054 this, &DolphinMainWindow::slotHandleUrlStatFinished
);
1057 new KRun(url
, this); // Automatically deletes itself after being finished
1061 void DolphinMainWindow::slotHandleUrlStatFinished(KJob
* job
)
1063 m_lastHandleUrlStatJob
= nullptr;
1064 const KIO::UDSEntry entry
= static_cast<KIO::StatJob
*>(job
)->statResult();
1065 const QUrl url
= static_cast<KIO::StatJob
*>(job
)->url();
1066 if (entry
.isDir()) {
1067 activeViewContainer()->setUrl(url
);
1069 new KRun(url
, this); // Automatically deletes itself after being finished
1073 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable
)
1075 // trash:/ is writable but we don't want to create new items in it.
1076 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1077 newFileMenu()->setEnabled(isFolderWritable
&& m_activeViewContainer
->url().scheme() != QLatin1String("trash"));
1080 void DolphinMainWindow::openContextMenu(const QPoint
& pos
,
1081 const KFileItem
& item
,
1083 const QList
<QAction
*>& customActions
)
1085 QPointer
<DolphinContextMenu
> contextMenu
= new DolphinContextMenu(this, pos
, item
, url
);
1086 contextMenu
.data()->setCustomActions(customActions
);
1087 const DolphinContextMenu::Command command
= contextMenu
.data()->open();
1090 case DolphinContextMenu::OpenParentFolder
:
1091 changeUrl(KIO::upUrl(item
.url()));
1092 m_activeViewContainer
->view()->markUrlsAsSelected({item
.url()});
1093 m_activeViewContainer
->view()->markUrlAsCurrent(item
.url());
1096 case DolphinContextMenu::OpenParentFolderInNewWindow
:
1097 Dolphin::openNewWindow({item
.url()}, this, Dolphin::OpenNewWindowFlag::Select
);
1100 case DolphinContextMenu::OpenParentFolderInNewTab
:
1101 openNewTabAfterLastTab(KIO::upUrl(item
.url()));
1104 case DolphinContextMenu::None
:
1109 // Delete the menu, unless it has been deleted in its own nested event loop already.
1111 contextMenu
->deleteLater();
1115 void DolphinMainWindow::updateControlMenu()
1117 QMenu
* menu
= qobject_cast
<QMenu
*>(sender());
1120 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1121 // because 'menu' is their parent.
1124 KActionCollection
* ac
= actionCollection();
1126 menu
->addMenu(m_newFileMenu
->menu());
1127 addActionToMenu(ac
->action(QStringLiteral("file_new")), menu
);
1128 addActionToMenu(ac
->action(QStringLiteral("new_tab")), menu
);
1129 addActionToMenu(ac
->action(QStringLiteral("closed_tabs")), menu
);
1131 menu
->addSeparator();
1133 // Add "Edit" actions
1134 bool added
= addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Undo
)), menu
) |
1135 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::SelectAll
)), menu
) |
1136 addActionToMenu(ac
->action(QStringLiteral("invert_selection")), menu
);
1139 menu
->addSeparator();
1142 // Add "View" actions
1143 if (!GeneralSettings::showZoomSlider()) {
1144 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomIn
)), menu
);
1145 addActionToMenu(ac
->action(QStringLiteral("view_zoom_reset")), menu
);
1146 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ZoomOut
)), menu
);
1147 menu
->addSeparator();
1150 added
= addActionToMenu(ac
->action(QStringLiteral("show_preview")), menu
) |
1151 addActionToMenu(ac
->action(QStringLiteral("show_in_groups")), menu
) |
1152 addActionToMenu(ac
->action(QStringLiteral("show_hidden_files")), menu
) |
1153 addActionToMenu(ac
->action(QStringLiteral("additional_info")), menu
) |
1154 addActionToMenu(ac
->action(QStringLiteral("view_properties")), menu
);
1157 menu
->addSeparator();
1160 // Add a curated assortment of items from the "Tools" menu
1161 addActionToMenu(ac
->action(QStringLiteral("show_filter_bar")), menu
);
1162 addActionToMenu(ac
->action(QStringLiteral("open_preferred_search_tool")), menu
);
1163 addActionToMenu(ac
->action(QStringLiteral("open_terminal")), menu
);
1164 connect(menu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction
);
1166 menu
->addSeparator();
1168 // Add "Show Panels" menu
1169 addActionToMenu(ac
->action(QStringLiteral("panels")), menu
);
1171 // Add "Settings" menu entries
1172 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::KeyBindings
)), menu
);
1173 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ConfigureToolbars
)), menu
);
1174 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::Preferences
)), menu
);
1175 addActionToMenu(ac
->action(KStandardAction::name(KStandardAction::ShowMenubar
)), menu
);
1178 auto helpMenu
= m_helpMenu
->menu();
1179 helpMenu
->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1180 menu
->addMenu(helpMenu
);
1183 void DolphinMainWindow::updateToolBar()
1185 if (!menuBar()->isVisible()) {
1186 createControlButton();
1190 void DolphinMainWindow::slotControlButtonDeleted()
1192 m_controlButton
= nullptr;
1193 m_updateToolBarTimer
->start();
1196 void DolphinMainWindow::slotPlaceActivated(const QUrl
& url
)
1198 DolphinViewContainer
* view
= activeViewContainer();
1200 if (view
->url() == url
) {
1201 // We can end up here if the user clicked a device in the Places Panel
1202 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1209 void DolphinMainWindow::closedTabsCountChanged(unsigned int count
)
1211 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count
> 0);
1214 void DolphinMainWindow::activeViewChanged(DolphinViewContainer
* viewContainer
)
1216 DolphinViewContainer
* oldViewContainer
= m_activeViewContainer
;
1217 Q_ASSERT(viewContainer
);
1219 m_activeViewContainer
= viewContainer
;
1221 if (oldViewContainer
) {
1222 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
1223 toggleSearchAction
->disconnect(oldViewContainer
);
1225 // Disconnect all signals between the old view container (container,
1226 // view and url navigator) and main window.
1227 oldViewContainer
->disconnect(this);
1228 oldViewContainer
->view()->disconnect(this);
1229 oldViewContainer
->urlNavigator()->disconnect(this);
1231 // except the requestItemInfo so that on hover the information panel can still be updated
1232 connect(oldViewContainer
->view(), &DolphinView::requestItemInfo
,
1233 this, &DolphinMainWindow::requestItemInfo
);
1236 connectViewSignals(viewContainer
);
1238 m_actionHandler
->setCurrentView(viewContainer
->view());
1241 updateFileAndEditActions();
1242 updatePasteAction();
1243 updateViewActions();
1245 updateSearchAction();
1247 const QUrl url
= viewContainer
->url();
1248 emit
urlChanged(url
);
1251 void DolphinMainWindow::tabCountChanged(int count
)
1253 const bool enableTabActions
= (count
> 1);
1254 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1255 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i
))->setEnabled(enableTabActions
);
1257 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions
);
1258 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions
);
1259 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions
);
1262 void DolphinMainWindow::updateWindowTitle()
1264 const QString newTitle
= m_activeViewContainer
->caption();
1265 if (windowTitle() != newTitle
) {
1266 setWindowTitle(newTitle
);
1270 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString
& mountPath
)
1272 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1273 m_tearDownFromPlacesRequested
= true;
1274 m_terminalPanel
->goHome();
1275 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1277 m_placesPanel
->proceedWithTearDown();
1281 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString
& mountPath
)
1283 if (m_terminalPanel
&& m_terminalPanel
->currentWorkingDirectory().startsWith(mountPath
)) {
1284 m_tearDownFromPlacesRequested
= false;
1285 m_terminalPanel
->goHome();
1289 void DolphinMainWindow::setupActions()
1291 // setup 'File' menu
1292 m_newFileMenu
= new DolphinNewFileMenu(actionCollection(), this);
1293 QMenu
* menu
= m_newFileMenu
->menu();
1294 menu
->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1295 menu
->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1296 m_newFileMenu
->setDelayed(false);
1297 connect(menu
, &QMenu::aboutToShow
,
1298 this, &DolphinMainWindow::updateNewMenu
);
1300 QAction
* newWindow
= KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow
, actionCollection());
1301 newWindow
->setText(i18nc("@action:inmenu File", "New &Window"));
1302 newWindow
->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1303 newWindow
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1304 "window just like this one with the current location and view."
1305 "<nl/>You can drag and drop items between windows."));
1306 newWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1308 QAction
* newTab
= actionCollection()->addAction(QStringLiteral("new_tab"));
1309 newTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1310 newTab
->setText(i18nc("@action:inmenu File", "New Tab"));
1311 newTab
->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1312 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1313 "A tab is an additional view within this window. "
1314 "You can drag and drop items between tabs."));
1315 actionCollection()->setDefaultShortcuts(newTab
, {Qt::CTRL
+ Qt::Key_T
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_N
});
1316 connect(newTab
, &QAction::triggered
, this, &DolphinMainWindow::openNewActivatedTab
);
1318 QAction
* addToPlaces
= actionCollection()->addAction(QStringLiteral("add_to_places"));
1319 addToPlaces
->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1320 addToPlaces
->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1321 "to the Places panel."));
1322 connect(addToPlaces
, &QAction::triggered
, this, &DolphinMainWindow::addToPlaces
);
1324 QAction
* closeTab
= KStandardAction::close(m_tabWidget
, QOverload
<>::of(&DolphinTabWidget::closeTab
), actionCollection());
1325 closeTab
->setText(i18nc("@action:inmenu File", "Close Tab"));
1326 closeTab
->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1327 "currently viewed tab. If no more tabs are left this window "
1328 "will close instead."));
1330 QAction
* quitAction
= KStandardAction::quit(this, &DolphinMainWindow::quit
, actionCollection());
1331 quitAction
->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1333 // setup 'Edit' menu
1334 KStandardAction::undo(this,
1335 &DolphinMainWindow::undo
,
1336 actionCollection());
1338 // i18n: This will be the last paragraph for the whatsthis for all three:
1339 // Cut, Copy and Paste
1340 const QString cutCopyPastePara
= xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1341 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1342 "applications and are among the most used commands. That's why their "
1343 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1344 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1345 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1346 QAction
* cutAction
= KStandardAction::cut(this, &DolphinMainWindow::cut
, actionCollection());
1347 cutAction
->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1348 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1349 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1350 "the clipboard to a new location. The items will be removed from their "
1351 "initial location.") + cutCopyPastePara
);
1352 QAction
* copyAction
= KStandardAction::copy(this, &DolphinMainWindow::copy
, actionCollection());
1353 copyAction
->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1354 "items in your current selection to the <emphasis>clipboard</emphasis>."
1355 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1356 "from the clipboard to a new location.") + cutCopyPastePara
);
1357 QAction
* paste
= KStandardAction::paste(this, &DolphinMainWindow::paste
, actionCollection());
1358 // The text of the paste-action is modified dynamically by Dolphin
1359 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1360 // due to the long text, the text "Paste" is used:
1361 paste
->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1362 paste
->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1363 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1364 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1365 "action they are removed from their old location.") + cutCopyPastePara
);
1367 QAction
*searchAction
= KStandardAction::find(this, &DolphinMainWindow::find
, actionCollection());
1368 searchAction
->setText(i18n("Search..."));
1369 searchAction
->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1370 searchAction
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1371 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1372 "There you can enter search terms and specify settings to find the "
1373 "objects you are looking for.</para><para>Use this help again on "
1374 "the find bar so we can have a look at it while the settings are "
1375 "explained.</para>"));
1377 // toggle_search acts as a copy of the main searchAction to be used mainly
1378 // in the toolbar, with no default shortcut attached, to avoid messing with
1379 // existing workflows (search bar always open and Ctrl-F to focus)
1380 QAction
*toggleSearchAction
= actionCollection()->addAction(QStringLiteral("toggle_search"));
1381 toggleSearchAction
->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1382 toggleSearchAction
->setIconText(i18nc("@action:intoolbar", "Search"));
1383 toggleSearchAction
->setIcon(searchAction
->icon());
1384 toggleSearchAction
->setToolTip(searchAction
->toolTip());
1385 toggleSearchAction
->setWhatsThis(searchAction
->whatsThis());
1386 toggleSearchAction
->setCheckable(true);
1388 QAction
* selectAllAction
= KStandardAction::selectAll(this, &DolphinMainWindow::selectAll
, actionCollection());
1389 selectAllAction
->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1390 "files and folders in the current location."));
1392 QAction
* invertSelection
= actionCollection()->addAction(QStringLiteral("invert_selection"));
1393 invertSelection
->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1394 invertSelection
->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1395 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1396 invertSelection
->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1397 actionCollection()->setDefaultShortcut(invertSelection
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_A
);
1398 connect(invertSelection
, &QAction::triggered
, this, &DolphinMainWindow::invertSelection
);
1400 // setup 'View' menu
1401 // (note that most of it is set up in DolphinViewActionHandler)
1403 QAction
* split
= actionCollection()->addAction(QStringLiteral("split_view"));
1404 split
->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1405 "the folder view below into two autonomous views.</para><para>This "
1406 "way you can see two locations at once and move items between them "
1407 "quickly.</para>Click this again afterwards to recombine the views."));
1408 actionCollection()->setDefaultShortcut(split
, Qt::Key_F3
);
1409 connect(split
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitView
);
1411 QAction
* stashSplit
= actionCollection()->addAction(QStringLiteral("split_stash"));
1412 actionCollection()->setDefaultShortcut(stashSplit
, Qt::CTRL
+ Qt::Key_S
);
1413 stashSplit
->setText(i18nc("@action:intoolbar Stash", "Stash"));
1414 stashSplit
->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1415 stashSplit
->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1416 stashSplit
->setCheckable(false);
1417 stashSplit
->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1418 connect(stashSplit
, &QAction::triggered
, this, &DolphinMainWindow::toggleSplitStash
);
1420 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView
, actionCollection());
1422 QAction
* stop
= actionCollection()->addAction(QStringLiteral("stop"));
1423 stop
->setText(i18nc("@action:inmenu View", "Stop"));
1424 stop
->setToolTip(i18nc("@info", "Stop loading"));
1425 stop
->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1426 stop
->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1427 connect(stop
, &QAction::triggered
, this, &DolphinMainWindow::stopLoading
);
1429 KToggleAction
* editableLocation
= actionCollection()->add
<KToggleAction
>(QStringLiteral("editable_location"));
1430 editableLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1431 editableLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1432 "This toggles the <emphasis>Location Bar</emphasis> to be "
1433 "editable so you can directly enter a location you want to go to.<nl/>"
1434 "You can also switch to editing by clicking to the right of the "
1435 "location and switch back by confirming the edited location."));
1436 actionCollection()->setDefaultShortcut(editableLocation
, Qt::Key_F6
);
1437 connect(editableLocation
, &KToggleAction::triggered
, this, &DolphinMainWindow::toggleEditLocation
);
1439 QAction
* replaceLocation
= actionCollection()->addAction(QStringLiteral("replace_location"));
1440 replaceLocation
->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1441 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1442 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1443 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1444 replaceLocation
->setWhatsThis(xi18nc("@info:whatsthis",
1445 "This switches to editing the location and selects it "
1446 "so you can quickly enter a different location."));
1447 actionCollection()->setDefaultShortcut(replaceLocation
, Qt::CTRL
+ Qt::Key_L
);
1448 connect(replaceLocation
, &QAction::triggered
, this, &DolphinMainWindow::replaceLocation
);
1452 QScopedPointer
<QAction
> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1453 m_backAction
= new KToolBarPopupAction(backAction
->icon(), backAction
->text(), actionCollection());
1454 m_backAction
->setObjectName(backAction
->objectName());
1455 m_backAction
->setShortcuts(backAction
->shortcuts());
1457 m_backAction
->setDelayed(true);
1458 m_backAction
->setStickyMenu(false);
1459 connect(m_backAction
, &QAction::triggered
, this, &DolphinMainWindow::goBack
);
1460 connect(m_backAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu
);
1461 connect(m_backAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoBack
);
1462 actionCollection()->addAction(m_backAction
->objectName(), m_backAction
);
1464 auto backShortcuts
= m_backAction
->shortcuts();
1465 backShortcuts
.append(QKeySequence(Qt::Key_Backspace
));
1466 actionCollection()->setDefaultShortcuts(m_backAction
, backShortcuts
);
1468 DolphinRecentTabsMenu
* recentTabsMenu
= new DolphinRecentTabsMenu(this);
1469 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu
);
1470 connect(m_tabWidget
, &DolphinTabWidget::rememberClosedTab
,
1471 recentTabsMenu
, &DolphinRecentTabsMenu::rememberClosedTab
);
1472 connect(recentTabsMenu
, &DolphinRecentTabsMenu::restoreClosedTab
,
1473 m_tabWidget
, &DolphinTabWidget::restoreClosedTab
);
1474 connect(recentTabsMenu
, &DolphinRecentTabsMenu::closedTabsCountChanged
,
1475 this, &DolphinMainWindow::closedTabsCountChanged
);
1477 QAction
* undoCloseTab
= actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1478 undoCloseTab
->setText(i18nc("@action:inmenu File", "Undo close tab"));
1479 undoCloseTab
->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1480 "This returns you to the previously closed tab."));
1481 actionCollection()->setDefaultShortcut(undoCloseTab
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_T
);
1482 undoCloseTab
->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1483 undoCloseTab
->setEnabled(false);
1484 connect(undoCloseTab
, &QAction::triggered
, recentTabsMenu
, &DolphinRecentTabsMenu::undoCloseTab
);
1486 auto undoAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Undo
));
1487 undoAction
->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1488 "the last change you made to files or folders.<nl/>"
1489 "Such changes include <interface>creating, renaming</interface> "
1490 "and <interface>moving</interface> them to a different location "
1491 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1492 "be undone will ask for your confirmation."));
1493 undoAction
->setEnabled(false); // undo should be disabled by default
1496 QScopedPointer
<QAction
> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1497 m_forwardAction
= new KToolBarPopupAction(forwardAction
->icon(), forwardAction
->text(), actionCollection());
1498 m_forwardAction
->setObjectName(forwardAction
->objectName());
1499 m_forwardAction
->setShortcuts(forwardAction
->shortcuts());
1501 m_forwardAction
->setDelayed(true);
1502 m_forwardAction
->setStickyMenu(false);
1503 connect(m_forwardAction
, &QAction::triggered
, this, &DolphinMainWindow::goForward
);
1504 connect(m_forwardAction
->menu(), &QMenu::aboutToShow
, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu
);
1505 connect(m_forwardAction
->menu(), &QMenu::triggered
, this, &DolphinMainWindow::slotGoForward
);
1506 actionCollection()->addAction(m_forwardAction
->objectName(), m_forwardAction
);
1507 actionCollection()->setDefaultShortcuts(m_forwardAction
, m_forwardAction
->shortcuts());
1509 // enable middle-click to open in a new tab
1510 auto *middleClickEventFilter
= new MiddleClickActionEventFilter(this);
1511 connect(middleClickEventFilter
, &MiddleClickActionEventFilter::actionMiddleClicked
, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked
);
1512 m_backAction
->menu()->installEventFilter(middleClickEventFilter
);
1513 m_forwardAction
->menu()->installEventFilter(middleClickEventFilter
);
1514 KStandardAction::up(this, &DolphinMainWindow::goUp
, actionCollection());
1515 QAction
* homeAction
= KStandardAction::home(this, &DolphinMainWindow::goHome
, actionCollection());
1516 homeAction
->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1517 "<filename>Home</filename> folder.<nl/>Every user account "
1518 "has their own <filename>Home</filename> that contains their data "
1519 "including folders that contain personal application data."));
1521 // setup 'Tools' menu
1522 QAction
* showFilterBar
= actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1523 showFilterBar
->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1524 showFilterBar
->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1525 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1526 "There you can enter a text to filter the files and folders currently displayed. "
1527 "Only those that contain the text in their name will be kept in view."));
1528 showFilterBar
->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1529 actionCollection()->setDefaultShortcuts(showFilterBar
, {Qt::CTRL
+ Qt::Key_I
, Qt::Key_Slash
});
1530 connect(showFilterBar
, &QAction::triggered
, this, &DolphinMainWindow::showFilterBar
);
1532 QAction
* compareFiles
= actionCollection()->addAction(QStringLiteral("compare_files"));
1533 compareFiles
->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1534 compareFiles
->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1535 compareFiles
->setEnabled(false);
1536 connect(compareFiles
, &QAction::triggered
, this, &DolphinMainWindow::compareFiles
);
1538 QAction
* openPreferredSearchTool
= actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1539 openPreferredSearchTool
->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1540 openPreferredSearchTool
->setWhatsThis(xi18nc("@info:whatsthis",
1541 "<para>This opens a preferred search tool for the viewed location.</para>"
1542 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1543 openPreferredSearchTool
->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1544 actionCollection()->setDefaultShortcut(openPreferredSearchTool
, Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_F
);
1545 connect(openPreferredSearchTool
, &QAction::triggered
, this, &DolphinMainWindow::openPreferredSearchTool
);
1547 #ifdef HAVE_TERMINAL
1548 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1549 QAction
* openTerminal
= actionCollection()->addAction(QStringLiteral("open_terminal"));
1550 openTerminal
->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1551 openTerminal
->setWhatsThis(xi18nc("@info:whatsthis",
1552 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1553 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1554 openTerminal
->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1555 actionCollection()->setDefaultShortcut(openTerminal
, Qt::SHIFT
+ Qt::Key_F4
);
1556 connect(openTerminal
, &QAction::triggered
, this, &DolphinMainWindow::openTerminal
);
1560 // setup 'Bookmarks' menu
1561 KActionMenu
*bookmarkMenu
= new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1562 bookmarkMenu
->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1563 // Make the toolbar button version work properly on click
1564 bookmarkMenu
->setDelayed(false);
1565 m_bookmarkHandler
= new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu
->menu(), this);
1566 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu
);
1568 // setup 'Settings' menu
1569 KToggleAction
* showMenuBar
= KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1570 showMenuBar
->setWhatsThis(xi18nc("@info:whatsthis",
1571 "This switches between having a <emphasis>Menubar</emphasis> "
1572 "and having a <interface>Control</interface> button. Both "
1573 "contain mostly the same commands and configuration options."));
1574 connect(showMenuBar
, &KToggleAction::triggered
, // Fixes #286822
1575 this, &DolphinMainWindow::toggleShowMenuBar
, Qt::QueuedConnection
);
1576 KStandardAction::preferences(this, &DolphinMainWindow::editSettings
, actionCollection());
1578 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1579 m_helpMenu
= new KHelpMenu(nullptr);
1580 m_helpMenu
->menu()->installEventFilter(this);
1581 // remove duplicate shortcuts
1582 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setShortcut(QKeySequence());
1583 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setShortcut(QKeySequence());
1585 // not in menu actions
1586 QList
<QKeySequence
> nextTabKeys
= KStandardShortcut::tabNext();
1587 nextTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::Key_Tab
));
1589 QList
<QKeySequence
> prevTabKeys
= KStandardShortcut::tabPrev();
1590 prevTabKeys
.append(QKeySequence(Qt::CTRL
+ Qt::SHIFT
+ Qt::Key_Tab
));
1592 for (int i
= 0; i
< MaxActivateTabShortcuts
; ++i
) {
1593 QAction
* activateTab
= actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i
));
1594 activateTab
->setText(i18nc("@action:inmenu", "Activate Tab %1", i
+ 1));
1595 activateTab
->setEnabled(false);
1596 connect(activateTab
, &QAction::triggered
, this, [this, i
]() { m_tabWidget
->activateTab(i
); });
1598 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1600 actionCollection()->setDefaultShortcut(activateTab
, QStringLiteral("Alt+%1").arg(i
+ 1));
1604 QAction
* activateLastTab
= actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1605 activateLastTab
->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1606 activateLastTab
->setEnabled(false);
1607 connect(activateLastTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateLastTab
);
1608 actionCollection()->setDefaultShortcut(activateLastTab
, Qt::ALT
+ Qt::Key_0
);
1610 QAction
* activateNextTab
= actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1611 activateNextTab
->setIconText(i18nc("@action:inmenu", "Next Tab"));
1612 activateNextTab
->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1613 activateNextTab
->setEnabled(false);
1614 connect(activateNextTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activateNextTab
);
1615 actionCollection()->setDefaultShortcuts(activateNextTab
, nextTabKeys
);
1617 QAction
* activatePrevTab
= actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1618 activatePrevTab
->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1619 activatePrevTab
->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1620 activatePrevTab
->setEnabled(false);
1621 connect(activatePrevTab
, &QAction::triggered
, m_tabWidget
, &DolphinTabWidget::activatePrevTab
);
1622 actionCollection()->setDefaultShortcuts(activatePrevTab
, prevTabKeys
);
1625 QAction
* showTarget
= actionCollection()->addAction(QStringLiteral("show_target"));
1626 showTarget
->setText(i18nc("@action:inmenu", "Show Target"));
1627 showTarget
->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1628 showTarget
->setEnabled(false);
1629 connect(showTarget
, &QAction::triggered
, this, &DolphinMainWindow::showTarget
);
1631 QAction
* openInNewTab
= actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1632 openInNewTab
->setText(i18nc("@action:inmenu", "Open in New Tab"));
1633 openInNewTab
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1634 connect(openInNewTab
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1636 QAction
* openInNewTabs
= actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1637 openInNewTabs
->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1638 openInNewTabs
->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1639 connect(openInNewTabs
, &QAction::triggered
, this, &DolphinMainWindow::openInNewTab
);
1641 QAction
* openInNewWindow
= actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1642 openInNewWindow
->setText(i18nc("@action:inmenu", "Open in New Window"));
1643 openInNewWindow
->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1644 connect(openInNewWindow
, &QAction::triggered
, this, &DolphinMainWindow::openInNewWindow
);
1647 void DolphinMainWindow::setupDockWidgets()
1649 const bool lock
= GeneralSettings::lockPanels();
1651 KDualAction
* lockLayoutAction
= actionCollection()->add
<KDualAction
>(QStringLiteral("lock_panels"));
1652 lockLayoutAction
->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1653 lockLayoutAction
->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1654 lockLayoutAction
->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1655 lockLayoutAction
->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1656 lockLayoutAction
->setWhatsThis(xi18nc("@info:whatsthis", "This "
1657 "switches between having panels <emphasis>locked</emphasis> or "
1658 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1659 "dragged to the other side of the window and have a close "
1660 "button.<nl/>Locked panels are embedded more cleanly."));
1661 lockLayoutAction
->setActive(lock
);
1662 connect(lockLayoutAction
, &KDualAction::triggered
, this, &DolphinMainWindow::togglePanelLockState
);
1664 // Setup "Information"
1665 DolphinDockWidget
* infoDock
= new DolphinDockWidget(i18nc("@title:window", "Information"));
1666 infoDock
->setLocked(lock
);
1667 infoDock
->setObjectName(QStringLiteral("infoDock"));
1668 infoDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1671 InformationPanel
* infoPanel
= new InformationPanel(infoDock
);
1672 infoPanel
->setCustomContextMenuActions({lockLayoutAction
});
1673 connect(infoPanel
, &InformationPanel::urlActivated
, this, &DolphinMainWindow::handleUrl
);
1674 infoDock
->setWidget(infoPanel
);
1676 QAction
* infoAction
= infoDock
->toggleViewAction();
1677 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11
, infoAction
, QStringLiteral("show_information_panel"));
1679 addDockWidget(Qt::RightDockWidgetArea
, infoDock
);
1680 connect(this, &DolphinMainWindow::urlChanged
,
1681 infoPanel
, &InformationPanel::setUrl
);
1682 connect(this, &DolphinMainWindow::selectionChanged
,
1683 infoPanel
, &InformationPanel::setSelection
);
1684 connect(this, &DolphinMainWindow::requestItemInfo
,
1685 infoPanel
, &InformationPanel::requestDelayedItemInfo
);
1688 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1689 const QString panelWhatsThis
= xi18nc("@info:whatsthis", "<para>To show or "
1690 "hide panels like this go to <interface>Control|Panels</interface> "
1691 "or <interface>View|Panels</interface>.</para>");
1693 actionCollection()->action(QStringLiteral("show_information_panel"))
1694 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1695 "<emphasis>information</emphasis> panel at the right side of the "
1696 "window.</para><para>The panel provides in-depth information "
1697 "about the items your mouse is hovering over or about the selected "
1698 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1699 "For single items a preview of their contents is provided.</para>"));
1701 infoDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1702 "provides in-depth information about the items your mouse is "
1703 "hovering over or about the selected items. Otherwise it informs "
1704 "you about the currently viewed folder.<nl/>For single items a "
1705 "preview of their contents is provided.</para><para>You can configure "
1706 "which and how details are given here by right-clicking.</para>") + panelWhatsThis
);
1709 DolphinDockWidget
* foldersDock
= new DolphinDockWidget(i18nc("@title:window", "Folders"));
1710 foldersDock
->setLocked(lock
);
1711 foldersDock
->setObjectName(QStringLiteral("foldersDock"));
1712 foldersDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1713 FoldersPanel
* foldersPanel
= new FoldersPanel(foldersDock
);
1714 foldersPanel
->setCustomContextMenuActions({lockLayoutAction
});
1715 foldersDock
->setWidget(foldersPanel
);
1717 QAction
* foldersAction
= foldersDock
->toggleViewAction();
1718 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7
, foldersAction
, QStringLiteral("show_folders_panel"));
1720 addDockWidget(Qt::LeftDockWidgetArea
, foldersDock
);
1721 connect(this, &DolphinMainWindow::urlChanged
,
1722 foldersPanel
, &FoldersPanel::setUrl
);
1723 connect(foldersPanel
, &FoldersPanel::folderActivated
,
1724 this, &DolphinMainWindow::changeUrl
);
1725 connect(foldersPanel
, &FoldersPanel::folderMiddleClicked
,
1726 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1727 connect(foldersPanel
, &FoldersPanel::errorMessage
,
1728 this, &DolphinMainWindow::showErrorMessage
);
1730 actionCollection()->action(QStringLiteral("show_folders_panel"))
1731 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1732 "<emphasis>folders</emphasis> panel at the left side of the window."
1733 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1734 "</emphasis> in a <emphasis>tree view</emphasis>."));
1735 foldersDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1736 "shows the folders of the <emphasis>file system</emphasis> in a "
1737 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1738 "there. Click the arrow to the left of a folder to see its subfolders. "
1739 "This allows quick switching between any folders.</para>") + panelWhatsThis
);
1742 #ifdef HAVE_TERMINAL
1743 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1744 DolphinDockWidget
* terminalDock
= new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1745 terminalDock
->setLocked(lock
);
1746 terminalDock
->setObjectName(QStringLiteral("terminalDock"));
1747 m_terminalPanel
= new TerminalPanel(terminalDock
);
1748 m_terminalPanel
->setCustomContextMenuActions({lockLayoutAction
});
1749 terminalDock
->setWidget(m_terminalPanel
);
1751 connect(m_terminalPanel
, &TerminalPanel::hideTerminalPanel
, terminalDock
, &DolphinDockWidget::hide
);
1752 connect(m_terminalPanel
, &TerminalPanel::changeUrl
, this, &DolphinMainWindow::slotTerminalDirectoryChanged
);
1753 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1754 m_terminalPanel
, &TerminalPanel::dockVisibilityChanged
);
1755 connect(terminalDock
, &DolphinDockWidget::visibilityChanged
,
1756 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged
);
1758 QAction
* terminalAction
= terminalDock
->toggleViewAction();
1759 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4
, terminalAction
, QStringLiteral("show_terminal_panel"));
1761 addDockWidget(Qt::BottomDockWidgetArea
, terminalDock
);
1762 connect(this, &DolphinMainWindow::urlChanged
,
1763 m_terminalPanel
, &TerminalPanel::setUrl
);
1765 if (GeneralSettings::version() < 200) {
1766 terminalDock
->hide();
1769 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1770 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1771 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1772 "<nl/>The location in the terminal will always match the folder "
1773 "view so you can navigate using either.</para><para>The terminal "
1774 "panel is not needed for basic computer usage but can be useful "
1775 "for advanced tasks. To learn more about terminals use the help "
1776 "in a standalone terminal application like Konsole.</para>"));
1777 terminalDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1778 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1779 "normal terminal but will match the location of the folder view "
1780 "so you can navigate using either.</para><para>The terminal panel "
1781 "is not needed for basic computer usage but can be useful for "
1782 "advanced tasks. To learn more about terminals use the help in a "
1783 "standalone terminal application like Konsole.</para>") + panelWhatsThis
);
1787 if (GeneralSettings::version() < 200) {
1789 foldersDock
->hide();
1793 DolphinDockWidget
* placesDock
= new DolphinDockWidget(i18nc("@title:window", "Places"));
1794 placesDock
->setLocked(lock
);
1795 placesDock
->setObjectName(QStringLiteral("placesDock"));
1796 placesDock
->setAllowedAreas(Qt::LeftDockWidgetArea
| Qt::RightDockWidgetArea
);
1798 m_placesPanel
= new PlacesPanel(placesDock
);
1799 m_placesPanel
->setCustomContextMenuActions({lockLayoutAction
});
1800 placesDock
->setWidget(m_placesPanel
);
1802 QAction
*placesAction
= placesDock
->toggleViewAction();
1803 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9
, placesAction
, QStringLiteral("show_places_panel"));
1805 addDockWidget(Qt::LeftDockWidgetArea
, placesDock
);
1806 connect(m_placesPanel
, &PlacesPanel::placeActivated
,
1807 this, &DolphinMainWindow::slotPlaceActivated
);
1808 connect(m_placesPanel
, &PlacesPanel::placeMiddleClicked
,
1809 this, &DolphinMainWindow::openNewTabAfterCurrentTab
);
1810 connect(m_placesPanel
, &PlacesPanel::errorMessage
,
1811 this, &DolphinMainWindow::showErrorMessage
);
1812 connect(this, &DolphinMainWindow::urlChanged
,
1813 m_placesPanel
, &PlacesPanel::setUrl
);
1814 connect(placesDock
, &DolphinDockWidget::visibilityChanged
,
1815 m_tabWidget
, &DolphinTabWidget::slotPlacesPanelVisibilityChanged
);
1816 connect(this, &DolphinMainWindow::settingsChanged
,
1817 m_placesPanel
, &PlacesPanel::readSettings
);
1818 connect(m_placesPanel
, &PlacesPanel::storageTearDownRequested
,
1819 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested
);
1820 connect(m_placesPanel
, &PlacesPanel::storageTearDownExternallyRequested
,
1821 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested
);
1822 m_tabWidget
->slotPlacesPanelVisibilityChanged(m_placesPanel
->isVisible());
1824 auto actionShowAllPlaces
= new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1825 actionShowAllPlaces
->setCheckable(true);
1826 actionShowAllPlaces
->setDisabled(true);
1827 actionShowAllPlaces
->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1828 "all places in the places panel that have been hidden. They will "
1829 "appear semi-transparent unless you uncheck their hide property."));
1831 connect(actionShowAllPlaces
, &QAction::triggered
, this, [actionShowAllPlaces
, this](bool checked
){
1832 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1833 m_placesPanel
->showHiddenEntries(checked
);
1836 connect(m_placesPanel
, &PlacesPanel::showHiddenEntriesChanged
, this, [actionShowAllPlaces
] (bool checked
){
1837 actionShowAllPlaces
->setChecked(checked
);
1838 actionShowAllPlaces
->setIcon(QIcon::fromTheme(checked
? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1841 actionCollection()->action(QStringLiteral("show_places_panel"))
1842 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1843 "<emphasis>places</emphasis> panel at the left side of the window."
1844 "</para><para>It allows you to go to locations you have "
1845 "bookmarked and to access disk or media attached to the computer "
1846 "or to the network. It also contains sections to find recently "
1847 "saved files or files of a certain type.</para>"));
1848 placesDock
->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1849 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1850 "you have bookmarked and to access disk or media attached to the "
1851 "computer or to the network. It also contains sections to find "
1852 "recently saved files or files of a certain type.</para><para>"
1853 "Click on an entry to go there. Click with the right mouse button "
1854 "instead to open any entry in a new tab or new window.</para>"
1855 "<para>New entries can be added by dragging folders onto this panel. "
1856 "Right-click any section or entry to hide it. Right-click an empty "
1857 "space on this panel and select <interface>Show Hidden Places"
1858 "</interface> to display it again.</para>") + panelWhatsThis
);
1860 // Add actions into the "Panels" menu
1861 KActionMenu
* panelsMenu
= new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1862 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu
);
1863 panelsMenu
->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1864 panelsMenu
->setDelayed(false);
1865 const KActionCollection
* ac
= actionCollection();
1866 panelsMenu
->addAction(ac
->action(QStringLiteral("show_places_panel")));
1868 panelsMenu
->addAction(ac
->action(QStringLiteral("show_information_panel")));
1870 panelsMenu
->addAction(ac
->action(QStringLiteral("show_folders_panel")));
1871 panelsMenu
->addAction(ac
->action(QStringLiteral("show_terminal_panel")));
1872 panelsMenu
->addSeparator();
1873 panelsMenu
->addAction(actionShowAllPlaces
);
1874 panelsMenu
->addAction(lockLayoutAction
);
1876 connect(panelsMenu
->menu(), &QMenu::aboutToShow
, this, [actionShowAllPlaces
, this]{
1877 actionShowAllPlaces
->setEnabled(m_placesPanel
->hiddenListCount());
1882 void DolphinMainWindow::updateFileAndEditActions()
1884 const KFileItemList list
= m_activeViewContainer
->view()->selectedItems();
1885 const KActionCollection
* col
= actionCollection();
1886 QAction
* addToPlacesAction
= col
->action(QStringLiteral("add_to_places"));
1888 if (list
.isEmpty()) {
1889 stateChanged(QStringLiteral("has_no_selection"));
1891 addToPlacesAction
->setEnabled(true);
1892 addToPlacesAction
->setText(i18nc("@action:inmenu Add current folder to places", "Add '%1' to Places", m_activeViewContainer
->placesText()));
1894 stateChanged(QStringLiteral("has_selection"));
1896 QAction
* renameAction
= col
->action(KStandardAction::name(KStandardAction::RenameFile
));
1897 QAction
* moveToTrashAction
= col
->action(KStandardAction::name(KStandardAction::MoveToTrash
));
1898 QAction
* deleteAction
= col
->action(KStandardAction::name(KStandardAction::DeleteFile
));
1899 QAction
* cutAction
= col
->action(KStandardAction::name(KStandardAction::Cut
));
1900 QAction
* deleteWithTrashShortcut
= col
->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1901 QAction
* showTarget
= col
->action(QStringLiteral("show_target"));
1903 if (list
.length() == 1 && list
.first().isDir()) {
1904 addToPlacesAction
->setEnabled(true);
1905 addToPlacesAction
->setText(i18nc("@action:inmenu Add current folder to places", "Add '%1' to Places", list
.first().name()));
1907 addToPlacesAction
->setEnabled(false);
1908 addToPlacesAction
->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1911 KFileItemListProperties
capabilities(list
);
1912 const bool enableMoveToTrash
= capabilities
.isLocal() && capabilities
.supportsMoving();
1914 renameAction
->setEnabled(capabilities
.supportsMoving());
1915 moveToTrashAction
->setEnabled(enableMoveToTrash
);
1916 deleteAction
->setEnabled(capabilities
.supportsDeleting());
1917 deleteWithTrashShortcut
->setEnabled(capabilities
.supportsDeleting() && !enableMoveToTrash
);
1918 cutAction
->setEnabled(capabilities
.supportsMoving());
1919 showTarget
->setEnabled(list
.length() == 1 && list
.at(0).isLink());
1923 void DolphinMainWindow::updateViewActions()
1925 m_actionHandler
->updateViewActions();
1927 QAction
* showFilterBarAction
= actionCollection()->action(QStringLiteral("show_filter_bar"));
1928 showFilterBarAction
->setChecked(m_activeViewContainer
->isFilterBarVisible());
1930 updateSplitAction();
1932 QAction
* editableLocactionAction
= actionCollection()->action(QStringLiteral("editable_location"));
1933 const KUrlNavigator
* urlNavigator
= m_activeViewContainer
->urlNavigator();
1934 editableLocactionAction
->setChecked(urlNavigator
->isUrlEditable());
1937 void DolphinMainWindow::updateGoActions()
1939 QAction
* goUpAction
= actionCollection()->action(KStandardAction::name(KStandardAction::Up
));
1940 const QUrl currentUrl
= m_activeViewContainer
->url();
1941 // I think this is one of the best places to firstly be confronted
1942 // with a file system and its hierarchy. Talking about the root
1943 // directory might seem too much here but it is the question that
1944 // naturally arises in this context.
1945 goUpAction
->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
1946 "the folder that contains the currently viewed one.</para>"
1947 "<para>All files and folders are organized in a hierarchical "
1948 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
1949 "a directory that contains all data connected to this computer"
1950 "—the <emphasis>root directory</emphasis>.</para>"));
1951 goUpAction
->setEnabled(KIO::upUrl(currentUrl
) != currentUrl
);
1954 void DolphinMainWindow::createControlButton()
1956 if (m_controlButton
) {
1959 Q_ASSERT(!m_controlButton
);
1961 m_controlButton
= new QToolButton(this);
1962 m_controlButton
->setAccessibleName(i18nc("@action:intoolbar", "Control"));
1963 m_controlButton
->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
1964 m_controlButton
->setToolTip(i18nc("@action", "Show menu"));
1965 m_controlButton
->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis
);
1966 m_controlButton
->setPopupMode(QToolButton::InstantPopup
);
1968 QMenu
* controlMenu
= new QMenu(m_controlButton
);
1969 connect(controlMenu
, &QMenu::aboutToShow
, this, &DolphinMainWindow::updateControlMenu
);
1970 controlMenu
->installEventFilter(this);
1972 m_controlButton
->setMenu(controlMenu
);
1974 toolBar()->addWidget(m_controlButton
);
1975 connect(toolBar(), &KToolBar::iconSizeChanged
,
1976 m_controlButton
, &QToolButton::setIconSize
);
1978 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1979 // gets edited. In this case we must add them again. The adding is done asynchronously by
1980 // m_updateToolBarTimer.
1981 connect(m_controlButton
, &QToolButton::destroyed
, this, &DolphinMainWindow::slotControlButtonDeleted
);
1982 m_updateToolBarTimer
= new QTimer(this);
1983 m_updateToolBarTimer
->setInterval(500);
1984 connect(m_updateToolBarTimer
, &QTimer::timeout
, this, &DolphinMainWindow::updateToolBar
);
1987 void DolphinMainWindow::deleteControlButton()
1989 delete m_controlButton
;
1990 m_controlButton
= nullptr;
1992 delete m_updateToolBarTimer
;
1993 m_updateToolBarTimer
= nullptr;
1996 bool DolphinMainWindow::addActionToMenu(QAction
* action
, QMenu
* menu
)
2001 const KToolBar
* toolBarWidget
= toolBar();
2002 foreach (const QWidget
* widget
, action
->associatedWidgets()) {
2003 if (widget
== toolBarWidget
) {
2008 menu
->addAction(action
);
2012 void DolphinMainWindow::refreshViews()
2014 m_tabWidget
->refreshViews();
2016 if (GeneralSettings::modifiedStartupSettings()) {
2017 // The startup settings have been changed by the user (see bug #254947).
2018 // Synchronize the split-view setting with the active view:
2019 const bool splitView
= GeneralSettings::splitView();
2020 m_tabWidget
->currentTabPage()->setSplitViewEnabled(splitView
);
2021 updateSplitAction();
2022 updateWindowTitle();
2025 emit
settingsChanged();
2028 void DolphinMainWindow::clearStatusBar()
2030 m_activeViewContainer
->statusBar()->resetToDefaultText();
2033 void DolphinMainWindow::connectViewSignals(DolphinViewContainer
* container
)
2035 connect(container
, &DolphinViewContainer::showFilterBarChanged
,
2036 this, &DolphinMainWindow::updateFilterBarAction
);
2037 connect(container
, &DolphinViewContainer::writeStateChanged
,
2038 this, &DolphinMainWindow::slotWriteStateChanged
);
2039 connect(container
, &DolphinViewContainer::searchModeEnabledChanged
,
2040 this, &DolphinMainWindow::updateSearchAction
);
2042 const QAction
* toggleSearchAction
= actionCollection()->action(QStringLiteral("toggle_search"));
2043 connect(toggleSearchAction
, &QAction::triggered
, container
, &DolphinViewContainer::setSearchModeEnabled
);
2045 const DolphinView
* view
= container
->view();
2046 connect(view
, &DolphinView::selectionChanged
,
2047 this, &DolphinMainWindow::slotSelectionChanged
);
2048 connect(view
, &DolphinView::requestItemInfo
,
2049 this, &DolphinMainWindow::requestItemInfo
);
2050 connect(view
, &DolphinView::tabRequested
,
2051 this, &DolphinMainWindow::openNewTab
);
2052 connect(view
, &DolphinView::requestContextMenu
,
2053 this, &DolphinMainWindow::openContextMenu
);
2054 connect(view
, &DolphinView::directoryLoadingStarted
,
2055 this, &DolphinMainWindow::enableStopAction
);
2056 connect(view
, &DolphinView::directoryLoadingCompleted
,
2057 this, &DolphinMainWindow::disableStopAction
);
2058 connect(view
, &DolphinView::directoryLoadingCompleted
,
2059 this, &DolphinMainWindow::slotDirectoryLoadingCompleted
);
2060 connect(view
, &DolphinView::goBackRequested
,
2061 this, &DolphinMainWindow::goBack
);
2062 connect(view
, &DolphinView::goForwardRequested
,
2063 this, &DolphinMainWindow::goForward
);
2064 connect(view
, &DolphinView::urlActivated
,
2065 this, &DolphinMainWindow::handleUrl
);
2067 const KUrlNavigator
* navigator
= container
->urlNavigator();
2068 connect(navigator
, &KUrlNavigator::urlChanged
,
2069 this, &DolphinMainWindow::changeUrl
);
2070 connect(navigator
, &KUrlNavigator::historyChanged
,
2071 this, &DolphinMainWindow::updateHistory
);
2072 connect(navigator
, &KUrlNavigator::editableStateChanged
,
2073 this, &DolphinMainWindow::slotEditableStateChanged
);
2074 connect(navigator
, &KUrlNavigator::tabRequested
,
2075 this, &DolphinMainWindow::openNewTabAfterLastTab
);
2078 void DolphinMainWindow::updateSplitAction()
2080 QAction
* splitAction
= actionCollection()->action(QStringLiteral("split_view"));
2081 const DolphinTabPage
* tabPage
= m_tabWidget
->currentTabPage();
2082 if (tabPage
->splitViewEnabled()) {
2083 if (GeneralSettings::closeActiveSplitView() ? tabPage
->primaryViewActive() : !tabPage
->primaryViewActive()) {
2084 splitAction
->setText(i18nc("@action:intoolbar Close left view", "Close"));
2085 splitAction
->setToolTip(i18nc("@info", "Close left view"));
2086 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2088 splitAction
->setText(i18nc("@action:intoolbar Close right view", "Close"));
2089 splitAction
->setToolTip(i18nc("@info", "Close right view"));
2090 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2093 splitAction
->setText(i18nc("@action:intoolbar Split view", "Split"));
2094 splitAction
->setToolTip(i18nc("@info", "Split view"));
2095 splitAction
->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2099 bool DolphinMainWindow::isKompareInstalled() const
2101 static bool initialized
= false;
2102 static bool installed
= false;
2104 // TODO: maybe replace this approach later by using a menu
2105 // plugin like kdiff3plugin.cpp
2106 installed
= !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2112 void DolphinMainWindow::createPanelAction(const QIcon
& icon
,
2113 const QKeySequence
& shortcut
,
2114 QAction
* dockAction
,
2115 const QString
& actionName
)
2117 QAction
* panelAction
= actionCollection()->addAction(actionName
);
2118 panelAction
->setCheckable(true);
2119 panelAction
->setChecked(dockAction
->isChecked());
2120 panelAction
->setText(dockAction
->text());
2121 panelAction
->setIcon(icon
);
2122 actionCollection()->setDefaultShortcut(panelAction
, shortcut
);
2124 connect(panelAction
, &QAction::triggered
, dockAction
, &QAction::trigger
);
2125 connect(dockAction
, &QAction::toggled
, panelAction
, &QAction::setChecked
);
2128 void DolphinMainWindow::setupWhatsThis()
2131 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2132 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2133 "configuration options. Left-click on any of the menus on this "
2134 "bar to see its contents.</para><para>The Menubar can be hidden "
2135 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2136 "most of its contents become available through a <interface>Control"
2137 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2138 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2139 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2140 "frequently used actions.</para><para>It is highly customizable. "
2141 "All items you see in the <interface>Control</interface> menu or "
2142 "in the <interface>Menubar</interface> can be placed on the "
2143 "Toolbar. Just right-click on it and select <interface>Configure "
2144 "Toolbars…</interface> or find this action in the <interface>"
2145 "Control</interface> or <interface>Settings</interface> menu."
2146 "</para><para>The location of the bar and the style of its "
2147 "buttons can also be changed in the right-click menu. Right-click "
2148 "a button if you want to show or hide its text.</para>"));
2149 m_tabWidget
->setWhatsThis(xi18nc("@info:whatsthis main view",
2150 "<para>Here you can see the <emphasis>folders</emphasis> and "
2151 "<emphasis>files</emphasis> that are at the location described in "
2152 "the <interface>Location Bar</interface> above. This area is the "
2153 "central part of this application where you navigate to the files "
2154 "you want to use.</para><para>For an elaborate and general "
2155 "introduction to this application <link "
2156 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2157 "click here</link>. This will open an introductory article from "
2158 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2159 "explanations of all the features of this <emphasis>view</emphasis> "
2160 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2161 "instead. This will open a page from the <emphasis>Handbook"
2162 "</emphasis> that covers the basics.</para>"));
2165 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings
))
2166 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2167 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2168 "There you can set up key combinations to trigger an action when "
2169 "they are pressed simultaneously. All commands in this application can "
2170 "be triggered this way.</para>"));
2171 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars
))
2172 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2173 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2174 "<para>All items you see in the <interface>Control</interface> menu "
2175 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2176 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences
))
2177 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2178 "change a multitude of settings for this application. For an explanation "
2179 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2180 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2183 // The whatsthis has to be set for the m_helpMenu and for the
2184 // StandardAction separately because both are used in different locations.
2185 // m_helpMenu is only used for createControlButton() button.
2187 // Links do not work within the Menubar so texts without links are provided there.
2189 // i18n: If the external link isn't available in your language you should
2190 // probably state the external link language at least in brackets to not
2191 // frustrate the user. If there are multiple languages that the user might
2192 // know with a reasonable chance you might want to have 2 external links.
2193 // The same is in my opinion true for every external link you translate.
2194 const QString whatsThisHelpContents
= xi18nc("@info:whatsthis handbook",
2195 "<para>This opens the Handbook for this application. It provides "
2196 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2197 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents
))
2198 ->setWhatsThis(whatsThisHelpContents
2199 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2200 "<para>If you want more elaborate introductions to the "
2201 "different features of <emphasis>Dolphin</emphasis> "
2202 "go to the KDE UserBase Wiki.</para>"));
2203 m_helpMenu
->action(KHelpMenu::menuHelpContents
)->setWhatsThis(whatsThisHelpContents
2204 + xi18nc("@info:whatsthis second half of handbook text with link",
2205 "<para>If you want more elaborate introductions to the "
2206 "different features of <emphasis>Dolphin</emphasis> "
2207 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2208 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2210 const QString whatsThisWhatsThis
= xi18nc("@info:whatsthis whatsthis button",
2211 "<para>This is the button that invokes the help feature you are "
2212 "using right now! Click it, then click any component of this "
2213 "application to ask \"What's this?\" about it. The mouse cursor "
2214 "will change appearance if no help is available for a spot.</para>");
2215 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis
))
2216 ->setWhatsThis(whatsThisWhatsThis
2217 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2218 "<para>There are two other ways to get help for this application: The "
2219 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2220 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2221 "article about <emphasis>File Management</emphasis> online."
2222 "</para><para>The \"What's this?\" help is "
2223 "missing in most other windows so don't get too used to this.</para>"));
2224 m_helpMenu
->action(KHelpMenu::menuWhatsThis
)->setWhatsThis(whatsThisWhatsThis
2225 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2226 "<para>There are two other ways to get help: "
2227 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2228 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2229 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2230 "missing in most other windows so don't get too used to this.</para>"));
2232 const QString whatsThisReportBug
= xi18nc("@info:whatsthis","<para>This opens a "
2233 "window that will guide you through reporting errors or flaws "
2234 "in this application or in other KDE software.</para>");
2235 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug
))
2236 ->setWhatsThis(whatsThisReportBug
);
2237 m_helpMenu
->action(KHelpMenu::menuReportBug
)->setWhatsThis(whatsThisReportBug
2238 + xi18nc("@info:whatsthis second half of reportbug text with link",
2239 "<para>High-quality bug reports are much appreciated. To learn "
2240 "how to make your bug report as effective as possible "
2241 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2242 "click here</link>.</para>"));
2244 const QString whatsThisDonate
= xi18nc("@info:whatsthis","<para>This opens a "
2245 "<emphasis>web page</emphasis> where you can donate to "
2246 "support the continued work on this application and many "
2247 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2248 "<para>Donating is the easiest and fastest way to efficiently "
2249 "support KDE and its projects. KDE projects are available for "
2250 "free therefore your donation is needed to cover things that "
2251 "require money like servers, contributor meetings, etc.</para>"
2252 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2253 "organization behind the KDE community.</para>");
2254 actionCollection()->action(KStandardAction::name(KStandardAction::Donate
))
2255 ->setWhatsThis(whatsThisDonate
);
2256 m_helpMenu
->action(KHelpMenu::menuDonate
)->setWhatsThis(whatsThisDonate
);
2258 const QString whatsThisSwitchLanguage
= xi18nc("@info:whatsthis",
2259 "With this you can change the language this application uses."
2260 "<nl/>You can even set secondary languages which will be used "
2261 "if texts are not available in your preferred language.");
2262 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage
))
2263 ->setWhatsThis(whatsThisSwitchLanguage
);
2264 m_helpMenu
->action(KHelpMenu::menuSwitchLanguage
)->setWhatsThis(whatsThisSwitchLanguage
);
2266 const QString whatsThisAboutApp
= xi18nc("@info:whatsthis","This opens a "
2267 "window that informs you about the version, license, "
2268 "used libraries and maintainers of this application.");
2269 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp
))
2270 ->setWhatsThis(whatsThisAboutApp
);
2271 m_helpMenu
->action(KHelpMenu::menuAboutApp
)->setWhatsThis(whatsThisAboutApp
);
2273 const QString whatsThisAboutKDE
= xi18nc("@info:whatsthis","This opens a "
2274 "window with information about <emphasis>KDE</emphasis>. "
2275 "The KDE community are the people behind this free software."
2276 "<nl/>If you like using this application but don't know "
2277 "about KDE or want to see a cute dragon have a look!");
2278 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE
))
2279 ->setWhatsThis(whatsThisAboutKDE
);
2280 m_helpMenu
->action(KHelpMenu::menuAboutKDE
)->setWhatsThis(whatsThisAboutKDE
);
2283 bool DolphinMainWindow::event(QEvent
*event
)
2285 if (event
->type() == QEvent::WhatsThisClicked
) {
2287 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2288 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2290 } else if (event
->type() == QEvent::WindowActivate
) {
2291 updateOpenPreferredSearchToolAction();
2293 return KXmlGuiWindow::event(event
);
2296 bool DolphinMainWindow::eventFilter(QObject
* obj
, QEvent
* event
)
2299 if (event
->type() == QEvent::WhatsThisClicked
) {
2301 QWhatsThisClickedEvent
* whatsThisEvent
= dynamic_cast<QWhatsThisClickedEvent
*>(event
);
2302 QDesktopServices::openUrl(QUrl(whatsThisEvent
->href()));
2308 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2309 KIO::FileUndoManager::UiInterface()
2313 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2317 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job
* job
)
2319 DolphinMainWindow
* mainWin
= qobject_cast
<DolphinMainWindow
*>(parentWidget());
2321 DolphinViewContainer
* container
= mainWin
->activeViewContainer();
2322 container
->showMessage(job
->errorString(), DolphinViewContainer::Error
);
2324 KIO::FileUndoManager::UiInterface::jobError(job
);
2328 bool DolphinMainWindow::isUrlOpen(const QString
& url
)
2330 return m_tabWidget
->isUrlOpen(QUrl::fromUserInput((url
)));