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