Author: gburt
Date: Tue Jan 29 22:57:41 2008
New Revision: 3085
URL: http://svn.gnome.org/viewvc/banshee?rev=3085&view=rev

Log:
2008-01-29  Gabriel Burt  <[EMAIL PROTECTED]>

        * ext/libmtp-sharp/Functions/TrackManagement.cs: Remove debug WriteLine,
        and more importantly, Console.ReadLine from SendTrack.

        * ext/libmtp-sharp/Functions/FunctionCalls.cs: Add DeviceVersion and
        Serialnumber getters, and FriendlyName setter.

        * ext/libmtp-sharp/MtpDevice.cs: Add Name setter (Set_FriendlyName) and
        Version (Deviceversion) and SerialNumber properties.  Don't throw an 
error
        just because the track list is empty.  Remove debug WriteLine.

        * src/Dap/Banshee.Dap.Mtp/MtpDap.cs: Rely much more heavily on HAL.  
Only
        allow one instance of MtpDap, since at the moment libmtp only lets us be
        connected to one at a time.  When MtpDap.Initialize is called, only
        actually initialize the/a MTP device iff its libmtp serialize number
        matches the HAL device we're checking.  Add support for renaming the
        device.  Add Version property information.  Update the remove/add 
progress
        after actually removing an item (so if you transfer one item, it doesn't
        go to 100% until after it's done).  Clean up Reload methods.  Get rid of
        'camera' terminology.

        * src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs: Use properties instead of
        protected variables.


Modified:
   branches/banshee/stable/ChangeLog
   branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs
   branches/banshee/stable/ext/libmtp-sharp/Functions/TrackManagement.cs
   branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs
   branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs
   branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs

Modified: branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs 
(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Functions/FunctionCalls.cs Tue Jan 
29 22:57:41 2008
@@ -54,30 +54,50 @@
                        if (result != 0)
                                throw new LibMtpException 
(ErrorCode.LIBMTP_ERROR_GENERAL, "Could not retrieve battery stats");
                }
-               
+
                public static void GetConnectedDevices (out IntPtr list)
                {
                        Error.CheckError (LIBMTP_Get_Connected_Devices (out 
list));
                }
+
                public static IntPtr GetErrorStack (MtpDeviceHandle handle)
                {
                        return LIBMTP_Get_Errorstack(handle);
                }
+
+               public static string GetDeviceversion(MtpDeviceHandle handle)
+               {
+                       IntPtr ptr = LibMtp.LIBMTP_Get_Deviceversion(handle);
+                       if (ptr == IntPtr.Zero)
+                               return null;
+                       
+            return StringFromIntPtr (ptr);
+               }
+
                
                public static string GetFriendlyName(MtpDeviceHandle handle)
                {
                        IntPtr ptr = LibMtp.LIBMTP_Get_Friendlyname(handle);
                        if (ptr == IntPtr.Zero)
-                               return "Mtp Device";
+                               return null;
                        
-                       int i = 0;
-                       while (Marshal.ReadByte (ptr, i) != (byte) 0) ++i;
-                       byte[] s_buf = new byte [i];
-                       Marshal.Copy (ptr, s_buf, 0, s_buf.Length);
-                       string s = System.Text.Encoding.UTF8.GetString (s_buf);
-                       Marshal.FreeCoTaskMem(ptr);
-                       return s;
+            return StringFromIntPtr (ptr);
                }
+
+               public static bool SetFriendlyName(MtpDeviceHandle handle, 
string name)
+        {
+            bool success = LIBMTP_Set_Friendlyname (handle, name) == 0;
+            return success;
+        }
+
+               public static string GetSerialnumber(MtpDeviceHandle handle)
+               {
+                       IntPtr ptr = LibMtp.LIBMTP_Get_Serialnumber(handle);
+                       if (ptr == IntPtr.Zero)
+                               return null;
+
+            return StringFromIntPtr (ptr);
+        }
                
                public static void GetStorage (MtpDeviceHandle handle, int 
sortMode)
                {
@@ -92,6 +112,17 @@
                {
                        LIBMTP_Release_Device(handle);
                }
+
+        private static string StringFromIntPtr (IntPtr ptr)
+        {
+                       int i = 0;
+                       while (Marshal.ReadByte (ptr, i) != (byte) 0) ++i;
+                       byte[] s_buf = new byte [i];
+                       Marshal.Copy (ptr, s_buf, 0, s_buf.Length);
+                       string s = System.Text.Encoding.UTF8.GetString (s_buf);
+                       Marshal.FreeCoTaskMem(ptr);
+                       return s;
+        }
                
                [DllImport("libmtp.dll")]
                private static extern void LIBMTP_Init ();
@@ -144,8 +175,8 @@
                [DllImportAttribute("libmtp.dll")]
                private static extern IntPtr LIBMTP_Get_Friendlyname 
(MtpDeviceHandle handle); // char *
                
-               //[DllImport("libmtp.dll")]
-               //private static extern int LIBMTP_Set_Friendlyname 
(MtpDeviceHandle handle, char const *const)
+               [DllImport("libmtp.dll")]
+               private static extern int LIBMTP_Set_Friendlyname 
(MtpDeviceHandle handle, string name);
                
                [DllImportAttribute("libmtp.dll")]
                private static extern IntPtr LIBMTP_Get_Errorstack 
(MtpDeviceHandle handle); // LIBMTP_error_t *

Modified: branches/banshee/stable/ext/libmtp-sharp/Functions/TrackManagement.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/Functions/TrackManagement.cs       
(original)
+++ branches/banshee/stable/ext/libmtp-sharp/Functions/TrackManagement.cs       
Tue Jan 29 22:57:41 2008
@@ -52,14 +52,11 @@
                }
                internal static void SendTrack (MtpDeviceHandle handle, string 
path, ref TrackStruct metadata, ProgressFunction callback, IntPtr data, uint 
parent)
                {
-                       Console.WriteLine("Sending: {0}", metadata.item_id);
                        if (LIBMTP_Send_Track_From_File (handle, path, ref 
metadata, callback, data, parent) != 0)
                        {
                                LibMtpException.CheckErrorStack(handle);
                                throw new LibMtpException 
(ErrorCode.LIBMTP_ERROR_GENERAL, "Could not upload the track");
                        }
-                       Console.WriteLine("Got: {0}", metadata.item_id);
-                       Console.ReadLine();
                }
                internal static void UpdateTrackMetadata(MtpDeviceHandle 
handle, ref TrackStruct metadata)
                {

Modified: branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs
==============================================================================
--- branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs       (original)
+++ branches/banshee/stable/ext/libmtp-sharp/MtpDevice.cs       Tue Jan 29 
22:57:41 2008
@@ -46,67 +46,68 @@
                private Folder podcastFolder;
                private Folder textFolder;
                private Folder videoFolder;
-               
-               public Folder AlbumFolder
-               {
-                       get { return albumFolder; }
+
+               static MtpDevice() {
+                       LibMtp.Init();
                }
                
-               public int BatteryLevel
-               {
-                       get
-                       {
+               public int BatteryLevel {
+                       get {
                                ushort level, maxLevel;
                                LibMtp.GetBatteryLevel (handle, out maxLevel, 
out level);
                                return (int)((level * 100.0) / maxLevel);
                        }
                }
 
-               public Folder MusicFolder
-               {
-                       get { return musicFolder;}
-               }
-               
-               public string Name
-               {
+        public string SerialNumber {
+            get { return LibMtp.GetSerialnumber (handle); }
+        }
+
+        public string Version {
+            get { return LibMtp.GetDeviceversion (handle); }
+        }
+
+               public string Name {
                        get { return name; }
+            set {
+                if (LibMtp.SetFriendlyName (handle, value)) {
+                    name = value;
+                }
+            }
                }
 
-               public Folder OrganizerFolder
-               {
+               public Folder AlbumFolder {
+                       get { return albumFolder; }
+               }
+
+               public Folder MusicFolder {
+                       get { return musicFolder; }
+               }
+
+               public Folder OrganizerFolder {
                        get { return organizerFolder; }
                }
 
-               public Folder PictureFolder
-               {
+               public Folder PictureFolder {
                        get { return pictureFolder; }
                }
 
-               public Folder PlaylistFolder
-               {
+               public Folder PlaylistFolder {
                        get { return playlistFolder; }
                }
 
-               public Folder PodcastFolder
-               {
+               public Folder PodcastFolder {
                        get { return podcastFolder; }
                }
 
-               public Folder TextFolder
-               {
+               public Folder TextFolder {
                        get { return textFolder; }
                }
                
-               public Folder VideoFolder
-               {
+               public Folder VideoFolder {
                        get { return videoFolder; }
                }
                
-               static MtpDevice()
-               {
-                       LibMtp.Init();
-               }
-               
                internal MtpDevice (MtpDeviceHandle handle, MtpDeviceStruct 
device)
                {
                        this.device = device;
@@ -170,10 +171,8 @@
                {
                        IntPtr ptr = TrackManagement.GetTrackListing(handle, 
callback, IntPtr.Zero);
 
-                       if (ptr == IntPtr.Zero)
-                               throw new 
LibMtpException(ErrorCode.LIBMTP_ERROR_PTP_LAYER);
-                       
                        List<Track> tracks = new List<Track>();
+                       
                        while (ptr != IntPtr.Zero)
                        {
                                TrackStruct track = 
(TrackStruct)Marshal.PtrToStructure(ptr, typeof(TrackStruct));
@@ -201,7 +200,6 @@
                
                public void Remove (Track track)
                {
-                       Console.WriteLine("Removing: {0}", track.FileId);
                        LibMtp.DeleteObject(handle, track.FileId);
                }
                

Modified: branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs
==============================================================================
--- branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs   (original)
+++ branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDap.cs   Tue Jan 29 
22:57:41 2008
@@ -60,129 +60,144 @@
        [DapProperties (DapType = DapType.NonGeneric)]
        [SupportedCodec (CodecType.Mp3)]
        [SupportedCodec (CodecType.Wma)]
-//     [SupportedCodec (CodecType.Wav)] // for some reason, files get sent to 
the device as Wav's when this is enabled.  wtf?
-       
        public sealed class MtpDap : DapDevice, IImportable//, IPlaylistCapable
        {
-               private MtpDevice camera;
+        private static MtpDap mtp_dap;
+
+               private MtpDevice device;
+        private Hal.Device hal_device;
                private List<MtpDapTrackInfo> metadataChangedQueue;
                private Queue<MtpDapTrackInfo> removeQueue;
-               private List<MtpDapTrackInfo> allTracks;
-
-               internal MtpDevice Camera {
-                       get { return camera; }
-               }
+               private List<MtpDapTrackInfo> all_tracks;
+        
+        private string hal_name = String.Empty;
 
-               public override bool CanSynchronize {
-                       get { return true; }
-               }
-               
                public MtpDap ()
                {
-                       allTracks = new List<MtpDapTrackInfo> ();
+                       all_tracks = new List<MtpDapTrackInfo> ();
                        metadataChangedQueue = new List<MtpDapTrackInfo> ();
                        removeQueue = new Queue<MtpDapTrackInfo> ();            
        
                }
                
-               
-               public override void Eject ()
-               {
-                       camera.Dispose ();
-                       base.Eject ();
-               }
-               
                public override InitializeResult Initialize (Hal.Device 
halDevice)
                {
-                       HalDevice = halDevice;
-                       //if (!halDevice.PropertyExists ("usb.vendor_id")) {
-                       //LogCore.Instance.PushDebug ("Missing Properties", 
"Cannot find usb.vendor_id");
-                       //}
-                       //if (!halDevice.PropertyExists ("usb.product_id")) {
-                       //LogCore.Instance.PushDebug ("Missing Properties", 
"Cannot find usb.product_id");
-                       //}
-                       short product_id = 0;// (short) 
halDevice.GetPropertyInteger ("usb.product_id");
-                       short vendor_id  = 0;// (short) 
halDevice.GetPropertyInteger ("usb.vendor_id");
-                       int deviceNumber = 0;//halDevice.GetPropertyInteger 
("usb.linux.device_number");
-                       int busNumber = 0;   //halDevice.GetPropertyInteger 
("usb.bus_number");
-                       
-                       // Pull out the properties we use for checking if the 
device is an MTP device or not
-                       string type = halDevice.PropertyExists 
("portable_audio_player.type") ? halDevice.GetPropertyString 
("portable_audio_player.type") : "??";
-                       string description = 
halDevice.PropertyExists("usb.interface.description") ? 
halDevice.GetPropertyString("usb.interface.description") : "??";
-                       string name = halDevice.PropertyExists 
("usb_device.product") ? halDevice.GetPropertyString ("usb_device.product") : 
"Mtp Device";
-                       
-                       if (type != "mtp" && description != "MTP Interface") {  
                
-                               LogCore.Instance.PushDebug ("MTP: Unsupported 
Device", string.Format("Type: {0}, Description: {1}", type, description));
+            hal_device = halDevice;
+
+            // Make sure it's an MTP device
+            if (hal_device["portable_audio_player.type"] != "mtp") {
                                return InitializeResult.Invalid;
-                       }
+            }
+
+            // libmtp only allows us to have one MTP device active
+            if (mtp_dap != null) {
+                LogCore.Instance.PushInformation(
+                    Catalog.GetString ("MTP Support Ignoring Device"),
+                    Catalog.GetString ("Banshee's MTP audio player support can 
only handle one device at a time."),
+                    true
+                );
+                               return InitializeResult.Invalid;
+            }
+
+            try {
+                hal_name = hal_device.Parent ["info.product"];
+            } catch {}
+
+            int product_id = hal_device.GetPropertyInteger ("usb.product_id");
+            int vendor_id = hal_device.GetPropertyInteger ("usb.vendor_id");
+            string serial = hal_device ["usb.serial"];
                        
-                       LogCore.Instance.PushDebug ("MTP: Starting 
initialization",
-                String.Format ("Name: {0}, Device: {1}, Bus:{2}", name, 
deviceNumber, busNumber)
-            );
                        
-                       List<MtpDevice> cameras = null;
+                       List<MtpDevice> devices = null;
                        try {
-                               cameras = MtpDevice.Detect ();
+                               devices = MtpDevice.Detect ();
                        } catch (TypeInitializationException ex) {
-                // Translators: {0} is just newline, {1} is some error string 
(in English?)
-                               string message = Catalog.GetString ("Required 
libraries could not be found. Read 
http://www.banshee-project.org/Guide/DAPs/MTP for more information. {0}{0}{1} 
could not be found.");
-                               LogCore.Instance.PushError (Catalog.GetString 
("Initialization error"),
-                    String.Format (message, Environment.NewLine, 
ex.InnerException.Message)
+                               LogCore.Instance.PushError (
+                    Catalog.GetString ("Error Initializing MTP Device 
Support"),
+                    Catalog.GetString ("There was an error intializing MTP 
device support.  See http://www.banshee-project.org/Guide/DAPs/MTP for more 
information.")
                 );
                                return InitializeResult.Invalid;
                        } catch (Exception ex) {
                                ShowGeneralExceptionDialog (ex);
                                return InitializeResult.Invalid;
                        }
-                       //camera = cameras.Find (delegate (Camera c) { return 
c.UsbBusNumber == busNumber && c.UsbDeviceNumber == deviceNumber; });
-                               
-                       if (cameras == null || cameras.Count != 1) {
-                               //LogCore.Instance.PushDebug ("Connection 
failed", string.Format ("MTP: found {0} devices, but not the one we're looking 
for.", cameras.Count));
-                               //foreach (MtpDap cam in cameras)
-                               //      LogCore.Instance.PushDebug ("Found", 
string.Format ("name={2}, vendor={0}, prod={1}", cam.Vendor, cam.Product, 
cam.Name));
-                               
-                               LogCore.Instance.PushDebug ("Connection 
failed", "We can only handle 1 connected mtp device at a time.");
-                               return Banshee.Dap.InitializeResult.Invalid;
-                       }
-                       camera = cameras[0];
-                       LogCore.Instance.PushDebug ("MTP: device found", 
String.Format ("vendor={0}, prod={1}", vendor_id, product_id));
 
-                       base.Initialize (halDevice);
+            bool device_found = false;
+
+            if (devices == null || devices.Count == 0) {
+                               LogCore.Instance.PushError (
+                    Catalog.GetString ("Error Finding MTP Device Support"),
+                    Catalog.GetString ("An MTP device was detected, but 
Banshee was unable to load support for it.")
+                );
+            } else {
+                string mtp_serial = devices[0].SerialNumber;
+                if (!String.IsNullOrEmpty (mtp_serial) && 
!String.IsNullOrEmpty (serial)) {
+                    if (mtp_serial.StartsWith (serial)) {
+                        device_found = true;
+                        device = devices[0];
+                    }
+                }
+
+                if (!device_found) {
+                    LogCore.Instance.PushInformation(
+                        Catalog.GetString ("MTP Support Ignoring Device"),
+                        Catalog.GetString ("Banshee's MTP audio player support 
can only handle one device at a time."),
+                        true
+                    );
+                }
+            }
+
+            if (!device_found) {
+                return InitializeResult.Invalid;
+            }
+
+                       LogCore.Instance.PushDebug ("Loading MTP Device",
+                String.Format ("Name: {0}, ProductID: {1}, VendorID: {2}, 
Serial: {3}",
+                    hal_name, product_id, vendor_id, serial
+                )
+            );
+
+                       base.Initialize (hal_device);
                        
-                       InstallProperty ("Model", camera.Name);
-                       InstallProperty ("Vendor", halDevice["usb.vendor"]);
-                       InstallProperty ("Serial Number", 
halDevice["usb.serial"]);
-                       ThreadAssist.Spawn (InitializeBackgroundThread);
+                       InstallProperty ("Vendor", hal_device["usb.vendor"]);
+                       InstallProperty ("Model", hal_name);
+                       InstallProperty ("Version", device.Version);
+                       InstallProperty ("Serial Number", serial);
+
+            // Don't continue until the UI is initialized
+            if(!Globals.UIManager.IsInitialized) {
+                Globals.UIManager.Initialized += OnUIManagerInitialized;
+            } else {
+                Reload ();
+            }
 
                        CanCancelSave = false;
                        return InitializeResult.Valid;
                }
 
-               public void InitializeBackgroundThread ()
+        private void OnUIManagerInitialized (object o, EventArgs args)
+        {
+            Globals.UIManager.Initialized -= OnUIManagerInitialized;
+            Reload ();
+        }
+
+        private bool ejecting;
+               public override void Eject ()
                {
-                       ActiveUserEvent userEvent = new ActiveUserEvent ("MTP 
Initialization");
-                       try {
-                               userEvent.CanCancel = true;
-                               userEvent.Header = Catalog.GetString 
(string.Format ("{0}: Found", camera.Name));
-                               userEvent.Message = Catalog.GetString 
("Connecting...");
-                               try {
-                                       ReloadDatabase (userEvent);
-                               } catch (Exception e) {
-                                       ShowGeneralExceptionDialog (e);
-                                       Dispose ();
-                                       return;
-                               }
-                       } finally {
-                               GLib.Timeout.Add (4000, delegate {
-                                       userEvent.Dispose ();
-                                       return false;
-                               });
-                       }
+            if (ejecting)
+                return;
+            ejecting = true;
+            // TODO this isn't needed atm since we don't support playback 
directly off MTP devices
+            UnmapPlayback(typeof(MtpDapTrackInfo));
+            Dispose ();
+                       base.Eject ();
+            ejecting = false;
                }
 
                public override void Dispose ()
         {
-                       camera.Dispose ();
+                       device.Dispose ();
                        base.Dispose ();
+            mtp_dap = null;
                }
                
                private void OnMetadataChanged (object sender, EventArgs e)
@@ -192,70 +207,56 @@
                                metadataChangedQueue.Add (info);
                }
                
-               private void ReloadDatabase (bool reconnect)
+               protected override void Reload ()
                {
-                       ActiveUserEvent userEvent = new ActiveUserEvent ("MTP 
Initialization");
+                       // Clear the list of tracks that banshee keeps
+            lock (Source.TracksMutex) {
+                ClearTracks (false);
+            }
+
+                       ActiveUserEvent user_event = new ActiveUserEvent (
+                String.Format (Catalog.GetString ("Loading {0}"), Name)
+            );
+
                        try {
-                               ReloadDatabase (userEvent);
+                List<Track> files = device.GetAllTracks (delegate (ulong 
current, ulong total, IntPtr data) {
+                    user_event.Progress = (double)current / total;
+                    return user_event.IsCancelRequested ? 1 : 0;
+                });
+                
+                if (user_event.IsCancelRequested) {
+                    return;
+                }
+                
+                all_tracks = new List<MtpDapTrackInfo> (files.Count + 50);
+                foreach (Track f in files) {
+                    MtpDapTrackInfo track = new MtpDapTrackInfo (device, f);
+                    track.Changed += OnMetadataChanged;
+                    AddTrack (track);
+                    all_tracks.Add (track);
+                }
                        } finally {
-                               GLib.Timeout.Add (4000, delegate {
-                                       userEvent.Dispose ();
-                                       return false;
-                               });
+                user_event.Dispose ();
                        }
                }
                
-               // FIXME: Try/catch this entire block?
-               private void ReloadDatabase (ActiveUserEvent userEvent)
-               {
-                       double startTime = Environment.TickCount;
-                       
-                       // Clear the list of tracks that banshee keeps
-                       ClearTracks (false);
-                               
-                       
-                       userEvent.Message = string.Format (Catalog.GetString 
("Loading database..."));
-                       
-                       List<Track> files = camera.GetAllTracks (delegate 
(ulong current, ulong total, IntPtr data) {
-                               userEvent.Progress = (double)current / total;
-                               return userEvent.IsCancelRequested ? 1 : 0;
-                       });
-                       
-                       if (userEvent.IsCancelRequested) {
-                               userEvent.Message = Catalog.GetString 
("Cancelled...");
-                               return;
-                       }
-                       
-                       allTracks = new List<MtpDapTrackInfo> (files.Count + 
50);
-                       foreach (Track f in files) {
-                               MtpDapTrackInfo track = new MtpDapTrackInfo 
(camera, f);
-                               track.Changed += new EventHandler 
(OnMetadataChanged);
-                               AddTrack (track);
-                               allTracks.Add (track);
-                       }
-                       
-                       startTime = (Environment.TickCount - startTime) / 
1000.0;
-                       userEvent.Message = string.Format (Catalog.GetString 
("Loaded {0} files in {1:0.00}sec"), this.tracks.Count, startTime);
-                       userEvent.Header = Catalog.GetString (string.Format 
("{0}: Ready", camera.Name));
-               }
-               
                protected override void OnTrackRemoved (TrackInfo track)
                {
                        base.OnTrackRemoved (track);
                        
                        MtpDapTrackInfo t = track as MtpDapTrackInfo;
-                       if (IsReadOnly || t == null || !t.OnCamera (camera)) {
+                       if (IsReadOnly || t == null || !t.OnCamera (device)) {
                                return;
             }
 
-                       // This means we have write access and the file is on 
the camera.
+                       // This means we have write access and the file is on 
the device.
                        removeQueue.Enqueue ((MtpDapTrackInfo) track);
                }
                
                public override void AddTrack (TrackInfo track)
                {
                        //FIXME: DO i need to check if i already have the track 
in the list?
-                       //if ((mtpTrack != null && mtpTrack.OnCamera (camera)))
+                       //if ((mtpTrack != null && mtpTrack.OnCamera (device)))
                        //      return;
                        
                        base.AddTrack (track);
@@ -312,24 +313,24 @@
                        int count = removeQueue.Count;
                        while (removeQueue.Count > 0) {
                                MtpDapTrackInfo track = removeQueue.Dequeue ();
-                               string message = string.Format ("Removing 
{0}/{1}: {2} - {3}", count - removeQueue.Count,
-                                                              count, 
track.Artist, track.Title);
-                               UpdateSaveProgress ("Synchronising...", 
message, ((double) count - removeQueue.Count) / count);
+                               string message = string.Format ("Removing: {0} 
- {1}", track.DisplayArtist, track.DisplayTitle);
                                
-                               // Quick check to see if the track is on this 
camera - possibly needed in
+                               // Quick check to see if the track is on this 
device - possibly needed in
                                // case we have multiple MTP devices connected 
simultaenously
-                               if (!track.OnCamera (camera)) {
+                               if (!track.OnCamera (device)) {
                                        continue;
                 }
                                
-                               camera.Remove (track.OriginalFile);
-                               allTracks.Remove (track);
+                               device.Remove (track.OriginalFile);
+                               all_tracks.Remove (track);
                                
                                if (metadataChangedQueue.Contains (track)) {
                                        metadataChangedQueue.Remove (track);
                 }
                                
-                               track.Changed -= new EventHandler 
(OnMetadataChanged);
+                               track.Changed -= OnMetadataChanged;
+
+                               UpdateSaveProgress (sync_title, message, 
((double) count - removeQueue.Count) / count);
                                
                                // Optimisation - Delete the folder if it's 
empty
                        }
@@ -353,16 +354,17 @@
                                FileInfo info = new FileInfo 
(tracks[i].Uri.AbsolutePath);
                                Track f = ToMusicFile (tracks[i], info.Name, 
(ulong)info.Length);
                                
-                               string message = string.Format ("Adding 
{0}/{1}: {2} - {3}",
-                                                              i + 1, 
tracks.Count, f.Artist, f.Title);
-                               UpdateSaveProgress ("Synchronising...", 
message, (double) (i + 1) / tracks.Count);
-                               camera.UploadTrack (tracks[i].Uri.AbsolutePath, 
f);
+                               string message = string.Format (
+                    "Adding: {0} - {1}", f.Artist, f.Title
+                );
+                               device.UploadTrack (tracks[i].Uri.AbsolutePath, 
f);
                                
                                // Create an MtpDapTrackInfo for the new file 
and add it to our lists
-                               MtpDapTrackInfo newTrackInfo = new 
MtpDapTrackInfo (camera, f);
-                               newTrackInfo.Changed += new EventHandler 
(OnMetadataChanged);
+                               MtpDapTrackInfo newTrackInfo = new 
MtpDapTrackInfo (device, f);
+                               newTrackInfo.Changed += OnMetadataChanged;
                                
-                               allTracks.Add (newTrackInfo);
+                               UpdateSaveProgress (sync_title, message, 
(double) (i + 1) / tracks.Count);
+                               all_tracks.Add (newTrackInfo);
                                AddTrack (newTrackInfo);
                        }
                }
@@ -391,11 +393,13 @@
                        }
                }
                
+        private string sync_title;
                public override void Synchronize ()
                {
                        // 1. remove everything in the remove queue if it's on 
the device
                        // 2. Add everything in the tracklist that isn't on the 
device
                        // 3. Sync playlists?
+                   sync_title = String.Format ("Synchronizing {0}", Name);
                        try {
                                RemoveTracks ();
                                UpdateMetadata ();
@@ -405,8 +409,8 @@
                        } finally {
                                ClearTracks (false);
 
-                               for (int i = 0; i < allTracks.Count; i++) {
-                                       AddTrack (allTracks[i]);
+                               for (int i = 0; i < all_tracks.Count; i++) {
+                                       AddTrack (all_tracks[i]);
                 }
 
                                FinishSave ();
@@ -415,10 +419,7 @@
                                
                private void ShowGeneralExceptionDialog (Exception ex)
                {
-                       string message = "There was an error using the device. 
Read http://www.banshee-project.org/Guide/DAPs/MTP for more information. ";
-                       message += (Environment.NewLine + Environment.NewLine);
-                       message += ex.ToString ();
-                       LogCore.Instance.PushError ("Device error", message);
+                       LogCore.Instance.PushError (Catalog.GetString ("MTP 
Device Error"), ex.ToString ());
                }
 
                public void Import (IEnumerable<TrackInfo> tracks, 
PlaylistSource playlist) 
@@ -449,8 +450,8 @@
                                        LogCore.Instance.PushDebug ("Not MTP 
track", "Tried to import a non-mtp track");
                 }
                                
-                               if (! ((MtpDapTrackInfo) track).OnCamera 
(this.camera)) {
-                                       LogCore.Instance.PushDebug ("Track not 
on this device", "The track to import did not come from this camera");
+                               if (! ((MtpDapTrackInfo) track).OnCamera 
(this.device)) {
+                                       LogCore.Instance.PushDebug ("Track not 
on this device", "The track to import did not come from this device");
                 }
                                
                                importer.Enqueue (track);
@@ -475,7 +476,7 @@
                        }
                        
                        importer.UserEvent.Progress = importer.ProcessedCount / 
(double)importer.TotalCount;
-                       importer.UserEvent.Message = string.Format ("{0}/{1}: 
{2} - {3}", importer.ProcessedCount, importer.TotalCount, track.Artist, 
track.Title);
+                       importer.UserEvent.Message = string.Format ("{0}/{1}: 
{2} - {3}", importer.ProcessedCount, importer.TotalCount, track.DisplayArtist, 
track.DisplayTitle);
                        
                        // This is the path where the file will be saved on-disk
                        string destination = FileNamePattern.BuildFull (track, 
Path.GetExtension (track.OriginalFile.Filename));
@@ -493,7 +494,7 @@
                                                }
                                                LogCore.Instance.PushDebug 
("Import warning", String.Format (
                             "Track {0} - {1} - {2} already exists in the 
library",
-                                                   track.Artist, track.Album, 
track.Title
+                                                   track.DisplayArtist, 
track.DisplayAlbum, track.DisplayTitle
                         ));
                                                return;
                                        }
@@ -523,15 +524,15 @@
                        }
                }
                
-               public void Import (IEnumerable<TrackInfo> tracks) {
+               public void Import (IEnumerable<TrackInfo> tracks)
+        {
                        Import (tracks, null);
                }
 
-               public override Gdk.Pixbuf GetIcon (int size) {
-                       string prefix = "multimedia-player-";
-                       string id = "dell-pocket-dj";
-                       Gdk.Pixbuf icon = IconThemeUtils.LoadIcon (prefix + id, 
size);
-                       return icon == null ? base.GetIcon (size) : icon;
+        string icon_name = "multimedia-player-dell-pocket-dj";
+               public override Gdk.Pixbuf GetIcon (int size)
+        {
+            return IconThemeUtils.HasIcon (icon_name) ? 
IconThemeUtils.LoadIcon (icon_name, size) : base.GetIcon (size);
                }
 /*
                public DapPlaylistSource AddPlaylist (Source playlist)
@@ -550,27 +551,35 @@
                        return (DapPlaylistSource) ips;
                }
 */
+
+        public override void SetName(string name)
+        {
+            if (device != null) {
+                device.Name = name;
+            }
+        }
+
+               public override bool CanSynchronize {
+                       get { return true; }
+               }
+
                public override string Name {
                        get {
-                               if (camera == null) {
-                                       return String.Empty;
+                               if (device == null) {
+                    return hal_name;
                 }
                                
-                               return camera.Name;
+                               return device.Name;
                        }
                }
 
-               public override string GenericName {
-                       get { return Name; }
-               }
-
                public override ulong StorageCapacity {
                        get {
-                               if (camera == null)
+                               if (device == null)
                                        return 0;
                                
                                ulong count = 0;
-                               foreach (DeviceStorage s in camera.GetStorage 
()) {
+                               foreach (DeviceStorage s in device.GetStorage 
()) {
                                        count += s.MaxCapacity;
                 }
                                return count;
@@ -579,10 +588,10 @@
 
                public override ulong StorageUsed {
                        get {
-                               if (camera == null)
+                               if (device == null)
                                        return 0;
                                ulong count = 0;
-                               foreach (DeviceStorage s in 
this.camera.GetStorage ()) {
+                               foreach (DeviceStorage s in device.GetStorage 
()) {
                                        count += s.MaxCapacity - s.FreeSpace;
                 }
                                return count;

Modified: branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs
==============================================================================
--- branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs  
(original)
+++ branches/banshee/stable/src/Dap/Banshee.Dap.Mtp/MtpDapTrackInfo.cs  Tue Jan 
29 22:57:41 2008
@@ -60,9 +60,11 @@
             title = file.Title;
             track_number = file.TrackNumber < 0 ? (uint)0 : file.TrackNumber;
             year = (file.Date != null && file.Date.Length >= 4) ? 
int.Parse(file.Date.Substring(0, 4)) : 0;
-            can_play = false;             // This can be implemented if 
there's enough people requesting it
-            can_save_to_database = true;
+
+            CanPlay = false;             // This can be implemented if there's 
enough people requesting it
+            CanSaveToDatabase = true;
             NeedSync = false;
+
                        // Set a URI even though it's not actually accessible 
through normal API's.
                        uri = new SafeUri("mtp://invalid");
         }
_______________________________________________
SVN-commits-list mailing list (read only)
http://mail.gnome.org/mailman/listinfo/svn-commits-list

Want to limit the commits to a few modules? Go to above URL, log in to edit 
your options and select the modules ('topics') you want.
Module maintainer? It is possible to set the reply-to to your development 
mailing list. Email [EMAIL PROTECTED] if interested.

Reply via email to