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