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
(cherry picked from commit a09a237950)
This commit is contained in:
Alex Fiestas 2012-10-24 01:21:02 +02:00
parent 04dabe84b2
commit 996fe25208
3 changed files with 25 additions and 6 deletions

View file

@ -37,6 +37,7 @@ PlacesItem::PlacesItem(const KBookmark& bookmark, PlacesItem* parent) :
m_access(), m_access(),
m_volume(), m_volume(),
m_disc(), m_disc(),
m_mtp(),
m_signalHandler(0), m_signalHandler(0),
m_trashDirLister(0), m_trashDirLister(0),
m_bookmark() m_bookmark()
@ -124,6 +125,7 @@ void PlacesItem::setBookmark(const KBookmark& bookmark)
delete m_access; delete m_access;
delete m_volume; delete m_volume;
delete m_disc; delete m_disc;
delete m_mtp;
const QString udi = bookmark.metaDataItem("UDI"); const QString udi = bookmark.metaDataItem("UDI");
@ -252,6 +254,7 @@ void PlacesItem::initializeDevice(const QString& udi)
m_access = m_device.as<Solid::StorageAccess>(); m_access = m_device.as<Solid::StorageAccess>();
m_volume = m_device.as<Solid::StorageVolume>(); m_volume = m_device.as<Solid::StorageVolume>();
m_disc = m_device.as<Solid::OpticalDisc>(); m_disc = m_device.as<Solid::OpticalDisc>();
m_mtp = m_device.as<Solid::PortableMediaPlayer>();
setText(m_device.description()); setText(m_device.description());
setIcon(m_device.icon()); 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) { } else if (m_disc && (m_disc->availableContent() & Solid::OpticalDisc::Audio) != 0) {
const QString device = m_device.as<Solid::Block>()->device(); const QString device = m_device.as<Solid::Block>()->device();
setUrl(QString("audiocd:/?device=%1").arg(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()));
} }
} }

View file

@ -28,6 +28,7 @@
#include <Solid/OpticalDisc> #include <Solid/OpticalDisc>
#include <Solid/StorageAccess> #include <Solid/StorageAccess>
#include <Solid/StorageVolume> #include <Solid/StorageVolume>
#include <Solid/PortableMediaPlayer>
class KDirLister; class KDirLister;
class PlacesItemSignalHandler; class PlacesItemSignalHandler;
@ -115,6 +116,7 @@ private:
QPointer<Solid::StorageAccess> m_access; QPointer<Solid::StorageAccess> m_access;
QPointer<Solid::StorageVolume> m_volume; QPointer<Solid::StorageVolume> m_volume;
QPointer<Solid::OpticalDisc> m_disc; QPointer<Solid::OpticalDisc> m_disc;
QPointer<Solid::PortableMediaPlayer> m_mtp;
QPointer<PlacesItemSignalHandler> m_signalHandler; QPointer<PlacesItemSignalHandler> m_signalHandler;
QPointer<KDirLister> m_trashDirLister; QPointer<KDirLister> m_trashDirLister;
KBookmark m_bookmark; KBookmark m_bookmark;

View file

@ -31,6 +31,7 @@
#include <KComponentData> #include <KComponentData>
#include <KDebug> #include <KDebug>
#include <KIcon> #include <KIcon>
#include <kprotocolinfo.h>
#include <KLocale> #include <KLocale>
#include <KStandardDirs> #include <KStandardDirs>
#include <KUser> #include <KUser>
@ -554,11 +555,14 @@ void PlacesItemModel::onItemChanged(int index, const QSet<QByteArray>& changedRo
void PlacesItemModel::slotDeviceAdded(const QString& udi) void PlacesItemModel::slotDeviceAdded(const QString& udi)
{ {
const Solid::Device device(udi); const Solid::Device device(udi);
if (m_predicate.matches(device)) {
m_availableDevices << udi; if (!m_predicate.matches(device)) {
const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi); return;
appendItem(new PlacesItem(bookmark));
} }
m_availableDevices << udi;
const KBookmark bookmark = PlacesItem::createDeviceBookmark(m_bookmarkManager, udi);
appendItem(new PlacesItem(bookmark));
} }
void PlacesItemModel::slotDeviceRemoved(const QString& udi) void PlacesItemModel::slotDeviceRemoved(const QString& udi)
@ -949,14 +953,21 @@ void PlacesItemModel::createSystemBookmarks()
void PlacesItemModel::initializeAvailableDevices() void PlacesItemModel::initializeAvailableDevices()
{ {
m_predicate = Solid::Predicate::fromString( QString predicate("[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]"
"[[[[ StorageVolume.ignored == false AND [ StorageVolume.usage == 'FileSystem' OR StorageVolume.usage == 'Encrypted' ]]"
" OR " " OR "
"[ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]" "[ IS StorageAccess AND StorageDrive.driveType == 'Floppy' ]]"
" OR " " OR "
"OpticalDisc.availableContent & 'Audio' ]" "OpticalDisc.availableContent & 'Audio' ]"
" OR " " OR "
"StorageAccess.ignored == false ]"); "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()); Q_ASSERT(m_predicate.isValid());
Solid::DeviceNotifier* notifier = Solid::DeviceNotifier::instance(); Solid::DeviceNotifier* notifier = Solid::DeviceNotifier::instance();