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