[longomatch] Add SortingFunction property to SectionsTimeNode



commit 0190083b75a6a95ee3f7807f9e2769feff306768
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Mon Jan 4 22:46:38 2010 +0100

    Add SortingFunction property to SectionsTimeNode

 LongoMatch/IO/SectionsReader.cs     |    5 ++
 LongoMatch/IO/SectionsWriter.cs     |    3 +
 LongoMatch/Time/SectionsTimeNode.cs |   71 +++++++++++++++++++++++++++++++----
 3 files changed, 71 insertions(+), 8 deletions(-)
---
diff --git a/LongoMatch/IO/SectionsReader.cs b/LongoMatch/IO/SectionsReader.cs
index f9862b8..b601473 100644
--- a/LongoMatch/IO/SectionsReader.cs
+++ b/LongoMatch/IO/SectionsReader.cs
@@ -71,6 +71,10 @@ namespace LongoMatch.IO
 			hotkey.Key = (Gdk.Key)GetIntValue("configuration","Key"+(section));
 			return hotkey;
 		}
+		
+		private String GetSortMethod(int section) {
+			return GetStringValue("configuration","SortMethod"+(section));
+		}
 
 		#endregion
 
@@ -84,6 +88,7 @@ namespace LongoMatch.IO
 				name = GetName(i);
 				if (name != null) {
 					tn = new SectionsTimeNode(name, GetStartTime(i), GetStopTime(i), GetHotKey(i), GetColor(i));
+					tn.SortingMethodString = GetSortMethod(i);
 					sections.AddSection(tn);
 				}
 				else tryNext=false;
diff --git a/LongoMatch/IO/SectionsWriter.cs b/LongoMatch/IO/SectionsWriter.cs
index 1527507..aea8596 100644
--- a/LongoMatch/IO/SectionsWriter.cs
+++ b/LongoMatch/IO/SectionsWriter.cs
@@ -22,6 +22,7 @@ using System;
 using System.Configuration;
 using System.IO;
 using System.Xml;
+using Mono.Unix;
 using LongoMatch.DB;
 using LongoMatch.TimeNodes;
 using Gdk;
@@ -52,6 +53,7 @@ namespace LongoMatch.IO
 				sb.Append("<add key=\"Blue"+i+"\" value=\"0\" />");
 				sb.Append("<add key=\"Modifier"+i+"\" value=\"-1\" />");
 				sb.Append("<add key=\"Key"+i+"\" value=\"-1\" />");
+				sb.Append("<add key=\"SortMethod"+i+"\" value=\""+Catalog.GetString("Sort by name")+"\" />");
 			}
 
 			sb.Append("</configuration>");
@@ -90,6 +92,7 @@ namespace LongoMatch.IO
 				sb.Append(String.Format("<add key=\"Blue{0}\" value=\"{1}\" />",i,tn.Color.Blue));
 				sb.Append(String.Format("<add key=\"Modifier{0}\" value=\"{1}\" />",i,(int)(tn.HotKey.Modifier)));
 				sb.Append(String.Format("<add key=\"Key{0}\" value=\"{1}\" />",i,(int)(tn.HotKey.Key)));
+				sb.Append(String.Format("<add key=\"SortMethod{0}\" value=\"{1}\" />",i,tn.SortingMethodString));
 				i++;
 			}
 			sb.Append("</configuration>");
diff --git a/LongoMatch/Time/SectionsTimeNode.cs b/LongoMatch/Time/SectionsTimeNode.cs
index 78b243d..7d93577 100644
--- a/LongoMatch/Time/SectionsTimeNode.cs
+++ b/LongoMatch/Time/SectionsTimeNode.cs
@@ -21,6 +21,7 @@
 using System;
 using System.Runtime.Serialization;
 using Gdk;
+using Mono.Unix;
 
 namespace LongoMatch.TimeNodes
 {
@@ -32,9 +33,18 @@ namespace LongoMatch.TimeNodes
 	[Serializable]
 	public class SectionsTimeNode:TimeNode, ISerializable
 	{
-		HotKey hotkey;
-		Gdk.Color color;
-
+		public enum SortMethod{
+			BY_NAME = 0,
+			BY_START_TIME = 1,
+			BY_STOP_TIME = 2,
+			BY_DURATION = 3
+		}
+		
+		private HotKey hotkey;
+		private Gdk.Color color;
+		private SortMethod sortMethod;
+		
+		
 		#region Constructors
 		/// <summary>
 		/// Creates a new category
@@ -58,6 +68,7 @@ namespace LongoMatch.TimeNodes
 		{
 			this.hotkey = hotkey;
 			this.color = color;
+			this.sortMethod = SortMethod.BY_NAME;
 		}
 		
 		// this constructor is automatically called during deserialization
@@ -81,10 +92,10 @@ namespace LongoMatch.TimeNodes
 		/// </value>
 		public HotKey HotKey {
 			get {
-				return this.hotkey;
+				return hotkey;
 			}
 			set {
-				this.hotkey = value;
+				hotkey = value;
 			}
 		}
 
@@ -93,13 +104,57 @@ namespace LongoMatch.TimeNodes
 		/// </value>
 		public Color Color {
 			get {
-				return this.color;
+				return color;
 			}
 			set {
-				this.color=value;
+				color=value;
+			}
+		}
+		
+		//// <value>
+		/// Sort method used to sort plays for this category 
+		/// </value>
+		public SortMethod SortingMethod{
+			get{
+				// New in 0.15.6
+				try{
+					return sortMethod;
+				}
+				catch{
+					return SortMethod.BY_NAME;
+				}
+			}
+			set{
+				this.sortMethod = value;
+			}			
+		}
+			
+		public string SortingMethodString{
+			get{
+				switch (sortMethod){
+					case SortMethod.BY_NAME:
+						return Catalog.GetString("Sort by name");
+					case SortMethod.BY_START_TIME:
+						return Catalog.GetString("Sort by start time");
+					case SortMethod.BY_STOP_TIME:
+						return Catalog.GetString("Sort by stop time");
+					case SortMethod.BY_DURATION:
+						return Catalog.GetString("Sort by duration");
+					default:
+						return Catalog.GetString("Sort by name");
+				}						
+			}
+			set{			
+				if (value == Catalog.GetString("Sort by start time"))
+					sortMethod = SortMethod.BY_START_TIME;
+				else if (value == Catalog.GetString("Sort by stop time"))
+					sortMethod = SortMethod.BY_STOP_TIME;
+				else if (value == Catalog.GetString("Sort by duration"))
+					sortMethod = SortMethod.BY_DURATION;
+				else
+					sortMethod = SortMethod.BY_NAME;
 			}
 		}
-				
 		// this method is automatically called during serialization
 		public void GetObjectData(SerializationInfo info, StreamingContext context) {
 			info.AddValue("name", Name);



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