]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Rewrite search integration
[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 #include <QAction>
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 QAction *newDirAction = actionCollection()->action(QStringLiteral("create_dir"));
144 QAction *newFileAction = actionCollection()->action(QStringLiteral("create_file"));
145 m_newFileMenu = new DolphinNewFileMenu(newDirAction, newFileAction, this);
146 m_newFileMenu->setParentWidget(widget());
147 connect(m_newFileMenu->menu(), &QMenu::aboutToShow, this, &DolphinPart::updateNewMenu);
148
149 QAction *editMimeTypeAction = actionCollection()->addAction(QStringLiteral("editMimeType"));
150 editMimeTypeAction->setText(i18nc("@action:inmenu Edit", "&Edit File Type…"));
151 connect(editMimeTypeAction, &QAction::triggered, this, &DolphinPart::slotEditMimeType);
152
153 QAction *selectItemsMatching = actionCollection()->addAction(QStringLiteral("select_items_matching"));
154 selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching…"));
155 actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL | Qt::Key_S);
156 connect(selectItemsMatching, &QAction::triggered, this, &DolphinPart::slotSelectItemsMatchingPattern);
157
158 QAction *unselectItemsMatching = actionCollection()->addAction(QStringLiteral("unselect_items_matching"));
159 unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching…"));
160 connect(unselectItemsMatching, &QAction::triggered, this, &DolphinPart::slotUnselectItemsMatchingPattern);
161
162 KStandardAction::selectAll(m_view, &DolphinView::selectAll, actionCollection());
163
164 QAction *unselectAll = actionCollection()->addAction(QStringLiteral("unselect_all"));
165 unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
166 connect(unselectAll, &QAction::triggered, m_view, &DolphinView::clearSelection);
167
168 QAction *invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
169 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
170 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL | Qt::SHIFT | Qt::Key_A);
171 connect(invertSelection, &QAction::triggered, m_view, &DolphinView::invertSelection);
172
173 // View menu: all done by DolphinViewActionHandler
174
175 // Go menu
176
177 QActionGroup *goActionGroup = new QActionGroup(this);
178 connect(goActionGroup, &QActionGroup::triggered, this, &DolphinPart::slotGoTriggered);
179
180 createGoAction("go_applications", "start-here-kde", i18nc("@action:inmenu Go", "App&lications"), QStringLiteral("programs:/"), goActionGroup);
181 createGoAction("go_network_folders", "folder-remote", i18nc("@action:inmenu Go", "&Network Folders"), QStringLiteral("remote:/"), goActionGroup);
182 createGoAction("go_trash", "user-trash", i18nc("@action:inmenu Go", "Trash"), QStringLiteral("trash:/"), goActionGroup);
183 createGoAction("go_autostart",
184 "",
185 i18nc("@action:inmenu Go", "Autostart"),
186 QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/autostart",
187 goActionGroup);
188
189 // Tools menu
190 m_findFileAction = KStandardAction::find(this, &DolphinPart::slotFindFile, actionCollection());
191 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File…"));
192
193 #ifndef Q_OS_WIN
194 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
195 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
196 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
197 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
198 connect(m_openTerminalAction, &QAction::triggered, this, &DolphinPart::slotOpenTerminal);
199 actionCollection()->setDefaultShortcut(m_openTerminalAction, Qt::Key_F4);
200 }
201 #endif
202 }
203
204 void DolphinPart::createGoAction(const char *name, const char *iconName, const QString &text, const QString &url, QActionGroup *actionGroup)
205 {
206 QAction *action = actionCollection()->addAction(name);
207 action->setIcon(QIcon::fromTheme(iconName));
208 action->setText(text);
209 action->setData(url);
210 action->setActionGroup(actionGroup);
211 }
212
213 void DolphinPart::slotGoTriggered(QAction *action)
214 {
215 const QString url = action->data().toString();
216 Q_EMIT m_extension->openUrlRequest(QUrl(url));
217 }
218
219 void DolphinPart::slotSelectionChanged(const KFileItemList &selection)
220 {
221 const bool hasSelection = !selection.isEmpty();
222
223 QAction *renameAction = actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile));
224 QAction *moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
225 QAction *deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
226 QAction *editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
227 QAction *propertiesAction = actionCollection()->action(QStringLiteral("properties"));
228 QAction *deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
229
230 if (!hasSelection) {
231 stateChanged(QStringLiteral("has_no_selection"));
232
233 Q_EMIT m_extension->enableAction("cut", false);
234 Q_EMIT m_extension->enableAction("copy", false);
235 deleteWithTrashShortcut->setEnabled(false);
236 editMimeTypeAction->setEnabled(false);
237 } else {
238 stateChanged(QStringLiteral("has_selection"));
239
240 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
241 // in libkonq
242 KFileItemListProperties capabilities(selection);
243 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
244
245 renameAction->setEnabled(capabilities.supportsMoving());
246 moveToTrashAction->setEnabled(enableMoveToTrash);
247 deleteAction->setEnabled(capabilities.supportsDeleting());
248 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
249 editMimeTypeAction->setEnabled(true);
250 propertiesAction->setEnabled(true);
251 Q_EMIT m_extension->enableAction("cut", capabilities.supportsMoving());
252 Q_EMIT m_extension->enableAction("copy", true);
253 }
254 }
255
256 void DolphinPart::updatePasteAction()
257 {
258 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
259 Q_EMIT m_extension->enableAction("paste", pasteInfo.first);
260 Q_EMIT m_extension->setActionText("paste", pasteInfo.second);
261 }
262
263 QString DolphinPart::urlToLocalFilePath(const QUrl &url)
264 {
265 KIO::StatJob *statJob = KIO::mostLocalUrl(url);
266 KJobWidgets::setWindow(statJob, widget());
267 statJob->exec();
268 QUrl localUrl = statJob->mostLocalUrl();
269 if (localUrl.isLocalFile()) {
270 return localUrl.toLocalFile();
271 }
272 return QString();
273 }
274
275 bool DolphinPart::openUrl(const QUrl &url)
276 {
277 bool reload = arguments().reload();
278 // A bit of a workaround so that changing the namefilter works: force reload.
279 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
280 if (m_nameFilter != m_view->nameFilter())
281 reload = true;
282 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
283 return true;
284 }
285 setUrl(url); // remember url at the KParts level
286 setLocalFilePath(urlToLocalFilePath(url)); // remember local path at the KParts level
287 QUrl visibleUrl(url);
288 if (!m_nameFilter.isEmpty()) {
289 visibleUrl.setPath(visibleUrl.path() + '/' + m_nameFilter);
290 }
291 QString prettyUrl = visibleUrl.toDisplayString(QUrl::PreferLocalFile);
292 Q_EMIT setWindowCaption(prettyUrl);
293 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
294 Q_EMIT started(nullptr); // get the wheel to spin
295 m_view->setNameFilter(m_nameFilter);
296 m_view->setUrl(url);
297 updatePasteAction();
298 Q_EMIT aboutToOpenURL();
299 if (reload)
300 m_view->reload();
301 // Disable "Find File" and "Open Terminal" actions for non-file URLs,
302 // e.g. ftp, smb, etc. #279283
303 const bool isLocalUrl = !(localFilePath().isEmpty());
304 m_findFileAction->setEnabled(isLocalUrl);
305 if (m_openTerminalAction) {
306 m_openTerminalAction->setEnabled(isLocalUrl);
307 }
308 return true;
309 }
310
311 void DolphinPart::slotMessage(const QString &msg)
312 {
313 Q_EMIT setStatusBarText(msg);
314 }
315
316 void DolphinPart::slotErrorMessage(const QString &msg)
317 {
318 qCDebug(DolphinDebug) << msg;
319 Q_EMIT canceled(msg);
320 //KMessageBox::error(m_view, msg);
321 }
322
323 void DolphinPart::slotRequestItemInfo(const KFileItem &item)
324 {
325 Q_EMIT m_extension->mouseOverInfo(item);
326 if (item.isNull()) {
327 updateStatusBar();
328 } else {
329 const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
330 Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
331 }
332 }
333
334 void DolphinPart::slotItemActivated(const KFileItem &item)
335 {
336 KParts::OpenUrlArguments args;
337 // Forget about the known mimetype if a target URL is used.
338 // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
339 if (item.targetUrl() == item.url()) {
340 args.setMimeType(item.mimetype());
341 }
342
343 Q_EMIT m_extension->openUrlRequest(item.targetUrl(), args);
344 }
345
346 void DolphinPart::slotItemsActivated(const KFileItemList &items)
347 {
348 for (const KFileItem &item : items) {
349 slotItemActivated(item);
350 }
351 }
352
353 void DolphinPart::createNewWindow(const QUrl &url)
354 {
355 // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
356 // should be moved into DolphinPart::slotItemActivated()
357 Q_EMIT m_extension->createNewWindow(url);
358 }
359
360 void DolphinPart::slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &)
361 {
362 KParts::NavigationExtension::PopupFlags popupFlags =
363 KParts::NavigationExtension::DefaultPopupItems | KParts::NavigationExtension::ShowProperties | KParts::NavigationExtension::ShowUrlOperations;
364
365 KFileItem item(_item);
366
367 if (item.isNull()) { // viewport context menu
368 item = m_view->rootItem();
369 if (item.isNull())
370 item = KFileItem(url());
371 else
372 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
373 }
374
375 KFileItemList items;
376 if (selectedItems.isEmpty()) {
377 items.append(item);
378 } else {
379 items = selectedItems;
380 }
381
382 KFileItemListProperties capabilities(items);
383
384 KParts::NavigationExtension::ActionGroupMap actionGroups;
385 QList<QAction *> editActions;
386 editActions += m_view->versionControlActions(m_view->selectedItems());
387
388 if (!_item.isNull()) { // only for context menu on one or more items
389 const bool supportsMoving = capabilities.supportsMoving();
390
391 if (capabilities.supportsDeleting()) {
392 const bool showDeleteAction =
393 (KSharedConfig::openConfig()->group(QStringLiteral("KDE")).readEntry("ShowDeleteCommand", false) || !item.isLocalFile());
394 const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
395
396 if (showDeleteAction && showMoveToTrashAction) {
397 delete m_removeAction;
398 m_removeAction = nullptr;
399 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
400 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
401 } else if (showDeleteAction && !showMoveToTrashAction) {
402 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
403 } else {
404 if (!m_removeAction)
405 m_removeAction = new DolphinRemoveAction(this, actionCollection());
406 editActions.append(m_removeAction);
407 m_removeAction->update();
408 }
409 } else {
410 popupFlags |= KParts::NavigationExtension::NoDeletion;
411 }
412
413 if (supportsMoving) {
414 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
415 }
416
417 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
418 // since otherwise the created file would not be visible.
419 // But in treeview mode we should allow it.
420 if (m_view->itemsExpandable())
421 popupFlags |= KParts::NavigationExtension::ShowCreateDirectory;
422 }
423
424 actionGroups.insert(QStringLiteral("editactions"), editActions);
425
426 Q_EMIT m_extension->popupMenu(pos, items, KParts::OpenUrlArguments(), popupFlags, actionGroups);
427 }
428
429 void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
430 {
431 qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
432 if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
433 KParts::ReadOnlyPart::setUrl(newUrl);
434 const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
435 Q_EMIT m_extension->setLocationBarUrl(prettyUrl);
436 }
437 }
438
439 void DolphinPart::slotEditMimeType()
440 {
441 const KFileItemList items = m_view->selectedItems();
442 if (!items.isEmpty()) {
443 KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
444 }
445 }
446
447 void DolphinPart::slotSelectItemsMatchingPattern()
448 {
449 openSelectionDialog(i18nc("@title:window", "Select"), i18n("Select all items matching this pattern:"), true);
450 }
451
452 void DolphinPart::slotUnselectItemsMatchingPattern()
453 {
454 openSelectionDialog(i18nc("@title:window", "Unselect"), i18n("Unselect all items matching this pattern:"), false);
455 }
456
457 void DolphinPart::openSelectionDialog(const QString &title, const QString &text, bool selectItems)
458 {
459 auto *dialog = new QInputDialog(m_view);
460 dialog->setAttribute(Qt::WA_DeleteOnClose, true);
461 dialog->setInputMode(QInputDialog::TextInput);
462 dialog->setWindowTitle(title);
463 dialog->setLabelText(text);
464
465 const KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
466 dialog->setComboBoxEditable(true);
467 dialog->setComboBoxItems(group.readEntry("History", QStringList()));
468
469 dialog->setTextValue(QStringLiteral("*"));
470
471 connect(dialog, &QDialog::accepted, this, [=, this]() {
472 const QString pattern = dialog->textValue();
473 if (!pattern.isEmpty()) {
474 QStringList items = dialog->comboBoxItems();
475 items.removeAll(pattern);
476 items.prepend(pattern);
477
478 // Need to evaluate this again here, because the captured value is const
479 // (even if the const were removed from 'const KConfigGroup group =' above).
480 KConfigGroup group = KSharedConfig::openConfig("dolphinpartrc")->group(QStringLiteral("Select Dialog"));
481 // Limit the size of the saved history.
482 group.writeEntry("History", items.mid(0, 10));
483 group.sync();
484
485 const QRegularExpression patternRegExp(QRegularExpression::wildcardToRegularExpression(pattern));
486 m_view->selectItems(patternRegExp, selectItems);
487 }
488 });
489
490 dialog->open();
491 }
492
493 void DolphinPart::setCurrentViewMode(const QString &viewModeName)
494 {
495 QAction *action = actionCollection()->action(viewModeName);
496 Q_ASSERT(action);
497 action->trigger();
498 }
499
500 QString DolphinPart::currentViewMode() const
501 {
502 return m_actionHandler->currentViewModeActionName();
503 }
504
505 void DolphinPart::setNameFilter(const QString &nameFilter)
506 {
507 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
508 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
509 m_nameFilter = nameFilter;
510 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
511 }
512
513 QString DolphinPart::localFilePathOrHome() const
514 {
515 const QString localPath = localFilePath();
516 if (!localPath.isEmpty()) {
517 return localPath;
518 }
519 return QDir::homePath();
520 }
521
522 void DolphinPart::slotOpenTerminal()
523 {
524 auto job = new KTerminalLauncherJob(QString());
525 job->setWorkingDirectory(localFilePathOrHome());
526 job->start();
527 }
528
529 void DolphinPart::slotFindFile()
530 {
531 KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob(QStringLiteral("kfind"), {url().toString()}, this);
532 job->setDesktopName(QStringLiteral("org.kde.kfind"));
533 job->setUiDelegate(new KDialogJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, widget()));
534 job->start();
535 }
536
537 void DolphinPart::updateNewMenu()
538 {
539 // As requested by KNewFileMenu :
540 m_newFileMenu->checkUpToDate();
541 // And set the files that the menu apply on :
542 m_newFileMenu->setWorkingDirectory(url());
543 }
544
545 void DolphinPart::updateStatusBar()
546 {
547 m_view->requestStatusBarText();
548 }
549
550 void DolphinPart::updateProgress(int percent)
551 {
552 Q_EMIT m_extension->loadingProgress(percent);
553 }
554
555 void DolphinPart::createDirectory()
556 {
557 m_newFileMenu->setWorkingDirectory(url());
558 m_newFileMenu->createDirectory();
559 }
560
561 void DolphinPart::setFilesToSelect(const QList<QUrl> &files)
562 {
563 if (files.isEmpty()) {
564 return;
565 }
566
567 m_view->markUrlsAsSelected(files);
568 m_view->markUrlAsCurrent(files.at(0));
569 }
570
571 bool DolphinPart::eventFilter(QObject *obj, QEvent *event)
572 {
573 using ShiftState = DolphinRemoveAction::ShiftState;
574 const int type = event->type();
575
576 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
577 QMenu *menu = qobject_cast<QMenu *>(obj);
578 if (menu && menu->parent() == m_view) {
579 QKeyEvent *ev = static_cast<QKeyEvent *>(event);
580 if (ev->key() == Qt::Key_Shift) {
581 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
582 }
583 }
584 }
585
586 return KParts::ReadOnlyPart::eventFilter(obj, event);
587 }
588
589 #include "dolphinpart.moc"
590 #include "moc_dolphinpart.cpp"