Commit 9db73d15 authored by Pedro Castro's avatar Pedro Castro

Fix #129 Clear video subtitle on File Close

Subtitle overlay was not being cleared when closing a subtitle file
parent f13de18a
/*
* 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);
}
}
}
}
/*
* 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 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment