b58af3019db6357aebf9eb07901ba731ae1f9775
[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 "lib/film.h"
23 #include "lib/subrip_content.h"
24 #include "subtitle_view.h"
25 #include "wx_util.h"
26
27 using std::list;
28 using boost::shared_ptr;
29 using boost::dynamic_pointer_cast;
30
31 SubtitleView::SubtitleView (wxWindow* parent, shared_ptr<Film> film, shared_ptr<SubtitleDecoder> decoder, DCPTime position)
32         : wxDialog (parent, wxID_ANY, _("Subtitles"))
33 {
34         _list = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL);
35
36         {
37                 wxListItem ip;
38                 ip.SetId (0);
39                 ip.SetText (_("Start"));
40                 ip.SetWidth (100);
41                 _list->InsertColumn (0, ip);
42         }
43
44         {
45                 wxListItem ip;
46                 ip.SetId (1);
47                 ip.SetText (_("End"));
48                 ip.SetWidth (100);
49                 _list->InsertColumn (1, ip);
50         }               
51
52         {
53                 wxListItem ip;
54                 ip.SetId (2);
55                 ip.SetText (_("Subtitle"));
56                 ip.SetWidth (640);
57                 _list->InsertColumn (2, ip);
58         }
59
60         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
61         sizer->Add (_list, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP);
62
63         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
64         if (buttons) {
65                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
66         }
67
68         list<ContentTextSubtitle> subs = decoder->get_text_subtitles (ContentTimePeriod (ContentTime(), ContentTime::max ()), true);
69         FrameRateChange const frc = film->active_frame_rate_change (position);
70         int n = 0;
71         for (list<ContentTextSubtitle>::const_iterator i = subs.begin(); i != subs.end(); ++i) {
72                 for (list<dcp::SubtitleString>::const_iterator j = i->subs.begin(); j != i->subs.end(); ++j) {
73                         wxListItem list_item;
74                         list_item.SetId (n);
75                         _list->InsertItem (list_item);
76                         ContentTimePeriod const p = i->period ();
77                         _list->SetItem (n, 0, std_to_wx (p.from.timecode (frc.source)));
78                         _list->SetItem (n, 1, std_to_wx (p.to.timecode (frc.source)));
79                         _list->SetItem (n, 2, std_to_wx (j->text ()));
80                         ++n;
81                 }
82         }
83
84         SetSizerAndFit (sizer);
85 }
86