1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2006-2007 Imendio AB.
4 * Copyright (C) 2007-2008 Collabora Ltd.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Authors: Based on Novell's e-image-chooser.
21 * Xavier Claessens <xclaesse@gmail.com>
28 #include <glib/gi18n.h>
32 #include <libempathy/empathy-utils.h>
33 #include "empathy-avatar-chooser.h"
34 #include "empathy-conf.h"
35 #include "empathy-ui-utils.h"
37 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
38 #include <libempathy/empathy-debug.h>
40 #define AVATAR_SIZE_SAVE 96
41 #define AVATAR_SIZE_VIEW 64
42 #define DEFAULT_DIR DATADIR"/pixmaps/faces"
44 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAvatarChooser)
46 EmpathyContactFactory *contact_factory;
48 EmpathyTpContactFactory *tp_contact_factory;
50 gulong ready_handler_id;
52 EmpathyAvatar *avatar;
53 } EmpathyAvatarChooserPriv;
55 static void avatar_chooser_finalize (GObject *object);
56 static void avatar_chooser_set_account (EmpathyAvatarChooser *self,
58 static void avatar_chooser_set_image (EmpathyAvatarChooser *chooser,
59 EmpathyAvatar *avatar,
61 gboolean set_locally);
62 static gboolean avatar_chooser_drag_motion_cb (GtkWidget *widget,
63 GdkDragContext *context,
67 EmpathyAvatarChooser *chooser);
68 static void avatar_chooser_drag_leave_cb (GtkWidget *widget,
69 GdkDragContext *context,
71 EmpathyAvatarChooser *chooser);
72 static gboolean avatar_chooser_drag_drop_cb (GtkWidget *widget,
73 GdkDragContext *context,
77 EmpathyAvatarChooser *chooser);
78 static void avatar_chooser_drag_data_received_cb (GtkWidget *widget,
79 GdkDragContext *context,
82 GtkSelectionData *selection_data,
85 EmpathyAvatarChooser *chooser);
86 static void avatar_chooser_clicked_cb (GtkWidget *button,
87 EmpathyAvatarChooser *chooser);
99 static guint signals [LAST_SIGNAL];
101 G_DEFINE_TYPE (EmpathyAvatarChooser, empathy_avatar_chooser, GTK_TYPE_BUTTON);
104 * Drag and drop stuff
106 #define URI_LIST_TYPE "text/uri-list"
109 DND_TARGET_TYPE_URI_LIST
112 static const GtkTargetEntry drop_types[] = {
113 { URI_LIST_TYPE, 0, DND_TARGET_TYPE_URI_LIST },
117 avatar_chooser_get_property (GObject *object,
122 EmpathyAvatarChooserPriv *priv = GET_PRIV (object);
126 g_value_set_object (value, priv->account);
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
135 avatar_chooser_set_property (GObject *object,
140 EmpathyAvatarChooser *self = EMPATHY_AVATAR_CHOOSER (object);
144 avatar_chooser_set_account (self, g_value_get_object (value));
147 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
153 empathy_avatar_chooser_class_init (EmpathyAvatarChooserClass *klass)
155 GObjectClass *object_class = G_OBJECT_CLASS (klass);
156 GParamSpec *param_spec;
158 object_class->finalize = avatar_chooser_finalize;
159 object_class->get_property = avatar_chooser_get_property;
160 object_class->set_property = avatar_chooser_set_property;
163 g_signal_new ("changed",
164 G_TYPE_FROM_CLASS (klass),
168 g_cclosure_marshal_VOID__VOID,
171 param_spec = g_param_spec_object ("account",
173 "McAccount whose avatar should be "
174 "shown and modified by this widget",
177 G_PARAM_STATIC_STRINGS);
178 g_object_class_install_property (object_class,
182 g_type_class_add_private (object_class, sizeof (EmpathyAvatarChooserPriv));
186 empathy_avatar_chooser_init (EmpathyAvatarChooser *chooser)
188 EmpathyAvatarChooserPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chooser,
189 EMPATHY_TYPE_AVATAR_CHOOSER, EmpathyAvatarChooserPriv);
191 chooser->priv = priv;
192 gtk_drag_dest_set (GTK_WIDGET (chooser),
193 GTK_DEST_DEFAULT_ALL,
195 G_N_ELEMENTS (drop_types),
198 g_signal_connect (chooser, "drag-motion",
199 G_CALLBACK (avatar_chooser_drag_motion_cb),
201 g_signal_connect (chooser, "drag-leave",
202 G_CALLBACK (avatar_chooser_drag_leave_cb),
204 g_signal_connect (chooser, "drag-drop",
205 G_CALLBACK (avatar_chooser_drag_drop_cb),
207 g_signal_connect (chooser, "drag-data-received",
208 G_CALLBACK (avatar_chooser_drag_data_received_cb),
210 g_signal_connect (chooser, "clicked",
211 G_CALLBACK (avatar_chooser_clicked_cb),
214 priv->contact_factory = empathy_contact_factory_new ();
216 empathy_avatar_chooser_set (chooser, NULL);
220 avatar_chooser_finalize (GObject *object)
222 EmpathyAvatarChooserPriv *priv;
224 priv = GET_PRIV (object);
226 avatar_chooser_set_account (EMPATHY_AVATAR_CHOOSER (object), NULL);
227 g_assert (priv->account == NULL);
228 g_assert (priv->tp_contact_factory == NULL);
230 g_object_unref (priv->contact_factory);
232 if (priv->avatar != NULL) {
233 empathy_avatar_unref (priv->avatar);
236 G_OBJECT_CLASS (empathy_avatar_chooser_parent_class)->finalize (object);
240 avatar_chooser_tp_cf_ready_cb (EmpathyTpContactFactory *tp_cf,
242 EmpathyAvatarChooser *self)
244 EmpathyAvatarChooserPriv *priv = GET_PRIV (self);
247 /* sanity check that we're listening on the right ETpCF */
248 g_assert (priv->tp_contact_factory == tp_cf);
250 ready = empathy_tp_contact_factory_is_ready (tp_cf);
251 gtk_widget_set_sensitive (GTK_WIDGET (self), ready);
255 avatar_chooser_set_account (EmpathyAvatarChooser *self,
258 EmpathyAvatarChooserPriv *priv = GET_PRIV (self);
260 if (priv->account != NULL) {
261 g_object_unref (priv->account);
262 priv->account = NULL;
264 g_assert (priv->tp_contact_factory != NULL);
266 g_signal_handler_disconnect (priv->tp_contact_factory,
267 priv->ready_handler_id);
268 priv->ready_handler_id = 0;
270 g_object_unref (priv->tp_contact_factory);
271 priv->tp_contact_factory = NULL;
274 if (account != NULL) {
275 priv->account = g_object_ref (account);
276 priv->tp_contact_factory = g_object_ref (
277 empathy_contact_factory_get_tp_factory (
278 priv->contact_factory, priv->account));
280 priv->ready_handler_id = g_signal_connect (
281 priv->tp_contact_factory, "notify::ready",
282 G_CALLBACK (avatar_chooser_tp_cf_ready_cb), self);
283 avatar_chooser_tp_cf_ready_cb (priv->tp_contact_factory, NULL,
289 str_in_strv (gchar *str,
296 while (*strv != NULL) {
297 if (g_str_equal (str, *strv)) {
305 /* The caller must free the strings stored in satisfactory_format_name and
306 * satisfactory_mime_type.
309 can_satisfy_mime_type_requirements (gchar **accepted_mime_types,
310 gchar **satisfactory_format_name,
311 gchar **satisfactory_mime_type)
315 gboolean done = FALSE;
317 if (accepted_mime_types == NULL || *accepted_mime_types == NULL) {
321 g_assert (satisfactory_format_name != NULL);
322 g_assert (satisfactory_mime_type != NULL);
324 /* Special-case png and jpeg to avoid accidentally saving to something
325 * uncompressed like bmp. This assumes that we can write image/png and
326 * image/jpeg; if this isn't true then something's really wrong with
329 if (str_in_strv ("image/png", accepted_mime_types)) {
330 name = g_strdup ("png");
331 type = g_strdup ("image/png");
333 } else if (str_in_strv ("image/jpeg", accepted_mime_types)) {
334 name = g_strdup ("jpeg");
335 type = g_strdup ("image/jpeg");
338 GSList *formats = gdk_pixbuf_get_formats ();
342 for (l = formats; !done && l != NULL; l = l->next) {
343 GdkPixbufFormat *format = l->data;
344 gchar **format_mime_types;
346 if (!gdk_pixbuf_format_is_writable (format)) {
350 format_mime_types = gdk_pixbuf_format_get_mime_types (format);
351 for (strv = format_mime_types; *strv != NULL; strv++) {
352 if (str_in_strv (*strv, accepted_mime_types)) {
353 name = gdk_pixbuf_format_get_name (format);
354 type = g_strdup (*strv);
359 g_strfreev (format_mime_types);
362 g_slist_free (formats);
366 *satisfactory_format_name = name;
367 *satisfactory_mime_type = type;
370 /* check we're not leaking. */
371 g_assert (name == NULL);
372 g_assert (type == NULL);
377 static EmpathyAvatar *
378 avatar_chooser_convert (EmpathyAvatarChooser *chooser,
379 GdkPixbuf *pixbuf_scaled,
383 gchar *format_name = NULL, *new_mime_type = NULL;
384 gchar *converted_image_data = NULL;
385 gsize converted_image_size = 0;
386 EmpathyAvatar *converted_avatar = NULL;
388 GError *error = NULL;
390 if (!can_satisfy_mime_type_requirements (mime_types, &format_name,
392 DEBUG ("Mon dieu! Can't convert to any acceptable format!");
396 saved = gdk_pixbuf_save_to_buffer (pixbuf_scaled, &converted_image_data,
397 &converted_image_size, format_name, &error, NULL);
398 g_free (format_name);
401 DEBUG ("Couldn't convert image: %s", error->message);
402 g_error_free (error);
404 g_free (new_mime_type);
408 /* Takes ownership of new_mime_type */
409 converted_avatar = empathy_avatar_new (converted_image_data,
410 converted_image_size, new_mime_type, NULL);
412 if (max_size > 0 && converted_avatar->len > max_size) {
413 /* FIXME: We could try converting to a different format; in
414 * particular, try converting to jpeg with increasingly
415 * high compression (if jpeg is supported). Not sure how
418 DEBUG ("Converted the image, but the new filesize is too big");
420 empathy_avatar_unref (converted_avatar);
421 converted_avatar = NULL;
424 return converted_avatar;
427 static EmpathyAvatar *
428 avatar_chooser_maybe_convert_and_scale (EmpathyAvatarChooser *chooser,
430 EmpathyAvatar *avatar)
432 EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);
433 EmpathyTpContactFactory *tp_cf = priv->tp_contact_factory;
434 gint max_width = 0, max_height = 0, max_size = 0;
435 gchar **mime_types = NULL;
436 gboolean needs_conversion = FALSE;
437 GdkPixbuf *pixbuf_scaled = NULL;
439 /* This should only be called if the user is setting a new avatar,
440 * which should only be allowed once the avatar requirements have been
443 g_return_val_if_fail (tp_cf != NULL, NULL);
444 g_return_val_if_fail (empathy_tp_contact_factory_is_ready (tp_cf),
448 "avatar-mime-types", &mime_types, /* Needs g_strfreev-ing */
449 "avatar-max-width", &max_width,
450 "avatar-max-height", &max_height,
451 "avatar-max-size", &max_size,
454 /* If the avatar's not already the right type, it needs converting. */
455 if (!str_in_strv (avatar->format, mime_types)) {
456 needs_conversion = TRUE;
459 /* If _scale_down_if_necessary yields a new pixbuf, then it needed
460 * scaling. If it's the same pixbuf, it did not, and did no extra work
461 * beyond checking the dimensions. Hence, we call it even if
462 * needs_conversion is already TRUE, rather than duplicating the
463 * dimension checking code here, as it's no more expensive than
464 * checking the dimensions first in the case where no scaling is
467 pixbuf_scaled = empathy_pixbuf_scale_down_if_necessary (pixbuf,
468 MIN(max_width, max_height));
469 if (pixbuf_scaled != pixbuf) {
470 needs_conversion = TRUE;
473 if (max_size > 0 && avatar->len > max_size) {
474 needs_conversion = TRUE;
477 if (needs_conversion) {
478 avatar = avatar_chooser_convert (chooser, pixbuf_scaled,
479 mime_types, max_size);
481 /* Just return another reference to the avatar passed in. */
482 avatar = empathy_avatar_ref (avatar);
485 g_object_unref (pixbuf_scaled);
486 g_strfreev (mime_types);
491 avatar_chooser_clear_image (EmpathyAvatarChooser *chooser)
493 EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);
496 if (priv->avatar == NULL) {
500 empathy_avatar_unref (priv->avatar);
503 image = gtk_image_new_from_icon_name ("stock_person", GTK_ICON_SIZE_DIALOG);
504 gtk_button_set_image (GTK_BUTTON (chooser), image);
505 g_signal_emit (chooser, signals[CHANGED], 0);
509 avatar_chooser_set_image_from_data (EmpathyAvatarChooser *chooser,
512 gboolean set_locally)
515 EmpathyAvatar *avatar = NULL;
516 gchar *mime_type = NULL;
519 avatar_chooser_clear_image (chooser);
524 pixbuf = empathy_pixbuf_from_data (data, size, &mime_type);
525 if (pixbuf == NULL) {
530 /* avatar takes ownership of data and mime_type */
531 avatar = empathy_avatar_new (data, size, mime_type, NULL);
533 avatar_chooser_set_image (chooser, avatar, pixbuf, set_locally);
537 avatar_chooser_set_image_from_avatar (EmpathyAvatarChooser *chooser,
538 EmpathyAvatar *avatar,
539 gboolean set_locally)
542 gchar *mime_type = NULL;
544 g_assert (avatar != NULL);
546 pixbuf = empathy_pixbuf_from_data (avatar->data, avatar->len, &mime_type);
547 if (pixbuf == NULL) {
548 DEBUG ("couldn't make a pixbuf from avatar; giving up");
552 if (avatar->format == NULL) {
553 avatar->format = mime_type;
555 if (strcmp (mime_type, avatar->format)) {
556 DEBUG ("avatar->format is %s; gdkpixbuf yields %s!",
557 avatar->format, mime_type);
562 empathy_avatar_ref (avatar);
564 avatar_chooser_set_image (chooser, avatar, pixbuf, set_locally);
568 avatar_chooser_set_image (EmpathyAvatarChooser *chooser,
569 EmpathyAvatar *avatar,
571 gboolean set_locally)
573 EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);
574 GdkPixbuf *pixbuf_view;
577 g_assert (avatar != NULL);
578 g_assert (pixbuf != NULL);
581 EmpathyAvatar *conv = avatar_chooser_maybe_convert_and_scale (
582 chooser, pixbuf, avatar);
583 empathy_avatar_unref (avatar);
586 /* An error occured; don't change the avatar. */
593 if (priv->avatar != NULL) {
594 empathy_avatar_unref (priv->avatar);
596 priv->avatar = avatar;
598 pixbuf_view = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_VIEW);
599 image = gtk_image_new_from_pixbuf (pixbuf_view);
601 gtk_button_set_image (GTK_BUTTON (chooser), image);
602 g_signal_emit (chooser, signals[CHANGED], 0);
604 g_object_unref (pixbuf_view);
605 g_object_unref (pixbuf);
609 avatar_chooser_set_image_from_file (EmpathyAvatarChooser *chooser,
610 const gchar *filename)
612 gchar *image_data = NULL;
613 gsize image_size = 0;
614 GError *error = NULL;
616 if (!g_file_get_contents (filename, &image_data, &image_size, &error)) {
617 DEBUG ("Failed to load image from '%s': %s", filename,
618 error ? error->message : "No error given");
620 g_clear_error (&error);
624 avatar_chooser_set_image_from_data (chooser, image_data, image_size, TRUE);
628 avatar_chooser_drag_motion_cb (GtkWidget *widget,
629 GdkDragContext *context,
633 EmpathyAvatarChooser *chooser)
635 EmpathyAvatarChooserPriv *priv;
638 priv = GET_PRIV (chooser);
640 for (p = context->targets; p != NULL; p = p->next) {
641 gchar *possible_type;
643 possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
645 if (!strcmp (possible_type, URI_LIST_TYPE)) {
646 g_free (possible_type);
647 gdk_drag_status (context, GDK_ACTION_COPY, time);
652 g_free (possible_type);
659 avatar_chooser_drag_leave_cb (GtkWidget *widget,
660 GdkDragContext *context,
662 EmpathyAvatarChooser *chooser)
667 avatar_chooser_drag_drop_cb (GtkWidget *widget,
668 GdkDragContext *context,
672 EmpathyAvatarChooser *chooser)
674 EmpathyAvatarChooserPriv *priv;
677 priv = GET_PRIV (chooser);
679 if (context->targets == NULL) {
683 for (p = context->targets; p != NULL; p = p->next) {
686 possible_type = gdk_atom_name (GDK_POINTER_TO_ATOM (p->data));
687 if (!strcmp (possible_type, URI_LIST_TYPE)) {
688 g_free (possible_type);
689 gtk_drag_get_data (widget, context,
690 GDK_POINTER_TO_ATOM (p->data),
696 g_free (possible_type);
703 avatar_chooser_drag_data_received_cb (GtkWidget *widget,
704 GdkDragContext *context,
707 GtkSelectionData *selection_data,
710 EmpathyAvatarChooser *chooser)
713 gboolean handled = FALSE;
715 target_type = gdk_atom_name (selection_data->target);
716 if (!strcmp (target_type, URI_LIST_TYPE)) {
718 GFileInputStream *input_stream;
722 nl = strstr (selection_data->data, "\r\n");
726 uri = g_strndup (selection_data->data,
727 nl - (gchar*) selection_data->data);
729 file = g_file_new_for_uri (uri);
732 file = g_file_new_for_uri (selection_data->data);
735 input_stream = g_file_read (file, NULL, NULL);
737 if (input_stream != NULL) {
740 info = g_file_query_info (file,
741 G_FILE_ATTRIBUTE_STANDARD_SIZE,
747 size = g_file_info_get_size (info);
748 data = g_malloc (size);
750 bytes_read = g_input_stream_read (G_INPUT_STREAM (input_stream),
753 if (bytes_read != -1) {
754 avatar_chooser_set_image_from_data (
762 g_object_unref (info);
765 g_object_unref (input_stream);
768 g_object_unref (file);
771 gtk_drag_finish (context, handled, FALSE, time);
775 avatar_chooser_update_preview_cb (GtkFileChooser *file_chooser,
776 EmpathyAvatarChooser *chooser)
780 filename = gtk_file_chooser_get_preview_filename (file_chooser);
784 GdkPixbuf *pixbuf = NULL;
785 GdkPixbuf *scaled_pixbuf;
787 pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
789 image = gtk_file_chooser_get_preview_widget (file_chooser);
792 scaled_pixbuf = empathy_pixbuf_scale_down_if_necessary (pixbuf, AVATAR_SIZE_SAVE);
793 gtk_image_set_from_pixbuf (GTK_IMAGE (image), scaled_pixbuf);
794 g_object_unref (scaled_pixbuf);
795 g_object_unref (pixbuf);
797 gtk_image_set_from_stock (GTK_IMAGE (image),
798 "gtk-dialog-question",
799 GTK_ICON_SIZE_DIALOG);
803 gtk_file_chooser_set_preview_widget_active (file_chooser, TRUE);
807 avatar_chooser_response_cb (GtkWidget *widget,
809 EmpathyAvatarChooser *chooser)
811 EmpathyAvatarChooserPriv *priv = GET_PRIV (chooser);
813 if (response == GTK_RESPONSE_CANCEL) {
817 /* Check if we went non-ready since displaying the dialog. */
818 if (!empathy_tp_contact_factory_is_ready (priv->tp_contact_factory)) {
819 DEBUG ("Can't set avatar when contact factory isn't ready.");
823 if (response == GTK_RESPONSE_OK) {
827 filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (widget));
828 avatar_chooser_set_image_from_file (chooser, filename);
831 path = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (widget));
833 empathy_conf_set_string (empathy_conf_get (),
834 EMPATHY_PREFS_UI_AVATAR_DIRECTORY,
839 else if (response == GTK_RESPONSE_NO) {
840 /* This corresponds to "No Image", not to "Cancel" */
841 avatar_chooser_clear_image (chooser);
845 gtk_widget_destroy (widget);
849 avatar_chooser_clicked_cb (GtkWidget *button,
850 EmpathyAvatarChooser *chooser)
852 GtkFileChooser *chooser_dialog;
854 gchar *saved_dir = NULL;
855 const gchar *default_dir = DEFAULT_DIR;
856 const gchar *pics_dir;
857 GtkFileFilter *filter;
859 chooser_dialog = GTK_FILE_CHOOSER (
860 gtk_file_chooser_dialog_new (_("Select Your Avatar Image"),
861 empathy_get_toplevel_window (GTK_WIDGET (chooser)),
862 GTK_FILE_CHOOSER_ACTION_OPEN,
871 /* Get special dirs */
872 empathy_conf_get_string (empathy_conf_get (),
873 EMPATHY_PREFS_UI_AVATAR_DIRECTORY,
875 if (saved_dir && !g_file_test (saved_dir, G_FILE_TEST_IS_DIR)) {
879 if (!g_file_test (default_dir, G_FILE_TEST_IS_DIR)) {
882 pics_dir = g_get_user_special_dir (G_USER_DIRECTORY_PICTURES);
883 if (pics_dir && !g_file_test (pics_dir, G_FILE_TEST_IS_DIR)) {
887 /* Set current dir to the last one or to DEFAULT_DIR or to home */
889 gtk_file_chooser_set_current_folder (chooser_dialog, saved_dir);
892 gtk_file_chooser_set_current_folder (chooser_dialog, pics_dir);
894 else if (default_dir) {
895 gtk_file_chooser_set_current_folder (chooser_dialog, default_dir);
897 gtk_file_chooser_set_current_folder (chooser_dialog, g_get_home_dir ());
900 /* Add shortcuts to special dirs */
902 gtk_file_chooser_add_shortcut_folder (chooser_dialog, saved_dir, NULL);
905 gtk_file_chooser_add_shortcut_folder (chooser_dialog, pics_dir, NULL);
908 gtk_file_chooser_add_shortcut_folder (chooser_dialog, default_dir, NULL);
911 /* Setup preview image */
912 image = gtk_image_new ();
913 gtk_file_chooser_set_preview_widget (chooser_dialog, image);
914 gtk_widget_set_size_request (image, AVATAR_SIZE_SAVE, AVATAR_SIZE_SAVE);
915 gtk_widget_show (image);
916 gtk_file_chooser_set_use_preview_label (chooser_dialog, FALSE);
917 g_signal_connect (chooser_dialog, "update-preview",
918 G_CALLBACK (avatar_chooser_update_preview_cb),
922 filter = gtk_file_filter_new ();
923 gtk_file_filter_set_name (filter, _("Images"));
924 gtk_file_filter_add_pixbuf_formats (filter);
925 gtk_file_chooser_add_filter (chooser_dialog, filter);
926 filter = gtk_file_filter_new ();
927 gtk_file_filter_set_name (filter, _("All Files"));
928 gtk_file_filter_add_pattern(filter, "*");
929 gtk_file_chooser_add_filter (chooser_dialog, filter);
932 gtk_dialog_set_default_response (GTK_DIALOG (chooser_dialog), GTK_RESPONSE_OK);
933 g_signal_connect (chooser_dialog, "response",
934 G_CALLBACK (avatar_chooser_response_cb),
937 gtk_widget_show (GTK_WIDGET (chooser_dialog));
942 empathy_avatar_chooser_new ()
944 return g_object_new (EMPATHY_TYPE_AVATAR_CHOOSER, NULL);
948 empathy_avatar_chooser_set (EmpathyAvatarChooser *chooser,
949 EmpathyAvatar *avatar)
951 g_return_if_fail (EMPATHY_IS_AVATAR_CHOOSER (chooser));
953 if (avatar != NULL) {
954 avatar_chooser_set_image_from_avatar (chooser, avatar, FALSE);
956 avatar_chooser_clear_image (chooser);
961 empathy_avatar_chooser_get_image_data (EmpathyAvatarChooser *chooser,
964 const gchar **mime_type)
966 EmpathyAvatarChooserPriv *priv;
968 g_return_if_fail (EMPATHY_IS_AVATAR_CHOOSER (chooser));
970 priv = GET_PRIV (chooser);
972 if (priv->avatar != NULL) {
974 *data = priv->avatar->data;
976 if (data_size != NULL) {
977 *data_size = priv->avatar->len;
979 if (mime_type != NULL) {
980 *mime_type = priv->avatar->format;
986 if (data_size != NULL) {
989 if (mime_type != NULL) {