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/>.
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"
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.
52 } CheeseAvatarChooserPrivate
;
54 static GParamSpec
*properties
[PROP_LAST
];
56 G_DEFINE_TYPE_WITH_PRIVATE (CheeseAvatarChooser
, cheese_avatar_chooser
, GTK_TYPE_DIALOG
)
59 update_select_button (CheeseAvatarWidget
*widget
,
61 CheeseAvatarChooser
*chooser
)
65 g_object_get (G_OBJECT (widget
), "pixbuf", &pixbuf
, NULL
);
66 gtk_dialog_set_response_sensitive (GTK_DIALOG (chooser
),
70 g_object_unref (pixbuf
);
74 cheese_avatar_chooser_init (CheeseAvatarChooser
*chooser
)
77 CheeseAvatarChooserPrivate
*priv
= cheese_avatar_chooser_get_instance_private (chooser
);
79 gtk_dialog_add_buttons (GTK_DIALOG (chooser
),
85 gtk_window_set_title (GTK_WINDOW (chooser
), _("Take a Photo"));
87 button
= gtk_dialog_get_widget_for_response (GTK_DIALOG (chooser
),
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
),
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
))),
102 g_signal_connect (G_OBJECT (priv
->widget
), "notify::pixbuf",
103 G_CALLBACK (update_select_button
), chooser
);
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
);
120 g_value_set_object (value
, cheese_avatar_widget_get_picture (CHEESE_AVATAR_WIDGET (priv
->widget
)));
123 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, prop_id
, pspec
);
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",
142 "A #GdkPixbuf object representing the cropped area of the picture, or %NULL.",
146 g_object_class_install_properties (object_class
, PROP_LAST
, properties
);
150 dialogs_use_header (void)
152 GtkSettings
*settings
;
155 settings
= gtk_settings_get_default ();
157 g_object_get (G_OBJECT (settings
),
158 "gtk-dialogs-use-header", &use_header
,
165 * cheese_avatar_chooser_new:
167 * Creates a new #CheeseAvatarChooser dialogue.
169 * Returns: a #CheeseAvatarChooser
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
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
));