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"
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.
60 struct _CheeseAvatarChooserPrivate
65 static GParamSpec
*properties
[PROP_LAST
];
67 G_DEFINE_TYPE_WITH_PRIVATE (CheeseAvatarChooser
, cheese_avatar_chooser
, GTK_TYPE_DIALOG
);
70 update_select_button (CheeseAvatarWidget
*widget
,
72 CheeseAvatarChooser
*chooser
)
76 g_object_get (G_OBJECT (widget
), "pixbuf", &pixbuf
, NULL
);
77 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser
),
81 g_object_unref (pixbuf
);
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
),
95 gtk_window_set_title (GTK_WINDOW (chooser
), _("Take a Photo"));
97 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser
),
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
))),
109 g_signal_connect (G_OBJECT (priv
->widget
), "notify::pixbuf",
110 G_CALLBACK (update_select_button
), chooser
);
115 cheese_avatar_chooser_get_property (GObject
*object
, guint prop_id
,
116 GValue
*value
, GParamSpec
*pspec
)
118 CheeseAvatarChooserPrivate
*priv
= ((CheeseAvatarChooser
*) object
)->priv
;
123 g_value_set_object (value
, cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv
->widget
)));
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
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",
145 "A #GdkPixbuf object representing the cropped area of the picture, or %NULL.",
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
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
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
));