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