Add configuration option to open the movie list window on startup
[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         private Hildon.CheckButton start_movies;
27         private Hildon.Button default_source;
28
29         public SettingsDialog (Gtk.Window window) {
30                 movie_list_window = window;
31                 set_transient_for (window);
32         }
33
34         construct {
35                 set_title (_("Settings"));
36
37                 VBox vbox;
38                 if (CinaestProgram.plugins.length () > 4) {
39                         vbox = new VBox (true, 0);
40
41                         var pannable = new PannableArea ();
42                         pannable.add_with_viewport (vbox);
43
44                         VBox area = (VBox) get_content_area ();
45                         area.pack_start (pannable, true, true, 0);
46                         area.set_size_request (-1, 5*70);
47                 } else {
48                         vbox = (VBox) get_content_area ();
49                 }
50
51                 download_posters = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
52                 download_posters.set_label (_("Download movie posters"));
53                 vbox.pack_start (download_posters, true, true, 0);
54
55                 start_movies = new Hildon.CheckButton (SizeType.FINGER_HEIGHT);
56                 start_movies.set_label (_("Show movie list on startup"));
57                 vbox.pack_start (start_movies, true, true, 0);
58
59                 default_source = new Hildon.Button.with_text (SizeType.FINGER_HEIGHT, ButtonArrangement.VERTICAL, _("Default movie source"), _("None"));
60                 default_source.set_style (ButtonStyle.PICKER);
61                 default_source.set_alignment (0, 0.5f, 0, 0.5f);
62                 vbox.pack_start (default_source, true, true, 0);
63
64                 default_source.clicked.connect (on_default_source_clicked);
65
66                 HBox hbox;
67                 int i = 0;
68                 buttons = new List<Hildon.Button> ();
69                 foreach (Plugin plugin in CinaestProgram.plugins) {
70                         var button = new Gtk.Button.with_label (plugin.get_name ());
71
72                         Hildon.gtk_widget_set_theme_size (button, SizeType.FINGER_HEIGHT);
73                         button.set_alignment(0, 0.5f);
74
75                         if (i++ == 0) {
76                                 hbox = new HBox (true, 0);
77                                 vbox.pack_start (hbox, true, true, 0);
78                         }
79                         if (i == 2)
80                                 i = 0;
81                         hbox.pack_start (button, true, true, 0);
82
83                         button.clicked.connect (on_plugin_settings);
84
85                         buttons.append (button);
86                 }
87
88                 add_button (_("Done"), ResponseType.ACCEPT);
89         }
90
91         public void on_default_source_clicked (Gtk.Button button) {
92                 var default_source = (Hildon.Button) button;
93                 var dialog = new SourceDialog (movie_list_window);
94
95                 MovieSource source = null;
96                 dialog.run (ref source);
97
98                 if (source != null) {
99                         default_source.set_value (source.get_name ());
100                 }
101         }
102
103         public void on_plugin_settings (Gtk.Button button) {
104                 int n = buttons.index (button);
105
106                 response (n);
107         }
108
109         public new int run () {
110                 int res = 0;
111                 var gc = GConf.Client.get_default ();
112
113                 try {
114                         download_posters.set_active (gc.get_bool ("/apps/cinaest/download_posters"));
115                         start_movies.set_active (gc.get_bool ("/apps/cinaest/start_movies"));
116                         string source = gc.get_string ("/apps/cinaest/default_source");
117                         if (source != null && source != "")
118                                 default_source.set_value (source);
119                 } catch (Error e) {
120                         stdout.printf ("Error getting GConf option: %s\n", e.message);
121                 }
122
123                 show_all ();
124
125                 do {
126                         res = base.run ();
127                         if (res >= 0) {
128                                 var plugin = CinaestProgram.plugins.nth_data (res);
129                                 plugin.settings_dialog (movie_list_window);
130                         }
131                 } while (res >= 0);
132
133                 if (res == ResponseType.ACCEPT) try {
134                         gc.set_bool ("/apps/cinaest/download_posters", download_posters.get_active ());
135                         gc.set_bool ("/apps/cinaest/start_movies", start_movies.get_active ());
136                         gc.set_string ("/apps/cinaest/default_source", default_source.get_value ());
137                 } catch (Error e) {
138                         stdout.printf ("Error setting GConf option: %s\n", e.message);
139                 }
140                 destroy ();
141
142                 return res;
143         }
144 }