]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
KItemViews: Internal directory restructuration
[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(finishedDirLoading(KUrl)), this, SLOT(slotCompleted(KUrl)));
73 connect(m_view, SIGNAL(dirLoadingProgress(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(slotRedirection(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::slotCompleted(const KUrl& url)
303 {
304 Q_UNUSED(url)
305 emit completed();
306 }
307
308 void DolphinPart::slotMessage(const QString& msg)
309 {
310 emit setStatusBarText(msg);
311 }
312
313 void DolphinPart::slotErrorMessage(const QString& msg)
314 {
315 kDebug() << msg;
316 emit canceled(msg);
317 //KMessageBox::error(m_view, msg);
318 }
319
320 void DolphinPart::slotRequestItemInfo(const KFileItem& item)
321 {
322 emit m_extension->mouseOverInfo(item);
323 if (item.isNull()) {
324 updateStatusBar();
325 } else {
326 ReadOnlyPart::setStatusBarText(item.getStatusBarInfo());
327 }
328 }
329
330 void DolphinPart::slotItemActivated(const KFileItem& item)
331 {
332 KParts::OpenUrlArguments args;
333 // Forget about the known mimetype if a target URL is used.
334 // Testcase: network:/ with a item (mimetype "inode/some-foo-service") pointing to a http URL (html)
335 if (item.targetUrl() == item.url()) {
336 args.setMimeType(item.mimetype());
337 }
338
339 // Ideally, konqueror should be changed to not require trustedSource for directory views,
340 // since the idea was not to need BrowserArguments for non-browser stuff...
341 KParts::BrowserArguments browserArgs;
342 browserArgs.trustedSource = true;
343 emit m_extension->openUrlRequest(item.targetUrl(), args, browserArgs);
344 }
345
346 void DolphinPart::createNewWindow(const KUrl& url)
347 {
348 // TODO: Check issue N176832 for the missing QAIV signal; task 177399 - maybe this code
349 // should be moved into DolphinPart::slotItemActivated()
350 emit m_extension->createNewWindow(url);
351 }
352
353 void DolphinPart::slotOpenContextMenu(const QPoint& pos,
354 const KFileItem& _item,
355 const KUrl&,
356 const QList<QAction*>& customActions)
357 {
358 KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::DefaultPopupItems
359 | KParts::BrowserExtension::ShowProperties
360 | KParts::BrowserExtension::ShowUrlOperations;
361
362 KFileItem item(_item);
363
364 if (item.isNull()) { // viewport context menu
365 popupFlags |= KParts::BrowserExtension::ShowNavigationItems | KParts::BrowserExtension::ShowUp;
366 item = m_view->rootItem();
367 if (item.isNull())
368 item = KFileItem( S_IFDIR, (mode_t)-1, url() );
369 else
370 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
371 }
372
373 // TODO: We should change the signature of the slots (and signals) for being able
374 // to tell for which items we want a popup.
375 KFileItemList items;
376 if (m_view->selectedItems().isEmpty()) {
377 items.append(item);
378 } else {
379 items = m_view->selectedItems();
380 }
381
382 KFileItemListProperties capabilities(items);
383
384 KParts::BrowserExtension::ActionGroupMap actionGroups;
385 QList<QAction *> editActions;
386 editActions += m_view->versionControlActions(m_view->selectedItems());
387 editActions += customActions;
388
389 if (!_item.isNull()) { // only for context menu on one or more items
390 bool supportsDeleting = capabilities.supportsDeleting();
391 bool supportsMoving = capabilities.supportsMoving();
392
393 if (!supportsDeleting) {
394 popupFlags |= KParts::BrowserExtension::NoDeletion;
395 }
396
397 if (supportsMoving) {
398 editActions.append(actionCollection()->action("rename"));
399 }
400
401 bool addTrash = capabilities.isLocal() && supportsMoving;
402 bool addDel = false;
403 if (supportsDeleting) {
404 if ( !item.isLocalFile() )
405 addDel = true;
406 else if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
407 addTrash = false;
408 addDel = true;
409 }
410 else {
411 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
412 KConfigGroup configGroup(globalConfig, "KDE");
413 addDel = configGroup.readEntry("ShowDeleteCommand", false);
414 }
415 }
416
417 if (addTrash)
418 editActions.append(actionCollection()->action("move_to_trash"));
419 if (addDel)
420 editActions.append(actionCollection()->action("delete"));
421
422 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
423 // since otherwise the created file would not be visible.
424 // But in treeview mode we should allow it.
425 if (m_view->itemsExpandable())
426 popupFlags |= KParts::BrowserExtension::ShowCreateDirectory;
427
428 }
429
430 actionGroups.insert("editactions", editActions);
431
432 emit m_extension->popupMenu(pos,
433 items,
434 KParts::OpenUrlArguments(),
435 KParts::BrowserArguments(),
436 popupFlags,
437 actionGroups);
438 }
439
440 void DolphinPart::slotRedirection(const KUrl& oldUrl, const KUrl& newUrl)
441 {
442 //kDebug() << oldUrl << newUrl << "currentUrl=" << url();
443 if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash /* #207572 */)) {
444 KParts::ReadOnlyPart::setUrl(newUrl);
445 const QString prettyUrl = newUrl.pathOrUrl();
446 emit m_extension->setLocationBarUrl(prettyUrl);
447 }
448 }
449
450
451 void DolphinPart::slotEditMimeType()
452 {
453 const KFileItemList items = m_view->selectedItems();
454 if (!items.isEmpty()) {
455 KonqOperations::editMimeType(items.first().mimetype(), m_view);
456 }
457 }
458
459 void DolphinPart::slotSelectItemsMatchingPattern()
460 {
461 openSelectionDialog(i18nc("@title:window", "Select"),
462 i18n("Select all items matching this pattern:"),
463 true);
464 }
465
466 void DolphinPart::slotUnselectItemsMatchingPattern()
467 {
468 openSelectionDialog(i18nc("@title:window", "Unselect"),
469 i18n("Unselect all items matching this pattern:"),
470 false);
471 }
472
473 void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
474 {
475 bool okClicked;
476 QString pattern = KInputDialog::getText(title, text, "*", &okClicked, m_view);
477
478 if (okClicked && !pattern.isEmpty()) {
479 QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
480 m_view->setItemSelectionEnabled(patternRegExp, selectItems);
481 }
482 }
483
484 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
485 {
486 QAction* action = actionCollection()->action(viewModeName);
487 Q_ASSERT(action);
488 action->trigger();
489 }
490
491 QString DolphinPart::currentViewMode() const
492 {
493 return m_actionHandler->currentViewModeActionName();
494 }
495
496 void DolphinPart::setNameFilter(const QString& nameFilter)
497 {
498 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
499 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
500 m_nameFilter = nameFilter;
501 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
502 }
503
504 void DolphinPart::slotOpenTerminal()
505 {
506 QString dir(QDir::homePath());
507
508 KUrl u(url());
509
510 // If the given directory is not local, it can still be the URL of an
511 // ioslave using UDS_LOCAL_PATH which to be converted first.
512 u = KIO::NetAccess::mostLocalUrl(u, widget());
513
514 //If the URL is local after the above conversion, set the directory.
515 if (u.isLocalFile()) {
516 dir = u.toLocalFile();
517 }
518
519 KToolInvocation::invokeTerminal(QString(), dir);
520 }
521
522 void DolphinPart::slotFindFile()
523 {
524 KRun::run("kfind", url(), widget());
525 }
526
527 void DolphinPart::updateNewMenu()
528 {
529 // As requested by KNewFileMenu :
530 m_newFileMenu->checkUpToDate();
531 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
532 // And set the files that the menu apply on :
533 m_newFileMenu->setPopupFiles(url());
534 }
535
536 void DolphinPart::updateStatusBar()
537 {
538 emit ReadOnlyPart::setStatusBarText(m_view->statusBarText());
539 }
540
541 void DolphinPart::updateProgress(int percent)
542 {
543 m_extension->loadingProgress(percent);
544 }
545
546 void DolphinPart::createDirectory()
547 {
548 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
549 m_newFileMenu->setPopupFiles(url());
550 m_newFileMenu->createDirectory();
551 }
552
553 void DolphinPart::setFilesToSelect(const KUrl::List& files)
554 {
555 m_view->markUrlsAsSelected(files);
556 }
557
558 ////
559
560 void DolphinPartBrowserExtension::restoreState(QDataStream &stream)
561 {
562 KParts::BrowserExtension::restoreState(stream);
563 m_part->view()->restoreState(stream);
564 }
565
566 void DolphinPartBrowserExtension::saveState(QDataStream &stream)
567 {
568 KParts::BrowserExtension::saveState(stream);
569 m_part->view()->saveState(stream);
570 }
571
572 void DolphinPartBrowserExtension::cut()
573 {
574 m_part->view()->cutSelectedItems();
575 }
576
577 void DolphinPartBrowserExtension::copy()
578 {
579 m_part->view()->copySelectedItems();
580 }
581
582 void DolphinPartBrowserExtension::paste()
583 {
584 m_part->view()->paste();
585 }
586
587 void DolphinPartBrowserExtension::pasteTo(const KUrl&)
588 {
589 m_part->view()->pasteIntoFolder();
590 }
591
592 void DolphinPartBrowserExtension::reparseConfiguration()
593 {
594 m_part->view()->readSettings();
595 }
596
597 ////
598
599 DolphinPartFileInfoExtension::DolphinPartFileInfoExtension(DolphinPart* part)
600 : KParts::FileInfoExtension(part)
601 {
602 }
603
604 DolphinPart* DolphinPartFileInfoExtension::part() const
605 {
606 return static_cast<DolphinPart*>(parent());
607 }
608
609 bool DolphinPartFileInfoExtension::hasSelection() const
610 {
611 return part()->view()->hasSelection();
612 }
613
614 KParts::FileInfoExtension::QueryModes DolphinPartFileInfoExtension::supportedQueryModes() const
615 {
616 return (KParts::FileInfoExtension::AllItems | KParts::FileInfoExtension::SelectedItems);
617 }
618
619 KFileItemList DolphinPartFileInfoExtension::queryFor(KParts::FileInfoExtension::QueryMode mode) const
620 {
621 KFileItemList list;
622
623 if (mode == KParts::FileInfoExtension::None)
624 return list;
625
626 if (!(supportedQueryModes() & mode))
627 return list;
628
629 switch (mode) {
630 case KParts::FileInfoExtension::SelectedItems:
631 if (hasSelection())
632 return part()->view()->selectedItems();
633 break;
634 case KParts::FileInfoExtension::AllItems:
635 return part()->view()->items();
636 default:
637 break;
638 }
639
640 return list;
641 }
642
643 #include "dolphinpart.moc"