hipo r170 - in trunk: . src



Author: bgarret
Date: Fri Mar 14 21:59:21 2008
New Revision: 170
URL: http://svn.gnome.org/viewvc/hipo?rev=170&view=rev

Log:
2008-03-14  Benoit Garret  <benoit garret_gnome gadz org>

        * src/DeviceSource.cs:
        * src/EditableCellRenderer.cs:
        * src/HipoMain.cs:
        * src/HipoMainWindow.cs:
        * src/ImportDialog.cs:
        * src/PlaylistSource.cs:
        * src/Saviour.cs:
        * src/Source.cs:
        * src/SourceList.cs:
        * src/Tools.cs:
        * src/TracksContainer.cs:
        * src/TracksSource.cs:

        More logging.



Modified:
   trunk/ChangeLog
   trunk/src/DeviceSource.cs
   trunk/src/EditableCellRenderer.cs
   trunk/src/HipoMain.cs
   trunk/src/HipoMainWindow.cs
   trunk/src/ImportDialog.cs
   trunk/src/PlaylistSource.cs
   trunk/src/Saviour.cs
   trunk/src/Source.cs
   trunk/src/SourceList.cs
   trunk/src/Tools.cs
   trunk/src/TracksContainer.cs
   trunk/src/TracksSource.cs

Modified: trunk/src/DeviceSource.cs
==============================================================================
--- trunk/src/DeviceSource.cs	(original)
+++ trunk/src/DeviceSource.cs	Fri Mar 14 21:59:21 2008
@@ -43,6 +43,8 @@
 		
 		public DeviceSource (Device device)
 		{
+			Tools.Log (this, 1, "Creating device source for {0}", device.Name);
+			
 			this.device = device;
 			
 			this.Type = SourceType.Device;
@@ -139,6 +141,8 @@
 				this.Name = entry.Text;
 			}
 			
+			Tools.Log (this, 3, "Device renamed to {0}", this.Name);
+			
 			dialog.Destroy ();
 		}
 	}

Modified: trunk/src/EditableCellRenderer.cs
==============================================================================
--- trunk/src/EditableCellRenderer.cs	(original)
+++ trunk/src/EditableCellRenderer.cs	Fri Mar 14 21:59:21 2008
@@ -23,7 +23,8 @@
 
 namespace Hipo
 {
-	public enum Column {
+	public enum Column
+	{
 		Icon,
 		Name,
 		Count,

Modified: trunk/src/HipoMain.cs
==============================================================================
--- trunk/src/HipoMain.cs	(original)
+++ trunk/src/HipoMain.cs	Fri Mar 14 21:59:21 2008
@@ -44,8 +44,6 @@
 			string stack = GetStackTrace (e);
 			string msg = GetMessage (e);
 			
-			Tools.Log (this, "Uh oh, something went wrong...");
-			
 			Gtk.Application.Invoke (delegate (object o, EventArgs args) {
 				
 				Glade.XML gxml = new Glade.XML ("errordialog.glade", "errorDialog");

Modified: trunk/src/HipoMainWindow.cs
==============================================================================
--- trunk/src/HipoMainWindow.cs	(original)
+++ trunk/src/HipoMainWindow.cs	Fri Mar 14 21:59:21 2008
@@ -51,11 +51,12 @@
 		public HipoMainWindow (string[] args)
 		{
 			// disable logging
-			Tools.LogEnabled = false;
+			Tools.LogLevel = 3;
 			
 			program = new Gnome.Program (Defines.PACKAGE, Defines.VERSION, Gnome.Modules.UI, args);
 			
 			// create the device combo and hook up device changed event
+			Tools.Log (this, 1, "Creating the DeviceCombo");
 			combo = new DeviceCombo ();
 			combo.Changed += OnDeviceChanged;
 			
@@ -76,72 +77,72 @@
 			ActionEntry[] entries =  {
 
 				new ActionEntry ("FileMenu",
-				                 null,
-				                 Catalog.GetString ("_File"),
-				                 null,
-				                 null,
-				                 null),
+									  null,
+									  Catalog.GetString ("_File"),
+									  null,
+									  null,
+									  null),
 				new ActionEntry ("AddFile",
-				                 Stock.Add, Catalog.GetString ("_Add File..."),
-				                 null,
-				                 Catalog.GetString ("Add a file to your iPod"),
-				                 OnAddActivated),
+									  Stock.Add, Catalog.GetString ("_Add File..."),
+									  null,
+									  Catalog.GetString ("Add a file to your iPod"),
+									  OnAddActivated),
 				new ActionEntry ("AddFolder",
-				                 Stock.Add,
-				                 Catalog.GetString ("A_dd Folder..."),
-				                 "<control>O",
-				                 Catalog.GetString ("Add a folder to your iPod"),
-				                 OnAddFolder),
+									  Stock.Add,
+									  Catalog.GetString ("A_dd Folder..."),
+									  "<control>O",
+									  Catalog.GetString ("Add a folder to your iPod"),
+									  OnAddFolder),
 				new ActionEntry ("NewPlaylist",
-				                 Stock.New,
-				                 Catalog.GetString ("New Playlist"),
-				                 null,
-				                 Catalog.GetString ("Create a new Playlist"),
-				                 OnNewPlaylist),
+									  Stock.New,
+									  Catalog.GetString ("New Playlist"),
+									  null,
+									  Catalog.GetString ("Create a new Playlist"),
+									  OnNewPlaylist),
 				new ActionEntry ("Eject",
-				                 null,
-				                 Catalog.GetString ("_Eject"),
-				                 null,
-				                 null,
-				                 OnEjectActivated),
+									  null,
+									  Catalog.GetString ("_Eject"),
+									  null,
+									  null,
+									  OnEjectActivated),
 				new ActionEntry ("Quit",
-				                 Stock.Quit,
-				                 null,
-				                 "<control>Q",
-				                 null,
-				                 OnQuitActivated),
+									  Stock.Quit,
+									  null,
+									  "<control>Q",
+									  null,
+									  OnQuitActivated),
 				
 				new ActionEntry ("EditMenu",
-				                 null,
-				                 Catalog.GetString ("_Edit"),
-				                 null,
-				                 null,
-				                 null),
+									  null,
+									  Catalog.GetString ("_Edit"),
+									  null,
+									  null,
+									  null),
 				new ActionEntry ("Preferences",
-				                 Stock.Preferences,
-				                 null,
-				                 null,
-				                 null,
-				                 OnPreferences),
+									  Stock.Preferences,
+									  null,
+									  null,
+									  null,
+									  OnPreferences),
 				
 				new ActionEntry ("HelpMenu",
-				                 null,
-				                 Catalog.GetString ("_Help"),
-				                 null,
-				                 null,
-				                 null),
+									  null,
+									  Catalog.GetString ("_Help"),
+									  null,
+									  null,
+									  null),
 				new ActionEntry ("Help",
-				                 Stock.Help,
-				                 null,
-				                 "F1",
-				                 null,
-				                 OnHelp),
+									  Stock.Help,
+									  null,
+									  "F1",
+									  null,
+									  OnHelp),
 				new ActionEntry ("About",
-				                 Gnome.Stock.About,
-				                 null,
-				                 null,
-				                 null,
-				                 OnAboutActivated)
+									  Gnome.Stock.About,
+									  null,
+									  null,
+									  null,
+									  OnAboutActivated)
 			};
 			
 			// create the ui manager and the keyboard shortcuts
@@ -177,7 +178,7 @@
 			// hook up the selection changed source list event
 			sourceList.SelectionChanged += OnSourceListSelectionChanged;			
 			
-			Tools.Log (this, "Finished creating the window");
+			Tools.Log (this, 3, "Finished creating the window");
 			
 			hipoWindow.ShowAll ();
 			
@@ -207,7 +208,7 @@
 				sourceList.SelectedSource = null;
 				sourceList.Clear ();
 				
-				Tools.Log (this, "No device set");
+				Tools.Log (this, 3, "No device set");
 				
 				return;
 			}
@@ -237,7 +238,7 @@
 			
 			sourceList.ExpandAll ();
 			
-			Tools.Log (this, "Set device {0}", device.Name);
+			Tools.Log (this, 3, "Set device {0}", device.Name);
 		}
 		
 		private void SetDevice ()
@@ -299,10 +300,10 @@
 			string[] uris;
 			
 			FileChooserDialog fileChooser = new FileChooserDialog (Catalog.GetString ("Select a folder to add"),
-			                                                       hipoWindow,
-			                                                       FileChooserAction.SelectFolder,
-			                                                       Stock.Cancel, ResponseType.Cancel,
-			                                                       Stock.Add, ResponseType.Accept);
+																					 hipoWindow,
+																					 FileChooserAction.SelectFolder,
+																					 Stock.Cancel, ResponseType.Cancel,
+																					 Stock.Add, ResponseType.Accept);
 			
 			fileChooser.LocalOnly = true;
 			
@@ -323,9 +324,9 @@
 			Entry entry = new Entry ();
 			
 			Dialog dialog = new Dialog (Catalog.GetString ("New Playlist"), this.hipoWindow,
-			                            DialogFlags.DestroyWithParent,
-			                            Stock.Cancel, ResponseType.Cancel,
-			                            Stock.Ok, ResponseType.Accept);
+												 DialogFlags.DestroyWithParent,
+												 Stock.Cancel, ResponseType.Cancel,
+												 Stock.Ok, ResponseType.Accept);
 
 			hbox.BorderWidth = 5;
 			hbox.Add (name);
@@ -392,7 +393,7 @@
 									 MessageType.Error,
 									 ButtonsType.Close,
 									 Catalog.GetString ("There was an error ejecting the iPod:")
-				                                         );
+																	  );
 				
 				error.SecondaryText = e.Message;
 				
@@ -416,23 +417,23 @@
 		{
 			try {
 				Gnome.Help.DisplayDesktopOnScreen (
-				              Gnome.Program.Get (),
-				              Defines.GNOME_HELP_DIR,
-				              filename,
-				              link_id,
-				              screen);
+								  Gnome.Program.Get (),
+								  Defines.GNOME_HELP_DIR,
+								  filename,
+								  link_id,
+								  screen);
 			} catch {
 				string message =
 					Catalog.GetString ("The \"Hipo Manual\" could " +
-					                   "not be found.  Please verify " +
-					                   "that your installation has been " +
-					                   "completed successfully.");
+											 "not be found.  Please verify " +
+											 "that your installation has been " +
+											 "completed successfully.");
 				MessageDialog dialog = new MessageDialog (parent,
-				                                          DialogFlags.DestroyWithParent,
-				                                          MessageType.Error,
-				                                          ButtonsType.Ok,
-				                                          Catalog.GetString ("Help not found"),
-				                                          message);
+																		DialogFlags.DestroyWithParent,
+																		MessageType.Error,
+																		ButtonsType.Ok,
+																		Catalog.GetString ("Help not found"),
+																		message);
 				dialog.Run ();
 				dialog.Destroy ();
 			}
@@ -442,13 +443,13 @@
 		{
 			AboutDialog aboutDialog = new AboutDialog ();
 			string[] authors = { "Pedro Villavicencio Garrido <pvillavi gnome org>",
-				                 "Felipe Barros S. <felipeb gnome cl>",
-				                 "Benoit Garret <benoit garret_gnome gadz org>" };
+									  "Felipe Barros S. <felipeb gnome cl>",
+									  "Benoit Garret <benoit garret_gnome gadz org>" };
 			string[] artists = { "Carlos Candia Flores <cerealk vtr net>",
-				                 "Gabriel Bustos Farret  <lemut lemut com>"	};
+									  "Gabriel Bustos Farret  <lemut lemut com>"	};
 			
 			string[] documenters = { "Gabriel Felipe Cornejo Salas <gfc gnome cl>",
-				                     "Basilio Kublik <basilio gnome cl>" };
+											"Basilio Kublik <basilio gnome cl>" };
 			
 			aboutDialog.Authors = authors;
 			aboutDialog.Copyright = "Copyright  2006-2007 Pedro Villavicencio Garrido";

Modified: trunk/src/ImportDialog.cs
==============================================================================
--- trunk/src/ImportDialog.cs	(original)
+++ trunk/src/ImportDialog.cs	Fri Mar 14 21:59:21 2008
@@ -11,120 +11,134 @@
 using GLib;
 using IPod;
 
-namespace Hipo {
-
-    public class ImportDialog : Dialog {
-
-        private TrackDatabase db;
-        private Label label;
-        private ProgressBar bar;
-        private ThreadNotify notify;
-
-        private bool visible;
-        private double fraction;
-        private string message;
-        
-        public TrackDatabase TrackDatabase {
-            get { return db; }
-            set {
-                if (db != null) {
-                    // disconnect
-                    db.SaveStarted -= OnSaveStarted;
-                    db.SaveProgressChanged -= OnSaveProgressChanged;
-                    db.SaveEnded -= OnSaveEnded;
-                }
-                
-                db = value;
-
-                if (db != null) {
-                    // connect
-                    db.SaveStarted += OnSaveStarted;
-                    db.SaveProgressChanged += OnSaveProgressChanged;
-                    db.SaveEnded += OnSaveEnded;
-                }
-            }
-        }
-        
-        public ImportDialog (Window parent) : base () {
-            this.Title = Catalog.GetString ("Updating iPod...");
-            this.HasSeparator = false;
-            this.TransientFor = parent;
-            this.DefaultWidth = 400;
-            
-            VBox vbox = new VBox (false, 6);
-            vbox.BorderWidth = 6;
-
-            HBox hbox = new HBox (false, 6);
-
-            Gdk.PixbufAnimation animation = new Gdk.PixbufAnimation (null, "ipod.gif");
-            hbox.PackStart (new Gtk.Image (animation), false, false, 0);
-
-            label = new Label ("");
-            label.Xalign = 0.0f;
-            label.UseMarkup = true;
-
-            SetEllipsize (label);
-            hbox.PackStart (label, true, true, 0);
-
-            vbox.PackStart (hbox, true, false, 0);
-
-            bar = new ProgressBar ();
-            vbox.PackStart (bar, true, false, 0);
-
-            VBox.PackStart (vbox, false, false, 0);
-            VBox.ShowAll ();
-
-            notify = new ThreadNotify (new ReadyEvent (OnNotify));
-        }
-
-        private void SetEllipsize (Label label) {
-            MethodInfo method = typeof (GLib.Object).GetMethod ("SetProperty",
-                                                                BindingFlags.Instance | BindingFlags.NonPublic);
-            method.Invoke (label, new object[] { "ellipsize", new GLib.Value (3) });
-        }
-
-        private void OnSaveStarted (object o, EventArgs args) {
-            visible = true;
-            message = Catalog.GetString ("<b>Preparing...</b>");
-            notify.WakeupMain ();
-        }
-
-        private void OnSaveProgressChanged (object o, TrackSaveProgressArgs args) {
-            lock (this) {
-                if (args.CurrentTrack != null) {
-		    /* number of tracks to add */
-                    string padstr = String.Format (Catalog.GetString ("Adding {0} of {0}"), args.TracksTotal);
-                    /* the number of tracks completed and the total of tracks */
-                    message = String.Format (Catalog.GetString ("Adding {0} of {1}"), args.TracksCompleted + 1, args.TracksTotal);
-                    message = message.PadLeft (padstr.Length);
-                    
-                    message = String.Format ("<b>{0}: {1}</b>", message, GLib.Markup.EscapeText (args.CurrentTrack.Title));
-                } else {
-                    message = String.Format (Catalog.GetString ("<b>Finishing...</b>"));
-                }
-
-                fraction = args.TotalProgress;
-                
-                notify.WakeupMain ();
-            }
-        }
-
-        private void OnSaveEnded (object o, EventArgs args) {
-            visible = false;
-            notify.WakeupMain ();
-        }
-
-        private void OnNotify () {
-            lock (this) {
-                if (this.visible && !Visible)
-                    Show ();
-                else if (!this.visible && Visible)
-                    Hide ();
-                
-                label.Markup = message;
-                bar.Fraction = fraction;
-            }
-        }
-    }
+namespace Hipo
+{
+	
+	public class ImportDialog : Dialog
+	{
+		private TrackDatabase db;
+		private Label label;
+		private ProgressBar bar;
+		private ThreadNotify notify;
+		
+		private bool visible;
+		private double fraction;
+		private string message;
+		
+		public TrackDatabase TrackDatabase
+		{
+			get { return db; }
+			set {
+				if (db != null) {
+					// disconnect
+					db.SaveStarted -= OnSaveStarted;
+					db.SaveProgressChanged -= OnSaveProgressChanged;
+					db.SaveEnded -= OnSaveEnded;
+				}
+				
+				db = value;
+				
+				if (db != null) {
+					// connect
+					db.SaveStarted += OnSaveStarted;
+					db.SaveProgressChanged += OnSaveProgressChanged;
+					db.SaveEnded += OnSaveEnded;
+				}
+			}
+		}
+		
+		public ImportDialog (Window parent) : base ()
+		{
+			Tools.Log (this, 3, "Creating the ImportDialog");
+			
+			this.Title = Catalog.GetString ("Updating iPod...");
+			this.HasSeparator = false;
+			this.TransientFor = parent;
+			this.DefaultWidth = 400;
+			
+			VBox vbox = new VBox (false, 6);
+			vbox.BorderWidth = 6;
+			
+			HBox hbox = new HBox (false, 6);
+			
+			Gdk.PixbufAnimation animation = new Gdk.PixbufAnimation (null, "ipod.gif");
+			hbox.PackStart (new Gtk.Image (animation), false, false, 0);
+			
+			label = new Label ("");
+			label.Xalign = 0.0f;
+			label.UseMarkup = true;
+			
+			SetEllipsize (label);
+			hbox.PackStart (label, true, true, 0);
+			
+			vbox.PackStart (hbox, true, false, 0);
+			
+			bar = new ProgressBar ();
+			vbox.PackStart (bar, true, false, 0);
+			
+			VBox.PackStart (vbox, false, false, 0);
+			VBox.ShowAll ();
+			
+			notify = new ThreadNotify (new ReadyEvent (OnNotify));
+		}
+		
+		private void SetEllipsize (Label label)
+		{
+			MethodInfo method = typeof (GLib.Object).GetMethod ("SetProperty",
+			                                                    BindingFlags.Instance | BindingFlags.NonPublic);
+			method.Invoke (label, new object[] { "ellipsize", new GLib.Value (3) });
+		}
+		
+		private void OnSaveStarted (object o, EventArgs args)
+		{
+			visible = true;
+			message = Catalog.GetString ("<b>Preparing...</b>");
+			notify.WakeupMain ();
+		}
+		
+		private void OnSaveProgressChanged (object o, TrackSaveProgressArgs args)
+		{
+			lock (this)
+			{
+				if (args.CurrentTrack != null)
+				{
+					/* number of tracks to add */
+					string padstr = String.Format (Catalog.GetString ("Adding {0} of {0}"), args.TracksTotal);
+					/* the number of tracks completed and the total of tracks */
+					message = String.Format (Catalog.GetString ("Adding {0} of {1}"), args.TracksCompleted + 1, args.TracksTotal);
+					message = message.PadLeft (padstr.Length);
+					
+					message = String.Format ("<b>{0}: {1}</b>", message, GLib.Markup.EscapeText (args.CurrentTrack.Title));
+				}
+				else
+				{
+					message = String.Format (Catalog.GetString ("<b>Finishing...</b>"));
+				}
+				
+				fraction = args.TotalProgress;
+				
+				notify.WakeupMain ();
+			}
+		}
+		
+		private void OnSaveEnded (object o, EventArgs args)
+		{
+			visible = false;
+			notify.WakeupMain ();
+		}
+		
+		private void OnNotify ()
+		{
+			lock (this)
+			{
+				if (this.visible && !Visible)
+					Show ();
+				else if (!this.visible && Visible)
+					Hide ();
+				
+				label.Markup = message;
+				bar.Fraction = fraction;
+			}
+		}
+	}
 }
-

Modified: trunk/src/PlaylistSource.cs
==============================================================================
--- trunk/src/PlaylistSource.cs	(original)
+++ trunk/src/PlaylistSource.cs	Fri Mar 14 21:59:21 2008
@@ -33,6 +33,8 @@
 		
 		public PlaylistSource (Playlist playlist) : base ()
 		{
+			Tools.Log (this, 1, "Creating playlist source for {0}", playlist.Name);
+			
 			this.playlist = playlist;
 			Tracks = playlist.Tracks;
 			
@@ -99,6 +101,7 @@
 		
 		public void AddTrack (Track track)
 		{
+			Tools.Log (this, 3, "Adding track {0} to the playlist {1}", track.Title, playlist.Name);
 			AddTrack (track, true);
 		}
 		
@@ -120,6 +123,8 @@
 		// Adds the tracks to the database, then to the playlist
 		public override bool AddTracks (string[] uris, bool save)
 		{
+			Tools.Log (this, 2, "Adding {0} tracks to the playlist {1}", uris.Length, playlist.Name);
+			
 			bool trackAdded = false;
 			
 			foreach (string uri in uris)
@@ -187,12 +192,13 @@
 		
 		public void RemoveTrack (Track track)
 		{
+			Tools.Log (this, 3, "Removing track {0} from the playlist {1}", track.Title, playlist.Name);
 			RemoveTrack (track, true);
 		}
 		
 		public override void RemoveTracks (List<Track> tracks)
 		{
-			Tools.Log (this, "Removing {0} tracks from the playlist {1}", tracks.Count, playlist.Name);
+			Tools.Log (this, 2, "Removing {0} tracks from the playlist {1}", tracks.Count, playlist.Name);
 			
 			foreach (Track track in tracks)
 			{
@@ -212,7 +218,7 @@
 		
 		protected override void AddEventHandlers ()
 		{
-			Tools.Log (this, "Hooking {0} source menu event handlers", this.Name);
+			Tools.Log (this, 3, "Hooking {0} source menu event handlers", this.Name);
 			
 			Menu menu = (Menu)UIManager.Instance.GetWidget ("/ui/PlaylistPopup");
 			
@@ -235,7 +241,7 @@
 		
 		protected override void RemoveEventHandlers ()
 		{
-			Tools.Log (this, "Unhooking {0} source menu event handlers", this.Name);
+			Tools.Log (this, 3, "Unhooking {0} source menu event handlers", this.Name);
 			
 			Menu menu = (Menu)UIManager.Instance.GetWidget ("/ui/PlaylistPopup");
 			
@@ -258,7 +264,7 @@
 		
 		private void OnTrackAdded (object o, int index, Track track)
 		{
-			Tools.Log (this, "Adding track {0} to playlist {1} at position {2}", track.Title, this.Name, index);
+			Tools.Log (this, 3, "Adding track {0} to playlist {1} at position {2}", track.Title, this.Name, index);
 			store.AppendValues (track);
 		}
 		
@@ -300,7 +306,10 @@
 		
 		private void OnDelete (object o, EventArgs args)
 		{
+			Tools.Log (this, 2, "Deleting playlist {0}", playlist.Name);
+			
 			SourceList.Instance.Tracks.DeletePlaylist (playlist);
+			playlist = null;
 			
 			if (Deleted != null)
 			{

Modified: trunk/src/Saviour.cs
==============================================================================
--- trunk/src/Saviour.cs	(original)
+++ trunk/src/Saviour.cs	Fri Mar 14 21:59:21 2008
@@ -32,12 +32,12 @@
 		
 		public Saviour (Device device)
 		{
-			Tools.Log (this, "A saviour named {0} is born", device.Name);
+			Tools.Log (this, 2, "A saviour named {0} is born", device.Name);
 			this.device = device;
 		}
 		
-		public static Saviour Instance {
-			
+		public static Saviour Instance
+		{
 			get {
 				return saviour;
 			}
@@ -50,6 +50,8 @@
 		
 		public void Save ()
 		{
+			Tools.Log (this, 3, "Saving database");
+			
 			ThreadStart starter = delegate {
 				
 				lock (this.device) {
@@ -67,12 +69,13 @@
 		
 		public UIManager () : base ()
 		{
-			Tools.Log (this, "Creating a new UIManager");
+			Tools.Log (this, 3, "Creating a new UIManager");
 		}
 		
 		public static Gtk.UIManager Instance {
 			
 			get {
+				
 				if (manager == null)
 				{
 					manager = new UIManager ();

Modified: trunk/src/Source.cs
==============================================================================
--- trunk/src/Source.cs	(original)
+++ trunk/src/Source.cs	Fri Mar 14 21:59:21 2008
@@ -82,6 +82,8 @@
 			id = idCounter;
 			idCounter++;
 			
+			Tools.Log (this, 3, "Creating source {0}", id);
+			
 			// initialize everything with dummy values
 			view = new Viewport ();
 			searchEntry = new Entry ();

Modified: trunk/src/SourceList.cs
==============================================================================
--- trunk/src/SourceList.cs	(original)
+++ trunk/src/SourceList.cs	Fri Mar 14 21:59:21 2008
@@ -61,12 +61,12 @@
 		
 		private SourceList ()
 		{
-			// initialize playlist list
+			Tools.Log (this, 1, "Creating source list");
 			
+			// initialize playlist list
 			sources = new List<ISource>();
 			
 			// create the columns, treeview, etc
-			
 			view = new TreeView ();
 			view.HeadersVisible = false;
 			
@@ -177,10 +177,11 @@
 			}
 			
 			set {
+				
 				if (value != null)
-					Tools.Log (this, "Selecting source {0}", value.Name);
+					Tools.Log (this, 2, "Selecting source {0}", value.Name);
 				else
-					Tools.Log (this, "No source selected");
+					Tools.Log (this, 2, "No source selected");
 				
 				if (selectedSource != null)
 					selectedSource.Selected = false;
@@ -207,7 +208,7 @@
 					if (SelectionChanged != null)
 					{
 						SelectionChanged (this, new SelectionChangedArgs (selectedSource));
-						Tools.Log (this, "Source {0} selected", selectedSource.Name);
+						Tools.Log (this, 2, "Source {0} selected", selectedSource.Name);
 					}
 				}
 				else
@@ -215,7 +216,7 @@
 					if (SelectionChanged != null)
 					{
 						SelectionChanged (this, new SelectionChangedArgs (null));
-						Tools.Log (this, "No source selected");
+						Tools.Log (this, 2, "No source selected");
 					}
 				}
 			}
@@ -224,6 +225,7 @@
 		public DeviceSource Device
 		{
 			get {
+				
 				DeviceSource device = (DeviceSource)sources.Find (delegate (ISource source) {
 					if (source.Type == SourceType.Device)
 						return true;
@@ -238,6 +240,7 @@
 		public TracksSource Tracks
 		{
 			get {
+				
 				TracksSource tracks = (TracksSource)sources.Find (delegate (ISource source) {
 					if (source.Type == SourceType.Tracks)
 						return true;
@@ -252,6 +255,7 @@
 		public List<ISource> Playlists
 		{
 			get {
+				
 				return sources.FindAll (delegate (ISource source) {
 					if (source.Type == SourceType.Playlist)
 						return true;
@@ -271,6 +275,7 @@
 		public static SourceList Instance {
 			
 			get {
+				
 				if (instance == null)
 					instance = new SourceList ();
 				
@@ -280,6 +285,8 @@
 		
 		public void Add (ISource source)
 		{
+			Tools.Log (this, 3, "Adding source {0} with id {1} to the list", source.Name, source.Id);
+			
 			sources.Add (source);
 			source.Deleted += OnSourceDeleted;
 			
@@ -301,7 +308,7 @@
 				});
 			}
 			
-			Tools.Log (this, "Added source {0} with id {1} to the list", source.Name, source.Id);
+			Tools.Log (this, 3, "Added source {0} with id {1} to the list", source.Name, source.Id);
 		}
 		
 		public void RefreshView ()
@@ -340,7 +347,6 @@
 			switch (args.Event.Button)
 			{
 			case 3:
-				Tools.Log (this, "Ooooh, right click");
 				PopupMenu (args.Event);
 				args.RetVal = true;
 				break;
@@ -352,7 +358,6 @@
 			switch (args.Event.Key)
 			{
 			case Gdk.Key.Menu:
-				Tools.Log (this, "Ooooh, menu button");
 				PopupMenu (args.Event);
 				args.RetVal = true;
 				break;
@@ -361,6 +366,8 @@
 		
 		private void PopupMenu (Gdk.Event ev)
 		{
+			Tools.Log (this, 3, "Showing popup menu for source {0}", selectedSource.Menu);
+			
 			// build the menu and show it
 			Menu menu = selectedSource.Menu;
 			
@@ -384,6 +391,8 @@
 		
 		private void OnSourceDeleted (object o)
 		{
+			Tools.Log (this, 2, "Removing source {0} from the source list");
+			
 			ISource source = (ISource)o;
 			
 			sources.Remove (source);
@@ -396,8 +405,8 @@
 					store.Remove (ref iter);
 					return true;
 				}
-				else
-					return false;
+
+				return false;
 			});
 		}
 		
@@ -433,7 +442,7 @@
 				Drag.Finish (args.Context, true, false, args.Time);
 				
 			} catch (Exception e) {
-				Tools.Log (this, "{0}", e.Message);
+				Tools.Log (this, 3, "{0}", e.Message);
 			}
 		}
 	}

Modified: trunk/src/Tools.cs
==============================================================================
--- trunk/src/Tools.cs	(original)
+++ trunk/src/Tools.cs	Fri Mar 14 21:59:21 2008
@@ -24,7 +24,7 @@
 {
 	public static class Tools
 	{
-		private static bool logEnabled;
+		private static int logLevel;
 		
 		public static string FormatString (double value)
 		{
@@ -35,25 +35,33 @@
 			}
 		}
 		
-		public static void Log (object o, string message)
+		public static void Log (object o, int level, string message)
 		{
-			if (logEnabled)
-				Console.WriteLine ("{0}: {1}", o, message);
+			if (logLevel < 0)
+			{
+				if (level < 1)
+					level = 1;
+				if (level > 3)
+					level = 3;
+				
+				if (logLevel > level)
+					Console.WriteLine ("{0}: {1}", o, message);
+			}
 		}
 		
-		public static void Log (object o, string format, params object[] args)
+		public static void Log (object o, int level, string format, params object[] args)
 		{
-			Log (o, String.Format (format, args));
+			Log (o, level, String.Format (format, args));
 		}
 		
-		public static bool LogEnabled
+		public static int LogLevel
 		{
 			get {
-				return logEnabled;
+				return logLevel;
 			}
 			
 			set {
-				logEnabled = value;
+				logLevel = value;
 			}
 		}
 	}

Modified: trunk/src/TracksContainer.cs
==============================================================================
--- trunk/src/TracksContainer.cs	(original)
+++ trunk/src/TracksContainer.cs	Fri Mar 14 21:59:21 2008
@@ -52,6 +52,8 @@
 		
 		public TracksContainer ()
 		{
+			Tools.Log (this, 3, "Creating tracks container");
+			
 			// create the columns, treeview, etc
 			view = new TreeView ();
 			
@@ -98,7 +100,7 @@
 			store_filter.VisibleFunc = SearchFilterFunc;
 			
 			// create action entries
-			ActionEntry[] entries =  {
+			ActionEntry[] entries = {
 
 				new ActionEntry ("AddToPlaylist",
 				                 Gtk.Stock.Add, Catalog.GetString ("Add to Playlist..."),
@@ -288,7 +290,7 @@
 			switch (args.Event.Button)
 			{
 			case 3:
-				Tools.Log (this, "Ooooh, right click");
+				Tools.Log (this, 3, "Ooooh, right click");
 				PopupMenu (args.Event);
 				args.RetVal = true;
 				break;
@@ -300,12 +302,12 @@
 			switch (args.Event.Key)
 			{
 			case Gdk.Key.Menu:
-				Tools.Log (this, "Ooooh, menu button");
+				Tools.Log (this, 3, "Ooooh, menu button");
 				PopupMenu (args.Event);
 				args.RetVal = true;
 				break;
 			case Gdk.Key.Delete:
-				Tools.Log (this, "Ooooh, delete button");
+				Tools.Log (this, 3, "Ooooh, delete button");
 				RemoveTracks (GetSelectedTracks ());
 				args.RetVal = true;
 				break;
@@ -318,7 +320,7 @@
 			
 			if (view.Selection.CountSelectedRows () > 0)
 			{
-				Tools.Log (this, "Building and showing track popup menu");
+				Tools.Log (this, 3, "Building and showing track popup menu");
 				
 				Menu playlistMenu = new Menu ();
 				MenuItem addToPlaylistItem = (MenuItem)UIManager.Instance.GetWidget ("/ui/TrackPopup/AddToPlaylist");
@@ -334,16 +336,13 @@
 						AddToPlaylist (playlistSource);
 					};
 					playlistMenu.Append (item);
-					Tools.Log (this, "Added playlist {0} to the menu", playlistSource.Name);
+					Tools.Log (this, 3, "Added playlist {0} to the menu", playlistSource.Name);
 				}
 				
 				addToPlaylistItem.Submenu = playlistMenu;
 				
 				Menu menu = (Menu)Hipo.UIManager.Instance.GetWidget ("/ui/TrackPopup");
 				
-				if (menu == null)
-					Console.WriteLine ("menu");
-				
 				menu.ShowAll ();
 				playlistMenu.ShowAll ();
 				
@@ -359,7 +358,7 @@
 		
 		protected virtual void AddEventHandlers ()
 		{
-			Tools.Log (this, "Hooking {0} track menu event handlers", this.Name);
+			Tools.Log (this, 3, "Hooking {0} track menu event handlers", this.Name);
 			
 			Menu menu = (Menu)UIManager.Instance.GetWidget ("/ui/TrackPopup");
 			
@@ -380,7 +379,7 @@
 		
 		protected virtual void RemoveEventHandlers ()
 		{
-			Tools.Log (this, "Unhooking {0} track menu event handlers", this.Name);
+			Tools.Log (this, 3, "Unhooking {0} track menu event handlers", this.Name);
 			
 			Menu menu = (Menu)UIManager.Instance.GetWidget ("/ui/TrackPopup");
 			

Modified: trunk/src/TracksSource.cs
==============================================================================
--- trunk/src/TracksSource.cs	(original)
+++ trunk/src/TracksSource.cs	Fri Mar 14 21:59:21 2008
@@ -72,6 +72,8 @@
 		
 		public Playlist CreatePlaylist (string name)
 		{
+			Tools.Log (this, 2, "Creating playlist {0}", name);
+			
 			Playlist playlist = null;
 			
 			if ((playlist = tracksDb.CreatePlaylist (name)) != null)
@@ -84,15 +86,15 @@
 		
 		public void DeletePlaylist (Playlist playlist)
 		{
+			Tools.Log (this, 2, "Removing playlist {0}", playlist.Name);
 			tracksDb.RemovePlaylist (playlist);
 		}
 		
 		public bool AddTrack (string path)
 		{
-			Track track = AddTrack (path, true);
+			Tools.Log (this, 3, "Adding track {0} to the database", path);
 			
-			if (track != null)
-				Saviour.Instance.Save ();
+			Track track = AddTrack (path, true);
 			
 			if (track == null)
 				return false;
@@ -102,12 +104,12 @@
 		
 		public override bool AddTracks (string[] uris, bool save)
 		{
+			Tools.Log (this, 2, "Adding {0} tracks to the database", uris.Length);
+			
 			bool trackAdded = false;
 			
 			foreach (string uri in uris)
 			{
-				Tools.Log (this, "Adding uri {0}", uri);
-				
 				Uri u = new Uri (uri);
 				Track track = AddTrack (u.LocalPath, false);
 				
@@ -162,8 +164,6 @@
 				track.TrackNumber = (int) file.Tag.Track;
 				
 				store.AppendValues (track);
-				
-				Tools.Log (this, "Added {0}", path);
 			}
 			
 			if (save && (track != null))
@@ -182,8 +182,6 @@
 				if (path == null)
 					return false;
 				
-				Tools.Log (this, "Adding uri {0}", path);
-				
 				System.Uri uri = new System.Uri (path);
 
 				UnixDirectoryInfo info = new UnixDirectoryInfo (uri.LocalPath);
@@ -214,12 +212,13 @@
 		
 		public void RemoveTrack (Track track)
 		{
+			Tools.Log (this, 3, "Removing track {0} from the database", track.Title);
 			RemoveTrack (track, true);
 		}
 		
 		public override void RemoveTracks (List<Track> tracks)
 		{
-			Tools.Log (this, "Removing {0} tracks from the database", tracks.Count);
+			Tools.Log (this, 2, "Removing {0} tracks from the database", tracks.Count);
 			
 			foreach (Track track in tracks)
 			{



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