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