[gnome-subtitles] Allow to rewind the video a specific time (set in gconf) when seeking after changing subtitles (curr



commit d083f70b58c5902d10cd37cdfe8b74ad9e3e7171
Author: Pedro Castro <mail pedrocastro org>
Date:   Sun Jun 5 23:59:54 2011 +0100

    Allow to rewind the video a specific time (set in gconf) when seeking after changing subtitles (currently works for subtitle start/end change, and shifting.

 data/gnome-subtitles.schemas                       |   22 ++++++++++
 .../Core/Command/ChangeTimingCommand.cs            |    4 +-
 .../Core/Command/ShiftTimingsCommand.cs            |    4 +-
 src/GnomeSubtitles/Core/Config.cs                  |   41 ++++++++++++++++++--
 src/GnomeSubtitles/Ui/VideoPreview/Video.cs        |    8 ++++
 5 files changed, 71 insertions(+), 8 deletions(-)
---
diff --git a/data/gnome-subtitles.schemas b/data/gnome-subtitles.schemas
index 3dd9eb0..21028b3 100644
--- a/data/gnome-subtitles.schemas
+++ b/data/gnome-subtitles.schemas
@@ -58,6 +58,28 @@
 			</locale>
 		</schema>
 		<schema>
+			<key>/schemas/apps/gnome-subtitles/preferences/video/seek_on_change</key>
+			<applyto>/apps/gnome-subtitles/preferences/video/seek_on_change</applyto>
+			<owner>gnome-subtitles</owner>
+			<type>bool</type>
+			<default>TRUE</default>
+			<locale name="C">
+				<short>Seek the video on subtitles change</short>
+				<long>Whether to seek the video to the start of the first subtitle when one or more subtitles are changed.</long>
+			</locale>
+		</schema>
+		<schema>
+			<key>/schemas/apps/gnome-subtitles/preferences/video/seek_on_change_rewind</key>
+			<applyto>/apps/gnome-subtitles/preferences/video/seek_on_change_rewind</applyto>
+			<owner>gnome-subtitles</owner>
+			<type>int</type>
+			<default>500</default>
+			<locale name="C">
+				<short>Seek on change rewind</short>
+				<long>Time, in milliseconds, to rewind the video when seeking on subtitles change.</long>
+			</locale>
+		</schema>
+		<schema>
 			<key>/schemas/apps/gnome-subtitles/preferences/view/line_lengths</key>
 			<applyto>/apps/gnome-subtitles/preferences/view/line_lengths</applyto>
 			<owner>gnome-subtitles</owner>
diff --git a/src/GnomeSubtitles/Core/Command/ChangeTimingCommand.cs b/src/GnomeSubtitles/Core/Command/ChangeTimingCommand.cs
index 8fda56d..633c19d 100644
--- a/src/GnomeSubtitles/Core/Command/ChangeTimingCommand.cs
+++ b/src/GnomeSubtitles/Core/Command/ChangeTimingCommand.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2008 Pedro Castro
+ * Copyright (C) 2006-2008,2011 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
@@ -57,7 +57,7 @@ public abstract class ChangeTimingCommand : FixedSingleSelectionCommand {
 	}
 	
 	protected override void PostProcess () {
-		Base.Ui.Video.SeekToSelection();
+		Base.Ui.Video.SeekToSelection(true);
 	}
 
 	protected abstract TimeSpan GetPreviousTime ();
diff --git a/src/GnomeSubtitles/Core/Command/ShiftTimingsCommand.cs b/src/GnomeSubtitles/Core/Command/ShiftTimingsCommand.cs
index 45a002d..070fa92 100644
--- a/src/GnomeSubtitles/Core/Command/ShiftTimingsCommand.cs
+++ b/src/GnomeSubtitles/Core/Command/ShiftTimingsCommand.cs
@@ -1,6 +1,6 @@
 /*
  * This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2009 Pedro Castro
+ * Copyright (C) 2006-2009,2011 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
@@ -63,7 +63,7 @@ public class ShiftTimingsCommand : FixedMultipleSelectionCommand {
 	}
 	
 	protected override void PostProcess () {
-		Base.Ui.Video.SeekToSelection();
+		Base.Ui.Video.SeekToSelection(true);
 	}
 	
 	/* Private Members */
diff --git a/src/GnomeSubtitles/Core/Config.cs b/src/GnomeSubtitles/Core/Config.cs
index 89deff2..7d627a1 100644
--- a/src/GnomeSubtitles/Core/Config.cs
+++ b/src/GnomeSubtitles/Core/Config.cs
@@ -55,6 +55,8 @@ public class Config {
 	private const string keyPrefsVideoAutoChooseFile = keyPrefsVideo + "auto_choose_file";
 	private const string keyPrefsVideoApplyReactionDelay = keyPrefsVideo + "apply_reaction_delay";
 	private const string keyPrefsVideoReactionDelay = keyPrefsVideo + "reaction_delay";
+	private const string keyPrefsVideoSeekOnChange = keyPrefsVideo + "seek_on_change"; //FIXME add option to the Preferences Dialog
+	private const string keyPrefsVideoSeekOnChangeRewind = keyPrefsVideo + "seek_on_change_rewind";
 	private const string keyPrefsViewLineLengths = keyPrefsView + "line_lengths";
 	private const string keyPrefsSpellCheckActiveTextLanguage = keyPrefsSpellCheck + "active_text_language";
 	private const string keyPrefsSpellCheckActiveTranslationLanguage = keyPrefsSpellCheck + "active_translation_language";
@@ -72,13 +74,16 @@ public class Config {
 	private const string keyPrefsDefaultsFileSaveNewline = keyPrefsDefaults + "file_save_newline";
 	private const string keyPrefsBackupAutoBackup = keyPrefsBackup + "auto_backup";
 	private const string keyPrefsBackupBackupTime = keyPrefsBackup + "backup_time";
-	private const string keyPrefsTimingsTimeStep = keyPrefsTimings + "time_step";
+	private const string keyPrefsTimingsTimeStep = keyPrefsTimings + "time_step"; //FIXME add option to the Preferences Dialog
 	private const string keyPrefsTimingsFramesStep = keyPrefsTimings + "frames_step";
 	
 	/* Cached values */
 	private bool isValuePrefsVideoApplyReactionDelayCached = false;
 	private bool valuePrefsVideoApplyReactionDelay = false;
 	private int valuePrefsVideoReactionDelay = -1;
+	private bool isValuePrefsVideoSeekOnChangeCached = false;
+	private bool valuePrefsVideoSeekOnChange = false;
+	private int valuePrefsVideoSeekOnChangeRewind = -1;
 	private int valuePrefsTimingsTimeStep = -1;
 	private int valuePrefsTimingsFramesStep = -1;
 	
@@ -145,6 +150,35 @@ public class Config {
 		}
 	}
 	
+	public bool PrefsVideoSeekOnChange {
+		get {
+			if (!isValuePrefsVideoSeekOnChangeCached) {
+				this.valuePrefsVideoSeekOnChange = GetBool(keyPrefsVideoSeekOnChange, true);
+				this.isValuePrefsVideoSeekOnChangeCached = true;
+			}
+			return valuePrefsVideoSeekOnChange;
+		}
+		set {
+			Set(keyPrefsVideoSeekOnChange, value);
+			this.valuePrefsVideoSeekOnChange = value;
+			this.isValuePrefsVideoSeekOnChangeCached = true;
+		}
+	}
+
+	//FIXME apply this to other changes
+	public int PrefsVideoSeekOnChangeRewind {
+		get {
+			if (this.valuePrefsVideoSeekOnChangeRewind == -1) {
+				this.valuePrefsVideoSeekOnChangeRewind = GetInt(keyPrefsVideoSeekOnChangeRewind, 500, 0, true, 2000, true);
+			}
+			return this.valuePrefsVideoSeekOnChangeRewind;
+		}
+		set {
+			Set(keyPrefsVideoSeekOnChangeRewind, value);
+			this.valuePrefsVideoSeekOnChangeRewind = value;
+		}
+	}
+	
 	public bool PrefsViewLineLengths {
 		get { return GetBool(keyPrefsViewLineLengths, true); }
 		set { Set(keyPrefsViewLineLengths, value); }
@@ -249,7 +283,7 @@ public class Config {
 	public int PrefsTimingsTimeStep {
 		get {
 			if (this.valuePrefsTimingsTimeStep == -1) {
-				this.valuePrefsTimingsTimeStep = GetInt(keyPrefsTimingsTimeStep, 100, 1, true, 0, false);
+				this.valuePrefsTimingsTimeStep = GetInt(keyPrefsTimingsTimeStep, 100, 1, true, 2000, true);
 			}
 			return this.valuePrefsTimingsTimeStep;
 		}
@@ -259,11 +293,10 @@ public class Config {
 		}
 	}
 	
-	/* Time in milliseconds */
 	public int PrefsTimingsFramesStep {
 		get {
 			if (this.valuePrefsTimingsFramesStep == -1) {
-				this.valuePrefsTimingsFramesStep = GetInt(keyPrefsTimingsFramesStep, 2, 1, true, 0, false);
+				this.valuePrefsTimingsFramesStep = GetInt(keyPrefsTimingsFramesStep, 2, 1, true, 60, true);
 			}
 			return this.valuePrefsTimingsFramesStep;
 		}
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
index a4bb832..2404888 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
@@ -199,8 +199,16 @@ public class Video {
 	}
 	
 	public void SeekToSelection () {
+		SeekToSelection(false);
+	}
+	
+	public void SeekToSelection (bool allowRewind) {
 		Subtitle subtitle = Core.Base.Ui.View.Selection.FirstSubtitle;
     	TimeSpan time = subtitle.Times.Start;
+    	if (allowRewind && Base.Config.PrefsVideoSeekOnChange) {
+    		TimeSpan rewind = TimeSpan.FromMilliseconds(Base.Config.PrefsVideoSeekOnChangeRewind);
+    		time = (time >= rewind ? time - rewind : TimeSpan.Zero);
+    	}
     	Seek(time);
 	}
 	



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