From a09a23795050be4ad6e2c987614cb28096030cc8 Mon Sep 17 00:00:00 2001 From: Alex Fiestas Date: Wed, 24 Oct 2012 01:21:02 +0200 Subject: [PATCH] Show MTP devices in case support for it is installed Basically adds a conditional that in case that mtp kioslave is installed devices with MTP are added to the predicated. REVIEW: 106651 --- dolphin/src/panels/places/placesitem.cpp | 6 +++++ dolphin/src/panels/places/placesitem.h | 2 ++ dolphin/src/panels/places/placesitemmodel.cpp | 23 ++++++++++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/dolphin/src/panels/places/placesitem.cpp b/dolphin/src/panels/places/placesitem.cpp index f72f639758..f78c98b76d 100644 --- a/dolphin/src/panels/places/placesitem.cpp +++ b/dolphin/src/panels/places/placesitem.cpp @@ -37,6 +37,7 @@ PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) : m_access(), m_volume(), m_disc(), + m_mtp(), m_signalHandler(0), m_trashDirLister(0), m_bookmark() @@ -124,6 +125,7 @@ void PlacesItem::setBookmark(const KBookmark& bookmark) delete m_access; delete m_volume; delete m_disc; + delete m_mtp; const QString udi = bookmark.metaDataItem("UDI"); @@ -252,6 +254,7 @@ void PlacesItem::initializeDevice(const QString& udi) m_access = m_device.as(); m_volume = m_device.as(); m_disc = m_device.as(); + m_mtp = m_device.as(); setText(m_device.description()); setIcon(m_device.icon()); @@ -265,6 +268,9 @@ void PlacesItem::initializeDevice(const QString& udi) } else if (m_disc && (m_disc->availableContent() & Solid::OpticalDisc::Audio) != 0) { const QString device = m_device.as()->device(); setUrl(QString("audiocd:/?device=%1").arg(device)); + } else if (m_mtp && m_mtp->supportedProtocols().contains("mtp")) { + setText(m_device.product()); + setUrl(QString("mtp:udi=%1").arg(m_device.udi())); } } diff --git a/dolphin/src/panels/places/placesitem.h b/dolphin/src/panels/places/placesitem.h index 5a24a52686..297f12d912 100644 --- a/dolphin/src/panels/places/placesitem.h +++ b/dolphin/src/panels/places/placesitem.h @@ -28,6 +28,7 @@ #include #include #include +#include class KDirLister; class PlacesItemSignalHandler; @@ -115,6 +116,7 @@ private: QPointer m_access; QPointer m_volume; QPointer m_disc; + QPointer m_mtp; QPointer m_signalHandler; QPointer m_trashDirLister; KBookmark m_bookmark; diff --git a/dolphin/src/panels/places/placesitemmodel.cpp b/dolphin/src/panels/places/placesitemmodel.cpp index 89488610fe..31285aea28 100644 --- a/dolphin/src/panels/places/placesitemmodel.cpp +++ b/dolphin/src/panels/places/placesitemmodel.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -554,11 +555,14 @@ void PlacesItemModel::onItemChanged(int index, const QSet& changedRo void PlacesItemModel::slotDeviceAdded(const QString& udi) { const Solid::Device device(udi); - if (m_predicate.matches(device)) { - m_availableDevices << udi; - const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); - appendItem(new PlacesItem(bookmark)); + + if (!m_predicate.matches(device)) { + return; } + + m_availableDevices << udi; + const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); + appendItem(new PlacesItem(bookmark)); } void PlacesItemModel::slotDeviceRemoved(const QString& udi) @@ -947,14 +951,21 @@ void PlacesItemModel::createSystemBookmarks() void PlacesItemModel::initializeAvailableDevices() { - m_predicate = Solid::Predicate::fromString( - "[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]" + QString predicate("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]" " OR " "[ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]" " OR " "OpticalDisc.availableContent & 'Audio' ]" " OR " "StorageAccess.ignored == false ]"); + + + if (KProtocolInfo::isKnownProtocol("mtp")) { + predicate.prepend("["); + predicate.append(" OR PortableMediaPlayer.supportedProtocols == 'mtp']"); + } + + m_predicate = Solid::Predicate::fromString(predicate); Q_ASSERT(m_predicate.isValid()); Solid::DeviceNotifier* notifier = Solid::DeviceNotifier::instance();