]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Adapt to NavigationExtension API change
[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 = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
392 const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
393
394 if (showDeleteAction && showMoveToTrashAction) {
395 delete m_removeAction;
396 m_removeAction = nullptr;
397 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
398 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
399 } else if (showDeleteAction && !showMoveToTrashAction) {
400 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
401 } else {
402 if (!m_removeAction)
403 m_removeAction = new DolphinRemoveAction(this, actionCollection());
404 editActions.append(m_removeAction);
405 m_removeAction->update();
406 }
407 } else {
408 popupFlags |= KParts::NavigationExtension::NoDeletion;
409 }
410
411 if (supportsMoving) {
412 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
413 }
414
415 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
416 // since otherwise the created file would not be visible.
417 // But in treeview mode we should allow it.
418 if (m_view->itemsExpandable())
419 popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
420 }
421
422 actionGroups.insert(QStringLiteral("editactions"), editActions);
423
424 Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), popupFlags, actionGroups);
425 }
426
427 void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
428 {
429 qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
430 if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
431 KParts::ReadOnlyPart::setUrl(newUrl);
432 const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
433 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
434 }
435 }
436
437 void DolphinPart::slotEditMimeType()
438 {
439 const KFileItemList items = m_view->selectedItems();
440 if (!items.isEmpty()) {
441 KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
442 }
443 }
444
445 void DolphinPart::slotSelectItemsMatchingPattern()
446 {
447 openSelectionDialog(i18nc("@title:window", "Select"), i18n("Select all items matching this pattern:"), true);
448 }
449
450 void DolphinPart::slotUnselectItemsMatchingPattern()
451 {
452 openSelectionDialog(i18nc("@title:window", "Unselect"), i18n("Unselect all items matching this pattern:"), false);
453 }
454
455 void DolphinPart::openSelectionDialog(const QString &title, const QString &text, bool selectItems)
456 {
457 auto *dialog = new QInputDialog(m_view);
458 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
459 dialog->setInputMode(QInputDialog::TextInput);
460 dialog->setWindowTitle(title);
461 dialog->setLabelText(text);
462
463 const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
464 dialog->setComboBoxEditable(true);
465 dialog->setComboBoxItems(group.readEntry("History", QStringList()));
466
467 dialog->setTextValue(QStringLiteral("*"));
468
469 connect(dialog, &QDialog::accepted, this, [=]() {
470 const QString pattern = dialog->textValue();
471 if (!pattern.isEmpty()) {
472 QStringList items = dialog->comboBoxItems();
473 items.removeAll(pattern);
474 items.prepend(pattern);
475
476 // Need to evaluate this again here, because the captured value is const
477 // (even if the const were removed from 'const KConfigGroup group =' above).
478 KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group("Select Dialog");
479 // Limit the size of the saved history.
480 group.writeEntry("History", items.mid(0, 10));
481 group.sync();
482
483 const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern));
484 m_view->selectItems(patternRegExp, selectItems);
485 }
486 });
487
488 dialog->open();
489 }
490
491 void DolphinPart::setCurrentViewMode(const QString &viewModeName)
492 {
493 QAction *action = actionCollection()->action(viewModeName);
494 Q_ASSERT(action);
495 action->trigger();
496 }
497
498 QString DolphinPart::currentViewMode() const
499 {
500 return m_actionHandler->currentViewModeActionName();
501 }
502
503 void DolphinPart::setNameFilter(const QString &nameFilter)
504 {
505 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
506 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
507 m_nameFilter = nameFilter;
508 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
509 }
510
511 QString DolphinPart::localFilePathOrHome() const
512 {
513 const QString localPath = localFilePath();
514 if (!localPath.isEmpty()) {
515 return localPath;
516 }
517 return QDir::homePath();
518 }
519
520 void DolphinPart::slotOpenTerminal()
521 {
522 auto job = new KTerminalLauncherJob(QString());
523 job->setWorkingDirectory(localFilePathOrHome());
524 job->start();
525 }
526
527 void DolphinPart::slotFindFile()
528 {
529 QMenu searchTools;
530 KMoreToolsMenuFactory("dolphin/search-tools").fillMenuFromGroupingNames(&searchTools, {"files-find"}, QUrl::fromLocalFile(localFilePathOrHome()));
531 QList<QAction *> actions = searchTools.actions();
532 if (!(actions.isEmpty())) {
533 actions.first()->trigger();
534 } else {
535 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
536 job->setDesktopName(QStringLiteral("org.kde.kfind"));
537 job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
538 job->start();
539 }
540 }
541
542 void DolphinPart::updateNewMenu()
543 {
544 // As requested by KNewFileMenu :
545 m_newFileMenu->checkUpToDate();
546 // And set the files that the menu apply on :
547 m_newFileMenu->setWorkingDirectory(url());
548 }
549
550 void DolphinPart::updateStatusBar()
551 {
552 m_view->requestStatusBarText();
553 }
554
555 void DolphinPart::updateProgress(int percent)
556 {
557 Q_EMIT m_extension->loadingProgress(percent);
558 }
559
560 void DolphinPart::createDirectory()
561 {
562 m_newFileMenu->setWorkingDirectory(url());
563 m_newFileMenu->createDirectory();
564 }
565
566 void DolphinPart::setFilesToSelect(const QList<QUrl> &files)
567 {
568 if (files.isEmpty()) {
569 return;
570 }
571
572 m_view->markUrlsAsSelected(files);
573 m_view->markUrlAsCurrent(files.at(0));
574 }
575
576 bool DolphinPart::eventFilter(QObject *obj, QEvent *event)
577 {
578 using ShiftState = DolphinRemoveAction::ShiftState;
579 const int type = event->type();
580
581 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
582 QMenu *menu = qobject_cast<QMenu *>(obj);
583 if (menu && menu->parent() == m_view) {
584 QKeyEvent *ev = static_cast<QKeyEvent *>(event);
585 if (ev->key() == Qt::Key_Shift) {
586 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
587 }
588 }
589 }
590
591 return KParts::ReadOnlyPart::eventFilter(obj, event);
592 }
593
594 #include "dolphinpart.moc"
595 #include "moc_dolphinpart.cpp"