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