Add settings dialog
[cinaest] / src / settings-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 SettingsDialog : Gtk.Dialog {
23         List<Gtk.Button> buttons;
24         Gtk.Window movie_list_window;
25
26         public SettingsDialog (Gtk.Window window) {
27                 movie_list_window = window;
28                 set_transient_for (window);
29         }
30
31         construct {
32                 set_title (_("Settings"));
33
34                 VBox vbox;
35                 if (CinaestProgram.plugins.length () > 5) {
36                         vbox = new VBox (true, 0);
37
38                         var pannable = new PannableArea ();
39                         pannable.add_with_viewport (vbox);
40
41                         VBox area = (VBox) get_content_area ();
42                         area.pack_start (pannable, true, true, 0);
43                         area.set_size_request (-1, 5*70);
44                 } else {
45                         vbox = (VBox) get_content_area ();
46                 }
47
48                 buttons = new List<Hildon.Button> ();
49                 foreach (Plugin plugin in CinaestProgram.plugins) {
50                         var button = new Gtk.Button.with_label (plugin.get_name ());
51
52                         Hildon.gtk_widget_set_theme_size (button, SizeType.FINGER_HEIGHT);
53                         button.set_alignment(0, 0.5f);
54
55                         vbox.pack_start (button, true, true, 0);
56
57                         button.clicked.connect (on_plugin_settings);
58
59                         buttons.append (button);
60                 }
61         }
62
63         public void on_plugin_settings (Gtk.Button button) {
64                 int n = buttons.index (button);
65
66                 response (n);
67         }
68
69         public new int run () {
70                 int res = 0;
71
72                 show_all ();
73
74                 do {
75                         res = base.run ();
76                         if (res >= 0) {
77                                 var plugin = CinaestProgram.plugins.nth_data (res);
78                                 plugin.settings_dialog (movie_list_window);
79                         }
80                 } while (res >= 0);
81
82                 destroy ();
83
84                 return res;
85         }
86 }