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