Merge master.
[dcpomatic.git] / src / wx / subtitle_view.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 #include "lib/subrip_decoder.h"
21 #include "lib/content_subtitle.h"
22 #include "subtitle_view.h"
23
24 using std::list;
25 using boost::shared_ptr;
26 using boost::dynamic_pointer_cast;
27
28 SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<SubRipContent> content)
29         : wxDialog (parent, wxID_ANY, _("Subtitles"))
30 {
31         _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
32
33         {
34                 wxListItem ip;
35                 ip.SetId (0);
36                 ip.SetText (_("Start"));
37                 ip.SetWidth (100);
38                 _list->InsertColumn (0, ip);
39         }
40
41         {
42                 wxListItem ip;
43                 ip.SetId (1);
44                 ip.SetText (_("End"));
45                 ip.SetWidth (100);
46                 _list->InsertColumn (1, ip);
47         }               
48
49         {
50                 wxListItem ip;
51                 ip.SetId (2);
52                 ip.SetText (_("Subtitle"));
53                 ip.SetWidth (640);
54                 _list->InsertColumn (2, ip);
55         }
56
57         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
58         sizer->Add (_list, 1, wxEXPAND);
59
60         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK | wxCANCEL);
61         if (buttons) {
62                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
63         }
64
65         shared_ptr<SubRipDecoder> decoder (new SubRipDecoder (content));
66         list<shared_ptr<ContentTextSubtitle> > subs = decoder->get_text_subtitles (ContentTime(), ContentTime::max ());
67         int n = 0;
68         for (list<shared_ptr<ContentTextSubtitle> >::const_iterator i = subs.begin(); i != subs.end(); ++i) {
69                 for (list<dcp::SubtitleString>::const_iterator j = (*i)->subs.begin(); j != (*i)->subs.end(); ++j) {
70                         wxListItem list_item;
71                         list_item.SetId (n);
72                         _list->InsertItem (list_item);
73                         _list->SetItem (n, 2, j->text ());
74                         ++n;
75                 }
76         }
77
78         SetSizerAndFit (sizer);
79 }
80