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