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