e9606d396cdf3899d5aa88719447ca4179f0a975
[dcpomatic.git] / src / wx / dvd_title_dialog.cc
1 /*
2     Copyright (C) 2012 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 <cassert>
21 #include <iostream>
22 #include "lib/exceptions.h"
23 #include "dvd_title_dialog.h"
24 #include "gtk_util.h"
25
26 using namespace std;
27
28 DVDTitleDialog::DVDTitleDialog ()
29 {
30         string const dvd = find_dvd ();
31         if (dvd.empty ()) {
32                 throw DVDError ("could not find DVD");
33         }
34
35         list<DVDTitle> t = dvd_titles (dvd);
36         if (t.empty ()) {
37                 throw DVDError ("no titles found on DVD");
38         }
39
40         set_title ("Choose DVD title");
41         get_vbox()->set_border_width (6);
42         get_vbox()->set_spacing (3);
43
44         Gtk::RadioButtonGroup g;
45         for (list<DVDTitle>::const_iterator i = t.begin(); i != t.end(); ++i) {
46                 Gtk::RadioButton* b = manage (new Gtk::RadioButton);
47                 stringstream s;
48 #if HAVE_G_FORMAT_SIZE          
49                 s << "Title " << i->number << ": " << g_format_size (i->size);
50 #else           
51                 s << "Title " << i->number << ": " << g_format_size_for_display (i->size);
52 #endif          
53                 b->set_label (s.str ());
54                 if (i == t.begin ()) {
55                         b->set_active ();
56                         g = b->get_group ();
57                 } else {
58                         b->set_group (g);
59                 }
60                 get_vbox()->pack_start (*b);
61                 _buttons[*i] = b;
62         }
63
64         add_button ("Cancel", Gtk::RESPONSE_CANCEL);
65         add_button ("Copy Title", Gtk::RESPONSE_OK);
66
67         show_all ();
68 }
69
70 DVDTitle
71 DVDTitleDialog::selected ()
72 {
73         std::map<DVDTitle, Gtk::RadioButton *>::const_iterator i = _buttons.begin ();
74         while (i != _buttons.end() && i->second->get_active() == false) {
75                 ++i;
76         }
77
78         assert (i != _buttons.end ());
79         return i->first;
80 }