]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Merge branch 'release/20.12'
[dolphin.git] / src / dolphinmainwindow.cpp
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "dolphinmainwindow.h"
10
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
13 #include "global.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnavigatorswidgetaction.h"
18 #include "dolphinnewfilemenu.h"
19 #include "dolphinrecenttabsmenu.h"
20 #include "dolphinurlnavigatorscontroller.h"
21 #include "dolphinviewcontainer.h"
22 #include "dolphintabpage.h"
23 #include "middleclickactioneventfilter.h"
24 #include "panels/folders/folderspanel.h"
25 #include "panels/places/placesitemmodel.h"
26 #include "panels/places/placespanel.h"
27 #include "panels/information/informationpanel.h"
28 #include "panels/terminal/terminalpanel.h"
29 #include "settings/dolphinsettingsdialog.h"
30 #include "statusbar/dolphinstatusbar.h"
31 #include "views/dolphinviewactionhandler.h"
32 #include "views/dolphinremoteencoding.h"
33 #include "views/draganddrophelper.h"
34 #include "views/viewproperties.h"
35 #include "views/dolphinnewfilemenuobserver.h"
36 #include "dolphin_generalsettings.h"
37
38 #include <KActionCollection>
39 #include <KActionMenu>
40 #include <KAuthorized>
41 #include <KConfig>
42 #include <KConfigGui>
43 #include <KDualAction>
44 #include <KFileItemListProperties>
45 #include <KHelpMenu>
46 #include <KIO/CommandLauncherJob>
47 #include <KIO/JobUiDelegate>
48 #include <KIO/OpenFileManagerWindowJob>
49 #include <KIO/OpenUrlJob>
50 #include <KJobWidgets>
51 #include <KLocalizedString>
52 #include <KMessageBox>
53 #include <KNS3/KMoreToolsMenuFactory>
54 #include <KProtocolInfo>
55 #include <KProtocolManager>
56 #include <KShell>
57 #include <KStandardAction>
58 #include <KStartupInfo>
59 #include <KSycoca>
60 #include <KToggleAction>
61 #include <KToolBar>
62 #include <KToolBarPopupAction>
63 #include <KToolInvocation>
64 #include <KUrlComboBox>
65 #include <KUrlNavigator>
66 #include <KWindowSystem>
67
68 #include <QApplication>
69 #include <QClipboard>
70 #include <QCloseEvent>
71 #include <QDesktopServices>
72 #include <QDialog>
73 #include <QFileInfo>
74 #include <QLineEdit>
75 #include <QMenuBar>
76 #include <QPushButton>
77 #include <QShowEvent>
78 #include <QStandardPaths>
79 #include <QTimer>
80 #include <QToolButton>
81 #include <QWhatsThisClickedEvent>
82
83 namespace {
84 // Used for GeneralSettings::version() to determine whether
85 // an updated version of Dolphin is running.
86 const int CurrentDolphinVersion = 200;
87 // The maximum number of entries in the back/forward popup menu
88 const int MaxNumberOfNavigationentries = 12;
89 // The maximum number of "Activate Tab" shortcuts
90 const int MaxActivateTabShortcuts = 9;
91 }
92
93 DolphinMainWindow::DolphinMainWindow() :
94 KXmlGuiWindow(nullptr),
95 m_newFileMenu(nullptr),
96 m_helpMenu(nullptr),
97 m_tabWidget(nullptr),
98 m_activeViewContainer(nullptr),
99 m_actionHandler(nullptr),
100 m_remoteEncoding(nullptr),
101 m_settingsDialog(),
102 m_bookmarkHandler(nullptr),
103 m_controlButton(nullptr),
104 m_updateToolBarTimer(nullptr),
105 m_lastHandleUrlOpenJob(nullptr),
106 m_terminalPanel(nullptr),
107 m_placesPanel(nullptr),
108 m_tearDownFromPlacesRequested(false),
109 m_backAction(nullptr),
110 m_forwardAction(nullptr)
111 {
112 Q_INIT_RESOURCE(dolphin);
113
114 new MainWindowAdaptor(this);
115
116 #ifndef Q_OS_WIN
117 setWindowFlags(Qt::WindowContextHelpButtonHint);
118 #endif
119 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
120 setObjectName(QStringLiteral("Dolphin#"));
121
122 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage,
123 this, &DolphinMainWindow::showErrorMessage);
124
125 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
126 undoManager->setUiInterface(new UndoUiInterface());
127
128 connect(undoManager, QOverload<bool>::of(&KIO::FileUndoManager::undoAvailable),
129 this, &DolphinMainWindow::slotUndoAvailable);
130 connect(undoManager, &KIO::FileUndoManager::undoTextChanged,
131 this, &DolphinMainWindow::slotUndoTextChanged);
132 connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted,
133 this, &DolphinMainWindow::clearStatusBar);
134 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished,
135 this, &DolphinMainWindow::showCommand);
136
137 GeneralSettings* generalSettings = GeneralSettings::self();
138 const bool firstRun = (generalSettings->version() < 200);
139 if (firstRun) {
140 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
141 }
142
143 setAcceptDrops(true);
144
145 auto *navigatorsWidgetAction = new DolphinNavigatorsWidgetAction(this);
146 actionCollection()->addAction(QStringLiteral("url_navigators"), navigatorsWidgetAction);
147 m_tabWidget = new DolphinTabWidget(navigatorsWidgetAction, this);
148 m_tabWidget->setObjectName("tabWidget");
149 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged,
150 this, &DolphinMainWindow::activeViewChanged);
151 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged,
152 this, &DolphinMainWindow::tabCountChanged);
153 connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged,
154 this, &DolphinMainWindow::updateWindowTitle);
155 setCentralWidget(m_tabWidget);
156
157 setupActions();
158
159 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
160 connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar);
161 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
162
163 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
164 connect(this, &DolphinMainWindow::urlChanged,
165 m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
166
167 setupDockWidgets();
168
169 setupGUI(Keys | Save | Create | ToolBar);
170 stateChanged(QStringLiteral("new_file"));
171
172 QClipboard* clipboard = QApplication::clipboard();
173 connect(clipboard, &QClipboard::dataChanged,
174 this, &DolphinMainWindow::updatePasteAction);
175
176 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
177 showFilterBarAction->setChecked(generalSettings->filterBar());
178
179 if (firstRun) {
180 menuBar()->setVisible(false);
181 // Assure a proper default size if Dolphin runs the first time
182 resize(750, 500);
183 }
184
185 const bool showMenu = !menuBar()->isHidden();
186 QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
187 showMenuBarAction->setChecked(showMenu); // workaround for bug #171080
188 if (!showMenu) {
189 createControlButton();
190 }
191
192 updateAllowedToolbarAreas();
193
194 // enable middle-click on back/forward/up to open in a new tab
195 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
196 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked);
197 toolBar()->installEventFilter(middleClickEventFilter);
198
199 setupWhatsThis();
200
201 connect(KSycoca::self(), QOverload<>::of(&KSycoca::databaseChanged), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
202
203 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
204 }
205
206 DolphinMainWindow::~DolphinMainWindow()
207 {
208 }
209
210 QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
211 {
212 QVector<DolphinViewContainer*> viewContainers;
213
214 for (int i = 0; i < m_tabWidget->count(); ++i) {
215 DolphinTabPage *tabPage = m_tabWidget->tabPageAt(i);
216
217 viewContainers << tabPage->primaryViewContainer();
218 if (tabPage->splitViewEnabled()) {
219 viewContainers << tabPage->secondaryViewContainer();
220 }
221 }
222 return viewContainers;
223 }
224
225 void DolphinMainWindow::setViewsWithInvalidPathsToHome()
226 {
227 const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
228 for (DolphinViewContainer *viewContainer : theViewContainers) {
229
230 // Only consider local dirs, not remote locations and abstract protocols
231 if (viewContainer->url().isLocalFile()) {
232 if (!QFileInfo::exists(viewContainer->url().toLocalFile())) {
233 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
234 }
235 }
236 }
237 }
238
239 void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs, bool splitView)
240 {
241 m_tabWidget->openDirectories(dirs, splitView);
242 }
243
244 void DolphinMainWindow::openDirectories(const QStringList& dirs, bool splitView)
245 {
246 openDirectories(QUrl::fromStringList(dirs), splitView);
247 }
248
249 void DolphinMainWindow::openFiles(const QList<QUrl>& files, bool splitView)
250 {
251 m_tabWidget->openFiles(files, splitView);
252 }
253
254 bool DolphinMainWindow::isFoldersPanelEnabled() const
255 {
256 return actionCollection()->action(QStringLiteral("show_folders_panel"))->isChecked();
257 }
258
259 bool DolphinMainWindow::isInformationPanelEnabled() const
260 {
261 return actionCollection()->action(QStringLiteral("show_information_panel"))->isChecked();
262 }
263
264 void DolphinMainWindow::openFiles(const QStringList& files, bool splitView)
265 {
266 openFiles(QUrl::fromStringList(files), splitView);
267 }
268
269 void DolphinMainWindow::activateWindow()
270 {
271 window()->setAttribute(Qt::WA_NativeWindow, true);
272 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
273 KWindowSystem::activateWindow(window()->effectiveWinId());
274 }
275
276 void DolphinMainWindow::showCommand(CommandType command)
277 {
278 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
279 switch (command) {
280 case KIO::FileUndoManager::Copy:
281 statusBar->setText(i18nc("@info:status", "Successfully copied."));
282 break;
283 case KIO::FileUndoManager::Move:
284 statusBar->setText(i18nc("@info:status", "Successfully moved."));
285 break;
286 case KIO::FileUndoManager::Link:
287 statusBar->setText(i18nc("@info:status", "Successfully linked."));
288 break;
289 case KIO::FileUndoManager::Trash:
290 statusBar->setText(i18nc("@info:status", "Successfully moved to trash."));
291 break;
292 case KIO::FileUndoManager::Rename:
293 statusBar->setText(i18nc("@info:status", "Successfully renamed."));
294 break;
295
296 case KIO::FileUndoManager::Mkdir:
297 statusBar->setText(i18nc("@info:status", "Created folder."));
298 break;
299
300 default:
301 break;
302 }
303 }
304
305 void DolphinMainWindow::pasteIntoFolder()
306 {
307 m_activeViewContainer->view()->pasteIntoFolder();
308 }
309
310 void DolphinMainWindow::changeUrl(const QUrl &url)
311 {
312 if (!KProtocolManager::supportsListing(url)) {
313 // The URL navigator only checks for validity, not
314 // if the URL can be listed. An error message is
315 // shown due to DolphinViewContainer::restoreView().
316 return;
317 }
318
319 m_activeViewContainer->setUrl(url);
320 updateFileAndEditActions();
321 updatePasteAction();
322 updateViewActions();
323 updateGoActions();
324
325 Q_EMIT urlChanged(url);
326 }
327
328 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url)
329 {
330 if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) {
331 m_placesPanel->proceedWithTearDown();
332 m_tearDownFromPlacesRequested = false;
333 }
334
335 m_activeViewContainer->setAutoGrabFocus(false);
336 changeUrl(url);
337 m_activeViewContainer->setAutoGrabFocus(true);
338 }
339
340 void DolphinMainWindow::slotEditableStateChanged(bool editable)
341 {
342 KToggleAction* editableLocationAction =
343 static_cast<KToggleAction*>(actionCollection()->action(QStringLiteral("editable_location")));
344 editableLocationAction->setChecked(editable);
345 }
346
347 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
348 {
349 updateFileAndEditActions();
350
351 const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
352
353 QAction* compareFilesAction = actionCollection()->action(QStringLiteral("compare_files"));
354 if (selectedUrlsCount == 2) {
355 compareFilesAction->setEnabled(isKompareInstalled());
356 } else {
357 compareFilesAction->setEnabled(false);
358 }
359
360 Q_EMIT selectionChanged(selection);
361 }
362
363 void DolphinMainWindow::updateHistory()
364 {
365 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
366 const int index = urlNavigator->historyIndex();
367
368 QAction* backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back));
369 if (backAction) {
370 backAction->setToolTip(i18nc("@info", "Go back"));
371 backAction->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
372 backAction->setEnabled(index < urlNavigator->historySize() - 1);
373 }
374
375 QAction* forwardAction = actionCollection()->action(KStandardAction::name(KStandardAction::Forward));
376 if (forwardAction) {
377 forwardAction->setToolTip(i18nc("@info", "Go forward"));
378 forwardAction->setWhatsThis(xi18nc("@info:whatsthis go forward",
379 "This undoes a <interface>Go|Back</interface> action."));
380 forwardAction->setEnabled(index > 0);
381 }
382 }
383
384 void DolphinMainWindow::updateFilterBarAction(bool show)
385 {
386 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
387 showFilterBarAction->setChecked(show);
388 }
389
390 void DolphinMainWindow::openNewMainWindow()
391 {
392 Dolphin::openNewWindow({m_activeViewContainer->url()}, this);
393 }
394
395 void DolphinMainWindow::openNewActivatedTab()
396 {
397 m_tabWidget->openNewActivatedTab();
398 }
399
400 void DolphinMainWindow::addToPlaces()
401 {
402 QUrl url;
403 QString name;
404
405 // If nothing is selected, act on the current dir
406 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
407 url = m_activeViewContainer->url();
408 name = m_activeViewContainer->placesText();
409 } else {
410 const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first();
411 url = dirToAdd.url();
412 name = dirToAdd.name();
413 }
414 if (url.isValid()) {
415 PlacesItemModel model;
416 QString icon;
417 if (m_activeViewContainer->isSearchModeEnabled()) {
418 icon = QStringLiteral("folder-saved-search-symbolic");
419 } else {
420 icon = KIO::iconNameForUrl(url);
421 }
422 model.createPlacesItem(name, url, icon);
423 }
424 }
425
426 void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement)
427 {
428 m_tabWidget->openNewTab(url, QUrl(), tabPlacement);
429 }
430
431 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl& url)
432 {
433 m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterCurrentTab);
434 }
435
436 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl& url)
437 {
438 m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterLastTab);
439 }
440
441 void DolphinMainWindow::openInNewTab()
442 {
443 const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
444 bool tabCreated = false;
445
446 for (const KFileItem& item : list) {
447 const QUrl& url = DolphinView::openItemAsFolderUrl(item);
448 if (!url.isEmpty()) {
449 openNewTabAfterCurrentTab(url);
450 tabCreated = true;
451 }
452 }
453
454 // if no new tab has been created from the selection
455 // open the current directory in a new tab
456 if (!tabCreated) {
457 openNewTabAfterCurrentTab(m_activeViewContainer->url());
458 }
459 }
460
461 void DolphinMainWindow::openInNewWindow()
462 {
463 QUrl newWindowUrl;
464
465 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
466 if (list.isEmpty()) {
467 newWindowUrl = m_activeViewContainer->url();
468 } else if (list.count() == 1) {
469 const KFileItem& item = list.first();
470 newWindowUrl = DolphinView::openItemAsFolderUrl(item);
471 }
472
473 if (!newWindowUrl.isEmpty()) {
474 Dolphin::openNewWindow({newWindowUrl}, this);
475 }
476 }
477
478 void DolphinMainWindow::showTarget()
479 {
480 const auto link = m_activeViewContainer->view()->selectedItems().at(0);
481 const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
482 auto linkDestination = link.linkDest();
483 if (QFileInfo(linkDestination).isRelative()) {
484 linkDestination = linkLocationDir.filePath(linkDestination);
485 }
486 if (QFileInfo::exists(linkDestination)) {
487 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
488 } else {
489 m_activeViewContainer->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination),
490 DolphinViewContainer::Warning);
491 }
492 }
493
494 void DolphinMainWindow::showEvent(QShowEvent* event)
495 {
496 KXmlGuiWindow::showEvent(event);
497
498 if (!event->spontaneous()) {
499 m_activeViewContainer->view()->setFocus();
500 }
501 }
502
503 void DolphinMainWindow::closeEvent(QCloseEvent* event)
504 {
505 // Find out if Dolphin is closed directly by the user or
506 // by the session manager because the session is closed
507 bool closedByUser = true;
508 if (qApp->isSavingSession()) {
509 closedByUser = false;
510 }
511
512 if (m_tabWidget->count() > 1
513 && GeneralSettings::confirmClosingMultipleTabs()
514 && !GeneralSettings::rememberOpenedTabs()
515 && closedByUser) {
516 // Ask the user if he really wants to quit and close all tabs.
517 // Open a confirmation dialog with 3 buttons:
518 // QDialogButtonBox::Yes -> Quit
519 // QDialogButtonBox::No -> Close only the current tab
520 // QDialogButtonBox::Cancel -> do nothing
521 QDialog *dialog = new QDialog(this, Qt::Dialog);
522 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
523 dialog->setModal(true);
524 QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
525 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
526 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
527 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
528 buttons->button(QDialogButtonBox::Yes)->setDefault(true);
529
530 bool doNotAskAgainCheckboxResult = false;
531
532 const auto result = KMessageBox::createKMessageBox(dialog,
533 buttons,
534 QMessageBox::Warning,
535 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
536 QStringList(),
537 i18n("Do not ask again"),
538 &doNotAskAgainCheckboxResult,
539 KMessageBox::Notify);
540
541 if (doNotAskAgainCheckboxResult) {
542 GeneralSettings::setConfirmClosingMultipleTabs(false);
543 }
544
545 switch (result) {
546 case QDialogButtonBox::Yes:
547 // Quit
548 break;
549 case QDialogButtonBox::No:
550 // Close only the current tab
551 m_tabWidget->closeTab();
552 Q_FALLTHROUGH();
553 default:
554 event->ignore();
555 return;
556 }
557 }
558
559 if (m_terminalPanel && m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) {
560 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
561 // Open a confirmation dialog with 3 buttons:
562 // QDialogButtonBox::Yes -> Quit
563 // QDialogButtonBox::No -> Show Terminal Panel
564 // QDialogButtonBox::Cancel -> do nothing
565 QDialog *dialog = new QDialog(this, Qt::Dialog);
566 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
567 dialog->setModal(true);
568 auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel;
569 if (!m_terminalPanel->isVisible()) {
570 standardButtons |= QDialogButtonBox::No;
571 }
572 QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons);
573 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit());
574 if (!m_terminalPanel->isVisible()) {
575 KGuiItem::assign(
576 buttons->button(QDialogButtonBox::No),
577 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
578 }
579 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
580
581 bool doNotAskAgainCheckboxResult = false;
582
583 const auto result = KMessageBox::createKMessageBox(
584 dialog,
585 buttons,
586 QMessageBox::Warning,
587 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()),
588 QStringList(),
589 i18n("Do not ask again"),
590 &doNotAskAgainCheckboxResult,
591 KMessageBox::Dangerous);
592
593 if (doNotAskAgainCheckboxResult) {
594 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
595 }
596
597 switch (result) {
598 case QDialogButtonBox::Yes:
599 // Quit
600 break;
601 case QDialogButtonBox::No:
602 actionCollection()->action("show_terminal_panel")->trigger();
603 // Do not quit, ignore quit event
604 Q_FALLTHROUGH();
605 default:
606 event->ignore();
607 return;
608 }
609 }
610
611 if (GeneralSettings::rememberOpenedTabs()) {
612 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
613 KConfig *config = KConfigGui::sessionConfig();
614 saveGlobalProperties(config);
615 savePropertiesInternal(config, 1);
616 config->sync();
617 }
618
619 GeneralSettings::setVersion(CurrentDolphinVersion);
620 GeneralSettings::self()->save();
621
622 KXmlGuiWindow::closeEvent(event);
623 }
624
625 void DolphinMainWindow::saveProperties(KConfigGroup& group)
626 {
627 m_tabWidget->saveProperties(group);
628 }
629
630 void DolphinMainWindow::readProperties(const KConfigGroup& group)
631 {
632 m_tabWidget->readProperties(group);
633 }
634
635 void DolphinMainWindow::updateNewMenu()
636 {
637 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
638 m_newFileMenu->checkUpToDate();
639 m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
640 }
641
642 void DolphinMainWindow::createDirectory()
643 {
644 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
645 m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
646 m_newFileMenu->createDirectory();
647 }
648
649 void DolphinMainWindow::quit()
650 {
651 close();
652 }
653
654 void DolphinMainWindow::showErrorMessage(const QString& message)
655 {
656 m_activeViewContainer->showMessage(message, DolphinViewContainer::Error);
657 }
658
659 void DolphinMainWindow::slotUndoAvailable(bool available)
660 {
661 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
662 if (undoAction) {
663 undoAction->setEnabled(available);
664 }
665 }
666
667 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
668 {
669 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
670 if (undoAction) {
671 undoAction->setText(text);
672 }
673 }
674
675 void DolphinMainWindow::undo()
676 {
677 clearStatusBar();
678 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
679 KIO::FileUndoManager::self()->undo();
680 }
681
682 void DolphinMainWindow::cut()
683 {
684 m_activeViewContainer->view()->cutSelectedItemsToClipboard();
685 }
686
687 void DolphinMainWindow::copy()
688 {
689 m_activeViewContainer->view()->copySelectedItemsToClipboard();
690 }
691
692 void DolphinMainWindow::paste()
693 {
694 m_activeViewContainer->view()->paste();
695 }
696
697 void DolphinMainWindow::find()
698 {
699 m_activeViewContainer->setSearchModeEnabled(true);
700 }
701
702 void DolphinMainWindow::updateSearchAction()
703 {
704 QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
705 toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled());
706 }
707
708 void DolphinMainWindow::updatePasteAction()
709 {
710 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
711 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
712 pasteAction->setEnabled(pasteInfo.first);
713 pasteAction->setText(pasteInfo.second);
714 }
715
716 void DolphinMainWindow::slotDirectoryLoadingCompleted()
717 {
718 updatePasteAction();
719 }
720
721 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
722 {
723 if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) {
724 goBackInNewTab();
725 } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) {
726 goForwardInNewTab();
727 } else if (action == actionCollection()->action(QStringLiteral("go_up"))) {
728 goUpInNewTab();
729 } else if (action == actionCollection()->action(QStringLiteral("go_home"))) {
730 goHomeInNewTab();
731 }
732 }
733
734 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
735 {
736 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
737 int entries = 0;
738 m_backAction->menu()->clear();
739 for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) {
740 QAction* action = new QAction(urlNavigator->locationUrl(i).toString(QUrl::PreferLocalFile), m_backAction->menu());
741 action->setData(i);
742 m_backAction->menu()->addAction(action);
743 }
744 }
745
746 void DolphinMainWindow::slotGoBack(QAction* action)
747 {
748 int gotoIndex = action->data().value<int>();
749 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
750 for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) {
751 goBack();
752 }
753 }
754
755 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction* action)
756 {
757 if (action) {
758 const KUrlNavigator *urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
759 openNewTabAfterCurrentTab(urlNavigator->locationUrl(action->data().value<int>()));
760 }
761 }
762
763 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
764 {
765 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
766 int entries = 0;
767 m_forwardAction->menu()->clear();
768 for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) {
769 QAction* action = new QAction(urlNavigator->locationUrl(i).toString(QUrl::PreferLocalFile), m_forwardAction->menu());
770 action->setData(i);
771 m_forwardAction->menu()->addAction(action);
772 }
773 }
774
775 void DolphinMainWindow::slotGoForward(QAction* action)
776 {
777 int gotoIndex = action->data().value<int>();
778 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
779 for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) {
780 goForward();
781 }
782 }
783
784 void DolphinMainWindow::selectAll()
785 {
786 clearStatusBar();
787
788 // if the URL navigator is editable and focused, select the whole
789 // URL instead of all items of the view
790
791 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
792 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
793 const bool selectUrl = urlNavigator->isUrlEditable() &&
794 lineEdit->hasFocus();
795 if (selectUrl) {
796 lineEdit->selectAll();
797 } else {
798 m_activeViewContainer->view()->selectAll();
799 }
800 }
801
802 void DolphinMainWindow::invertSelection()
803 {
804 clearStatusBar();
805 m_activeViewContainer->view()->invertSelection();
806 }
807
808 void DolphinMainWindow::toggleSplitView()
809 {
810 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
811 tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled());
812
813 updateViewActions();
814 }
815
816 void DolphinMainWindow::toggleSplitStash()
817 {
818 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
819 tabPage->setSplitViewEnabled(false);
820 tabPage->setSplitViewEnabled(true, QUrl("stash:/"));
821 }
822
823 void DolphinMainWindow::reloadView()
824 {
825 clearStatusBar();
826 m_activeViewContainer->reload();
827 m_activeViewContainer->statusBar()->updateSpaceInfo();
828 }
829
830 void DolphinMainWindow::stopLoading()
831 {
832 m_activeViewContainer->view()->stopLoading();
833 }
834
835 void DolphinMainWindow::enableStopAction()
836 {
837 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
838 }
839
840 void DolphinMainWindow::disableStopAction()
841 {
842 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
843 }
844
845 void DolphinMainWindow::showFilterBar()
846 {
847 m_activeViewContainer->setFilterBarVisible(true);
848 }
849
850 void DolphinMainWindow::toggleEditLocation()
851 {
852 clearStatusBar();
853
854 QAction* action = actionCollection()->action(QStringLiteral("editable_location"));
855 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
856 urlNavigator->setUrlEditable(action->isChecked());
857 }
858
859 void DolphinMainWindow::replaceLocation()
860 {
861 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
862 QLineEdit* lineEdit = navigator->editor()->lineEdit();
863
864 // If the text field currently has focus and everything is selected,
865 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
866 if (navigator->isUrlEditable()
867 && lineEdit->hasFocus()
868 && lineEdit->selectedText() == lineEdit->text() ) {
869 navigator->setUrlEditable(false);
870 } else {
871 navigator->setUrlEditable(true);
872 navigator->setFocus();
873 lineEdit->selectAll();
874 }
875 }
876
877 void DolphinMainWindow::togglePanelLockState()
878 {
879 const bool newLockState = !GeneralSettings::lockPanels();
880 const auto childrenObjects = children();
881 for (QObject* child : childrenObjects) {
882 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
883 if (dock) {
884 dock->setLocked(newLockState);
885 }
886 }
887
888 GeneralSettings::setLockPanels(newLockState);
889 }
890
891 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
892 {
893 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
894 m_activeViewContainer->view()->setFocus();
895 }
896 }
897
898 void DolphinMainWindow::goBack()
899 {
900 DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternalWithHistory();
901 urlNavigator->goBack();
902
903 if (urlNavigator->locationState().isEmpty()) {
904 // An empty location state indicates a redirection URL,
905 // which must be skipped too
906 urlNavigator->goBack();
907 }
908 }
909
910 void DolphinMainWindow::goForward()
911 {
912 m_activeViewContainer->urlNavigatorInternalWithHistory()->goForward();
913 }
914
915 void DolphinMainWindow::goUp()
916 {
917 m_activeViewContainer->urlNavigatorInternalWithHistory()->goUp();
918 }
919
920 void DolphinMainWindow::goHome()
921 {
922 m_activeViewContainer->urlNavigatorInternalWithHistory()->goHome();
923 }
924
925 void DolphinMainWindow::goBackInNewTab()
926 {
927 const KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
928 const int index = urlNavigator->historyIndex() + 1;
929 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
930 }
931
932 void DolphinMainWindow::goForwardInNewTab()
933 {
934 const KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternalWithHistory();
935 const int index = urlNavigator->historyIndex() - 1;
936 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
937 }
938
939 void DolphinMainWindow::goUpInNewTab()
940 {
941 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
942 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl));
943 }
944
945 void DolphinMainWindow::goHomeInNewTab()
946 {
947 openNewTabAfterCurrentTab(Dolphin::homeUrl());
948 }
949
950 void DolphinMainWindow::compareFiles()
951 {
952 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
953 if (items.count() != 2) {
954 // The action is disabled in this case, but it could have been triggered
955 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
956 return;
957 }
958
959 QUrl urlA = items.at(0).url();
960 QUrl urlB = items.at(1).url();
961
962 QString command(QStringLiteral("kompare -c \""));
963 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
964 command.append("\" \"");
965 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
966 command.append('\"');
967
968 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this);
969 job->setDesktopName(QStringLiteral("org.kde.kompare"));
970 job->start();
971 }
972
973 void DolphinMainWindow::toggleShowMenuBar()
974 {
975 const bool visible = menuBar()->isVisible();
976 menuBar()->setVisible(!visible);
977 if (visible) {
978 createControlButton();
979 } else {
980 deleteControlButton();
981 }
982 }
983
984 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
985 {
986 m_searchTools.clear();
987 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
988 &m_searchTools, { "files-find" }, m_activeViewContainer->url()
989 );
990 QList<QAction*> actions = m_searchTools.actions();
991 if (actions.isEmpty()) {
992 return nullptr;
993 }
994 QAction* action = actions.first();
995 if (action->isSeparator()) {
996 return nullptr;
997 }
998 return action;
999 }
1000
1001 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1002 {
1003 QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1004 if (!openPreferredSearchTool) {
1005 return;
1006 }
1007 QPointer<QAction> tool = preferredSearchTool();
1008 if (tool) {
1009 openPreferredSearchTool->setVisible(true);
1010 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
1011 openPreferredSearchTool->setIcon(tool->icon());
1012 } else {
1013 openPreferredSearchTool->setVisible(false);
1014 // still visible in Shortcuts configuration window
1015 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1016 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1017 }
1018 }
1019
1020 void DolphinMainWindow::openPreferredSearchTool()
1021 {
1022 QPointer<QAction> tool = preferredSearchTool();
1023 if (tool) {
1024 tool->trigger();
1025 }
1026 }
1027
1028 void DolphinMainWindow::openTerminal()
1029 {
1030 const QUrl url = m_activeViewContainer->url();
1031
1032 if (url.isLocalFile()) {
1033 KToolInvocation::invokeTerminal(QString(), url.toLocalFile());
1034 return;
1035 }
1036
1037 // Not a local file, with protocol Class ":local", try stat'ing
1038 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
1039 KIO::StatJob *job = KIO::mostLocalUrl(url);
1040 KJobWidgets::setWindow(job, this);
1041 connect(job, &KJob::result, this, [job]() {
1042 QUrl statUrl;
1043 if (!job->error()) {
1044 statUrl = job->mostLocalUrl();
1045 }
1046
1047 KToolInvocation::invokeTerminal(QString(), statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
1048 });
1049
1050 return;
1051 }
1052
1053 // Nothing worked, just use $HOME
1054 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1055 }
1056
1057 void DolphinMainWindow::editSettings()
1058 {
1059 if (!m_settingsDialog) {
1060 DolphinViewContainer* container = activeViewContainer();
1061 container->view()->writeSettings();
1062
1063 const QUrl url = container->url();
1064 DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
1065 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
1066 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged,
1067 &DolphinUrlNavigatorsController::slotReadSettings);
1068 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1069 settingsDialog->show();
1070 m_settingsDialog = settingsDialog;
1071 } else {
1072 m_settingsDialog.data()->raise();
1073 }
1074 }
1075
1076 void DolphinMainWindow::handleUrl(const QUrl& url)
1077 {
1078 delete m_lastHandleUrlOpenJob;
1079 m_lastHandleUrlOpenJob = nullptr;
1080
1081 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1082 activeViewContainer()->setUrl(url);
1083 } else {
1084 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
1085 m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1086 m_lastHandleUrlOpenJob->setRunExecutables(true);
1087
1088 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this,
1089 [this, url](const QString &mimetype) {
1090 if (mimetype == QLatin1String("inode/directory")) {
1091 // If it's a dir, we'll take it from here
1092 m_lastHandleUrlOpenJob->kill();
1093 m_lastHandleUrlOpenJob = nullptr;
1094 activeViewContainer()->setUrl(url);
1095 }
1096 });
1097
1098 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
1099 m_lastHandleUrlOpenJob = nullptr;
1100 });
1101
1102 m_lastHandleUrlOpenJob->start();
1103 }
1104 }
1105
1106 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1107 {
1108 // trash:/ is writable but we don't want to create new items in it.
1109 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1110 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
1111 }
1112
1113 void DolphinMainWindow::openContextMenu(const QPoint& pos,
1114 const KFileItem& item,
1115 const QUrl& url,
1116 const QList<QAction*>& customActions)
1117 {
1118 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
1119 contextMenu.data()->setCustomActions(customActions);
1120 const DolphinContextMenu::Command command = contextMenu.data()->open();
1121
1122 switch (command) {
1123 case DolphinContextMenu::OpenParentFolder:
1124 changeUrl(KIO::upUrl(item.url()));
1125 m_activeViewContainer->view()->markUrlsAsSelected({item.url()});
1126 m_activeViewContainer->view()->markUrlAsCurrent(item.url());
1127 break;
1128
1129 case DolphinContextMenu::OpenParentFolderInNewWindow:
1130 Dolphin::openNewWindow({item.url()}, this, Dolphin::OpenNewWindowFlag::Select);
1131 break;
1132
1133 case DolphinContextMenu::OpenParentFolderInNewTab:
1134 openNewTabAfterLastTab(KIO::upUrl(item.url()));
1135 break;
1136
1137 case DolphinContextMenu::None:
1138 default:
1139 break;
1140 }
1141
1142 // Delete the menu, unless it has been deleted in its own nested event loop already.
1143 if (contextMenu) {
1144 contextMenu->deleteLater();
1145 }
1146 }
1147
1148 void DolphinMainWindow::updateControlMenu()
1149 {
1150 QMenu* menu = qobject_cast<QMenu*>(sender());
1151 Q_ASSERT(menu);
1152
1153 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1154 // because 'menu' is their parent.
1155 menu->clear();
1156
1157 KActionCollection* ac = actionCollection();
1158
1159 menu->addMenu(m_newFileMenu->menu());
1160 addActionToMenu(ac->action(QStringLiteral("file_new")), menu);
1161 addActionToMenu(ac->action(QStringLiteral("new_tab")), menu);
1162 addActionToMenu(ac->action(QStringLiteral("closed_tabs")), menu);
1163
1164 menu->addSeparator();
1165
1166 // Add "Edit" actions
1167 bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
1168 addActionToMenu(ac->action(QString("copy_location")), menu) |
1169 addActionToMenu(ac->action(QStringLiteral("copy_to_inactive_split_view")), menu) |
1170 addActionToMenu(ac->action(QStringLiteral("move_to_inactive_split_view")), menu) |
1171 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::SelectAll)), menu) |
1172 addActionToMenu(ac->action(QStringLiteral("invert_selection")), menu);
1173
1174 if (added) {
1175 menu->addSeparator();
1176 }
1177
1178 // Add "View" actions
1179 if (!GeneralSettings::showZoomSlider()) {
1180 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu);
1181 addActionToMenu(ac->action(QStringLiteral("view_zoom_reset")), menu);
1182 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu);
1183 menu->addSeparator();
1184 }
1185
1186 added = addActionToMenu(ac->action(QStringLiteral("show_preview")), menu) |
1187 addActionToMenu(ac->action(QStringLiteral("show_in_groups")), menu) |
1188 addActionToMenu(ac->action(QStringLiteral("show_hidden_files")), menu) |
1189 addActionToMenu(ac->action(QStringLiteral("additional_info")), menu) |
1190 addActionToMenu(ac->action(QStringLiteral("view_properties")), menu);
1191
1192 if (added) {
1193 menu->addSeparator();
1194 }
1195
1196 // Add a curated assortment of items from the "Tools" menu
1197 addActionToMenu(ac->action(QStringLiteral("show_filter_bar")), menu);
1198 addActionToMenu(ac->action(QStringLiteral("open_preferred_search_tool")), menu);
1199 addActionToMenu(ac->action(QStringLiteral("open_terminal")), menu);
1200
1201 menu->addSeparator();
1202
1203 // Add "Show Panels" menu
1204 addActionToMenu(ac->action(QStringLiteral("panels")), menu);
1205
1206 // Add "Settings" menu entries
1207 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::KeyBindings)), menu);
1208 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)), menu);
1209 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Preferences)), menu);
1210 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu);
1211
1212 // Add "Help" menu
1213 auto helpMenu = m_helpMenu->menu();
1214 helpMenu->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1215 menu->addMenu(helpMenu);
1216 }
1217
1218 void DolphinMainWindow::updateToolBar()
1219 {
1220 if (!menuBar()->isVisible()) {
1221 createControlButton();
1222 }
1223 }
1224
1225 void DolphinMainWindow::slotControlButtonDeleted()
1226 {
1227 m_controlButton = nullptr;
1228 m_updateToolBarTimer->start();
1229 }
1230
1231 void DolphinMainWindow::slotPlaceActivated(const QUrl& url)
1232 {
1233 DolphinViewContainer* view = activeViewContainer();
1234
1235 if (view->url() == url) {
1236 // We can end up here if the user clicked a device in the Places Panel
1237 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1238 reloadView();
1239 } else {
1240 changeUrl(url);
1241 }
1242 }
1243
1244 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1245 {
1246 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1247 }
1248
1249 void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
1250 {
1251 DolphinViewContainer* oldViewContainer = m_activeViewContainer;
1252 Q_ASSERT(viewContainer);
1253
1254 m_activeViewContainer = viewContainer;
1255
1256 if (oldViewContainer) {
1257 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
1258 toggleSearchAction->disconnect(oldViewContainer);
1259
1260 // Disconnect all signals between the old view container (container,
1261 // view and url navigator) and main window.
1262 oldViewContainer->disconnect(this);
1263 oldViewContainer->view()->disconnect(this);
1264 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
1265 (actionCollection()->action(QStringLiteral("url_navigators")));
1266 navigators->primaryUrlNavigator()->disconnect(this);
1267 if (auto secondaryUrlNavigator = navigators->secondaryUrlNavigator()) {
1268 secondaryUrlNavigator->disconnect(this);
1269 }
1270
1271 // except the requestItemInfo so that on hover the information panel can still be updated
1272 connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
1273 this, &DolphinMainWindow::requestItemInfo);
1274 }
1275
1276 connectViewSignals(viewContainer);
1277
1278 m_actionHandler->setCurrentView(viewContainer->view());
1279
1280 updateHistory();
1281 updateFileAndEditActions();
1282 updatePasteAction();
1283 updateViewActions();
1284 updateGoActions();
1285 updateSearchAction();
1286
1287 const QUrl url = viewContainer->url();
1288 Q_EMIT urlChanged(url);
1289 }
1290
1291 void DolphinMainWindow::tabCountChanged(int count)
1292 {
1293 const bool enableTabActions = (count > 1);
1294 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1295 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions);
1296 }
1297 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions);
1298 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1299 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1300 }
1301
1302 void DolphinMainWindow::updateWindowTitle()
1303 {
1304 const QString newTitle = m_activeViewContainer->captionWindowTitle();
1305 if (windowTitle() != newTitle) {
1306 setWindowTitle(newTitle);
1307 }
1308 }
1309
1310 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
1311 {
1312 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1313 setViewsToHomeIfMountPathOpen(mountPath);
1314 });
1315
1316 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1317 m_tearDownFromPlacesRequested = true;
1318 m_terminalPanel->goHome();
1319 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1320 } else {
1321 m_placesPanel->proceedWithTearDown();
1322 }
1323 }
1324
1325 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
1326 {
1327 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1328 setViewsToHomeIfMountPathOpen(mountPath);
1329 });
1330
1331 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1332 m_tearDownFromPlacesRequested = false;
1333 m_terminalPanel->goHome();
1334 }
1335 }
1336
1337 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString& mountPath)
1338 {
1339 const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
1340 for (DolphinViewContainer *viewContainer : theViewContainers) {
1341 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
1342 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1343 }
1344 }
1345 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1346 }
1347
1348 void DolphinMainWindow::setupActions()
1349 {
1350 // setup 'File' menu
1351 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
1352 QMenu* menu = m_newFileMenu->menu();
1353 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1354 menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1355 m_newFileMenu->setDelayed(false);
1356 connect(menu, &QMenu::aboutToShow,
1357 this, &DolphinMainWindow::updateNewMenu);
1358
1359 QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1360 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1361 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1362 newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1363 "window just like this one with the current location and view."
1364 "<nl/>You can drag and drop items between windows."));
1365 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1366
1367 QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1368 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1369 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1370 newTab->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1371 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1372 "A tab is an additional view within this window. "
1373 "You can drag and drop items between tabs."));
1374 actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
1375 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1376
1377 QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1378 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1379 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1380 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1381 "to the Places panel."));
1382 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1383
1384 QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1385 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1386 closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1387 "currently viewed tab. If no more tabs are left this window "
1388 "will close instead."));
1389
1390 QAction* quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1391 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1392
1393 // setup 'Edit' menu
1394 KStandardAction::undo(this,
1395 &DolphinMainWindow::undo,
1396 actionCollection());
1397
1398 // i18n: This will be the last paragraph for the whatsthis for all three:
1399 // Cut, Copy and Paste
1400 const QString cutCopyPastePara = xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1401 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1402 "applications and are among the most used commands. That's why their "
1403 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1404 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1405 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1406 QAction* cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1407 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1408 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1409 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1410 "the clipboard to a new location. The items will be removed from their "
1411 "initial location.") + cutCopyPastePara);
1412 QAction* copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1413 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1414 "items in your current selection to the <emphasis>clipboard</emphasis>."
1415 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1416 "from the clipboard to a new location.") + cutCopyPastePara);
1417 QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1418 // The text of the paste-action is modified dynamically by Dolphin
1419 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1420 // due to the long text, the text "Paste" is used:
1421 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1422 paste->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1423 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1424 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1425 "action they are removed from their old location.") + cutCopyPastePara);
1426
1427 QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1428 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1429 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1430 "the <emphasis>active</emphasis> view to the inactive split view."));
1431 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1432 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1433 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT + Qt::Key_F5 );
1434 connect(copyToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::copyToInactiveSplitView);
1435
1436 QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1437 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1438 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1439 "the <emphasis>active</emphasis> view to the inactive split view."));
1440 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1441 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1442 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT + Qt::Key_F6 );
1443 connect(moveToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::moveToInactiveSplitView);
1444
1445 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1446 searchAction->setText(i18n("Search..."));
1447 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1448 searchAction->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1449 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1450 "There you can enter search terms and specify settings to find the "
1451 "objects you are looking for.</para><para>Use this help again on "
1452 "the find bar so we can have a look at it while the settings are "
1453 "explained.</para>"));
1454
1455 // toggle_search acts as a copy of the main searchAction to be used mainly
1456 // in the toolbar, with no default shortcut attached, to avoid messing with
1457 // existing workflows (search bar always open and Ctrl-F to focus)
1458 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1459 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1460 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1461 toggleSearchAction->setIcon(searchAction->icon());
1462 toggleSearchAction->setToolTip(searchAction->toolTip());
1463 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1464 toggleSearchAction->setCheckable(true);
1465
1466 QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1467 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1468 "files and folders in the current location."));
1469
1470 QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1471 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1472 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1473 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1474 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1475 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A);
1476 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1477
1478 // setup 'View' menu
1479 // (note that most of it is set up in DolphinViewActionHandler)
1480
1481 QAction* split = actionCollection()->addAction(QStringLiteral("split_view"));
1482 split->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1483 "the folder view below into two autonomous views.</para><para>This "
1484 "way you can see two locations at once and move items between them "
1485 "quickly.</para>Click this again afterwards to recombine the views."));
1486 actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
1487 connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1488
1489 QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1490 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL + Qt::Key_S);
1491 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1492 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1493 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1494 stashSplit->setCheckable(false);
1495 stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1496 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1497
1498 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1499
1500 QAction* stop = actionCollection()->addAction(QStringLiteral("stop"));
1501 stop->setText(i18nc("@action:inmenu View", "Stop"));
1502 stop->setToolTip(i18nc("@info", "Stop loading"));
1503 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1504 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1505 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1506
1507 KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1508 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1509 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1510 "This toggles the <emphasis>Location Bar</emphasis> to be "
1511 "editable so you can directly enter a location you want to go to.<nl/>"
1512 "You can also switch to editing by clicking to the right of the "
1513 "location and switch back by confirming the edited location."));
1514 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1515 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1516
1517 QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1518 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1519 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1520 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1521 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1522 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1523 "This switches to editing the location and selects it "
1524 "so you can quickly enter a different location."));
1525 actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL + Qt::Key_L);
1526 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
1527
1528 // setup 'Go' menu
1529 {
1530 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1531 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
1532 m_backAction->setObjectName(backAction->objectName());
1533 m_backAction->setShortcuts(backAction->shortcuts());
1534 }
1535 m_backAction->setDelayed(true);
1536 m_backAction->setStickyMenu(false);
1537 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
1538 connect(m_backAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
1539 connect(m_backAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
1540 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
1541
1542 auto backShortcuts = m_backAction->shortcuts();
1543 backShortcuts.append(QKeySequence(Qt::Key_Backspace));
1544 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
1545
1546 DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
1547 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
1548 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab,
1549 recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
1550 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab,
1551 m_tabWidget, &DolphinTabWidget::restoreClosedTab);
1552 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged,
1553 this, &DolphinMainWindow::closedTabsCountChanged);
1554
1555 QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1556 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
1557 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1558 "This returns you to the previously closed tab."));
1559 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL + Qt::SHIFT + Qt::Key_T);
1560 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1561 undoCloseTab->setEnabled(false);
1562 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
1563
1564 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
1565 undoAction->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1566 "the last change you made to files or folders.<nl/>"
1567 "Such changes include <interface>creating, renaming</interface> "
1568 "and <interface>moving</interface> them to a different location "
1569 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1570 "be undone will ask for your confirmation."));
1571 undoAction->setEnabled(false); // undo should be disabled by default
1572
1573 {
1574 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1575 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
1576 m_forwardAction->setObjectName(forwardAction->objectName());
1577 m_forwardAction->setShortcuts(forwardAction->shortcuts());
1578 }
1579 m_forwardAction->setDelayed(true);
1580 m_forwardAction->setStickyMenu(false);
1581 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
1582 connect(m_forwardAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
1583 connect(m_forwardAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
1584 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
1585 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
1586
1587 // enable middle-click to open in a new tab
1588 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
1589 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
1590 m_backAction->menu()->installEventFilter(middleClickEventFilter);
1591 m_forwardAction->menu()->installEventFilter(middleClickEventFilter);
1592 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
1593 QAction* homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
1594 homeAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1595 "<filename>Home</filename> folder.<nl/>Every user account "
1596 "has their own <filename>Home</filename> that contains their data "
1597 "including folders that contain personal application data."));
1598
1599 // setup 'Tools' menu
1600 QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1601 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1602 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1603 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1604 "There you can enter a text to filter the files and folders currently displayed. "
1605 "Only those that contain the text in their name will be kept in view."));
1606 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1607 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL + Qt::Key_I, Qt::Key_Slash});
1608 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1609
1610 QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
1611 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1612 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1613 compareFiles->setEnabled(false);
1614 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
1615
1616 QAction* openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1617 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1618 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
1619 "<para>This opens a preferred search tool for the viewed location.</para>"
1620 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1621 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1622 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL + Qt::SHIFT + Qt::Key_F);
1623 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
1624
1625 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1626 QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1627 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1628 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1629 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1630 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1631 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1632 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4);
1633 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1634
1635 #ifdef HAVE_TERMINAL
1636 QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1637 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1638 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1639 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL + Qt::SHIFT + Qt::Key_F4);
1640 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel);
1641 #endif
1642 }
1643
1644 // setup 'Bookmarks' menu
1645 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1646 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1647 // Make the toolbar button version work properly on click
1648 bookmarkMenu->setDelayed(false);
1649 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
1650 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
1651
1652 // setup 'Settings' menu
1653 KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1654 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
1655 "This switches between having a <emphasis>Menubar</emphasis> "
1656 "and having a <interface>Control</interface> button. Both "
1657 "contain mostly the same commands and configuration options."));
1658 connect(showMenuBar, &KToggleAction::triggered, // Fixes #286822
1659 this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection);
1660 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
1661
1662 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1663 m_helpMenu = new KHelpMenu(nullptr);
1664 m_helpMenu->menu()->installEventFilter(this);
1665 // remove duplicate shortcuts
1666 m_helpMenu->action(KHelpMenu::menuHelpContents)->setShortcut(QKeySequence());
1667 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setShortcut(QKeySequence());
1668
1669 // not in menu actions
1670 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
1671 nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab));
1672
1673 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
1674 prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
1675
1676 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1677 QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
1678 activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1));
1679 activateTab->setEnabled(false);
1680 connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); });
1681
1682 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1683 if (i < 9) {
1684 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
1685 }
1686 }
1687
1688 QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1689 activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1690 activateLastTab->setEnabled(false);
1691 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
1692 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT + Qt::Key_0);
1693
1694 QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1695 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
1696 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1697 activateNextTab->setEnabled(false);
1698 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
1699 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
1700
1701 QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1702 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1703 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1704 activatePrevTab->setEnabled(false);
1705 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
1706 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
1707
1708 // for context menu
1709 QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
1710 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
1711 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1712 showTarget->setEnabled(false);
1713 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
1714
1715 QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1716 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1717 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1718 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1719
1720 QAction* openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1721 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1722 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1723 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1724
1725 QAction* openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1726 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1727 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1728 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
1729 }
1730
1731 void DolphinMainWindow::setupDockWidgets()
1732 {
1733 const bool lock = GeneralSettings::lockPanels();
1734
1735 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
1736 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1737 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1738 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1739 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1740 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", "This "
1741 "switches between having panels <emphasis>locked</emphasis> or "
1742 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1743 "dragged to the other side of the window and have a close "
1744 "button.<nl/>Locked panels are embedded more cleanly."));
1745 lockLayoutAction->setActive(lock);
1746 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
1747
1748 // Setup "Information"
1749 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1750 infoDock->setLocked(lock);
1751 infoDock->setObjectName(QStringLiteral("infoDock"));
1752 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1753
1754 #ifdef HAVE_BALOO
1755 InformationPanel* infoPanel = new InformationPanel(infoDock);
1756 infoPanel->setCustomContextMenuActions({lockLayoutAction});
1757 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
1758 infoDock->setWidget(infoPanel);
1759
1760 QAction* infoAction = infoDock->toggleViewAction();
1761 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel"));
1762
1763 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1764 connect(this, &DolphinMainWindow::urlChanged,
1765 infoPanel, &InformationPanel::setUrl);
1766 connect(this, &DolphinMainWindow::selectionChanged,
1767 infoPanel, &InformationPanel::setSelection);
1768 connect(this, &DolphinMainWindow::requestItemInfo,
1769 infoPanel, &InformationPanel::requestDelayedItemInfo);
1770 #endif
1771
1772 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1773 const QString panelWhatsThis = xi18nc("@info:whatsthis", "<para>To show or "
1774 "hide panels like this go to <interface>Control|Panels</interface> "
1775 "or <interface>View|Panels</interface>.</para>");
1776 #ifdef HAVE_BALOO
1777 actionCollection()->action(QStringLiteral("show_information_panel"))
1778 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1779 "<emphasis>information</emphasis> panel at the right side of the "
1780 "window.</para><para>The panel provides in-depth information "
1781 "about the items your mouse is hovering over or about the selected "
1782 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1783 "For single items a preview of their contents is provided.</para>"));
1784 #endif
1785 infoDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1786 "provides in-depth information about the items your mouse is "
1787 "hovering over or about the selected items. Otherwise it informs "
1788 "you about the currently viewed folder.<nl/>For single items a "
1789 "preview of their contents is provided.</para><para>You can configure "
1790 "which and how details are given here by right-clicking.</para>") + panelWhatsThis);
1791
1792 // Setup "Folders"
1793 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1794 foldersDock->setLocked(lock);
1795 foldersDock->setObjectName(QStringLiteral("foldersDock"));
1796 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1797 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1798 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
1799 foldersDock->setWidget(foldersPanel);
1800
1801 QAction* foldersAction = foldersDock->toggleViewAction();
1802 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel"));
1803
1804 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1805 connect(this, &DolphinMainWindow::urlChanged,
1806 foldersPanel, &FoldersPanel::setUrl);
1807 connect(foldersPanel, &FoldersPanel::folderActivated,
1808 this, &DolphinMainWindow::changeUrl);
1809 connect(foldersPanel, &FoldersPanel::folderMiddleClicked,
1810 this, &DolphinMainWindow::openNewTabAfterCurrentTab);
1811 connect(foldersPanel, &FoldersPanel::errorMessage,
1812 this, &DolphinMainWindow::showErrorMessage);
1813
1814 actionCollection()->action(QStringLiteral("show_folders_panel"))
1815 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1816 "<emphasis>folders</emphasis> panel at the left side of the window."
1817 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1818 "</emphasis> in a <emphasis>tree view</emphasis>."));
1819 foldersDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1820 "shows the folders of the <emphasis>file system</emphasis> in a "
1821 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1822 "there. Click the arrow to the left of a folder to see its subfolders. "
1823 "This allows quick switching between any folders.</para>") + panelWhatsThis);
1824
1825 // Setup "Terminal"
1826 #ifdef HAVE_TERMINAL
1827 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1828 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1829 terminalDock->setLocked(lock);
1830 terminalDock->setObjectName(QStringLiteral("terminalDock"));
1831 m_terminalPanel = new TerminalPanel(terminalDock);
1832 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
1833 terminalDock->setWidget(m_terminalPanel);
1834
1835 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
1836 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
1837 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
1838 m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
1839 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
1840 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
1841
1842 QAction* terminalAction = terminalDock->toggleViewAction();
1843 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
1844
1845 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1846 connect(this, &DolphinMainWindow::urlChanged,
1847 m_terminalPanel, &TerminalPanel::setUrl);
1848
1849 if (GeneralSettings::version() < 200) {
1850 terminalDock->hide();
1851 }
1852
1853 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1854 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1855 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1856 "<nl/>The location in the terminal will always match the folder "
1857 "view so you can navigate using either.</para><para>The terminal "
1858 "panel is not needed for basic computer usage but can be useful "
1859 "for advanced tasks. To learn more about terminals use the help "
1860 "in a standalone terminal application like Konsole.</para>"));
1861 terminalDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1862 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1863 "normal terminal but will match the location of the folder view "
1864 "so you can navigate using either.</para><para>The terminal panel "
1865 "is not needed for basic computer usage but can be useful for "
1866 "advanced tasks. To learn more about terminals use the help in a "
1867 "standalone terminal application like Konsole.</para>") + panelWhatsThis);
1868 }
1869 #endif
1870
1871 if (GeneralSettings::version() < 200) {
1872 infoDock->hide();
1873 foldersDock->hide();
1874 }
1875
1876 // Setup "Places"
1877 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1878 placesDock->setLocked(lock);
1879 placesDock->setObjectName(QStringLiteral("placesDock"));
1880 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1881
1882 m_placesPanel = new PlacesPanel(placesDock);
1883 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
1884 placesDock->setWidget(m_placesPanel);
1885
1886 QAction *placesAction = placesDock->toggleViewAction();
1887 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
1888
1889 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1890 connect(m_placesPanel, &PlacesPanel::placeActivated,
1891 this, &DolphinMainWindow::slotPlaceActivated);
1892 connect(m_placesPanel, &PlacesPanel::placeMiddleClicked,
1893 this, &DolphinMainWindow::openNewTabAfterCurrentTab);
1894 connect(m_placesPanel, &PlacesPanel::errorMessage,
1895 this, &DolphinMainWindow::showErrorMessage);
1896 connect(this, &DolphinMainWindow::urlChanged,
1897 m_placesPanel, &PlacesPanel::setUrl);
1898 connect(placesDock, &DolphinDockWidget::visibilityChanged,
1899 &DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged);
1900 connect(this, &DolphinMainWindow::settingsChanged,
1901 m_placesPanel, &PlacesPanel::readSettings);
1902 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
1903 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
1904 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
1905 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
1906 DolphinUrlNavigatorsController::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
1907
1908 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1909 actionShowAllPlaces->setCheckable(true);
1910 actionShowAllPlaces->setDisabled(true);
1911 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1912 "all places in the places panel that have been hidden. They will "
1913 "appear semi-transparent unless you uncheck their hide property."));
1914
1915 connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){
1916 actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1917 m_placesPanel->showHiddenEntries(checked);
1918 });
1919
1920 connect(m_placesPanel, &PlacesPanel::showHiddenEntriesChanged, this, [actionShowAllPlaces] (bool checked){
1921 actionShowAllPlaces->setChecked(checked);
1922 actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1923 });
1924
1925 actionCollection()->action(QStringLiteral("show_places_panel"))
1926 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1927 "<emphasis>places</emphasis> panel at the left side of the window."
1928 "</para><para>It allows you to go to locations you have "
1929 "bookmarked and to access disk or media attached to the computer "
1930 "or to the network. It also contains sections to find recently "
1931 "saved files or files of a certain type.</para>"));
1932 placesDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1933 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1934 "you have bookmarked and to access disk or media attached to the "
1935 "computer or to the network. It also contains sections to find "
1936 "recently saved files or files of a certain type.</para><para>"
1937 "Click on an entry to go there. Click with the right mouse button "
1938 "instead to open any entry in a new tab or new window.</para>"
1939 "<para>New entries can be added by dragging folders onto this panel. "
1940 "Right-click any section or entry to hide it. Right-click an empty "
1941 "space on this panel and select <interface>Show Hidden Places"
1942 "</interface> to display it again.</para>") + panelWhatsThis);
1943
1944 // Add actions into the "Panels" menu
1945 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
1946 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
1947 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
1948 panelsMenu->setDelayed(false);
1949 const KActionCollection* ac = actionCollection();
1950 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
1951 #ifdef HAVE_BALOO
1952 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
1953 #endif
1954 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
1955 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
1956 panelsMenu->addSeparator();
1957 panelsMenu->addAction(actionShowAllPlaces);
1958 panelsMenu->addAction(lockLayoutAction);
1959
1960 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{
1961 actionShowAllPlaces->setEnabled(m_placesPanel->hiddenListCount());
1962 });
1963 }
1964
1965
1966 void DolphinMainWindow::updateFileAndEditActions()
1967 {
1968 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1969 const KActionCollection* col = actionCollection();
1970 KFileItemListProperties capabilitiesSource(list);
1971
1972 QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
1973 QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
1974 QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
1975 QAction* copyLocation = col->action(QString("copy_location"));
1976
1977 if (list.isEmpty()) {
1978 stateChanged(QStringLiteral("has_no_selection"));
1979
1980 addToPlacesAction->setEnabled(true);
1981 copyToOtherViewAction->setEnabled(false);
1982 moveToOtherViewAction->setEnabled(false);
1983 copyLocation->setEnabled(false);
1984 } else {
1985 stateChanged(QStringLiteral("has_selection"));
1986
1987 QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
1988 QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
1989 QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
1990 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1991 QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1992 QAction* showTarget = col->action(QStringLiteral("show_target"));
1993 QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
1994
1995 if (list.length() == 1 && list.first().isDir()) {
1996 addToPlacesAction->setEnabled(true);
1997 } else {
1998 addToPlacesAction->setEnabled(false);
1999 }
2000
2001 if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
2002 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2003 KFileItem capabilitiesDestination;
2004
2005 if (tabPage->primaryViewActive()) {
2006 capabilitiesDestination = tabPage->secondaryViewContainer()->url();
2007 } else {
2008 capabilitiesDestination = tabPage->primaryViewContainer()->url();
2009 }
2010
2011 copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
2012 moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving() && capabilitiesDestination.isWritable());
2013 } else {
2014 copyToOtherViewAction->setEnabled(false);
2015 moveToOtherViewAction->setEnabled(false);
2016 }
2017
2018 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2019
2020 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2021 moveToTrashAction->setEnabled(enableMoveToTrash);
2022 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2023 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
2024 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2025 copyLocation->setEnabled(list.length() == 1);
2026 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2027 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2028 }
2029 }
2030
2031 void DolphinMainWindow::updateViewActions()
2032 {
2033 m_actionHandler->updateViewActions();
2034
2035 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
2036 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2037
2038 updateSplitAction();
2039 }
2040
2041 void DolphinMainWindow::updateGoActions()
2042 {
2043 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2044 const QUrl currentUrl = m_activeViewContainer->url();
2045 // I think this is one of the best places to firstly be confronted
2046 // with a file system and its hierarchy. Talking about the root
2047 // directory might seem too much here but it is the question that
2048 // naturally arises in this context.
2049 goUpAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2050 "the folder that contains the currently viewed one.</para>"
2051 "<para>All files and folders are organized in a hierarchical "
2052 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2053 "a directory that contains all data connected to this computer"
2054 "—the <emphasis>root directory</emphasis>.</para>"));
2055 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2056 }
2057
2058 void DolphinMainWindow::createControlButton()
2059 {
2060 if (m_controlButton) {
2061 return;
2062 }
2063 Q_ASSERT(!m_controlButton);
2064
2065 m_controlButton = new QToolButton(this);
2066 m_controlButton->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2067 m_controlButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2068 m_controlButton->setToolTip(i18nc("@action", "Show menu"));
2069 m_controlButton->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis);
2070 m_controlButton->setPopupMode(QToolButton::InstantPopup);
2071
2072 QMenu* controlMenu = new QMenu(m_controlButton);
2073 connect(controlMenu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateControlMenu);
2074 controlMenu->installEventFilter(this);
2075
2076 m_controlButton->setMenu(controlMenu);
2077
2078 toolBar()->addWidget(m_controlButton);
2079 connect(toolBar(), &KToolBar::iconSizeChanged,
2080 m_controlButton, &QToolButton::setIconSize);
2081
2082 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2083 // gets edited. In this case we must add them again. The adding is done asynchronously by
2084 // m_updateToolBarTimer.
2085 connect(m_controlButton, &QToolButton::destroyed, this, &DolphinMainWindow::slotControlButtonDeleted);
2086 m_updateToolBarTimer = new QTimer(this);
2087 m_updateToolBarTimer->setInterval(500);
2088 connect(m_updateToolBarTimer, &QTimer::timeout, this, &DolphinMainWindow::updateToolBar);
2089 }
2090
2091 void DolphinMainWindow::deleteControlButton()
2092 {
2093 delete m_controlButton;
2094 m_controlButton = nullptr;
2095
2096 delete m_updateToolBarTimer;
2097 m_updateToolBarTimer = nullptr;
2098 }
2099
2100 bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu)
2101 {
2102 Q_ASSERT(action);
2103 Q_ASSERT(menu);
2104
2105 const KToolBar* toolBarWidget = toolBar();
2106 const auto associatedWidgets = action->associatedWidgets();
2107 for (const QWidget* widget : associatedWidgets) {
2108 if (widget == toolBarWidget) {
2109 return false;
2110 }
2111 }
2112
2113 menu->addAction(action);
2114 return true;
2115 }
2116
2117 void DolphinMainWindow::refreshViews()
2118 {
2119 m_tabWidget->refreshViews();
2120
2121 if (GeneralSettings::modifiedStartupSettings()) {
2122 // The startup settings have been changed by the user (see bug #254947).
2123 // Synchronize the split-view setting with the active view:
2124 const bool splitView = GeneralSettings::splitView();
2125 m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView);
2126 updateSplitAction();
2127 updateWindowTitle();
2128 }
2129
2130 Q_EMIT settingsChanged();
2131 }
2132
2133 void DolphinMainWindow::clearStatusBar()
2134 {
2135 m_activeViewContainer->statusBar()->resetToDefaultText();
2136 }
2137
2138 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
2139 {
2140 connect(container, &DolphinViewContainer::showFilterBarChanged,
2141 this, &DolphinMainWindow::updateFilterBarAction);
2142 connect(container, &DolphinViewContainer::writeStateChanged,
2143 this, &DolphinMainWindow::slotWriteStateChanged);
2144 connect(container, &DolphinViewContainer::searchModeEnabledChanged,
2145 this, &DolphinMainWindow::updateSearchAction);
2146
2147 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
2148 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
2149
2150 const DolphinView* view = container->view();
2151 connect(view, &DolphinView::selectionChanged,
2152 this, &DolphinMainWindow::slotSelectionChanged);
2153 connect(view, &DolphinView::requestItemInfo,
2154 this, &DolphinMainWindow::requestItemInfo);
2155 connect(view, &DolphinView::tabRequested,
2156 this, &DolphinMainWindow::openNewTab);
2157 connect(view, &DolphinView::requestContextMenu,
2158 this, &DolphinMainWindow::openContextMenu);
2159 connect(view, &DolphinView::directoryLoadingStarted,
2160 this, &DolphinMainWindow::enableStopAction);
2161 connect(view, &DolphinView::directoryLoadingCompleted,
2162 this, &DolphinMainWindow::disableStopAction);
2163 connect(view, &DolphinView::directoryLoadingCompleted,
2164 this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2165 connect(view, &DolphinView::goBackRequested,
2166 this, &DolphinMainWindow::goBack);
2167 connect(view, &DolphinView::goForwardRequested,
2168 this, &DolphinMainWindow::goForward);
2169 connect(view, &DolphinView::urlActivated,
2170 this, &DolphinMainWindow::handleUrl);
2171 connect(view, &DolphinView::goUpRequested,
2172 this, &DolphinMainWindow::goUp);
2173
2174 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2175 (actionCollection()->action(QStringLiteral("url_navigators")));
2176
2177 const KUrlNavigator *navigator = m_tabWidget->currentTabPage()->primaryViewActive() ?
2178 navigators->primaryUrlNavigator() :
2179 navigators->secondaryUrlNavigator();
2180
2181 connect(navigator, &KUrlNavigator::urlChanged,
2182 this, &DolphinMainWindow::changeUrl);
2183 QAction *editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2184 editableLocactionAction->setChecked(navigator->isUrlEditable());
2185 connect(navigator, &KUrlNavigator::editableStateChanged,
2186 this, &DolphinMainWindow::slotEditableStateChanged);
2187 connect(navigator, &KUrlNavigator::tabRequested,
2188 this, &DolphinMainWindow::openNewTabAfterLastTab);
2189
2190 disconnect(m_updateHistoryConnection);
2191 m_updateHistoryConnection = connect(
2192 container->urlNavigatorInternalWithHistory(), &KUrlNavigator::historyChanged,
2193 this, &DolphinMainWindow::updateHistory);
2194 }
2195
2196 void DolphinMainWindow::updateSplitAction()
2197 {
2198 QAction* splitAction = actionCollection()->action(QStringLiteral("split_view"));
2199 const DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2200 if (tabPage->splitViewEnabled()) {
2201 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2202 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2203 splitAction->setToolTip(i18nc("@info", "Close left view"));
2204 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2205 } else {
2206 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2207 splitAction->setToolTip(i18nc("@info", "Close right view"));
2208 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2209 }
2210 } else {
2211 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2212 splitAction->setToolTip(i18nc("@info", "Split view"));
2213 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2214 }
2215 }
2216
2217 void DolphinMainWindow::updateAllowedToolbarAreas()
2218 {
2219 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2220 (actionCollection()->action(QStringLiteral("url_navigators")));
2221 if (toolBar()->actions().contains(navigators)) {
2222 toolBar()->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
2223 if (toolBarArea(toolBar()) == Qt::LeftToolBarArea ||
2224 toolBarArea(toolBar()) == Qt::RightToolBarArea) {
2225 addToolBar(Qt::TopToolBarArea, toolBar());
2226 }
2227 } else {
2228 toolBar()->setAllowedAreas(Qt::AllToolBarAreas);
2229 }
2230 }
2231
2232 bool DolphinMainWindow::isKompareInstalled() const
2233 {
2234 static bool initialized = false;
2235 static bool installed = false;
2236 if (!initialized) {
2237 // TODO: maybe replace this approach later by using a menu
2238 // plugin like kdiff3plugin.cpp
2239 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2240 initialized = true;
2241 }
2242 return installed;
2243 }
2244
2245 void DolphinMainWindow::createPanelAction(const QIcon& icon,
2246 const QKeySequence& shortcut,
2247 QAction* dockAction,
2248 const QString& actionName)
2249 {
2250 QAction* panelAction = actionCollection()->addAction(actionName);
2251 panelAction->setCheckable(true);
2252 panelAction->setChecked(dockAction->isChecked());
2253 panelAction->setText(dockAction->text());
2254 panelAction->setIcon(icon);
2255 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2256
2257 connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
2258 connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
2259 }
2260
2261 void DolphinMainWindow::setupWhatsThis()
2262 {
2263 // main widgets
2264 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2265 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2266 "configuration options. Left-click on any of the menus on this "
2267 "bar to see its contents.</para><para>The Menubar can be hidden "
2268 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2269 "most of its contents become available through a <interface>Control"
2270 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2271 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2272 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2273 "frequently used actions.</para><para>It is highly customizable. "
2274 "All items you see in the <interface>Control</interface> menu or "
2275 "in the <interface>Menubar</interface> can be placed on the "
2276 "Toolbar. Just right-click on it and select <interface>Configure "
2277 "Toolbars…</interface> or find this action in the <interface>"
2278 "Control</interface> or <interface>Settings</interface> menu."
2279 "</para><para>The location of the bar and the style of its "
2280 "buttons can also be changed in the right-click menu. Right-click "
2281 "a button if you want to show or hide its text.</para>"));
2282 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2283 "<para>Here you can see the <emphasis>folders</emphasis> and "
2284 "<emphasis>files</emphasis> that are at the location described in "
2285 "the <interface>Location Bar</interface> above. This area is the "
2286 "central part of this application where you navigate to the files "
2287 "you want to use.</para><para>For an elaborate and general "
2288 "introduction to this application <link "
2289 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2290 "click here</link>. This will open an introductory article from "
2291 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2292 "explanations of all the features of this <emphasis>view</emphasis> "
2293 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2294 "instead. This will open a page from the <emphasis>Handbook"
2295 "</emphasis> that covers the basics.</para>"));
2296
2297 // Settings menu
2298 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2299 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2300 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2301 "There you can set up key combinations to trigger an action when "
2302 "they are pressed simultaneously. All commands in this application can "
2303 "be triggered this way.</para>"));
2304 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2305 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2306 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2307 "<para>All items you see in the <interface>Control</interface> menu "
2308 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2309 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2310 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2311 "change a multitude of settings for this application. For an explanation "
2312 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2313 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2314
2315 // Help menu
2316 // The whatsthis has to be set for the m_helpMenu and for the
2317 // StandardAction separately because both are used in different locations.
2318 // m_helpMenu is only used for createControlButton() button.
2319
2320 // Links do not work within the Menubar so texts without links are provided there.
2321
2322 // i18n: If the external link isn't available in your language you should
2323 // probably state the external link language at least in brackets to not
2324 // frustrate the user. If there are multiple languages that the user might
2325 // know with a reasonable chance you might want to have 2 external links.
2326 // The same is in my opinion true for every external link you translate.
2327 const QString whatsThisHelpContents = xi18nc("@info:whatsthis handbook",
2328 "<para>This opens the Handbook for this application. It provides "
2329 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2330 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents))
2331 ->setWhatsThis(whatsThisHelpContents
2332 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2333 "<para>If you want more elaborate introductions to the "
2334 "different features of <emphasis>Dolphin</emphasis> "
2335 "go to the KDE UserBase Wiki.</para>"));
2336 m_helpMenu->action(KHelpMenu::menuHelpContents)->setWhatsThis(whatsThisHelpContents
2337 + xi18nc("@info:whatsthis second half of handbook text with link",
2338 "<para>If you want more elaborate introductions to the "
2339 "different features of <emphasis>Dolphin</emphasis> "
2340 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2341 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2342
2343 const QString whatsThisWhatsThis = xi18nc("@info:whatsthis whatsthis button",
2344 "<para>This is the button that invokes the help feature you are "
2345 "using right now! Click it, then click any component of this "
2346 "application to ask \"What's this?\" about it. The mouse cursor "
2347 "will change appearance if no help is available for a spot.</para>");
2348 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis))
2349 ->setWhatsThis(whatsThisWhatsThis
2350 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2351 "<para>There are two other ways to get help for this application: The "
2352 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2353 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2354 "article about <emphasis>File Management</emphasis> online."
2355 "</para><para>The \"What's this?\" help is "
2356 "missing in most other windows so don't get too used to this.</para>"));
2357 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setWhatsThis(whatsThisWhatsThis
2358 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2359 "<para>There are two other ways to get help: "
2360 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2361 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2362 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2363 "missing in most other windows so don't get too used to this.</para>"));
2364
2365 const QString whatsThisReportBug = xi18nc("@info:whatsthis","<para>This opens a "
2366 "window that will guide you through reporting errors or flaws "
2367 "in this application or in other KDE software.</para>");
2368 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug))
2369 ->setWhatsThis(whatsThisReportBug);
2370 m_helpMenu->action(KHelpMenu::menuReportBug)->setWhatsThis(whatsThisReportBug
2371 + xi18nc("@info:whatsthis second half of reportbug text with link",
2372 "<para>High-quality bug reports are much appreciated. To learn "
2373 "how to make your bug report as effective as possible "
2374 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2375 "click here</link>.</para>"));
2376
2377 const QString whatsThisDonate = xi18nc("@info:whatsthis","<para>This opens a "
2378 "<emphasis>web page</emphasis> where you can donate to "
2379 "support the continued work on this application and many "
2380 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2381 "<para>Donating is the easiest and fastest way to efficiently "
2382 "support KDE and its projects. KDE projects are available for "
2383 "free therefore your donation is needed to cover things that "
2384 "require money like servers, contributor meetings, etc.</para>"
2385 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2386 "organization behind the KDE community.</para>");
2387 actionCollection()->action(KStandardAction::name(KStandardAction::Donate))
2388 ->setWhatsThis(whatsThisDonate);
2389 m_helpMenu->action(KHelpMenu::menuDonate)->setWhatsThis(whatsThisDonate);
2390
2391 const QString whatsThisSwitchLanguage = xi18nc("@info:whatsthis",
2392 "With this you can change the language this application uses."
2393 "<nl/>You can even set secondary languages which will be used "
2394 "if texts are not available in your preferred language.");
2395 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))
2396 ->setWhatsThis(whatsThisSwitchLanguage);
2397 m_helpMenu->action(KHelpMenu::menuSwitchLanguage)->setWhatsThis(whatsThisSwitchLanguage);
2398
2399 const QString whatsThisAboutApp = xi18nc("@info:whatsthis","This opens a "
2400 "window that informs you about the version, license, "
2401 "used libraries and maintainers of this application.");
2402 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp))
2403 ->setWhatsThis(whatsThisAboutApp);
2404 m_helpMenu->action(KHelpMenu::menuAboutApp)->setWhatsThis(whatsThisAboutApp);
2405
2406 const QString whatsThisAboutKDE = xi18nc("@info:whatsthis","This opens a "
2407 "window with information about <emphasis>KDE</emphasis>. "
2408 "The KDE community are the people behind this free software."
2409 "<nl/>If you like using this application but don't know "
2410 "about KDE or want to see a cute dragon have a look!");
2411 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE))
2412 ->setWhatsThis(whatsThisAboutKDE);
2413 m_helpMenu->action(KHelpMenu::menuAboutKDE)->setWhatsThis(whatsThisAboutKDE);
2414 }
2415
2416 bool DolphinMainWindow::event(QEvent *event)
2417 {
2418 if (event->type() == QEvent::WhatsThisClicked) {
2419 event->accept();
2420 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2421 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2422 return true;
2423 }
2424 return KXmlGuiWindow::event(event);
2425 }
2426
2427 bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event)
2428 {
2429 Q_UNUSED(obj)
2430 if (event->type() == QEvent::WhatsThisClicked) {
2431 event->accept();
2432 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2433 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2434 return true;
2435 }
2436 return false;
2437 }
2438
2439 void DolphinMainWindow::saveNewToolbarConfig()
2440 {
2441 KXmlGuiWindow::saveNewToolbarConfig(); // Applies the new config. This has to be called first
2442 // because the rest of this method decides things
2443 // based on the new config.
2444 auto navigators = static_cast<DolphinNavigatorsWidgetAction *>
2445 (actionCollection()->action(QStringLiteral("url_navigators")));
2446 if (!toolBar()->actions().contains(navigators)) {
2447 m_tabWidget->currentTabPage()->insertNavigatorsWidget(navigators);
2448 }
2449 updateAllowedToolbarAreas();
2450 }
2451
2452 void DolphinMainWindow::focusTerminalPanel()
2453 {
2454 if (m_terminalPanel->isVisible()) {
2455 if (m_terminalPanel->terminalHasFocus()) {
2456 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2457 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2458 } else {
2459 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2460 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2461 }
2462 } else {
2463 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2464 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2465 }
2466 }
2467
2468 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2469 KIO::FileUndoManager::UiInterface()
2470 {
2471 }
2472
2473 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2474 {
2475 }
2476
2477 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2478 {
2479 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2480 if (mainWin) {
2481 DolphinViewContainer* container = mainWin->activeViewContainer();
2482 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2483 } else {
2484 KIO::FileUndoManager::UiInterface::jobError(job);
2485 }
2486 }
2487
2488 bool DolphinMainWindow::isUrlOpen(const QString& url)
2489 {
2490 return m_tabWidget->isUrlOpen(QUrl::fromUserInput((url)));
2491 }
2492