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