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