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