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