]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Merge remote-tracking branch 'upstream/master' into work/zakharafoniam/useful-groups
[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 <KPluginFactory>
32 #include <KPluginMetaData>
33 #include <KSharedConfig>
34 #include <KTerminalLauncherJob>
35
36 #include <QActionGroup>
37 #include <QApplication>
38 #include <QClipboard>
39 #include <QDir>
40 #include <QInputDialog>
41 #include <QKeyEvent>
42 #include <QMenu>
43 #include <QRegularExpression>
44 #include <QStandardPaths>
45 #include <QTextDocument>
46
47 #include <KPluginFactory>
48
49 K_PLUGIN_CLASS_WITH_JSON(DolphinPart, "dolphinpart.json")
50
51 DolphinPart::DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
52 : KParts::ReadOnlyPart(parent, metaData)
53 , m_openTerminalAction(nullptr)
54 , m_removeAction(nullptr)
55 {
56 Q_UNUSED(args)
57
58 m_extension = new DolphinPartBrowserExtension(this);
59
60 // make sure that other apps using this part find Dolphin's view-file-columns icons
61 KIconLoader::global()->addAppDir(QStringLiteral("dolphin"));
62
63 m_view = new DolphinView(QUrl(), parentWidget);
64 m_view->setTabsForFilesEnabled(true);
65 setWidget(m_view);
66
67 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage, this, &DolphinPart::slotErrorMessage);
68
69 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &KParts::ReadOnlyPart::completed);
70 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinPart::updatePasteAction);
71 connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinPart::updateProgress);
72 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
73
74 setXMLFile(QStringLiteral("dolphinpart.rc"));
75
76 connect(m_view, &DolphinView::infoMessage, this, &DolphinPart::slotMessage);
77 connect(m_view, &DolphinView::operationCompletedMessage, this, &DolphinPart::slotMessage);
78 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
79 connect(m_view, &DolphinView::itemActivated, this, &DolphinPart::slotItemActivated);
80 connect(m_view, &DolphinView::itemsActivated, this, &DolphinPart::slotItemsActivated);
81 connect(m_view, &DolphinView::statusBarTextChanged, this, [this](const QString &text) {
82 const QString escapedText = Qt::convertFromPlainText(text);
83 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
84 });
85 connect(m_view, &DolphinView::tabRequested, this, &DolphinPart::createNewWindow);
86 connect(m_view, &DolphinView::requestContextMenu, this, &DolphinPart::slotOpenContextMenu);
87 connect(m_view, &DolphinView::selectionChanged, m_extension, &KParts::NavigationExtension::selectionInfo);
88 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::slotSelectionChanged);
89 connect(m_view, &DolphinView::requestItemInfo, this, &DolphinPart::slotRequestItemInfo);
90 connect(m_view, &DolphinView::modeChanged, this, &DolphinPart::viewModeChanged); // relay signal
91 connect(m_view, &DolphinView::redirection, this, &DolphinPart::slotDirectoryRedirection);
92
93 // Watch for changes that should result in updates to the
94 // status bar text.
95 connect(m_view, &DolphinView::itemCountChanged, this, &DolphinPart::updateStatusBar);
96 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::updateStatusBar);
97
98 m_actionHandler = new DolphinViewActionHandler(actionCollection(), nullptr, this);
99 m_actionHandler->setCurrentView(m_view);
100 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinPart::createDirectory);
101
102 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
103 connect(this, &DolphinPart::aboutToOpenURL, m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
104
105 QClipboard *clipboard = QApplication::clipboard();
106 connect(clipboard, &QClipboard::dataChanged, this, &DolphinPart::updatePasteAction);
107
108 // Create file info and listing filter extensions.
109 // NOTE: Listing filter needs to be instantiated after the creation of the view.
110 new DolphinPartFileInfoExtension(this);
111
112 new DolphinPartListingFilterExtension(this);
113
114 KDirLister *lister = m_view->m_model->m_dirLister;
115 if (lister) {
116 DolphinPartListingNotificationExtension *notifyExt = new DolphinPartListingNotificationExtension(this);
117 connect(lister, &KDirLister::newItems, notifyExt, &DolphinPartListingNotificationExtension::slotNewItems);
118 connect(lister, &KDirLister::itemsDeleted, notifyExt, &DolphinPartListingNotificationExtension::slotItemsDeleted);
119 } else {
120 qCWarning(DolphinDebug) << "NULL KDirLister object! KParts::ListingNotificationExtension will NOT be supported";
121 }
122
123 createActions();
124 m_actionHandler->updateViewActions();
125 slotSelectionChanged(KFileItemList()); // initially disable selection-dependent actions
126
127 // Listen to events from the app so we can update the remove key by
128 // checking for a Shift key press.
129 qApp->installEventFilter(this);
130
131 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
132 // (sort of spacial navigation)
133 }
134
135 DolphinPart::~DolphinPart()
136 {
137 }
138
139 void DolphinPart::createActions()
140 {
141 // Edit menu
142
143 m_newFileMenu = new DolphinNewFileMenu(actionCollection()->action(QStringLiteral("create_dir")), this);
144 m_newFileMenu->setParentWidget(widget());
145 connect(m_newFileMenu->menu(), &QMenu::aboutToShow, this, &DolphinPart::updateNewMenu);
146
147 QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType"));
148 editMimeTypeAction->setText(i18nc("@action:inmenu Edit", "&Edit File Type…"));
149 connect(editMimeTypeAction, &QAction::triggered, this, &DolphinPart::slotEditMimeType);
150
151 QAction *selectItemsMatching = actionCollection()->addAction(QStringLiteral("select_items_matching"));
152 selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching…"));
153 actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL | Qt::Key_S);
154 connect(selectItemsMatching, &QAction::triggered, this, &DolphinPart::slotSelectItemsMatchingPattern);
155
156 QAction *unselectItemsMatching = actionCollection()->addAction(QStringLiteral("unselect_items_matching"));
157 unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching…"));
158 connect(unselectItemsMatching, &QAction::triggered, this, &DolphinPart::slotUnselectItemsMatchingPattern);
159
160 KStandardAction::selectAll(m_view, &DolphinView::selectAll, actionCollection());
161
162 QAction *unselectAll = actionCollection()->addAction(QStringLiteral("unselect_all"));
163 unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
164 connect(unselectAll, &QAction::triggered, m_view, &DolphinView::clearSelection);
165
166 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
167 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
168 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
169 connect(invertSelection, &QAction::triggered, m_view, &DolphinView::invertSelection);
170
171 // View menu: all done by DolphinViewActionHandler
172
173 // Go menu
174
175 QActionGroup *goActionGroup = new QActionGroup(this);
176 connect(goActionGroup, &QActionGroup::triggered, this, &DolphinPart::slotGoTriggered);
177
178 createGoAction("go_applications", "start-here-kde", i18nc("@action:inmenu Go", "App&lications"), QStringLiteral("programs:/"), goActionGroup);
179 createGoAction("go_network_folders", "folder-remote", i18nc("@action:inmenu Go", "&Network Folders"), QStringLiteral("remote:/"), goActionGroup);
180 createGoAction("go_trash", "user-trash", i18nc("@action:inmenu Go", "Trash"), QStringLiteral("trash:/"), goActionGroup);
181 createGoAction("go_autostart",
182 "",
183 i18nc("@action:inmenu Go", "Autostart"),
184 QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/autostart",
185 goActionGroup);
186
187 // Tools menu
188 m_findFileAction = KStandardAction::find(this, &DolphinPart::slotFindFile, actionCollection());
189 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File…"));
190
191 #ifndef Q_OS_WIN
192 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
193 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
194 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
195 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
196 connect(m_openTerminalAction, &QAction::triggered, this, &DolphinPart::slotOpenTerminal);
197 actionCollection()->setDefaultShortcut(m_openTerminalAction, Qt::Key_F4);
198 }
199 #endif
200 }
201
202 void DolphinPart::createGoAction(const char *name, const char *iconName, const QString &text, const QString &url, QActionGroup *actionGroup)
203 {
204 QAction *action = actionCollection()->addAction(name);
205 action->setIcon(QIcon::fromTheme(iconName));
206 action->setText(text);
207 action->setData(url);
208 action->setActionGroup(actionGroup);
209 }
210
211 void DolphinPart::slotGoTriggered(QAction *action)
212 {
213 const QString url = action->data().toString();
214 Q_EMIT m_extension->openUrlRequest(QUrl(url));
215 }
216
217 void DolphinPart::slotSelectionChanged(const KFileItemList &selection)
218 {
219 const bool hasSelection = !selection.isEmpty();
220
221 QAction *renameAction = actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile));
222 QAction *moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
223 QAction *deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
224 QAction *editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
225 QAction *propertiesAction = actionCollection()->action(QStringLiteral("properties"));
226 QAction *deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
227
228 if (!hasSelection) {
229 stateChanged(QStringLiteral("has_no_selection"));
230
231 Q_EMIT m_extension->enableAction("cut", false);
232 Q_EMIT m_extension->enableAction("copy", false);
233 deleteWithTrashShortcut->setEnabled(false);
234 editMimeTypeAction->setEnabled(false);
235 } else {
236 stateChanged(QStringLiteral("has_selection"));
237
238 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
239 // in libkonq
240 KFileItemListProperties capabilities(selection);
241 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
242
243 renameAction->setEnabled(capabilities.supportsMoving());
244 moveToTrashAction->setEnabled(enableMoveToTrash);
245 deleteAction->setEnabled(capabilities.supportsDeleting());
246 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
247 editMimeTypeAction->setEnabled(true);
248 propertiesAction->setEnabled(true);
249 Q_EMIT m_extension->enableAction("cut", capabilities.supportsMoving());
250 Q_EMIT m_extension->enableAction("copy", true);
251 }
252 }
253
254 void DolphinPart::updatePasteAction()
255 {
256 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
257 Q_EMIT m_extension->enableAction("paste", pasteInfo.first);
258 Q_EMIT m_extension->setActionText("paste", pasteInfo.second);
259 }
260
261 QString DolphinPart::urlToLocalFilePath(const QUrl &url)
262 {
263 KIO::StatJob *statJob = KIO::mostLocalUrl(url);
264 KJobWidgets::setWindow(statJob, widget());
265 statJob->exec();
266 QUrl localUrl = statJob->mostLocalUrl();
267 if (localUrl.isLocalFile()) {
268 return localUrl.toLocalFile();
269 }
270 return QString();
271 }
272
273 bool DolphinPart::openUrl(const QUrl &url)
274 {
275 bool reload = arguments().reload();
276 // A bit of a workaround so that changing the namefilter works: force reload.
277 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
278 if (m_nameFilter != m_view->nameFilter())
279 reload = true;
280 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
281 return true;
282 }
283 setUrl(url); // remember url at the KParts level
284 setLocalFilePath(urlToLocalFilePath(url)); // remember local path at the KParts level
285 QUrl visibleUrl(url);
286 if (!m_nameFilter.isEmpty()) {
287 visibleUrl.setPath(visibleUrl.path() + '/' + m_nameFilter);
288 }
289 QString prettyUrl = visibleUrl.toDisplayString(QUrl::PreferLocalFile);
290 Q_EMIT setWindowCaption(prettyUrl);
291 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
292 Q_EMIT started(nullptr); // get the wheel to spin
293 m_view->setNameFilter(m_nameFilter);
294 m_view->setUrl(url);
295 updatePasteAction();
296 Q_EMIT aboutToOpenURL();
297 if (reload)
298 m_view->reload();
299 // Disable "Find File" and "Open Terminal" actions for non-file URLs,
300 // e.g. ftp, smb, etc. #279283
301 const bool isLocalUrl = !(localFilePath().isEmpty());
302 m_findFileAction->setEnabled(isLocalUrl);
303 if (m_openTerminalAction) {
304 m_openTerminalAction->setEnabled(isLocalUrl);
305 }
306 return true;
307 }
308
309 void DolphinPart::slotMessage(const QString &msg)
310 {
311 Q_EMIT setStatusBarText(msg);
312 }
313
314 void DolphinPart::slotErrorMessage(const QString &msg)
315 {
316 qCDebug(DolphinDebug) << msg;
317 Q_EMIT canceled(msg);
318 //KMessageBox::error(m_view, msg);
319 }
320
321 void DolphinPart::slotRequestItemInfo(const KFileItem &item)
322 {
323 Q_EMIT m_extension->mouseOverInfo(item);
324 if (item.isNull()) {
325 updateStatusBar();
326 } else {
327 const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
328 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
329 }
330 }
331
332 void DolphinPart::slotItemActivated(const KFileItem &item)
333 {
334 KParts::OpenUrlArguments args;
335 // Forget about the known mimetype if a target URL is used.
336 // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
337 if (item.targetUrl() == item.url()) {
338 args.setMimeType(item.mimetype());
339 }
340
341 Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args);
342 }
343
344 void DolphinPart::slotItemsActivated(const KFileItemList &items)
345 {
346 for (const KFileItem &item : items) {
347 slotItemActivated(item);
348 }
349 }
350
351 void DolphinPart::createNewWindow(const QUrl &url)
352 {
353 // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
354 // should be moved into DolphinPart::slotItemActivated()
355 Q_EMIT m_extension->createNewWindow(url);
356 }
357
358 void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &)
359 {
360 KParts::NavigationExtension::PopupFlags popupFlags =
361 KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
362
363 KFileItem item(_item);
364
365 if (item.isNull()) { // viewport context menu
366 item = m_view->rootItem();
367 if (item.isNull())
368 item = KFileItem(url());
369 else
370 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
371 }
372
373 KFileItemList items;
374 if (selectedItems.isEmpty()) {
375 items.append(item);
376 } else {
377 items = selectedItems;
378 }
379
380 KFileItemListProperties capabilities(items);
381
382 KParts::NavigationExtension::ActionGroupMap actionGroups;
383 QList<QAction *> editActions;
384 editActions += m_view->versionControlActions(m_view->selectedItems());
385
386 if (!_item.isNull()) { // only for context menu on one or more items
387 const bool supportsMoving = capabilities.supportsMoving();
388
389 if (capabilities.supportsDeleting()) {
390 const bool showDeleteAction =
391 (KSharedConfig::openConfig()->group(QStringLiteral("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(QStringLiteral("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(QStringLiteral("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 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
530 job->setDesktopName(QStringLiteral("org.kde.kfind"));
531 job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
532 job->start();
533 }
534
535 void DolphinPart::updateNewMenu()
536 {
537 // As requested by KNewFileMenu :
538 m_newFileMenu->checkUpToDate();
539 // And set the files that the menu apply on :
540 m_newFileMenu->setWorkingDirectory(url());
541 }
542
543 void DolphinPart::updateStatusBar()
544 {
545 m_view->requestStatusBarText();
546 }
547
548 void DolphinPart::updateProgress(int percent)
549 {
550 Q_EMIT m_extension->loadingProgress(percent);
551 }
552
553 void DolphinPart::createDirectory()
554 {
555 m_newFileMenu->setWorkingDirectory(url());
556 m_newFileMenu->createDirectory();
557 }
558
559 void DolphinPart::setFilesToSelect(const QList<QUrl> &files)
560 {
561 if (files.isEmpty()) {
562 return;
563 }
564
565 m_view->markUrlsAsSelected(files);
566 m_view->markUrlAsCurrent(files.at(0));
567 }
568
569 bool DolphinPart::eventFilter(QObject *obj, QEvent *event)
570 {
571 using ShiftState = DolphinRemoveAction::ShiftState;
572 const int type = event->type();
573
574 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
575 QMenu *menu = qobject_cast<QMenu *>(obj);
576 if (menu && menu->parent() == m_view) {
577 QKeyEvent *ev = static_cast<QKeyEvent *>(event);
578 if (ev->key() == Qt::Key_Shift) {
579 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
580 }
581 }
582 }
583
584 return KParts::ReadOnlyPart::eventFilter(obj, event);
585 }
586
587 #include "dolphinpart.moc"
588 #include "moc_dolphinpart.cpp"