Add "Open Subtitles From Video" menu option. Closes #253.

Originally committed to SVN as r4306.
This commit is contained in:
Thomas Goyne 2010-05-19 00:44:37 +00:00
parent ea100e9bff
commit a573b0897b
7 changed files with 65 additions and 21 deletions

View file

@ -357,6 +357,7 @@ void FrameMain::InitMenu() {
AppendBitmapMenuItem(fileMenu,Menu_File_New_Subtitles, MakeHotkeyText(_("&New Subtitles"), _T("New Subtitles")), _("New subtitles"),GETIMAGE(new_toolbutton_16));
AppendBitmapMenuItem(fileMenu,Menu_File_Open_Subtitles, MakeHotkeyText(_("&Open Subtitles..."), _T("Open Subtitles")), _("Opens a subtitles file"),GETIMAGE(open_toolbutton_16));
AppendBitmapMenuItem(fileMenu,Menu_File_Open_Subtitles_Charset, _("&Open Subtitles with Charset..."), _("Opens a subtitles file with a specific charset"),GETIMAGE(open_with_toolbutton_16));
fileMenu->Append(Menu_File_Open_Subtitles_From_Video, _("Open Subtitles from &Video"), _("Opens the subtitles from the current video file"));
AppendBitmapMenuItem(fileMenu,Menu_File_Save_Subtitles, MakeHotkeyText(_("&Save Subtitles"), _T("Save Subtitles")), _("Saves subtitles"),GETIMAGE(save_toolbutton_16));
AppendBitmapMenuItem(fileMenu,Menu_File_Save_Subtitles_As, _("Save Subtitles as..."), _("Saves subtitles with another name"), GETIMAGE(save_as_toolbutton_16));
AppendBitmapMenuItem(fileMenu,Menu_File_Export_Subtitles, _("Export Subtitles..."), _("Saves a copy of subtitles with processing applied to it."), GETIMAGE(export_menu_16));

View file

@ -214,6 +214,7 @@ private:
void OnNewSubtitles (wxCommandEvent &event);
void OnOpenSubtitles (wxCommandEvent &event);
void OnOpenSubtitlesCharset (wxCommandEvent &event);
void OnOpenSubtitlesVideo (wxCommandEvent &event);
void OnSaveSubtitles (wxCommandEvent &event);
void OnSaveSubtitlesAs (wxCommandEvent &event);
void OnSaveSubtitlesCharset (wxCommandEvent &event);
@ -412,6 +413,7 @@ enum {
/// DOCME
Menu_File_Open_Subtitles_Charset,
Menu_File_Open_Subtitles_From_Video,
/// DOCME
Menu_File_New_Subtitles,

View file

@ -124,6 +124,7 @@ BEGIN_EVENT_TABLE(FrameMain, wxFrame)
EVT_MENU(Menu_File_Close_Video, FrameMain::OnCloseVideo)
EVT_MENU(Menu_File_Open_Subtitles, FrameMain::OnOpenSubtitles)
EVT_MENU(Menu_File_Open_Subtitles_Charset, FrameMain::OnOpenSubtitlesCharset)
EVT_MENU(Menu_File_Open_Subtitles_From_Video, FrameMain::OnOpenSubtitlesVideo)
EVT_MENU(Menu_File_New_Subtitles, FrameMain::OnNewSubtitles)
EVT_MENU(Menu_File_Save_Subtitles, FrameMain::OnSaveSubtitles)
EVT_MENU(Menu_File_Save_Subtitles_As, FrameMain::OnSaveSubtitlesAs)
@ -296,6 +297,8 @@ void FrameMain::OnMenuOpen (wxMenuEvent &event) {
if (curMenu == fileMenu) {
// Rebuild recent
RebuildRecentList(_T("Recent sub"),RecentSubs,Menu_File_Recent);
MenuBar->Enable(Menu_File_Open_Subtitles_From_Video,VideoContext::Get()->HasSubtitles());
}
// View menu
@ -811,6 +814,11 @@ void FrameMain::OnOpenSubtitlesCharset(wxCommandEvent& WXUNUSED(event)) {
}
}
/// @brief Open subtitles from the currently open video file
void FrameMain::OnOpenSubtitlesVideo(wxCommandEvent&) {
LoadSubtitles(VideoContext::Get()->videoName);
}
/// @brief Save subtitles as

View file

@ -508,9 +508,31 @@ void MatroskaWrapper::GetSubtitles(AssFile *target) {
}
}
bool MatroskaWrapper::HasSubtitles(wxString const& filename) {
char err[2048];
MkvStdIO input(filename);
if (!input.fp) return false;
MatroskaFile* file = mkv_Open(&input, err, sizeof(err));
if (!file) return false;
// Find tracks
int tracks = mkv_GetNumTracks(file);
for (int track = 0; track < tracks; track++) {
TrackInfo *trackInfo = mkv_GetTrackInfo(file, track);
if (trackInfo->Type == 0x11) {
wxString CodecID = wxString(trackInfo->CodecID, *wxConvCurrent);
if (CodecID == _T("S_TEXT/SSA") || CodecID == _T("S_TEXT/ASS") || CodecID == _T("S_TEXT/UTF8")) {
mkv_Close(file);
return true;
}
}
}
mkv_Close(file);
return false;
}
////////////////////////////// LOTS OF HAALI C CODE DOWN HERE ///////////////////////////////////////

View file

@ -174,6 +174,7 @@ public:
unsigned int GetFrameCount() { return timecodes.size(); }
wxArrayInt GetKeyFrames();
void GetSubtitles(AssFile *target);
static bool HasSubtitles(wxString const& filename);
/// DOCME

View file

@ -62,6 +62,7 @@
#include "ass_style.h"
#include "ass_time.h"
#include "audio_display.h"
#include "mkv_wrap.h"
#include "options.h"
#include "standard_paths.h"
#include "subs_edit_box.h"
@ -95,27 +96,26 @@ VideoContext *VideoContext::instance = NULL;
/// @brief Constructor
///
VideoContext::VideoContext() {
// Set GL context
glContext = NULL;
ownGlContext = false;
// Set options
audio = NULL;
provider = NULL;
subsProvider = NULL;
curLine = NULL;
loaded = false;
keyFramesLoaded = false;
overKeyFramesLoaded = false;
frame_n = 0;
length = 0;
fps = 0;
arType = 0;
arValue = 1.0;
isPlaying = false;
nextFrame = -1;
keepAudioSync = true;
VideoContext::VideoContext()
: glContext(NULL)
, ownGlContext(false)
, audio(NULL)
, provider(NULL)
, subsProvider(NULL)
, curLine(NULL)
, loaded(false)
, keyFramesLoaded(false)
, overKeyFramesLoaded(false)
, frame_n(0)
, length(0)
, fps(0)
, arType(0)
, arValue(1.)
, isPlaying(false)
, nextFrame(-1)
, keepAudioSync(true)
, hasSubtitles(false)
{
}
/// @brief Destructor
@ -274,6 +274,11 @@ void VideoContext::SetVideo(const wxString &filename) {
wxString warning = provider->GetWarning().c_str();
if (!warning.IsEmpty()) wxMessageBox(warning,_T("Warning"),wxICON_WARNING | wxOK);
hasSubtitles = false;
if (filename.Right(4).Lower() == L".mkv") {
hasSubtitles = MatroskaWrapper::HasSubtitles(filename);
}
UpdateDisplays(true);
}

View file

@ -174,6 +174,8 @@ private:
/// DOCME
int arType;
bool hasSubtitles;
void OnPlayTimer(wxTimerEvent &event);
public:
@ -215,6 +217,9 @@ public:
/// @return
bool IsPlaying() { return isPlaying; }
/// @brief Does the video file loaded have muxed subtitles that we can load?
bool HasSubtitles() {return hasSubtitles; }
/// @brief DOCME
/// @param sync
/// @return