Add source selection dialog
[cinaest] / src / source-dialog.vala
1 /* This file is part of Cinaest.
2  *
3  * Copyright (C) 2009 Philipp Zabel
4  *
5  * Cinaest is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Cinaest is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Cinaest. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using Hildon;
20 using Gtk;
21
22 class SourceDialog : Gtk.Dialog {
23         List<MovieSource> sources;
24         List<Gtk.Button> buttons;
25
26         public SourceDialog (Gtk.Window window) {
27                 set_transient_for (window);
28                 set_title (_("Select movie source"));
29
30                 VBox vbox;
31                 if (CinaestProgram.plugins.length () > 5) {
32                         vbox = new VBox (true, 0);
33
34                         var pannable = new PannableArea ();
35                         pannable.add_with_viewport (vbox);
36
37                         VBox area = (VBox) get_content_area ();
38                         area.pack_start (pannable, true, true, 0);
39                         area.set_size_request (-1, 5*70);
40                 } else {
41                         vbox = (VBox) get_content_area ();
42                 }
43
44                 sources = new List<MovieSource> ();
45                 buttons = new List<Hildon.Button> ();
46                 foreach (Plugin plugin in CinaestProgram.plugins) {
47                         foreach (MovieSource source in plugin.get_sources ()) {
48                                 var button = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, source.get_name (), source.get_description ());
49                                 button.set_alignment(0, (float) 0.5, 0, 0);
50                                 vbox.pack_start (button, true, true, 0);
51
52                                 button.clicked.connect (on_source_select);
53
54                                 buttons.append (button);
55                                 sources.append (source);
56                         }
57                 }
58         }
59
60         public void on_source_select (Gtk.Button button) {
61                 int n = buttons.index (button);
62
63                 response (n);
64         }
65
66         public new int run (ref MovieSource source) {
67                 int res = 0;
68
69                 show_all ();
70
71                 res = base.run ();
72                 destroy ();
73
74                 if (res >= 0) {
75                         source = sources.nth_data (res);
76                         return 0;
77                 }
78
79                 return res;
80         }
81 }
82