]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Merge branch 'Applications/19.08'
[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 <KPluginFactory>
44 #include <KRun>
45 #include <KSharedConfig>
46 #include <KToolInvocation>
47
48 #include <QActionGroup>
49 #include <QApplication>
50 #include <QClipboard>
51 #include <QDir>
52 #include <QInputDialog>
53 #include <QKeyEvent>
54 #include <QMenu>
55 #include <QStandardPaths>
56 #include <QTextDocument>
57
58 K_PLUGIN_FACTORY(DolphinPartFactory, registerPlugin<DolphinPart>();)
59
60 DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, const QVariantList& args)
61 : KParts::ReadOnlyPart(parent)
62 ,m_openTerminalAction(nullptr)
63 ,m_removeAction(nullptr)
64 {
65 Q_UNUSED(args)
66 setComponentData(*createAboutData(), false);
67 m_extension = new DolphinPartBrowserExtension(this);
68
69 // make sure that other apps using this part find Dolphin's view-file-columns icons
70 KIconLoader::global()->addAppDir(QStringLiteral("dolphin"));
71
72 m_view = new DolphinView(QUrl(), parentWidget);
73 m_view->setTabsForFilesEnabled(true);
74 setWidget(m_view);
75
76 connect(&DolphinNewFileMenuObserver::instance(), &DolphinNewFileMenuObserver::errorMessage,
77 this, &DolphinPart::slotErrorMessage);
78
79 connect(m_view, &DolphinView::directoryLoadingCompleted, this, QOverload<>::of(&KParts::ReadOnlyPart::completed));
80 connect(m_view, &DolphinView::directoryLoadingCompleted, this, &DolphinPart::updatePasteAction);
81 connect(m_view, &DolphinView::directoryLoadingProgress, this, &DolphinPart::updateProgress);
82 connect(m_view, &DolphinView::errorMessage, this, &DolphinPart::slotErrorMessage);
83
84 setXMLFile(QStringLiteral("dolphinpart.rc"));
85
86 connect(m_view, &DolphinView::infoMessage,
87 this, &DolphinPart::slotMessage);
88 connect(m_view, &DolphinView::operationCompletedMessage,
89 this, &DolphinPart::slotMessage);
90 connect(m_view, &DolphinView::errorMessage,
91 this, &DolphinPart::slotErrorMessage);
92 connect(m_view, &DolphinView::itemActivated,
93 this, &DolphinPart::slotItemActivated);
94 connect(m_view, &DolphinView::itemsActivated,
95 this, &DolphinPart::slotItemsActivated);
96 connect(m_view, &DolphinView::tabRequested,
97 this, &DolphinPart::createNewWindow);
98 connect(m_view, &DolphinView::requestContextMenu,
99 this, &DolphinPart::slotOpenContextMenu);
100 connect(m_view, &DolphinView::selectionChanged,
101 m_extension, QOverload<const KFileItemList&>::of(&KParts::BrowserExtension::selectionInfo));
102 connect(m_view, &DolphinView::selectionChanged,
103 this, &DolphinPart::slotSelectionChanged);
104 connect(m_view, &DolphinView::requestItemInfo,
105 this, &DolphinPart::slotRequestItemInfo);
106 connect(m_view, &DolphinView::modeChanged,
107 this, &DolphinPart::viewModeChanged); // relay signal
108 connect(m_view, &DolphinView::redirection,
109 this, &DolphinPart::slotDirectoryRedirection);
110
111 // Watch for changes that should result in updates to the
112 // status bar text.
113 connect(m_view, &DolphinView::itemCountChanged, this, &DolphinPart::updateStatusBar);
114 connect(m_view, &DolphinView::selectionChanged, this, &DolphinPart::updateStatusBar);
115
116 m_actionHandler = new DolphinViewActionHandler(actionCollection(), this);
117 m_actionHandler->setCurrentView(m_view);
118 connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinPart::createDirectory);
119
120 m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler);
121 connect(this, &DolphinPart::aboutToOpenURL,
122 m_remoteEncoding, &DolphinRemoteEncoding::slotAboutToOpenUrl);
123
124 QClipboard* clipboard = QApplication::clipboard();
125 connect(clipboard, &QClipboard::dataChanged,
126 this, &DolphinPart::updatePasteAction);
127
128 // Create file info and listing filter extensions.
129 // NOTE: Listing filter needs to be instantiated after the creation of the view.
130 new DolphinPartFileInfoExtension(this);
131
132 new DolphinPartListingFilterExtension(this);
133
134 KDirLister* lister = m_view->m_model->m_dirLister;
135 if (lister) {
136 DolphinPartListingNotificationExtension* notifyExt = new DolphinPartListingNotificationExtension(this);
137 connect(lister, &KDirLister::newItems, notifyExt, &DolphinPartListingNotificationExtension::slotNewItems);
138 connect(lister, &KDirLister::itemsDeleted, notifyExt, &DolphinPartListingNotificationExtension::slotItemsDeleted);
139 } else {
140 qCWarning(DolphinDebug) << "NULL KDirLister object! KParts::ListingNotificationExtension will NOT be supported";
141 }
142
143 createActions();
144 m_actionHandler->updateViewActions();
145 slotSelectionChanged(KFileItemList()); // initially disable selection-dependent actions
146
147 // Listen to events from the app so we can update the remove key by
148 // checking for a Shift key press.
149 qApp->installEventFilter(this);
150
151 // TODO there was a "always open a new window" (when clicking on a directory) setting in konqueror
152 // (sort of spacial navigation)
153
154 loadPlugins(this, this, componentData());
155 }
156
157 DolphinPart::~DolphinPart()
158 {
159 }
160
161 void DolphinPart::createActions()
162 {
163 // Edit menu
164
165 m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this);
166 m_newFileMenu->setParentWidget(widget());
167 connect(m_newFileMenu->menu(), &QMenu::aboutToShow,
168 this, &DolphinPart::updateNewMenu);
169
170 QAction *editMimeTypeAction = actionCollection()->addAction( QStringLiteral("editMimeType") );
171 editMimeTypeAction->setText( i18nc("@action:inmenu Edit", "&Edit File Type..." ) );
172 connect(editMimeTypeAction, &QAction::triggered, this, &DolphinPart::slotEditMimeType);
173
174 QAction* selectItemsMatching = actionCollection()->addAction(QStringLiteral("select_items_matching"));
175 selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching..."));
176 actionCollection()->setDefaultShortcut(selectItemsMatching, Qt::CTRL + Qt::Key_S);
177 connect(selectItemsMatching, &QAction::triggered, this, &DolphinPart::slotSelectItemsMatchingPattern);
178
179 QAction* unselectItemsMatching = actionCollection()->addAction(QStringLiteral("unselect_items_matching"));
180 unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching..."));
181 connect(unselectItemsMatching, &QAction::triggered, this, &DolphinPart::slotUnselectItemsMatchingPattern);
182
183 KStandardAction::selectAll(m_view, &DolphinView::selectAll, actionCollection());
184
185 QAction* unselectAll = actionCollection()->addAction(QStringLiteral("unselect_all"));
186 unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
187 connect(unselectAll, &QAction::triggered, m_view, &DolphinView::clearSelection);
188
189 QAction* invertSelection = actionCollection()->addAction(QStringLiteral("invert_selection"));
190 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
191 actionCollection()->setDefaultShortcut(invertSelection, Qt::CTRL + Qt::SHIFT + Qt::Key_A);
192 connect(invertSelection, &QAction::triggered, m_view, &DolphinView::invertSelection);
193
194 // View menu: all done by DolphinViewActionHandler
195
196 // Go menu
197
198 QActionGroup* goActionGroup = new QActionGroup(this);
199 connect(goActionGroup, &QActionGroup::triggered,
200 this, &DolphinPart::slotGoTriggered);
201
202 createGoAction("go_applications", "start-here-kde",
203 i18nc("@action:inmenu Go", "App&lications"), QStringLiteral("programs:/"),
204 goActionGroup);
205 createGoAction("go_network_folders", "folder-remote",
206 i18nc("@action:inmenu Go", "&Network Folders"), QStringLiteral("remote:/"),
207 goActionGroup);
208 createGoAction("go_settings", "preferences-system",
209 i18nc("@action:inmenu Go", "Sett&ings"), QStringLiteral("settings:/"),
210 goActionGroup);
211 createGoAction("go_trash", "user-trash",
212 i18nc("@action:inmenu Go", "Trash"), QStringLiteral("trash:/"),
213 goActionGroup);
214 createGoAction("go_autostart", "",
215 i18nc("@action:inmenu Go", "Autostart"), QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/autostart",
216 goActionGroup);
217
218 // Tools menu
219 m_findFileAction = KStandardAction::find(this, &DolphinPart::slotFindFile, actionCollection());
220 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File..."));
221
222 #ifndef Q_OS_WIN
223 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
224 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
225 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts")));
226 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
227 connect(m_openTerminalAction, &QAction::triggered, this, &DolphinPart::slotOpenTerminal);
228 actionCollection()->setDefaultShortcut(m_openTerminalAction, Qt::Key_F4);
229 }
230 #endif
231 }
232
233 void DolphinPart::createGoAction(const char* name, const char* iconName,
234 const QString& text, const QString& url,
235 QActionGroup* actionGroup)
236 {
237 QAction* action = actionCollection()->addAction(name);
238 action->setIcon(QIcon::fromTheme(iconName));
239 action->setText(text);
240 action->setData(url);
241 action->setActionGroup(actionGroup);
242 }
243
244 void DolphinPart::slotGoTriggered(QAction* action)
245 {
246 const QString url = action->data().toString();
247 emit m_extension->openUrlRequest(QUrl(url));
248 }
249
250 void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
251 {
252 const bool hasSelection = !selection.isEmpty();
253
254 QAction* renameAction = actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile));
255 QAction* moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
256 QAction* deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
257 QAction* editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
258 QAction* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
259 QAction* deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
260
261 if (!hasSelection) {
262 stateChanged(QStringLiteral("has_no_selection"));
263
264 emit m_extension->enableAction("cut", false);
265 emit m_extension->enableAction("copy", false);
266 deleteWithTrashShortcut->setEnabled(false);
267 editMimeTypeAction->setEnabled(false);
268 } else {
269 stateChanged(QStringLiteral("has_selection"));
270
271 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
272 // in libkonq
273 KFileItemListProperties capabilities(selection);
274 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
275
276 renameAction->setEnabled(capabilities.supportsMoving());
277 moveToTrashAction->setEnabled(enableMoveToTrash);
278 deleteAction->setEnabled(capabilities.supportsDeleting());
279 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
280 editMimeTypeAction->setEnabled(true);
281 propertiesAction->setEnabled(true);
282 emit m_extension->enableAction("cut", capabilities.supportsMoving());
283 emit m_extension->enableAction("copy", true);
284 }
285 }
286
287 void DolphinPart::updatePasteAction()
288 {
289 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
290 emit m_extension->enableAction( "paste", pasteInfo.first );
291 emit m_extension->setActionText( "paste", pasteInfo.second );
292 }
293
294 KAboutData* DolphinPart::createAboutData()
295 {
296 return new KAboutData(QStringLiteral("dolphinpart"), i18nc("@title", "Dolphin Part"), QStringLiteral("0.1"));
297 }
298
299 bool DolphinPart::openUrl(const QUrl &url)
300 {
301 bool reload = arguments().reload();
302 // A bit of a workaround so that changing the namefilter works: force reload.
303 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
304 if (m_nameFilter != m_view->nameFilter())
305 reload = true;
306 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
307 return true;
308 }
309 setUrl(url); // remember it 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 emit setWindowCaption(prettyUrl);
316 emit m_extension->setLocationBarUrl(prettyUrl);
317 emit started(nullptr); // get the wheel to spin
318 m_view->setNameFilter(m_nameFilter);
319 m_view->setUrl(url);
320 updatePasteAction();
321 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 = url.isLocalFile();
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 emit setStatusBarText(msg);
337 }
338
339 void DolphinPart::slotErrorMessage(const QString& msg)
340 {
341 qCDebug(DolphinDebug) << msg;
342 emit canceled(msg);
343 //KMessageBox::error(m_view, msg);
344 }
345
346 void DolphinPart::slotRequestItemInfo(const KFileItem& item)
347 {
348 emit m_extension->mouseOverInfo(item);
349 if (item.isNull()) {
350 updateStatusBar();
351 } else {
352 const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
353 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 emit m_extension->openUrlRequest(item.targetUrl(), args, browserArgs);
371 }
372
373 void DolphinPart::slotItemsActivated(const KFileItemList& items)
374 {
375 foreach (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 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 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 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 bool okClicked;
505 const QString pattern = QInputDialog::getText(m_view, title, text, QLineEdit::Normal, QStringLiteral("*"), &okClicked);
506
507 if (okClicked && !pattern.isEmpty()) {
508 QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
509 m_view->selectItems(patternRegExp, selectItems);
510 }
511 }
512
513 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
514 {
515 QAction* action = actionCollection()->action(viewModeName);
516 Q_ASSERT(action);
517 action->trigger();
518 }
519
520 QString DolphinPart::currentViewMode() const
521 {
522 return m_actionHandler->currentViewModeActionName();
523 }
524
525 void DolphinPart::setNameFilter(const QString& nameFilter)
526 {
527 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
528 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
529 m_nameFilter = nameFilter;
530 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
531 }
532
533 void DolphinPart::slotOpenTerminal()
534 {
535 QString dir(QDir::homePath());
536
537 QUrl u(url());
538
539 // If the given directory is not local, it can still be the URL of an
540 // ioslave using UDS_LOCAL_PATH which to be converted first.
541 KIO::StatJob* statJob = KIO::mostLocalUrl(u);
542 KJobWidgets::setWindow(statJob, widget());
543 statJob->exec();
544 u = statJob->mostLocalUrl();
545
546 //If the URL is local after the above conversion, set the directory.
547 if (u.isLocalFile()) {
548 dir = u.toLocalFile();
549 }
550
551 KToolInvocation::invokeTerminal(QString(), dir);
552 }
553
554 void DolphinPart::slotFindFile()
555 {
556 KRun::run(QStringLiteral("kfind"), {url()}, widget());
557 }
558
559 void DolphinPart::updateNewMenu()
560 {
561 // As requested by KNewFileMenu :
562 m_newFileMenu->checkUpToDate();
563 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
564 // And set the files that the menu apply on :
565 m_newFileMenu->setPopupFiles(url());
566 }
567
568 void DolphinPart::updateStatusBar()
569 {
570 const QString escapedText = Qt::convertFromPlainText(m_view->statusBarText());
571 emit ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
572 }
573
574 void DolphinPart::updateProgress(int percent)
575 {
576 emit m_extension->loadingProgress(percent);
577 }
578
579 void DolphinPart::createDirectory()
580 {
581 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
582 m_newFileMenu->setPopupFiles(url());
583 m_newFileMenu->createDirectory();
584 }
585
586 void DolphinPart::setFilesToSelect(const QList<QUrl>& files)
587 {
588 if (files.isEmpty()) {
589 return;
590 }
591
592 m_view->markUrlsAsSelected(files);
593 m_view->markUrlAsCurrent(files.at(0));
594 }
595
596 bool DolphinPart::eventFilter(QObject* obj, QEvent* event)
597 {
598 using ShiftState = DolphinRemoveAction::ShiftState;
599 const int type = event->type();
600
601 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
602 QMenu* menu = qobject_cast<QMenu*>(obj);
603 if (menu && menu->parent() == m_view) {
604 QKeyEvent* ev = static_cast<QKeyEvent*>(event);
605 if (ev->key() == Qt::Key_Shift) {
606 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
607 }
608 }
609 }
610
611 return KParts::ReadOnlyPart::eventFilter(obj, event);
612 }
613
614 #include "dolphinpart.moc"