[cheese] Add CheeseAvatarWidget
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese] Add CheeseAvatarWidget
- Date: Mon, 28 Oct 2013 21:50:35 +0000 (UTC)
commit 3a1d55c9371ab642670064254d8f473e48104eac
Author: Bastien Nocera <hadess hadess net>
Date: Fri Oct 25 12:26:08 2013 +0200
Add CheeseAvatarWidget
A stand-alone widget for avatar capture, like the avatar chooser but
without the precanned dialogue.
https://bugzilla.gnome.org/show_bug.cgi?id=710874
Makefile.am | 2 +
docs/reference/cheese.types | 1 +
libcheese/cheese-avatar-chooser.c | 237 ++----------------------
libcheese/cheese-avatar-widget.c | 366 +++++++++++++++++++++++++++++++++++++
libcheese/cheese-avatar-widget.h | 72 ++++++++
libcheese/cheese-gtk.symbols | 2 +
po/POTFILES.in | 1 +
7 files changed, 463 insertions(+), 218 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index 5f3019f..b358687 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -97,6 +97,7 @@ libcheese_gtk_la_LDFLAGS = \
libcheese_gtk_la_SOURCES = \
libcheese/cheese-avatar-chooser.c \
+ libcheese/cheese-avatar-widget.c \
libcheese/totem-aspect-frame.c \
libcheese/cheese-flash.c \
libcheese/cheese-gtk.c \
@@ -106,6 +107,7 @@ libcheese_gtk_la_SOURCES = \
noinst_libcheese_gtk_headers = \
libcheese/totem-aspect-frame.h \
libcheese/cheese-avatar-chooser.h \
+ libcheese/cheese-avatar-widget.c \
libcheese/cheese-flash.h \
libcheese/cheese-widget.h \
libcheese/cheese-widget-private.h \
diff --git a/docs/reference/cheese.types b/docs/reference/cheese.types
index c8803fd..00f337e 100644
--- a/docs/reference/cheese.types
+++ b/docs/reference/cheese.types
@@ -1,4 +1,5 @@
cheese_avatar_chooser_get_type
+cheese_avatar_widget_get_type
cheese_camera_device_get_type
cheese_camera_device_monitor_get_type
cheese_camera_get_type
diff --git a/libcheese/cheese-avatar-chooser.c b/libcheese/cheese-avatar-chooser.c
index 740d555..e0fd485 100644
--- a/libcheese/cheese-avatar-chooser.c
+++ b/libcheese/cheese-avatar-chooser.c
@@ -26,6 +26,7 @@
#include "cheese-widget-private.h"
#include "cheese-flash.h"
#include "cheese-avatar-chooser.h"
+#include "cheese-avatar-widget.h"
#include "um-crop-area.h"
/**
@@ -58,13 +59,7 @@ enum
struct _CheeseAvatarChooserPrivate
{
- GtkWidget *notebook;
- GtkWidget *camera;
- GtkWidget *image;
- GtkWidget *take_button;
- GtkWidget *take_again_button;
- CheeseFlash *flash;
- gulong photo_taken_id;
+ GtkWidget *widget;
};
static GParamSpec *properties[PROP_LAST];
@@ -75,179 +70,26 @@ static GParamSpec *properties[PROP_LAST];
G_DEFINE_TYPE (CheeseAvatarChooser, cheese_avatar_chooser, GTK_TYPE_DIALOG);
-/*
- * cheese_widget_photo_taken_cb:
- * @camera: a #CheeseCamera
- * @pixbuf: the #GdkPixbuf of the image that was just taken
- * @choose: a #CheeseAvatarChooser
- *
- * Show the image that was just taken from the camera (as @pixbuf) in the
- * cropping tool.
- */
-static void
-cheese_widget_photo_taken_cb (CheeseCamera *camera,
- GdkPixbuf *pixbuf,
- CheeseAvatarChooser *chooser)
-{
- CheeseAvatarChooserPrivate *priv = chooser->priv;
- GtkAllocation allocation;
-
- gtk_widget_get_allocation (priv->camera, &allocation);
- gtk_widget_set_size_request (priv->image, allocation.width, allocation.height);
-
- um_crop_area_set_picture (UM_CROP_AREA (priv->image), pixbuf);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), IMAGE_PAGE);
- gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
- GTK_RESPONSE_ACCEPT,
- TRUE);
- gtk_widget_set_sensitive (priv->take_button, TRUE);
-
- g_object_notify_by_pspec (G_OBJECT (chooser), properties[PROP_PIXBUF]);
-}
-
-/*
- * take_button_clicked_cb:
- * @button: the #GtkButton that was clicked
- * @chooser: the #CheeseAvatarChooser
- *
- * Take a photo with the #CheeseCamera of @chooser. When the photo has been
- * taken, call cheese_widget_photo_taken_cb().
- */
-static void
-take_button_clicked_cb (GtkButton *button,
- CheeseAvatarChooser *chooser)
-{
- CheeseAvatarChooserPrivate *priv = chooser->priv;
- GObject *camera;
-
- camera = cheese_widget_get_camera (CHEESE_WIDGET (priv->camera));
- if (priv->photo_taken_id == 0)
- {
- gtk_widget_set_sensitive (priv->take_button, FALSE);
- priv->photo_taken_id = g_signal_connect (G_OBJECT (camera), "photo-taken",
- G_CALLBACK (cheese_widget_photo_taken_cb), chooser);
- }
- if (cheese_camera_take_photo_pixbuf (CHEESE_CAMERA (camera)))
- {
- cheese_flash_fire (CHEESE_FLASH (priv->flash));
- ca_gtk_play_for_widget (GTK_WIDGET (chooser), 0,
- CA_PROP_EVENT_ID, "camera-shutter",
- CA_PROP_MEDIA_ROLE, "event",
- CA_PROP_EVENT_DESCRIPTION, _("Shutter sound"),
- NULL);
- }
- else
- {
- g_assert_not_reached ();
- }
-}
-
-/*
- * take_again_button_clicked_cb:
- * @button: the #GtkButton that was clicked
- * @chooser: the #CheeseAvatarChooser
- *
- * Switch the @chooser back to the camera view, ready to take another photo.
- */
static void
-take_again_button_clicked_cb (GtkButton *button,
- CheeseAvatarChooser *chooser)
+update_select_button (CheeseAvatarWidget *widget,
+ GParamSpec *pspec,
+ CheeseAvatarChooser *chooser)
{
- CheeseAvatarChooserPrivate *priv = chooser->priv;
+ GdkPixbuf *pixbuf;
- gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), WIDGET_PAGE);
+ g_object_get (G_OBJECT (widget), "pixbuf", &pixbuf, NULL);
gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
GTK_RESPONSE_ACCEPT,
- FALSE);
-
- um_crop_area_set_picture (UM_CROP_AREA (priv->image), NULL);
-
- g_object_notify_by_pspec (G_OBJECT (chooser), properties[PROP_PIXBUF]);
-}
-
-/* state_change_cb:
- * @object: the #CheeseWidget on which the state changed
- * @param_spec: the (unused) parameter specification
- * @chooser: a #CheeseAvatarChooser
- *
- * Handle state changes on the #CheeseWidget, and update the UI appropriately.
- */
-static void
-state_change_cb (GObject *object,
- GParamSpec *param_spec,
- CheeseAvatarChooser *chooser)
-{
- CheeseAvatarChooserPrivate *priv = chooser->priv;
- CheeseWidgetState state;
-
- g_object_get (object, "state", &state, NULL);
-
- switch (state)
- {
- case CHEESE_WIDGET_STATE_READY:
- gtk_widget_set_sensitive (priv->take_button, TRUE);
- gtk_widget_set_sensitive (priv->take_again_button, TRUE);
- break;
- case CHEESE_WIDGET_STATE_ERROR:
- gtk_widget_set_sensitive (priv->take_button, FALSE);
- gtk_widget_set_sensitive (priv->take_again_button, FALSE);
- break;
- case CHEESE_WIDGET_STATE_NONE:
- break;
- default:
- g_assert_not_reached ();
- }
-}
-
-/*
- * create_page:
- * @child: the #CheeseWidget to pack into the container
- * @button: the #GtkButton for taking a photo
- *
- * Create the widgets for the #CheeseAvatarChooser and pack them into a
- * container.
- *
- * Returns: a #GtkBox containing the individual #CheeseAvatarChooser widgets
- */
-static GtkWidget *
-create_page (GtkWidget *child,
- GtkWidget *button)
-{
- GtkWidget *vgrid, *bar;
- GtkStyleContext *context;
-
- vgrid = gtk_grid_new ();
- gtk_grid_attach (GTK_GRID (vgrid),
- child, 0, 0, 1, 1);
- gtk_widget_set_hexpand (child, TRUE);
- gtk_widget_set_vexpand (child, TRUE);
-
- bar = gtk_header_bar_new ();
- context = gtk_widget_get_style_context (GTK_WIDGET (bar));
- gtk_style_context_remove_class (context, "header-bar");
- gtk_style_context_add_class (context, "inline-toolbar");
- gtk_style_context_add_class (context, "toolbar");
- gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
-
- g_object_set (G_OBJECT (button), "margin-top", 6, "margin-bottom", 6, NULL);
- gtk_header_bar_set_custom_title (GTK_HEADER_BAR (bar), button);
- gtk_grid_attach (GTK_GRID (vgrid),
- bar, 0, 1, 1, 1);
-
- return vgrid;
+ pixbuf != NULL);
+ if (pixbuf)
+ g_object_unref (pixbuf);
}
static void
cheese_avatar_chooser_init (CheeseAvatarChooser *chooser)
{
- GtkWidget *frame;
- GtkWidget *image;
- GtkSizeGroup *sizegroup;
-
CheeseAvatarChooserPrivate *priv = chooser->priv = CHEESE_AVATAR_CHOOSER_GET_PRIVATE (chooser);
- priv->flash = cheese_flash_new (GTK_WIDGET (chooser));
-
gtk_dialog_add_buttons (GTK_DIALOG (chooser),
GTK_STOCK_CANCEL,
GTK_RESPONSE_REJECT,
@@ -260,57 +102,17 @@ cheese_avatar_chooser_init (CheeseAvatarChooser *chooser)
GTK_RESPONSE_ACCEPT,
FALSE);
- priv->notebook = gtk_notebook_new ();
- g_object_set(G_OBJECT (priv->notebook), "margin", 12, NULL);
- gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
- gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
+ g_object_set (G_OBJECT (gtk_dialog_get_action_area (GTK_DIALOG (chooser))), "margin", 8, NULL);
+ priv->widget = cheese_avatar_widget_new ();
+ gtk_widget_show (priv->widget);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (chooser))),
- priv->notebook,
- TRUE, TRUE, 8);
-
- /* Camera tab */
- priv->camera = cheese_widget_new ();
- g_signal_connect (G_OBJECT (priv->camera), "notify::state",
- G_CALLBACK (state_change_cb), chooser);
- image = gtk_image_new_from_icon_name ("camera-photo-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
- priv->take_button = gtk_button_new ();
- gtk_button_set_image (GTK_BUTTON (priv->take_button), image);
- g_signal_connect (G_OBJECT (priv->take_button), "clicked",
- G_CALLBACK (take_button_clicked_cb), chooser);
- gtk_widget_set_sensitive (priv->take_button, FALSE);
- gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
- create_page (priv->camera, priv->take_button),
- gtk_label_new ("webcam"));
-
- /* Image tab */
- priv->image = um_crop_area_new ();
- frame = gtk_frame_new (NULL);
- gtk_container_add (GTK_CONTAINER (frame), priv->image);
- gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
- priv->take_again_button = gtk_button_new_with_mnemonic (_("_Take Another Picture"));
- g_signal_connect (G_OBJECT (priv->take_again_button), "clicked",
- G_CALLBACK (take_again_button_clicked_cb), chooser);
- gtk_widget_set_sensitive (priv->take_again_button, FALSE);
- gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
- create_page (frame, priv->take_again_button),
- gtk_label_new ("image"));
-
- sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
- gtk_size_group_add_widget (sizegroup, priv->take_button);
- gtk_size_group_add_widget (sizegroup, priv->take_again_button);
-
- gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (chooser)));
-}
-
-static void
-cheese_avatar_chooser_finalize (GObject *object)
-{
- CheeseAvatarChooserPrivate *priv = ((CheeseAvatarChooser *) object)->priv;
+ priv->widget,
+ TRUE, TRUE, 0);
- g_clear_object (&priv->flash);
+ g_signal_connect (G_OBJECT (priv->widget), "notify::pixbuf",
+ G_CALLBACK (update_select_button), chooser);
- G_OBJECT_CLASS (cheese_avatar_chooser_parent_class)->finalize (object);
}
static void
@@ -322,7 +124,7 @@ cheese_avatar_chooser_get_property (GObject *object, guint prop_id,
switch (prop_id)
{
case PROP_PIXBUF:
- g_value_set_object (value, um_crop_area_get_picture (UM_CROP_AREA (priv->image)));
+ g_value_set_object (value, cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv->widget)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -335,7 +137,6 @@ cheese_avatar_chooser_class_init (CheeseAvatarChooserClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = cheese_avatar_chooser_finalize;
object_class->get_property = cheese_avatar_chooser_get_property;
/**
@@ -381,5 +182,5 @@ cheese_avatar_chooser_get_picture (CheeseAvatarChooser *chooser)
{
g_return_val_if_fail (CHEESE_IS_AVATAR_CHOOSER (chooser), NULL);
- return um_crop_area_get_picture (UM_CROP_AREA (chooser->priv->image));
+ return cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (chooser->priv->widget));
}
diff --git a/libcheese/cheese-avatar-widget.c b/libcheese/cheese-avatar-widget.c
new file mode 100644
index 0000000..d8d75b6
--- /dev/null
+++ b/libcheese/cheese-avatar-widget.c
@@ -0,0 +1,366 @@
+/*
+ * Copyright © 2009 Bastien Nocera <hadess hadess net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "cheese-config.h"
+
+#include <glib/gi18n.h>
+#include <canberra-gtk.h>
+
+#include "cheese-camera.h"
+#include "cheese-widget-private.h"
+#include "cheese-flash.h"
+#include "cheese-avatar-widget.h"
+#include "um-crop-area.h"
+
+/**
+ * SECTION:cheese-avatar-widget
+ * @short_description: A photo capture dialog for avatars
+ * @stability: Unstable
+ * @include: cheese/cheese-avatar-widget.h
+ *
+ * #CheeseAvatarWidget presents a simple window to the user for taking a photo
+ * for use as an avatar.
+ */
+
+enum
+{
+ LAST_SIGNAL
+};
+
+enum
+{
+ PROP_0,
+ PROP_PIXBUF,
+ PROP_LAST
+};
+
+enum
+{
+ WIDGET_PAGE = 0,
+ IMAGE_PAGE = 1,
+};
+
+struct _CheeseAvatarWidgetPrivate
+{
+ GtkWidget *notebook;
+ GtkWidget *camera;
+ GtkWidget *image;
+ GtkWidget *take_button;
+ GtkWidget *take_again_button;
+ CheeseFlash *flash;
+ gulong photo_taken_id;
+};
+
+static GParamSpec *properties[PROP_LAST];
+
+#define CHEESE_AVATAR_WIDGET_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), CHEESE_TYPE_AVATAR_WIDGET, \
+ CheeseAvatarWidgetPrivate))
+
+G_DEFINE_TYPE (CheeseAvatarWidget, cheese_avatar_widget, GTK_TYPE_BIN);
+
+/*
+ * cheese_widget_photo_taken_cb:
+ * @camera: a #CheeseCamera
+ * @pixbuf: the #GdkPixbuf of the image that was just taken
+ * @choose: a #CheeseAvatarWidget
+ *
+ * Show the image that was just taken from the camera (as @pixbuf) in the
+ * cropping tool.
+ */
+static void
+cheese_widget_photo_taken_cb (CheeseCamera *camera,
+ GdkPixbuf *pixbuf,
+ CheeseAvatarWidget *widget)
+{
+ CheeseAvatarWidgetPrivate *priv = widget->priv;
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (priv->camera, &allocation);
+ gtk_widget_set_size_request (priv->image, allocation.width, allocation.height);
+
+ um_crop_area_set_picture (UM_CROP_AREA (priv->image), pixbuf);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), IMAGE_PAGE);
+
+ gtk_widget_set_sensitive (priv->take_button, TRUE);
+
+ g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_PIXBUF]);
+}
+
+/*
+ * take_button_clicked_cb:
+ * @button: the #GtkButton that was clicked
+ * @widget: the #CheeseAvatarWidget
+ *
+ * Take a photo with the #CheeseCamera of @widget. When the photo has been
+ * taken, call cheese_widget_photo_taken_cb().
+ */
+static void
+take_button_clicked_cb (GtkButton *button,
+ CheeseAvatarWidget *widget)
+{
+ CheeseAvatarWidgetPrivate *priv = widget->priv;
+ GObject *camera;
+
+ camera = cheese_widget_get_camera (CHEESE_WIDGET (priv->camera));
+ if (priv->photo_taken_id == 0)
+ {
+ gtk_widget_set_sensitive (priv->take_button, FALSE);
+ priv->photo_taken_id = g_signal_connect (G_OBJECT (camera), "photo-taken",
+ G_CALLBACK (cheese_widget_photo_taken_cb), widget);
+ }
+ if (cheese_camera_take_photo_pixbuf (CHEESE_CAMERA (camera)))
+ {
+ cheese_flash_fire (CHEESE_FLASH (priv->flash));
+ ca_gtk_play_for_widget (GTK_WIDGET (widget), 0,
+ CA_PROP_EVENT_ID, "camera-shutter",
+ CA_PROP_MEDIA_ROLE, "event",
+ CA_PROP_EVENT_DESCRIPTION, _("Shutter sound"),
+ NULL);
+ }
+ else
+ {
+ g_assert_not_reached ();
+ }
+}
+
+/*
+ * take_again_button_clicked_cb:
+ * @button: the #GtkButton that was clicked
+ * @widget: the #CheeseAvatarWidget
+ *
+ * Switch the @widget back to the camera view, ready to take another photo.
+ */
+static void
+take_again_button_clicked_cb (GtkButton *button,
+ CheeseAvatarWidget *widget)
+{
+ CheeseAvatarWidgetPrivate *priv = widget->priv;
+
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook), WIDGET_PAGE);
+
+ um_crop_area_set_picture (UM_CROP_AREA (priv->image), NULL);
+
+ g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_PIXBUF]);
+}
+
+/* state_change_cb:
+ * @object: the #CheeseWidget on which the state changed
+ * @param_spec: the (unused) parameter specification
+ * @widget: a #CheeseAvatarWidget
+ *
+ * Handle state changes on the #CheeseWidget, and update the UI appropriately.
+ */
+static void
+state_change_cb (GObject *object,
+ GParamSpec *param_spec,
+ CheeseAvatarWidget *widget)
+{
+ CheeseAvatarWidgetPrivate *priv = widget->priv;
+ CheeseWidgetState state;
+
+ g_object_get (object, "state", &state, NULL);
+
+ switch (state)
+ {
+ case CHEESE_WIDGET_STATE_READY:
+ gtk_widget_set_sensitive (priv->take_button, TRUE);
+ gtk_widget_set_sensitive (priv->take_again_button, TRUE);
+ break;
+ case CHEESE_WIDGET_STATE_ERROR:
+ gtk_widget_set_sensitive (priv->take_button, FALSE);
+ gtk_widget_set_sensitive (priv->take_again_button, FALSE);
+ break;
+ case CHEESE_WIDGET_STATE_NONE:
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+/*
+ * create_page:
+ * @child: the #CheeseWidget to pack into the container
+ * @button: the #GtkButton for taking a photo
+ *
+ * Create the widgets for the #CheeseAvatarWidget and pack them into a
+ * container.
+ *
+ * Returns: a #GtkBox containing the individual #CheeseAvatarWidget widgets
+ */
+static GtkWidget *
+create_page (GtkWidget *child,
+ GtkWidget *button)
+{
+ GtkWidget *vgrid, *bar;
+ GtkStyleContext *context;
+
+ vgrid = gtk_grid_new ();
+ gtk_grid_attach (GTK_GRID (vgrid),
+ child, 0, 0, 1, 1);
+ gtk_widget_set_hexpand (child, TRUE);
+ gtk_widget_set_vexpand (child, TRUE);
+
+ bar = gtk_header_bar_new ();
+ context = gtk_widget_get_style_context (GTK_WIDGET (bar));
+ gtk_style_context_remove_class (context, "header-bar");
+ gtk_style_context_add_class (context, "inline-toolbar");
+ gtk_style_context_add_class (context, "toolbar");
+ gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
+
+ g_object_set (G_OBJECT (button), "margin-top", 6, "margin-bottom", 6, NULL);
+ gtk_header_bar_set_custom_title (GTK_HEADER_BAR (bar), button);
+ gtk_grid_attach (GTK_GRID (vgrid),
+ bar, 0, 1, 1, 1);
+
+ return vgrid;
+}
+
+static void
+cheese_avatar_widget_init (CheeseAvatarWidget *widget)
+{
+ GtkWidget *frame;
+ GtkWidget *image;
+ GtkSizeGroup *sizegroup;
+
+ CheeseAvatarWidgetPrivate *priv = widget->priv = CHEESE_AVATAR_WIDGET_GET_PRIVATE (widget);
+
+ priv->flash = cheese_flash_new (GTK_WIDGET (widget));
+
+ priv->notebook = gtk_notebook_new ();
+ g_object_set(G_OBJECT (priv->notebook), "margin", 12, NULL);
+ gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
+
+ gtk_container_add (GTK_CONTAINER (widget), priv->notebook);
+
+ /* Camera tab */
+ priv->camera = cheese_widget_new ();
+ g_signal_connect (G_OBJECT (priv->camera), "notify::state",
+ G_CALLBACK (state_change_cb), widget);
+ image = gtk_image_new_from_icon_name ("camera-photo-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
+ priv->take_button = gtk_button_new ();
+ gtk_button_set_image (GTK_BUTTON (priv->take_button), image);
+ g_signal_connect (G_OBJECT (priv->take_button), "clicked",
+ G_CALLBACK (take_button_clicked_cb), widget);
+ gtk_widget_set_sensitive (priv->take_button, FALSE);
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
+ create_page (priv->camera, priv->take_button),
+ gtk_label_new ("webcam"));
+
+ /* Image tab */
+ priv->image = um_crop_area_new ();
+ frame = gtk_frame_new (NULL);
+ gtk_container_add (GTK_CONTAINER (frame), priv->image);
+ gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_ETCHED_IN);
+ priv->take_again_button = gtk_button_new_with_mnemonic (_("_Take Another Picture"));
+ g_signal_connect (G_OBJECT (priv->take_again_button), "clicked",
+ G_CALLBACK (take_again_button_clicked_cb), widget);
+ gtk_widget_set_sensitive (priv->take_again_button, FALSE);
+ gtk_notebook_append_page (GTK_NOTEBOOK (priv->notebook),
+ create_page (frame, priv->take_again_button),
+ gtk_label_new ("image"));
+
+ sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
+ gtk_size_group_add_widget (sizegroup, priv->take_button);
+ gtk_size_group_add_widget (sizegroup, priv->take_again_button);
+
+ gtk_widget_show_all (GTK_WIDGET (widget));
+}
+
+static void
+cheese_avatar_widget_finalize (GObject *object)
+{
+ CheeseAvatarWidgetPrivate *priv = ((CheeseAvatarWidget *) object)->priv;
+
+ g_clear_object (&priv->flash);
+
+ G_OBJECT_CLASS (cheese_avatar_widget_parent_class)->finalize (object);
+}
+
+static void
+cheese_avatar_widget_get_property (GObject *object, guint prop_id,
+ GValue *value, GParamSpec *pspec)
+{
+ CheeseAvatarWidgetPrivate *priv = ((CheeseAvatarWidget *) object)->priv;
+
+ switch (prop_id)
+ {
+ case PROP_PIXBUF:
+ g_value_set_object (value, um_crop_area_get_picture (UM_CROP_AREA (priv->image)));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+cheese_avatar_widget_class_init (CheeseAvatarWidgetClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = cheese_avatar_widget_finalize;
+ object_class->get_property = cheese_avatar_widget_get_property;
+
+ /**
+ * CheeseAvatarWidget:pixbuf:
+ *
+ * A #GdkPixbuf object representing the cropped area of the picture, or %NULL.
+ */
+ properties[PROP_PIXBUF] = g_param_spec_object ("pixbuf",
+ "Pixbuf",
+ "A #GdkPixbuf object representing the cropped area of the
picture, or %NULL.",
+ GDK_TYPE_PIXBUF,
+ G_PARAM_READABLE);
+
+ g_object_class_install_properties (object_class, PROP_LAST, properties);
+
+ g_type_class_add_private (klass, sizeof (CheeseAvatarWidgetPrivate));
+}
+
+/**
+ * cheese_avatar_widget_new:
+ *
+ * Creates a new #CheeseAvatarWidget dialogue.
+ *
+ * Returns: a #CheeseAvatarWidget
+ */
+GtkWidget *
+cheese_avatar_widget_new (void)
+{
+ return g_object_new (CHEESE_TYPE_AVATAR_WIDGET, NULL);
+}
+
+/**
+ * cheese_avatar_widget_get_picture:
+ * @widget: a #CheeseAvatarWidget dialogue
+ *
+ * Returns the portion of image selected through the builtin cropping tool,
+ * after a picture has been captured on the webcam.
+ *
+ * Return value: a #GdkPixbuf object, or %NULL if no picture has been taken yet
+ */
+GdkPixbuf *
+cheese_avatar_widget_get_picture (CheeseAvatarWidget *widget)
+{
+ g_return_val_if_fail (CHEESE_IS_AVATAR_WIDGET (widget), NULL);
+
+ return um_crop_area_get_picture (UM_CROP_AREA (widget->priv->image));
+}
diff --git a/libcheese/cheese-avatar-widget.h b/libcheese/cheese-avatar-widget.h
new file mode 100644
index 0000000..9b7c121
--- /dev/null
+++ b/libcheese/cheese-avatar-widget.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright © 2009 Bastien Nocera <hadess hadess net>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _CHEESE_AVATAR_WIDGET_H_
+#define _CHEESE_AVATAR_WIDGET_H_
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define CHEESE_TYPE_AVATAR_WIDGET (cheese_avatar_widget_get_type ())
+#define CHEESE_AVATAR_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CHEESE_TYPE_AVATAR_WIDGET, \
+ CheeseAvatarWidget))
+#define CHEESE_AVATAR_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CHEESE_TYPE_AVATAR_WIDGET, \
+ CheeseAvatarWidgetClass))
+#define CHEESE_IS_AVATAR_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CHEESE_TYPE_AVATAR_WIDGET))
+#define CHEESE_IS_AVATAR_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CHEESE_TYPE_AVATAR_WIDGET))
+#define CHEESE_AVATAR_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CHEESE_TYPE_AVATAR_WIDGET, \
+ CheeseAvatarWidgetClass))
+
+typedef struct _CheeseAvatarWidgetPrivate CheeseAvatarWidgetPrivate;
+typedef struct _CheeseAvatarWidgetClass CheeseAvatarWidgetClass;
+typedef struct _CheeseAvatarWidget CheeseAvatarWidget;
+
+/**
+ * CheeseAvatarWidgetClass:
+ *
+ * Use the accessor functions below.
+ */
+struct _CheeseAvatarWidgetClass
+{
+ /*< private >*/
+ GtkBinClass parent_class;
+};
+
+/**
+ * CheeseAvatarWidget:
+ *
+ * Use the accessor functions below.
+ */
+struct _CheeseAvatarWidget
+{
+ /*< private >*/
+ GtkBin parent_instance;
+ CheeseAvatarWidgetPrivate *priv;
+};
+
+GType cheese_avatar_widget_get_type (void) G_GNUC_CONST;
+
+GtkWidget *cheese_avatar_widget_new (void);
+GdkPixbuf *cheese_avatar_widget_get_picture (CheeseAvatarWidget *widget);
+
+G_END_DECLS
+
+#endif /* _CHEESE_AVATAR_WIDGET_H_ */
diff --git a/libcheese/cheese-gtk.symbols b/libcheese/cheese-gtk.symbols
index fc43faf..f913444 100644
--- a/libcheese/cheese-gtk.symbols
+++ b/libcheese/cheese-gtk.symbols
@@ -14,6 +14,8 @@ cheese_avatar_chooser_get_type
cheese_avatar_chooser_new
cheese_avatar_chooser_get_picture
um_crop_area_get_type
+cheese_avatar_widget_get_type
+cheese_avatar_widget_get_picture
cheese_camera_device_monitor_get_type
cheese_camera_device_monitor_new
cheese_camera_device_monitor_coldplug
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 6175f0e..8675246 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -6,6 +6,7 @@
data/cheese.desktop.in.in
data/org.gnome.Cheese.gschema.xml
libcheese/cheese-avatar-chooser.c
+libcheese/cheese-avatar-widget.c
libcheese/cheese-camera.c
libcheese/cheese-camera-device.c
libcheese/cheese-widget.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]