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