[gnome-subtitles: 1/2] Fix #129 Clear video subtitle on File Close
- From: Pedro Castro <pcastro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-subtitles: 1/2] Fix #129 Clear video subtitle on File Close
- Date: Sun, 19 May 2019 10:52:45 +0000 (UTC)
commit 9db73d15b93d63656d025833885eb15fba84960d
Author: Pedro Castro <pedro gnomesubtitles org>
Date: Sun May 19 11:51:33 2019 +0100
Fix #129 Clear video subtitle on File Close
Subtitle overlay was not being cleared when closing a subtitle file
.../Ui/VideoPreview/SubtitleTracker.cs | 30 ++++++++++++++--------
src/GnomeSubtitles/Ui/VideoPreview/Video.cs | 15 ++++-------
2 files changed, 24 insertions(+), 21 deletions(-)
---
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/SubtitleTracker.cs
b/src/GnomeSubtitles/Ui/VideoPreview/SubtitleTracker.cs
index b67ab88..c79d5ab 100755
--- a/src/GnomeSubtitles/Ui/VideoPreview/SubtitleTracker.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/SubtitleTracker.cs
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2007-2017 Pedro Castro
+ * Copyright (C) 2007-2019 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
@@ -18,7 +18,6 @@
*/
using GnomeSubtitles.Core;
-using Gtk;
using SubLib.Core.Domain;
using SubLib.Core.Search;
using System;
@@ -52,10 +51,9 @@ public class SubtitleTracker {
return searchOp.FindNearTime(position);
}
+ //Called when closing the video. Unload video-related stuff (not subtitle-related stuff though, as we
may open another video file later).
public void Close(){
- if (IsSubtitleLoaded()) {
- UnSetCurrentSubtitle();
- }
+ ClearCurrentSubtitle();
}
@@ -72,11 +70,15 @@ public class SubtitleTracker {
private void SetCurrentSubtitle (int index) {
this.subtitle = Base.Document.Subtitles[index];
this.currentSubtitleIndex = index;
+
+ EmitSubtitlePulse(this.currentSubtitleIndex);
}
- private void UnSetCurrentSubtitle () {
+ private void ClearCurrentSubtitle () {
this.currentSubtitleIndex = -1;
this.subtitle = null;
+
+ EmitSubtitlePulse(this.currentSubtitleIndex);
}
private void EmitSubtitlePulse(int newIndex) {
@@ -90,28 +92,34 @@ public class SubtitleTracker {
private void OnBaseInitFinished () {
Base.Ui.Video.Position.PositionPulse += OnVideoPositionPulse;
Base.DocumentLoaded += OnBaseDocumentLoaded;
+ Base.DocumentUnloaded += OnBaseDocumentUnloaded;
}
private void OnBaseDocumentLoaded (Document document) {
this.searchOp = new SearchOperator(document.Subtitles);
}
+
+ private void OnBaseDocumentUnloaded (Document document) {
+ this.searchOp = null;
+
+ ClearCurrentSubtitle();
+ }
private void OnVideoPositionPulse (TimeSpan newPosition) {
- if (!(Base.IsDocumentLoaded))
+ if (!Base.IsDocumentLoaded) {
return;
+ }
if (!IsTimeInCurrentSubtitle(newPosition)) {
int foundSubtitle = searchOp.FindWithTime(newPosition);
if (foundSubtitle == -1) {
- UnSetCurrentSubtitle();
+ ClearCurrentSubtitle();
} else {
SetCurrentSubtitle(foundSubtitle);
}
}
-
- EmitSubtitlePulse(this.currentSubtitleIndex);
}
- }
+}
}
diff --git a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
index b7420d4..8224826 100644
--- a/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
+++ b/src/GnomeSubtitles/Ui/VideoPreview/Video.cs
@@ -1,6 +1,6 @@
/*
* This file is part of Gnome Subtitles.
- * Copyright (C) 2006-2018 Pedro Castro
+ * Copyright (C) 2006-2019 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
@@ -22,11 +22,9 @@ using GnomeSubtitles.Core;
using GnomeSubtitles.Dialog.Unmanaged;
using Gtk;
using GStreamer;
-using SubLib.Core;
using SubLib.Core.Domain;
using SubLib.Core.Timing;
using System;
-using System.Text.RegularExpressions;
namespace GnomeSubtitles.Ui.VideoPreview {
@@ -42,10 +40,6 @@ public class Video {
private bool isLoaded = false;
private bool playPauseToggleIsSilent = false; //Used to indicate whether toggling the button should
not issue the toggled signal
- /* Constants */
- //private const string videoSetSubtitleStartIconFilename = "video-set-subtitle-start-16x.png";
- //private const string videoSetSubtitleEndIconFilename = "video-set-subtitle-end-16x.png";
- //private const string videoSetSubtitleStartEndIconFilename = "video-set-subtitle-start-end-30x.png";
public Video () {
videoArea = Base.GetWidget(WidgetNames.VideoAreaHBox) as Box;
@@ -53,9 +47,9 @@ public class Video {
InitializeVideoFrame();
InitializePlayer();
- overlay = new SubtitleOverlay();
position = new VideoPosition(player);
tracker = new SubtitleTracker();
+ overlay = new SubtitleOverlay();
Base.InitFinished += OnBaseInitFinished;
}
@@ -98,6 +92,7 @@ public class Video {
get { return (player != null) && (player.HasVideo); }
}
+
/* Public methods */
public void Show () {
@@ -123,9 +118,9 @@ public class Video {
isLoaded = false;
player.Close();
- overlay.Close();
- tracker.Close();
position.Disable();
+ tracker.Close();
+ overlay.Close();
/* Update the frame */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]