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