]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Adapt to KConfigGroup name officially being a QString type
[dolphin.git] / src / dolphinpart.cpp
1 /* This file is part of the KDE project
2 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 #include "dolphinpart.h"
8
9 #include "dolphindebug.h"
10 #include "dolphinnewfilemenu.h"
11 #include "dolphinpart_ext.h"
12 #include "dolphinremoveaction.h"
13 #include "kitemviews/kfileitemmodel.h"
14 #include "views/dolphinnewfilemenuobserver.h"
15 #include "views/dolphinremoteencoding.h"
16 #include "views/dolphinview.h"
17 #include "views/dolphinviewactionhandler.h"
18
19 #include <KActionCollection>
20 #include <KAuthorized>
21 #include <KConfigGroup>
22 #include <KDialogJobUiDelegate>
23 #include <KDirLister>
24 #include <KFileItemListProperties>
25 #include <KIO/CommandLauncherJob>
26 #include <KIconLoader>
27 #include <KJobWidgets>
28 #include <KLocalizedString>
29 #include <KMessageBox>
30 #include <KMimeTypeEditor>
31 #include <KMoreToolsMenuFactory>
32 #include <KPluginFactory>
33 #include <KPluginMetaData>
34 #include <KSharedConfig>
35 #include <KTerminalLauncherJob>
36
37 #include <QActionGroup>
38 #include <QApplication>
39 #include <QClipboard>
40 #include <QDir>
41 #include <QInputDialog>
42 #include <QKeyEvent>
43 #include <QMenu>
44 #include <QRegularExpression>
45 #include <QStandardPaths>
46 #include <QTextDocument>
47
48 #include <KPluginFactory>
49
50 K_PLUGIN_CLASS_WITH_JSON(DolphinPart, "dolphinpart.json")
51
52 DolphinPart::DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
53 : KParts::ReadOnlyPart(parent, metaData)
54 , m_openTerminalAction(nullptr)
55 , m_removeAction(nullptr)
56 {
57 Q_UNUSED(args)
58
59 m_extension = new DolphinPartBrowserExtension(this);
60
61 // make sure that other apps using this part find Dolphin's view-file-columns icons
62 KIconLoader::global()->addAppDir(QStringLiteral("dolphin"));
63
64 m_view = new DolphinView(QUrl(), parentWidget);
65 m_view->setTabsForFilesEnabled(true);
66 setWidget(m_view);
67
68 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, this, &DolphinPart::slotErrorMessage);
69
70 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &KParts::ReadOnlyPart::completed);
71 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinPart::updatePasteAction);
72 connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinPart::updateProgress);
73 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
74
75 setXMLFile(QStringLiteral("dolphinpart.rc"));
76
77 connect(m_view, &DolphinView::infoMessage, this, &DolphinPart::slotMessage);
78 connect(m_view, &DolphinView::operationCompletedMessage, this, &DolphinPart::slotMessage);
79 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
80 connect(m_view, &DolphinView::itemActivated, this, &DolphinPart::slotItemActivated);
81 connect(m_view, &DolphinView::itemsActivated, this, &DolphinPart::slotItemsActivated);
82 connect(m_view, &DolphinView::statusBarTextChanged, this, [this](const QString &text) {
83 const QString escapedText = Qt::convertFromPlainText(text);
84 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
85 });
86 connect(m_view, &DolphinView::tabRequested, this, &DolphinPart::createNewWindow);
87 connect(m_view, &DolphinView::requestContextMenu, this, &DolphinPart::slotOpenContextMenu);
88 connect(m_view, &DolphinView::selectionChanged, m_extension, &KParts::NavigationExtension::selectionInfo);
89 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::slotSelectionChanged);
90 connect(m_view, &DolphinView::requestItemInfo, this, &DolphinPart::slotRequestItemInfo);
91 connect(m_view, &DolphinView::modeChanged, this, &DolphinPart::viewModeChanged); // relay signal
92 connect(m_view, &DolphinView::redirection, this, &DolphinPart::slotDirectoryRedirection);
93
94 // Watch for changes that should result in updates to the
95 // status bar text.
96 connect(m_view, &DolphinView::itemCountChanged, this, &DolphinPart::updateStatusBar);
97 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::updateStatusBar);
98
99 m_actionHandler = new DolphinViewActionHandler(actionCollection(), nullptr, this);
100 m_actionHandler->setCurrentView(m_view);
101 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinPart::createDirectory);
102
103 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
104 connect(this, &DolphinPart::aboutToOpenURL, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
105
106 QClipboard *clipboard = QApplication::clipboard();
107 connect(clipboard, &QClipboard::dataChanged, this, &DolphinPart::updatePasteAction);
108
109 // Create file info and listing filter extensions.
110 // NOTE: Listing filter needs to be instantiated after the creation of the view.
111 new DolphinPartFileInfoExtension(this);
112
113 new DolphinPartListingFilterExtension(this);
114
115 KDirLister *lister = m_view->m_model->m_dirLister;
116 if (lister) {
117 DolphinPartListingNotificationExtension *notifyExt = new DolphinPartListingNotificationExtension(this);
118 connect(lister, &KDirLister::newItems, notifyExt, &DolphinPartListingNotificationExtension::slotNewItems);
119 connect(lister, &KDirLister::itemsDeleted, notifyExt, &DolphinPartListingNotificationExtension::slotItemsDeleted);
120 } else {
121 qCWarning(DolphinDebug) << "NULL KDirLister object! KParts::ListingNotificationExtension will NOT be supported";
122 }
123
124 createActions();
125 m_actionHandler->updateViewActions();
126 slotSelectionChanged(KFileItemList()); // initially disable selection-dependent actions
127
128 // Listen to events from the app so we can update the remove key by
129 // checking for a Shift key press.
130 qApp->installEventFilter(this);
131
132 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
133 // (sort of spacial navigation)
134 }
135
136 DolphinPart::~DolphinPart()
137 {
138 }
139
140 void DolphinPart::createActions()
141 {
142 // Edit menu
143
144 m_newFileMenu = new DolphinNewFileMenu(actionCollection()->action(QStringLiteral("create_dir")), this);
145 m_newFileMenu->setParentWidget(widget());
146 connect(m_newFileMenu->menu(), &QMenu::aboutToShow, this, &DolphinPart::updateNewMenu);
147
148 QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType"));
149 editMimeTypeAction->setText(i18nc("@action:inmenu Edit", "&Edit File Type…"));
150 connect(editMimeTypeAction, &QAction::triggered, this, &DolphinPart::slotEditMimeType);
151
152 QAction *selectItemsMatching = actionCollection()->addAction(QStringLiteral("select_items_matching"));
153 selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching…"));
154 actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL | Qt::Key_S);
155 connect(selectItemsMatching, &QAction::triggered, this, &DolphinPart::slotSelectItemsMatchingPattern);
156
157 QAction *unselectItemsMatching = actionCollection()->addAction(QStringLiteral("unselect_items_matching"));
158 unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching…"));
159 connect(unselectItemsMatching, &QAction::triggered, this, &DolphinPart::slotUnselectItemsMatchingPattern);
160
161 KStandardAction::selectAll(m_view, &DolphinView::selectAll, actionCollection());
162
163 QAction *unselectAll = actionCollection()->addAction(QStringLiteral("unselect_all"));
164 unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
165 connect(unselectAll, &QAction::triggered, m_view, &DolphinView::clearSelection);
166
167 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
168 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
169 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
170 connect(invertSelection, &QAction::triggered, m_view, &DolphinView::invertSelection);
171
172 // View menu: all done by DolphinViewActionHandler
173
174 // Go menu
175
176 QActionGroup *goActionGroup = new QActionGroup(this);
177 connect(goActionGroup, &QActionGroup::triggered, this, &DolphinPart::slotGoTriggered);
178
179 createGoAction("go_applications", "start-here-kde", i18nc("@action:inmenu Go", "App&lications"), QStringLiteral("programs:/"), goActionGroup);
180 createGoAction("go_network_folders", "folder-remote", i18nc("@action:inmenu Go", "&Network Folders"), QStringLiteral("remote:/"), goActionGroup);
181 createGoAction("go_trash", "user-trash", i18nc("@action:inmenu Go", "Trash"), QStringLiteral("trash:/"), goActionGroup);
182 createGoAction("go_autostart",
183 "",
184 i18nc("@action:inmenu Go", "Autostart"),
185 QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/autostart",
186 goActionGroup);
187
188 // Tools menu
189 m_findFileAction = KStandardAction::find(this, &DolphinPart::slotFindFile, actionCollection());
190 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File…"));
191
192 #ifndef Q_OS_WIN
193 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
194 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
195 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
196 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
197 connect(m_openTerminalAction, &QAction::triggered, this, &DolphinPart::slotOpenTerminal);
198 actionCollection()->setDefaultShortcut(m_openTerminalAction, Qt::Key_F4);
199 }
200 #endif
201 }
202
203 void DolphinPart::createGoAction(const char *name, const char *iconName, const QString &text, const QString &url, QActionGroup *actionGroup)
204 {
205 QAction *action = actionCollection()->addAction(name);
206 action->setIcon(QIcon::fromTheme(iconName));
207 action->setText(text);
208 action->setData(url);
209 action->setActionGroup(actionGroup);
210 }
211
212 void DolphinPart::slotGoTriggered(QAction *action)
213 {
214 const QString url = action->data().toString();
215 Q_EMIT m_extension->openUrlRequest(QUrl(url));
216 }
217
218 void DolphinPart::slotSelectionChanged(const KFileItemList &selection)
219 {
220 const bool hasSelection = !selection.isEmpty();
221
222 QAction *renameAction = actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile));
223 QAction *moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
224 QAction *deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
225 QAction *editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
226 QAction *propertiesAction = actionCollection()->action(QStringLiteral("properties"));
227 QAction *deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
228
229 if (!hasSelection) {
230 stateChanged(QStringLiteral("has_no_selection"));
231
232 Q_EMIT m_extension->enableAction("cut", false);
233 Q_EMIT m_extension->enableAction("copy", false);
234 deleteWithTrashShortcut->setEnabled(false);
235 editMimeTypeAction->setEnabled(false);
236 } else {
237 stateChanged(QStringLiteral("has_selection"));
238
239 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
240 // in libkonq
241 KFileItemListProperties capabilities(selection);
242 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
243
244 renameAction->setEnabled(capabilities.supportsMoving());
245 moveToTrashAction->setEnabled(enableMoveToTrash);
246 deleteAction->setEnabled(capabilities.supportsDeleting());
247 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
248 editMimeTypeAction->setEnabled(true);
249 propertiesAction->setEnabled(true);
250 Q_EMIT m_extension->enableAction("cut", capabilities.supportsMoving());
251 Q_EMIT m_extension->enableAction("copy", true);
252 }
253 }
254
255 void DolphinPart::updatePasteAction()
256 {
257 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
258 Q_EMIT m_extension->enableAction("paste", pasteInfo.first);
259 Q_EMIT m_extension->setActionText("paste", pasteInfo.second);
260 }
261
262 QString DolphinPart::urlToLocalFilePath(const QUrl &url)
263 {
264 KIO::StatJob *statJob = KIO::mostLocalUrl(url);
265 KJobWidgets::setWindow(statJob, widget());
266 statJob->exec();
267 QUrl localUrl = statJob->mostLocalUrl();
268 if (localUrl.isLocalFile()) {
269 return localUrl.toLocalFile();
270 }
271 return QString();
272 }
273
274 bool DolphinPart::openUrl(const QUrl &url)
275 {
276 bool reload = arguments().reload();
277 // A bit of a workaround so that changing the namefilter works: force reload.
278 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
279 if (m_nameFilter != m_view->nameFilter())
280 reload = true;
281 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
282 return true;
283 }
284 setUrl(url); // remember url at the KParts level
285 setLocalFilePath(urlToLocalFilePath(url)); // remember local path at the KParts level
286 QUrl visibleUrl(url);
287 if (!m_nameFilter.isEmpty()) {
288 visibleUrl.setPath(visibleUrl.path() + '/' + m_nameFilter);
289 }
290 QString prettyUrl = visibleUrl.toDisplayString(QUrl::PreferLocalFile);
291 Q_EMIT setWindowCaption(prettyUrl);
292 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
293 Q_EMIT started(nullptr); // get the wheel to spin
294 m_view->setNameFilter(m_nameFilter);
295 m_view->setUrl(url);
296 updatePasteAction();
297 Q_EMIT aboutToOpenURL();
298 if (reload)
299 m_view->reload();
300 // Disable "Find File" and "Open Terminal" actions for non-file URLs,
301 // e.g. ftp, smb, etc. #279283
302 const bool isLocalUrl = !(localFilePath().isEmpty());
303 m_findFileAction->setEnabled(isLocalUrl);
304 if (m_openTerminalAction) {
305 m_openTerminalAction->setEnabled(isLocalUrl);
306 }
307 return true;
308 }
309
310 void DolphinPart::slotMessage(const QString &msg)
311 {
312 Q_EMIT setStatusBarText(msg);
313 }
314
315 void DolphinPart::slotErrorMessage(const QString &msg)
316 {
317 qCDebug(DolphinDebug) << msg;
318 Q_EMIT canceled(msg);
319 //KMessageBox::error(m_view, msg);
320 }
321
322 void DolphinPart::slotRequestItemInfo(const KFileItem &item)
323 {
324 Q_EMIT m_extension->mouseOverInfo(item);
325 if (item.isNull()) {
326 updateStatusBar();
327 } else {
328 const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
329 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
330 }
331 }
332
333 void DolphinPart::slotItemActivated(const KFileItem &item)
334 {
335 KParts::OpenUrlArguments args;
336 // Forget about the known mimetype if a target URL is used.
337 // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
338 if (item.targetUrl() == item.url()) {
339 args.setMimeType(item.mimetype());
340 }
341
342 Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args);
343 }
344
345 void DolphinPart::slotItemsActivated(const KFileItemList &items)
346 {
347 for (const KFileItem &item : items) {
348 slotItemActivated(item);
349 }
350 }
351
352 void DolphinPart::createNewWindow(const QUrl &url)
353 {
354 // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
355 // should be moved into DolphinPart::slotItemActivated()
356 Q_EMIT m_extension->createNewWindow(url);
357 }
358
359 void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &)
360 {
361 KParts::NavigationExtension::PopupFlags popupFlags =
362 KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
363
364 KFileItem item(_item);
365
366 if (item.isNull()) { // viewport context menu
367 item = m_view->rootItem();
368 if (item.isNull())
369 item = KFileItem(url());
370 else
371 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
372 }
373
374 KFileItemList items;
375 if (selectedItems.isEmpty()) {
376 items.append(item);
377 } else {
378 items = selectedItems;
379 }
380
381 KFileItemListProperties capabilities(items);
382
383 KParts::NavigationExtension::ActionGroupMap actionGroups;
384 QList<QAction *> editActions;
385 editActions += m_view->versionControlActions(m_view->selectedItems());
386
387 if (!_item.isNull()) { // only for context menu on one or more items
388 const bool supportsMoving = capabilities.supportsMoving();
389
390 if (capabilities.supportsDeleting()) {
391 const bool showDeleteAction =
392 (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
393 const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
394
395 if (showDeleteAction && showMoveToTrashAction) {
396 delete m_removeAction;
397 m_removeAction = nullptr;
398 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
399 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
400 } else if (showDeleteAction && !showMoveToTrashAction) {
401 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
402 } else {
403 if (!m_removeAction)
404 m_removeAction = new DolphinRemoveAction(this, actionCollection());
405 editActions.append(m_removeAction);
406 m_removeAction->update();
407 }
408 } else {
409 popupFlags |= KParts::NavigationExtension::NoDeletion;
410 }
411
412 if (supportsMoving) {
413 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
414 }
415
416 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
417 // since otherwise the created file would not be visible.
418 // But in treeview mode we should allow it.
419 if (m_view->itemsExpandable())
420 popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
421 }
422
423 actionGroups.insert(QStringLiteral("editactions"), editActions);
424
425 Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), popupFlags, actionGroups);
426 }
427
428 void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
429 {
430 qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
431 if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
432 KParts::ReadOnlyPart::setUrl(newUrl);
433 const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
434 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
435 }
436 }
437
438 void DolphinPart::slotEditMimeType()
439 {
440 const KFileItemList items = m_view->selectedItems();
441 if (!items.isEmpty()) {
442 KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
443 }
444 }
445
446 void DolphinPart::slotSelectItemsMatchingPattern()
447 {
448 openSelectionDialog(i18nc("@title:window", "Select"), i18n("Select all items matching this pattern:"), true);
449 }
450
451 void DolphinPart::slotUnselectItemsMatchingPattern()
452 {
453 openSelectionDialog(i18nc("@title:window", "Unselect"), i18n("Unselect all items matching this pattern:"), false);
454 }
455
456 void DolphinPart::openSelectionDialog(const QString &title, const QString &text, bool selectItems)
457 {
458 auto *dialog = new QInputDialog(m_view);
459 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
460 dialog->setInputMode(QInputDialog::TextInput);
461 dialog->setWindowTitle(title);
462 dialog->setLabelText(text);
463
464 const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
465 dialog->setComboBoxEditable(true);
466 dialog->setComboBoxItems(group.readEntry("History", QStringList()));
467
468 dialog->setTextValue(QStringLiteral("*"));
469
470 connect(dialog, &QDialog::accepted, this, [=]() {
471 const QString pattern = dialog->textValue();
472 if (!pattern.isEmpty()) {
473 QStringList items = dialog->comboBoxItems();
474 items.removeAll(pattern);
475 items.prepend(pattern);
476
477 // Need to evaluate this again here, because the captured value is const
478 // (even if the const were removed from 'const KConfigGroup group =' above).
479 KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
480 // Limit the size of the saved history.
481 group.writeEntry("History", items.mid(0, 10));
482 group.sync();
483
484 const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern));
485 m_view->selectItems(patternRegExp, selectItems);
486 }
487 });
488
489 dialog->open();
490 }
491
492 void DolphinPart::setCurrentViewMode(const QString &viewModeName)
493 {
494 QAction *action = actionCollection()->action(viewModeName);
495 Q_ASSERT(action);
496 action->trigger();
497 }
498
499 QString DolphinPart::currentViewMode() const
500 {
501 return m_actionHandler->currentViewModeActionName();
502 }
503
504 void DolphinPart::setNameFilter(const QString &nameFilter)
505 {
506 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
507 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
508 m_nameFilter = nameFilter;
509 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
510 }
511
512 QString DolphinPart::localFilePathOrHome() const
513 {
514 const QString localPath = localFilePath();
515 if (!localPath.isEmpty()) {
516 return localPath;
517 }
518 return QDir::homePath();
519 }
520
521 void DolphinPart::slotOpenTerminal()
522 {
523 auto job = new KTerminalLauncherJob(QString());
524 job->setWorkingDirectory(localFilePathOrHome());
525 job->start();
526 }
527
528 void DolphinPart::slotFindFile()
529 {
530 QMenu searchTools;
531 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&searchTools, {"files-find"}, QUrl::fromLocalFile(localFilePathOrHome()));
532 QList<QAction *> actions = searchTools.actions();
533 if (!(actions.isEmpty())) {
534 actions.first()->trigger();
535 } else {
536 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
537 job->setDesktopName(QStringLiteral("org.kde.kfind"));
538 job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
539 job->start();
540 }
541 }
542
543 void DolphinPart::updateNewMenu()
544 {
545 // As requested by KNewFileMenu :
546 m_newFileMenu->checkUpToDate();
547 // And set the files that the menu apply on :
548 m_newFileMenu->setWorkingDirectory(url());
549 }
550
551 void DolphinPart::updateStatusBar()
552 {
553 m_view->requestStatusBarText();
554 }
555
556 void DolphinPart::updateProgress(int percent)
557 {
558 Q_EMIT m_extension->loadingProgress(percent);
559 }
560
561 void DolphinPart::createDirectory()
562 {
563 m_newFileMenu->setWorkingDirectory(url());
564 m_newFileMenu->createDirectory();
565 }
566
567 void DolphinPart::setFilesToSelect(const QList<QUrl> &files)
568 {
569 if (files.isEmpty()) {
570 return;
571 }
572
573 m_view->markUrlsAsSelected(files);
574 m_view->markUrlAsCurrent(files.at(0));
575 }
576
577 bool DolphinPart::eventFilter(QObject *obj, QEvent *event)
578 {
579 using ShiftState = DolphinRemoveAction::ShiftState;
580 const int type = event->type();
581
582 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
583 QMenu *menu = qobject_cast<QMenu *>(obj);
584 if (menu && menu->parent() == m_view) {
585 QKeyEvent *ev = static_cast<QKeyEvent *>(event);
586 if (ev->key() == Qt::Key_Shift) {
587 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
588 }
589 }
590 }
591
592 return KParts::ReadOnlyPart::eventFilter(obj, event);
593 }
594
595 #include "dolphinpart.moc"
596 #include "moc_dolphinpart.cpp"