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