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