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