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