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