]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Merge branch 'Applications/16.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 #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(0)
64 ,m_removeAction(0)
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::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, static_cast<void(DolphinPartBrowserExtension::*)(const KFileItemList&)>(&DolphinPartBrowserExtension::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::createDirectory, 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 actionCollection()->addAction(KStandardAction::SelectAll, QStringLiteral("select_all"), m_view, SLOT(selectAll()));
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 = actionCollection()->addAction(QStringLiteral("find_file"));
220 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File..."));
221 actionCollection()->setDefaultShortcut(m_findFileAction, Qt::CTRL | Qt::Key_F);
222 m_findFileAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-find")));
223 connect(m_findFileAction, &QAction::triggered, this, &DolphinPart::slotFindFile);
224
225 if (KAuthorized::authorize(QStringLiteral("shell_access"))) {
226 m_openTerminalAction = actionCollection()->addAction(QStringLiteral("open_terminal"));
227 m_openTerminalAction->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal")));
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 }
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(QStringLiteral("rename"));
256 QAction* moveToTrashAction = actionCollection()->action(QStringLiteral("move_to_trash"));
257 QAction* deleteAction = actionCollection()->action(QStringLiteral("delete"));
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(0); // 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 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 popupFlags |= KParts::BrowserExtension::ShowNavigationItems | KParts::BrowserExtension::ShowUp;
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 = 0;
435 editActions.append(actionCollection()->action(QStringLiteral("move_to_trash")));
436 editActions.append(actionCollection()->action(QStringLiteral("delete")));
437 } else if (showDeleteAction && !showMoveToTrashAction) {
438 editActions.append(actionCollection()->action(QStringLiteral("delete")));
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(QStringLiteral("rename")));
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 QString dir(QDir::homePath());
538
539 QUrl u(url());
540
541 // If the given directory is not local, it can still be the URL of an
542 // ioslave using UDS_LOCAL_PATH which to be converted first.
543 KIO::StatJob* statJob = KIO::mostLocalUrl(u);
544 KJobWidgets::setWindow(statJob, widget());
545 statJob->exec();
546 u = statJob->mostLocalUrl();
547
548 //If the URL is local after the above conversion, set the directory.
549 if (u.isLocalFile()) {
550 dir = u.toLocalFile();
551 }
552
553 KToolInvocation::invokeTerminal(QString(), dir);
554 }
555
556 void DolphinPart::slotFindFile()
557 {
558 KRun::run(QStringLiteral("kfind"), {url()}, widget());
559 }
560
561 void DolphinPart::updateNewMenu()
562 {
563 // As requested by KNewFileMenu :
564 m_newFileMenu->checkUpToDate();
565 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
566 // And set the files that the menu apply on :
567 m_newFileMenu->setPopupFiles(url());
568 }
569
570 void DolphinPart::updateStatusBar()
571 {
572 const QString escapedText = Qt::convertFromPlainText(m_view->statusBarText());
573 emit ReadOnlyPart::setStatusBarText(QStringLiteral("<qt>%1</qt>").arg(escapedText));
574 }
575
576 void DolphinPart::updateProgress(int percent)
577 {
578 m_extension->loadingProgress(percent);
579 }
580
581 void DolphinPart::createDirectory()
582 {
583 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
584 m_newFileMenu->setPopupFiles(url());
585 m_newFileMenu->createDirectory();
586 }
587
588 void DolphinPart::setFilesToSelect(const QList<QUrl>& files)
589 {
590 if (files.isEmpty()) {
591 return;
592 }
593
594 m_view->markUrlsAsSelected(files);
595 m_view->markUrlAsCurrent(files.at(0));
596 }
597
598 bool DolphinPart::eventFilter(QObject* obj, QEvent* event)
599 {
600 const int type = event->type();
601
602 if ((type == QEvent::KeyPress || type == QEvent::KeyRelease) && m_removeAction) {
603 QMenu* menu = qobject_cast<QMenu*>(obj);
604 if (menu && menu->parent() == m_view) {
605 QKeyEvent* ev = static_cast<QKeyEvent*>(event);
606 if (ev->key() == Qt::Key_Shift) {
607 m_removeAction->update();
608 }
609 }
610 }
611
612 return KParts::ReadOnlyPart::eventFilter(obj, event);
613 }
614
615 #include "dolphinpart.moc"