Settings dialog: two columns of plugin settings buttons
[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                 HBox hbox;
49                 int i = 0;
50                 buttons = new List<Hildon.Button> ();
51                 foreach (Plugin plugin in CinaestProgram.plugins) {
52                         var button = new Gtk.Button.with_label (plugin.get_name ());
53
54                         Hildon.gtk_widget_set_theme_size (button, SizeType.FINGER_HEIGHT);
55                         button.set_alignment(0, 0.5f);
56
57                         if (i++ == 0) {
58                                 hbox = new HBox (true, 0);
59                                 vbox.pack_start (hbox, true, true, 0);
60                         }
61                         if (i == 2)
62                                 i = 0;
63                         hbox.pack_start (button, true, true, 0);
64
65                         button.clicked.connect (on_plugin_settings);
66
67                         buttons.append (button);
68                 }
69         }
70
71         public void on_plugin_settings (Gtk.Button button) {
72                 int n = buttons.index (button);
73
74                 response (n);
75         }
76
77         public new int run () {
78                 int res = 0;
79
80                 show_all ();
81
82                 do {
83                         res = base.run ();
84                         if (res >= 0) {
85                                 var plugin = CinaestProgram.plugins.nth_data (res);
86                                 plugin.settings_dialog (movie_list_window);
87                         }
88                 } while (res >= 0);
89
90                 destroy ();
91
92                 return res;
93         }
94 }