Update Catalan translation
[cheese.git] / libcheese / cheese-avatar-chooser.c
blobaa64db6ef87aab01a59da39bf474e14060b46c14
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 "config.h"
22 #include <glib/gi18n-lib.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 PROP_0,
45 PROP_PIXBUF,
46 PROP_LAST
49 typedef struct
51 GtkWidget *widget;
52 } CheeseAvatarChooserPrivate;
54 static GParamSpec *properties[PROP_LAST];
56 G_DEFINE_TYPE_WITH_PRIVATE (CheeseAvatarChooser, cheese_avatar_chooser, GTK_TYPE_DIALOG)
58 static void
59 update_select_button (CheeseAvatarWidget *widget,
60 GParamSpec *pspec,
61 CheeseAvatarChooser *chooser)
63 GdkPixbuf *pixbuf;
65 g_object_get (G_OBJECT (widget), "pixbuf", &pixbuf, NULL);
66 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
67 GTK_RESPONSE_ACCEPT,
68 pixbuf != NULL);
69 if (pixbuf)
70 g_object_unref (pixbuf);
73 static void
74 cheese_avatar_chooser_init (CheeseAvatarChooser *chooser)
76 GtkWidget *button;
77 CheeseAvatarChooserPrivate *priv = cheese_avatar_chooser_get_instance_private (chooser);
79 gtk_dialog_add_buttons (GTK_DIALOG (chooser),
80 _("_Cancel"),
81 GTK_RESPONSE_CANCEL,
82 _("_Select"),
83 GTK_RESPONSE_ACCEPT,
84 NULL);
85 gtk_window_set_title (GTK_WINDOW (chooser), _("Take a Photo"));
87 button = gtk_dialog_get_widget_for_response (GTK_DIALOG (chooser),
88 GTK_RESPONSE_ACCEPT);
89 gtk_style_context_add_class (gtk_widget_get_style_context (button),
90 GTK_STYLE_CLASS_SUGGESTED_ACTION);
92 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser),
93 GTK_RESPONSE_ACCEPT,
94 FALSE);
96 priv->widget = cheese_avatar_widget_new ();
97 gtk_widget_show (priv->widget);
98 gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (chooser))),
99 priv->widget,
100 TRUE, TRUE, 0);
102 g_signal_connect (G_OBJECT (priv->widget), "notify::pixbuf",
103 G_CALLBACK (update_select_button), chooser);
107 static void
108 cheese_avatar_chooser_get_property (GObject *object, guint prop_id,
109 GValue *value, GParamSpec *pspec)
111 CheeseAvatarChooser *chooser;
112 CheeseAvatarChooserPrivate *priv;
114 chooser = CHEESE_AVATAR_CHOOSER (object);
115 priv = cheese_avatar_chooser_get_instance_private (chooser);
117 switch (prop_id)
119 case PROP_PIXBUF:
120 g_value_set_object (value, cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv->widget)));
121 break;
122 default:
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
124 break;
128 static void
129 cheese_avatar_chooser_class_init (CheeseAvatarChooserClass *klass)
131 GObjectClass *object_class = G_OBJECT_CLASS (klass);
133 object_class->get_property = cheese_avatar_chooser_get_property;
136 * CheeseAvatarChooser:pixbuf:
138 * A #GdkPixbuf object representing the cropped area of the picture, or %NULL.
140 properties[PROP_PIXBUF] = g_param_spec_object ("pixbuf",
141 "Pixbuf",
142 "A #GdkPixbuf object representing the cropped area of the picture, or %NULL.",
143 GDK_TYPE_PIXBUF,
144 G_PARAM_READABLE);
146 g_object_class_install_properties (object_class, PROP_LAST, properties);
149 static gboolean
150 dialogs_use_header (void)
152 GtkSettings *settings;
153 gboolean use_header;
155 settings = gtk_settings_get_default ();
157 g_object_get (G_OBJECT (settings),
158 "gtk-dialogs-use-header", &use_header,
159 NULL);
161 return use_header;
165 * cheese_avatar_chooser_new:
167 * Creates a new #CheeseAvatarChooser dialogue.
169 * Returns: a #CheeseAvatarChooser
171 GtkWidget *
172 cheese_avatar_chooser_new (void)
174 return g_object_new (CHEESE_TYPE_AVATAR_CHOOSER, "use-header-bar",
175 dialogs_use_header (), NULL);
179 * cheese_avatar_chooser_get_picture:
180 * @chooser: a #CheeseAvatarChooser dialogue
182 * Returns the portion of image selected through the builtin cropping tool,
183 * after a picture has been captured on the webcam.
185 * Return value: a #GdkPixbuf object, or %NULL if no picture has been taken yet
187 GdkPixbuf *
188 cheese_avatar_chooser_get_picture (CheeseAvatarChooser *chooser)
190 CheeseAvatarChooserPrivate *priv;
191 g_return_val_if_fail (CHEESE_IS_AVATAR_CHOOSER (chooser), NULL);
193 priv = cheese_avatar_chooser_get_instance_private (chooser);
195 return cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv->widget));