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