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