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