diff options
author | Jan-Michael Brummer <jan.brummer@tabos.org> | 2018-05-01 22:48:43 +0200 |
---|---|---|
committer | David King <amigadave@amigadave.com> | 2018-05-18 13:11:06 +0100 |
commit | b1dccccafedd4025650a32aa8d915dc3415d5121 (patch) | |
tree | 9ce52a52247830b9f958f88da3dbf53281c5f29b /src | |
parent | 92e84f9651dc51138efd18337d8d2552e903248b (diff) | |
download | cheese-b1dccccafedd4025650a32aa8d915dc3415d5121.tar.gz |
cheese-window: Add camera toggle button
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=750285
Diffstat (limited to 'src')
-rw-r--r-- | src/cheese-window.vala | 93 |
1 files changed, 92 insertions, 1 deletions
diff --git a/src/cheese-window.vala b/src/cheese-window.vala index 50e024b1..09879fc5 100644 --- a/src/cheese-window.vala +++ b/src/cheese-window.vala @@ -73,6 +73,8 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow private Gtk.ToggleButton effects_toggle_button; [GtkChild] private Gtk.Widget buttons_area; + [GtkChild] + private Gtk.Button switch_camera_button; private Gtk.Menu thumbnail_popup; private Clutter.Stage viewport; @@ -1213,6 +1215,92 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow } /** + * Select next camera in list and activate it. + */ + public void on_switch_camera_clicked () + { + Cheese.CameraDevice selected; + Cheese.CameraDevice next = null; + GLib.PtrArray cameras; + uint i; + + if (camera == null) + { + return; + } + + selected = camera.get_selected_device (); + + if (selected == null) + { + return; + } + + cameras = camera.get_camera_devices (); + + for (i = 0; i < cameras.len; i++) + { + next = (Cheese.CameraDevice )cameras.index (i); + + if (next == selected) + { + break; + } + } + + if (i + 1 < cameras.len) + { + next = (Cheese.CameraDevice )cameras.index (i + 1); + } + else + { + next = (Cheese.CameraDevice )cameras.index (0); + } + + if (next == selected) + { + /* Next is the same device.... */ + return; + } + + camera.set_device (next); + camera.switch_camera_device (); + } + + /** + * Set switch camera buttons visible state. + */ + public void set_switch_camera_button_state () + { + Cheese.CameraDevice selected; + GLib.PtrArray cameras; + + if (camera == null) + { + switch_camera_button.set_visible (false); + return; + } + + selected = camera.get_selected_device (); + + if (selected == null) + { + switch_camera_button.set_visible (false); + return; + } + + cameras = camera.get_camera_devices (); + + if (cameras.len > 1) + { + switch_camera_button.set_visible (true); + return; + } + + switch_camera_button.set_visible (false); + } + + /** * Load the UI from the GtkBuilder description. */ public void setup_ui () @@ -1277,6 +1365,8 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow thumb_view.button_press_event.connect (on_thumbnail_button_press_event); + switch_camera_button.clicked.connect (on_switch_camera_clicked); + /* needed for the sizing tricks in set_wide_mode (allocation is 0 * if the widget is not realized */ viewport_widget.realize (); @@ -1368,5 +1458,6 @@ public class Cheese.MainWindow : Gtk.ApplicationWindow public void set_camera (Camera camera) { this.camera = camera; - } + set_switch_camera_button_state (); + } } |