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