]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Adress the first round of Angelaccio's review comments
[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->urlNavigatorInternal();
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->urlNavigatorInternal();
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->urlNavigatorInternal();
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()->urlNavigatorInternal();
755 openNewTabAfterCurrentTab(urlNavigator->locationUrl(action->data().value<int>()));
756 }
757 }
758
759 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
760 {
761 const KUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
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->urlNavigatorInternal();
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 // prevent the switching if it would leave the user without a visible UrlNavigator
862 if (locationInToolbar && !toolBar()->actions().contains(urlNavigatorWidgetAction)) {
863 QAction *configureToolbars = actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars));
864 KMessageWidget *messageWidget = m_activeViewContainer->showMessage(
865 xi18nc("@info 2 is the visible text on a button just below the message",
866 "The location could not be moved onto the toolbar because there is currently "
867 "no \"%1\" item on the toolbar. Select <interface>%2</interface> and add the "
868 "\"%1\" item. Then this will work.", urlNavigatorWidgetAction->iconText(),
869 configureToolbars->iconText()), DolphinViewContainer::Information);
870 messageWidget->addAction(configureToolbars);
871 messageWidget->addAction(locationInToolbarAction);
872 locationInToolbarAction->setChecked(false);
873 return;
874 }
875
876 // do the switching
877 GeneralSettings::setLocationInToolbar(locationInToolbar);
878 if (locationInToolbar) {
879 for (const auto viewContainer : viewContainers) {
880 viewContainer->disconnectUrlNavigator();
881 }
882 m_activeViewContainer->connectUrlNavigator(urlNavigatorWidgetAction->urlNavigator());
883 } else {
884 m_activeViewContainer->disconnectUrlNavigator();
885 for (const auto viewContainer : viewContainers) {
886 viewContainer->connectToInternalUrlNavigator();
887 }
888 }
889
890 urlNavigatorWidgetAction->setUrlNavigatorVisible(locationInToolbar);
891 m_activeViewContainer->urlNavigator()->setUrlEditable(isEditable);
892 if (hasFocus) { // the rest of this method is unneeded perfectionism
893 m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setText(lineEdit->text());
894 m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setFocus();
895 m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setCursorPosition(cursorPosition);
896 if (selectionStart != -1) {
897 m_activeViewContainer->urlNavigator()->editor()->lineEdit()->setSelection(selectionStart, selectionLength);
898 }
899 }
900 }
901
902 void DolphinMainWindow::toggleEditLocation()
903 {
904 clearStatusBar();
905
906 QAction* action = actionCollection()->action(QStringLiteral("editable_location"));
907 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
908 urlNavigator->setUrlEditable(action->isChecked());
909 }
910
911 void DolphinMainWindow::replaceLocation()
912 {
913 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
914 QLineEdit* lineEdit = navigator->editor()->lineEdit();
915
916 // If the text field currently has focus and everything is selected,
917 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
918 if (navigator->isUrlEditable()
919 && lineEdit->hasFocus()
920 && lineEdit->selectedText() == lineEdit->text() ) {
921 navigator->setUrlEditable(false);
922 } else {
923 navigator->setUrlEditable(true);
924 navigator->setFocus();
925 lineEdit->selectAll();
926 }
927 }
928
929 void DolphinMainWindow::togglePanelLockState()
930 {
931 const bool newLockState = !GeneralSettings::lockPanels();
932 const auto childrenObjects = children();
933 for (QObject* child : childrenObjects) {
934 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
935 if (dock) {
936 dock->setLocked(newLockState);
937 }
938 }
939
940 GeneralSettings::setLockPanels(newLockState);
941 }
942
943 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
944 {
945 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
946 m_activeViewContainer->view()->setFocus();
947 }
948 }
949
950 void DolphinMainWindow::goBack()
951 {
952 DolphinUrlNavigator *urlNavigator = m_activeViewContainer->urlNavigatorInternal();
953 urlNavigator->goBack();
954
955 if (urlNavigator->locationState().isEmpty()) {
956 // An empty location state indicates a redirection URL,
957 // which must be skipped too
958 urlNavigator->goBack();
959 }
960 }
961
962 void DolphinMainWindow::goForward()
963 {
964 m_activeViewContainer->urlNavigator()->goForward();
965 }
966
967 void DolphinMainWindow::goUp()
968 {
969 m_activeViewContainer->urlNavigator()->goUp();
970 }
971
972 void DolphinMainWindow::goHome()
973 {
974 m_activeViewContainer->urlNavigator()->goHome();
975 }
976
977 void DolphinMainWindow::goBackInNewTab()
978 {
979 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternal();
980 const int index = urlNavigator->historyIndex() + 1;
981 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
982 }
983
984 void DolphinMainWindow::goForwardInNewTab()
985 {
986 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigatorInternal();
987 const int index = urlNavigator->historyIndex() - 1;
988 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
989 }
990
991 void DolphinMainWindow::goUpInNewTab()
992 {
993 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
994 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl));
995 }
996
997 void DolphinMainWindow::goHomeInNewTab()
998 {
999 openNewTabAfterCurrentTab(Dolphin::homeUrl());
1000 }
1001
1002 void DolphinMainWindow::compareFiles()
1003 {
1004 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
1005 if (items.count() != 2) {
1006 // The action is disabled in this case, but it could have been triggered
1007 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
1008 return;
1009 }
1010
1011 QUrl urlA = items.at(0).url();
1012 QUrl urlB = items.at(1).url();
1013
1014 QString command(QStringLiteral("kompare -c \""));
1015 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
1016 command.append("\" \"");
1017 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
1018 command.append('\"');
1019
1020 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this);
1021 job->setDesktopName(QStringLiteral("org.kde.kompare"));
1022 job->start();
1023 }
1024
1025 void DolphinMainWindow::toggleShowMenuBar()
1026 {
1027 const bool visible = menuBar()->isVisible();
1028 menuBar()->setVisible(!visible);
1029 if (visible) {
1030 createControlButton();
1031 } else {
1032 deleteControlButton();
1033 }
1034 }
1035
1036 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
1037 {
1038 m_searchTools.clear();
1039 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
1040 &m_searchTools, { "files-find" }, m_activeViewContainer->url()
1041 );
1042 QList<QAction*> actions = m_searchTools.actions();
1043 if (actions.isEmpty()) {
1044 return nullptr;
1045 }
1046 QAction* action = actions.first();
1047 if (action->isSeparator()) {
1048 return nullptr;
1049 }
1050 return action;
1051 }
1052
1053 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
1054 {
1055 QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
1056 if (!openPreferredSearchTool) {
1057 return;
1058 }
1059 QPointer<QAction> tool = preferredSearchTool();
1060 if (tool) {
1061 openPreferredSearchTool->setVisible(true);
1062 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
1063 openPreferredSearchTool->setIcon(tool->icon());
1064 } else {
1065 openPreferredSearchTool->setVisible(false);
1066 // still visible in Shortcuts configuration window
1067 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1068 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1069 }
1070 }
1071
1072 void DolphinMainWindow::openPreferredSearchTool()
1073 {
1074 QPointer<QAction> tool = preferredSearchTool();
1075 if (tool) {
1076 tool->trigger();
1077 }
1078 }
1079
1080 void DolphinMainWindow::openTerminal()
1081 {
1082 const QUrl url = m_activeViewContainer->url();
1083
1084 if (url.isLocalFile()) {
1085 KToolInvocation::invokeTerminal(QString(), url.toLocalFile());
1086 return;
1087 }
1088
1089 // Not a local file, with protocol Class ":local", try stat'ing
1090 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
1091 KIO::StatJob *job = KIO::mostLocalUrl(url);
1092 KJobWidgets::setWindow(job, this);
1093 connect(job, &KJob::result, this, [job]() {
1094 QUrl statUrl;
1095 if (!job->error()) {
1096 statUrl = job->mostLocalUrl();
1097 }
1098
1099 KToolInvocation::invokeTerminal(QString(), statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
1100 });
1101
1102 return;
1103 }
1104
1105 // Nothing worked, just use $HOME
1106 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1107 }
1108
1109 void DolphinMainWindow::editSettings()
1110 {
1111 if (!m_settingsDialog) {
1112 DolphinViewContainer* container = activeViewContainer();
1113 container->view()->writeSettings();
1114
1115 const QUrl url = container->url();
1116 DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
1117 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
1118 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, &DolphinUrlNavigator::slotReadSettings);
1119 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1120 settingsDialog->show();
1121 m_settingsDialog = settingsDialog;
1122 } else {
1123 m_settingsDialog.data()->raise();
1124 }
1125 }
1126
1127 void DolphinMainWindow::handleUrl(const QUrl& url)
1128 {
1129 delete m_lastHandleUrlOpenJob;
1130 m_lastHandleUrlOpenJob = nullptr;
1131
1132 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1133 activeViewContainer()->setUrl(url);
1134 } else {
1135 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
1136 m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1137 m_lastHandleUrlOpenJob->setRunExecutables(true);
1138
1139 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this,
1140 [this, url](const QString &mimetype) {
1141 if (mimetype == QLatin1String("inode/directory")) {
1142 // If it's a dir, we'll take it from here
1143 m_lastHandleUrlOpenJob->kill();
1144 m_lastHandleUrlOpenJob = nullptr;
1145 activeViewContainer()->setUrl(url);
1146 }
1147 });
1148
1149 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
1150 m_lastHandleUrlOpenJob = nullptr;
1151 });
1152
1153 m_lastHandleUrlOpenJob->start();
1154 }
1155 }
1156
1157 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
1158 {
1159 // trash:/ is writable but we don't want to create new items in it.
1160 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
1161 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
1162 }
1163
1164 void DolphinMainWindow::openContextMenu(const QPoint& pos,
1165 const KFileItem& item,
1166 const QUrl& url,
1167 const QList<QAction*>& customActions)
1168 {
1169 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
1170 contextMenu.data()->setCustomActions(customActions);
1171 const DolphinContextMenu::Command command = contextMenu.data()->open();
1172
1173 switch (command) {
1174 case DolphinContextMenu::OpenParentFolder:
1175 changeUrl(KIO::upUrl(item.url()));
1176 m_activeViewContainer->view()->markUrlsAsSelected({item.url()});
1177 m_activeViewContainer->view()->markUrlAsCurrent(item.url());
1178 break;
1179
1180 case DolphinContextMenu::OpenParentFolderInNewWindow:
1181 Dolphin::openNewWindow({item.url()}, this, Dolphin::OpenNewWindowFlag::Select);
1182 break;
1183
1184 case DolphinContextMenu::OpenParentFolderInNewTab:
1185 openNewTabAfterLastTab(KIO::upUrl(item.url()));
1186 break;
1187
1188 case DolphinContextMenu::None:
1189 default:
1190 break;
1191 }
1192
1193 // Delete the menu, unless it has been deleted in its own nested event loop already.
1194 if (contextMenu) {
1195 contextMenu->deleteLater();
1196 }
1197 }
1198
1199 void DolphinMainWindow::updateControlMenu()
1200 {
1201 QMenu* menu = qobject_cast<QMenu*>(sender());
1202 Q_ASSERT(menu);
1203
1204 // All actions get cleared by QMenu::clear(). This includes the sub-menus
1205 // because 'menu' is their parent.
1206 menu->clear();
1207
1208 KActionCollection* ac = actionCollection();
1209
1210 menu->addMenu(m_newFileMenu->menu());
1211 addActionToMenu(ac->action(QStringLiteral("file_new")), menu);
1212 addActionToMenu(ac->action(QStringLiteral("new_tab")), menu);
1213 addActionToMenu(ac->action(QStringLiteral("closed_tabs")), menu);
1214
1215 menu->addSeparator();
1216
1217 // Add "Edit" actions
1218 bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
1219 addActionToMenu(ac->action(QString("copy_location")), menu) |
1220 addActionToMenu(ac->action(QStringLiteral("copy_to_inactive_split_view")), menu) |
1221 addActionToMenu(ac->action(QStringLiteral("move_to_inactive_split_view")), menu) |
1222 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::SelectAll)), menu) |
1223 addActionToMenu(ac->action(QStringLiteral("invert_selection")), menu);
1224
1225 if (added) {
1226 menu->addSeparator();
1227 }
1228
1229 // Add "View" actions
1230 if (!GeneralSettings::showZoomSlider()) {
1231 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu);
1232 addActionToMenu(ac->action(QStringLiteral("view_zoom_reset")), menu);
1233 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu);
1234 menu->addSeparator();
1235 }
1236
1237 added = addActionToMenu(ac->action(QStringLiteral("show_preview")), menu) |
1238 addActionToMenu(ac->action(QStringLiteral("show_in_groups")), menu) |
1239 addActionToMenu(ac->action(QStringLiteral("show_hidden_files")), menu) |
1240 addActionToMenu(ac->action(QStringLiteral("additional_info")), menu) |
1241 addActionToMenu(ac->action(QStringLiteral("view_properties")), menu);
1242
1243 if (added) {
1244 menu->addSeparator();
1245 }
1246
1247 // Add a curated assortment of items from the "Tools" menu
1248 addActionToMenu(ac->action(QStringLiteral("show_filter_bar")), menu);
1249 addActionToMenu(ac->action(QStringLiteral("open_preferred_search_tool")), menu);
1250 addActionToMenu(ac->action(QStringLiteral("open_terminal")), menu);
1251
1252 menu->addSeparator();
1253
1254 // Add "Show Panels" menu
1255 addActionToMenu(ac->action(QStringLiteral("panels")), menu);
1256
1257 // Add "Settings" menu entries
1258 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::KeyBindings)), menu);
1259 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)), menu);
1260 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Preferences)), menu);
1261 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu);
1262
1263 // Add "Help" menu
1264 auto helpMenu = m_helpMenu->menu();
1265 helpMenu->setIcon(QIcon::fromTheme(QStringLiteral("system-help")));
1266 menu->addMenu(helpMenu);
1267 }
1268
1269 void DolphinMainWindow::updateToolBar()
1270 {
1271 if (!menuBar()->isVisible()) {
1272 createControlButton();
1273 }
1274 }
1275
1276 void DolphinMainWindow::slotControlButtonDeleted()
1277 {
1278 m_controlButton = nullptr;
1279 m_updateToolBarTimer->start();
1280 }
1281
1282 void DolphinMainWindow::slotPlaceActivated(const QUrl& url)
1283 {
1284 DolphinViewContainer* view = activeViewContainer();
1285
1286 if (view->url() == url) {
1287 // We can end up here if the user clicked a device in the Places Panel
1288 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1289 reloadView();
1290 } else {
1291 changeUrl(url);
1292 }
1293 }
1294
1295 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1296 {
1297 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1298 }
1299
1300 void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
1301 {
1302 DolphinViewContainer* oldViewContainer = m_activeViewContainer;
1303 Q_ASSERT(viewContainer);
1304
1305 m_activeViewContainer = viewContainer;
1306
1307 if (oldViewContainer) {
1308 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
1309 toggleSearchAction->disconnect(oldViewContainer);
1310
1311 // Disconnect all signals between the old view container (container,
1312 // view and url navigator) and main window.
1313 oldViewContainer->disconnect(this);
1314 oldViewContainer->view()->disconnect(this);
1315 oldViewContainer->urlNavigator()->disconnect(this);
1316 if (GeneralSettings::locationInToolbar()) {
1317 oldViewContainer->disconnectUrlNavigator();
1318 }
1319
1320 // except the requestItemInfo so that on hover the information panel can still be updated
1321 connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
1322 this, &DolphinMainWindow::requestItemInfo);
1323 }
1324
1325 if (GeneralSettings::locationInToolbar()) {
1326 viewContainer->connectUrlNavigator(static_cast<DolphinUrlNavigatorWidgetAction *>
1327 (actionCollection()->action(QStringLiteral("url_navigator")))->urlNavigator());
1328 }
1329 connectViewSignals(viewContainer);
1330
1331 m_actionHandler->setCurrentView(viewContainer->view());
1332
1333 updateHistory();
1334 updateFileAndEditActions();
1335 updatePasteAction();
1336 updateViewActions();
1337 updateGoActions();
1338 updateSearchAction();
1339
1340 const QUrl url = viewContainer->url();
1341 Q_EMIT urlChanged(url);
1342 }
1343
1344 void DolphinMainWindow::tabCountChanged(int count)
1345 {
1346 const bool enableTabActions = (count > 1);
1347 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1348 actionCollection()->action(QStringLiteral("activate_tab_%1").arg(i))->setEnabled(enableTabActions);
1349 }
1350 actionCollection()->action(QStringLiteral("activate_last_tab"))->setEnabled(enableTabActions);
1351 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1352 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1353 }
1354
1355 void DolphinMainWindow::updateWindowTitle()
1356 {
1357 const QString newTitle = m_activeViewContainer->captionWindowTitle();
1358 if (windowTitle() != newTitle) {
1359 setWindowTitle(newTitle);
1360 }
1361 }
1362
1363 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
1364 {
1365 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1366 setViewsToHomeIfMountPathOpen(mountPath);
1367 });
1368
1369 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1370 m_tearDownFromPlacesRequested = true;
1371 m_terminalPanel->goHome();
1372 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1373 } else {
1374 m_placesPanel->proceedWithTearDown();
1375 }
1376 }
1377
1378 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
1379 {
1380 connect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, this, [this, mountPath]() {
1381 setViewsToHomeIfMountPathOpen(mountPath);
1382 });
1383
1384 if (m_terminalPanel && m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1385 m_tearDownFromPlacesRequested = false;
1386 m_terminalPanel->goHome();
1387 }
1388 }
1389
1390 void DolphinMainWindow::setViewsToHomeIfMountPathOpen(const QString& mountPath)
1391 {
1392 const QVector<DolphinViewContainer*> theViewContainers = viewContainers();
1393 for (DolphinViewContainer *viewContainer : theViewContainers) {
1394 if (viewContainer && viewContainer->url().toLocalFile().startsWith(mountPath)) {
1395 viewContainer->setUrl(QUrl::fromLocalFile(QDir::homePath()));
1396 }
1397 }
1398 disconnect(m_placesPanel, &PlacesPanel::storageTearDownSuccessful, nullptr, nullptr);
1399 }
1400
1401 void DolphinMainWindow::setupActions()
1402 {
1403 // setup 'File' menu
1404 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
1405 QMenu* menu = m_newFileMenu->menu();
1406 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1407 menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1408 m_newFileMenu->setDelayed(false);
1409 connect(menu, &QMenu::aboutToShow,
1410 this, &DolphinMainWindow::updateNewMenu);
1411
1412 QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1413 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1414 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1415 newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1416 "window just like this one with the current location and view."
1417 "<nl/>You can drag and drop items between windows."));
1418 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1419
1420 QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1421 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1422 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1423 newTab->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1424 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1425 "A tab is an additional view within this window. "
1426 "You can drag and drop items between tabs."));
1427 actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
1428 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1429
1430 QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places"));
1431 addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new")));
1432 addToPlaces->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places"));
1433 addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder "
1434 "to the Places panel."));
1435 connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces);
1436
1437 QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1438 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1439 closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1440 "currently viewed tab. If no more tabs are left this window "
1441 "will close instead."));
1442
1443 QAction* quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1444 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1445
1446 // setup 'Edit' menu
1447 KStandardAction::undo(this,
1448 &DolphinMainWindow::undo,
1449 actionCollection());
1450
1451 // i18n: This will be the last paragraph for the whatsthis for all three:
1452 // Cut, Copy and Paste
1453 const QString cutCopyPastePara = xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1454 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1455 "applications and are among the most used commands. That's why their "
1456 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1457 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1458 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1459 QAction* cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1460 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1461 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1462 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1463 "the clipboard to a new location. The items will be removed from their "
1464 "initial location.") + cutCopyPastePara);
1465 QAction* copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1466 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1467 "items in your current selection to the <emphasis>clipboard</emphasis>."
1468 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1469 "from the clipboard to a new location.") + cutCopyPastePara);
1470 QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1471 // The text of the paste-action is modified dynamically by Dolphin
1472 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1473 // due to the long text, the text "Paste" is used:
1474 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1475 paste->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1476 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1477 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1478 "action they are removed from their old location.") + cutCopyPastePara);
1479
1480 QAction* copyToOtherViewAction = actionCollection()->addAction(QStringLiteral("copy_to_inactive_split_view"));
1481 copyToOtherViewAction->setText(i18nc("@action:inmenu", "Copy to Inactive Split View"));
1482 copyToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Copy", "This copies the selected items from "
1483 "the <emphasis>active</emphasis> view to the inactive split view."));
1484 copyToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-copy")));
1485 copyToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Copy to Inactive Split View"));
1486 actionCollection()->setDefaultShortcut(copyToOtherViewAction, Qt::SHIFT + Qt::Key_F5 );
1487 connect(copyToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::copyToInactiveSplitView);
1488
1489 QAction* moveToOtherViewAction = actionCollection()->addAction(QStringLiteral("move_to_inactive_split_view"));
1490 moveToOtherViewAction->setText(i18nc("@action:inmenu", "Move to Inactive Split View"));
1491 moveToOtherViewAction->setWhatsThis(xi18nc("@info:whatsthis Move", "This moves the selected items from "
1492 "the <emphasis>active</emphasis> view to the inactive split view."));
1493 moveToOtherViewAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-cut")));
1494 moveToOtherViewAction->setIconText(i18nc("@action:inmenu Edit", "Move to Inactive Split View"));
1495 actionCollection()->setDefaultShortcut(moveToOtherViewAction, Qt::SHIFT + Qt::Key_F6 );
1496 connect(moveToOtherViewAction, &QAction::triggered, m_tabWidget, &DolphinTabWidget::moveToInactiveSplitView);
1497
1498 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1499 searchAction->setText(i18n("Search..."));
1500 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1501 searchAction->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1502 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1503 "There you can enter search terms and specify settings to find the "
1504 "objects you are looking for.</para><para>Use this help again on "
1505 "the find bar so we can have a look at it while the settings are "
1506 "explained.</para>"));
1507
1508 // toggle_search acts as a copy of the main searchAction to be used mainly
1509 // in the toolbar, with no default shortcut attached, to avoid messing with
1510 // existing workflows (search bar always open and Ctrl-F to focus)
1511 QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search"));
1512 toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar"));
1513 toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search"));
1514 toggleSearchAction->setIcon(searchAction->icon());
1515 toggleSearchAction->setToolTip(searchAction->toolTip());
1516 toggleSearchAction->setWhatsThis(searchAction->whatsThis());
1517 toggleSearchAction->setCheckable(true);
1518
1519 QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1520 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1521 "files and folders in the current location."));
1522
1523 QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1524 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1525 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1526 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1527 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1528 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A);
1529 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1530
1531 // setup 'View' menu
1532 // (note that most of it is set up in DolphinViewActionHandler)
1533
1534 QAction* split = actionCollection()->addAction(QStringLiteral("split_view"));
1535 split->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1536 "the folder view below into two autonomous views.</para><para>This "
1537 "way you can see two locations at once and move items between them "
1538 "quickly.</para>Click this again afterwards to recombine the views."));
1539 actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
1540 connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1541
1542 QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1543 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL + Qt::Key_S);
1544 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1545 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1546 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1547 stashSplit->setCheckable(false);
1548 stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1549 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1550
1551 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1552
1553 QAction* stop = actionCollection()->addAction(QStringLiteral("stop"));
1554 stop->setText(i18nc("@action:inmenu View", "Stop"));
1555 stop->setToolTip(i18nc("@info", "Stop loading"));
1556 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1557 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1558 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1559
1560 KToggleAction* locationInToolbar = actionCollection()->add<KToggleAction>(QStringLiteral("location_in_toolbar"));
1561 locationInToolbar->setText(i18nc("@action:inmenu Navigation Bar", "Location in Toolbar"));
1562 locationInToolbar->setWhatsThis(xi18nc("@info:whatsthis",
1563 "This toggles between showing the <emphasis>path</emphasis> in the "
1564 "<emphasis>Location Bar</emphasis> and in the <emphasis>Toolbar</emphasis>."));
1565 actionCollection()->setDefaultShortcut(locationInToolbar, Qt::Key_F12);
1566 locationInToolbar->setChecked(GeneralSettings::locationInToolbar());
1567 connect(locationInToolbar, &KToggleAction::triggered, this, &DolphinMainWindow::toggleLocationInToolbar);
1568 DolphinUrlNavigator::addToContextMenu(locationInToolbar);
1569
1570 KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1571 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1572 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1573 "This toggles the <emphasis>Location Bar</emphasis> to be "
1574 "editable so you can directly enter a location you want to go to.<nl/>"
1575 "You can also switch to editing by clicking to the right of the "
1576 "location and switch back by confirming the edited location."));
1577 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1578 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1579
1580 QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1581 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1582 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1583 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1584 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1585 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1586 "This switches to editing the location and selects it "
1587 "so you can quickly enter a different location."));
1588 actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL + Qt::Key_L);
1589 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
1590
1591 // setup 'Go' menu
1592 {
1593 QScopedPointer<QAction> backAction(KStandardAction::back(nullptr, nullptr, nullptr));
1594 m_backAction = new KToolBarPopupAction(backAction->icon(), backAction->text(), actionCollection());
1595 m_backAction->setObjectName(backAction->objectName());
1596 m_backAction->setShortcuts(backAction->shortcuts());
1597 }
1598 m_backAction->setDelayed(true);
1599 m_backAction->setStickyMenu(false);
1600 connect(m_backAction, &QAction::triggered, this, &DolphinMainWindow::goBack);
1601 connect(m_backAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowBackPopupMenu);
1602 connect(m_backAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoBack);
1603 actionCollection()->addAction(m_backAction->objectName(), m_backAction);
1604
1605 auto backShortcuts = m_backAction->shortcuts();
1606 backShortcuts.append(QKeySequence(Qt::Key_Backspace));
1607 actionCollection()->setDefaultShortcuts(m_backAction, backShortcuts);
1608
1609 DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
1610 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
1611 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab,
1612 recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
1613 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab,
1614 m_tabWidget, &DolphinTabWidget::restoreClosedTab);
1615 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged,
1616 this, &DolphinMainWindow::closedTabsCountChanged);
1617
1618 QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1619 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
1620 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1621 "This returns you to the previously closed tab."));
1622 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL + Qt::SHIFT + Qt::Key_T);
1623 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1624 undoCloseTab->setEnabled(false);
1625 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
1626
1627 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
1628 undoAction->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1629 "the last change you made to files or folders.<nl/>"
1630 "Such changes include <interface>creating, renaming</interface> "
1631 "and <interface>moving</interface> them to a different location "
1632 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1633 "be undone will ask for your confirmation."));
1634 undoAction->setEnabled(false); // undo should be disabled by default
1635
1636 {
1637 QScopedPointer<QAction> forwardAction(KStandardAction::forward(nullptr, nullptr, nullptr));
1638 m_forwardAction = new KToolBarPopupAction(forwardAction->icon(), forwardAction->text(), actionCollection());
1639 m_forwardAction->setObjectName(forwardAction->objectName());
1640 m_forwardAction->setShortcuts(forwardAction->shortcuts());
1641 }
1642 m_forwardAction->setDelayed(true);
1643 m_forwardAction->setStickyMenu(false);
1644 connect(m_forwardAction, &QAction::triggered, this, &DolphinMainWindow::goForward);
1645 connect(m_forwardAction->menu(), &QMenu::aboutToShow, this, &DolphinMainWindow::slotAboutToShowForwardPopupMenu);
1646 connect(m_forwardAction->menu(), &QMenu::triggered, this, &DolphinMainWindow::slotGoForward);
1647 actionCollection()->addAction(m_forwardAction->objectName(), m_forwardAction);
1648 actionCollection()->setDefaultShortcuts(m_forwardAction, m_forwardAction->shortcuts());
1649
1650 // enable middle-click to open in a new tab
1651 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
1652 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotBackForwardActionMiddleClicked);
1653 m_backAction->menu()->installEventFilter(middleClickEventFilter);
1654 m_forwardAction->menu()->installEventFilter(middleClickEventFilter);
1655 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
1656 QAction* homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
1657 homeAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1658 "<filename>Home</filename> folder.<nl/>Every user account "
1659 "has their own <filename>Home</filename> that contains their data "
1660 "including folders that contain personal application data."));
1661
1662 // setup 'Tools' menu
1663 QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1664 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1665 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1666 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1667 "There you can enter a text to filter the files and folders currently displayed. "
1668 "Only those that contain the text in their name will be kept in view."));
1669 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1670 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL + Qt::Key_I, Qt::Key_Slash});
1671 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1672
1673 QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
1674 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1675 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1676 compareFiles->setEnabled(false);
1677 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
1678
1679 QAction* openPreferredSearchTool = actionCollection()->addAction(QStringLiteral("open_preferred_search_tool"));
1680 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
1681 openPreferredSearchTool->setWhatsThis(xi18nc("@info:whatsthis",
1682 "<para>This opens a preferred search tool for the viewed location.</para>"
1683 "<para>Use <emphasis>More Search Tools</emphasis> menu to configure it.</para>"));
1684 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
1685 actionCollection()->setDefaultShortcut(openPreferredSearchTool, Qt::CTRL + Qt::SHIFT + Qt::Key_F);
1686 connect(openPreferredSearchTool, &QAction::triggered, this, &DolphinMainWindow::openPreferredSearchTool);
1687
1688 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1689 QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1690 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1691 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1692 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1693 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1694 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1695 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4);
1696 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1697
1698 #ifdef HAVE_TERMINAL
1699 QAction* focusTerminalPanel = actionCollection()->addAction(QStringLiteral("focus_terminal_panel"));
1700 focusTerminalPanel->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
1701 focusTerminalPanel->setIcon(QIcon::fromTheme(QStringLiteral("swap-panels")));
1702 actionCollection()->setDefaultShortcut(focusTerminalPanel, Qt::CTRL + Qt::SHIFT + Qt::Key_F4);
1703 connect(focusTerminalPanel, &QAction::triggered, this, &DolphinMainWindow::focusTerminalPanel);
1704 #endif
1705 }
1706
1707 // setup 'Bookmarks' menu
1708 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1709 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1710 // Make the toolbar button version work properly on click
1711 bookmarkMenu->setDelayed(false);
1712 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
1713 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
1714
1715 // setup 'Settings' menu
1716 KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1717 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
1718 "This switches between having a <emphasis>Menubar</emphasis> "
1719 "and having a <interface>Control</interface> button. Both "
1720 "contain mostly the same commands and configuration options."));
1721 connect(showMenuBar, &KToggleAction::triggered, // Fixes #286822
1722 this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection);
1723 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
1724
1725 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1726 m_helpMenu = new KHelpMenu(nullptr);
1727 m_helpMenu->menu()->installEventFilter(this);
1728 // remove duplicate shortcuts
1729 m_helpMenu->action(KHelpMenu::menuHelpContents)->setShortcut(QKeySequence());
1730 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setShortcut(QKeySequence());
1731
1732 // not in menu actions
1733 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
1734 nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab));
1735
1736 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
1737 prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
1738
1739 for (int i = 0; i < MaxActivateTabShortcuts; ++i) {
1740 QAction* activateTab = actionCollection()->addAction(QStringLiteral("activate_tab_%1").arg(i));
1741 activateTab->setText(i18nc("@action:inmenu", "Activate Tab %1", i + 1));
1742 activateTab->setEnabled(false);
1743 connect(activateTab, &QAction::triggered, this, [this, i]() { m_tabWidget->activateTab(i); });
1744
1745 // only add default shortcuts for the first 9 tabs regardless of MaxActivateTabShortcuts
1746 if (i < 9) {
1747 actionCollection()->setDefaultShortcut(activateTab, QStringLiteral("Alt+%1").arg(i + 1));
1748 }
1749 }
1750
1751 QAction* activateLastTab = actionCollection()->addAction(QStringLiteral("activate_last_tab"));
1752 activateLastTab->setText(i18nc("@action:inmenu", "Activate Last Tab"));
1753 activateLastTab->setEnabled(false);
1754 connect(activateLastTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateLastTab);
1755 actionCollection()->setDefaultShortcut(activateLastTab, Qt::ALT + Qt::Key_0);
1756
1757 QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1758 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
1759 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1760 activateNextTab->setEnabled(false);
1761 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
1762 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
1763
1764 QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1765 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1766 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1767 activatePrevTab->setEnabled(false);
1768 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
1769 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
1770
1771 auto *urlNavigatorWidgetAction = new DolphinUrlNavigatorWidgetAction(this);
1772 urlNavigatorWidgetAction->setText(i18nc("@action:inmenu auto-hide: "
1773 "Depending on the settings this Widget is blank/invisible.",
1774 "Url Navigator (auto-hide)"));
1775 actionCollection()->addAction(QStringLiteral("url_navigator"), urlNavigatorWidgetAction);
1776
1777 // for context menu
1778 QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
1779 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
1780 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1781 showTarget->setEnabled(false);
1782 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
1783
1784 QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1785 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1786 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1787 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1788
1789 QAction* openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1790 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1791 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1792 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1793
1794 QAction* openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1795 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1796 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1797 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
1798 }
1799
1800 void DolphinMainWindow::setupDockWidgets()
1801 {
1802 const bool lock = GeneralSettings::lockPanels();
1803
1804 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
1805 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1806 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1807 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1808 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1809 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", "This "
1810 "switches between having panels <emphasis>locked</emphasis> or "
1811 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1812 "dragged to the other side of the window and have a close "
1813 "button.<nl/>Locked panels are embedded more cleanly."));
1814 lockLayoutAction->setActive(lock);
1815 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
1816
1817 // Setup "Information"
1818 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1819 infoDock->setLocked(lock);
1820 infoDock->setObjectName(QStringLiteral("infoDock"));
1821 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1822
1823 #ifdef HAVE_BALOO
1824 InformationPanel* infoPanel = new InformationPanel(infoDock);
1825 infoPanel->setCustomContextMenuActions({lockLayoutAction});
1826 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
1827 infoDock->setWidget(infoPanel);
1828
1829 QAction* infoAction = infoDock->toggleViewAction();
1830 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel"));
1831
1832 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1833 connect(this, &DolphinMainWindow::urlChanged,
1834 infoPanel, &InformationPanel::setUrl);
1835 connect(this, &DolphinMainWindow::selectionChanged,
1836 infoPanel, &InformationPanel::setSelection);
1837 connect(this, &DolphinMainWindow::requestItemInfo,
1838 infoPanel, &InformationPanel::requestDelayedItemInfo);
1839 #endif
1840
1841 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1842 const QString panelWhatsThis = xi18nc("@info:whatsthis", "<para>To show or "
1843 "hide panels like this go to <interface>Control|Panels</interface> "
1844 "or <interface>View|Panels</interface>.</para>");
1845 #ifdef HAVE_BALOO
1846 actionCollection()->action(QStringLiteral("show_information_panel"))
1847 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1848 "<emphasis>information</emphasis> panel at the right side of the "
1849 "window.</para><para>The panel provides in-depth information "
1850 "about the items your mouse is hovering over or about the selected "
1851 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1852 "For single items a preview of their contents is provided.</para>"));
1853 #endif
1854 infoDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1855 "provides in-depth information about the items your mouse is "
1856 "hovering over or about the selected items. Otherwise it informs "
1857 "you about the currently viewed folder.<nl/>For single items a "
1858 "preview of their contents is provided.</para><para>You can configure "
1859 "which and how details are given here by right-clicking.</para>") + panelWhatsThis);
1860
1861 // Setup "Folders"
1862 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1863 foldersDock->setLocked(lock);
1864 foldersDock->setObjectName(QStringLiteral("foldersDock"));
1865 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1866 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1867 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
1868 foldersDock->setWidget(foldersPanel);
1869
1870 QAction* foldersAction = foldersDock->toggleViewAction();
1871 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel"));
1872
1873 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1874 connect(this, &DolphinMainWindow::urlChanged,
1875 foldersPanel, &FoldersPanel::setUrl);
1876 connect(foldersPanel, &FoldersPanel::folderActivated,
1877 this, &DolphinMainWindow::changeUrl);
1878 connect(foldersPanel, &FoldersPanel::folderMiddleClicked,
1879 this, &DolphinMainWindow::openNewTabAfterCurrentTab);
1880 connect(foldersPanel, &FoldersPanel::errorMessage,
1881 this, &DolphinMainWindow::showErrorMessage);
1882
1883 actionCollection()->action(QStringLiteral("show_folders_panel"))
1884 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1885 "<emphasis>folders</emphasis> panel at the left side of the window."
1886 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1887 "</emphasis> in a <emphasis>tree view</emphasis>."));
1888 foldersDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1889 "shows the folders of the <emphasis>file system</emphasis> in a "
1890 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1891 "there. Click the arrow to the left of a folder to see its subfolders. "
1892 "This allows quick switching between any folders.</para>") + panelWhatsThis);
1893
1894 // Setup "Terminal"
1895 #ifdef HAVE_TERMINAL
1896 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1897 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1898 terminalDock->setLocked(lock);
1899 terminalDock->setObjectName(QStringLiteral("terminalDock"));
1900 m_terminalPanel = new TerminalPanel(terminalDock);
1901 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
1902 terminalDock->setWidget(m_terminalPanel);
1903
1904 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
1905 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
1906 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
1907 m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
1908 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
1909 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
1910
1911 QAction* terminalAction = terminalDock->toggleViewAction();
1912 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
1913
1914 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1915 connect(this, &DolphinMainWindow::urlChanged,
1916 m_terminalPanel, &TerminalPanel::setUrl);
1917
1918 if (GeneralSettings::version() < 200) {
1919 terminalDock->hide();
1920 }
1921
1922 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1923 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1924 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1925 "<nl/>The location in the terminal will always match the folder "
1926 "view so you can navigate using either.</para><para>The terminal "
1927 "panel is not needed for basic computer usage but can be useful "
1928 "for advanced tasks. To learn more about terminals use the help "
1929 "in a standalone terminal application like Konsole.</para>"));
1930 terminalDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1931 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1932 "normal terminal but will match the location of the folder view "
1933 "so you can navigate using either.</para><para>The terminal panel "
1934 "is not needed for basic computer usage but can be useful for "
1935 "advanced tasks. To learn more about terminals use the help in a "
1936 "standalone terminal application like Konsole.</para>") + panelWhatsThis);
1937 }
1938 #endif
1939
1940 if (GeneralSettings::version() < 200) {
1941 infoDock->hide();
1942 foldersDock->hide();
1943 }
1944
1945 // Setup "Places"
1946 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1947 placesDock->setLocked(lock);
1948 placesDock->setObjectName(QStringLiteral("placesDock"));
1949 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1950
1951 m_placesPanel = new PlacesPanel(placesDock);
1952 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
1953 placesDock->setWidget(m_placesPanel);
1954
1955 QAction *placesAction = placesDock->toggleViewAction();
1956 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
1957
1958 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1959 connect(m_placesPanel, &PlacesPanel::placeActivated,
1960 this, &DolphinMainWindow::slotPlaceActivated);
1961 connect(m_placesPanel, &PlacesPanel::placeMiddleClicked,
1962 this, &DolphinMainWindow::openNewTabAfterCurrentTab);
1963 connect(m_placesPanel, &PlacesPanel::errorMessage,
1964 this, &DolphinMainWindow::showErrorMessage);
1965 connect(this, &DolphinMainWindow::urlChanged,
1966 m_placesPanel, &PlacesPanel::setUrl);
1967 connect(placesDock, &DolphinDockWidget::visibilityChanged,
1968 &DolphinUrlNavigator::slotPlacesPanelVisibilityChanged);
1969 connect(this, &DolphinMainWindow::settingsChanged,
1970 m_placesPanel, &PlacesPanel::readSettings);
1971 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
1972 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
1973 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
1974 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
1975 DolphinUrlNavigator::slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
1976
1977 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1978 actionShowAllPlaces->setCheckable(true);
1979 actionShowAllPlaces->setDisabled(true);
1980 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1981 "all places in the places panel that have been hidden. They will "
1982 "appear semi-transparent unless you uncheck their hide property."));
1983
1984 connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){
1985 actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1986 m_placesPanel->showHiddenEntries(checked);
1987 });
1988
1989 connect(m_placesPanel, &PlacesPanel::showHiddenEntriesChanged, this, [actionShowAllPlaces] (bool checked){
1990 actionShowAllPlaces->setChecked(checked);
1991 actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden")));
1992 });
1993
1994 actionCollection()->action(QStringLiteral("show_places_panel"))
1995 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1996 "<emphasis>places</emphasis> panel at the left side of the window."
1997 "</para><para>It allows you to go to locations you have "
1998 "bookmarked and to access disk or media attached to the computer "
1999 "or to the network. It also contains sections to find recently "
2000 "saved files or files of a certain type.</para>"));
2001 placesDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2002 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
2003 "you have bookmarked and to access disk or media attached to the "
2004 "computer or to the network. It also contains sections to find "
2005 "recently saved files or files of a certain type.</para><para>"
2006 "Click on an entry to go there. Click with the right mouse button "
2007 "instead to open any entry in a new tab or new window.</para>"
2008 "<para>New entries can be added by dragging folders onto this panel. "
2009 "Right-click any section or entry to hide it. Right-click an empty "
2010 "space on this panel and select <interface>Show Hidden Places"
2011 "</interface> to display it again.</para>") + panelWhatsThis);
2012
2013 // Add actions into the "Panels" menu
2014 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Show Panels"), this);
2015 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
2016 panelsMenu->setIcon(QIcon::fromTheme(QStringLiteral("view-sidetree")));
2017 panelsMenu->setDelayed(false);
2018 const KActionCollection* ac = actionCollection();
2019 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
2020 #ifdef HAVE_BALOO
2021 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
2022 #endif
2023 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
2024 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
2025 panelsMenu->addSeparator();
2026 panelsMenu->addAction(actionShowAllPlaces);
2027 panelsMenu->addAction(lockLayoutAction);
2028
2029 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{
2030 actionShowAllPlaces->setEnabled(m_placesPanel->hiddenListCount());
2031 });
2032 }
2033
2034
2035 void DolphinMainWindow::updateFileAndEditActions()
2036 {
2037 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
2038 const KActionCollection* col = actionCollection();
2039 KFileItemListProperties capabilitiesSource(list);
2040
2041 QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places"));
2042 QAction* copyToOtherViewAction = col->action(QStringLiteral("copy_to_inactive_split_view"));
2043 QAction* moveToOtherViewAction = col->action(QStringLiteral("move_to_inactive_split_view"));
2044 QAction* copyLocation = col->action(QString("copy_location"));
2045
2046 if (list.isEmpty()) {
2047 stateChanged(QStringLiteral("has_no_selection"));
2048
2049 addToPlacesAction->setEnabled(true);
2050 copyToOtherViewAction->setEnabled(false);
2051 moveToOtherViewAction->setEnabled(false);
2052 copyLocation->setEnabled(false);
2053 } else {
2054 stateChanged(QStringLiteral("has_selection"));
2055
2056 QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
2057 QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
2058 QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
2059 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
2060 QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
2061 QAction* showTarget = col->action(QStringLiteral("show_target"));
2062 QAction* duplicateAction = col->action(QStringLiteral("duplicate")); // see DolphinViewActionHandler
2063
2064 if (list.length() == 1 && list.first().isDir()) {
2065 addToPlacesAction->setEnabled(true);
2066 } else {
2067 addToPlacesAction->setEnabled(false);
2068 }
2069
2070 if (m_tabWidget->currentTabPage()->splitViewEnabled()) {
2071 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2072 KFileItem capabilitiesDestination;
2073
2074 if (tabPage->primaryViewActive()) {
2075 capabilitiesDestination = tabPage->secondaryViewContainer()->url();
2076 } else {
2077 capabilitiesDestination = tabPage->primaryViewContainer()->url();
2078 }
2079
2080 copyToOtherViewAction->setEnabled(capabilitiesDestination.isWritable());
2081 moveToOtherViewAction->setEnabled(capabilitiesSource.supportsMoving() && capabilitiesDestination.isWritable());
2082 } else {
2083 copyToOtherViewAction->setEnabled(false);
2084 moveToOtherViewAction->setEnabled(false);
2085 }
2086
2087 const bool enableMoveToTrash = capabilitiesSource.isLocal() && capabilitiesSource.supportsMoving();
2088
2089 renameAction->setEnabled(capabilitiesSource.supportsMoving());
2090 moveToTrashAction->setEnabled(enableMoveToTrash);
2091 deleteAction->setEnabled(capabilitiesSource.supportsDeleting());
2092 deleteWithTrashShortcut->setEnabled(capabilitiesSource.supportsDeleting() && !enableMoveToTrash);
2093 cutAction->setEnabled(capabilitiesSource.supportsMoving());
2094 copyLocation->setEnabled(list.length() == 1);
2095 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
2096 duplicateAction->setEnabled(capabilitiesSource.supportsWriting());
2097 }
2098 }
2099
2100 void DolphinMainWindow::updateViewActions()
2101 {
2102 m_actionHandler->updateViewActions();
2103
2104 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
2105 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
2106
2107 updateSplitAction();
2108
2109 QAction* editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
2110 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
2111 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
2112 }
2113
2114 void DolphinMainWindow::updateGoActions()
2115 {
2116 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
2117 const QUrl currentUrl = m_activeViewContainer->url();
2118 // I think this is one of the best places to firstly be confronted
2119 // with a file system and its hierarchy. Talking about the root
2120 // directory might seem too much here but it is the question that
2121 // naturally arises in this context.
2122 goUpAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
2123 "the folder that contains the currently viewed one.</para>"
2124 "<para>All files and folders are organized in a hierarchical "
2125 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
2126 "a directory that contains all data connected to this computer"
2127 "—the <emphasis>root directory</emphasis>.</para>"));
2128 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
2129 }
2130
2131 void DolphinMainWindow::createControlButton()
2132 {
2133 if (m_controlButton) {
2134 return;
2135 }
2136 Q_ASSERT(!m_controlButton);
2137
2138 m_controlButton = new QToolButton(this);
2139 m_controlButton->setAccessibleName(i18nc("@action:intoolbar", "Control"));
2140 m_controlButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
2141 m_controlButton->setToolTip(i18nc("@action", "Show menu"));
2142 m_controlButton->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis);
2143 m_controlButton->setPopupMode(QToolButton::InstantPopup);
2144
2145 QMenu* controlMenu = new QMenu(m_controlButton);
2146 connect(controlMenu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateControlMenu);
2147 controlMenu->installEventFilter(this);
2148
2149 m_controlButton->setMenu(controlMenu);
2150
2151 toolBar()->addWidget(m_controlButton);
2152 connect(toolBar(), &KToolBar::iconSizeChanged,
2153 m_controlButton, &QToolButton::setIconSize);
2154
2155 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
2156 // gets edited. In this case we must add them again. The adding is done asynchronously by
2157 // m_updateToolBarTimer.
2158 connect(m_controlButton, &QToolButton::destroyed, this, &DolphinMainWindow::slotControlButtonDeleted);
2159 m_updateToolBarTimer = new QTimer(this);
2160 m_updateToolBarTimer->setInterval(500);
2161 connect(m_updateToolBarTimer, &QTimer::timeout, this, &DolphinMainWindow::updateToolBar);
2162 }
2163
2164 void DolphinMainWindow::deleteControlButton()
2165 {
2166 delete m_controlButton;
2167 m_controlButton = nullptr;
2168
2169 delete m_updateToolBarTimer;
2170 m_updateToolBarTimer = nullptr;
2171 }
2172
2173 bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu)
2174 {
2175 Q_ASSERT(action);
2176 Q_ASSERT(menu);
2177
2178 const KToolBar* toolBarWidget = toolBar();
2179 const auto associatedWidgets = action->associatedWidgets();
2180 for (const QWidget* widget : associatedWidgets) {
2181 if (widget == toolBarWidget) {
2182 return false;
2183 }
2184 }
2185
2186 menu->addAction(action);
2187 return true;
2188 }
2189
2190 void DolphinMainWindow::refreshViews()
2191 {
2192 m_tabWidget->refreshViews();
2193
2194 if (GeneralSettings::modifiedStartupSettings()) {
2195 // The startup settings have been changed by the user (see bug #254947).
2196 // Synchronize the split-view setting with the active view:
2197 const bool splitView = GeneralSettings::splitView();
2198 m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView);
2199 updateSplitAction();
2200 updateWindowTitle();
2201 }
2202
2203 Q_EMIT settingsChanged();
2204 }
2205
2206 void DolphinMainWindow::clearStatusBar()
2207 {
2208 m_activeViewContainer->statusBar()->resetToDefaultText();
2209 }
2210
2211 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
2212 {
2213 connect(container, &DolphinViewContainer::showFilterBarChanged,
2214 this, &DolphinMainWindow::updateFilterBarAction);
2215 connect(container, &DolphinViewContainer::writeStateChanged,
2216 this, &DolphinMainWindow::slotWriteStateChanged);
2217 connect(container, &DolphinViewContainer::searchModeEnabledChanged,
2218 this, &DolphinMainWindow::updateSearchAction);
2219
2220 const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
2221 connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled);
2222
2223 const DolphinView* view = container->view();
2224 connect(view, &DolphinView::selectionChanged,
2225 this, &DolphinMainWindow::slotSelectionChanged);
2226 connect(view, &DolphinView::requestItemInfo,
2227 this, &DolphinMainWindow::requestItemInfo);
2228 connect(view, &DolphinView::tabRequested,
2229 this, &DolphinMainWindow::openNewTab);
2230 connect(view, &DolphinView::requestContextMenu,
2231 this, &DolphinMainWindow::openContextMenu);
2232 connect(view, &DolphinView::directoryLoadingStarted,
2233 this, &DolphinMainWindow::enableStopAction);
2234 connect(view, &DolphinView::directoryLoadingCompleted,
2235 this, &DolphinMainWindow::disableStopAction);
2236 connect(view, &DolphinView::directoryLoadingCompleted,
2237 this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
2238 connect(view, &DolphinView::goBackRequested,
2239 this, &DolphinMainWindow::goBack);
2240 connect(view, &DolphinView::goForwardRequested,
2241 this, &DolphinMainWindow::goForward);
2242 connect(view, &DolphinView::urlActivated,
2243 this, &DolphinMainWindow::handleUrl);
2244 connect(view, &DolphinView::goUpRequested,
2245 this, &DolphinMainWindow::goUp);
2246
2247 const KUrlNavigator* navigator = container->urlNavigator();
2248 connect(navigator, &KUrlNavigator::urlChanged,
2249 this, &DolphinMainWindow::changeUrl);
2250 connect(navigator, &KUrlNavigator::editableStateChanged,
2251 this, &DolphinMainWindow::slotEditableStateChanged);
2252 connect(navigator, &KUrlNavigator::tabRequested,
2253 this, &DolphinMainWindow::openNewTabAfterLastTab);
2254
2255 connect(container->urlNavigatorInternal(), &KUrlNavigator::historyChanged,
2256 this, &DolphinMainWindow::updateHistory);
2257 }
2258
2259 void DolphinMainWindow::updateSplitAction()
2260 {
2261 QAction* splitAction = actionCollection()->action(QStringLiteral("split_view"));
2262 const DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2263 if (tabPage->splitViewEnabled()) {
2264 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2265 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2266 splitAction->setToolTip(i18nc("@info", "Close left view"));
2267 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2268 } else {
2269 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2270 splitAction->setToolTip(i18nc("@info", "Close right view"));
2271 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2272 }
2273 } else {
2274 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2275 splitAction->setToolTip(i18nc("@info", "Split view"));
2276 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2277 }
2278 }
2279
2280 bool DolphinMainWindow::isKompareInstalled() const
2281 {
2282 static bool initialized = false;
2283 static bool installed = false;
2284 if (!initialized) {
2285 // TODO: maybe replace this approach later by using a menu
2286 // plugin like kdiff3plugin.cpp
2287 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2288 initialized = true;
2289 }
2290 return installed;
2291 }
2292
2293 void DolphinMainWindow::createPanelAction(const QIcon& icon,
2294 const QKeySequence& shortcut,
2295 QAction* dockAction,
2296 const QString& actionName)
2297 {
2298 QAction* panelAction = actionCollection()->addAction(actionName);
2299 panelAction->setCheckable(true);
2300 panelAction->setChecked(dockAction->isChecked());
2301 panelAction->setText(dockAction->text());
2302 panelAction->setIcon(icon);
2303 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2304
2305 connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
2306 connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
2307 }
2308
2309 void DolphinMainWindow::setupWhatsThis()
2310 {
2311 // main widgets
2312 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2313 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2314 "configuration options. Left-click on any of the menus on this "
2315 "bar to see its contents.</para><para>The Menubar can be hidden "
2316 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2317 "most of its contents become available through a <interface>Control"
2318 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2319 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2320 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2321 "frequently used actions.</para><para>It is highly customizable. "
2322 "All items you see in the <interface>Control</interface> menu or "
2323 "in the <interface>Menubar</interface> can be placed on the "
2324 "Toolbar. Just right-click on it and select <interface>Configure "
2325 "Toolbars…</interface> or find this action in the <interface>"
2326 "Control</interface> or <interface>Settings</interface> menu."
2327 "</para><para>The location of the bar and the style of its "
2328 "buttons can also be changed in the right-click menu. Right-click "
2329 "a button if you want to show or hide its text.</para>"));
2330 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2331 "<para>Here you can see the <emphasis>folders</emphasis> and "
2332 "<emphasis>files</emphasis> that are at the location described in "
2333 "the <interface>Location Bar</interface> above. This area is the "
2334 "central part of this application where you navigate to the files "
2335 "you want to use.</para><para>For an elaborate and general "
2336 "introduction to this application <link "
2337 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2338 "click here</link>. This will open an introductory article from "
2339 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2340 "explanations of all the features of this <emphasis>view</emphasis> "
2341 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2342 "instead. This will open a page from the <emphasis>Handbook"
2343 "</emphasis> that covers the basics.</para>"));
2344
2345 // Settings menu
2346 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2347 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2348 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2349 "There you can set up key combinations to trigger an action when "
2350 "they are pressed simultaneously. All commands in this application can "
2351 "be triggered this way.</para>"));
2352 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2353 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2354 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2355 "<para>All items you see in the <interface>Control</interface> menu "
2356 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2357 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2358 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2359 "change a multitude of settings for this application. For an explanation "
2360 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2361 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2362
2363 // Help menu
2364 // The whatsthis has to be set for the m_helpMenu and for the
2365 // StandardAction separately because both are used in different locations.
2366 // m_helpMenu is only used for createControlButton() button.
2367
2368 // Links do not work within the Menubar so texts without links are provided there.
2369
2370 // i18n: If the external link isn't available in your language you should
2371 // probably state the external link language at least in brackets to not
2372 // frustrate the user. If there are multiple languages that the user might
2373 // know with a reasonable chance you might want to have 2 external links.
2374 // The same is in my opinion true for every external link you translate.
2375 const QString whatsThisHelpContents = xi18nc("@info:whatsthis handbook",
2376 "<para>This opens the Handbook for this application. It provides "
2377 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2378 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents))
2379 ->setWhatsThis(whatsThisHelpContents
2380 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2381 "<para>If you want more elaborate introductions to the "
2382 "different features of <emphasis>Dolphin</emphasis> "
2383 "go to the KDE UserBase Wiki.</para>"));
2384 m_helpMenu->action(KHelpMenu::menuHelpContents)->setWhatsThis(whatsThisHelpContents
2385 + xi18nc("@info:whatsthis second half of handbook text with link",
2386 "<para>If you want more elaborate introductions to the "
2387 "different features of <emphasis>Dolphin</emphasis> "
2388 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2389 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2390
2391 const QString whatsThisWhatsThis = xi18nc("@info:whatsthis whatsthis button",
2392 "<para>This is the button that invokes the help feature you are "
2393 "using right now! Click it, then click any component of this "
2394 "application to ask \"What's this?\" about it. The mouse cursor "
2395 "will change appearance if no help is available for a spot.</para>");
2396 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis))
2397 ->setWhatsThis(whatsThisWhatsThis
2398 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2399 "<para>There are two other ways to get help for this application: The "
2400 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2401 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2402 "article about <emphasis>File Management</emphasis> online."
2403 "</para><para>The \"What's this?\" help is "
2404 "missing in most other windows so don't get too used to this.</para>"));
2405 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setWhatsThis(whatsThisWhatsThis
2406 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2407 "<para>There are two other ways to get help: "
2408 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2409 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2410 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2411 "missing in most other windows so don't get too used to this.</para>"));
2412
2413 const QString whatsThisReportBug = xi18nc("@info:whatsthis","<para>This opens a "
2414 "window that will guide you through reporting errors or flaws "
2415 "in this application or in other KDE software.</para>");
2416 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug))
2417 ->setWhatsThis(whatsThisReportBug);
2418 m_helpMenu->action(KHelpMenu::menuReportBug)->setWhatsThis(whatsThisReportBug
2419 + xi18nc("@info:whatsthis second half of reportbug text with link",
2420 "<para>High-quality bug reports are much appreciated. To learn "
2421 "how to make your bug report as effective as possible "
2422 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2423 "click here</link>.</para>"));
2424
2425 const QString whatsThisDonate = xi18nc("@info:whatsthis","<para>This opens a "
2426 "<emphasis>web page</emphasis> where you can donate to "
2427 "support the continued work on this application and many "
2428 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2429 "<para>Donating is the easiest and fastest way to efficiently "
2430 "support KDE and its projects. KDE projects are available for "
2431 "free therefore your donation is needed to cover things that "
2432 "require money like servers, contributor meetings, etc.</para>"
2433 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2434 "organization behind the KDE community.</para>");
2435 actionCollection()->action(KStandardAction::name(KStandardAction::Donate))
2436 ->setWhatsThis(whatsThisDonate);
2437 m_helpMenu->action(KHelpMenu::menuDonate)->setWhatsThis(whatsThisDonate);
2438
2439 const QString whatsThisSwitchLanguage = xi18nc("@info:whatsthis",
2440 "With this you can change the language this application uses."
2441 "<nl/>You can even set secondary languages which will be used "
2442 "if texts are not available in your preferred language.");
2443 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))
2444 ->setWhatsThis(whatsThisSwitchLanguage);
2445 m_helpMenu->action(KHelpMenu::menuSwitchLanguage)->setWhatsThis(whatsThisSwitchLanguage);
2446
2447 const QString whatsThisAboutApp = xi18nc("@info:whatsthis","This opens a "
2448 "window that informs you about the version, license, "
2449 "used libraries and maintainers of this application.");
2450 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp))
2451 ->setWhatsThis(whatsThisAboutApp);
2452 m_helpMenu->action(KHelpMenu::menuAboutApp)->setWhatsThis(whatsThisAboutApp);
2453
2454 const QString whatsThisAboutKDE = xi18nc("@info:whatsthis","This opens a "
2455 "window with information about <emphasis>KDE</emphasis>. "
2456 "The KDE community are the people behind this free software."
2457 "<nl/>If you like using this application but don't know "
2458 "about KDE or want to see a cute dragon have a look!");
2459 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE))
2460 ->setWhatsThis(whatsThisAboutKDE);
2461 m_helpMenu->action(KHelpMenu::menuAboutKDE)->setWhatsThis(whatsThisAboutKDE);
2462 }
2463
2464 bool DolphinMainWindow::event(QEvent *event)
2465 {
2466 if (event->type() == QEvent::WhatsThisClicked) {
2467 event->accept();
2468 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2469 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2470 return true;
2471 }
2472 return KXmlGuiWindow::event(event);
2473 }
2474
2475 bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event)
2476 {
2477 Q_UNUSED(obj)
2478 if (event->type() == QEvent::WhatsThisClicked) {
2479 event->accept();
2480 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2481 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2482 return true;
2483 }
2484 return false;
2485 }
2486
2487 void DolphinMainWindow::focusTerminalPanel()
2488 {
2489 if (m_terminalPanel->isVisible()) {
2490 if (m_terminalPanel->terminalHasFocus()) {
2491 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2492 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2493 } else {
2494 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2495 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2496 }
2497 } else {
2498 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2499 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2500 }
2501 }
2502
2503 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2504 KIO::FileUndoManager::UiInterface()
2505 {
2506 }
2507
2508 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2509 {
2510 }
2511
2512 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2513 {
2514 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2515 if (mainWin) {
2516 DolphinViewContainer* container = mainWin->activeViewContainer();
2517 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2518 } else {
2519 KIO::FileUndoManager::UiInterface::jobError(job);
2520 }
2521 }
2522
2523 bool DolphinMainWindow::isUrlOpen(const QString& url)
2524 {
2525 return m_tabWidget->isUrlOpen(QUrl::fromUserInput((url)));
2526 }
2527