]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinmainwindow.cpp
Change default Dolphin toolbar layout
[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::updatePasteAction()
621 {
622 QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste));
623 QPair<bool, QString> pasteInfo = m_activeViewContainer->view()->pasteInfo();
624 pasteAction->setEnabled(pasteInfo.first);
625 pasteAction->setText(pasteInfo.second);
626 }
627
628 void DolphinMainWindow::slotDirectoryLoadingCompleted()
629 {
630 updatePasteAction();
631 }
632
633 void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
634 {
635 if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Back))) {
636 goBackInNewTab();
637 } else if (action == actionCollection()->action(KStandardAction::name(KStandardAction::Forward))) {
638 goForwardInNewTab();
639 } else if (action == actionCollection()->action(QStringLiteral("go_up"))) {
640 goUpInNewTab();
641 } else if (action == actionCollection()->action(QStringLiteral("go_home"))) {
642 goHomeInNewTab();
643 }
644 }
645
646 void DolphinMainWindow::selectAll()
647 {
648 clearStatusBar();
649
650 // if the URL navigator is editable and focused, select the whole
651 // URL instead of all items of the view
652
653 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
654 QLineEdit* lineEdit = urlNavigator->editor()->lineEdit();
655 const bool selectUrl = urlNavigator->isUrlEditable() &&
656 lineEdit->hasFocus();
657 if (selectUrl) {
658 lineEdit->selectAll();
659 } else {
660 m_activeViewContainer->view()->selectAll();
661 }
662 }
663
664 void DolphinMainWindow::invertSelection()
665 {
666 clearStatusBar();
667 m_activeViewContainer->view()->invertSelection();
668 }
669
670 void DolphinMainWindow::toggleSplitView()
671 {
672 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
673 tabPage->setSplitViewEnabled(!tabPage->splitViewEnabled());
674
675 updateViewActions();
676 }
677
678 void DolphinMainWindow::toggleSplitStash()
679 {
680 DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
681 tabPage->setSplitViewEnabled(false);
682 tabPage->setSplitViewEnabled(true, QUrl("stash:/"));
683 }
684
685 void DolphinMainWindow::reloadView()
686 {
687 clearStatusBar();
688 m_activeViewContainer->reload();
689 m_activeViewContainer->statusBar()->updateSpaceInfo();
690 }
691
692 void DolphinMainWindow::stopLoading()
693 {
694 m_activeViewContainer->view()->stopLoading();
695 }
696
697 void DolphinMainWindow::enableStopAction()
698 {
699 actionCollection()->action(QStringLiteral("stop"))->setEnabled(true);
700 }
701
702 void DolphinMainWindow::disableStopAction()
703 {
704 actionCollection()->action(QStringLiteral("stop"))->setEnabled(false);
705 }
706
707 void DolphinMainWindow::showFilterBar()
708 {
709 m_activeViewContainer->setFilterBarVisible(true);
710 }
711
712 void DolphinMainWindow::toggleEditLocation()
713 {
714 clearStatusBar();
715
716 QAction* action = actionCollection()->action(QStringLiteral("editable_location"));
717 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
718 urlNavigator->setUrlEditable(action->isChecked());
719 }
720
721 void DolphinMainWindow::replaceLocation()
722 {
723 KUrlNavigator* navigator = m_activeViewContainer->urlNavigator();
724 QLineEdit* lineEdit = navigator->editor()->lineEdit();
725
726 // If the text field currently has focus and everything is selected,
727 // pressing the keyboard shortcut returns the whole thing to breadcrumb mode
728 if (navigator->isUrlEditable()
729 && lineEdit->hasFocus()
730 && lineEdit->selectedText() == lineEdit->text() ) {
731 navigator->setUrlEditable(false);
732 } else {
733 navigator->setUrlEditable(true);
734 navigator->setFocus();
735 lineEdit->selectAll();
736 }
737 }
738
739 void DolphinMainWindow::togglePanelLockState()
740 {
741 const bool newLockState = !GeneralSettings::lockPanels();
742 foreach (QObject* child, children()) {
743 DolphinDockWidget* dock = qobject_cast<DolphinDockWidget*>(child);
744 if (dock) {
745 dock->setLocked(newLockState);
746 }
747 }
748
749 GeneralSettings::setLockPanels(newLockState);
750 }
751
752 void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
753 {
754 if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
755 m_activeViewContainer->view()->setFocus();
756 }
757 }
758
759 void DolphinMainWindow::goBack()
760 {
761 KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
762 urlNavigator->goBack();
763
764 if (urlNavigator->locationState().isEmpty()) {
765 // An empty location state indicates a redirection URL,
766 // which must be skipped too
767 urlNavigator->goBack();
768 }
769 }
770
771 void DolphinMainWindow::goForward()
772 {
773 m_activeViewContainer->urlNavigator()->goForward();
774 }
775
776 void DolphinMainWindow::goUp()
777 {
778 m_activeViewContainer->urlNavigator()->goUp();
779 }
780
781 void DolphinMainWindow::goHome()
782 {
783 m_activeViewContainer->urlNavigator()->goHome();
784 }
785
786 void DolphinMainWindow::goBackInNewTab()
787 {
788 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
789 const int index = urlNavigator->historyIndex() + 1;
790 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
791 }
792
793 void DolphinMainWindow::goForwardInNewTab()
794 {
795 KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
796 const int index = urlNavigator->historyIndex() - 1;
797 openNewTabAfterCurrentTab(urlNavigator->locationUrl(index));
798 }
799
800 void DolphinMainWindow::goUpInNewTab()
801 {
802 const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
803 openNewTabAfterCurrentTab(KIO::upUrl(currentUrl));
804 }
805
806 void DolphinMainWindow::goHomeInNewTab()
807 {
808 openNewTabAfterCurrentTab(Dolphin::homeUrl());
809 }
810
811 void DolphinMainWindow::compareFiles()
812 {
813 const KFileItemList items = m_tabWidget->currentTabPage()->selectedItems();
814 if (items.count() != 2) {
815 // The action is disabled in this case, but it could have been triggered
816 // via D-Bus, see https://bugs.kde.org/show_bug.cgi?id=325517
817 return;
818 }
819
820 QUrl urlA = items.at(0).url();
821 QUrl urlB = items.at(1).url();
822
823 QString command(QStringLiteral("kompare -c \""));
824 command.append(urlA.toDisplayString(QUrl::PreferLocalFile));
825 command.append("\" \"");
826 command.append(urlB.toDisplayString(QUrl::PreferLocalFile));
827 command.append('\"');
828 KRun::runCommand(command, QStringLiteral("Kompare"), QStringLiteral("kompare"), this);
829 }
830
831 void DolphinMainWindow::toggleShowMenuBar()
832 {
833 const bool visible = menuBar()->isVisible();
834 menuBar()->setVisible(!visible);
835 if (visible) {
836 createControlButton();
837 } else {
838 deleteControlButton();
839 }
840 }
841
842 void DolphinMainWindow::openTerminal()
843 {
844 QString dir(QDir::homePath());
845
846 // If the given directory is not local, it can still be the URL of an
847 // ioslave using UDS_LOCAL_PATH which to be converted first.
848 KIO::StatJob* statJob = KIO::mostLocalUrl(m_activeViewContainer->url());
849 KJobWidgets::setWindow(statJob, this);
850 statJob->exec();
851 QUrl url = statJob->mostLocalUrl();
852
853 //If the URL is local after the above conversion, set the directory.
854 if (url.isLocalFile()) {
855 dir = url.toLocalFile();
856 }
857
858 KToolInvocation::invokeTerminal(QString(), dir);
859 }
860
861 void DolphinMainWindow::editSettings()
862 {
863 if (!m_settingsDialog) {
864 DolphinViewContainer* container = activeViewContainer();
865 container->view()->writeSettings();
866
867 const QUrl url = container->url();
868 DolphinSettingsDialog* settingsDialog = new DolphinSettingsDialog(url, this);
869 connect(settingsDialog, &DolphinSettingsDialog::settingsChanged, this, &DolphinMainWindow::refreshViews);
870 settingsDialog->setAttribute(Qt::WA_DeleteOnClose);
871 settingsDialog->show();
872 m_settingsDialog = settingsDialog;
873 } else {
874 m_settingsDialog.data()->raise();
875 }
876 }
877
878 void DolphinMainWindow::handleUrl(const QUrl& url)
879 {
880 delete m_lastHandleUrlStatJob;
881 m_lastHandleUrlStatJob = nullptr;
882
883 if (url.isLocalFile() && QFileInfo(url.toLocalFile()).isDir()) {
884 activeViewContainer()->setUrl(url);
885 } else if (KProtocolManager::supportsListing(url)) {
886 // stat the URL to see if it is a dir or not
887 m_lastHandleUrlStatJob = KIO::stat(url, KIO::HideProgressInfo);
888 if (m_lastHandleUrlStatJob->uiDelegate()) {
889 KJobWidgets::setWindow(m_lastHandleUrlStatJob, this);
890 }
891 connect(m_lastHandleUrlStatJob, &KIO::Job::result,
892 this, &DolphinMainWindow::slotHandleUrlStatFinished);
893
894 } else {
895 new KRun(url, this); // Automatically deletes itself after being finished
896 }
897 }
898
899 void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job)
900 {
901 m_lastHandleUrlStatJob = nullptr;
902 const KIO::UDSEntry entry = static_cast<KIO::StatJob*>(job)->statResult();
903 const QUrl url = static_cast<KIO::StatJob*>(job)->url();
904 if (entry.isDir()) {
905 activeViewContainer()->setUrl(url);
906 } else {
907 new KRun(url, this); // Automatically deletes itself after being finished
908 }
909 }
910
911 void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable)
912 {
913 // trash:/ is writable but we don't want to create new items in it.
914 // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented
915 newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash"));
916 }
917
918 void DolphinMainWindow::openContextMenu(const QPoint& pos,
919 const KFileItem& item,
920 const QUrl& url,
921 const QList<QAction*>& customActions)
922 {
923 QPointer<DolphinContextMenu> contextMenu = new DolphinContextMenu(this, pos, item, url);
924 contextMenu.data()->setCustomActions(customActions);
925 const DolphinContextMenu::Command command = contextMenu.data()->open();
926
927 switch (command) {
928 case DolphinContextMenu::OpenParentFolder:
929 changeUrl(KIO::upUrl(item.url()));
930 m_activeViewContainer->view()->markUrlsAsSelected({item.url()});
931 m_activeViewContainer->view()->markUrlAsCurrent(item.url());
932 break;
933
934 case DolphinContextMenu::OpenParentFolderInNewWindow:
935 Dolphin::openNewWindow({item.url()}, this, Dolphin::OpenNewWindowFlag::Select);
936 break;
937
938 case DolphinContextMenu::OpenParentFolderInNewTab:
939 openNewTabAfterLastTab(KIO::upUrl(item.url()));
940 break;
941
942 case DolphinContextMenu::None:
943 default:
944 break;
945 }
946
947 // Delete the menu, unless it has been deleted in its own nested event loop already.
948 if (contextMenu) {
949 contextMenu->deleteLater();
950 }
951 }
952
953 void DolphinMainWindow::updateControlMenu()
954 {
955 QMenu* menu = qobject_cast<QMenu*>(sender());
956 Q_ASSERT(menu);
957
958 // All actions get cleared by QMenu::clear(). This includes the sub-menus
959 // because 'menu' is their parent.
960 menu->clear();
961
962 KActionCollection* ac = actionCollection();
963
964 // Add "Create New" menu
965 menu->addMenu(m_newFileMenu->menu());
966
967 menu->addSeparator();
968
969 // Overwrite Find action to Search action
970 QAction *searchAction = ac->action(KStandardAction::name(KStandardAction::Find));
971 searchAction->setText(i18n("Search..."));
972
973 // Add "Edit" actions
974 bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) |
975 addActionToMenu(searchAction, menu) |
976 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::SelectAll)), menu) |
977 addActionToMenu(ac->action(QStringLiteral("invert_selection")), menu);
978
979 if (added) {
980 menu->addSeparator();
981 }
982
983 // Add "View" actions
984 if (!GeneralSettings::showZoomSlider()) {
985 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomIn)), menu);
986 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ZoomOut)), menu);
987 menu->addSeparator();
988 }
989
990 added = addActionToMenu(ac->action(QStringLiteral("sort")), menu) |
991 addActionToMenu(ac->action(QStringLiteral("view_mode")), menu) |
992 addActionToMenu(ac->action(QStringLiteral("additional_info")), menu) |
993 addActionToMenu(ac->action(QStringLiteral("show_preview")), menu) |
994 addActionToMenu(ac->action(QStringLiteral("show_in_groups")), menu) |
995 addActionToMenu(ac->action(QStringLiteral("show_hidden_files")), menu);
996
997 if (added) {
998 menu->addSeparator();
999 }
1000
1001 added = addActionToMenu(ac->action(QStringLiteral("split_view")), menu) |
1002 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Redisplay)), menu) |
1003 addActionToMenu(ac->action(QStringLiteral("view_properties")), menu);
1004 if (added) {
1005 menu->addSeparator();
1006 }
1007
1008 addActionToMenu(ac->action(QStringLiteral("panels")), menu);
1009 QMenu* locationBarMenu = new QMenu(i18nc("@action:inmenu", "Location Bar"), menu);
1010 locationBarMenu->addAction(ac->action(QStringLiteral("editable_location")));
1011 locationBarMenu->addAction(ac->action(QStringLiteral("replace_location")));
1012 menu->addMenu(locationBarMenu);
1013
1014 menu->addSeparator();
1015
1016 // Add "Go" menu
1017 QMenu* goMenu = new QMenu(i18nc("@action:inmenu", "Go"), menu);
1018 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Back)));
1019 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Forward)));
1020 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Up)));
1021 goMenu->addAction(ac->action(KStandardAction::name(KStandardAction::Home)));
1022 goMenu->addAction(ac->action(QStringLiteral("closed_tabs")));
1023 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), goMenu);
1024 m_bookmarkHandler->fillControlMenu(bookmarkMenu->menu(), ac);
1025 goMenu->addAction(bookmarkMenu);
1026 menu->addMenu(goMenu);
1027
1028 // Add "Tool" menu
1029 QMenu* toolsMenu = new QMenu(i18nc("@action:inmenu", "Tools"), menu);
1030 toolsMenu->addAction(ac->action(QStringLiteral("show_filter_bar")));
1031 toolsMenu->addAction(ac->action(QStringLiteral("compare_files")));
1032 toolsMenu->addAction(ac->action(QStringLiteral("open_terminal")));
1033 toolsMenu->addAction(ac->action(QStringLiteral("change_remote_encoding")));
1034 menu->addMenu(toolsMenu);
1035
1036 // Add "Settings" menu entries
1037 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::KeyBindings)), menu);
1038 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ConfigureToolbars)), menu);
1039 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Preferences)), menu);
1040
1041 // Add "Help" menu
1042 menu->addMenu(m_helpMenu->menu());
1043
1044 menu->addSeparator();
1045 addActionToMenu(ac->action(KStandardAction::name(KStandardAction::ShowMenubar)), menu);
1046 }
1047
1048 void DolphinMainWindow::updateToolBar()
1049 {
1050 if (!menuBar()->isVisible()) {
1051 createControlButton();
1052 }
1053 }
1054
1055 void DolphinMainWindow::slotControlButtonDeleted()
1056 {
1057 m_controlButton = nullptr;
1058 m_updateToolBarTimer->start();
1059 }
1060
1061 void DolphinMainWindow::slotPlaceActivated(const QUrl& url)
1062 {
1063 DolphinViewContainer* view = activeViewContainer();
1064
1065 if (view->url() == url) {
1066 // We can end up here if the user clicked a device in the Places Panel
1067 // which had been unmounted earlier, see https://bugs.kde.org/show_bug.cgi?id=161385.
1068 reloadView();
1069 } else {
1070 changeUrl(url);
1071 }
1072 }
1073
1074 void DolphinMainWindow::closedTabsCountChanged(unsigned int count)
1075 {
1076 actionCollection()->action(QStringLiteral("undo_close_tab"))->setEnabled(count > 0);
1077 }
1078
1079 void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer)
1080 {
1081 DolphinViewContainer* oldViewContainer = m_activeViewContainer;
1082 Q_ASSERT(viewContainer);
1083
1084 m_activeViewContainer = viewContainer;
1085
1086 if (oldViewContainer) {
1087 // Disconnect all signals between the old view container (container,
1088 // view and url navigator) and main window.
1089 oldViewContainer->disconnect(this);
1090 oldViewContainer->view()->disconnect(this);
1091 oldViewContainer->urlNavigator()->disconnect(this);
1092
1093 // except the requestItemInfo so that on hover the information panel can still be updated
1094 connect(oldViewContainer->view(), &DolphinView::requestItemInfo,
1095 this, &DolphinMainWindow::requestItemInfo);
1096 }
1097
1098 connectViewSignals(viewContainer);
1099
1100 m_actionHandler->setCurrentView(viewContainer->view());
1101
1102 updateHistory();
1103 updateEditActions();
1104 updatePasteAction();
1105 updateViewActions();
1106 updateGoActions();
1107
1108 const QUrl url = viewContainer->url();
1109 emit urlChanged(url);
1110 }
1111
1112 void DolphinMainWindow::tabCountChanged(int count)
1113 {
1114 const bool enableTabActions = (count > 1);
1115 actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions);
1116 actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions);
1117 }
1118
1119 void DolphinMainWindow::updateWindowTitle()
1120 {
1121 const QString newTitle = m_activeViewContainer->caption();
1122 if (windowTitle() != newTitle) {
1123 setWindowTitle(newTitle);
1124 }
1125 }
1126
1127 void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath)
1128 {
1129 if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1130 m_tearDownFromPlacesRequested = true;
1131 m_terminalPanel->goHome();
1132 // m_placesPanel->proceedWithTearDown() will be called in slotTerminalDirectoryChanged
1133 } else {
1134 m_placesPanel->proceedWithTearDown();
1135 }
1136 }
1137
1138 void DolphinMainWindow::slotStorageTearDownExternallyRequested(const QString& mountPath)
1139 {
1140 if (m_terminalPanel->currentWorkingDirectory().startsWith(mountPath)) {
1141 m_tearDownFromPlacesRequested = false;
1142 m_terminalPanel->goHome();
1143 }
1144 }
1145
1146 void DolphinMainWindow::setupActions()
1147 {
1148 // setup 'File' menu
1149 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
1150 QMenu* menu = m_newFileMenu->menu();
1151 menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New"));
1152 menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
1153 m_newFileMenu->setDelayed(false);
1154 connect(menu, &QMenu::aboutToShow,
1155 this, &DolphinMainWindow::updateNewMenu);
1156
1157 QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection());
1158 newWindow->setText(i18nc("@action:inmenu File", "New &Window"));
1159 newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window"));
1160 newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1161 "window just like this one with the current location and view."
1162 "<nl/>You can drag and drop items between windows."));
1163 newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1164
1165 QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab"));
1166 newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1167 newTab->setText(i18nc("@action:inmenu File", "New Tab"));
1168 newTab->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new "
1169 "<emphasis>Tab</emphasis> with the current location and view.<nl/>"
1170 "A tab is an additional view within this window. "
1171 "You can drag and drop items between tabs."));
1172 actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N});
1173 connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab);
1174
1175 QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection());
1176 closeTab->setText(i18nc("@action:inmenu File", "Close Tab"));
1177 closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the "
1178 "currently viewed tab. If no more tabs are left this window "
1179 "will close instead."));
1180
1181 QAction* quitAction = KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection());
1182 quitAction->setWhatsThis(i18nc("@info:whatsthis quit", "This closes this window."));
1183
1184 // setup 'Edit' menu
1185 KStandardAction::undo(this,
1186 &DolphinMainWindow::undo,
1187 actionCollection());
1188
1189 // i18n: This will be the last paragraph for the whatsthis for all three:
1190 // Cut, Copy and Paste
1191 const QString cutCopyPastePara = xi18nc("@info:whatsthis", "<para><emphasis>Cut, "
1192 "Copy</emphasis> and <emphasis>Paste</emphasis> work between many "
1193 "applications and are among the most used commands. That's why their "
1194 "<emphasis>keyboard shortcuts</emphasis> are prominently placed right "
1195 "next to each other on the keyboard: <shortcut>Ctrl+X</shortcut>, "
1196 "<shortcut>Ctrl+C</shortcut> and <shortcut>Ctrl+V</shortcut>.</para>");
1197 QAction* cutAction = KStandardAction::cut(this, &DolphinMainWindow::cut, actionCollection());
1198 cutAction->setWhatsThis(xi18nc("@info:whatsthis cut", "This copies the items "
1199 "in your current selection to the <emphasis>clipboard</emphasis>.<nl/>"
1200 "Use the <emphasis>Paste</emphasis> action afterwards to copy them from "
1201 "the clipboard to a new location. The items will be removed from their "
1202 "initial location.") + cutCopyPastePara);
1203 QAction* copyAction = KStandardAction::copy(this, &DolphinMainWindow::copy, actionCollection());
1204 copyAction->setWhatsThis(xi18nc("@info:whatsthis copy", "This copies the "
1205 "items in your current selection to the <emphasis>clipboard</emphasis>."
1206 "<nl/>Use the <emphasis>Paste</emphasis> action afterwards to copy them "
1207 "from the clipboard to a new location.") + cutCopyPastePara);
1208 QAction* paste = KStandardAction::paste(this, &DolphinMainWindow::paste, actionCollection());
1209 // The text of the paste-action is modified dynamically by Dolphin
1210 // (e. g. to "Paste One Folder"). To prevent that the size of the toolbar changes
1211 // due to the long text, the text "Paste" is used:
1212 paste->setIconText(i18nc("@action:inmenu Edit", "Paste"));
1213 paste->setWhatsThis(xi18nc("@info:whatsthis paste", "This copies the items from "
1214 "your <emphasis>clipboard</emphasis> to the currently viewed folder.<nl/>"
1215 "If the items were added to the clipboard by the <emphasis>Cut</emphasis> "
1216 "action they are removed from their old location.") + cutCopyPastePara);
1217
1218 QAction *searchAction = KStandardAction::find(this, &DolphinMainWindow::find, actionCollection());
1219 searchAction->setText(i18n("Search..."));
1220 searchAction->setToolTip(i18nc("@info:tooltip", "Search for files and folders"));
1221 searchAction->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This helps you "
1222 "find files and folders by opening a <emphasis>find bar</emphasis>. "
1223 "There you can enter search terms and specify settings to find the "
1224 "objects you are looking for.</para><para>Use this help again on "
1225 "the find bar so we can have a look at it while the settings are "
1226 "explained.</para>"));
1227
1228 QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection());
1229 selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all "
1230 "files and folders in the current location."));
1231
1232 QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
1233 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
1234 invertSelection->setWhatsThis(xi18nc("@info:whatsthis invert", "This selects all "
1235 "objects that you have currently <emphasis>not</emphasis> selected instead."));
1236 invertSelection->setIcon(QIcon::fromTheme(QStringLiteral("edit-select-invert")));
1237 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A);
1238 connect(invertSelection, &QAction::triggered, this, &DolphinMainWindow::invertSelection);
1239
1240 // setup 'View' menu
1241 // (note that most of it is set up in DolphinViewActionHandler)
1242
1243 QAction* split = actionCollection()->addAction(QStringLiteral("split_view"));
1244 split->setWhatsThis(xi18nc("@info:whatsthis find", "<para>This splits "
1245 "the folder view below into two autonomous views.</para><para>This "
1246 "way you can see two locations at once and move items between them "
1247 "quickly.</para>Click this again afterwards to recombine the views."));
1248 actionCollection()->setDefaultShortcut(split, Qt::Key_F3);
1249 connect(split, &QAction::triggered, this, &DolphinMainWindow::toggleSplitView);
1250
1251 QAction* stashSplit = actionCollection()->addAction(QStringLiteral("split_stash"));
1252 actionCollection()->setDefaultShortcut(stashSplit, Qt::CTRL + Qt::Key_S);
1253 stashSplit->setText(i18nc("@action:intoolbar Stash", "Stash"));
1254 stashSplit->setToolTip(i18nc("@info", "Opens the stash virtual directory in a split window"));
1255 stashSplit->setIcon(QIcon::fromTheme(QStringLiteral("folder-stash")));
1256 stashSplit->setCheckable(false);
1257 stashSplit->setVisible(KProtocolInfo::isKnownProtocol("stash"));
1258 connect(stashSplit, &QAction::triggered, this, &DolphinMainWindow::toggleSplitStash);
1259
1260 KStandardAction::redisplay(this, &DolphinMainWindow::reloadView, actionCollection());
1261
1262 QAction* stop = actionCollection()->addAction(QStringLiteral("stop"));
1263 stop->setText(i18nc("@action:inmenu View", "Stop"));
1264 stop->setToolTip(i18nc("@info", "Stop loading"));
1265 stop->setWhatsThis(i18nc("@info", "This stops the loading of the contents of the current folder."));
1266 stop->setIcon(QIcon::fromTheme(QStringLiteral("process-stop")));
1267 connect(stop, &QAction::triggered, this, &DolphinMainWindow::stopLoading);
1268
1269 KToggleAction* editableLocation = actionCollection()->add<KToggleAction>(QStringLiteral("editable_location"));
1270 editableLocation->setText(i18nc("@action:inmenu Navigation Bar", "Editable Location"));
1271 editableLocation->setWhatsThis(xi18nc("@info:whatsthis",
1272 "This toggles the <emphasis>Location Bar</emphasis> to be "
1273 "editable so you can directly enter a location you want to go to.<nl/>"
1274 "You can also switch to editing by clicking to the right of the "
1275 "location and switch back by confirming the edited location."));
1276 actionCollection()->setDefaultShortcut(editableLocation, Qt::Key_F6);
1277 connect(editableLocation, &KToggleAction::triggered, this, &DolphinMainWindow::toggleEditLocation);
1278
1279 QAction* replaceLocation = actionCollection()->addAction(QStringLiteral("replace_location"));
1280 replaceLocation->setText(i18nc("@action:inmenu Navigation Bar", "Replace Location"));
1281 // i18n: "enter" is used both in the meaning of "writing" and "going to" a new location here.
1282 // Both meanings are useful but not necessary to understand the use of "Replace Location".
1283 // So you might want to be more verbose in your language to convey the meaning but it's up to you.
1284 replaceLocation->setWhatsThis(xi18nc("@info:whatsthis",
1285 "This switches to editing the location and selects it "
1286 "so you can quickly enter a different location."));
1287 actionCollection()->setDefaultShortcut(replaceLocation, Qt::CTRL + Qt::Key_L);
1288 connect(replaceLocation, &QAction::triggered, this, &DolphinMainWindow::replaceLocation);
1289
1290 // setup 'Go' menu
1291 QAction* backAction = KStandardAction::back(this, &DolphinMainWindow::goBack, actionCollection());
1292 auto backShortcuts = backAction->shortcuts();
1293 backShortcuts.append(QKeySequence(Qt::Key_Backspace));
1294 actionCollection()->setDefaultShortcuts(backAction, backShortcuts);
1295
1296 DolphinRecentTabsMenu* recentTabsMenu = new DolphinRecentTabsMenu(this);
1297 actionCollection()->addAction(QStringLiteral("closed_tabs"), recentTabsMenu);
1298 connect(m_tabWidget, &DolphinTabWidget::rememberClosedTab,
1299 recentTabsMenu, &DolphinRecentTabsMenu::rememberClosedTab);
1300 connect(recentTabsMenu, &DolphinRecentTabsMenu::restoreClosedTab,
1301 m_tabWidget, &DolphinTabWidget::restoreClosedTab);
1302 connect(recentTabsMenu, &DolphinRecentTabsMenu::closedTabsCountChanged,
1303 this, &DolphinMainWindow::closedTabsCountChanged);
1304
1305 QAction* undoCloseTab = actionCollection()->addAction(QStringLiteral("undo_close_tab"));
1306 undoCloseTab->setText(i18nc("@action:inmenu File", "Undo close tab"));
1307 undoCloseTab->setWhatsThis(i18nc("@info:whatsthis undo close tab",
1308 "This returns you to the previously closed tab."));
1309 actionCollection()->setDefaultShortcut(undoCloseTab, Qt::CTRL + Qt::SHIFT + Qt::Key_T);
1310 undoCloseTab->setIcon(QIcon::fromTheme(QStringLiteral("edit-undo")));
1311 undoCloseTab->setEnabled(false);
1312 connect(undoCloseTab, &QAction::triggered, recentTabsMenu, &DolphinRecentTabsMenu::undoCloseTab);
1313
1314 auto undoAction = actionCollection()->action(KStandardAction::name(KStandardAction::Undo));
1315 undoAction->setWhatsThis(xi18nc("@info:whatsthis", "This undoes "
1316 "the last change you made to files or folders.<nl/>"
1317 "Such changes include <interface>creating, renaming</interface> "
1318 "and <interface>moving</interface> them to a different location "
1319 "or to the <filename>Trash</filename>. <nl/>Changes that can't "
1320 "be undone will ask for your confirmation."));
1321 undoAction->setEnabled(false); // undo should be disabled by default
1322
1323 KStandardAction::forward(this, &DolphinMainWindow::goForward, actionCollection());
1324 KStandardAction::up(this, &DolphinMainWindow::goUp, actionCollection());
1325 QAction* homeAction = KStandardAction::home(this, &DolphinMainWindow::goHome, actionCollection());
1326 homeAction->setWhatsThis(xi18nc("@info:whatsthis", "Go to your "
1327 "<filename>Home</filename> folder.<nl/>Every user account "
1328 "has their own <filename>Home</filename> that contains their data "
1329 "including folders that contain personal application data."));
1330
1331 // setup 'Tools' menu
1332 QAction* showFilterBar = actionCollection()->addAction(QStringLiteral("show_filter_bar"));
1333 showFilterBar->setText(i18nc("@action:inmenu Tools", "Show Filter Bar"));
1334 showFilterBar->setWhatsThis(xi18nc("@info:whatsthis", "This opens the "
1335 "<emphasis>Filter Bar</emphasis> at the bottom of the window.<nl/> "
1336 "There you can enter a text to filter the files and folders currently displayed. "
1337 "Only those that contain the text in their name will be kept in view."));
1338 showFilterBar->setIcon(QIcon::fromTheme(QStringLiteral("view-filter")));
1339 actionCollection()->setDefaultShortcuts(showFilterBar, {Qt::CTRL + Qt::Key_I, Qt::Key_Slash});
1340 connect(showFilterBar, &QAction::triggered, this, &DolphinMainWindow::showFilterBar);
1341
1342 QAction* compareFiles = actionCollection()->addAction(QStringLiteral("compare_files"));
1343 compareFiles->setText(i18nc("@action:inmenu Tools", "Compare Files"));
1344 compareFiles->setIcon(QIcon::fromTheme(QStringLiteral("kompare")));
1345 compareFiles->setEnabled(false);
1346 connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles);
1347
1348 #ifdef HAVE_TERMINAL
1349 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1350 QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal"));
1351 openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal"));
1352 openTerminal->setWhatsThis(xi18nc("@info:whatsthis",
1353 "<para>This opens a <emphasis>terminal</emphasis> application for the viewed location.</para>"
1354 "<para>To learn more about terminals use the help in the terminal application.</para>"));
1355 openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
1356 actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4);
1357 connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal);
1358 }
1359 #endif
1360
1361 // setup 'Bookmarks' menu
1362 KActionMenu *bookmarkMenu = new KActionMenu(i18nc("@title:menu", "&Bookmarks"), this);
1363 bookmarkMenu->setIcon(QIcon::fromTheme(QStringLiteral("bookmarks")));
1364 // Make the toolbar button version work properly on click
1365 bookmarkMenu->setDelayed(false);
1366 m_bookmarkHandler = new DolphinBookmarkHandler(this, actionCollection(), bookmarkMenu->menu(), this);
1367 actionCollection()->addAction(QStringLiteral("bookmarks"), bookmarkMenu);
1368
1369 // setup 'Settings' menu
1370 KToggleAction* showMenuBar = KStandardAction::showMenubar(nullptr, nullptr, actionCollection());
1371 showMenuBar->setWhatsThis(xi18nc("@info:whatsthis",
1372 "This switches between having a <emphasis>Menubar</emphasis> "
1373 "and having a <interface>Control</interface> button. Both "
1374 "contain mostly the same commands and configuration options."));
1375 connect(showMenuBar, &KToggleAction::triggered, // Fixes #286822
1376 this, &DolphinMainWindow::toggleShowMenuBar, Qt::QueuedConnection);
1377 KStandardAction::preferences(this, &DolphinMainWindow::editSettings, actionCollection());
1378
1379 // setup 'Help' menu for the m_controlButton. The other one is set up in the base class.
1380 m_helpMenu = new KHelpMenu(nullptr);
1381 m_helpMenu->menu()->installEventFilter(this);
1382 // remove duplicate shortcuts
1383 m_helpMenu->action(KHelpMenu::menuHelpContents)->setShortcut(QKeySequence());
1384 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setShortcut(QKeySequence());
1385
1386 // not in menu actions
1387 QList<QKeySequence> nextTabKeys = KStandardShortcut::tabNext();
1388 nextTabKeys.append(QKeySequence(Qt::CTRL + Qt::Key_Tab));
1389
1390 QList<QKeySequence> prevTabKeys = KStandardShortcut::tabPrev();
1391 prevTabKeys.append(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Tab));
1392
1393 QAction* activateNextTab = actionCollection()->addAction(QStringLiteral("activate_next_tab"));
1394 activateNextTab->setIconText(i18nc("@action:inmenu", "Next Tab"));
1395 activateNextTab->setText(i18nc("@action:inmenu", "Activate Next Tab"));
1396 activateNextTab->setEnabled(false);
1397 connect(activateNextTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activateNextTab);
1398 actionCollection()->setDefaultShortcuts(activateNextTab, nextTabKeys);
1399
1400 QAction* activatePrevTab = actionCollection()->addAction(QStringLiteral("activate_prev_tab"));
1401 activatePrevTab->setIconText(i18nc("@action:inmenu", "Previous Tab"));
1402 activatePrevTab->setText(i18nc("@action:inmenu", "Activate Previous Tab"));
1403 activatePrevTab->setEnabled(false);
1404 connect(activatePrevTab, &QAction::triggered, m_tabWidget, &DolphinTabWidget::activatePrevTab);
1405 actionCollection()->setDefaultShortcuts(activatePrevTab, prevTabKeys);
1406
1407 // for context menu
1408 QAction* showTarget = actionCollection()->addAction(QStringLiteral("show_target"));
1409 showTarget->setText(i18nc("@action:inmenu", "Show Target"));
1410 showTarget->setIcon(QIcon::fromTheme(QStringLiteral("document-open-folder")));
1411 showTarget->setEnabled(false);
1412 connect(showTarget, &QAction::triggered, this, &DolphinMainWindow::showTarget);
1413
1414 QAction* openInNewTab = actionCollection()->addAction(QStringLiteral("open_in_new_tab"));
1415 openInNewTab->setText(i18nc("@action:inmenu", "Open in New Tab"));
1416 openInNewTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1417 connect(openInNewTab, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1418
1419 QAction* openInNewTabs = actionCollection()->addAction(QStringLiteral("open_in_new_tabs"));
1420 openInNewTabs->setText(i18nc("@action:inmenu", "Open in New Tabs"));
1421 openInNewTabs->setIcon(QIcon::fromTheme(QStringLiteral("tab-new")));
1422 connect(openInNewTabs, &QAction::triggered, this, &DolphinMainWindow::openInNewTab);
1423
1424 QAction* openInNewWindow = actionCollection()->addAction(QStringLiteral("open_in_new_window"));
1425 openInNewWindow->setText(i18nc("@action:inmenu", "Open in New Window"));
1426 openInNewWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new")));
1427 connect(openInNewWindow, &QAction::triggered, this, &DolphinMainWindow::openInNewWindow);
1428 }
1429
1430 void DolphinMainWindow::setupDockWidgets()
1431 {
1432 const bool lock = GeneralSettings::lockPanels();
1433
1434 KDualAction* lockLayoutAction = actionCollection()->add<KDualAction>(QStringLiteral("lock_panels"));
1435 lockLayoutAction->setActiveText(i18nc("@action:inmenu Panels", "Unlock Panels"));
1436 lockLayoutAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("object-unlocked")));
1437 lockLayoutAction->setInactiveText(i18nc("@action:inmenu Panels", "Lock Panels"));
1438 lockLayoutAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("object-locked")));
1439 lockLayoutAction->setWhatsThis(xi18nc("@info:whatsthis", "This "
1440 "switches between having panels <emphasis>locked</emphasis> or "
1441 "<emphasis>unlocked</emphasis>.<nl/>Unlocked panels can be "
1442 "dragged to the other side of the window and have a close "
1443 "button.<nl/>Locked panels are embedded more cleanly."));
1444 lockLayoutAction->setActive(lock);
1445 connect(lockLayoutAction, &KDualAction::triggered, this, &DolphinMainWindow::togglePanelLockState);
1446
1447 // Setup "Information"
1448 DolphinDockWidget* infoDock = new DolphinDockWidget(i18nc("@title:window", "Information"));
1449 infoDock->setLocked(lock);
1450 infoDock->setObjectName(QStringLiteral("infoDock"));
1451 infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1452
1453 #ifdef HAVE_BALOO
1454 InformationPanel* infoPanel = new InformationPanel(infoDock);
1455 infoPanel->setCustomContextMenuActions({lockLayoutAction});
1456 connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl);
1457 infoDock->setWidget(infoPanel);
1458
1459 QAction* infoAction = infoDock->toggleViewAction();
1460 createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-information")), Qt::Key_F11, infoAction, QStringLiteral("show_information_panel"));
1461
1462 addDockWidget(Qt::RightDockWidgetArea, infoDock);
1463 connect(this, &DolphinMainWindow::urlChanged,
1464 infoPanel, &InformationPanel::setUrl);
1465 connect(this, &DolphinMainWindow::selectionChanged,
1466 infoPanel, &InformationPanel::setSelection);
1467 connect(this, &DolphinMainWindow::requestItemInfo,
1468 infoPanel, &InformationPanel::requestDelayedItemInfo);
1469 #endif
1470
1471 // i18n: This is the last paragraph for the "What's This"-texts of all four panels.
1472 const QString panelWhatsThis = xi18nc("@info:whatsthis", "<para>To show or "
1473 "hide panels like this go to <interface>Control|Panels</interface> "
1474 "or <interface>View|Panels</interface>.</para>");
1475 #ifdef HAVE_BALOO
1476 actionCollection()->action(QStringLiteral("show_information_panel"))
1477 ->setWhatsThis(xi18nc("@info:whatsthis", "<para> This toggles the "
1478 "<emphasis>information</emphasis> panel at the right side of the "
1479 "window.</para><para>The panel provides in-depth information "
1480 "about the items your mouse is hovering over or about the selected "
1481 "items. Otherwise it informs you about the currently viewed folder.<nl/>"
1482 "For single items a preview of their contents is provided.</para>"));
1483 #endif
1484 infoDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1485 "provides in-depth information about the items your mouse is "
1486 "hovering over or about the selected items. Otherwise it informs "
1487 "you about the currently viewed folder.<nl/>For single items a "
1488 "preview of their contents is provided.</para><para>You can configure "
1489 "which and how details are given here by right-clicking.</para>") + panelWhatsThis);
1490
1491 // Setup "Folders"
1492 DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders"));
1493 foldersDock->setLocked(lock);
1494 foldersDock->setObjectName(QStringLiteral("foldersDock"));
1495 foldersDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1496 FoldersPanel* foldersPanel = new FoldersPanel(foldersDock);
1497 foldersPanel->setCustomContextMenuActions({lockLayoutAction});
1498 foldersDock->setWidget(foldersPanel);
1499
1500 QAction* foldersAction = foldersDock->toggleViewAction();
1501 createPanelAction(QIcon::fromTheme(QStringLiteral("folder")), Qt::Key_F7, foldersAction, QStringLiteral("show_folders_panel"));
1502
1503 addDockWidget(Qt::LeftDockWidgetArea, foldersDock);
1504 connect(this, &DolphinMainWindow::urlChanged,
1505 foldersPanel, &FoldersPanel::setUrl);
1506 connect(foldersPanel, &FoldersPanel::folderActivated,
1507 this, &DolphinMainWindow::changeUrl);
1508 connect(foldersPanel, &FoldersPanel::folderMiddleClicked,
1509 this, &DolphinMainWindow::openNewTabAfterCurrentTab);
1510 connect(foldersPanel, &FoldersPanel::errorMessage,
1511 this, &DolphinMainWindow::showErrorMessage);
1512
1513 actionCollection()->action(QStringLiteral("show_folders_panel"))
1514 ->setWhatsThis(xi18nc("@info:whatsthis", "This toggles the "
1515 "<emphasis>folders</emphasis> panel at the left side of the window."
1516 "<nl/><nl/>It shows the folders of the <emphasis>file system"
1517 "</emphasis> in a <emphasis>tree view</emphasis>."));
1518 foldersDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This panel "
1519 "shows the folders of the <emphasis>file system</emphasis> in a "
1520 "<emphasis>tree view</emphasis>.</para><para>Click a folder to go "
1521 "there. Click the arrow to the left of a folder to see its subfolders. "
1522 "This allows quick switching between any folders.</para>") + panelWhatsThis);
1523
1524 // Setup "Terminal"
1525 #ifdef HAVE_TERMINAL
1526 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
1527 DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal"));
1528 terminalDock->setLocked(lock);
1529 terminalDock->setObjectName(QStringLiteral("terminalDock"));
1530 m_terminalPanel = new TerminalPanel(terminalDock);
1531 m_terminalPanel->setCustomContextMenuActions({lockLayoutAction});
1532 terminalDock->setWidget(m_terminalPanel);
1533
1534 connect(m_terminalPanel, &TerminalPanel::hideTerminalPanel, terminalDock, &DolphinDockWidget::hide);
1535 connect(m_terminalPanel, &TerminalPanel::changeUrl, this, &DolphinMainWindow::slotTerminalDirectoryChanged);
1536 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
1537 m_terminalPanel, &TerminalPanel::dockVisibilityChanged);
1538 connect(terminalDock, &DolphinDockWidget::visibilityChanged,
1539 this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged);
1540
1541 QAction* terminalAction = terminalDock->toggleViewAction();
1542 createPanelAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel"));
1543
1544 addDockWidget(Qt::BottomDockWidgetArea, terminalDock);
1545 connect(this, &DolphinMainWindow::urlChanged,
1546 m_terminalPanel, &TerminalPanel::setUrl);
1547
1548 if (GeneralSettings::version() < 200) {
1549 terminalDock->hide();
1550 }
1551
1552 actionCollection()->action(QStringLiteral("show_terminal_panel"))
1553 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1554 "<emphasis>terminal</emphasis> panel at the bottom of the window."
1555 "<nl/>The location in the terminal will always match the folder "
1556 "view so you can navigate using either.</para><para>The terminal "
1557 "panel is not needed for basic computer usage but can be useful "
1558 "for advanced tasks. To learn more about terminals use the help "
1559 "in a standalone terminal application like Konsole.</para>"));
1560 terminalDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is "
1561 "the <emphasis>terminal</emphasis> panel. It behaves like a "
1562 "normal terminal but will match the location of the folder view "
1563 "so you can navigate using either.</para><para>The terminal panel "
1564 "is not needed for basic computer usage but can be useful for "
1565 "advanced tasks. To learn more about terminals use the help in a "
1566 "standalone terminal application like Konsole.</para>") + panelWhatsThis);
1567 }
1568 #endif
1569
1570 if (GeneralSettings::version() < 200) {
1571 infoDock->hide();
1572 foldersDock->hide();
1573 }
1574
1575 // Setup "Places"
1576 DolphinDockWidget* placesDock = new DolphinDockWidget(i18nc("@title:window", "Places"));
1577 placesDock->setLocked(lock);
1578 placesDock->setObjectName(QStringLiteral("placesDock"));
1579 placesDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
1580
1581 m_placesPanel = new PlacesPanel(placesDock);
1582 m_placesPanel->setCustomContextMenuActions({lockLayoutAction});
1583 placesDock->setWidget(m_placesPanel);
1584
1585 QAction *placesAction = placesDock->toggleViewAction();
1586 createPanelAction(QIcon::fromTheme(QStringLiteral("bookmarks")), Qt::Key_F9, placesAction, QStringLiteral("show_places_panel"));
1587
1588 addDockWidget(Qt::LeftDockWidgetArea, placesDock);
1589 connect(m_placesPanel, &PlacesPanel::placeActivated,
1590 this, &DolphinMainWindow::slotPlaceActivated);
1591 connect(m_placesPanel, &PlacesPanel::placeMiddleClicked,
1592 this, &DolphinMainWindow::openNewTabAfterCurrentTab);
1593 connect(m_placesPanel, &PlacesPanel::errorMessage,
1594 this, &DolphinMainWindow::showErrorMessage);
1595 connect(this, &DolphinMainWindow::urlChanged,
1596 m_placesPanel, &PlacesPanel::setUrl);
1597 connect(placesDock, &DolphinDockWidget::visibilityChanged,
1598 m_tabWidget, &DolphinTabWidget::slotPlacesPanelVisibilityChanged);
1599 connect(this, &DolphinMainWindow::settingsChanged,
1600 m_placesPanel, &PlacesPanel::readSettings);
1601 connect(m_placesPanel, &PlacesPanel::storageTearDownRequested,
1602 this, &DolphinMainWindow::slotStorageTearDownFromPlacesRequested);
1603 connect(m_placesPanel, &PlacesPanel::storageTearDownExternallyRequested,
1604 this, &DolphinMainWindow::slotStorageTearDownExternallyRequested);
1605 m_tabWidget->slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible());
1606
1607 auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("hint")), i18nc("@item:inmenu", "Show Hidden Places"), this);
1608 actionShowAllPlaces->setCheckable(true);
1609 actionShowAllPlaces->setDisabled(true);
1610 actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays "
1611 "all places in the places panel that have been hidden. They will "
1612 "appear semi-transparent unless you uncheck their hide property."));
1613
1614 connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){
1615 actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("visibility") : QStringLiteral("hint")));
1616 m_placesPanel->showHiddenEntries(checked);
1617 });
1618
1619 connect(m_placesPanel, &PlacesPanel::showHiddenEntriesChanged, this, [actionShowAllPlaces] (bool checked){
1620 actionShowAllPlaces->setChecked(checked);
1621 actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("visibility") : QStringLiteral("hint")));
1622 });
1623
1624 actionCollection()->action(QStringLiteral("show_places_panel"))
1625 ->setWhatsThis(xi18nc("@info:whatsthis", "<para>This toggles the "
1626 "<emphasis>places</emphasis> panel at the left side of the window."
1627 "</para><para>It allows you to go to locations you have "
1628 "bookmarked and to access disk or media attached to the computer "
1629 "or to the network. It also contains sections to find recently "
1630 "saved files or files of a certain type.</para>"));
1631 placesDock->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1632 "<emphasis>Places</emphasis> panel. It allows you to go to locations "
1633 "you have bookmarked and to access disk or media attached to the "
1634 "computer or to the network. It also contains sections to find "
1635 "recently saved files or files of a certain type.</para><para>"
1636 "Click on an entry to go there. Click with the right mouse button "
1637 "instead to open any entry in a new tab or new window.</para>"
1638 "<para>New entries can be added by dragging folders onto this panel. "
1639 "Right-click any section or entry to hide it. Right-click an empty "
1640 "space on this panel and select <interface>Show Hidden Places"
1641 "</interface> to display it again.</para>") + panelWhatsThis);
1642
1643 // Add actions into the "Panels" menu
1644 KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this);
1645 actionCollection()->addAction(QStringLiteral("panels"), panelsMenu);
1646 panelsMenu->setDelayed(false);
1647 const KActionCollection* ac = actionCollection();
1648 panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel")));
1649 #ifdef HAVE_BALOO
1650 panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel")));
1651 #endif
1652 panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel")));
1653 panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel")));
1654 panelsMenu->addSeparator();
1655 panelsMenu->addAction(actionShowAllPlaces);
1656 panelsMenu->addAction(lockLayoutAction);
1657
1658 connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{
1659 actionShowAllPlaces->setEnabled(m_placesPanel->hiddenListCount());
1660 });
1661 }
1662
1663 void DolphinMainWindow::updateEditActions()
1664 {
1665 const KFileItemList list = m_activeViewContainer->view()->selectedItems();
1666 if (list.isEmpty()) {
1667 stateChanged(QStringLiteral("has_no_selection"));
1668 } else {
1669 stateChanged(QStringLiteral("has_selection"));
1670
1671 KActionCollection* col = actionCollection();
1672 QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile));
1673 QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash));
1674 QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile));
1675 QAction* cutAction = col->action(KStandardAction::name(KStandardAction::Cut));
1676 QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
1677 QAction* showTarget = col->action(QStringLiteral("show_target"));
1678
1679 KFileItemListProperties capabilities(list);
1680 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
1681
1682 renameAction->setEnabled(capabilities.supportsMoving());
1683 moveToTrashAction->setEnabled(enableMoveToTrash);
1684 deleteAction->setEnabled(capabilities.supportsDeleting());
1685 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
1686 cutAction->setEnabled(capabilities.supportsMoving());
1687 showTarget->setEnabled(list.length() == 1 && list.at(0).isLink());
1688 }
1689 }
1690
1691 void DolphinMainWindow::updateViewActions()
1692 {
1693 m_actionHandler->updateViewActions();
1694
1695 QAction* showFilterBarAction = actionCollection()->action(QStringLiteral("show_filter_bar"));
1696 showFilterBarAction->setChecked(m_activeViewContainer->isFilterBarVisible());
1697
1698 updateSplitAction();
1699
1700 QAction* editableLocactionAction = actionCollection()->action(QStringLiteral("editable_location"));
1701 const KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator();
1702 editableLocactionAction->setChecked(urlNavigator->isUrlEditable());
1703 }
1704
1705 void DolphinMainWindow::updateGoActions()
1706 {
1707 QAction* goUpAction = actionCollection()->action(KStandardAction::name(KStandardAction::Up));
1708 const QUrl currentUrl = m_activeViewContainer->url();
1709 // I think this is one of the best places to firstly be confronted
1710 // with a file system and its hierarchy. Talking about the root
1711 // directory might seem too much here but it is the question that
1712 // naturally arises in this context.
1713 goUpAction->setWhatsThis(xi18nc("@info:whatsthis", "<para>Go to "
1714 "the folder that contains the currently viewed one.</para>"
1715 "<para>All files and folders are organized in a hierarchical "
1716 "<emphasis>file system</emphasis>. At the top of this hierarchy is "
1717 "a directory that contains all data connected to this computer"
1718 "—the <emphasis>root directory</emphasis>.</para>"));
1719 goUpAction->setEnabled(KIO::upUrl(currentUrl) != currentUrl);
1720 }
1721
1722 void DolphinMainWindow::createControlButton()
1723 {
1724 if (m_controlButton) {
1725 return;
1726 }
1727 Q_ASSERT(!m_controlButton);
1728
1729 m_controlButton = new QToolButton(this);
1730 m_controlButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
1731 m_controlButton->setToolTip(i18nc("@action", "Show menu"));
1732 m_controlButton->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis);
1733 m_controlButton->setPopupMode(QToolButton::InstantPopup);
1734
1735 QMenu* controlMenu = new QMenu(m_controlButton);
1736 connect(controlMenu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateControlMenu);
1737 controlMenu->installEventFilter(this);
1738
1739 m_controlButton->setMenu(controlMenu);
1740
1741 toolBar()->addWidget(m_controlButton);
1742 connect(toolBar(), &KToolBar::iconSizeChanged,
1743 m_controlButton, &QToolButton::setIconSize);
1744
1745 // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar
1746 // gets edited. In this case we must add them again. The adding is done asynchronously by
1747 // m_updateToolBarTimer.
1748 connect(m_controlButton, &QToolButton::destroyed, this, &DolphinMainWindow::slotControlButtonDeleted);
1749 m_updateToolBarTimer = new QTimer(this);
1750 m_updateToolBarTimer->setInterval(500);
1751 connect(m_updateToolBarTimer, &QTimer::timeout, this, &DolphinMainWindow::updateToolBar);
1752 }
1753
1754 void DolphinMainWindow::deleteControlButton()
1755 {
1756 delete m_controlButton;
1757 m_controlButton = nullptr;
1758
1759 delete m_updateToolBarTimer;
1760 m_updateToolBarTimer = nullptr;
1761 }
1762
1763 bool DolphinMainWindow::addActionToMenu(QAction* action, QMenu* menu)
1764 {
1765 Q_ASSERT(action);
1766 Q_ASSERT(menu);
1767
1768 const KToolBar* toolBarWidget = toolBar();
1769 foreach (const QWidget* widget, action->associatedWidgets()) {
1770 if (widget == toolBarWidget) {
1771 return false;
1772 }
1773 }
1774
1775 menu->addAction(action);
1776 return true;
1777 }
1778
1779 void DolphinMainWindow::refreshViews()
1780 {
1781 m_tabWidget->refreshViews();
1782
1783 if (GeneralSettings::modifiedStartupSettings()) {
1784 // The startup settings have been changed by the user (see bug #254947).
1785 // Synchronize the split-view setting with the active view:
1786 const bool splitView = GeneralSettings::splitView();
1787 m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView);
1788 updateSplitAction();
1789 updateWindowTitle();
1790 }
1791
1792 emit settingsChanged();
1793 }
1794
1795 void DolphinMainWindow::clearStatusBar()
1796 {
1797 m_activeViewContainer->statusBar()->resetToDefaultText();
1798 }
1799
1800 void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container)
1801 {
1802 connect(container, &DolphinViewContainer::showFilterBarChanged,
1803 this, &DolphinMainWindow::updateFilterBarAction);
1804 connect(container, &DolphinViewContainer::writeStateChanged,
1805 this, &DolphinMainWindow::slotWriteStateChanged);
1806
1807 const DolphinView* view = container->view();
1808 connect(view, &DolphinView::selectionChanged,
1809 this, &DolphinMainWindow::slotSelectionChanged);
1810 connect(view, &DolphinView::requestItemInfo,
1811 this, &DolphinMainWindow::requestItemInfo);
1812 connect(view, &DolphinView::tabRequested,
1813 this, &DolphinMainWindow::openNewTab);
1814 connect(view, &DolphinView::requestContextMenu,
1815 this, &DolphinMainWindow::openContextMenu);
1816 connect(view, &DolphinView::directoryLoadingStarted,
1817 this, &DolphinMainWindow::enableStopAction);
1818 connect(view, &DolphinView::directoryLoadingCompleted,
1819 this, &DolphinMainWindow::disableStopAction);
1820 connect(view, &DolphinView::directoryLoadingCompleted,
1821 this, &DolphinMainWindow::slotDirectoryLoadingCompleted);
1822 connect(view, &DolphinView::goBackRequested,
1823 this, &DolphinMainWindow::goBack);
1824 connect(view, &DolphinView::goForwardRequested,
1825 this, &DolphinMainWindow::goForward);
1826 connect(view, &DolphinView::urlActivated,
1827 this, &DolphinMainWindow::handleUrl);
1828
1829 const KUrlNavigator* navigator = container->urlNavigator();
1830 connect(navigator, &KUrlNavigator::urlChanged,
1831 this, &DolphinMainWindow::changeUrl);
1832 connect(navigator, &KUrlNavigator::historyChanged,
1833 this, &DolphinMainWindow::updateHistory);
1834 connect(navigator, &KUrlNavigator::editableStateChanged,
1835 this, &DolphinMainWindow::slotEditableStateChanged);
1836 connect(navigator, &KUrlNavigator::tabRequested,
1837 this, &DolphinMainWindow::openNewTabAfterLastTab);
1838 }
1839
1840 void DolphinMainWindow::updateSplitAction()
1841 {
1842 QAction* splitAction = actionCollection()->action(QStringLiteral("split_view"));
1843 const DolphinTabPage* tabPage = m_tabWidget->currentTabPage();
1844 if (tabPage->splitViewEnabled()) {
1845 if (GeneralSettings::closeActiveSplitView() ? tabPage->primaryViewActive() : !tabPage->primaryViewActive()) {
1846 splitAction->setText(i18nc("@action:intoolbar Close left view", "Close"));
1847 splitAction->setToolTip(i18nc("@info", "Close left view"));
1848 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-left-close")));
1849 } else {
1850 splitAction->setText(i18nc("@action:intoolbar Close right view", "Close"));
1851 splitAction->setToolTip(i18nc("@info", "Close right view"));
1852 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-close")));
1853 }
1854 } else {
1855 splitAction->setText(i18nc("@action:intoolbar Split view", "Split"));
1856 splitAction->setToolTip(i18nc("@info", "Split view"));
1857 splitAction->setIcon(QIcon::fromTheme(QStringLiteral("view-right-new")));
1858 }
1859 }
1860
1861 bool DolphinMainWindow::isKompareInstalled() const
1862 {
1863 static bool initialized = false;
1864 static bool installed = false;
1865 if (!initialized) {
1866 // TODO: maybe replace this approach later by using a menu
1867 // plugin like kdiff3plugin.cpp
1868 installed = !QStandardPaths::findExecutable(QStringLiteral("kompare")).isEmpty();
1869 initialized = true;
1870 }
1871 return installed;
1872 }
1873
1874 void DolphinMainWindow::createPanelAction(const QIcon& icon,
1875 const QKeySequence& shortcut,
1876 QAction* dockAction,
1877 const QString& actionName)
1878 {
1879 QAction* panelAction = actionCollection()->addAction(actionName);
1880 panelAction->setCheckable(true);
1881 panelAction->setChecked(dockAction->isChecked());
1882 panelAction->setText(dockAction->text());
1883 panelAction->setIcon(icon);
1884 actionCollection()->setDefaultShortcut(panelAction, shortcut);
1885
1886 connect(panelAction, &QAction::triggered, dockAction, &QAction::trigger);
1887 connect(dockAction, &QAction::toggled, panelAction, &QAction::setChecked);
1888 }
1889
1890 void DolphinMainWindow::setupWhatsThis()
1891 {
1892 // main widgets
1893 menuBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1894 "<emphasis>Menubar</emphasis>. It provides access to commands and "
1895 "configuration options. Left-click on any of the menus on this "
1896 "bar to see its contents.</para><para>The Menubar can be hidden "
1897 "by unchecking <interface>Settings|Show Menubar</interface>. Then "
1898 "most of its contents become available through a <interface>Control"
1899 "</interface> button on the <emphasis>Toolbar</emphasis>.</para>"));
1900 toolBar()->setWhatsThis(xi18nc("@info:whatsthis", "<para>This is the "
1901 "<emphasis>Toolbar</emphasis>. It allows quick access to "
1902 "frequently used actions.</para><para>It is highly customizable. "
1903 "All items you see in the <interface>Control</interface> menu or "
1904 "in the <interface>Menubar</interface> can be placed on the "
1905 "Toolbar. Just right-click on it and select <interface>Configure "
1906 "Toolbars…</interface> or find this action in the <interface>"
1907 "Control</interface> or <interface>Settings</interface> menu."
1908 "</para><para>The location of the bar and the style of its "
1909 "buttons can also be changed in the right-click menu. Right-click "
1910 "a button if you want to show or hide its text.</para>"));
1911 m_tabWidget->setWhatsThis(xi18nc("@info:whatsthis main view",
1912 "<para>Here you can see the <emphasis>folders</emphasis> and "
1913 "<emphasis>files</emphasis> that are at the location described in "
1914 "the <interface>Location Bar</interface> above. This area is the "
1915 "central part of this application where you navigate to the files "
1916 "you want to use.</para><para>For an elaborate and general "
1917 "introduction to this application <link "
1918 "url='https://userbase.kde.org/Dolphin/File_Management#Introduction_to_Dolphin'>"
1919 "click here</link>. This will open an introductory article from "
1920 "the <emphasis>KDE UserBase Wiki</emphasis>.</para><para>For brief "
1921 "explanations of all the features of this <emphasis>view</emphasis> "
1922 "<link url='help:/dolphin/dolphin-view.html'>click here</link> "
1923 "instead. This will open a page from the <emphasis>Handbook"
1924 "</emphasis> that covers the basics.</para>"));
1925
1926 // Settings menu
1927 actionCollection()->action(KStandardAction::name(KStandardAction::KeyBindings))
1928 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window "
1929 "that lists the <emphasis>keyboard shortcuts</emphasis>.<nl/>"
1930 "There you can set up key combinations to trigger an action when "
1931 "they are pressed simultaneously. All commands in this application can "
1932 "be triggered this way.</para>"));
1933 actionCollection()->action(KStandardAction::name(KStandardAction::ConfigureToolbars))
1934 ->setWhatsThis(xi18nc("@info:whatsthis","<para>This opens a window in which "
1935 "you can change which buttons appear on the <emphasis>Toolbar</emphasis>.</para>"
1936 "<para>All items you see in the <interface>Control</interface> menu "
1937 "or in the <interface>Menubar</interface> can also be placed on the Toolbar.</para>"));
1938 actionCollection()->action(KStandardAction::name(KStandardAction::Preferences))
1939 ->setWhatsThis(xi18nc("@info:whatsthis","This opens a window where you can "
1940 "change a multitude of settings for this application. For an explanation "
1941 "of the various settings go to the chapter <emphasis>Configuring Dolphin"
1942 "</emphasis> in <interface>Help|Dolphin Handbook</interface>."));
1943
1944 // Help menu
1945 // The whatsthis has to be set for the m_helpMenu and for the
1946 // StandardAction separately because both are used in different locations.
1947 // m_helpMenu is only used for createControlButton() button.
1948
1949 // Links do not work within the Menubar so texts without links are provided there.
1950
1951 // i18n: If the external link isn't available in your language you should
1952 // probably state the external link language at least in brackets to not
1953 // frustrate the user. If there are multiple languages that the user might
1954 // know with a reasonable chance you might want to have 2 external links.
1955 // The same is in my opinion true for every external link you translate.
1956 const QString whatsThisHelpContents = xi18nc("@info:whatsthis handbook",
1957 "<para>This opens the Handbook for this application. It provides "
1958 "explanations for every part of <emphasis>Dolphin</emphasis>.</para>");
1959 actionCollection()->action(KStandardAction::name(KStandardAction::HelpContents))
1960 ->setWhatsThis(whatsThisHelpContents
1961 + xi18nc("@info:whatsthis second half of handbook hb text without link",
1962 "<para>If you want more elaborate introductions to the "
1963 "different features of <emphasis>Dolphin</emphasis> "
1964 "go to the KDE UserBase Wiki.</para>"));
1965 m_helpMenu->action(KHelpMenu::menuHelpContents)->setWhatsThis(whatsThisHelpContents
1966 + xi18nc("@info:whatsthis second half of handbook text with link",
1967 "<para>If you want more elaborate introductions to the "
1968 "different features of <emphasis>Dolphin</emphasis> "
1969 "<link url='https://userbase.kde.org/Dolphin/File_Management'>click here</link>. "
1970 "It will open the dedicated page in the KDE UserBase Wiki.</para>"));
1971
1972 const QString whatsThisWhatsThis = xi18nc("@info:whatsthis whatsthis button",
1973 "<para>This is the button that invokes the help feature you are "
1974 "using right now! Click it, then click any component of this "
1975 "application to ask \"What's this?\" about it. The mouse cursor "
1976 "will change appearance if no help is available for a spot.</para>");
1977 actionCollection()->action(KStandardAction::name(KStandardAction::WhatsThis))
1978 ->setWhatsThis(whatsThisWhatsThis
1979 + xi18nc("@info:whatsthis second half of whatsthis button text without link",
1980 "<para>There are two other ways to get help for this application: The "
1981 "<interface>Dolphin Handbook</interface> in the <interface>Help"
1982 "</interface> menu and the <emphasis>KDE UserBase Wiki</emphasis> "
1983 "article about <emphasis>File Management</emphasis> online."
1984 "</para><para>The \"What's this?\" help is "
1985 "missing in most other windows so don't get too used to this.</para>"));
1986 m_helpMenu->action(KHelpMenu::menuWhatsThis)->setWhatsThis(whatsThisWhatsThis
1987 + xi18nc("@info:whatsthis second half of whatsthis button text with link",
1988 "<para>There are two other ways to get help: "
1989 "The <link url='help:/dolphin/index.html'>Dolphin Handbook</link> and "
1990 "the <link url='https://userbase.kde.org/Dolphin/File_Management'>KDE "
1991 "UserBase Wiki</link>.</para><para>The \"What's this?\" help is "
1992 "missing in most other windows so don't get too used to this.</para>"));
1993
1994 const QString whatsThisReportBug = xi18nc("@info:whatsthis","<para>This opens a "
1995 "window that will guide you through reporting errors or flaws "
1996 "in this application or in other KDE software.</para>");
1997 actionCollection()->action(KStandardAction::name(KStandardAction::ReportBug))
1998 ->setWhatsThis(whatsThisReportBug);
1999 m_helpMenu->action(KHelpMenu::menuReportBug)->setWhatsThis(whatsThisReportBug
2000 + xi18nc("@info:whatsthis second half of reportbug text with link",
2001 "<para>High-quality bug reports are much appreciated. To learn "
2002 "how to make your bug report as effective as possible "
2003 "<link url='https://community.kde.org/Get_Involved/Bug_Reporting'>"
2004 "click here</link>.</para>"));
2005
2006 const QString whatsThisDonate = xi18nc("@info:whatsthis","<para>This opens a "
2007 "<emphasis>web page</emphasis> where you can donate to "
2008 "support the continued work on this application and many "
2009 "other projects by the <emphasis>KDE</emphasis> community.</para>"
2010 "<para>Donating is the easiest and fastest way to efficiently "
2011 "support KDE and its projects. KDE projects are available for "
2012 "free therefore your donation is needed to cover things that "
2013 "require money like servers, contributor meetings, etc.</para>"
2014 "<para><emphasis>KDE e.V.</emphasis> is the non-profit "
2015 "organization behind the KDE community.</para>");
2016 actionCollection()->action(KStandardAction::name(KStandardAction::Donate))
2017 ->setWhatsThis(whatsThisDonate);
2018 m_helpMenu->action(KHelpMenu::menuDonate)->setWhatsThis(whatsThisDonate);
2019
2020 const QString whatsThisSwitchLanguage = xi18nc("@info:whatsthis",
2021 "With this you can change the language this application uses."
2022 "<nl/>You can even set secondary languages which will be used "
2023 "if texts are not available in your preferred language.");
2024 actionCollection()->action(KStandardAction::name(KStandardAction::SwitchApplicationLanguage))
2025 ->setWhatsThis(whatsThisSwitchLanguage);
2026 m_helpMenu->action(KHelpMenu::menuSwitchLanguage)->setWhatsThis(whatsThisSwitchLanguage);
2027
2028 const QString whatsThisAboutApp = xi18nc("@info:whatsthis","This opens a "
2029 "window that informs you about the version, license, "
2030 "used libraries and maintainers of this application.");
2031 actionCollection()->action(KStandardAction::name(KStandardAction::AboutApp))
2032 ->setWhatsThis(whatsThisAboutApp);
2033 m_helpMenu->action(KHelpMenu::menuAboutApp)->setWhatsThis(whatsThisAboutApp);
2034
2035 const QString whatsThisAboutKDE = xi18nc("@info:whatsthis","This opens a "
2036 "window with information about <emphasis>KDE</emphasis>. "
2037 "The KDE community are the people behind this free software."
2038 "<nl/>If you like using this application but don't know "
2039 "about KDE or want to see a cute dragon have a look!");
2040 actionCollection()->action(KStandardAction::name(KStandardAction::AboutKDE))
2041 ->setWhatsThis(whatsThisAboutKDE);
2042 m_helpMenu->action(KHelpMenu::menuAboutKDE)->setWhatsThis(whatsThisAboutKDE);
2043 }
2044
2045 bool DolphinMainWindow::event(QEvent *event)
2046 {
2047 if (event->type() == QEvent::WhatsThisClicked) {
2048 event->accept();
2049 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2050 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2051 return true;
2052 }
2053 return KXmlGuiWindow::event(event);
2054 }
2055
2056 bool DolphinMainWindow::eventFilter(QObject* obj, QEvent* event)
2057 {
2058 Q_UNUSED(obj)
2059 if (event->type() == QEvent::WhatsThisClicked) {
2060 event->accept();
2061 QWhatsThisClickedEvent* whatsThisEvent = dynamic_cast<QWhatsThisClickedEvent*>(event);
2062 QDesktopServices::openUrl(QUrl(whatsThisEvent->href()));
2063 return true;
2064 }
2065 return false;
2066 }
2067
2068 DolphinMainWindow::UndoUiInterface::UndoUiInterface() :
2069 KIO::FileUndoManager::UiInterface()
2070 {
2071 }
2072
2073 DolphinMainWindow::UndoUiInterface::~UndoUiInterface()
2074 {
2075 }
2076
2077 void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job)
2078 {
2079 DolphinMainWindow* mainWin= qobject_cast<DolphinMainWindow *>(parentWidget());
2080 if (mainWin) {
2081 DolphinViewContainer* container = mainWin->activeViewContainer();
2082 container->showMessage(job->errorString(), DolphinViewContainer::Error);
2083 } else {
2084 KIO::FileUndoManager::UiInterface::jobError(job);
2085 }
2086 }
2087
2088 bool DolphinMainWindow::isUrlOpen(const QString& url)
2089 {
2090 if (m_tabWidget->getIndexByUrl(QUrl::fromUserInput((url))) >= 0) {
2091 return true;
2092 } else {
2093 return false;
2094 }
2095 }
2096