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