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