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