Movie list view: poster update on row-inserted signal
[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                 start_movies.toggled.connect (on_start_movies_toggled);
65                 default_source.clicked.connect (on_default_source_clicked);
66
67                 HBox hbox;
68                 int i = 0;
69                 buttons = new List<Hildon.Button> ();
70                 foreach (Plugin plugin in CinaestProgram.plugins) {
71                         var button = new Gtk.Button.with_label (plugin.get_name ());
72
73                         Hildon.gtk_widget_set_theme_size (button, SizeType.FINGER_HEIGHT);
74                         button.set_alignment(0, 0.5f);
75
76                         if (i++ == 0) {
77                                 hbox = new HBox (true, 0);
78                                 vbox.pack_start (hbox, true, true, 0);
79                         }
80                         if (i == 2)
81                                 i = 0;
82                         hbox.pack_start (button, true, true, 0);
83
84                         button.clicked.connect (on_plugin_settings);
85
86                         buttons.append (button);
87                 }
88
89                 add_button (_("Done"), ResponseType.ACCEPT);
90         }
91
92         public void on_start_movies_toggled () {
93                 default_source.set_sensitive (start_movies.get_active ());
94         }
95
96         public void on_default_source_clicked (Gtk.Button button) {
97                 var default_source = (Hildon.Button) button;
98                 var dialog = new SourceDialog (movie_list_window);
99
100                 MovieSource source = null;
101                 dialog.run (ref source);
102
103                 if (source != null) {
104                         default_source.set_value (source.get_name ());
105                 }
106         }
107
108         public void on_plugin_settings (Gtk.Button button) {
109                 int n = buttons.index (button);
110
111                 response (n);
112         }
113
114         public new int run () {
115                 int res = 0;
116                 var gc = GConf.Client.get_default ();
117
118                 try {
119                         download_posters.set_active (gc.get_bool ("/apps/cinaest/download_posters"));
120                         start_movies.set_active (gc.get_bool ("/apps/cinaest/start_movies"));
121                         default_source.set_sensitive (start_movies.get_active ());
122                         string source = gc.get_string ("/apps/cinaest/default_source");
123                         if (source != null && source != "")
124                                 default_source.set_value (source);
125                 } catch (Error e) {
126                         stdout.printf ("Error getting GConf option: %s\n", e.message);
127                 }
128
129                 show_all ();
130
131                 do {
132                         res = base.run ();
133                         if (res >= 0) {
134                                 var plugin = CinaestProgram.plugins.nth_data (res);
135                                 plugin.settings_dialog (movie_list_window);
136                         }
137                 } while (res >= 0);
138
139                 if (res == ResponseType.ACCEPT) try {
140                         gc.set_bool ("/apps/cinaest/download_posters", download_posters.get_active ());
141                         gc.set_bool ("/apps/cinaest/start_movies", start_movies.get_active ());
142                         gc.set_string ("/apps/cinaest/default_source", default_source.get_value ());
143                 } catch (Error e) {
144                         stdout.printf ("Error setting GConf option: %s\n", e.message);
145                 }
146                 destroy ();
147
148                 return res;
149         }
150 }