2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <boost/lexical_cast.hpp>
21 #include "lib/ffmpeg_content.h"
22 #include "ffmpeg_content_dialog.h"
27 using boost::shared_ptr;
28 using boost::lexical_cast;
30 FFmpegContentDialog::FFmpegContentDialog (wxWindow* parent, shared_ptr<FFmpegContent> content)
31 : wxDialog (parent, wxID_ANY, _("Video"))
33 wxFlexGridSizer* grid = new wxFlexGridSizer (3, 6, 6);
34 grid->AddGrowableCol (1, 1);
36 add_label_to_sizer (grid, this, _("Audio Stream"));
37 _audio_stream = new wxChoice (this, wxID_ANY);
38 grid->Add (_audio_stream, 1, wxEXPAND | wxALL, 6);
39 _audio_description = new wxStaticText (this, wxID_ANY, wxT (""));
40 grid->Add (_audio_description, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
42 add_label_to_sizer (grid, this, _("Subtitle stream"));
43 _subtitle_stream = new wxChoice (this, wxID_ANY);
44 grid->Add (_subtitle_stream, 1, wxEXPAND | wxALL, 6);
47 _audio_stream->Clear ();
48 vector<FFmpegAudioStream> a = content->audio_streams ();
49 for (vector<FFmpegAudioStream>::iterator i = a.begin(); i != a.end(); ++i) {
50 _audio_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (lexical_cast<string> (i->id))));
53 if (content->audio_stream()) {
54 checked_set (_audio_stream, lexical_cast<string> (content->audio_stream()->id));
57 _subtitle_stream->Clear ();
58 vector<FFmpegSubtitleStream> s = content->subtitle_streams ();
60 _subtitle_stream->Enable (false);
62 for (vector<FFmpegSubtitleStream>::iterator i = s.begin(); i != s.end(); ++i) {
63 _subtitle_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (lexical_cast<string> (i->id))));
66 if (content->subtitle_stream()) {
67 checked_set (_subtitle_stream, lexical_cast<string> (content->subtitle_stream()->id));
69 _subtitle_stream->SetSelection (wxNOT_FOUND);
72 wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
73 overall_sizer->Add (grid, 1, wxEXPAND | wxALL, 6);
75 wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
77 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
80 SetSizer (overall_sizer);
81 overall_sizer->Layout ();
82 overall_sizer->SetSizeHints (this);
84 _audio_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FFmpegContentDialog::audio_stream_changed), 0, this);
85 _subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FFmpegContentDialog::subtitle_stream_changed), 0, this);
89 FFmpegContentDialog::audio_stream_changed (wxCommandEvent &)
91 shared_ptr<FFmpegContent> c = _content.lock ();
96 vector<FFmpegAudioStream> a = c->audio_streams ();
97 vector<FFmpegAudioStream>::iterator i = a.begin ();
98 string const s = string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ()));
99 while (i != a.end() && lexical_cast<string> (i->id) != s) {
104 c->set_audio_stream (*i);
107 if (!c->audio_stream ()) {
108 _audio_description->SetLabel (wxT (""));
111 if (c->audio_channels() == 1) {
114 s << c->audio_channels() << wxT (" ") << _("channels");
116 s << wxT (", ") << c->content_audio_frame_rate() << _("Hz");
117 _audio_description->SetLabel (s);
124 FFmpegContentDialog::subtitle_stream_changed (wxCommandEvent &)
126 shared_ptr<FFmpegContent> c = _content.lock ();
131 vector<FFmpegSubtitleStream> a = c->subtitle_streams ();
132 vector<FFmpegSubtitleStream>::iterator i = a.begin ();
133 string const s = string_client_data (_subtitle_stream->GetClientObject (_subtitle_stream->GetSelection ()));
134 while (i != a.end() && lexical_cast<string> (i->id) != s) {
139 c->set_subtitle_stream (*i);