[banshee] [mtp] Fall back to ModelName if there is no Name



commit b36c4bfaee36a45101dc66ccf4799d8428216194
Author: Alan McGovern <alan mcgovern gmail com>
Date:   Wed Sep 8 18:53:10 2010 +0100

    [mtp] Fall back to ModelName if there is no Name
    
    If there's no friendly name (user set name for the device) or the
    friendly name is '?????', fall back to using the device model as the
    name, i.e. "Creative Zen" instead of "?????". Fixes #629095.

 .../Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs   |    8 +++++++-
 src/Libraries/Mtp/Mtp/MtpDevice.cs                 |   18 ++++++++++++++++--
 2 files changed, 23 insertions(+), 3 deletions(-)
---
diff --git a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
index 2236f66..ae222c5 100644
--- a/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
+++ b/src/Dap/Banshee.Dap.Mtp/Banshee.Dap.Mtp/MtpSource.cs
@@ -116,7 +116,13 @@ namespace Banshee.Dap.Mtp
                 throw new InvalidDeviceException ();
             }
 
-            Name = mtp_device.Name;
+            // libmtp sometimes returns '?????'. I assume this is if the device does
+            // not supply a friendly name. In this case show the model name.
+            if (string.IsNullOrEmpty (mtp_device.Name) || mtp_device.Name == "?????")
+                Name = mtp_device.ModelName;
+            else
+                Name = mtp_device.Name;
+
             Initialize ();
 
             List<string> mimetypes = new List<string> ();
diff --git a/src/Libraries/Mtp/Mtp/MtpDevice.cs b/src/Libraries/Mtp/Mtp/MtpDevice.cs
index e594bf7..db2ba99 100644
--- a/src/Libraries/Mtp/Mtp/MtpDevice.cs
+++ b/src/Libraries/Mtp/Mtp/MtpDevice.cs
@@ -78,6 +78,10 @@ namespace Mtp
             get { return GetDeviceversion (Handle); }
         }
 
+        public string ModelName {
+            get; private set;
+        }
+
         public string Name {
             get { return name; }
             set {
@@ -124,6 +128,7 @@ namespace Mtp
             this.device = device;
             this.Handle = handle;
             this.name = GetFriendlyName(Handle);
+            this.ModelName = GetModelName (Handle);
             SetDefaultFolders ();
         }
         
@@ -341,6 +346,15 @@ namespace Mtp
             return success;
         }
 
+        internal static string GetModelName(MtpDeviceHandle handle)
+        {
+            IntPtr ptr = LIBMTP_Get_Modelname (handle);
+            if (ptr == IntPtr.Zero)
+                return null;
+
+            return StringFromIntPtr (ptr);
+        }
+
         internal static string GetSerialnumber(MtpDeviceHandle handle)
         {
             IntPtr ptr = LIBMTP_Get_Serialnumber(handle);
@@ -431,8 +445,8 @@ namespace Mtp
         [DllImport("libmtp.dll")]
         private static extern int LIBMTP_Get_Batterylevel (MtpDeviceHandle handle, out ushort maxLevel, out ushort currentLevel);
         
-        //[DllImportAttribute("libmtp.dll")]
-        //private static extern IntPtr LIBMTP_Get_Modelname (MtpDeviceHandle handle); // char *
+        [DllImportAttribute("libmtp.dll")]
+        private static extern IntPtr LIBMTP_Get_Modelname (MtpDeviceHandle handle); // char *
         
         [DllImportAttribute("libmtp.dll")]
         private static extern IntPtr LIBMTP_Get_Serialnumber (MtpDeviceHandle handle); // char *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]