Commit b1dcccca authored by Jan-Michael Brummer's avatar Jan-Michael Brummer Committed by David King

cheese-window: Add camera toggle button

Fixes: https://bugzilla.gnome.org/show_bug.cgi?id=750285
parent 92e84f96
......@@ -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"/>
......@@ -86,12 +86,28 @@
<packing>
</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"/>
......
......@@ -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;
......@@ -1212,6 +1214,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.
*/
......@@ -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 ();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment