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