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