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