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