gnome-subtitles r1105 - in trunk: . src/Glade src/GnomeSubtitles/Core src/GnomeSubtitles/Dialog src/GnomeSubtitles/Execution src/GnomeSubtitles/Ui src/GnomeSubtitles/Ui/View



Author: pcastro
Date: Wed Dec 31 01:37:15 2008
New Revision: 1105
URL: http://svn.gnome.org/viewvc/gnome-subtitles?rev=1105&view=rev

Log:
Improved the Timings Synchronization functionality, allowing to set the 
sync points in the synchronization dialog. 


Added:
   trunk/src/GnomeSubtitles/Dialog/SyncPoints.cs
   trunk/src/GnomeSubtitles/Execution/AssemblyInfo.cs
Modified:
   trunk/gnome-subtitles.mdp
   trunk/src/Glade/MainWindow.glade
   trunk/src/Glade/TimingsSynchronizeDialog.glade
   trunk/src/GnomeSubtitles/Core/EventHandlers.cs
   trunk/src/GnomeSubtitles/Core/Util.cs
   trunk/src/GnomeSubtitles/Dialog/Dialogs.cs
   trunk/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs
   trunk/src/GnomeSubtitles/Ui/Menus.cs
   trunk/src/GnomeSubtitles/Ui/View/SubtitleView.cs
   trunk/src/GnomeSubtitles/Ui/WidgetNames.cs

Modified: trunk/gnome-subtitles.mdp
==============================================================================
--- trunk/gnome-subtitles.mdp	(original)
+++ trunk/gnome-subtitles.mdp	Wed Dec 31 01:37:15 2008
@@ -138,6 +138,7 @@
     <File name="src/GnomeSubtitles/Ui/VideoPreview/Exceptions/PlayerCouldNotInitiateEngineException.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Execution/ConfigureDefines.cs" subtype="Code" buildaction="Compile" />
     <File name="src/GnomeSubtitles/Ui/VideoPreview/SubtitleOverlay.cs" subtype="Code" buildaction="Compile" />
+    <File name="src/GnomeSubtitles/Dialog/SyncPoints.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="gtk-sharp, Version=2.8.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />

Modified: trunk/src/Glade/MainWindow.glade
==============================================================================
--- trunk/src/Glade/MainWindow.glade	(original)
+++ trunk/src/Glade/MainWindow.glade	Wed Dec 31 01:37:15 2008
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Sun Nov 23 16:19:23 2008 
+<!--Generated with glade3 3.4.5 on Tue Dec 30 22:22:11 2008 
 	Version: 3.0.1
 	Date: Thu Dec  7 16:42:10 2006
 	User: noup
@@ -233,8 +233,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                         <signal name="activate" handler="OnEditRedo"/>
-                        <accelerator key="Y" modifiers="GDK_CONTROL_MASK" signal="activate"/>
                         <accelerator key="Z" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK" signal="activate"/>
+                        <accelerator key="Y" modifiers="GDK_CONTROL_MASK" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -512,8 +512,8 @@
                         <property name="label" translatable="yes">Find Ne_xt</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindNext"/>
-                        <accelerator key="F3" modifiers="" signal="activate"/>
                         <accelerator key="G" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+                        <accelerator key="F3" modifiers="" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -523,8 +523,8 @@
                         <property name="label" translatable="yes">Find Pre_vious</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnSearchFindPrevious"/>
-                        <accelerator key="F3" modifiers="GDK_SHIFT_MASK" signal="activate"/>
                         <accelerator key="G" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK" signal="activate"/>
+                        <accelerator key="F3" modifiers="GDK_SHIFT_MASK" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -701,6 +701,7 @@
                     <child>
                       <widget class="GtkMenuItem" id="timingsSynchronize">
                         <property name="visible">True</property>
+                        <property name="sensitive">False</property>
                         <property name="label" translatable="yes">_Synchronize</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnTimingsSynchronize"/>
@@ -777,8 +778,8 @@
                         <property name="label" translatable="yes">_Play / Pause</property>
                         <property name="use_underline">True</property>
                         <signal name="activate" handler="OnVideoPlayPause"/>
-                        <accelerator key="F5" modifiers="" signal="activate"/>
                         <accelerator key="P" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+                        <accelerator key="F5" modifiers="" signal="activate"/>
                         <child internal-child="image">
                           <widget class="GtkImage" id="videoPlayPauseImage">
                             <property name="visible">True</property>
@@ -797,8 +798,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                         <signal name="activate" handler="OnVideoRewind"/>
-                        <accelerator key="F6" modifiers="" signal="activate"/>
                         <accelerator key="K" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+                        <accelerator key="F6" modifiers="" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -809,8 +810,8 @@
                         <property name="use_underline">True</property>
                         <property name="use_stock">True</property>
                         <signal name="activate" handler="OnVideoForward"/>
-                        <accelerator key="F7" modifiers="" signal="activate"/>
                         <accelerator key="L" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+                        <accelerator key="F7" modifiers="" signal="activate"/>
                       </widget>
                     </child>
                     <child>
@@ -1527,39 +1528,31 @@
                         <property name="n_columns">2</property>
                         <property name="row_spacing">2</property>
                         <child>
-                          <widget class="GtkLabel" id="startLabel">
-                            <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes" comments="This is the start time/frame of a subtitle.">From:</property>
-                          </widget>
-                          <packing>
-                            <property name="x_options">GTK_FILL</property>
-                            <property name="y_options"></property>
-                          </packing>
-                        </child>
-                        <child>
-                          <widget class="GtkLabel" id="endLabel">
+                          <widget class="GtkSpinButton" id="startSpinButton">
                             <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes" comments="This is the end time/frame of a subtitle.">To:</property>
+                            <property name="can_focus">True</property>
+                            <property name="adjustment">0 0 100 1 10 0</property>
+                            <property name="climb_rate">1</property>
+                            <property name="numeric">True</property>
                           </widget>
                           <packing>
-                            <property name="top_attach">1</property>
-                            <property name="bottom_attach">2</property>
-                            <property name="x_options">GTK_FILL</property>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
                             <property name="y_options"></property>
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="durationLabel">
+                          <widget class="GtkSpinButton" id="durationSpinButton">
                             <property name="visible">True</property>
-                            <property name="xalign">0</property>
-                            <property name="label" translatable="yes" comments="This is the duration of a subtitle.">During:</property>
+                            <property name="can_focus">True</property>
+                            <property name="adjustment">0 0 100 1 10 0</property>
+                            <property name="climb_rate">1</property>
                           </widget>
                           <packing>
+                            <property name="left_attach">1</property>
+                            <property name="right_attach">2</property>
                             <property name="top_attach">2</property>
                             <property name="bottom_attach">3</property>
-                            <property name="x_options">GTK_FILL</property>
                             <property name="y_options"></property>
                           </packing>
                         </child>
@@ -1579,31 +1572,39 @@
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkSpinButton" id="durationSpinButton">
+                          <widget class="GtkLabel" id="durationLabel">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="adjustment">0 0 100 1 10 0</property>
-                            <property name="climb_rate">1</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes" comments="This is the duration of a subtitle.">During:</property>
                           </widget>
                           <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
                             <property name="top_attach">2</property>
                             <property name="bottom_attach">3</property>
+                            <property name="x_options">GTK_FILL</property>
                             <property name="y_options"></property>
                           </packing>
                         </child>
                         <child>
-                          <widget class="GtkSpinButton" id="startSpinButton">
+                          <widget class="GtkLabel" id="endLabel">
                             <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="adjustment">0 0 100 1 10 0</property>
-                            <property name="climb_rate">1</property>
-                            <property name="numeric">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes" comments="This is the end time/frame of a subtitle.">To:</property>
                           </widget>
                           <packing>
-                            <property name="left_attach">1</property>
-                            <property name="right_attach">2</property>
+                            <property name="top_attach">1</property>
+                            <property name="bottom_attach">2</property>
+                            <property name="x_options">GTK_FILL</property>
+                            <property name="y_options"></property>
+                          </packing>
+                        </child>
+                        <child>
+                          <widget class="GtkLabel" id="startLabel">
+                            <property name="visible">True</property>
+                            <property name="xalign">0</property>
+                            <property name="label" translatable="yes" comments="This is the start time/frame of a subtitle.">From:</property>
+                          </widget>
+                          <packing>
+                            <property name="x_options">GTK_FILL</property>
                             <property name="y_options"></property>
                           </packing>
                         </child>

Modified: trunk/src/Glade/TimingsSynchronizeDialog.glade
==============================================================================
--- trunk/src/Glade/TimingsSynchronizeDialog.glade	(original)
+++ trunk/src/Glade/TimingsSynchronizeDialog.glade	Wed Dec 31 01:37:15 2008
@@ -1,12 +1,14 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
-<!--Generated with glade3 3.4.5 on Sat Oct  4 21:44:06 2008 -->
+<!--Generated with glade3 3.4.5 on Tue Dec 30 22:57:54 2008 -->
 <glade-interface>
   <widget class="GtkDialog" id="dialog">
     <property name="border_width">5</property>
+    <property name="title" translatable="yes">Synchronize Timings</property>
     <property name="window_position">GTK_WIN_POS_CENTER_ON_PARENT</property>
     <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
     <property name="has_separator">False</property>
+    <signal name="response" handler="OnResponse"/>
     <child internal-child="vbox">
       <widget class="GtkVBox" id="dialogVBox">
         <property name="visible">True</property>
@@ -28,10 +30,17 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkTreeView" id="treeview1">
+              <widget class="GtkScrolledWindow" id="scrolledwindow1">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="headers_clickable">True</property>
+                <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property>
+                <child>
+                  <widget class="GtkTreeView" id="tree">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                  </widget>
+                </child>
               </widget>
               <packing>
                 <property name="position">1</property>
@@ -41,24 +50,25 @@
               <widget class="GtkHBox" id="hbox1">
                 <property name="visible">True</property>
                 <child>
-                  <widget class="GtkButton" id="button1">
+                  <widget class="GtkButton" id="buttonAdd">
                     <property name="visible">True</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="response_id">0</property>
+                    <signal name="clicked" handler="OnAdd"/>
                     <child>
-                      <widget class="GtkHBox" id="hbox2">
+                      <widget class="GtkHBox" id="buttonAddHBox">
                         <property name="visible">True</property>
                         <child>
-                          <widget class="GtkImage" id="image1">
+                          <widget class="GtkImage" id="buttonAddImage">
                             <property name="visible">True</property>
                             <property name="stock">gtk-add</property>
                           </widget>
                         </child>
                         <child>
-                          <widget class="GtkLabel" id="label1">
+                          <widget class="GtkLabel" id="buttonAddLabel">
                             <property name="visible">True</property>
-                            <property name="label" translatable="yes">Add from video</property>
+                            <property name="label" translatable="yes">Add sync point</property>
                           </widget>
                           <packing>
                             <property name="position">1</property>
@@ -73,13 +83,15 @@
                   </packing>
                 </child>
                 <child>
-                  <widget class="GtkButton" id="button2">
+                  <widget class="GtkButton" id="removeButton">
                     <property name="visible">True</property>
+                    <property name="sensitive">False</property>
                     <property name="can_focus">True</property>
                     <property name="receives_default">True</property>
                     <property name="label" translatable="yes">gtk-remove</property>
                     <property name="use_stock">True</property>
                     <property name="response_id">0</property>
+                    <signal name="clicked" handler="OnRemove"/>
                   </widget>
                   <packing>
                     <property name="expand">False</property>
@@ -90,14 +102,14 @@
                 </child>
               </widget>
               <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
                 <property name="pack_type">GTK_PACK_END</property>
                 <property name="position">2</property>
               </packing>
             </child>
           </widget>
           <packing>
-            <property name="expand">False</property>
-            <property name="fill">False</property>
             <property name="position">1</property>
           </packing>
         </child>
@@ -106,13 +118,13 @@
             <property name="visible">True</property>
             <property name="layout_style">GTK_BUTTONBOX_END</property>
             <child>
-              <widget class="GtkButton" id="button3">
+              <widget class="GtkButton" id="buttonClose">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
-                <property name="label" translatable="yes">gtk-cancel</property>
+                <property name="label" translatable="yes">gtk-close</property>
                 <property name="use_stock">True</property>
-                <property name="response_id">0</property>
+                <property name="response_id">-7</property>
               </widget>
               <packing>
                 <property name="expand">False</property>
@@ -120,13 +132,13 @@
               </packing>
             </child>
             <child>
-              <widget class="GtkButton" id="button4">
+              <widget class="GtkButton" id="buttonSynchronize">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">True</property>
                 <property name="label" translatable="yes">gtk-ok</property>
                 <property name="use_stock">True</property>
-                <property name="response_id">0</property>
+                <property name="response_id">-5</property>
               </widget>
               <packing>
                 <property name="expand">False</property>

Modified: trunk/src/GnomeSubtitles/Core/EventHandlers.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/EventHandlers.cs	(original)
+++ trunk/src/GnomeSubtitles/Core/EventHandlers.cs	Wed Dec 31 01:37:15 2008
@@ -217,7 +217,7 @@
 	}
 	
 	public void OnTimingsSynchronize (object o, EventArgs args) {
-		Base.Dialogs.TimingsSynchronizeDialog.Show();
+		new TimingsSynchronizeDialog().Show();
 	}
 	
 	

Modified: trunk/src/GnomeSubtitles/Core/Util.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Core/Util.cs	(original)
+++ trunk/src/GnomeSubtitles/Core/Util.cs	Wed Dec 31 01:37:15 2008
@@ -28,6 +28,26 @@
 
 public class Util {
   
+  	//TODO move to other util?
+  	public static int ColumnWidth (Widget widget, string text) {
+  		int margins = 10;
+  		return TextWidth(widget, text, margins); 
+    }
+    
+    public static TreeViewColumn CreateTreeViewColumn (string title, int width, CellRenderer cell, TreeCellDataFunc dataFunction) {
+		cell.Xalign = 0.5f;
+		cell.Yalign = 0;
+		TreeViewColumn column = new TreeViewColumn();
+		column.Alignment = 0.5f;
+		column.Title = title;
+		column.FixedWidth = width;
+		column.Sizing = TreeViewColumnSizing.Fixed;
+		column.Resizable = true;
+		column.PackStart(cell, true);
+		column.SetCellDataFunc(cell, dataFunction);
+		return column;
+	}
+  
     public static int TextWidth (Widget widget, string text, int margins) {
     	Pango.Layout layout = widget.CreatePangoLayout(text);
     	int width, height;

Modified: trunk/src/GnomeSubtitles/Dialog/Dialogs.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Dialog/Dialogs.cs	(original)
+++ trunk/src/GnomeSubtitles/Dialog/Dialogs.cs	Wed Dec 31 01:37:15 2008
@@ -26,7 +26,6 @@
 	private FileSaveAsDialog translationSaveAsDialog = null;
 	private SearchDialog searchDialog = null;
 	private TimingsShiftDialog timingsShiftDialog = null;
-	private TimingsSynchronizeDialog timingsSynchronizeDialog = null;
 	
 	public FileSaveAsDialog FileSaveAsDialog {
 		get {
@@ -64,17 +63,6 @@
 		}
 	}
 
-	public TimingsSynchronizeDialog TimingsSynchronizeDialog {
-		get {
-			if (timingsSynchronizeDialog == null)
-				timingsSynchronizeDialog = new TimingsSynchronizeDialog();
-			
-			return timingsSynchronizeDialog;		
-		}
-	}
-
-
-
 }
 
 }
\ No newline at end of file

Added: trunk/src/GnomeSubtitles/Dialog/SyncPoints.cs
==============================================================================
--- (empty file)
+++ trunk/src/GnomeSubtitles/Dialog/SyncPoints.cs	Wed Dec 31 01:37:15 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.Dialog {
+
+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);
+		System.Console.WriteLine("Inserted at " + index); //TODO remove
+	}
+	
+	private void Replace (int index, SyncPoint syncPoint) {
+		collection.Replace(index, syncPoint);
+		
+		TreeIter iter;
+		model.GetIterFromString(out iter, index.ToString());
+		model.SetValue(iter, 0, syncPoint);
+		System.Console.WriteLine("Replaced at " + index); //TODO remove
+	}
+	
+	private void Add (SyncPoint syncPoint) {
+		collection.Add(syncPoint);
+		model.AppendValues(syncPoint);
+	}
+
+}
+
+}

Modified: trunk/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs	(original)
+++ trunk/src/GnomeSubtitles/Dialog/TimingsSynchronizeDialog.cs	Wed Dec 31 01:37:15 2008
@@ -17,26 +17,122 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+using Glade;
+using GnomeSubtitles.Core;
 using Gtk;
+using Mono.Unix;
+using SubLib.Core.Domain;
+using System;
 
 namespace GnomeSubtitles.Dialog {
 
-
 public class TimingsSynchronizeDialog : GladeDialog {
-	
+	private TimingMode timingMode = TimingMode.Times; 
+	private SyncPoints syncPoints = new SyncPoints();
+	private TreeViewColumn numberCol = null;
+	private TreeViewColumn currentStartCol = null;
+	private TreeViewColumn correctStartCol = null;
+		
 	/* Constant strings */
 	private const string gladeFilename = "TimingsSynchronizeDialog.glade";
 	
 	/* Widgets */
+	[WidgetAttribute] private TreeView tree = null;
 
 	public TimingsSynchronizeDialog () : base(gladeFilename){
+		CreateColumns();
+		SetModel();
+		ConnectHandlers();
+	}
 	
+	/* Private methods */
+	
+	private void CreateColumns() {
+    	/* Number column */
+    	numberCol = Core.Util.CreateTreeViewColumn(Catalog.GetString("No."), Core.Util.ColumnWidth(tree, "000"), new CellRendererText(), RenderSubtitleNumberCell);
+    	
+    	/* Start (current and correct) columns */
+    	int timeWidth = Core.Util.ColumnWidth(tree, "00:00:00.000");
+    	currentStartCol = Core.Util.CreateTreeViewColumn(Catalog.GetString("Current Start"), timeWidth, new CellRendererText(), RenderCurrentStartCell);
+    	correctStartCol = Core.Util.CreateTreeViewColumn(Catalog.GetString("Correct Start"), timeWidth, new CellRendererText(), RenderCorrectStartCell);
+
+    	tree.AppendColumn(numberCol);
+    	tree.AppendColumn(currentStartCol);
+    	tree.AppendColumn(correctStartCol);
+
+    	tree.AppendColumn(new TreeViewColumn()); //Appending to leave empty space to the right
+    }
+    
+    private void SetModel () {
+		tree.Model = syncPoints.Model;
+	}
+    
+    /* Cell Renderers */
+
+	private void RenderSubtitleNumberCell (TreeViewColumn column, CellRenderer cell, TreeModel treeModel, TreeIter iter) {
+		(cell as CellRendererText).Text = (syncPoints[iter].SubtitleNumber + 1).ToString();
 	}
+
+	private void RenderCurrentStartCell (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) {
+		CellRendererText renderer = cell as CellRendererText;
+		if (timingMode == TimingMode.Frames)
+			renderer.Text = syncPoints[iter].Current.Frame.ToString();
+		else
+			renderer.Text = Core.Util.TimeSpanToText(syncPoints[iter].Current.Time);
+	}
+	
+	private void RenderCorrectStartCell (TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) {
+		CellRendererText renderer = cell as CellRendererText;
+		if (timingMode == TimingMode.Frames)
+			renderer.Text = syncPoints[iter].Correct.Frame.ToString();
+		else
+			renderer.Text = Core.Util.TimeSpanToText(syncPoints[iter].Correct.Time);
+	}
+	
+	/* Event members */
 	
+	#pragma warning disable 169		//Disables warning about handlers not being used
+	
+	private void ConnectHandlers () {
+		tree.Selection.Changed += OnSelectionChanged;
+	}
+	
+	private void OnSelectionChanged (object o, EventArgs args) {
+		System.Console.WriteLine(o);
+	}
+	
+	private void OnAdd (object o, EventArgs args) {
+		/* Check if document and video are loaded */
+		if (!(Base.IsDocumentLoaded && Base.Ui.Video.IsLoaded))
+			return;
+	
+		/* Get selected subtitle */
+		TreePath[] selectedPaths = Base.Ui.View.Selection.Paths;
+		if (selectedPaths.Length != 1)
+			return;
+		
+		TreePath path = selectedPaths[0];
+		int subtitleNumber = Core.Util.PathToInt(path);
+		Subtitle subtitle = Base.Ui.View.Selection.Subtitle;
+		
+		/* Get current start */
+		Timing currentTiming = new Timing(subtitle.Frames.Start, subtitle.Times.Start);
+		
+		/* Get correct start from video */
+		Timing correctTiming = new Timing(Base.Ui.Video.Position.CurrentFrames, Base.Ui.Video.Position.CurrentTime);
+
+		/* Create and add the sync point */
+		SyncPoint syncPoint = new SyncPoint(subtitleNumber, currentTiming, correctTiming);
+		syncPoints.InsertSorted(syncPoint);
+	}
+	
+	private void OnRemove (object o, EventArgs args) {
+		System.Console.WriteLine("Remove");
+	}
 	
 	private void OnResponse (object o, ResponseArgs args) {
-		/*if (args.ResponseId == ResponseType.Ok) {
-			SelectionIntended selectionIntended = (allSubtitlesRadioButton.Active ? SelectionIntended.All : SelectionIntended.Range);
+		if (args.ResponseId == ResponseType.Ok) {
+		/*	SelectionIntended selectionIntended = (allSubtitlesRadioButton.Active ? SelectionIntended.All : SelectionIntended.Range);
 			
 			if (timingMode == TimingMode.Times) {
 				TimeSpan firstTime = TimeSpan.Parse(firstSubtitleNewStartSpinButton.Text);
@@ -47,9 +143,11 @@
 				int firstFrame = (int)firstSubtitleNewStartSpinButton.Value;
 				int lastFrame = (int)lastSubtitleNewStartSpinButton.Value;
 				Base.CommandManager.Execute(new AdjustTimingsCommand(firstFrame, lastFrame, selectionIntended));
-			}
-		}*/
-		Close();
+			}*/
+		}
+		else {
+			Close();
+		}
 	}
 
 }

Added: trunk/src/GnomeSubtitles/Execution/AssemblyInfo.cs
==============================================================================
--- (empty file)
+++ trunk/src/GnomeSubtitles/Execution/AssemblyInfo.cs	Wed Dec 31 01:37:15 2008
@@ -0,0 +1,27 @@
+/*
+ * This file is part of Gnome Subtitles.
+ * Copyright (C) 2006-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 System.Reflection;
+using System.Runtime.CompilerServices;
+
+[assembly: AssemblyVersion("0.9")]
+[assembly: AssemblyTitle ("Gnome Subtitles")]
+[assembly: AssemblyDescription ("Video subtitling for the GNOME desktop")]
+[assembly: AssemblyCopyright ("Copyright (c) 2006-2008 Pedro Castro")]
+

Modified: trunk/src/GnomeSubtitles/Ui/Menus.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/Menus.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/Menus.cs	Wed Dec 31 01:37:15 2008
@@ -257,6 +257,8 @@
 		SetSensitivity(WidgetNames.SearchFindNext, false);
 		SetSensitivity(WidgetNames.SearchFindPrevious, false);
 		SetSensitivity(WidgetNames.SearchReplace, false);
+		/* Timings Menu */
+		SetSensitivity(WidgetNames.TimingsSynchronize, false);
 		/* Tools Menu */
 		SetToolsAutocheckSpellingSensitivity(false);
 		/* Toolbar */
@@ -295,6 +297,8 @@
 			/* Search Menu */
 			SetSensitivity(WidgetNames.SearchFind, true);
 			SetSensitivity(WidgetNames.SearchReplace, true);
+			/* Timings Menu */
+			SetSensitivity(WidgetNames.TimingsSynchronize, true);
 			/* Tools Menu */
 			SetSensitivity(WidgetNames.ToolsSetTextLanguage, true);
 			SetSensitivity(WidgetNames.ToolsSetTranslationLanguage, false);

Modified: trunk/src/GnomeSubtitles/Ui/View/SubtitleView.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/View/SubtitleView.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/View/SubtitleView.cs	Wed Dec 31 01:37:15 2008
@@ -223,24 +223,24 @@
 	
     private void CreateColumns() {
     	/* Number column */
-    	numberCol = CreateColumn(Catalog.GetString("No."), ColumnWidth("000"), new CellRendererText(), RenderNumberCell);
+    	numberCol = Util.CreateTreeViewColumn(Catalog.GetString("No."), Util.ColumnWidth(tree, "000"), new CellRendererText(), RenderNumberCell);
     	
     	/* Start, end and duration columns */
-    	int timeWidth = ColumnWidth("00:00:00.000");
-    	startCol = CreateColumn(Catalog.GetString("From"), timeWidth, new CellRendererText(), RenderStartCell);
-    	endCol = CreateColumn(Catalog.GetString("To"), timeWidth, new CellRendererText(), RenderEndCell);
-    	durationCol = CreateColumn(Catalog.GetString("During"), timeWidth, new CellRendererText(), RenderDurationCell);
+    	int timeWidth = Util.ColumnWidth(tree, "00:00:00.000");
+    	startCol = Util.CreateTreeViewColumn(Catalog.GetString("From"), timeWidth, new CellRendererText(), RenderStartCell);
+    	endCol = Util.CreateTreeViewColumn(Catalog.GetString("To"), timeWidth, new CellRendererText(), RenderEndCell);
+    	durationCol = Util.CreateTreeViewColumn(Catalog.GetString("During"), timeWidth, new CellRendererText(), RenderDurationCell);
     	
     	/* Text column */
-    	int textWidth = ColumnWidth("0123456789012345678901234567890123456789");
+    	int textWidth = Util.ColumnWidth(tree, "0123456789012345678901234567890123456789");
     	CellRendererText textCellRenderer = new CellRendererText();
     	textCellRenderer.Alignment = Pango.Alignment.Center;
-    	textCol = CreateColumn(Catalog.GetString("Text"), textWidth, textCellRenderer, RenderTextCell);
+    	textCol = Util.CreateTreeViewColumn(Catalog.GetString("Text"), textWidth, textCellRenderer, RenderTextCell);
     	
     	/* Translation column */
     	CellRendererText translationCellRenderer = new CellRendererText();
     	translationCellRenderer.Alignment = Pango.Alignment.Center;
-    	translationCol = CreateColumn(Catalog.GetString("Translation"), textWidth, translationCellRenderer, RenderTranslationCell);
+    	translationCol = Util.CreateTreeViewColumn(Catalog.GetString("Translation"), textWidth, translationCellRenderer, RenderTranslationCell);
     	SetTranslationVisible(false);
 
     	tree.AppendColumn(numberCol);
@@ -251,25 +251,6 @@
     	tree.AppendColumn(translationCol);
     	tree.AppendColumn(new TreeViewColumn()); //Appending to leave empty space to the right 
     }
-
-	private TreeViewColumn CreateColumn (string title, int width, CellRenderer cell, TreeCellDataFunc dataFunction) {
-		cell.Xalign = 0.5f;
-		cell.Yalign = 0;
-		TreeViewColumn column = new TreeViewColumn();
-		column.Alignment = 0.5f;
-		column.Title = title;
-		column.FixedWidth = width;
-		column.Sizing = TreeViewColumnSizing.Fixed;
-		column.Resizable = true;
-		column.PackStart(cell, true);
-		column.SetCellDataFunc(cell, dataFunction);
-		return column;
-	}
-
-	private int ColumnWidth (string text) {
-		const int margins = 10;
-		return Util.TextWidth(tree, text, margins);
-	}
 	
 	private void SetTranslationVisible (bool visible) {
 		translationCol.Visible = visible;

Modified: trunk/src/GnomeSubtitles/Ui/WidgetNames.cs
==============================================================================
--- trunk/src/GnomeSubtitles/Ui/WidgetNames.cs	(original)
+++ trunk/src/GnomeSubtitles/Ui/WidgetNames.cs	Wed Dec 31 01:37:15 2008
@@ -67,6 +67,7 @@
 	/* Timings Menu */
 	public const string TimingsInputFrameRateMenu = "timingsInputFrameRateMenu";
 	public const string TimingsVideoFrameRateMenu = "timingsVideoFrameRateMenu";
+	public const string TimingsSynchronize = "timingsSynchronize";
 	public const string TimingsAdjust = "timingsAdjust";
 	public const string TimingsShift = "timingsShift";
 	



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