]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Fix DolphinMainWindow::viewContainers() to take into account split views
[dolphin.git] / src / dolphinmainwindow.cpp
1 /*
2 * SPDX-FileCopyrightText: 2006 Peter Penz <peter.penz19@gmail.com>
3 * SPDX-FileCopyrightText: 2006 Stefan Monov <logixoul@gmail.com>
4 * SPDX-FileCopyrightText: 2006 Cvetoslav Ludmiloff <ludmiloff@gmail.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0-or-later
7 */
8
9 #include "dolphinmainwindow.h"
10
11 #include "dolphinmainwindowadaptor.h"
12 #include "config-terminal.h"
13 #include "global.h"
14 #include "dolphinbookmarkhandler.h"
15 #include "dolphindockwidget.h"
16 #include "dolphincontextmenu.h"
17 #include "dolphinnewfilemenu.h"
18 #include "dolphinrecenttabsmenu.h"
19 #include "dolphinviewcontainer.h"
20 #include "dolphintabpage.h"
21 #include "middleclickactioneventfilter.h"
22 #include "panels/folders/folderspanel.h"
23 #include "panels/places/placesitemmodel.h"
24 #include "panels/places/placespanel.h"
25 #include "panels/information/informationpanel.h"
26 #include "panels/terminal/terminalpanel.h"
27 #include "settings/dolphinsettingsdialog.h"
28 #include "statusbar/dolphinstatusbar.h"
29 #include "views/dolphinviewactionhandler.h"
30 #include "views/dolphinremoteencoding.h"
31 #include "views/draganddrophelper.h"
32 #include "views/viewproperties.h"
33 #include "views/dolphinnewfilemenuobserver.h"
34 #include "dolphin_generalsettings.h"
35
36 #include <KActionCollection>
37 #include <KActionMenu>
38 #include <KAuthorized>
39 #include <KConfig>
40 #include <KConfigGui>
41 #include <KDualAction>
42 #include <KFileItemListProperties>
43 #include <KHelpMenu>
44 #include <KIO/CommandLauncherJob>
45 #include <KIO/JobUiDelegate>
46 #include <KIO/OpenFileManagerWindowJob>
47 #include <KIO/OpenUrlJob>
48 #include <KJobWidgets>
49 #include <KLocalizedString>
50 #include <KMessageBox>
51 #include <KNS3/KMoreToolsMenuFactory>
52 #include <KProtocolInfo>
53 #include <KProtocolManager>
54 #include <KShell>
55 #include <KStandardAction>
56 #include <KStartupInfo>
57 #include <KSycoca>
58 #include <KToggleAction>
59 #include <KToolBar>
60 #include <KToolBarPopupAction>
61 #include <KToolInvocation>
62 #include <KUrlComboBox>
63 #include <KUrlNavigator>
64 #include <KWindowSystem>
65
66 #include <QApplication>
67 #include <QClipboard>
68 #include <QCloseEvent>
69 #include <QDesktopServices>
70 #include <QDialog>
71 #include <QFileInfo>
72 #include <QLineEdit>
73 #include <QMenuBar>
74 #include <QPushButton>
75 #include <QShowEvent>
76 #include <QStandardPaths>
77 #include <QTimer>
78 #include <QToolButton>
79 #include <QWhatsThisClickedEvent>
80
81 namespace {
82 // Used for GeneralSettings::version() to determine whether
83 // an updated version of Dolphin is running.
84 const int CurrentDolphinVersion = 200;
85 // The maximum number of entries in the back/forward popup menu
86 const int MaxNumberOfNavigationentries = 12;
87 // The maximum number of "Activate Tab" shortcuts
88 const int MaxActivateTabShortcuts = 9;
89 }
90
91 DolphinMainWindow::DolphinMainWindow() :
92 KXmlGuiWindow(nullptr),
93 m_newFileMenu(nullptr),
94 m_helpMenu(nullptr),
95 m_tabWidget(nullptr),
96 m_activeViewContainer(nullptr),
97 m_actionHandler(nullptr),
98 m_remoteEncoding(nullptr),
99 m_settingsDialog(),
100 m_bookmarkHandler(nullptr),
101 m_controlButton(nullptr),
102 m_updateToolBarTimer(nullptr),
103 m_lastHandleUrlOpenJob(nullptr),
104 m_terminalPanel(nullptr),
105 m_placesPanel(nullptr),
106 m_tearDownFromPlacesRequested(false),
107 m_backAction(nullptr),
108 m_forwardAction(nullptr)
109 {
110 Q_INIT_RESOURCE(dolphin);
111
112 new MainWindowAdaptor(this);
113
114 #ifndef Q_OS_WIN
115 setWindowFlags(Qt::WindowContextHelpButtonHint);
116 #endif
117 setComponentName(QStringLiteral("dolphin"), QGuiApplication::applicationDisplayName());
118 setObjectName(QStringLiteral("Dolphin#"));
119
120 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage,
121 this, &DolphinMainWindow::showErrorMessage);
122
123 KIO::FileUndoManager* undoManager = KIO::FileUndoManager::self();
124 undoManager->setUiInterface(new UndoUiInterface());
125
126 connect(undoManager, QOverload<bool>::of(&KIO::FileUndoManager::undoAvailable),
127 this, &DolphinMainWindow::slotUndoAvailable);
128 connect(undoManager, &KIO::FileUndoManager::undoTextChanged,
129 this, &DolphinMainWindow::slotUndoTextChanged);
130 connect(undoManager, &KIO::FileUndoManager::jobRecordingStarted,
131 this, &DolphinMainWindow::clearStatusBar);
132 connect(undoManager, &KIO::FileUndoManager::jobRecordingFinished,
133 this, &DolphinMainWindow::showCommand);
134
135 GeneralSettings* generalSettings = GeneralSettings::self();
136 const bool firstRun = (generalSettings->version() < 200);
137 if (firstRun) {
138 generalSettings->setViewPropsTimestamp(QDateTime::currentDateTime());
139 }
140
141 setAcceptDrops(true);
142
143 m_tabWidget = new DolphinTabWidget(this);
144 m_tabWidget->setObjectName("tabWidget");
145 connect(m_tabWidget, &DolphinTabWidget::activeViewChanged,
146 this, &DolphinMainWindow::activeViewChanged);
147 connect(m_tabWidget, &DolphinTabWidget::tabCountChanged,
148 this, &DolphinMainWindow::tabCountChanged);
149 connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged,
150 this, &DolphinMainWindow::updateWindowTitle);
151 setCentralWidget(m_tabWidget);
152
153 setupActions();
154
155 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
156 connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar);
157 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory);
158
159 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
160 connect(this, &DolphinMainWindow::urlChanged,
161 m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
162
163 setupDockWidgets();
164
165 setupGUI(Keys | Save | Create | ToolBar);
166 stateChanged(QStringLiteral("new_file"));
167
168 QClipboard* clipboard = QApplication::clipboard();
169 connect(clipboard, &QClipboard::dataChanged,
170 this, &DolphinMainWindow::updatePasteAction);
171
172 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
173 showFilterBarAction->setChecked(generalSettings->filterBar());
174
175 if (firstRun) {
176 menuBar()->setVisible(false);
177 // Assure a proper default size if Dolphin runs the first time
178 resize(750, 500);
179 }
180
181 const bool showMenu = !menuBar()->isHidden();
182 QAction* showMenuBarAction = actionCollection()->action(KStandardAction::name(KStandardAction::ShowMenubar));
183 showMenuBarAction->setChecked(showMenu); // workaround for bug #171080
184 if (!showMenu) {
185 createControlButton();
186 }
187
188 // enable middle-click on back/forward/up to open in a new tab
189 auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
190 connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked);
191 toolBar()->installEventFilter(middleClickEventFilter);
192
193 setupWhatsThis();
194
195 connect(KSycoca::self(), QOverload<>::of(&KSycoca::databaseChanged), this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
196
197 QTimer::singleShot(0, this, &DolphinMainWindow::updateOpenPreferredSearchToolAction);
198 }
199
200 DolphinMainWindow::~DolphinMainWindow()
201 {
202 }
203
204 QVector<DolphinViewContainer*> DolphinMainWindow::viewContainers() const
205 {
206 QVector<DolphinViewContainer*> viewContainers;
207
208 for (int i = 0; i < m_tabWidget->count(); ++i) {
209 DolphinTabPage *tabPage = m_tabWidget->tabPageAt(i);
210
211 viewContainers << tabPage->primaryViewContainer();
212 if (tabPage->splitViewEnabled()) {
213 viewContainers << tabPage->secondaryViewContainer();
214 }
215 }
216 return viewContainers;
217 }
218
219 void DolphinMainWindow::openDirectories(const QList<QUrl>& dirs, bool splitView)
220 {
221 m_tabWidget->openDirectories(dirs, splitView);
222 }
223
224 void DolphinMainWindow::openDirectories(const QStringList& dirs, bool splitView)
225 {
226 openDirectories(QUrl::fromStringList(dirs), splitView);
227 }
228
229 void DolphinMainWindow::openFiles(const QList<QUrl>& files, bool splitView)
230 {
231 m_tabWidget->openFiles(files, splitView);
232 }
233
234 void DolphinMainWindow::openFiles(const QStringList& files, bool splitView)
235 {
236 openFiles(QUrl::fromStringList(files), splitView);
237 }
238
239 void DolphinMainWindow::activateWindow()
240 {
241 window()->setAttribute(Qt::WA_NativeWindow, true);
242 KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
243 KWindowSystem::activateWindow(window()->effectiveWinId());
244 }
245
246 void DolphinMainWindow::showCommand(CommandType command)
247 {
248 DolphinStatusBar* statusBar = m_activeViewContainer->statusBar();
249 switch (command) {
250 case KIO::FileUndoManager::Copy:
251 statusBar->setText(i18nc("@info:status", "Successfully copied."));
252 break;
253 case KIO::FileUndoManager::Move:
254 statusBar->setText(i18nc("@info:status", "Successfully moved."));
255 break;
256 case KIO::FileUndoManager::Link:
257 statusBar->setText(i18nc("@info:status", "Successfully linked."));
258 break;
259 case KIO::FileUndoManager::Trash:
260 statusBar->setText(i18nc("@info:status", "Successfully moved to trash."));
261 break;
262 case KIO::FileUndoManager::Rename:
263 statusBar->setText(i18nc("@info:status", "Successfully renamed."));
264 break;
265
266 case KIO::FileUndoManager::Mkdir:
267 statusBar->setText(i18nc("@info:status", "Created folder."));
268 break;
269
270 default:
271 break;
272 }
273 }
274
275 void DolphinMainWindow::pasteIntoFolder()
276 {
277 m_activeViewContainer->view()->pasteIntoFolder();
278 }
279
280 void DolphinMainWindow::changeUrl(const QUrl &url)
281 {
282 if (!KProtocolManager::supportsListing(url)) {
283 // The URL navigator only checks for validity, not
284 // if the URL can be listed. An error message is
285 // shown due to DolphinViewContainer::restoreView().
286 return;
287 }
288
289 m_activeViewContainer->setUrl(url);
290 updateFileAndEditActions();
291 updatePasteAction();
292 updateViewActions();
293 updateGoActions();
294
295 emit urlChanged(url);
296 }
297
298 void DolphinMainWindow::slotTerminalDirectoryChanged(const QUrl& url)
299 {
300 if (m_tearDownFromPlacesRequested && url == QUrl::fromLocalFile(QDir::homePath())) {
301 m_placesPanel->proceedWithTearDown();
302 m_tearDownFromPlacesRequested = false;
303 }
304
305 m_activeViewContainer->setAutoGrabFocus(false);
306 changeUrl(url);
307 m_activeViewContainer->setAutoGrabFocus(true);
308 }
309
310 void DolphinMainWindow::slotEditableStateChanged(bool editable)
311 {
312 KToggleAction* editableLocationAction =
313 static_cast<KToggleAction*>(actionCollection()->action(QStringLiteral("editable_location")));
314 editableLocationAction->setChecked(editable);
315 }
316
317 void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
318 {
319 updateFileAndEditActions();
320
321 const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
322
323 QAction* compareFilesAction = actionCollection()->action(QStringLiteral("compare_files"));
324 if (selectedUrlsCount == 2) {
325 compareFilesAction->setEnabled(isKompareInstalled());
326 } else {
327 compareFilesAction->setEnabled(false);
328 }
329
330 emit selectionChanged(selection);
331 }
332
333 void DolphinMainWindow::updateHistory()
334 {
335 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
336 const int index = urlNavigator->historyIndex();
337
338 QAction* backAction = actionCollection()->action(KStandardAction::name(KStandardAction::Back));
339 if (backAction) {
340 backAction->setToolTip(i18nc("@info", "Go back"));
341 backAction->setWhatsThis(i18nc("@info:whatsthis go back", "Return to the previously viewed folder."));
342 backAction->setEnabled(index < urlNavigator->historySize() - 1);
343 }
344
345 QAction* forwardAction = actionCollection()->action(KStandardAction::name(KStandardAction::Forward));
346 if (forwardAction) {
347 forwardAction->setToolTip(i18nc("@info", "Go forward"));
348 forwardAction->setWhatsThis(xi18nc("@info:whatsthis go forward",
349 "This undoes a <interface>Go|Back</interface> action."));
350 forwardAction->setEnabled(index > 0);
351 }
352 }
353
354 void DolphinMainWindow::updateFilterBarAction(bool show)
355 {
356 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
357 showFilterBarAction->setChecked(show);
358 }
359
360 void DolphinMainWindow::openNewMainWindow()
361 {
362 Dolphin::openNewWindow({m_activeViewContainer->url()}, this);
363 }
364
365 void DolphinMainWindow::openNewActivatedTab()
366 {
367 m_tabWidget->openNewActivatedTab();
368 }
369
370 void DolphinMainWindow::addToPlaces()
371 {
372 QUrl url;
373 QString name;
374
375 // If nothing is selected, act on the current dir
376 if (m_activeViewContainer->view()->selectedItems().isEmpty()) {
377 url = m_activeViewContainer->url();
378 name = m_activeViewContainer->placesText();
379 } else {
380 const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first();
381 url = dirToAdd.url();
382 name = dirToAdd.name();
383 }
384 if (url.isValid()) {
385 PlacesItemModel model;
386 QString icon;
387 if (m_activeViewContainer->isSearchModeEnabled()) {
388 icon = QStringLiteral("folder-saved-search-symbolic");
389 } else {
390 icon = KIO::iconNameForUrl(url);
391 }
392 model.createPlacesItem(name, url, icon);
393 }
394 }
395
396 void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement)
397 {
398 m_tabWidget->openNewTab(url, QUrl(), tabPlacement);
399 }
400
401 void DolphinMainWindow::openNewTabAfterCurrentTab(const QUrl& url)
402 {
403 m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterCurrentTab);
404 }
405
406 void DolphinMainWindow::openNewTabAfterLastTab(const QUrl& url)
407 {
408 m_tabWidget->openNewTab(url, QUrl(), DolphinTabWidget::AfterLastTab);
409 }
410
411 void DolphinMainWindow::openInNewTab()
412 {
413 const KFileItemList& list = m_activeViewContainer->view()->selectedItems();
414 bool tabCreated = false;
415
416 foreach (const KFileItem& item, list) {
417 const QUrl& url = DolphinView::openItemAsFolderUrl(item);
418 if (!url.isEmpty()) {
419 openNewTabAfterCurrentTab(url);
420 tabCreated = true;
421 }
422 }
423
424 // if no new tab has been created from the selection
425 // open the current directory in a new tab
426 if (!tabCreated) {
427 openNewTabAfterCurrentTab(m_activeViewContainer->url());
428 }
429 }
430
431 void DolphinMainWindow::openInNewWindow()
432 {
433 QUrl newWindowUrl;
434
435 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
436 if (list.isEmpty()) {
437 newWindowUrl = m_activeViewContainer->url();
438 } else if (list.count() == 1) {
439 const KFileItem& item = list.first();
440 newWindowUrl = DolphinView::openItemAsFolderUrl(item);
441 }
442
443 if (!newWindowUrl.isEmpty()) {
444 Dolphin::openNewWindow({newWindowUrl}, this);
445 }
446 }
447
448 void DolphinMainWindow::showTarget()
449 {
450 const auto link = m_activeViewContainer->view()->selectedItems().at(0);
451 const auto linkLocationDir = QFileInfo(link.localPath()).absoluteDir();
452 auto linkDestination = link.linkDest();
453 if (QFileInfo(linkDestination).isRelative()) {
454 linkDestination = linkLocationDir.filePath(linkDestination);
455 }
456 if (QFileInfo::exists(linkDestination)) {
457 KIO::highlightInFileManager({QUrl::fromLocalFile(linkDestination).adjusted(QUrl::StripTrailingSlash)});
458 } else {
459 m_activeViewContainer->showMessage(xi18nc("@info", "Could not access <filename>%1</filename>.", linkDestination),
460 DolphinViewContainer::Warning);
461 }
462 }
463
464 void DolphinMainWindow::showEvent(QShowEvent* event)
465 {
466 KXmlGuiWindow::showEvent(event);
467
468 if (!event->spontaneous()) {
469 m_activeViewContainer->view()->setFocus();
470 }
471 }
472
473 void DolphinMainWindow::closeEvent(QCloseEvent* event)
474 {
475 // Find out if Dolphin is closed directly by the user or
476 // by the session manager because the session is closed
477 bool closedByUser = true;
478 if (qApp->isSavingSession()) {
479 closedByUser = false;
480 }
481
482 if (m_tabWidget->count() > 1
483 && GeneralSettings::confirmClosingMultipleTabs()
484 && !GeneralSettings::rememberOpenedTabs()
485 && closedByUser) {
486 // Ask the user if he really wants to quit and close all tabs.
487 // Open a confirmation dialog with 3 buttons:
488 // QDialogButtonBox::Yes -> Quit
489 // QDialogButtonBox::No -> Close only the current tab
490 // QDialogButtonBox::Cancel -> do nothing
491 QDialog *dialog = new QDialog(this, Qt::Dialog);
492 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
493 dialog->setModal(true);
494 QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Cancel);
495 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KGuiItem(i18nc("@action:button 'Quit Dolphin' button", "&Quit %1", QGuiApplication::applicationDisplayName()), QIcon::fromTheme(QStringLiteral("application-exit"))));
496 KGuiItem::assign(buttons->button(QDialogButtonBox::No), KGuiItem(i18n("C&lose Current Tab"), QIcon::fromTheme(QStringLiteral("tab-close"))));
497 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
498 buttons->button(QDialogButtonBox::Yes)->setDefault(true);
499
500 bool doNotAskAgainCheckboxResult = false;
501
502 const auto result = KMessageBox::createKMessageBox(dialog,
503 buttons,
504 QMessageBox::Warning,
505 i18n("You have multiple tabs open in this window, are you sure you want to quit?"),
506 QStringList(),
507 i18n("Do not ask again"),
508 &doNotAskAgainCheckboxResult,
509 KMessageBox::Notify);
510
511 if (doNotAskAgainCheckboxResult) {
512 GeneralSettings::setConfirmClosingMultipleTabs(false);
513 }
514
515 switch (result) {
516 case QDialogButtonBox::Yes:
517 // Quit
518 break;
519 case QDialogButtonBox::No:
520 // Close only the current tab
521 m_tabWidget->closeTab();
522 Q_FALLTHROUGH();
523 default:
524 event->ignore();
525 return;
526 }
527 }
528
529 if (m_terminalPanel && m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) {
530 // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel
531 // Open a confirmation dialog with 3 buttons:
532 // QDialogButtonBox::Yes -> Quit
533 // QDialogButtonBox::No -> Show Terminal Panel
534 // QDialogButtonBox::Cancel -> do nothing
535 QDialog *dialog = new QDialog(this, Qt::Dialog);
536 dialog->setWindowTitle(i18nc("@title:window", "Confirmation"));
537 dialog->setModal(true);
538 auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel;
539 if (!m_terminalPanel->isVisible()) {
540 standardButtons |= QDialogButtonBox::No;
541 }
542 QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons);
543 KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit());
544 if (!m_terminalPanel->isVisible()) {
545 KGuiItem::assign(
546 buttons->button(QDialogButtonBox::No),
547 KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts"))));
548 }
549 KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
550
551 bool doNotAskAgainCheckboxResult = false;
552
553 const auto result = KMessageBox::createKMessageBox(
554 dialog,
555 buttons,
556 QMessageBox::Warning,
557 i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()),
558 QStringList(),
559 i18n("Do not ask again"),
560 &doNotAskAgainCheckboxResult,
561 KMessageBox::Dangerous);
562
563 if (doNotAskAgainCheckboxResult) {
564 GeneralSettings::setConfirmClosingTerminalRunningProgram(false);
565 }
566
567 switch (result) {
568 case QDialogButtonBox::Yes:
569 // Quit
570 break;
571 case QDialogButtonBox::No:
572 actionCollection()->action("show_terminal_panel")->trigger();
573 // Do not quit, ignore quit event
574 Q_FALLTHROUGH();
575 default:
576 event->ignore();
577 return;
578 }
579 }
580
581 if (GeneralSettings::rememberOpenedTabs()) {
582 KConfigGui::setSessionConfig(QStringLiteral("dolphin"), QStringLiteral("dolphin"));
583 KConfig *config = KConfigGui::sessionConfig();
584 saveGlobalProperties(config);
585 savePropertiesInternal(config, 1);
586 config->sync();
587 }
588
589 GeneralSettings::setVersion(CurrentDolphinVersion);
590 GeneralSettings::self()->save();
591
592 KXmlGuiWindow::closeEvent(event);
593 }
594
595 void DolphinMainWindow::saveProperties(KConfigGroup& group)
596 {
597 m_tabWidget->saveProperties(group);
598 }
599
600 void DolphinMainWindow::readProperties(const KConfigGroup& group)
601 {
602 m_tabWidget->readProperties(group);
603 }
604
605 void DolphinMainWindow::updateNewMenu()
606 {
607 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
608 m_newFileMenu->checkUpToDate();
609 m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
610 }
611
612 void DolphinMainWindow::createDirectory()
613 {
614 m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown());
615 m_newFileMenu->setPopupFiles(QList<QUrl>() << activeViewContainer()->url());
616 m_newFileMenu->createDirectory();
617 }
618
619 void DolphinMainWindow::quit()
620 {
621 close();
622 }
623
624 void DolphinMainWindow::showErrorMessage(const QString& message)
625 {
626 m_activeViewContainer->showMessage(message, DolphinViewContainer::Error);
627 }
628
629 void DolphinMainWindow::slotUndoAvailable(bool available)
630 {
631 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
632 if (undoAction) {
633 undoAction->setEnabled(available);
634 }
635 }
636
637 void DolphinMainWindow::slotUndoTextChanged(const QString& text)
638 {
639 QAction* undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
640 if (undoAction) {
641 undoAction->setText(text);
642 }
643 }
644
645 void DolphinMainWindow::undo()
646 {
647 clearStatusBar();
648 KIO::FileUndoManager::self()->uiInterface()->setParentWidget(this);
649 KIO::FileUndoManager::self()->undo();
650 }
651
652 void DolphinMainWindow::cut()
653 {
654 m_activeViewContainer->view()->cutSelectedItemsToClipboard();
655 }
656
657 void DolphinMainWindow::copy()
658 {
659 m_activeViewContainer->view()->copySelectedItemsToClipboard();
660 }
661
662 void DolphinMainWindow::paste()
663 {
664 m_activeViewContainer->view()->paste();
665 }
666
667 void DolphinMainWindow::find()
668 {
669 m_activeViewContainer->setSearchModeEnabled(true);
670 }
671
672 void DolphinMainWindow::updateSearchAction()
673 {
674 QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search"));
675 toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled());
676 }
677
678 void DolphinMainWindow::updatePasteAction()
679 {
680 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
681 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
682 pasteAction->setEnabled(pasteInfo.first);
683 pasteAction->setText(pasteInfo.second);
684 }
685
686 void DolphinMainWindow::slotDirectoryLoadingCompleted()
687 {
688 updatePasteAction();
689 }
690
691 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
692 {
693 if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) {
694 goBackInNewTab();
695 } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) {
696 goForwardInNewTab();
697 } else if (action == actionCollection()->action(QStringLiteral("go_up"))) {
698 goUpInNewTab();
699 } else if (action == actionCollection()->action(QStringLiteral("go_home"))) {
700 goHomeInNewTab();
701 }
702 }
703
704 void DolphinMainWindow::slotAboutToShowBackPopupMenu()
705 {
706 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
707 int entries = 0;
708 m_backAction->menu()->clear();
709 for (int i = urlNavigator->historyIndex() + 1; i < urlNavigator->historySize() && entries < MaxNumberOfNavigationentries; ++i, ++entries) {
710 QAction* action = new QAction(urlNavigator->locationUrl(i).toString(QUrl::PreferLocalFile), m_backAction->menu());
711 action->setData(i);
712 m_backAction->menu()->addAction(action);
713 }
714 }
715
716 void DolphinMainWindow::slotGoBack(QAction* action)
717 {
718 int gotoIndex = action->data().value<int>();
719 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
720 for (int i = gotoIndex - urlNavigator->historyIndex(); i > 0; --i) {
721 goBack();
722 }
723 }
724
725 void DolphinMainWindow::slotBackForwardActionMiddleClicked(QAction* action)
726 {
727 if (action) {
728 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
729 openNewTabAfterCurrentTab(urlNavigator->locationUrl(action->data().value<int>()));
730 }
731 }
732
733 void DolphinMainWindow::slotAboutToShowForwardPopupMenu()
734 {
735 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
736 int entries = 0;
737 m_forwardAction->menu()->clear();
738 for (int i = urlNavigator->historyIndex() - 1; i >= 0 && entries < MaxNumberOfNavigationentries; --i, ++entries) {
739 QAction* action = new QAction(urlNavigator->locationUrl(i).toString(QUrl::PreferLocalFile), m_forwardAction->menu());
740 action->setData(i);
741 m_forwardAction->menu()->addAction(action);
742 }
743 }
744
745 void DolphinMainWindow::slotGoForward(QAction* action)
746 {
747 int gotoIndex = action->data().value<int>();
748 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
749 for (int i = urlNavigator->historyIndex() - gotoIndex; i > 0; --i) {
750 goForward();
751 }
752 }
753
754 void DolphinMainWindow::selectAll()
755 {
756 clearStatusBar();
757
758 // if the URL navigator is editable and focused, select the whole
759 // URL instead of all items of the view
760
761 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
762 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
763 const bool selectUrl = urlNavigator->isUrlEditable() &&
764 lineEdit->hasFocus();
765 if (selectUrl) {
766 lineEdit->selectAll();
767 } else {
768 m_activeViewContainer->view()->selectAll();
769 }
770 }
771
772 void DolphinMainWindow::invertSelection()
773 {
774 clearStatusBar();
775 m_activeViewContainer->view()->invertSelection();
776 }
777
778 void DolphinMainWindow::toggleSplitView()
779 {
780 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
781 tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled());
782
783 updateViewActions();
784 }
785
786 void DolphinMainWindow::toggleSplitStash()
787 {
788 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
789 tabPage->setSplitViewEnabled(false);
790 tabPage->setSplitViewEnabled(true, QUrl("stash:/"));
791 }
792
793 void DolphinMainWindow::reloadView()
794 {
795 clearStatusBar();
796 m_activeViewContainer->reload();
797 m_activeViewContainer->statusBar()->updateSpaceInfo();
798 }
799
800 void DolphinMainWindow::stopLoading()
801 {
802 m_activeViewContainer->view()->stopLoading();
803 }
804
805 void DolphinMainWindow::enableStopAction()
806 {
807 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
808 }
809
810 void DolphinMainWindow::disableStopAction()
811 {
812 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
813 }
814
815 void DolphinMainWindow::showFilterBar()
816 {
817 m_activeViewContainer->setFilterBarVisible(true);
818 }
819
820 void DolphinMainWindow::toggleEditLocation()
821 {
822 clearStatusBar();
823
824 QAction* action = actionCollection()->action(QStringLiteral("editable_location"));
825 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
826 urlNavigator->setUrlEditable(action->isChecked());
827 }
828
829 void DolphinMainWindow::replaceLocation()
830 {
831 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
832 QLineEdit* lineEdit = navigator->editor()->lineEdit();
833
834 // If the text field currently has focus and everything is selected,
835 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
836 if (navigator->isUrlEditable()
837 && lineEdit->hasFocus()
838 && lineEdit->selectedText() == lineEdit->text() ) {
839 navigator->setUrlEditable(false);
840 } else {
841 navigator->setUrlEditable(true);
842 navigator->setFocus();
843 lineEdit->selectAll();
844 }
845 }
846
847 void DolphinMainWindow::togglePanelLockState()
848 {
849 const bool newLockState = !GeneralSettings::lockPanels();
850 foreach (QObject* child, children()) {
851 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
852 if (dock) {
853 dock->setLocked(newLockState);
854 }
855 }
856
857 GeneralSettings::setLockPanels(newLockState);
858 }
859
860 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
861 {
862 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
863 m_activeViewContainer->view()->setFocus();
864 }
865 }
866
867 void DolphinMainWindow::goBack()
868 {
869 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
870 urlNavigator->goBack();
871
872 if (urlNavigator->locationState().isEmpty()) {
873 // An empty location state indicates a redirection URL,
874 // which must be skipped too
875 urlNavigator->goBack();
876 }
877 }
878
879 void DolphinMainWindow::goForward()
880 {
881 m_activeViewContainer->urlNavigator()->goForward();
882 }
883
884 void DolphinMainWindow::goUp()
885 {
886 m_activeViewContainer->urlNavigator()->goUp();
887 }
888
889 void DolphinMainWindow::goHome()
890 {
891 m_activeViewContainer->urlNavigator()->goHome();
892 }
893
894 void DolphinMainWindow::goBackInNewTab()
895 {
896 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
897 const int index = urlNavigator->historyIndex() + 1;
898 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
899 }
900
901 void DolphinMainWindow::goForwardInNewTab()
902 {
903 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
904 const int index = urlNavigator->historyIndex() - 1;
905 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
906 }
907
908 void DolphinMainWindow::goUpInNewTab()
909 {
910 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
911 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl));
912 }
913
914 void DolphinMainWindow::goHomeInNewTab()
915 {
916 openNewTabAfterCurrentTab(Dolphin::homeUrl());
917 }
918
919 void DolphinMainWindow::compareFiles()
920 {
921 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
922 if (items.count() != 2) {
923 // The action is disabled in this case, but it could have been triggered
924 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
925 return;
926 }
927
928 QUrl urlA = items.at(0).url();
929 QUrl urlB = items.at(1).url();
930
931 QString command(QStringLiteral("kompare -c \""));
932 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
933 command.append("\" \"");
934 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
935 command.append('\"');
936
937 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(command, this);
938 job->setDesktopName(QStringLiteral("org.kde.kompare"));
939 job->start();
940 }
941
942 void DolphinMainWindow::toggleShowMenuBar()
943 {
944 const bool visible = menuBar()->isVisible();
945 menuBar()->setVisible(!visible);
946 if (visible) {
947 createControlButton();
948 } else {
949 deleteControlButton();
950 }
951 }
952
953 QPointer<QAction> DolphinMainWindow::preferredSearchTool()
954 {
955 m_searchTools.clear();
956 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(
957 &m_searchTools, { "files-find" }, m_activeViewContainer->url()
958 );
959 QList<QAction*> actions = m_searchTools.actions();
960 if (actions.isEmpty()) {
961 return nullptr;
962 }
963 QAction* action = actions.first();
964 if (action->isSeparator()) {
965 return nullptr;
966 }
967 return action;
968 }
969
970 void DolphinMainWindow::updateOpenPreferredSearchToolAction()
971 {
972 QAction* openPreferredSearchTool = actionCollection()->action(QStringLiteral("open_preferred_search_tool"));
973 if (!openPreferredSearchTool) {
974 return;
975 }
976 QPointer<QAction> tool = preferredSearchTool();
977 if (tool) {
978 openPreferredSearchTool->setVisible(true);
979 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open %1", tool->text()));
980 openPreferredSearchTool->setIcon(tool->icon());
981 } else {
982 openPreferredSearchTool->setVisible(false);
983 // still visible in Shortcuts configuration window
984 openPreferredSearchTool->setText(i18nc("@action:inmenu Tools", "Open Preferred Search Tool"));
985 openPreferredSearchTool->setIcon(QIcon::fromTheme(QStringLiteral("search")));
986 }
987 }
988
989 void DolphinMainWindow::openPreferredSearchTool()
990 {
991 QPointer<QAction> tool = preferredSearchTool();
992 if (tool) {
993 tool->trigger();
994 }
995 }
996
997 void DolphinMainWindow::openTerminal()
998 {
999 const QUrl url = m_activeViewContainer->url();
1000
1001 if (url.isLocalFile()) {
1002 KToolInvocation::invokeTerminal(QString(), url.toLocalFile());
1003 return;
1004 }
1005
1006 // Not a local file, with protocol Class ":local", try stat'ing
1007 if (KProtocolInfo::protocolClass(url.scheme()) == QLatin1String(":local")) {
1008 KIO::StatJob *job = KIO::mostLocalUrl(url);
1009 KJobWidgets::setWindow(job, this);
1010 connect(job, &KJob::result, this, [job]() {
1011 QUrl statUrl;
1012 if (!job->error()) {
1013 statUrl = job->mostLocalUrl();
1014 }
1015
1016 KToolInvocation::invokeTerminal(QString(), statUrl.isLocalFile() ? statUrl.toLocalFile() : QDir::homePath());
1017 });
1018
1019 return;
1020 }
1021
1022 // Nothing worked, just use $HOME
1023 KToolInvocation::invokeTerminal(QString(), QDir::homePath());
1024 }
1025
1026 void DolphinMainWindow::editSettings()
1027 {
1028 if (!m_settingsDialog) {
1029 DolphinViewContainer* container = activeViewContainer();
1030 container->view()->writeSettings();
1031
1032 const QUrl url = container->url();
1033 DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
1034 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
1035 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
1036 settingsDialog->show();
1037 m_settingsDialog = settingsDialog;
1038 } else {
1039 m_settingsDialog.data()->raise();
1040 }
1041 }
1042
1043 void DolphinMainWindow::handleUrl(const QUrl& url)
1044 {
1045 delete m_lastHandleUrlOpenJob;
1046 m_lastHandleUrlOpenJob = nullptr;
1047
1048 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
1049 activeViewContainer()->setUrl(url);
1050 } else {
1051 m_lastHandleUrlOpenJob = new KIO::OpenUrlJob(url);
1052 m_lastHandleUrlOpenJob->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, this));
1053 m_lastHandleUrlOpenJob->setRunExecutables(true);
1054
1055 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::mimeTypeFound, this,
1056 [this, url](const QString &mimetype) {
1057 if (mimetype == QLatin1String("inode/directory")) {
1058 // If it's a dir, we'll take it from here
1059 m_lastHandleUrlOpenJob->kill();
1060 m_lastHandleUrlOpenJob = nullptr;
1061 activeViewContainer()->setUrl(url);
1062 }
1063 });
1064
1065 connect(m_lastHandleUrlOpenJob, &KIO::OpenUrlJob::result, this, [this]() {
1066 m_lastHandleUrlOpenJob = nullptr;
1067 });
1068
1069 m_lastHandleUrlOpenJob->start();
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 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1569 QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1570 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1571 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1572 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1573 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1574 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
1575 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4);
1576 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1577
1578 #ifdef HAVE_TERMINAL
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 #endif
1585 }
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 connect(view, &DolphinView::goUpRequested,
2118 this, &DolphinMainWindow::goUp);
2119
2120 const KUrlNavigator* navigator = container->urlNavigator();
2121 connect(navigator, &KUrlNavigator::urlChanged,
2122 this, &DolphinMainWindow::changeUrl);
2123 connect(navigator, &KUrlNavigator::historyChanged,
2124 this, &DolphinMainWindow::updateHistory);
2125 connect(navigator, &KUrlNavigator::editableStateChanged,
2126 this, &DolphinMainWindow::slotEditableStateChanged);
2127 connect(navigator, &KUrlNavigator::tabRequested,
2128 this, &DolphinMainWindow::openNewTabAfterLastTab);
2129 }
2130
2131 void DolphinMainWindow::updateSplitAction()
2132 {
2133 QAction* splitAction = actionCollection()->action(QStringLiteral("split_view"));
2134 const DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
2135 if (tabPage->splitViewEnabled()) {
2136 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
2137 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
2138 splitAction->setToolTip(i18nc("@info", "Close left view"));
2139 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
2140 } else {
2141 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
2142 splitAction->setToolTip(i18nc("@info", "Close right view"));
2143 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
2144 }
2145 } else {
2146 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
2147 splitAction->setToolTip(i18nc("@info", "Split view"));
2148 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
2149 }
2150 }
2151
2152 bool DolphinMainWindow::isKompareInstalled() const
2153 {
2154 static bool initialized = false;
2155 static bool installed = false;
2156 if (!initialized) {
2157 // TODO: maybe replace this approach later by using a menu
2158 // plugin like kdiff3plugin.cpp
2159 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
2160 initialized = true;
2161 }
2162 return installed;
2163 }
2164
2165 void DolphinMainWindow::createPanelAction(const QIcon& icon,
2166 const QKeySequence& shortcut,
2167 QAction* dockAction,
2168 const QString& actionName)
2169 {
2170 QAction* panelAction = actionCollection()->addAction(actionName);
2171 panelAction->setCheckable(true);
2172 panelAction->setChecked(dockAction->isChecked());
2173 panelAction->setText(dockAction->text());
2174 panelAction->setIcon(icon);
2175 actionCollection()->setDefaultShortcut(panelAction, shortcut);
2176
2177 connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
2178 connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
2179 }
2180
2181 void DolphinMainWindow::setupWhatsThis()
2182 {
2183 // main widgets
2184 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2185 "<emphasis>Menubar</emphasis>. It provides access to commands and "
2186 "configuration options. Left-click on any of the menus on this "
2187 "bar to see its contents.</para><para>The Menubar can be hidden "
2188 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
2189 "most of its contents become available through a <interface>Control"
2190 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
2191 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
2192 "<emphasis>Toolbar</emphasis>. It allows quick access to "
2193 "frequently used actions.</para><para>It is highly customizable. "
2194 "All items you see in the <interface>Control</interface> menu or "
2195 "in the <interface>Menubar</interface> can be placed on the "
2196 "Toolbar. Just right-click on it and select <interface>Configure "
2197 "Toolbars…</interface> or find this action in the <interface>"
2198 "Control</interface> or <interface>Settings</interface> menu."
2199 "</para><para>The location of the bar and the style of its "
2200 "buttons can also be changed in the right-click menu. Right-click "
2201 "a button if you want to show or hide its text.</para>"));
2202 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
2203 "<para>Here you can see the <emphasis>folders</emphasis> and "
2204 "<emphasis>files</emphasis> that are at the location described in "
2205 "the <interface>Location Bar</interface> above. This area is the "
2206 "central part of this application where you navigate to the files "
2207 "you want to use.</para><para>For an elaborate and general "
2208 "introduction to this application <link "
2209 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
2210 "click here</link>. This will open an introductory article from "
2211 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
2212 "explanations of all the features of this <emphasis>view</emphasis> "
2213 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
2214 "instead. This will open a page from the <emphasis>Handbook"
2215 "</emphasis> that covers the basics.</para>"));
2216
2217 // Settings menu
2218 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
2219 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
2220 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
2221 "There you can set up key combinations to trigger an action when "
2222 "they are pressed simultaneously. All commands in this application can "
2223 "be triggered this way.</para>"));
2224 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
2225 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
2226 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
2227 "<para>All items you see in the <interface>Control</interface> menu "
2228 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
2229 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
2230 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
2231 "change a multitude of settings for this application. For an explanation "
2232 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
2233 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
2234
2235 // Help menu
2236 // The whatsthis has to be set for the m_helpMenu and for the
2237 // StandardAction separately because both are used in different locations.
2238 // m_helpMenu is only used for createControlButton() button.
2239
2240 // Links do not work within the Menubar so texts without links are provided there.
2241
2242 // i18n: If the external link isn't available in your language you should
2243 // probably state the external link language at least in brackets to not
2244 // frustrate the user. If there are multiple languages that the user might
2245 // know with a reasonable chance you might want to have 2 external links.
2246 // The same is in my opinion true for every external link you translate.
2247 const QString whatsThisHelpContents = xi18nc("@info:whatsthis handbook",
2248 "<para>This opens the Handbook for this application. It provides "
2249 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
2250 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents))
2251 ->setWhatsThis(whatsThisHelpContents
2252 + xi18nc("@info:whatsthis second half of handbook hb text without link",
2253 "<para>If you want more elaborate introductions to the "
2254 "different features of <emphasis>Dolphin</emphasis> "
2255 "go to the KDE UserBase Wiki.</para>"));
2256 m_helpMenu->action(KHelpMenu::menuHelpContents)->setWhatsThis(whatsThisHelpContents
2257 + xi18nc("@info:whatsthis second half of handbook text with link",
2258 "<para>If you want more elaborate introductions to the "
2259 "different features of <emphasis>Dolphin</emphasis> "
2260 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
2261 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
2262
2263 const QString whatsThisWhatsThis = xi18nc("@info:whatsthis whatsthis button",
2264 "<para>This is the button that invokes the help feature you are "
2265 "using right now! Click it, then click any component of this "
2266 "application to ask \"What's this?\" about it. The mouse cursor "
2267 "will change appearance if no help is available for a spot.</para>");
2268 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis))
2269 ->setWhatsThis(whatsThisWhatsThis
2270 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
2271 "<para>There are two other ways to get help for this application: The "
2272 "<interface>Dolphin Handbook</interface> in the <interface>Help"
2273 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
2274 "article about <emphasis>File Management</emphasis> online."
2275 "</para><para>The \"What's this?\" help is "
2276 "missing in most other windows so don't get too used to this.</para>"));
2277 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setWhatsThis(whatsThisWhatsThis
2278 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
2279 "<para>There are two other ways to get help: "
2280 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
2281 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
2282 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
2283 "missing in most other windows so don't get too used to this.</para>"));
2284
2285 const QString whatsThisReportBug = xi18nc("@info:whatsthis","<para>This opens a "
2286 "window that will guide you through reporting errors or flaws "
2287 "in this application or in other KDE software.</para>");
2288 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug))
2289 ->setWhatsThis(whatsThisReportBug);
2290 m_helpMenu->action(KHelpMenu::menuReportBug)->setWhatsThis(whatsThisReportBug
2291 + xi18nc("@info:whatsthis second half of reportbug text with link",
2292 "<para>High-quality bug reports are much appreciated. To learn "
2293 "how to make your bug report as effective as possible "
2294 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2295 "click here</link>.</para>"));
2296
2297 const QString whatsThisDonate = xi18nc("@info:whatsthis","<para>This opens a "
2298 "<emphasis>web page</emphasis> where you can donate to "
2299 "support the continued work on this application and many "
2300 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2301 "<para>Donating is the easiest and fastest way to efficiently "
2302 "support KDE and its projects. KDE projects are available for "
2303 "free therefore your donation is needed to cover things that "
2304 "require money like servers, contributor meetings, etc.</para>"
2305 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2306 "organization behind the KDE community.</para>");
2307 actionCollection()->action(KStandardAction::name(KStandardAction::Donate))
2308 ->setWhatsThis(whatsThisDonate);
2309 m_helpMenu->action(KHelpMenu::menuDonate)->setWhatsThis(whatsThisDonate);
2310
2311 const QString whatsThisSwitchLanguage = xi18nc("@info:whatsthis",
2312 "With this you can change the language this application uses."
2313 "<nl/>You can even set secondary languages which will be used "
2314 "if texts are not available in your preferred language.");
2315 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))
2316 ->setWhatsThis(whatsThisSwitchLanguage);
2317 m_helpMenu->action(KHelpMenu::menuSwitchLanguage)->setWhatsThis(whatsThisSwitchLanguage);
2318
2319 const QString whatsThisAboutApp = xi18nc("@info:whatsthis","This opens a "
2320 "window that informs you about the version, license, "
2321 "used libraries and maintainers of this application.");
2322 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp))
2323 ->setWhatsThis(whatsThisAboutApp);
2324 m_helpMenu->action(KHelpMenu::menuAboutApp)->setWhatsThis(whatsThisAboutApp);
2325
2326 const QString whatsThisAboutKDE = xi18nc("@info:whatsthis","This opens a "
2327 "window with information about <emphasis>KDE</emphasis>. "
2328 "The KDE community are the people behind this free software."
2329 "<nl/>If you like using this application but don't know "
2330 "about KDE or want to see a cute dragon have a look!");
2331 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE))
2332 ->setWhatsThis(whatsThisAboutKDE);
2333 m_helpMenu->action(KHelpMenu::menuAboutKDE)->setWhatsThis(whatsThisAboutKDE);
2334 }
2335
2336 bool DolphinMainWindow::event(QEvent *event)
2337 {
2338 if (event->type() == QEvent::WhatsThisClicked) {
2339 event->accept();
2340 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2341 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2342 return true;
2343 }
2344 return KXmlGuiWindow::event(event);
2345 }
2346
2347 bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event)
2348 {
2349 Q_UNUSED(obj)
2350 if (event->type() == QEvent::WhatsThisClicked) {
2351 event->accept();
2352 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2353 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2354 return true;
2355 }
2356 return false;
2357 }
2358
2359 void DolphinMainWindow::focusTerminalPanel()
2360 {
2361 if (m_terminalPanel->isVisible()) {
2362 if (m_terminalPanel->terminalHasFocus()) {
2363 m_activeViewContainer->view()->setFocus(Qt::FocusReason::ShortcutFocusReason);
2364 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Focus Terminal Panel"));
2365 } else {
2366 m_terminalPanel->setFocus(Qt::FocusReason::ShortcutFocusReason);
2367 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2368 }
2369 } else {
2370 actionCollection()->action(QStringLiteral("show_terminal_panel"))->trigger();
2371 actionCollection()->action(QStringLiteral("focus_terminal_panel"))->setText(i18nc("@action:inmenu Tools", "Defocus Terminal Panel"));
2372 }
2373 }
2374
2375 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2376 KIO::FileUndoManager::UiInterface()
2377 {
2378 }
2379
2380 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2381 {
2382 }
2383
2384 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2385 {
2386 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2387 if (mainWin) {
2388 DolphinViewContainer* container = mainWin->activeViewContainer();
2389 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2390 } else {
2391 KIO::FileUndoManager::UiInterface::jobError(job);
2392 }
2393 }
2394
2395 bool DolphinMainWindow::isUrlOpen(const QString& url)
2396 {
2397 return m_tabWidget->isUrlOpen(QUrl::fromUserInput((url)));
2398 }
2399