542655477381eed773be38cd6440a3f08ee8df1b
[dcpomatic.git] / src / wx / move_to_dialog.cc
1 /*
2     Copyright (C) 2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "move_to_dialog.h"
22 #include "lib/film.h"
23 #include <wx/spinctrl.h>
24
25 using std::list;
26 using std::shared_ptr;
27 using boost::optional;
28 using namespace dcpomatic;
29
30 MoveToDialog::MoveToDialog (wxWindow* parent, optional<DCPTime> position, shared_ptr<const Film> film)
31         : TableDialog (parent, _("Move content"), 2, 0, true)
32         , _film (film)
33 {
34         add (_("Start of reel"), true);
35         _reel = new wxSpinCtrl (this, wxID_ANY);
36         _reel->SetRange (1, film->reels().size());
37         add (_reel);
38
39         layout ();
40
41         if (position) {
42                 int j = 0;
43                 for (auto i: film->reels()) {
44                         if (i.from == position.get()) {
45                                 _reel->SetValue (j + 1);
46                         }
47                         ++j;
48                 }
49         }
50 }
51
52 DCPTime
53 MoveToDialog::position () const
54 {
55         shared_ptr<const Film> film = _film.lock ();
56         DCPOMATIC_ASSERT (film);
57         list<DCPTimePeriod> reels = film->reels ();
58         list<DCPTimePeriod>::const_iterator i = reels.begin ();
59         for (int j = 0; j < _reel->GetValue() - 1; ++j) {
60                 DCPOMATIC_ASSERT (i != reels.end());
61                 ++i;
62         }
63
64         DCPOMATIC_ASSERT (i != reels.end());
65         return i->from;
66 }