]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinpart.cpp
Show the "Find File" and "Open Terminal" actions in the Tools for file URLs only.
[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 ,m_openTerminalAction(0)
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(directoryLoadingCompleted()), this, SIGNAL(completed()));
74 connect(m_view, SIGNAL(directoryLoadingProgress(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(QPoint,KFileItem,KUrl,QList<QAction*>)),
90 this, SLOT(slotOpenContextMenu(QPoint,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(slotDirectoryRedirection(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 DolphinNewFileMenuObserver::instance().detach(m_newFileMenu);
133 }
134
135 void DolphinPart::createActions()
136 {
137 // Edit menu
138
139 m_newFileMenu = new KNewFileMenu(actionCollection(), "new_menu", this);
140 m_newFileMenu->setParentWidget(widget());
141 DolphinNewFileMenuObserver::instance().attach(m_newFileMenu);
142 connect(m_newFileMenu->menu(), SIGNAL(aboutToShow()),
143 this, SLOT(updateNewMenu()));
144
145 KAction *editMimeTypeAction = actionCollection()->addAction( "editMimeType" );
146 editMimeTypeAction->setText( i18nc("@action:inmenu Edit", "&Edit File Type..." ) );
147 connect(editMimeTypeAction, SIGNAL(triggered()), SLOT(slotEditMimeType()));
148
149 KAction* selectItemsMatching = actionCollection()->addAction("select_items_matching");
150 selectItemsMatching->setText(i18nc("@action:inmenu Edit", "Select Items Matching..."));
151 selectItemsMatching->setShortcut(Qt::CTRL | Qt::Key_S);
152 connect(selectItemsMatching, SIGNAL(triggered()), this, SLOT(slotSelectItemsMatchingPattern()));
153
154 KAction* unselectItemsMatching = actionCollection()->addAction("unselect_items_matching");
155 unselectItemsMatching->setText(i18nc("@action:inmenu Edit", "Unselect Items Matching..."));
156 connect(unselectItemsMatching, SIGNAL(triggered()), this, SLOT(slotUnselectItemsMatchingPattern()));
157
158 actionCollection()->addAction(KStandardAction::SelectAll, "select_all", m_view, SLOT(selectAll()));
159
160 KAction* unselectAll = actionCollection()->addAction("unselect_all");
161 unselectAll->setText(i18nc("@action:inmenu Edit", "Unselect All"));
162 connect(unselectAll, SIGNAL(triggered()), m_view, SLOT(clearSelection()));
163
164 KAction* invertSelection = actionCollection()->addAction("invert_selection");
165 invertSelection->setText(i18nc("@action:inmenu Edit", "Invert Selection"));
166 invertSelection->setShortcut(Qt::CTRL | Qt::SHIFT | Qt::Key_A);
167 connect(invertSelection, SIGNAL(triggered()), m_view, SLOT(invertSelection()));
168
169 // View menu: all done by DolphinViewActionHandler
170
171 // Go menu
172
173 QActionGroup* goActionGroup = new QActionGroup(this);
174 connect(goActionGroup, SIGNAL(triggered(QAction*)),
175 this, SLOT(slotGoTriggered(QAction*)));
176
177 createGoAction("go_applications", "start-here-kde",
178 i18nc("@action:inmenu Go", "App&lications"), QString("programs:/"),
179 goActionGroup);
180 createGoAction("go_network_folders", "folder-remote",
181 i18nc("@action:inmenu Go", "&Network Folders"), QString("remote:/"),
182 goActionGroup);
183 createGoAction("go_settings", "preferences-system",
184 i18nc("@action:inmenu Go", "Sett&ings"), QString("settings:/"),
185 goActionGroup);
186 createGoAction("go_trash", "user-trash",
187 i18nc("@action:inmenu Go", "Trash"), QString("trash:/"),
188 goActionGroup);
189 createGoAction("go_autostart", "",
190 i18nc("@action:inmenu Go", "Autostart"), KGlobalSettings::autostartPath(),
191 goActionGroup);
192
193 // Tools menu
194 m_findFileAction = actionCollection()->addAction("find_file");
195 m_findFileAction->setText(i18nc("@action:inmenu Tools", "Find File..."));
196 m_findFileAction->setShortcut(Qt::CTRL | Qt::Key_F);
197 m_findFileAction->setIcon(KIcon("edit-find"));
198 connect(m_findFileAction, SIGNAL(triggered()), this, SLOT(slotFindFile()));
199
200 if (KAuthorized::authorizeKAction("shell_access")) {
201 m_openTerminalAction = actionCollection()->addAction("open_terminal");
202 m_openTerminalAction->setIcon(KIcon("utilities-terminal"));
203 m_openTerminalAction->setText(i18nc("@action:inmenu Tools", "Open &Terminal"));
204 connect(m_openTerminalAction, SIGNAL(triggered()), SLOT(slotOpenTerminal()));
205 m_openTerminalAction->setShortcut(Qt::Key_F4);
206 }
207 }
208
209 void DolphinPart::createGoAction(const char* name, const char* iconName,
210 const QString& text, const QString& url,
211 QActionGroup* actionGroup)
212 {
213 KAction* action = actionCollection()->addAction(name);
214 action->setIcon(KIcon(iconName));
215 action->setText(text);
216 action->setData(url);
217 action->setActionGroup(actionGroup);
218 }
219
220 void DolphinPart::slotGoTriggered(QAction* action)
221 {
222 const QString url = action->data().toString();
223 emit m_extension->openUrlRequest(KUrl(url));
224 }
225
226 void DolphinPart::slotSelectionChanged(const KFileItemList& selection)
227 {
228 const bool hasSelection = !selection.isEmpty();
229
230 QAction* renameAction = actionCollection()->action("rename");
231 QAction* moveToTrashAction = actionCollection()->action("move_to_trash");
232 QAction* deleteAction = actionCollection()->action("delete");
233 QAction* editMimeTypeAction = actionCollection()->action("editMimeType");
234 QAction* propertiesAction = actionCollection()->action("properties");
235 QAction* deleteWithTrashShortcut = actionCollection()->action("delete_shortcut"); // see DolphinViewActionHandler
236
237 if (!hasSelection) {
238 stateChanged("has_no_selection");
239
240 emit m_extension->enableAction("cut", false);
241 emit m_extension->enableAction("copy", false);
242 deleteWithTrashShortcut->setEnabled(false);
243 editMimeTypeAction->setEnabled(false);
244 } else {
245 stateChanged("has_selection");
246
247 // TODO share this code with DolphinMainWindow::updateEditActions (and the desktop code)
248 // in libkonq
249 KFileItemListProperties capabilities(selection);
250 const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving();
251
252 renameAction->setEnabled(capabilities.supportsMoving());
253 moveToTrashAction->setEnabled(enableMoveToTrash);
254 deleteAction->setEnabled(capabilities.supportsDeleting());
255 deleteWithTrashShortcut->setEnabled(capabilities.supportsDeleting() && !enableMoveToTrash);
256 editMimeTypeAction->setEnabled(true);
257 propertiesAction->setEnabled(true);
258 emit m_extension->enableAction("cut", capabilities.supportsMoving());
259 emit m_extension->enableAction("copy", true);
260 }
261 }
262
263 void DolphinPart::updatePasteAction()
264 {
265 QPair<bool, QString> pasteInfo = m_view->pasteInfo();
266 emit m_extension->enableAction( "paste", pasteInfo.first );
267 emit m_extension->setActionText( "paste", pasteInfo.second );
268 }
269
270 KAboutData* DolphinPart::createAboutData()
271 {
272 return new KAboutData("dolphinpart", "dolphin", ki18nc("@title", "Dolphin Part"), "0.1");
273 }
274
275 bool DolphinPart::openUrl(const KUrl& url)
276 {
277 bool reload = arguments().reload();
278 // A bit of a workaround so that changing the namefilter works: force reload.
279 // Otherwise DolphinView wouldn't relist the URL, so nothing would happen.
280 if (m_nameFilter != m_view->nameFilter())
281 reload = true;
282 if (m_view->url() == url && !reload) { // DolphinView won't do anything in that case, so don't emit started
283 return true;
284 }
285 setUrl(url); // remember it at the KParts level
286 KUrl visibleUrl(url);
287 if (!m_nameFilter.isEmpty()) {
288 visibleUrl.addPath(m_nameFilter);
289 }
290 QString prettyUrl = visibleUrl.pathOrUrl();
291 emit setWindowCaption(prettyUrl);
292 emit m_extension->setLocationBarUrl(prettyUrl);
293 emit started(0); // get the wheel to spin
294 m_view->setNameFilter(m_nameFilter);
295 m_view->setUrl(url);
296 updatePasteAction();
297 emit aboutToOpenURL();
298 if (reload)
299 m_view->reload();
300 // Disable "Find File" and "Open Terminal" actions for non-file URLs,
301 // e.g. ftp, smb, etc. #279283
302 const bool isLocalUrl = url.isLocalFile();
303 m_findFileAction->setEnabled(isLocalUrl);
304 if (m_openTerminalAction) {
305 m_openTerminalAction->setEnabled(isLocalUrl);
306 }
307 return true;
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 QPoint& pos,
356 const KFileItem& _item,
357 const KUrl&,
358 const QList<QAction*>& customActions)
359 {
360 KParts::BrowserExtension::PopupFlags popupFlags = KParts::BrowserExtension::DefaultPopupItems
361 | KParts::BrowserExtension::ShowProperties
362 | KParts::BrowserExtension::ShowUrlOperations;
363
364 KFileItem item(_item);
365
366 if (item.isNull()) { // viewport context menu
367 popupFlags |= KParts::BrowserExtension::ShowNavigationItems | KParts::BrowserExtension::ShowUp;
368 item = m_view->rootItem();
369 if (item.isNull())
370 item = KFileItem( S_IFDIR, (mode_t)-1, url() );
371 else
372 item.setUrl(url()); // ensure we use the view url, not the canonical path (#213799)
373 }
374
375 // TODO: We should change the signature of the slots (and signals) for being able
376 // to tell for which items we want a popup.
377 KFileItemList items;
378 if (m_view->selectedItems().isEmpty()) {
379 items.append(item);
380 } else {
381 items = m_view->selectedItems();
382 }
383
384 KFileItemListProperties capabilities(items);
385
386 KParts::BrowserExtension::ActionGroupMap actionGroups;
387 QList<QAction *> editActions;
388 editActions += m_view->versionControlActions(m_view->selectedItems());
389 editActions += customActions;
390
391 if (!_item.isNull()) { // only for context menu on one or more items
392 bool supportsDeleting = capabilities.supportsDeleting();
393 bool supportsMoving = capabilities.supportsMoving();
394
395 if (!supportsDeleting) {
396 popupFlags |= KParts::BrowserExtension::NoDeletion;
397 }
398
399 if (supportsMoving) {
400 editActions.append(actionCollection()->action("rename"));
401 }
402
403 bool addTrash = capabilities.isLocal() && supportsMoving;
404 bool addDel = false;
405 if (supportsDeleting) {
406 if ( !item.isLocalFile() )
407 addDel = true;
408 else if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
409 addTrash = false;
410 addDel = true;
411 }
412 else {
413 KSharedConfig::Ptr globalConfig = KSharedConfig::openConfig("kdeglobals", KConfig::IncludeGlobals);
414 KConfigGroup configGroup(globalConfig, "KDE");
415 addDel = configGroup.readEntry("ShowDeleteCommand", false);
416 }
417 }
418
419 if (addTrash)
420 editActions.append(actionCollection()->action("move_to_trash"));
421 if (addDel)
422 editActions.append(actionCollection()->action("delete"));
423
424 // Normally KonqPopupMenu only shows the "Create new" submenu in the current view
425 // since otherwise the created file would not be visible.
426 // But in treeview mode we should allow it.
427 if (m_view->itemsExpandable())
428 popupFlags |= KParts::BrowserExtension::ShowCreateDirectory;
429
430 }
431
432 actionGroups.insert("editactions", editActions);
433
434 emit m_extension->popupMenu(pos,
435 items,
436 KParts::OpenUrlArguments(),
437 KParts::BrowserArguments(),
438 popupFlags,
439 actionGroups);
440 }
441
442 void DolphinPart::slotDirectoryRedirection(const KUrl& oldUrl, const KUrl& newUrl)
443 {
444 //kDebug() << oldUrl << newUrl << "currentUrl=" << url();
445 if (oldUrl.equals(url(), KUrl::CompareWithoutTrailingSlash /* #207572 */)) {
446 KParts::ReadOnlyPart::setUrl(newUrl);
447 const QString prettyUrl = newUrl.pathOrUrl();
448 emit m_extension->setLocationBarUrl(prettyUrl);
449 }
450 }
451
452
453 void DolphinPart::slotEditMimeType()
454 {
455 const KFileItemList items = m_view->selectedItems();
456 if (!items.isEmpty()) {
457 KonqOperations::editMimeType(items.first().mimetype(), m_view);
458 }
459 }
460
461 void DolphinPart::slotSelectItemsMatchingPattern()
462 {
463 openSelectionDialog(i18nc("@title:window", "Select"),
464 i18n("Select all items matching this pattern:"),
465 true);
466 }
467
468 void DolphinPart::slotUnselectItemsMatchingPattern()
469 {
470 openSelectionDialog(i18nc("@title:window", "Unselect"),
471 i18n("Unselect all items matching this pattern:"),
472 false);
473 }
474
475 void DolphinPart::openSelectionDialog(const QString& title, const QString& text, bool selectItems)
476 {
477 bool okClicked;
478 QString pattern = KInputDialog::getText(title, text, "*", &okClicked, m_view);
479
480 if (okClicked && !pattern.isEmpty()) {
481 QRegExp patternRegExp(pattern, Qt::CaseSensitive, QRegExp::Wildcard);
482 m_view->selectItems(patternRegExp, selectItems);
483 }
484 }
485
486 void DolphinPart::setCurrentViewMode(const QString& viewModeName)
487 {
488 QAction* action = actionCollection()->action(viewModeName);
489 Q_ASSERT(action);
490 action->trigger();
491 }
492
493 QString DolphinPart::currentViewMode() const
494 {
495 return m_actionHandler->currentViewModeActionName();
496 }
497
498 void DolphinPart::setNameFilter(const QString& nameFilter)
499 {
500 // This is the "/home/dfaure/*.diff" kind of name filter (KDirLister::setNameFilter)
501 // which is unrelated to DolphinView::setNameFilter which is substring filtering in a proxy.
502 m_nameFilter = nameFilter;
503 // TODO save/restore name filter in saveState/restoreState like KonqDirPart did in kde3?
504 }
505
506 void DolphinPart::slotOpenTerminal()
507 {
508 QString dir(QDir::homePath());
509
510 KUrl u(url());
511
512 // If the given directory is not local, it can still be the URL of an
513 // ioslave using UDS_LOCAL_PATH which to be converted first.
514 u = KIO::NetAccess::mostLocalUrl(u, widget());
515
516 //If the URL is local after the above conversion, set the directory.
517 if (u.isLocalFile()) {
518 dir = u.toLocalFile();
519 }
520
521 KToolInvocation::invokeTerminal(QString(), dir);
522 }
523
524 void DolphinPart::slotFindFile()
525 {
526 KRun::run("kfind", url(), widget());
527 }
528
529 void DolphinPart::updateNewMenu()
530 {
531 // As requested by KNewFileMenu :
532 m_newFileMenu->checkUpToDate();
533 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
534 // And set the files that the menu apply on :
535 m_newFileMenu->setPopupFiles(url());
536 }
537
538 void DolphinPart::updateStatusBar()
539 {
540 emit ReadOnlyPart::setStatusBarText(m_view->statusBarText());
541 }
542
543 void DolphinPart::updateProgress(int percent)
544 {
545 m_extension->loadingProgress(percent);
546 }
547
548 void DolphinPart::createDirectory()
549 {
550 m_newFileMenu->setViewShowsHiddenFiles(m_view->hiddenFilesShown());
551 m_newFileMenu->setPopupFiles(url());
552 m_newFileMenu->createDirectory();
553 }
554
555 void DolphinPart::setFilesToSelect(const KUrl::List& files)
556 {
557 m_view->markUrlsAsSelected(files);
558 }
559
560 ////
561
562 void DolphinPartBrowserExtension::restoreState(QDataStream &stream)
563 {
564 KParts::BrowserExtension::restoreState(stream);
565 m_part->view()->restoreState(stream);
566 }
567
568 void DolphinPartBrowserExtension::saveState(QDataStream &stream)
569 {
570 KParts::BrowserExtension::saveState(stream);
571 m_part->view()->saveState(stream);
572 }
573
574 void DolphinPartBrowserExtension::cut()
575 {
576 m_part->view()->cutSelectedItems();
577 }
578
579 void DolphinPartBrowserExtension::copy()
580 {
581 m_part->view()->copySelectedItems();
582 }
583
584 void DolphinPartBrowserExtension::paste()
585 {
586 m_part->view()->paste();
587 }
588
589 void DolphinPartBrowserExtension::pasteTo(const KUrl&)
590 {
591 m_part->view()->pasteIntoFolder();
592 }
593
594 void DolphinPartBrowserExtension::reparseConfiguration()
595 {
596 m_part->view()->readSettings();
597 }
598
599 ////
600
601 DolphinPartFileInfoExtension::DolphinPartFileInfoExtension(DolphinPart* part)
602 : KParts::FileInfoExtension(part)
603 {
604 }
605
606 DolphinPart* DolphinPartFileInfoExtension::part() const
607 {
608 return static_cast<DolphinPart*>(parent());
609 }
610
611 bool DolphinPartFileInfoExtension::hasSelection() const
612 {
613 return part()->view()->selectedItemsCount() > 0;
614 }
615
616 KParts::FileInfoExtension::QueryModes DolphinPartFileInfoExtension::supportedQueryModes() const
617 {
618 return (KParts::FileInfoExtension::AllItems | KParts::FileInfoExtension::SelectedItems);
619 }
620
621 KFileItemList DolphinPartFileInfoExtension::queryFor(KParts::FileInfoExtension::QueryMode mode) const
622 {
623 KFileItemList list;
624
625 if (mode == KParts::FileInfoExtension::None)
626 return list;
627
628 if (!(supportedQueryModes() & mode))
629 return list;
630
631 switch (mode) {
632 case KParts::FileInfoExtension::SelectedItems:
633 if (hasSelection())
634 return part()->view()->selectedItems();
635 break;
636 case KParts::FileInfoExtension::AllItems:
637 return part()->view()->items();
638 default:
639 break;
640 }
641
642 return list;
643 }
644
645 #include "dolphinpart.moc"