gnome-subtitles r1114 - trunk/src/GnomeSubtitles/Core



Author: pcastro
Date: Fri Jan  9 23:07:08 2009
New Revision: 1114
URL: http://svn.gnome.org/viewvc/gnome-subtitles?rev=1114&view=rev

Log:
Improved feature that allows to synchronize subtitles using multiple 
sync points.


Added:
   trunk/src/GnomeSubtitles/Core/SyncPoints.cs

Added: trunk/src/GnomeSubtitles/Core/SyncPoints.cs
==============================================================================
--- (empty file)
+++ trunk/src/GnomeSubtitles/Core/SyncPoints.cs	Fri Jan  9 23:07:08 2009
@@ -0,0 +1,108 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2008 Pedro Castro
+ *
+ * Gnome Subtitles is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Gnome Subtitles is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+using Gtk;
+using SubLib.Core.Domain;
+using System.Collections;
+
+namespace GnomeSubtitles.Core {
+
+public class SyncPoints {
+	private ListStore model = new ListStore(typeof(SyncPoint));
+	private SubLib.Core.Domain.SyncPoints collection = new SubLib.Core.Domain.SyncPoints();
+	
+	
+	public SyncPoints () : base() {
+		LoadModelFromCollection();
+	}
+	
+	/* Indexers */
+	
+	public SyncPoint this [TreeIter iter] {
+		get { return model.GetValue(iter, 0) as SyncPoint; }
+	}
+
+	public SyncPoint this [TreePath path] {
+		get { return collection[path.Indices[0]]; }
+	}
+	
+	/* Public properties */
+
+	public ListStore Model {
+		get { return model; }
+	}
+	
+	public SubLib.Core.Domain.SyncPoints Collection {
+		get { return collection; }
+	}
+	
+	/* Public methods */
+	
+	public void InsertSorted (SyncPoint syncPoint) {
+		for (int index = 0 ; index < collection.Count ; index++) {
+			SyncPoint existing = collection[index] as SyncPoint;
+			if (syncPoint.SubtitleNumber == existing.SubtitleNumber) { //Found an existing sync point for this subtitle number
+				Replace(index, syncPoint);
+				return;
+			}
+			else if (syncPoint.SubtitleNumber < existing.SubtitleNumber) { //The new sync point comes before the current
+				Insert(index, syncPoint);
+				return;
+			}
+		}
+		/* Inserting in the end */
+		Add(syncPoint);
+	}
+	
+	public IEnumerator GetEnumerator () {
+		return collection.GetEnumerator();
+	}
+	
+
+	/* Private members */
+
+	private void LoadModelFromCollection () {
+		model.Clear();
+		foreach (SyncPoint syncPoint in collection) {
+			model.AppendValues(syncPoint);
+		}
+	}
+	
+		
+	private void Insert (int index, SyncPoint syncPoint) {
+		collection.Insert(index, syncPoint);
+		model.SetValue(model.Insert(index), 0, syncPoint);
+	}
+	
+	private void Replace (int index, SyncPoint syncPoint) {
+		collection.Replace(index, syncPoint);
+		
+		TreeIter iter;
+		model.GetIterFromString(out iter, index.ToString());
+		model.SetValue(iter, 0, syncPoint);
+	}
+	
+	private void Add (SyncPoint syncPoint) {
+		collection.Add(syncPoint);
+		model.AppendValues(syncPoint);
+	}
+
+}
+
+}



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