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