~ubuntu-branches/ubuntu/precise/cheese/precise-proposed

« back to all changes in this revision

Viewing changes to src/cheese-preferences.vala

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher, Jeremy Bicha, Robert Ancell
  • Date: 2011-06-10 11:45:37 UTC
  • mfrom: (1.2.24 upstream)
  • Revision ID: james.westby@ubuntu.com-20110610114537-p9e4zl8m0ehf2b5a
Tags: 3.0.0-0ubuntu1
* Upload to oneiric

[ Jeremy Bicha ]
* Depend on gnome-video-effects since clicking Effects when it is
  not installed results in a segmentation fault.

[ Robert Ancell]
* New upstream version
* debian/control:
  - Use standards version 3.9.1
  - Add build-depends on dh-autoreconf, valac, libclutter-1.0-dev,
    libclutter-gtk-1.0-dev, libclutter-gst-dev, libmx-dev,
    gnome-video-effects-dev, libgee-dev, gnome-common, gobject-introspection, 
    libgirepository1.0-dev, gir1.2-freedesktop, gir1.2-glib-2.0, 
    gir1.2-gstreamer-0.10, gir1.2-clutter-1.0, gir1.2-gdkpixbuf-2.0
  - Drop build-depends on libgconf2-dev, libdbus-1-dev, libdbus-glib-1-dev,
  - Bump build-depends on libglib2.0-dev, libgtk-3-dev,
    libgnome-desktop-3-dev, libgstreamer0.10-dev,
    libgstreamer-plugins-base0.10-dev, libcairo2-dev, libpango1.0-dev,
    librsvg2-dev, libcanberra-gtk3-dev
  - Add new gir1.2-cheese-3.0 package
  - libcheese-gtk18 -> libcheese-gtk19
* debian/cheese.install:
* debian/cheese-common.install:
* debian/libcheese-gtk-dev.install
  - Update for new/changed files
* debian/gir1.2-cheese-3.0.install:
  - Install typelib
* debian/patches/fix-linking.patch:
  - Fix linking issues
* debian/patches/no-gnu-gettext.patch:
  - Don't use both AM_GNU_GETTEXT and IT_PROG_INTLTOOL

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>
 
5
 *
 
6
 * Licensed under the GNU General Public License Version 2
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 */
 
21
 
 
22
using Gtk;
 
23
 
 
24
public class Cheese.PreferencesDialog : GLib.Object
 
25
{
 
26
  private Cheese.Camera camera;
 
27
 
 
28
  private GLib.Settings settings;
 
29
 
 
30
  private Gtk.Dialog dialog;
 
31
 
 
32
  private Gtk.ComboBox photo_resolution_combo;
 
33
  private Gtk.ComboBox video_resolution_combo;
 
34
  private Gtk.ComboBox source_combo;
 
35
 
 
36
  private Gtk.Adjustment brightness_adjustment;
 
37
  private Gtk.Adjustment contrast_adjustment;
 
38
  private Gtk.Adjustment hue_adjustment;
 
39
  private Gtk.Adjustment saturation_adjustment;
 
40
 
 
41
  private Gtk.Scale brightness_scale;
 
42
  private Gtk.Scale contrast_scale;
 
43
  private Gtk.Scale hue_scale;
 
44
  private Gtk.Scale saturation_scale;
 
45
 
 
46
  private Gtk.SpinButton burst_repeat_spin;
 
47
  private Gtk.SpinButton burst_delay_spin;
 
48
 
 
49
  private Gtk.CheckButton countdown_check;
 
50
  private Gtk.CheckButton flash_check;
 
51
  
 
52
  private MediaMode current_mode;
 
53
 
 
54
  public PreferencesDialog (Cheese.Camera camera, GLib.Settings settings)
 
55
  {
 
56
    this.camera = camera;
 
57
    this.settings   = settings;
 
58
 
 
59
    Gtk.Builder builder = new Gtk.Builder ();
 
60
    try
 
61
    {
 
62
      builder.add_from_file (GLib.Path.build_filename (Config.PACKAGE_DATADIR, "cheese-prefs.ui"));
 
63
    }
 
64
    catch (Error err)
 
65
    {
 
66
      error ("Error: %s", err.message);
 
67
    }
 
68
 
 
69
    this.dialog = (Gtk.Dialog)builder.get_object ("cheese_prefs_dialog");
 
70
 
 
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");
 
75
 
 
76
    /* Here instead of in cheese-prefs.ui because of https://bugzilla.gnome.org/show_bug.cgi?id=624443 */
 
77
 
 
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");
 
82
 
 
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);
 
87
 
 
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");
 
91
 
 
92
    this.burst_repeat_spin = (Gtk.SpinButton) builder.get_object ("burst_repeat");
 
93
    this.burst_delay_spin  = (Gtk.SpinButton) builder.get_object ("burst_delay");
 
94
 
 
95
    this.countdown_check  = (Gtk.CheckButton) builder.get_object ("countdown");
 
96
    this.flash_check  = (Gtk.CheckButton) builder.get_object ("flash");
 
97
 
 
98
    setup_combo_box_models ();
 
99
    initialize_camera_devices ();
 
100
    initialize_values_from_settings ();
 
101
 
 
102
    /*
 
103
     * Connect signals only after all the widgets have been setup
 
104
     * Stops a bunch of unnecessary signals from being fired
 
105
     */
 
106
    builder.connect_signals (this);
 
107
  }
 
108
 
 
109
  private void setup_combo_box_models ()
 
110
  {
 
111
    CellRendererText cell = new CellRendererText ();
 
112
 
 
113
    photo_resolution_combo.pack_start (cell, false);
 
114
    photo_resolution_combo.set_attributes (cell, "text", 0);
 
115
 
 
116
    video_resolution_combo.pack_start (cell, false);
 
117
    video_resolution_combo.set_attributes (cell, "text", 0);
 
118
 
 
119
    source_combo.pack_start (cell, false);
 
120
    source_combo.set_attributes (cell, "text", 0);
 
121
  }
 
122
 
 
123
  private void initialize_camera_devices ()
 
124
  {
 
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));
 
128
 
 
129
    source_combo.model = camera_model;
 
130
    if (devices.len <= 1)
 
131
      source_combo.sensitive = false;
 
132
 
 
133
    for (int i = 0; i < devices.len; i++)
 
134
    {
 
135
      TreeIter iter;
 
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 () + " )",
 
140
                        1, dev);
 
141
      if (camera.get_selected_device ().get_device_file () == dev.get_device_file ())
 
142
      {
 
143
        source_combo.set_active_iter (iter);
 
144
      }
 
145
    }
 
146
 
 
147
    settings.set_string ("camera", camera.get_selected_device ().get_device_file ());
 
148
    setup_resolutions_for_device (camera.get_selected_device ());
 
149
  }
 
150
 
 
151
  private void setup_resolutions_for_device (Cheese.CameraDevice device)
 
152
  {
 
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));
 
156
 
 
157
    photo_resolution_combo.model = resolution_model;
 
158
    video_resolution_combo.model = resolution_model;
 
159
 
 
160
    for (int i = 0; i < formats.length (); i++)
 
161
    {
 
162
      TreeIter iter;
 
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 (),
 
167
                            1, format);
 
168
      if (camera.get_current_video_format ().width == format.width &&
 
169
          camera.get_current_video_format ().height == format.height)
 
170
      {
 
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);
 
174
      }
 
175
 
 
176
      if (settings.get_int ("video-x-resolution") == format.width &&
 
177
          settings.get_int ("video-y-resolution") == format.height)
 
178
      {
 
179
        video_resolution_combo.set_active_iter (iter);
 
180
      }
 
181
    }
 
182
 
 
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.
 
186
    */
 
187
    if (video_resolution_combo.get_active () == -1)
 
188
    {
 
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"));
 
192
    }
 
193
  }
 
194
 
 
195
  private void initialize_values_from_settings ()
 
196
  {
 
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");
 
201
 
 
202
    burst_repeat_spin.value = settings.get_int ("burst-repeat");
 
203
    burst_delay_spin.value  = settings.get_int ("burst-delay") / 1000;
 
204
 
 
205
    countdown_check.active = settings.get_boolean ("countdown");
 
206
    flash_check.active = settings.get_boolean ("flash");
 
207
  }
 
208
 
 
209
  [CCode (instance_pos = -1)]
 
210
  public void on_source_change (Gtk.ComboBox combo)
 
211
  {
 
212
    TreeIter iter;
 
213
 
 
214
    Cheese.CameraDevice dev;
 
215
 
 
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 ());
 
222
  }
 
223
 
 
224
  [CCode (instance_pos = -1)]
 
225
  public void on_photo_resolution_change (Gtk.ComboBox combo)
 
226
  {
 
227
    TreeIter iter;
 
228
 
 
229
    unowned Cheese.VideoFormat format;
 
230
 
 
231
    combo.get_active_iter (out iter);
 
232
    combo.model.get (iter, 1, out format);
 
233
    
 
234
    if (current_mode == MediaMode.PHOTO || current_mode == MediaMode.BURST)
 
235
      camera.set_video_format (format);
 
236
 
 
237
    settings.set_int ("photo-x-resolution", format.width);
 
238
    settings.set_int ("photo-y-resolution", format.height);
 
239
  }
 
240
 
 
241
  [CCode (instance_pos = -1)]
 
242
  public void on_video_resolution_change (Gtk.ComboBox combo)
 
243
  {
 
244
    TreeIter iter;
 
245
 
 
246
    unowned Cheese.VideoFormat format;
 
247
 
 
248
    combo.get_active_iter (out iter);
 
249
    combo.model.get (iter, 1, out format);
 
250
    
 
251
    if (current_mode == MediaMode.VIDEO)
 
252
      camera.set_video_format (format);
 
253
 
 
254
    settings.set_int ("video-x-resolution", format.width);
 
255
    settings.set_int ("video-y-resolution", format.height);
 
256
  }
 
257
 
 
258
  [CCode (instance_pos = -1)]
 
259
  public void on_dialog_close (Gtk.Button button)
 
260
  {
 
261
    this.dialog.hide ();
 
262
  }
 
263
 
 
264
  [CCode (instance_pos = -1)]
 
265
  public void on_countdown_toggle (Gtk.CheckButton checkbutton)
 
266
  {
 
267
    settings.set_boolean ("countdown", checkbutton.active);
 
268
  }
 
269
 
 
270
  [CCode (instance_pos = -1)]
 
271
  public void on_flash_toggle (Gtk.CheckButton checkbutton)
 
272
  {
 
273
    settings.set_boolean ("flash", checkbutton.active);
 
274
  }
 
275
 
 
276
  [CCode (instance_pos = -1)]
 
277
  public void on_burst_repeat_change (Gtk.SpinButton spinbutton)
 
278
  {
 
279
    settings.set_int ("burst-repeat", (int) spinbutton.value);
 
280
  }
 
281
 
 
282
  [CCode (instance_pos = -1)]
 
283
  public void on_burst_delay_change (Gtk.SpinButton spinbutton)
 
284
  {
 
285
    settings.set_int ("burst-delay", (int) spinbutton.value * 1000);
 
286
  }
 
287
 
 
288
  [CCode (instance_pos = -1)]
 
289
  public void on_brightness_change (Gtk.Adjustment adjustment)
 
290
  {
 
291
    this.camera.set_balance_property ("brightness", adjustment.value);
 
292
    settings.set_double ("brightness", adjustment.value);
 
293
  }
 
294
 
 
295
  [CCode (instance_pos = -1)]
 
296
  public void on_contrast_change (Gtk.Adjustment adjustment)
 
297
  {
 
298
    this.camera.set_balance_property ("contrast", adjustment.value);
 
299
    settings.set_double ("contrast", adjustment.value);
 
300
  }
 
301
 
 
302
  [CCode (instance_pos = -1)]
 
303
  public void on_hue_change (Gtk.Adjustment adjustment)
 
304
  {
 
305
    this.camera.set_balance_property ("hue", adjustment.value);
 
306
    settings.set_double ("hue", adjustment.value);
 
307
  }
 
308
 
 
309
  [CCode (instance_pos = -1)]
 
310
  public void on_saturation_change (Gtk.Adjustment adjustment)
 
311
  {
 
312
    this.camera.set_balance_property ("saturation", adjustment.value);
 
313
    settings.set_double ("saturation", adjustment.value);
 
314
  }
 
315
 
 
316
  public void show ()
 
317
  {
 
318
    this.dialog.show_all ();
 
319
  }
 
320
  
 
321
  public void set_current_mode (MediaMode mode)
 
322
  {
 
323
    this.current_mode = mode;
 
324
  }
 
325
  
 
326
}