[longomatch/redesign] WIP: almost working



commit cc61b6125e93fbb4ae5ba95c566efc5da989d0da
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Oct 25 14:55:53 2010 +0200

    WIP: almost working

 CesarPlayer/Utils/MediaFile.cs                     |    5 +-
 CesarPlayer/Utils/PreviewMediaFile.cs              |    1 +
 LongoMatch/DB/DataBase.cs                          |   23 +++----
 LongoMatch/DB/Project.cs                           |   43 +++++++-----
 LongoMatch/DB/ProjectDescription.cs                |    5 --
 LongoMatch/DB/TeamTemplate.cs                      |    5 +-
 LongoMatch/Gui/Component/ButtonsWidget.cs          |    2 +-
 LongoMatch/Gui/Component/PlaysListTreeWidget.cs    |   10 ++-
 LongoMatch/Gui/Component/ProjectDetailsWidget.cs   |   15 +++-
 LongoMatch/Gui/Component/ProjectListWidget.cs      |    6 +-
 LongoMatch/Gui/Component/ProjectTemplateWidget.cs  |    8 +--
 LongoMatch/Gui/Component/TagsTreeWidget.cs         |    7 +-
 LongoMatch/Gui/Component/TimeLineWidget.cs         |   70 +++++++++-----------
 LongoMatch/Gui/Component/TimeReferenceWidget.cs    |    6 +-
 LongoMatch/Gui/Component/TimeScale.cs              |    4 +-
 LongoMatch/Gui/TreeView/CategoriesTreeView.cs      |   12 ++--
 LongoMatch/Handlers/Handlers.cs                    |    4 +-
 LongoMatch/Main.cs                                 |    5 +-
 LongoMatch/Time/Category.cs                        |    9 ++-
 LongoMatch/Time/Play.cs                            |   10 ++--
 LongoMatch/Time/Time.cs                            |    9 ++-
 LongoMatch/Utils/ProjectUtils.cs                   |   23 +++----
 ...ngoMatch.Gui.Component.ProjectTemplateWidget.cs |   11 ++--
 LongoMatch/gtk-gui/gui.stetic                      |    4 +-
 LongoMatch/gtk-gui/objects.xml                     |   66 +++++++++---------
 25 files changed, 192 insertions(+), 171 deletions(-)
---
diff --git a/CesarPlayer/Utils/MediaFile.cs b/CesarPlayer/Utils/MediaFile.cs
index 9cc8b21..67721ad 100644
--- a/CesarPlayer/Utils/MediaFile.cs
+++ b/CesarPlayer/Utils/MediaFile.cs
@@ -123,6 +123,7 @@ namespace LongoMatch.Video.Utils
 		}
 		
 		public uint GetFrames(){
+			Console.WriteLine (Length);
 			return (uint) (Fps*Length/1000);
 		}
 		
@@ -151,7 +152,9 @@ namespace LongoMatch.Video.Utils
 				height = (int) reader.GetMetadata(MetadataType.DimensionX);
 				width = (int) reader.GetMetadata (MetadataType.DimensionY);
 								
-				return new MediaFile(filePath,duration*1000,(ushort)fps,hasAudio,hasVideo,videoCodec,audioCodec,(uint)height,(uint)width);
+				return new MediaFile(filePath,duration*1000,(ushort)fps,
+				                     hasAudio,hasVideo,videoCodec,audioCodec,
+				                     (uint)height,(uint)width);
 		
 			}
 			catch (GLib.GException ex){
diff --git a/CesarPlayer/Utils/PreviewMediaFile.cs b/CesarPlayer/Utils/PreviewMediaFile.cs
index 0fd512d..3549fbf 100644
--- a/CesarPlayer/Utils/PreviewMediaFile.cs
+++ b/CesarPlayer/Utils/PreviewMediaFile.cs
@@ -97,6 +97,7 @@ namespace LongoMatch.Video.Utils
 					thumbnailer.SeekTime(1000,false);
 					preview = thumbnailer.GetCurrentFrame(THUMBNAIL_MAX_WIDTH,THUMBNAIL_MAX_HEIGHT);
 					duration =(int) ((thumbnailer as GstPlayer).StreamLength/1000);				/* On Windows some formats report a 0 duration, try a last time with the reader */
+					Console.WriteLine ("Duration scanning is "+duration);
 					if (duration == 0)
 						duration = (int)reader.GetMetadata(MetadataType.Duration);
 					thumbnailer.Dispose();
diff --git a/LongoMatch/DB/DataBase.cs b/LongoMatch/DB/DataBase.cs
index 65359ed..7b39a3c 100644
--- a/LongoMatch/DB/DataBase.cs
+++ b/LongoMatch/DB/DataBase.cs
@@ -184,9 +184,7 @@ namespace LongoMatch.DB
 			lock (this.locker) {
 				IObjectContainer db = Db4oFactory.OpenFile(file);
 				try	{
-					IQuery query = db.Query();
-					query.Constrain(typeof(Project));
-					query.Descend("file").Descend("filePath").Constrain(filename);
+					IQuery query = GetQueryWithContrains(db, file);
 					IObjectSet result = query.Execute();
 					ret = (Project) db.Ext().PeekPersisted(result.Next(),10,true);
 					return ret;
@@ -232,9 +230,7 @@ namespace LongoMatch.DB
 				SetDeleteCascadeOptions();
 				IObjectContainer db = Db4oFactory.OpenFile(file);
 				try	{
-					IQuery query = db.Query();
-					query.Constrain(typeof(Project));
-					query.Descend("file").Descend("filePath").Constrain(filePath);
+					IQuery query = GetQueryWithContrains(db, file);
 					IObjectSet result = query.Execute();
 					Project project = (Project)result.Next();
 					db.Delete(project);
@@ -268,9 +264,7 @@ namespace LongoMatch.DB
 				try	{
 					// We look for a project with the same filename
 					if (!Exists(project.Description.File.FilePath,db)) {
-						IQuery query = db.Query();
-						query.Constrain(typeof(Project));
-						query.Descend("file").Descend("filePath").Constrain(previousFileName);
+						IQuery query = GetQueryWithContrains(db, file);
 						IObjectSet result = query.Execute();
 						//Get the stored project and replace it with the new one
 						if (result.Count == 1){
@@ -305,9 +299,7 @@ namespace LongoMatch.DB
 				SetDeleteCascadeOptions();
 				IObjectContainer db = Db4oFactory.OpenFile(file);
 				try	{
-					IQuery query = db.Query();
-					query.Constrain(typeof(Project));
-					query.Descend("file").Descend("filePath").Constrain(project.Description.File.FilePath);
+					IQuery query = GetQueryWithContrains(db, file);
 					IObjectSet result = query.Execute();
 					//Get the stored project and replace it with the new one
 					Project fd = (Project)result.Next();
@@ -341,6 +333,13 @@ namespace LongoMatch.DB
 				CloseDB(db);
 			}				
 		}
+		
+		private IQuery GetQueryWithContrains(IObjectContainer db, string filename){
+			IQuery query = db.Query();
+			query.Constrain(typeof(Project));
+			query.Descend("description").Descend("file").Descend("filePath").Constrain(filename);
+			return query;
+		}
 
 		private void CloseDB(IObjectContainer db) {
 			db.Ext().Purge();
diff --git a/LongoMatch/DB/Project.cs b/LongoMatch/DB/Project.cs
index c6507b7..29969d0 100644
--- a/LongoMatch/DB/Project.cs
+++ b/LongoMatch/DB/Project.cs
@@ -60,6 +60,7 @@ namespace LongoMatch.DB
 			Categories = new Categories();
 			LocalTeamTemplate = new TeamTemplate();
 			VisitorTeamTemplate = new TeamTemplate();
+			Tags = new TagsTemplate();
 		}
 		#endregion
 
@@ -133,7 +134,7 @@ namespace LongoMatch.DB
 		/// </returns>
 		public Play AddPlay(Category category, Time start, Time stop,Pixbuf miniature) {
 			string count= String.Format("{0:000}",playsList.Count+1);
-			string name = String.Format("{0} \" \" {1}",category.Name, count);
+			string name = String.Format("{0} {1}",category.Name, count);
 			// HACK: Used for capture where fps is not specified, asuming PAL 25fps
 			ushort fps = Description.File != null ? Description.File.Fps : (ushort)25;
 
@@ -178,26 +179,25 @@ namespace LongoMatch.DB
 			/* query for all the plays with this Category */
 			var plays = 
 				from play in playsList
-					where play.Category == category
+					where play.Category.UUID == category.UUID
 					select play;
 			/* Delete them */
 			foreach (var play in playsList)
 				playsList.Remove(play);
 		}
 		
-		public List<List<Play>> PlaysGroupedByCategory {
-			get {
-				var list = new List<List<Play>> ();
-				var queryPlaysByCategory = 
-					from play in playsList
-						group play by play.Category;
-				
-				foreach (var playsGroup in queryPlaysByCategory)
-					list.Add(playsGroup.ToList());
-				return list;
-			}
+		public List<Play> PlaysInCategory (Category category){
+			Console.WriteLine ("Plays are " + playsList.Count);
+			return (from play in playsList
+			        where play.Category.UUID == category.UUID
+			        select play).ToList();
 		}
-
+		
+		public List<Play> AllPlays (){
+			return (from play in playsList
+			        select play).ToList();
+		}
+		
 		/// <summary>
 		/// Returns a <see cref="Gtk.TreeStore"/> in which project categories are
 		/// root nodes and their respectives plays child nodes
@@ -206,15 +206,24 @@ namespace LongoMatch.DB
 		/// A <see cref="TreeStore"/>
 		/// </returns>
 		public TreeStore GetModel() {
+			Dictionary<Category, TreeIter> itersDic = new Dictionary<Category, TreeIter>();
 			Gtk.TreeStore dataFileListStore = new Gtk.TreeStore(typeof(Play));
+			
 			IEnumerable<IGrouping<Category, Play>> queryPlaysByCategory = 
 				from play in playsList
 					group play by play.Category;
 			
+			foreach (Category cat in Categories.CategoriesList){
+				Gtk.TreeIter iter = dataFileListStore.AppendValues(cat);
+				itersDic.Add(cat, iter);
+			} 
+			
 			foreach (var playsGroup in queryPlaysByCategory) {
-				Gtk.TreeIter iter = dataFileListStore.AppendValues(playsGroup.Key);
+				Category cat = playsGroup.Key;
+				if (!itersDic.ContainsKey(cat))
+					continue;
 				foreach (Play play in playsGroup) {
-					dataFileListStore.AppendValues(iter,play);
+					dataFileListStore.AppendValues(itersDic[cat],play);
 				}
 			}
 			return dataFileListStore;
@@ -285,7 +294,7 @@ namespace LongoMatch.DB
 		#region Private Methods
 		
 		private TreeStore GetTeamModel(TeamTemplate team){
-			var dataFileListStore = new Gtk.TreeStore(typeof(object));
+			TreeStore dataFileListStore = new TreeStore(typeof(object));
 			
 			/* For all the players in the team */
 			foreach (var player in team.PlayersList){
diff --git a/LongoMatch/DB/ProjectDescription.cs b/LongoMatch/DB/ProjectDescription.cs
index 8dad4c7..ad7259d 100644
--- a/LongoMatch/DB/ProjectDescription.cs
+++ b/LongoMatch/DB/ProjectDescription.cs
@@ -83,11 +83,6 @@ namespace LongoMatch.DB
 			set;
 		}
 		
-		public Time Length {
-			get;
-			set;
-		}
-		
 		public String VideoCodec {
 			get;
 			set;
diff --git a/LongoMatch/DB/TeamTemplate.cs b/LongoMatch/DB/TeamTemplate.cs
index 84bbbfc..0af2438 100644
--- a/LongoMatch/DB/TeamTemplate.cs
+++ b/LongoMatch/DB/TeamTemplate.cs
@@ -42,8 +42,9 @@ namespace LongoMatch.DB
 		}
 
 		public List<Player> PlayersList{
-			set;
-			get;
+			get {
+				return playersList;
+			}
 		}
 
 		public void Clear() {
diff --git a/LongoMatch/Gui/Component/ButtonsWidget.cs b/LongoMatch/Gui/Component/ButtonsWidget.cs
index 04b098a..f6976a5 100644
--- a/LongoMatch/Gui/Component/ButtonsWidget.cs
+++ b/LongoMatch/Gui/Component/ButtonsWidget.cs
@@ -65,7 +65,7 @@ namespace LongoMatch.Gui.Component
 					table1.Remove(w);
 					w.Destroy();
 				}
-				Categories = value;
+				categories = value;
 				if (value == null)
 					return;
 				
diff --git a/LongoMatch/Gui/Component/PlaysListTreeWidget.cs b/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
index 0a15d1f..e9f2dc6 100644
--- a/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
+++ b/LongoMatch/Gui/Component/PlaysListTreeWidget.cs
@@ -55,7 +55,7 @@ namespace LongoMatch.Gui.Component
             treeview.SnapshotSeriesEvent += OnSnapshotSeriesEvent;
             treeview.PlayersTagged += OnPlayersTagged;
             treeview.TagPlay += OnTagPlay;
-		}		
+		}
 
 		public void RemovePlay(Play play) {
 			if (project != null) {
@@ -64,7 +64,7 @@ namespace LongoMatch.Gui.Component
 				
 				var category = play.Category;
 				var model = (TreeStore)treeview.Model;
-				model.GetIterFromString(out iter, category.Position.ToString());
+				model.GetIterFromString(out iter, CategoryPath(category));
 				model.IterChildren(out child, iter);
 				// Searching the TimeNode to remove it
 				while (model.IterIsValid(child)) {
@@ -89,7 +89,7 @@ namespace LongoMatch.Gui.Component
 			
 			var cat = play.Category;
 			var model = (TreeStore)treeview.Model;
-			model.GetIterFromString(out categoryIter, cat.Position.ToString());
+			model.GetIterFromString(out categoryIter, CategoryPath(cat));
 			var playIter = model.AppendValues(categoryIter,play);
 			var playPath = model.GetPath(playIter);
 			treeview.Selection.UnselectAll();				
@@ -123,6 +123,10 @@ namespace LongoMatch.Gui.Component
 				treeview.PlayListLoaded=value;
 			}
 		}
+		
+		private string CategoryPath(Category cat){
+			return project.Categories.CategoriesList.IndexOf(cat).ToString();
+		}
 
 		protected virtual void OnTimeNodeChanged(TimeNode tNode,object val) {
 			if (TimeNodeChanged != null)
diff --git a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
index 2018fe4..03eee91 100644
--- a/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectDetailsWidget.cs
@@ -416,6 +416,7 @@ namespace LongoMatch.Gui.Component
 			tagscombobox.Active = index;
 			var reader = new CategoriesReader(System.IO.Path.Combine(MainClass.TemplatesDir(),SectionsFile));
 			Categories = reader.GetCategories();
+			Console.WriteLine (Categories.Count);
 		}
 
 		private void FillTeamsTemplate() {
@@ -436,8 +437,10 @@ namespace LongoMatch.Gui.Component
 			}
 			localcombobox.Active = index;
 			visitorcombobox.Active = index;
-			LocalTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(),LocalTeamTemplateFile));
-			VisitorTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(),VisitorTeamTemplateFile));
+			LocalTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(),
+			                                                                     LocalTeamTemplateFile));
+			VisitorTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(),
+			                                                                       VisitorTeamTemplateFile));
 		}
 		
 		private void FillFormats(){
@@ -497,6 +500,7 @@ namespace LongoMatch.Gui.Component
 						md.Icon=Stetic.IconLoader.LoadIcon(this, "longomatch", Gtk.IconSize.Dialog, 48);
 						md.Show();
 						mFile = LongoMatch.Video.Utils.PreviewMediaFile.GetMediaFile(filename);
+						Console.WriteLine (mFile.Length.ToString());
 						if (!mFile.HasVideo || mFile.VideoCodec == "")
 							throw new Exception(Catalog.GetString("This file doesn't contain a video stream."));
 						if (mFile.HasVideo && mFile.Length == 0)
@@ -541,19 +545,22 @@ namespace LongoMatch.Gui.Component
 
 		protected virtual void OnVisitorcomboboxChanged(object sender, System.EventArgs e)
 		{
-			VisitorTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(), VisitorTeamTemplateFile));
+			VisitorTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(), 
+			                                                                       VisitorTeamTemplateFile));
 		}
 
 
 		protected virtual void OnLocalcomboboxChanged(object sender, System.EventArgs e)
 		{
-			LocalTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(), LocalTeamTemplateFile));
+			LocalTeamTemplate = TeamTemplate.LoadFromFile(System.IO.Path.Combine(MainClass.TemplatesDir(), 
+			                                                                     LocalTeamTemplateFile));
 		}
 
 		protected virtual void OnEditbuttonClicked(object sender, System.EventArgs e)
 		{
 			ProjectTemplateEditorDialog ted = new ProjectTemplateEditorDialog();
 			ted.TransientFor = (Window)Toplevel;
+			Console.WriteLine (Categories.Count);
 			ted.Categories = Categories;
 			ted.Project = project;
 			ted.CanExport = Use == ProjectType.EditProject;
diff --git a/LongoMatch/Gui/Component/ProjectListWidget.cs b/LongoMatch/Gui/Component/ProjectListWidget.cs
index 75d08ad..d1a80de 100644
--- a/LongoMatch/Gui/Component/ProjectListWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectListWidget.cs
@@ -91,8 +91,9 @@ namespace LongoMatch.Gui.Component
 			projectsList = projects;
 			projectsList.Sort();
 			projectsListStore.Clear();
-			foreach (ProjectDescription project in projectsList)
+			foreach (ProjectDescription project in projectsList){
 				projectsListStore.AppendValues(project);
+			}
 			filter = new Gtk.TreeModelFilter(projectsListStore, null);
 			filter.VisibleFunc = new Gtk.TreeModelFilterVisibleFunc(FilterTree);
 			treeview.Model = filter;
@@ -116,7 +117,8 @@ namespace LongoMatch.Gui.Component
 			string text;
 			ProjectDescription project = (ProjectDescription) model.GetValue(iter, 0);
 			
-			text = "\n"+"\n"+"\n"+"<b>"+Catalog.GetString("File length")+":</b>  " + project.Length.ToSecondsString();
+			text = "\n"+"\n"+"\n"+"<b>"+Catalog.GetString("File length")+":</b>  " + 
+				(new Time ((int)project.File.Length)).ToSecondsString();
 			text = text +"\n"+"<b>"+Catalog.GetString("Video codec")+":</b>  " + project.VideoCodec;
 			text = text +"\n"+"<b>"+Catalog.GetString("Audio codec")+":</b>  " + project.AudioCodec;
 			text = text +"\n"+"<b>"+Catalog.GetString("Format")+":</b>  " + project.Format;
diff --git a/LongoMatch/Gui/Component/ProjectTemplateWidget.cs b/LongoMatch/Gui/Component/ProjectTemplateWidget.cs
index ccd7bbe..1eb00d3 100644
--- a/LongoMatch/Gui/Component/ProjectTemplateWidget.cs
+++ b/LongoMatch/Gui/Component/ProjectTemplateWidget.cs
@@ -71,8 +71,7 @@ namespace LongoMatch.Gui.Component
 						hkList.Add(cat.HotKey);
 					} catch {}; //Do not add duplicated hotkeys
 				}
-				/* FIXME */
-				//categoriestreeview1.Model = categoriesListStore;
+				categoriestreeview.Model = categoriesListStore;
 				ButtonsSensitive = false;
 			}
 		}
@@ -188,12 +187,12 @@ namespace LongoMatch.Gui.Component
 			EditSelectedSection();
 		}
 
-		protected virtual void OnCategoriestreeview1SectionClicked(LongoMatch.TimeNodes.Category tNode)
+		protected virtual void OnCategoriestreeviewSectionClicked(LongoMatch.TimeNodes.Category tNode)
 		{
 			EditSelectedSection();
 		}
 
-		protected virtual void OnCategoriestreeview1CategoriesSelected (List<Category> tNodesList)
+		protected virtual void OnCategoriestreeviewCategoriesSelected (List<Category> tNodesList)
 		{
 			selectedCategories = tNodesList;
 			if (tNodesList.Count == 0)
@@ -241,6 +240,5 @@ namespace LongoMatch.Gui.Component
 			}	
 			dialog.Destroy();
 		}
-		
 	}
 }
diff --git a/LongoMatch/Gui/Component/TagsTreeWidget.cs b/LongoMatch/Gui/Component/TagsTreeWidget.cs
index 2d2f462..b0ecfc7 100644
--- a/LongoMatch/Gui/Component/TagsTreeWidget.cs
+++ b/LongoMatch/Gui/Component/TagsTreeWidget.cs
@@ -112,10 +112,9 @@ namespace LongoMatch.Gui.Component
 				project = value;
 				if (project != null) {
 					model.Clear();
-					foreach (List<Play> list in project.PlaysGroupedByCategory){
-						foreach (Play tNode in list)
-							model.AppendValues(tNode);
-					}
+					foreach (Play play in value.AllPlays())
+						model.AppendValues(play);
+					
 					UpdateTagsList();
 					treeview.LocalTeam = project.Description.LocalName;
 					treeview.VisitorTeam = project.Description.VisitorName;
diff --git a/LongoMatch/Gui/Component/TimeLineWidget.cs b/LongoMatch/Gui/Component/TimeLineWidget.cs
index 9bf81dd..545758f 100644
--- a/LongoMatch/Gui/Component/TimeLineWidget.cs
+++ b/LongoMatch/Gui/Component/TimeLineWidget.cs
@@ -39,13 +39,13 @@ namespace LongoMatch.Gui.Component {
 		//public event PlayListNodeAddedHandler PlayListNodeAdded;
 
 		private List<TimeScale> tsList;
-		private List<List<Play>> playsByCategory;
-		private Categories sections;
+		private Categories categories;
 		private TimeReferenceWidget tr;
 		private uint frames;
 		private uint pixelRatio;
 		private Play selected;
 		private uint currentFrame;
+		private bool hasProject;
 
 
 		public TimeLineWidget()
@@ -54,18 +54,18 @@ namespace LongoMatch.Gui.Component {
 			SetPixelRatio(10);
 			vscale1.CanFocus = false;
 		}
-
+		
 		public Play SelectedTimeNode {
 			get {
 				return selected;
 			}
 			set {
+				if (!hasProject)
+					return;
+					
 				selected = value;
-				if (tsList != null && playsByCategory != null) {
-					foreach (TimeScale  ts in tsList) {
-						ts.SelectedTimeNode = value;
-					}
-				}
+				foreach (TimeScale  ts in tsList)
+					ts.SelectedTimeNode = value;
 				if (selected != null) {
 					if (SelectedTimeNode.StartFrame/pixelRatio < GtkScrolledWindow.Hadjustment.Value ||
 					                SelectedTimeNode.StartFrame/pixelRatio > GtkScrolledWindow.Hadjustment.Value +
@@ -81,14 +81,13 @@ namespace LongoMatch.Gui.Component {
 				return currentFrame;
 			}
 			set {
+				if (!hasProject)
+					return;
+				
 				currentFrame = value;
-
-				if (tsList != null && playsByCategory != null) {
-					foreach (TimeScale  ts in tsList) {
-						ts.CurrentFrame = value;
-					}
-					tr.CurrentFrame = value;
-				}
+				foreach (TimeScale  ts in tsList) 
+					ts.CurrentFrame = value;
+				tr.CurrentFrame = value;
 				QueueDraw();
 			}
 		}
@@ -112,53 +111,48 @@ namespace LongoMatch.Gui.Component {
 			}
 		}
 
-
 		private void SetPixelRatio(uint pixelRatio) {
-			if (tsList != null && playsByCategory != null) {
-				this.pixelRatio = pixelRatio;
-				tr.PixelRatio = pixelRatio;
-				foreach (TimeScale  ts in tsList) {
-					ts.PixelRatio = pixelRatio;
-				}
-				vscale1.Value=pixelRatio;
-			}
+			if (!hasProject)
+				return;
+			
+			this.pixelRatio = pixelRatio;
+			tr.PixelRatio = pixelRatio;
+			foreach (TimeScale  ts in tsList)
+				ts.PixelRatio = pixelRatio;
+			vscale1.Value=pixelRatio;
 		}
 
-
 		public Project Project {
 			set {
-				int i = 0;
-				
 				ResetGui();
 
 				if (value == null) {
-					sections = null;
-					playsByCategory = null;
+					categories = null;
 					tsList=null;
+					hasProject = false;
 					return;
 				}
-
-				sections = value.Categories;
-				playsByCategory = value.PlaysGroupedByCategory;
+				
+				hasProject = true;
+				categories = value.Categories;
 				tsList = new List<TimeScale>();
-
 				frames = value.Description.File.GetFrames();
+				Console.WriteLine (frames);
 				ushort fps = value.Description.File.Fps;
-
 				tr = new TimeReferenceWidget(frames,fps);
 				vbox1.PackStart(tr,false,false,0);
 				tr.Show();
 				
-				foreach (List<Play> playsList in playsByCategory) {
-					TimeScale ts = new TimeScale(i, playsList ,frames);					
-					tsList[i]=ts;
+				foreach (Category cat in  categories.CategoriesList) {
+					List<Play> playsList = value.PlaysInCategory(cat);
+					TimeScale ts = new TimeScale(cat, playsList,frames);
+					tsList.Add(ts);
 					ts.TimeNodeChanged += new TimeNodeChangedHandler(OnTimeNodeChanged);
 					ts.TimeNodeSelected += new TimeNodeSelectedHandler(OnTimeNodeSelected);
 					ts.TimeNodeDeleted += new TimeNodeDeletedHandler(OnTimeNodeDeleted);
 					ts.NewMarkAtFrameEvent += new NewMarkAtFrameEventHandler(OnNewMark);
 					vbox1.PackStart(ts,true,true,0);
 					ts.Show();
-					i++;
 				}
 				SetPixelRatio(3);
 			}
diff --git a/LongoMatch/Gui/Component/TimeReferenceWidget.cs b/LongoMatch/Gui/Component/TimeReferenceWidget.cs
index c152c20..7dfcc2b 100644
--- a/LongoMatch/Gui/Component/TimeReferenceWidget.cs
+++ b/LongoMatch/Gui/Component/TimeReferenceWidget.cs
@@ -1,4 +1,4 @@
-// TimeReferenceWidget.cs
+// TimeReferenceWidget.cs
 //
 //  Copyright (C2007-2009 Andoni Morales Alastruey
 //
@@ -115,7 +115,7 @@ namespace LongoMatch.Gui.Component
 
 
 					g.MoveTo(new PointD(i-13,height-20));
-					time.MSeconds = (int)(i/frameRate*pixelRatio);
+					time.MSeconds = (int)(i*1000/frameRate*pixelRatio);
 					g.ShowText(time.ToSecondsString());
 					i=i+10*frameRate;
 				}
@@ -141,7 +141,7 @@ namespace LongoMatch.Gui.Component
 			for (int i=10*frameRate; i<=frames/pixelRatio;) {
 				// Drawing separator line
 				evnt.Window.DrawLine(Style.DarkGC(StateType.Normal),i,height,i,height-10);
-				time.MSeconds = (int)(i/frameRate*pixelRatio);
+				time.MSeconds = (int)(i*1000/frameRate*pixelRatio);
 				layout.SetMarkup(time.ToSecondsString());
 				this.GdkWindow.DrawLayout(this.Style.TextGC(StateType.Normal),i-13,height-23,layout);
 				//g.ShowText(time.ToSecondsString());
diff --git a/LongoMatch/Gui/Component/TimeScale.cs b/LongoMatch/Gui/Component/TimeScale.cs
index 7a95441..64c63f5 100644
--- a/LongoMatch/Gui/Component/TimeScale.cs
+++ b/LongoMatch/Gui/Component/TimeScale.cs
@@ -70,9 +70,9 @@ namespace LongoMatch.Gui.Component
 		public event TimeNodeDeletedHandler TimeNodeDeleted;
 
 
-		public TimeScale(int section,List<Play> list, uint frames)
+		public TimeScale(Category category, List<Play> list, uint frames)
 		{
-			this.category = list[0].Category;
+			this.category = category;
 			this.frames = frames;
 			this.list = list;
 			HeightRequest= SECTION_HEIGHT;
diff --git a/LongoMatch/Gui/TreeView/CategoriesTreeView.cs b/LongoMatch/Gui/TreeView/CategoriesTreeView.cs
index 5c0cbdd..7b390ac 100644
--- a/LongoMatch/Gui/TreeView/CategoriesTreeView.cs
+++ b/LongoMatch/Gui/TreeView/CategoriesTreeView.cs
@@ -34,8 +34,8 @@ namespace LongoMatch.Gui.Component
 	[System.ComponentModel.ToolboxItem(true)]
 	public class CategoriesTreeView : Gtk.TreeView
 	{
-		public event SectionHandler SectionClicked;
-		public event SectionsHandler SectionsSelected;
+		public event CategoryHandler CategoryClicked;
+		public event CategoriesHandler CategoriesSelected;
 
 		public CategoriesTreeView() {
 
@@ -144,8 +144,8 @@ namespace LongoMatch.Gui.Component
 				Model.GetIterFromString (out iter, pathArray[i].ToString());
 				list.Add((Category) Model.GetValue(iter, 0));
 			}
-			if (SectionsSelected != null)
-				SectionsSelected(list);
+			if (CategoriesSelected != null)
+				CategoriesSelected(list);
 		}
 
 		protected virtual void OnTreeviewRowActivated(object o, Gtk.RowActivatedArgs args)
@@ -154,8 +154,8 @@ namespace LongoMatch.Gui.Component
 			Model.GetIter(out iter, args.Path);
 			Category tNode = (Category)Model.GetValue(iter, 0);
 
-			if (SectionClicked != null)
-				SectionClicked(tNode);
+			if (CategoryClicked != null)
+				CategoryClicked(tNode);
 		}
 	}
 }
\ No newline at end of file
diff --git a/LongoMatch/Handlers/Handlers.cs b/LongoMatch/Handlers/Handlers.cs
index 822eebe..e2b444e 100644
--- a/LongoMatch/Handlers/Handlers.cs
+++ b/LongoMatch/Handlers/Handlers.cs
@@ -83,8 +83,8 @@ namespace LongoMatch.Handlers
 	public delegate void NewVersionHandler(Version version, string URL);
 
 	
-	public delegate void SectionHandler(Category category);
-	public delegate void SectionsHandler(List<Category> categoriesList);
+	public delegate void CategoryHandler(Category category);
+	public delegate void CategoriesHandler(List<Category> categoriesList);
 	
 	public delegate void ProjectsSelectedHandler(List<ProjectDescription> projects);
 }
diff --git a/LongoMatch/Main.cs b/LongoMatch/Main.cs
index 09a0f89..7f10f1a 100644
--- a/LongoMatch/Main.cs
+++ b/LongoMatch/Main.cs
@@ -61,7 +61,7 @@ namespace LongoMatch
 			//Iniciamos la aplicación
 			Application.Init();
 
-			GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnException);
+			//GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnException);
 
 			LongoMatch.Video.Player.GstPlayer.InitBackend("");
 
@@ -80,7 +80,8 @@ namespace LongoMatch
 				win.Show();
 				Application.Run();
 			} catch (Exception ex) {
-				ProcessExecutionError(ex);
+				//ProcessExecutionError(ex);
+				throw ex;
 			}
 		}
 
diff --git a/LongoMatch/Time/Category.cs b/LongoMatch/Time/Category.cs
index f768ee6..faace79 100644
--- a/LongoMatch/Time/Category.cs
+++ b/LongoMatch/Time/Category.cs
@@ -35,13 +35,20 @@ namespace LongoMatch.TimeNodes
 	public class Category:TimeNode, ISerializable
 	{
 		
+		private Guid _UUID;
 		
 		#region Constructors
 		#endregion
 		public Category (){
-			
+			_UUID = System.Guid.NewGuid();
 		}
 		#region  Properties
+		
+		public Guid UUID{
+			get {
+				return _UUID;
+			}
+		}
 
 		/// <value>
 		/// A key combination to create plays in my category
diff --git a/LongoMatch/Time/Play.cs b/LongoMatch/Time/Play.cs
index f209627..0dc8b52 100644
--- a/LongoMatch/Time/Play.cs
+++ b/LongoMatch/Time/Play.cs
@@ -85,10 +85,10 @@ namespace LongoMatch.TimeNodes
 		/// </value>
 		public uint StartFrame {
 			get {
-				return (uint) (Start.MSeconds / (Fps * 1000));
+				return (uint) (Start.MSeconds * Fps / 1000);
 			}
 			set {
-				Start = new Time((int)(1000*value/Fps));
+				Start = new Time((int)(1000 * value / Fps));
 			}
 		}
 
@@ -97,10 +97,10 @@ namespace LongoMatch.TimeNodes
 		/// </value>
 		public uint StopFrame {
 			get {
-				return (uint) (Stop.MSeconds / (Fps * (uint)1000));
+				return (uint) (Stop.MSeconds * Fps / 1000);
 			}
 			set {
-				Stop = new Time((int)(1000*value/Fps));
+				Stop = new Time((int)(1000 * value / Fps));
 			}
 		}
 
@@ -110,7 +110,7 @@ namespace LongoMatch.TimeNodes
 		public uint KeyFrame {
 			get {
 				if (HasKeyFrame)
-					return (uint) KeyFrameDrawing.StopTime*Fps/1000;
+					return (uint) KeyFrameDrawing.StopTime * Fps / 1000;
 				else return 0;
 			}
 		}
diff --git a/LongoMatch/Time/Time.cs b/LongoMatch/Time/Time.cs
index b7a2579..e4b6d0a 100644
--- a/LongoMatch/Time/Time.cs
+++ b/LongoMatch/Time/Time.cs
@@ -83,11 +83,12 @@ namespace LongoMatch.TimeNodes
 		/// </returns>
 		public  string ToSecondsString()
 		{
-			int _h, _m, _s;
+			int _h, _m, _s, _time;
 
-			_h = (time / 3600);
-			_m = ((time % 3600) / 60);
-			_s = ((time % 3600) % 60);
+			_time = time / 1000;
+			_h = (_time / 3600);
+			_m = ((_time % 3600) / 60);
+			_s = ((_time % 3600) % 60);
 
 			if (_h > 0)
 				return String.Format("{0}:{1}:{2}", _h, _m.ToString("d2"),
diff --git a/LongoMatch/Utils/ProjectUtils.cs b/LongoMatch/Utils/ProjectUtils.cs
index c426104..079b10e 100644
--- a/LongoMatch/Utils/ProjectUtils.cs
+++ b/LongoMatch/Utils/ProjectUtils.cs
@@ -279,20 +279,19 @@ namespace LongoMatch.Utils
 			factory = new MultimediaFactory();
 			capturer = factory.getFramesCapturer();
 			capturer.Open (project.Description.File.FilePath);
-			foreach (List<Play> list in project.PlaysGroupedByCategory){
-				foreach (Play play in list){
-					try{
-						capturer.SeekTime(play.Start.MSeconds + ((play.Stop - play.Start).MSeconds/2),
-						                  true);
-						play.Miniature = capturer.GetCurrentFrame(Constants.THUMBNAIL_MAX_WIDTH,
-						                                          Constants.THUMBNAIL_MAX_HEIGHT);
-						dialog.Pulse();
-						
-					} catch {
+			foreach (Play play in project.AllPlays()){
+				try{
+					capturer.SeekTime(play.Start.MSeconds + ((play.Stop - play.Start).MSeconds/2),
+					                  true);
+					play.Miniature = capturer.GetCurrentFrame(Constants.THUMBNAIL_MAX_WIDTH,
+					                                          Constants.THUMBNAIL_MAX_HEIGHT);
+					dialog.Pulse();
+					
+				} catch {
 						/* FIXME: Add log */
-					}					
 				}					
-			}	
+			}					
+			
 			capturer.Dispose();
 			dialog.Destroy();
 		}
diff --git a/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectTemplateWidget.cs b/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectTemplateWidget.cs
index 8f24b99..b8531fc 100644
--- a/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectTemplateWidget.cs
+++ b/LongoMatch/gtk-gui/LongoMatch.Gui.Component.ProjectTemplateWidget.cs
@@ -17,7 +17,7 @@ namespace LongoMatch.Gui.Component {
         
         private Gtk.ScrolledWindow scrolledwindow2;
         
-        private LongoMatch.Gui.Component.CategoriesTreeView sectionstreeview1;
+        private LongoMatch.Gui.Component.CategoriesTreeView categoriestreeview;
         
         private Gtk.VBox vbox2;
         
@@ -48,10 +48,10 @@ namespace LongoMatch.Gui.Component {
             this.scrolledwindow2.Name = "scrolledwindow2";
             this.scrolledwindow2.ShadowType = ((Gtk.ShadowType)(1));
             // Container child scrolledwindow2.Gtk.Container+ContainerChild
-            this.sectionstreeview1 = new LongoMatch.Gui.Component.CategoriesTreeView();
-            this.sectionstreeview1.CanFocus = true;
-            this.sectionstreeview1.Name = "sectionstreeview1";
-            this.scrolledwindow2.Add(this.sectionstreeview1);
+            this.categoriestreeview = new LongoMatch.Gui.Component.CategoriesTreeView();
+            this.categoriestreeview.CanFocus = true;
+            this.categoriestreeview.Name = "categoriestreeview";
+            this.scrolledwindow2.Add(this.categoriestreeview);
             this.hbox1.Add(this.scrolledwindow2);
             Gtk.Box.BoxChild w2 = ((Gtk.Box.BoxChild)(this.hbox1[this.scrolledwindow2]));
             w2.Position = 0;
@@ -220,6 +220,7 @@ namespace LongoMatch.Gui.Component {
             this.exportbutton.Hide();
             this.Show();
             this.KeyPressEvent += new Gtk.KeyPressEventHandler(this.OnKeyPressEvent);
+            this.categoriestreeview.CategoriesSelected += new LongoMatch.Handlers.CategoriesHandler(this.OnCategoriestreeviewCategoriesSelected);
             this.newprevbutton.Clicked += new System.EventHandler(this.OnNewBefore);
             this.newafterbutton.Clicked += new System.EventHandler(this.OnNewAfter);
             this.newafterbutton.Activated += new System.EventHandler(this.OnNewBefore);
diff --git a/LongoMatch/gtk-gui/gui.stetic b/LongoMatch/gtk-gui/gui.stetic
index bdf40dd..0aac887 100644
--- a/LongoMatch/gtk-gui/gui.stetic
+++ b/LongoMatch/gtk-gui/gui.stetic
@@ -1584,9 +1584,10 @@
             <property name="CanFocus">True</property>
             <property name="ShadowType">In</property>
             <child>
-              <widget class="LongoMatch.Gui.Component.CategoriesTreeView" id="sectionstreeview1">
+              <widget class="LongoMatch.Gui.Component.CategoriesTreeView" id="categoriestreeview">
                 <property name="MemberName" />
                 <property name="CanFocus">True</property>
+                <signal name="CategoriesSelected" handler="OnCategoriestreeviewCategoriesSelected" />
               </widget>
             </child>
           </widget>
@@ -4485,7 +4486,6 @@ Hotkeys with a single key are also allowed with Ctrl+key.</property>
                 <property name="MemberName" />
                 <property name="CanFocus">True</property>
                 <property name="Label" translatable="yes" />
-                <property name="Active">True</property>
                 <property name="DrawIndicator">False</property>
                 <property name="HasLabel">False</property>
                 <property name="UseUnderline">True</property>
diff --git a/LongoMatch/gtk-gui/objects.xml b/LongoMatch/gtk-gui/objects.xml
index aa72a78..6638a40 100644
--- a/LongoMatch/gtk-gui/objects.xml
+++ b/LongoMatch/gtk-gui/objects.xml
@@ -72,8 +72,8 @@
     <itemgroups />
     <signals>
       <itemgroup label="CategoriesTreeView Signals">
-        <signal name="SectionClicked" />
-        <signal name="SectionsSelected" />
+        <signal name="CategoryClicked" />
+        <signal name="CategoriesSelected" />
       </itemgroup>
     </signals>
   </object>
@@ -141,22 +141,6 @@
     <itemgroups />
     <signals />
   </object>
-  <object type="LongoMatch.Gui.Component.ProjectListWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
-    <itemgroups />
-    <signals>
-      <itemgroup label="ProjectListWidget Signals">
-        <signal name="ProjectsSelected" />
-      </itemgroup>
-    </signals>
-  </object>
-  <object type="LongoMatch.Gui.Component.CategoryProperties" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
-    <itemgroups />
-    <signals>
-      <itemgroup label="CategoryProperties Signals">
-        <signal name="HotKeyChanged" />
-      </itemgroup>
-    </signals>
-  </object>
   <object type="LongoMatch.Gui.Component.DrawingToolBox" palette-category="General" allow-children="false" base-type="Gtk.Bin">
     <itemgroups />
     <signals>
@@ -209,6 +193,20 @@
       </itemgroup>
     </signals>
   </object>
+  <object type="LongoMatch.Gui.Component.PlaysListTreeWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
+    <itemgroups />
+    <signals>
+      <itemgroup label="PlaysListTreeWidget Signals">
+        <signal name="TimeNodeSelected" />
+        <signal name="TimeNodeChanged" />
+        <signal name="TimeNodeDeleted" />
+        <signal name="PlayListNodeAdded" />
+        <signal name="SnapshotSeriesEvent" />
+        <signal name="PlayersTagged" />
+        <signal name="TagPlay" />
+      </itemgroup>
+    </signals>
+  </object>
   <object type="LongoMatch.Gui.Component.ProjectDetailsWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups>
       <itemgroup label="ProjectDetailsWidget Properties">
@@ -228,10 +226,6 @@
       </itemgroup>
     </signals>
   </object>
-  <object type="LongoMatch.Gui.Popup.TransparentDrawingArea" palette-category="General" allow-children="false" base-type="Gtk.Window">
-    <itemgroups />
-    <signals />
-  </object>
   <object type="LongoMatch.Gui.Component.ProjectTemplateWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups>
       <itemgroup label="ProjectTemplateWidget Properties">
@@ -240,6 +234,14 @@
     </itemgroups>
     <signals />
   </object>
+  <object type="LongoMatch.Gui.Component.CategoryProperties" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
+    <itemgroups />
+    <signals>
+      <itemgroup label="CategoryProperties Signals">
+        <signal name="HotKeyChanged" />
+      </itemgroup>
+    </signals>
+  </object>
   <object type="LongoMatch.Gui.Component.TimeLineWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups>
       <itemgroup label="TimeLineWidget Properties">
@@ -255,28 +257,26 @@
       </itemgroup>
     </signals>
   </object>
-  <object type="LongoMatch.Gui.Component.PlaysListTreeWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
+  <object type="LongoMatch.Gui.Popup.TransparentDrawingArea" palette-category="General" allow-children="false" base-type="Gtk.Window">
+    <itemgroups />
+    <signals />
+  </object>
+  <object type="LongoMatch.Gui.Component.TagsTreeWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups />
     <signals>
-      <itemgroup label="PlaysListTreeWidget Signals">
+      <itemgroup label="TagsTreeWidget Signals">
         <signal name="TimeNodeSelected" />
         <signal name="TimeNodeChanged" />
-        <signal name="TimeNodeDeleted" />
         <signal name="PlayListNodeAdded" />
         <signal name="SnapshotSeriesEvent" />
-        <signal name="PlayersTagged" />
-        <signal name="TagPlay" />
       </itemgroup>
     </signals>
   </object>
-  <object type="LongoMatch.Gui.Component.TagsTreeWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
+  <object type="LongoMatch.Gui.Component.ProjectListWidget" palette-category="LongoMatch" allow-children="false" base-type="Gtk.Bin">
     <itemgroups />
     <signals>
-      <itemgroup label="TagsTreeWidget Signals">
-        <signal name="TimeNodeSelected" />
-        <signal name="TimeNodeChanged" />
-        <signal name="PlayListNodeAdded" />
-        <signal name="SnapshotSeriesEvent" />
+      <itemgroup label="ProjectListWidget Signals">
+        <signal name="ProjectsSelected" />
       </itemgroup>
     </signals>
   </object>



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