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