2
* Copyright © 2010 Yuvaraj Pandian T <yuvipanda@yuvi.in>
3
* Copyright © 2010 daniel g. siegel <dgsiegel@gnome.org>
4
* Copyright © 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
6
* Licensed under the GNU General Public License Version 2
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24
public class Cheese.PreferencesDialog : GLib.Object
26
private Cheese.Camera camera;
28
private GLib.Settings settings;
30
private Gtk.Dialog dialog;
32
private Gtk.ComboBox photo_resolution_combo;
33
private Gtk.ComboBox video_resolution_combo;
34
private Gtk.ComboBox source_combo;
36
private Gtk.Adjustment brightness_adjustment;
37
private Gtk.Adjustment contrast_adjustment;
38
private Gtk.Adjustment hue_adjustment;
39
private Gtk.Adjustment saturation_adjustment;
41
private Gtk.Scale brightness_scale;
42
private Gtk.Scale contrast_scale;
43
private Gtk.Scale hue_scale;
44
private Gtk.Scale saturation_scale;
46
private Gtk.SpinButton burst_repeat_spin;
47
private Gtk.SpinButton burst_delay_spin;
49
private Gtk.CheckButton countdown_check;
50
private Gtk.CheckButton flash_check;
52
private MediaMode current_mode;
54
public PreferencesDialog (Cheese.Camera camera, GLib.Settings settings)
57
this.settings = settings;
59
Gtk.Builder builder = new Gtk.Builder ();
62
builder.add_from_file (GLib.Path.build_filename (Config.PACKAGE_DATADIR, "cheese-prefs.ui"));
66
error ("Error: %s", err.message);
69
this.dialog = (Gtk.Dialog)builder.get_object ("cheese_prefs_dialog");
71
this.brightness_adjustment = (Gtk.Adjustment) builder.get_object ("brightness_adjustment");
72
this.contrast_adjustment = (Gtk.Adjustment) builder.get_object ("contrast_adjustment");
73
this.hue_adjustment = (Gtk.Adjustment) builder.get_object ("hue_adjustment");
74
this.saturation_adjustment = (Gtk.Adjustment) builder.get_object ("saturation_adjustment");
76
/* Here instead of in cheese-prefs.ui because of https://bugzilla.gnome.org/show_bug.cgi?id=624443 */
78
this.brightness_scale = (Gtk.Scale) builder.get_object ("brightness_scale");
79
this.contrast_scale = (Gtk.Scale) builder.get_object ("contrast_scale");
80
this.hue_scale = (Gtk.Scale) builder.get_object ("hue_scale");
81
this.saturation_scale = (Gtk.Scale) builder.get_object ("saturation_scale");
83
this.brightness_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
84
this.contrast_scale.add_mark (1, Gtk.PositionType.BOTTOM, null);
85
this.hue_scale.add_mark (0, Gtk.PositionType.BOTTOM, null);
86
this.saturation_scale.add_mark (1, Gtk.PositionType.BOTTOM, null);
88
this.photo_resolution_combo = (Gtk.ComboBox) builder.get_object ("photo_resolution_combo_box");
89
this.video_resolution_combo = (Gtk.ComboBox) builder.get_object ("video_resolution_combo_box");
90
this.source_combo = (Gtk.ComboBox) builder.get_object ("camera_combo_box");
92
this.burst_repeat_spin = (Gtk.SpinButton) builder.get_object ("burst_repeat");
93
this.burst_delay_spin = (Gtk.SpinButton) builder.get_object ("burst_delay");
95
this.countdown_check = (Gtk.CheckButton) builder.get_object ("countdown");
96
this.flash_check = (Gtk.CheckButton) builder.get_object ("flash");
98
setup_combo_box_models ();
99
initialize_camera_devices ();
100
initialize_values_from_settings ();
103
* Connect signals only after all the widgets have been setup
104
* Stops a bunch of unnecessary signals from being fired
106
builder.connect_signals (this);
109
private void setup_combo_box_models ()
111
CellRendererText cell = new CellRendererText ();
113
photo_resolution_combo.pack_start (cell, false);
114
photo_resolution_combo.set_attributes (cell, "text", 0);
116
video_resolution_combo.pack_start (cell, false);
117
video_resolution_combo.set_attributes (cell, "text", 0);
119
source_combo.pack_start (cell, false);
120
source_combo.set_attributes (cell, "text", 0);
123
private void initialize_camera_devices ()
125
Cheese.CameraDevice dev;
126
unowned GLib.PtrArray devices = camera.get_camera_devices ();
127
ListStore camera_model = new ListStore (2, typeof (string), typeof (Cheese.CameraDevice));
129
source_combo.model = camera_model;
130
if (devices.len <= 1)
131
source_combo.sensitive = false;
133
for (int i = 0; i < devices.len; i++)
136
dev = (Cheese.CameraDevice) devices.index (i);
137
camera_model.append (out iter);
138
camera_model.set (iter,
139
0, dev.get_name () + " (" + dev.get_device_file () + " )",
141
if (camera.get_selected_device ().get_device_file () == dev.get_device_file ())
143
source_combo.set_active_iter (iter);
147
settings.set_string ("camera", camera.get_selected_device ().get_device_file ());
148
setup_resolutions_for_device (camera.get_selected_device ());
151
private void setup_resolutions_for_device (Cheese.CameraDevice device)
153
unowned List<VideoFormat> formats = device.get_format_list ();
154
unowned Cheese.VideoFormat format;
155
ListStore resolution_model = new ListStore (2, typeof (string), typeof (Cheese.VideoFormat));
157
photo_resolution_combo.model = resolution_model;
158
video_resolution_combo.model = resolution_model;
160
for (int i = 0; i < formats.length (); i++)
163
format = formats<VideoFormat>.nth (i).data;
164
resolution_model.append (out iter);
165
resolution_model.set (iter,
166
0, format.width.to_string () + " x " + format.height.to_string (),
168
if (camera.get_current_video_format ().width == format.width &&
169
camera.get_current_video_format ().height == format.height)
171
photo_resolution_combo.set_active_iter (iter);
172
settings.set_int ("photo-x-resolution", format.width);
173
settings.set_int ("photo-y-resolution", format.height);
176
if (settings.get_int ("video-x-resolution") == format.width &&
177
settings.get_int ("video-y-resolution") == format.height)
179
video_resolution_combo.set_active_iter (iter);
183
/* Video resolution combo shows photo resolution by
184
* default if previous user choice is not found in settings or not supported
185
* by current device. These values are saved to settings.
187
if (video_resolution_combo.get_active () == -1)
189
video_resolution_combo.set_active (photo_resolution_combo.get_active ());
190
settings.set_int ("video-x-resolution", settings.get_int ("photo-x-resolution"));
191
settings.set_int ("video-y-resolution", settings.get_int ("photo-y-resolution"));
195
private void initialize_values_from_settings ()
197
brightness_adjustment.value = settings.get_double ("brightness");
198
contrast_adjustment.value = settings.get_double ("contrast");
199
hue_adjustment.value = settings.get_double ("hue");
200
saturation_adjustment.value = settings.get_double ("saturation");
202
burst_repeat_spin.value = settings.get_int ("burst-repeat");
203
burst_delay_spin.value = settings.get_int ("burst-delay") / 1000;
205
countdown_check.active = settings.get_boolean ("countdown");
206
flash_check.active = settings.get_boolean ("flash");
209
[CCode (instance_pos = -1)]
210
public void on_source_change (Gtk.ComboBox combo)
214
Cheese.CameraDevice dev;
216
combo.get_active_iter (out iter);
217
combo.model.get (iter, 1, out dev);
218
camera.set_device_by_dev_file (dev.get_device_file ());
219
camera.switch_camera_device ();
220
setup_resolutions_for_device (camera.get_selected_device ());
221
settings.set_string ("camera", dev.get_device_file ());
224
[CCode (instance_pos = -1)]
225
public void on_photo_resolution_change (Gtk.ComboBox combo)
229
unowned Cheese.VideoFormat format;
231
combo.get_active_iter (out iter);
232
combo.model.get (iter, 1, out format);
234
if (current_mode == MediaMode.PHOTO || current_mode == MediaMode.BURST)
235
camera.set_video_format (format);
237
settings.set_int ("photo-x-resolution", format.width);
238
settings.set_int ("photo-y-resolution", format.height);
241
[CCode (instance_pos = -1)]
242
public void on_video_resolution_change (Gtk.ComboBox combo)
246
unowned Cheese.VideoFormat format;
248
combo.get_active_iter (out iter);
249
combo.model.get (iter, 1, out format);
251
if (current_mode == MediaMode.VIDEO)
252
camera.set_video_format (format);
254
settings.set_int ("video-x-resolution", format.width);
255
settings.set_int ("video-y-resolution", format.height);
258
[CCode (instance_pos = -1)]
259
public void on_dialog_close (Gtk.Button button)
264
[CCode (instance_pos = -1)]
265
public void on_countdown_toggle (Gtk.CheckButton checkbutton)
267
settings.set_boolean ("countdown", checkbutton.active);
270
[CCode (instance_pos = -1)]
271
public void on_flash_toggle (Gtk.CheckButton checkbutton)
273
settings.set_boolean ("flash", checkbutton.active);
276
[CCode (instance_pos = -1)]
277
public void on_burst_repeat_change (Gtk.SpinButton spinbutton)
279
settings.set_int ("burst-repeat", (int) spinbutton.value);
282
[CCode (instance_pos = -1)]
283
public void on_burst_delay_change (Gtk.SpinButton spinbutton)
285
settings.set_int ("burst-delay", (int) spinbutton.value * 1000);
288
[CCode (instance_pos = -1)]
289
public void on_brightness_change (Gtk.Adjustment adjustment)
291
this.camera.set_balance_property ("brightness", adjustment.value);
292
settings.set_double ("brightness", adjustment.value);
295
[CCode (instance_pos = -1)]
296
public void on_contrast_change (Gtk.Adjustment adjustment)
298
this.camera.set_balance_property ("contrast", adjustment.value);
299
settings.set_double ("contrast", adjustment.value);
302
[CCode (instance_pos = -1)]
303
public void on_hue_change (Gtk.Adjustment adjustment)
305
this.camera.set_balance_property ("hue", adjustment.value);
306
settings.set_double ("hue", adjustment.value);
309
[CCode (instance_pos = -1)]
310
public void on_saturation_change (Gtk.Adjustment adjustment)
312
this.camera.set_balance_property ("saturation", adjustment.value);
313
settings.set_double ("saturation", adjustment.value);
318
this.dialog.show_all ();
321
public void set_current_mode (MediaMode mode)
323
this.current_mode = mode;