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