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