Add GConf option to control poster downloads
[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         private Hildon.CheckButton download_posters;
26
27         public SettingsDialog (Gtk.Window window) {
28                 movie_list_window = window;
29                 set_transient_for (window);
30         }
31
32         construct {
33                 set_title (_("Settings"));
34
35                 VBox vbox;
36                 if (CinaestProgram.plugins.length () > 5) {
37                         vbox = new VBox (true, 0);
38
39                         var pannable = new PannableArea ();
40                         pannable.add_with_viewport (vbox);
41
42                         VBox area = (VBox) get_content_area ();
43                         area.pack_start (pannable, true, true, 0);
44                         area.set_size_request (-1, 5*70);
45                 } else {
46                         vbox = (VBox) get_content_area ();
47                 }
48
49                 download_posters = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
50                 download_posters.set_label (_("Download movie posters"));
51                 vbox.pack_start (download_posters, true, true, 0);
52
53                 HBox hbox;
54                 int i = 0;
55                 buttons = new List<Hildon.Button> ();
56                 foreach (Plugin plugin in CinaestProgram.plugins) {
57                         var button = new Gtk.Button.with_label (plugin.get_name ());
58
59                         Hildon.gtk_widget_set_theme_size (button, SizeType.FINGER_HEIGHT);
60                         button.set_alignment(0, 0.5f);
61
62                         if (i++ == 0) {
63                                 hbox = new HBox (true, 0);
64                                 vbox.pack_start (hbox, true, true, 0);
65                         }
66                         if (i == 2)
67                                 i = 0;
68                         hbox.pack_start (button, true, true, 0);
69
70                         button.clicked.connect (on_plugin_settings);
71
72                         buttons.append (button);
73                 }
74
75                 add_button (_("Done"), ResponseType.ACCEPT);
76         }
77
78         public void on_plugin_settings (Gtk.Button button) {
79                 int n = buttons.index (button);
80
81                 response (n);
82         }
83
84         public new int run () {
85                 int res = 0;
86                 var gc = GConf.Client.get_default ();
87
88                 download_posters.set_active (gc.get_bool ("/apps/cinaest/download_posters"));
89
90                 show_all ();
91
92                 do {
93                         res = base.run ();
94                         if (res >= 0) {
95                                 var plugin = CinaestProgram.plugins.nth_data (res);
96                                 plugin.settings_dialog (movie_list_window);
97                         }
98                 } while (res >= 0);
99
100                 if (res == ResponseType.ACCEPT)
101                         gc.set_bool ("/apps/cinaest/download_posters", download_posters.get_active ());
102                 destroy ();
103
104                 return res;
105         }
106 }