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