[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kdelibs/KDE/4.9] kfile: Fix/add support for mtp devices
From:       Alex Fiestas <afiestas () kde ! org>
Date:       2012-10-31 22:58:26
Message-ID: 20121031225826.B449DA6078 () git ! kde ! org
[Download RAW message or body]

Git commit fa90ceda3812b75e67368899dcc5e715e9bc74d5 by Alex Fiestas.
Committed on 31/10/2012 at 23:58.
Pushed by afiestas into branch 'KDE/4.9'.

Fix/add support for mtp devices

In case kio_mtp is installed, list them as a deviceO

M  +6    -0    kfile/kfileplacesitem.cpp
M  +2    -0    kfile/kfileplacesitem_p.h
M  +11   -2    kfile/kfileplacesmodel.cpp

http://commits.kde.org/kdelibs/fa90ceda3812b75e67368899dcc5e715e9bc74d5

diff --git a/kfile/kfileplacesitem.cpp b/kfile/kfileplacesitem.cpp
index d571955..119ccc0 100644
--- a/kfile/kfileplacesitem.cpp
+++ b/kfile/kfileplacesitem.cpp
@@ -32,6 +32,7 @@
 #include <solid/storageaccess.h>
 #include <solid/storagevolume.h>
 #include <solid/storagedrive.h>
+#include <solid/portablemediaplayer.h>
 
 
 KFilePlacesItem::KFilePlacesItem(KBookmarkManager *manager,
@@ -58,6 +59,7 @@ KFilePlacesItem::KFilePlacesItem(KBookmarkManager *manager,
         m_access = m_device.as<Solid::StorageAccess>();
         m_volume = m_device.as<Solid::StorageVolume>();
         m_disc = m_device.as<Solid::OpticalDisc>();
+        m_mtp = m_device.as<Solid::PortableMediaPlayer>();
         if (m_access) {
             connect(m_access, SIGNAL(accessibilityChanged(bool,QString)),
                     this, SLOT(onAccessibilityChanged(bool)));
@@ -115,10 +117,12 @@ Solid::Device KFilePlacesItem::device() const
             m_access = m_device.as<Solid::StorageAccess>();
             m_volume = m_device.as<Solid::StorageVolume>();
             m_disc = m_device.as<Solid::OpticalDisc>();
+            m_mtp = m_device.as<Solid::PortableMediaPlayer>();
         } else {
             m_access = 0;
             m_volume = 0;
             m_disc = 0;
+            m_mtp = 0;
         }
     }
     return m_device;
@@ -183,6 +187,8 @@ QVariant KFilePlacesItem::deviceData(int role) const
             } else if (m_disc && (m_disc->availableContent() & \
Solid::OpticalDisc::Audio)!=0) {  QString device = d.as<Solid::Block>()->device();
                 return QUrl(QString("audiocd:/?device=%1").arg(device));
+            } else if (m_mtp) {
+                return QUrl(QString("mtp:udi=%1").arg(d.udi()));
             } else {
                 return QVariant();
             }
diff --git a/kfile/kfileplacesitem_p.h b/kfile/kfileplacesitem_p.h
index dec3e64..b50cec4 100644
--- a/kfile/kfileplacesitem_p.h
+++ b/kfile/kfileplacesitem_p.h
@@ -34,6 +34,7 @@ namespace Solid
 class StorageAccess;
 class StorageVolume;
 class OpticalDisc;
+class PortableMediaPlayer;
 }
 
 class KFilePlacesItem : public QObject
@@ -93,6 +94,7 @@ private:
     mutable QPointer<Solid::StorageAccess> m_access;
     mutable QPointer<Solid::StorageVolume> m_volume;
     mutable QPointer<Solid::OpticalDisc> m_disc;
+    mutable QPointer<Solid::PortableMediaPlayer> m_mtp;
     QString m_iconPath;
     QStringList m_emblems;
 };
diff --git a/kfile/kfileplacesmodel.cpp b/kfile/kfileplacesmodel.cpp
index 99e7597..0192926 100644
--- a/kfile/kfileplacesmodel.cpp
+++ b/kfile/kfileplacesmodel.cpp
@@ -47,6 +47,7 @@
 #include <kbookmark.h>
 
 #include <kio/netaccess.h>
+#include <kprotocolinfo.h>
 
 #include <solid/devicenotifier.h>
 #include <solid/storageaccess.h>
@@ -54,6 +55,7 @@
 #include <solid/storagevolume.h>
 #include <solid/opticaldrive.h>
 #include <solid/opticaldisc.h>
+#include <solid/portablemediaplayer.h>
 #include <solid/predicate.h>
 
 class KFilePlacesModel::Private
@@ -147,14 +149,21 @@ KFilePlacesModel::KFilePlacesModel(QObject *parent)
     // create after, so if we have own places, they are added afterwards, in case of \
                equal priorities
     d->sharedBookmarks = new KFilePlacesSharedBookmarks(d->bookmarkManager);
 
-    d->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']");
+    }
+
+    d->predicate = Solid::Predicate::fromString(predicate);
+
     Q_ASSERT(d->predicate.isValid());
 
     connect(d->bookmarkManager, SIGNAL(changed(QString,QString)),


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic