[cheese] cheese-window: Add camera toggle button
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese] cheese-window: Add camera toggle button
- Date: Fri, 18 May 2018 12:12:20 +0000 (UTC)
commit b1dccccafedd4025650a32aa8d915dc3415d5121
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Tue May 1 22:48:43 2018 +0200
cheese-window: Add camera toggle button
Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=750285
data/cheese-main-window.ui | 19 ++++++++-
src/cheese-window.vala | 93 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 109 insertions(+), 3 deletions(-)
---
diff --git a/data/cheese-main-window.ui b/data/cheese-main-window.ui
index c0ff90f..bdaf5a1 100644
--- a/data/cheese-main-window.ui
+++ b/data/cheese-main-window.ui
@@ -35,12 +35,12 @@
<object class="GtkGrid" id="buttons_area">
<property name="border-width">6</property>
<property name="orientation">horizontal</property>
+ <property name="column-spacing">6</property>
<property name="visible">True</property>
<child>
<object class="GtkBox" id="mode_toggle_buttons">
<property name="orientation">horizontal</property>
<property name="halign">start</property>
- <property name="hexpand">True</property>
<property name="visible">True</property>
<style>
<class name="linked"/>
@@ -87,11 +87,27 @@
</packing>
</child>
<child>
+ <object class="GtkButton" id="switch_camera_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">True</property>
+ <property name="halign">start</property>
+ <child>
+ <object class="GtkImage">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">camera-switch-symbolic</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child>
<object class="GtkButton" id="take_action_button">
<property name="action-name">app.shoot</property>
<property name="tooltip_text" translatable="yes">Take a photo using a
webcam</property>
<property name="halign">center</property>
<property name="visible">True</property>
+ <property name="hexpand">True</property>
<style>
<class name="image-button"/>
</style>
@@ -107,7 +123,6 @@
<object class="GtkBox" id="effects_actions_pack">
<property name="orientation">horizontal</property>
<property name="halign">end</property>
- <property name="hexpand">True</property>
<property name="visible">True</property>
<style>
<class name="linked"/>
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index 50e024b..09879fc 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 ();
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]