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