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