]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Merge branch 'Applications/17.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 #include "dolphinremoveaction.h"
22
23 #include <KFileItemListProperties>
24
25 #include <KAboutData>
26 #include <KActionCollection>
27 #include "dolphindebug.h"
28 #include <KIconLoader>
29 #include <KLocalizedString>
30 #include <KMessageBox>
31 #include <KPluginFactory>
32 #include <KRun>
33 #include <KToolInvocation>
34 #include <KAuthorized>
35 #include <QMenu>
36 #include <KSharedConfig>
37 #include <KConfigGroup>
38 #include <KMimeTypeEditor>
39 #include <KJobWidgets>
40
41 #include "dolphinpart_ext.h"
42 #include "dolphinnewfilemenu.h"
43 #include "views/dolphinview.h"
44 #include "views/dolphinviewactionhandler.h"
45 #include "views/dolphinnewfilemenuobserver.h"
46 #include "views/dolphinremoteencoding.h"
47 #include "kitemviews/kfileitemmodel.h"
48 #include "kitemviews/private/kfileitemmodeldirlister.h"
49
50 #include <QStandardPaths>
51 #include <QActionGroup>
52 #include <QTextDocument>
53 #include <QApplication>
54 #include <QClipboard>
55 #include <QDir>
56 #include <QKeyEvent>
57 #include <QInputDialog>
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, static_cast<void(DolphinPart::*)()>(&DolphinPart::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, static_cast<void(DolphinPartBrowserExtension::*)(const KFileItemList&)>(&DolphinPartBrowserExtension::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::createDirectory, 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 actionCollection()->addAction(KStandardAction::SelectAll, QStringLiteral("select_all"), m_view, SLOT(selectAll()));
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 = actionCollection()->addAction(QStringLiteral("find_file"));
221 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File..."));
222 actionCollection()->setDefaultShortcut(m_findFileAction, Qt::CTRL | Qt::Key_F);
223 m_findFileAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-find")));
224 connect(m_findFileAction, &QAction::triggered, this, &DolphinPart::slotFindFile);
225
226 #ifndef Q_OS_WIN
227 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
228 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
229 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
230 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
231 connect(m_openTerminalAction, &QAction::triggered, this, &DolphinPart::slotOpenTerminal);
232 actionCollection()->setDefaultShortcut(m_openTerminalAction, Qt::Key_F4);
233 }
234 #endif
235 }
236
237 void DolphinPart::createGoAction(const char* name, const char* iconName,
238 const QString& text, const QString& url,
239 QActionGroup* actionGroup)
240 {
241 QAction* action = actionCollection()->addAction(name);
242 action->setIcon(QIcon::fromTheme(iconName));
243 action->setText(text);
244 action->setData(url);
245 action->setActionGroup(actionGroup);
246 }
247
248 void DolphinPart::slotGoTriggered(QAction* action)
249 {
250 const QString url = action->data().toString();
251 emit m_extension->openUrlRequest(QUrl(url));
252 }
253
254 void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
255 {
256 const bool hasSelection = !selection.isEmpty();
257
258 QAction* renameAction = actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile));
259 QAction* moveToTrashAction = actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash));
260 QAction* deleteAction = actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile));
261 QAction* editMimeTypeAction = actionCollection()->action(QStringLiteral("editMimeType"));
262 QAction* propertiesAction = actionCollection()->action(QStringLiteral("properties"));
263 QAction* deleteWithTrashShortcut = actionCollection()->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler
264
265 if (!hasSelection) {
266 stateChanged(QStringLiteral("has_no_selection"));
267
268 emit m_extension->enableAction("cut", false);
269 emit m_extension->enableAction("copy", false);
270 deleteWithTrashShortcut->setEnabled(false);
271 editMimeTypeAction->setEnabled(false);
272 } else {
273 stateChanged(QStringLiteral("has_selection"));
274
275 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
276 // in libkonq
277 KFileItemListProperties capabilities(selection);
278 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
279
280 renameAction->setEnabled(capabilities.supportsMoving());
281 moveToTrashAction->setEnabled(enableMoveToTrash);
282 deleteAction->setEnabled(capabilities.supportsDeleting());
283 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
284 editMimeTypeAction->setEnabled(true);
285 propertiesAction->setEnabled(true);
286 emit m_extension->enableAction("cut", capabilities.supportsMoving());
287 emit m_extension->enableAction("copy", true);
288 }
289 }
290
291 void DolphinPart::updatePasteAction()
292 {
293 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
294 emit m_extension->enableAction( "paste", pasteInfo.first );
295 emit m_extension->setActionText( "paste", pasteInfo.second );
296 }
297
298 KAboutData* DolphinPart::createAboutData()
299 {
300 return new KAboutData(QStringLiteral("dolphinpart"), i18nc("@title", "Dolphin Part"), QStringLiteral("0.1"));
301 }
302
303 bool DolphinPart::openUrl(const QUrl &url)
304 {
305 bool reload = arguments().reload();
306 // A bit of a workaround so that changing the namefilter works: force reload.
307 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
308 if (m_nameFilter != m_view->nameFilter())
309 reload = true;
310 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
311 return true;
312 }
313 setUrl(url); // remember it at the KParts level
314 QUrl visibleUrl(url);
315 if (!m_nameFilter.isEmpty()) {
316 visibleUrl.setPath(visibleUrl.path() + '/' + m_nameFilter);
317 }
318 QString prettyUrl = visibleUrl.toDisplayString(QUrl::PreferLocalFile);
319 emit setWindowCaption(prettyUrl);
320 emit m_extension->setLocationBarUrl(prettyUrl);
321 emit started(nullptr); // get the wheel to spin
322 m_view->setNameFilter(m_nameFilter);
323 m_view->setUrl(url);
324 updatePasteAction();
325 emit aboutToOpenURL();
326 if (reload)
327 m_view->reload();
328 // Disable "Find File" and "Open Terminal" actions for non-file URLs,
329 // e.g. ftp, smb, etc. #279283
330 const bool isLocalUrl = url.isLocalFile();
331 m_findFileAction->setEnabled(isLocalUrl);
332 if (m_openTerminalAction) {
333 m_openTerminalAction->setEnabled(isLocalUrl);
334 }
335 return true;
336 }
337
338 void DolphinPart::slotMessage(const QString& msg)
339 {
340 emit setStatusBarText(msg);
341 }
342
343 void DolphinPart::slotErrorMessage(const QString& msg)
344 {
345 qCDebug(DolphinDebug) << msg;
346 emit canceled(msg);
347 //KMessageBox::error(m_view, msg);
348 }
349
350 void DolphinPart::slotRequestItemInfo(const KFileItem& item)
351 {
352 emit m_extension->mouseOverInfo(item);
353 if (item.isNull()) {
354 updateStatusBar();
355 } else {
356 const QString escapedText = Qt::convertFromPlainText(item.getStatusBarInfo());
357 emit ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
358 }
359 }
360
361 void DolphinPart::slotItemActivated(const KFileItem& item)
362 {
363 KParts::OpenUrlArguments args;
364 // Forget about the known mimetype if a target URL is used.
365 // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
366 if (item.targetUrl() == item.url()) {
367 args.setMimeType(item.mimetype());
368 }
369
370 // Ideally, konqueror should be changed to not require trustedSource for directory views,
371 // since the idea was not to need BrowserArguments for non-browser stuff...
372 KParts::BrowserArguments browserArgs;
373 browserArgs.trustedSource = true;
374 emit m_extension->openUrlRequest(item.targetUrl(), args, browserArgs);
375 }
376
377 void DolphinPart::slotItemsActivated(const KFileItemList& items)
378 {
379 foreach (const KFileItem& item, items) {
380 slotItemActivated(item);
381 }
382 }
383
384 void DolphinPart::createNewWindow(const QUrl& url)
385 {
386 // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
387 // should be moved into DolphinPart::slotItemActivated()
388 emit m_extension->createNewWindow(url);
389 }
390
391 void DolphinPart::slotOpenContextMenu(const QPoint& pos,
392 const KFileItem& _item,
393 const QUrl &,
394 const QList<QAction*>& customActions)
395 {
396 KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::DefaultPopupItems
397 | KParts::BrowserExtension::ShowProperties
398 | KParts::BrowserExtension::ShowUrlOperations;
399
400 KFileItem item(_item);
401
402 if (item.isNull()) { // viewport context menu
403 item = m_view->rootItem();
404 if (item.isNull())
405 item = KFileItem(url());
406 else
407 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
408 }
409
410 // TODO: We should change the signature of the slots (and signals) for being able
411 // to tell for which items we want a popup.
412 KFileItemList items;
413 if (m_view->selectedItems().isEmpty()) {
414 items.append(item);
415 } else {
416 items = m_view->selectedItems();
417 }
418
419 KFileItemListProperties capabilities(items);
420
421 KParts::BrowserExtension::ActionGroupMap actionGroups;
422 QList<QAction *> editActions;
423 editActions += m_view->versionControlActions(m_view->selectedItems());
424 editActions += customActions;
425
426 if (!_item.isNull()) { // only for context menu on one or more items
427 const bool supportsMoving = capabilities.supportsMoving();
428
429 if (capabilities.supportsDeleting()) {
430 const bool showDeleteAction = (KSharedConfig::openConfig()->group("KDE").readEntry("ShowDeleteCommand", false) ||
431 !item.isLocalFile());
432 const bool showMoveToTrashAction = capabilities.isLocal() && supportsMoving;
433
434 if (showDeleteAction && showMoveToTrashAction) {
435 delete m_removeAction;
436 m_removeAction = nullptr;
437 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::MoveToTrash)));
438 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
439 } else if (showDeleteAction && !showMoveToTrashAction) {
440 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::DeleteFile)));
441 } else {
442 if (!m_removeAction)
443 m_removeAction = new DolphinRemoveAction(this, actionCollection());
444 editActions.append(m_removeAction);
445 m_removeAction->update();
446 }
447 } else {
448 popupFlags |= KParts::BrowserExtension::NoDeletion;
449 }
450
451 if (supportsMoving) {
452 editActions.append(actionCollection()->action(KStandardAction::name(KStandardAction::RenameFile)));
453 }
454
455 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
456 // since otherwise the created file would not be visible.
457 // But in treeview mode we should allow it.
458 if (m_view->itemsExpandable())
459 popupFlags |= KParts::BrowserExtension::ShowCreateDirectory;
460
461 }
462
463 actionGroups.insert(QStringLiteral("editactions"), editActions);
464
465 emit m_extension->popupMenu(pos,
466 items,
467 KParts::OpenUrlArguments(),
468 KParts::BrowserArguments(),
469 popupFlags,
470 actionGroups);
471 }
472
473 void DolphinPart::slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl)
474 {
475 qCDebug(DolphinDebug) << oldUrl << newUrl << "currentUrl=" << url();
476 if (oldUrl.matches(url(), QUrl::StripTrailingSlash /* #207572 */)) {
477 KParts::ReadOnlyPart::setUrl(newUrl);
478 const QString prettyUrl = newUrl.toDisplayString(QUrl::PreferLocalFile);
479 emit m_extension->setLocationBarUrl(prettyUrl);
480 }
481 }
482
483
484 void DolphinPart::slotEditMimeType()
485 {
486 const KFileItemList items = m_view->selectedItems();
487 if (!items.isEmpty()) {
488 KMimeTypeEditor::editMimeType(items.first().mimetype(), m_view);
489 }
490 }
491
492 void DolphinPart::slotSelectItemsMatchingPattern()
493 {
494 openSelectionDialog(i18nc("@title:window", "Select"),
495 i18n("Select all items matching this pattern:"),
496 true);
497 }
498
499 void DolphinPart::slotUnselectItemsMatchingPattern()
500 {
501 openSelectionDialog(i18nc("@title:window", "Unselect"),
502 i18n("Unselect all items matching this pattern:"),
503 false);
504 }
505
506 void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
507 {
508 bool okClicked;
509 const QString pattern = QInputDialog::getText(m_view, title, text, QLineEdit::Normal, QStringLiteral("*"), &okClicked);
510
511 if (okClicked && !pattern.isEmpty()) {
512 QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
513 m_view->selectItems(patternRegExp, selectItems);
514 }
515 }
516
517 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
518 {
519 QAction* action = actionCollection()->action(viewModeName);
520 Q_ASSERT(action);
521 action->trigger();
522 }
523
524 QString DolphinPart::currentViewMode() const
525 {
526 return m_actionHandler->currentViewModeActionName();
527 }
528
529 void DolphinPart::setNameFilter(const QString& nameFilter)
530 {
531 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
532 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
533 m_nameFilter = nameFilter;
534 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
535 }
536
537 void DolphinPart::slotOpenTerminal()
538 {
539 QString dir(QDir::homePath());
540
541 QUrl u(url());
542
543 // If the given directory is not local, it can still be the URL of an
544 // ioslave using UDS_LOCAL_PATH which to be converted first.
545 KIO::StatJob* statJob = KIO::mostLocalUrl(u);
546 KJobWidgets::setWindow(statJob, widget());
547 statJob->exec();
548 u = statJob->mostLocalUrl();
549
550 //If the URL is local after the above conversion, set the directory.
551 if (u.isLocalFile()) {
552 dir = u.toLocalFile();
553 }
554
555 KToolInvocation::invokeTerminal(QString(), dir);
556 }
557
558 void DolphinPart::slotFindFile()
559 {
560 KRun::run(QStringLiteral("kfind"), {url()}, widget());
561 }
562
563 void DolphinPart::updateNewMenu()
564 {
565 // As requested by KNewFileMenu :
566 m_newFileMenu->checkUpToDate();
567 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
568 // And set the files that the menu apply on :
569 m_newFileMenu->setPopupFiles(url());
570 }
571
572 void DolphinPart::updateStatusBar()
573 {
574 const QString escapedText = Qt::convertFromPlainText(m_view->statusBarText());
575 emit ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
576 }
577
578 void DolphinPart::updateProgress(int percent)
579 {
580 emit m_extension->loadingProgress(percent);
581 }
582
583 void DolphinPart::createDirectory()
584 {
585 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
586 m_newFileMenu->setPopupFiles(url());
587 m_newFileMenu->createDirectory();
588 }
589
590 void DolphinPart::setFilesToSelect(const QList<QUrl>& files)
591 {
592 if (files.isEmpty()) {
593 return;
594 }
595
596 m_view->markUrlsAsSelected(files);
597 m_view->markUrlAsCurrent(files.at(0));
598 }
599
600 bool DolphinPart::eventFilter(QObject* obj, QEvent* event)
601 {
602 using ShiftState = DolphinRemoveAction::ShiftState;
603 const int type = event->type();
604
605 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
606 QMenu* menu = qobject_cast<QMenu*>(obj);
607 if (menu && menu->parent() == m_view) {
608 QKeyEvent* ev = static_cast<QKeyEvent*>(event);
609 if (ev->key() == Qt::Key_Shift) {
610 m_removeAction->update(type == QEvent::KeyPress ? ShiftState::Pressed : ShiftState::Released);
611 }
612 }
613 }
614
615 return KParts::ReadOnlyPart::eventFilter(obj, event);
616 }
617
618 #include "dolphinpart.moc"