Post-release version bump to 3.11.91
[cheese.git] / libcheese / cheese-avatar-chooser.c
blob05e4eef3de48f7772c8e4d480ce14b814019f2a8
1 /*
2 * Copyright © 2009 Bastien Nocera <hadess@hadess.net>
4 * Licensed under the GNU General Public License Version 2
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "cheese-config.h"
22 #include <glib/gi18n.h>
23 #include <canberra-gtk.h>
25 #include "cheese-camera.h"
26 #include "cheese-widget-private.h"
27 #include "cheese-flash.h"
28 #include "cheese-avatar-chooser.h"
29 #include "cheese-avatar-widget.h"
30 #include "um-crop-area.h"
32 /**
33 * SECTION:cheese-avatar-chooser
34 * @short_description: A photo capture dialog for avatars
35 * @stability: Unstable
36 * @include: cheese/cheese-avatar-chooser.h
38 * #CheeseAvatarChooser presents a simple window to the user for taking a photo
39 * for use as an avatar.
42 enum
44 LAST_SIGNAL
47 enum
49 PROP_0,
50 PROP_PIXBUF,
51 PROP_LAST
54 enum
56 WIDGET_PAGE = 0,
57 IMAGE_PAGE = 1,
60 struct _CheeseAvatarChooserPrivate
62 GtkWidget *widget;
65 static GParamSpec *properties[PROP_LAST];
67 G_DEFINE_TYPE_WITH_PRIVATE (CheeseAvatarChooser, cheese_avatar_chooser, GTK_TYPE_DIALOG);
69 static void
70 update_select_button (CheeseAvatarWidget *widget,
71 GParamSpec *pspec,
72 CheeseAvatarChooser *chooser)
74 GdkPixbuf *pixbuf;
76 g_object_get (G_OBJECT (widget), "pixbuf", &pixbuf, NULL);
77 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
78 GTK_RESPONSE_ACCEPT,
79 pixbuf != NULL);
80 if (pixbuf)
81 g_object_unref (pixbuf);
84 static void
85 cheese_avatar_chooser_init (CheeseAvatarChooser *chooser)
87 CheeseAvatarChooserPrivate *priv = chooser->priv = cheese_avatar_chooser_get_instance_private (chooser);
89 gtk_dialog_add_buttons (GTK_DIALOG (chooser),
90 _("_Cancel"),
91 GTK_RESPONSE_REJECT,
92 _("_Select"),
93 GTK_RESPONSE_ACCEPT,
94 NULL);
95 gtk_window_set_title (GTK_WINDOW (chooser), _("Take a Photo"));
97 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
98 GTK_RESPONSE_ACCEPT,
99 FALSE);
101 g_object_set (G_OBJECT (gtk_dialog_get_action_area (GTK_DIALOG (chooser))), "margin", 8, NULL);
103 priv->widget = cheese_avatar_widget_new ();
104 gtk_widget_show (priv->widget);
105 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (chooser))),
106 priv->widget,
107 TRUE, TRUE, 0);
109 g_signal_connect (G_OBJECT (priv->widget), "notify::pixbuf",
110 G_CALLBACK (update_select_button), chooser);
114 static void
115 cheese_avatar_chooser_get_property (GObject *object, guint prop_id,
116 GValue *value, GParamSpec *pspec)
118 CheeseAvatarChooserPrivate *priv = ((CheeseAvatarChooser *) object)->priv;
120 switch (prop_id)
122 case PROP_PIXBUF:
123 g_value_set_object (value, cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv->widget)));
124 break;
125 default:
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
127 break;
131 static void
132 cheese_avatar_chooser_class_init (CheeseAvatarChooserClass *klass)
134 GObjectClass *object_class = G_OBJECT_CLASS (klass);
136 object_class->get_property = cheese_avatar_chooser_get_property;
139 * CheeseAvatarChooser:pixbuf:
141 * A #GdkPixbuf object representing the cropped area of the picture, or %NULL.
143 properties[PROP_PIXBUF] = g_param_spec_object ("pixbuf",
144 "Pixbuf",
145 "A #GdkPixbuf object representing the cropped area of the picture, or %NULL.",
146 GDK_TYPE_PIXBUF,
147 G_PARAM_READABLE);
149 g_object_class_install_properties (object_class, PROP_LAST, properties);
153 * cheese_avatar_chooser_new:
155 * Creates a new #CheeseAvatarChooser dialogue.
157 * Returns: a #CheeseAvatarChooser
159 GtkWidget *
160 cheese_avatar_chooser_new (void)
162 return g_object_new (CHEESE_TYPE_AVATAR_CHOOSER, NULL);
166 * cheese_avatar_chooser_get_picture:
167 * @chooser: a #CheeseAvatarChooser dialogue
169 * Returns the portion of image selected through the builtin cropping tool,
170 * after a picture has been captured on the webcam.
172 * Return value: a #GdkPixbuf object, or %NULL if no picture has been taken yet
174 GdkPixbuf *
175 cheese_avatar_chooser_get_picture (CheeseAvatarChooser *chooser)
177 g_return_val_if_fail (CHEESE_IS_AVATAR_CHOOSER (chooser), NULL);
179 return cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (chooser->priv->widget));