]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-contact-widget.c
EmpathyContactWidget: remove all remaining flags
[empathy.git] / libempathy-gtk / empathy-contact-widget.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007-2009 Collabora Ltd.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library 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  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors: Xavier Claessens <xclaesse@gmail.com>
20  */
21
22 #include <config.h>
23
24 #include <string.h>
25 #include <stdlib.h>
26
27 #include <gtk/gtk.h>
28 #include <glib/gi18n-lib.h>
29
30 #include <telepathy-glib/account.h>
31 #include <telepathy-glib/util.h>
32 #include <telepathy-glib/interfaces.h>
33
34 #include <libempathy/empathy-time.h>
35 #include <libempathy/empathy-utils.h>
36 #include <libempathy/empathy-client-factory.h>
37
38 #include "empathy-calendar-button.h"
39 #include "empathy-contact-widget.h"
40 #include "empathy-contactinfo-utils.h"
41 #include "empathy-account-chooser.h"
42 #include "empathy-avatar-chooser.h"
43 #include "empathy-avatar-image.h"
44 #include "empathy-groups-widget.h"
45 #include "empathy-ui-utils.h"
46 #include "empathy-string-parser.h"
47
48 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
49 #include <libempathy/empathy-debug.h>
50
51 /**
52  * SECTION:empathy-contact-widget
53  * @title:EmpathyContactWidget
54  * @short_description: A widget used to display and edit details about a contact
55  * @include: libempathy-empathy-contact-widget.h
56  *
57  * #EmpathyContactWidget is a widget which displays appropriate widgets
58  * with details about a contact, also allowing changing these details,
59  * if desired.
60  */
61
62 /**
63  * EmpathyContactWidget:
64  * @parent: parent object
65  *
66  * Widget which displays appropriate widgets with details about a contact,
67  * also allowing changing these details, if desired.
68  */
69
70 G_DEFINE_TYPE (EmpathyContactWidget, empathy_contact_widget, GTK_TYPE_BOX)
71
72 /* Delay before updating the widget when the id entry changed (seconds) */
73 #define ID_CHANGED_TIMEOUT 1
74
75 #define DATA_FIELD "contact-info-field"
76
77 struct _EmpathyContactWidgetPriv
78 {
79   EmpathyContact *contact;
80   guint widget_id_timeout;
81   gulong fav_sig_id;
82
83   /* Contact */
84   GtkWidget *widget_avatar;
85   GtkWidget *widget_account;
86   GtkWidget *image_account;
87   GtkWidget *label_account;
88   GtkWidget *widget_id;
89   GtkWidget *widget_alias;
90   GtkWidget *label_alias;
91   GtkWidget *hbox_presence;
92   GtkWidget *image_state;
93   GtkWidget *label_status;
94   GtkWidget *grid_contact;
95   GtkWidget *vbox_avatar;
96   GtkWidget *favourite_checkbox;
97   GtkWidget *label_details;
98   GtkWidget *label_left_account;
99
100   /* Groups */
101   GtkWidget *groups_widget;
102
103   /* Client */
104   GtkWidget *vbox_client;
105   GtkWidget *grid_client;
106   GtkWidget *hbox_client_requested;
107 };
108
109 typedef struct
110 {
111   EmpathyContactWidget *self;
112   const gchar *name;
113   gboolean found;
114   GtkTreeIter found_iter;
115 } FindName;
116
117 enum
118 {
119   COL_NAME,
120   COL_ENABLED,
121   COL_EDITABLE,
122   COL_COUNT
123 };
124
125
126 static void
127 contact_widget_client_update (EmpathyContactWidget *self)
128 {
129   /* FIXME: Needs new telepathy spec */
130 }
131
132 static void
133 contact_widget_client_setup (EmpathyContactWidget *self)
134 {
135   /* FIXME: Needs new telepathy spec */
136   gtk_widget_hide (self->priv->vbox_client);
137 }
138
139 static void
140 contact_widget_groups_update (EmpathyContactWidget *self)
141 {
142   if (self->priv->contact != NULL)
143     {
144       FolksPersona *persona =
145           empathy_contact_get_persona (self->priv->contact);
146
147       if (FOLKS_IS_GROUP_DETAILS (persona))
148         {
149           empathy_groups_widget_set_group_details (
150               EMPATHY_GROUPS_WIDGET (self->priv->groups_widget),
151               FOLKS_GROUP_DETAILS (persona));
152           gtk_widget_show (self->priv->groups_widget);
153
154           return;
155         }
156     }
157
158   /* In case of failure */
159   gtk_widget_hide (self->priv->groups_widget);
160 }
161
162 static void
163 save_avatar_menu_activate_cb (GtkWidget *widget,
164     EmpathyContactWidget *self)
165 {
166   GtkWidget *dialog;
167   EmpathyAvatar *avatar;
168   gchar *ext = NULL, *filename;
169
170   dialog = gtk_file_chooser_dialog_new (_("Save Avatar"),
171       NULL,
172       GTK_FILE_CHOOSER_ACTION_SAVE,
173       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
174       GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
175       NULL);
176
177   gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog),
178       TRUE);
179
180   /* look for the avatar extension */
181   avatar = empathy_contact_get_avatar (self->priv->contact);
182   if (avatar->format != NULL)
183     {
184       gchar **splitted;
185
186       splitted = g_strsplit (avatar->format, "/", 2);
187       if (splitted[0] != NULL && splitted[1] != NULL)
188           ext = g_strdup (splitted[1]);
189
190       g_strfreev (splitted);
191     }
192   else
193     {
194       /* Avatar was loaded from the cache so was converted to PNG */
195       ext = g_strdup ("png");
196     }
197
198   if (ext != NULL)
199     {
200       gchar *id;
201
202       id = tp_escape_as_identifier (empathy_contact_get_id (
203             self->priv->contact));
204
205       filename = g_strdup_printf ("%s.%s", id, ext);
206       gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filename);
207
208       g_free (id);
209       g_free (ext);
210       g_free (filename);
211     }
212
213   if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
214     {
215       GError *error = NULL;
216
217       filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
218
219       if (!empathy_avatar_save_to_file (avatar, filename, &error))
220         {
221           /* Save error */
222           GtkWidget *error_dialog;
223
224           error_dialog = gtk_message_dialog_new (NULL, 0,
225               GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
226               _("Unable to save avatar"));
227
228           gtk_message_dialog_format_secondary_text (
229               GTK_MESSAGE_DIALOG (error_dialog), "%s", error->message);
230
231           g_signal_connect (error_dialog, "response",
232               G_CALLBACK (gtk_widget_destroy), NULL);
233
234           gtk_window_present (GTK_WINDOW (error_dialog));
235
236           g_clear_error (&error);
237         }
238
239       g_free (filename);
240     }
241
242   gtk_widget_destroy (dialog);
243 }
244
245 static void
246 popup_avatar_menu (EmpathyContactWidget *self,
247                    GtkWidget *parent,
248                    GdkEventButton *event)
249 {
250   GtkWidget *menu, *item;
251   gint button, event_time;
252
253   if (self->priv->contact == NULL ||
254       empathy_contact_get_avatar (self->priv->contact) == NULL)
255       return;
256
257   menu = empathy_context_menu_new (parent);
258
259   /* Add "Save as..." entry */
260   item = gtk_image_menu_item_new_from_stock (GTK_STOCK_SAVE_AS, NULL);
261   gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
262   gtk_widget_show (item);
263
264   g_signal_connect (item, "activate",
265       G_CALLBACK (save_avatar_menu_activate_cb), self);
266
267   if (event)
268     {
269       button = event->button;
270       event_time = event->time;
271     }
272   else
273     {
274       button = 0;
275       event_time = gtk_get_current_event_time ();
276     }
277
278   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
279       button, event_time);
280 }
281
282 static gboolean
283 widget_avatar_popup_menu_cb (GtkWidget *widget,
284                              EmpathyContactWidget *self)
285 {
286   popup_avatar_menu (self, widget, NULL);
287
288   return TRUE;
289 }
290
291 static gboolean
292 widget_avatar_button_press_event_cb (GtkWidget *widget,
293                                      GdkEventButton *event,
294                                      EmpathyContactWidget *self)
295 {
296   /* Ignore double-clicks and triple-clicks */
297   if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
298     {
299       popup_avatar_menu (self, widget, event);
300       return TRUE;
301     }
302
303   return FALSE;
304 }
305
306 static void
307 set_nickname_cb (GObject *source,
308     GAsyncResult *res,
309     gpointer user_data)
310 {
311   GError *error = NULL;
312
313   if (!tp_account_set_nickname_finish (TP_ACCOUNT (source), res, &error))
314     {
315       DEBUG ("Failed to set Account.Nickname: %s", error->message);
316       g_error_free (error);
317     }
318 }
319
320 static gboolean
321 contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
322     GdkEventFocus *event,
323     EmpathyContactWidget *self)
324 {
325   if (self->priv->contact)
326     {
327       const gchar *alias;
328
329       alias = gtk_entry_get_text (GTK_ENTRY (editable));
330
331       if (empathy_contact_is_user (self->priv->contact))
332         {
333           TpAccount * account;
334           const gchar *current_nickname;
335
336           account = empathy_contact_get_account (self->priv->contact);
337           current_nickname = tp_account_get_nickname (account);
338
339           if (tp_strdiff (current_nickname, alias))
340             {
341               DEBUG ("Set Account.Nickname to %s", alias);
342
343               tp_account_set_nickname_async (account, alias, set_nickname_cb,
344                   NULL);
345             }
346         }
347       else
348         {
349           empathy_contact_set_alias (self->priv->contact, alias);
350         }
351     }
352
353   return FALSE;
354 }
355
356 static void
357 contact_widget_name_notify_cb (EmpathyContactWidget *self)
358 {
359   if (GTK_IS_ENTRY (self->priv->widget_alias))
360       gtk_entry_set_text (GTK_ENTRY (self->priv->widget_alias),
361           empathy_contact_get_alias (self->priv->contact));
362   else
363       gtk_label_set_label (GTK_LABEL (self->priv->widget_alias),
364           empathy_contact_get_alias (self->priv->contact));
365 }
366
367 static void
368 contact_widget_presence_notify_cb (EmpathyContactWidget *self)
369 {
370   const gchar *status;
371   gchar *markup_text = NULL;
372
373   status = empathy_contact_get_status (self->priv->contact);
374   if (status != NULL)
375     markup_text = empathy_add_link_markup (status);
376   gtk_label_set_markup (GTK_LABEL (self->priv->label_status), markup_text);
377   g_free (markup_text);
378
379   gtk_image_set_from_icon_name (GTK_IMAGE (self->priv->image_state),
380       empathy_icon_name_for_contact (self->priv->contact),
381       GTK_ICON_SIZE_BUTTON);
382   gtk_widget_show (self->priv->image_state);
383 }
384
385 static void
386 contact_widget_remove_contact (EmpathyContactWidget *self)
387 {
388   if (self->priv->contact)
389     {
390       g_signal_handlers_disconnect_by_func (self->priv->contact,
391           contact_widget_name_notify_cb, self);
392       g_signal_handlers_disconnect_by_func (self->priv->contact,
393           contact_widget_presence_notify_cb, self);
394
395       g_object_unref (self->priv->contact);
396       self->priv->contact = NULL;
397     }
398 }
399
400 static void contact_widget_change_contact (EmpathyContactWidget *self);
401
402 static void
403 contact_widget_contact_update (EmpathyContactWidget *self)
404 {
405   TpAccount *account = NULL;
406   const gchar *id = NULL;
407
408   /* Connect and get info from new contact */
409   if (self->priv->contact)
410     {
411       g_signal_connect_swapped (self->priv->contact, "notify::name",
412           G_CALLBACK (contact_widget_name_notify_cb), self);
413       g_signal_connect_swapped (self->priv->contact, "notify::presence",
414           G_CALLBACK (contact_widget_presence_notify_cb), self);
415       g_signal_connect_swapped (self->priv->contact,
416           "notify::presence-message",
417           G_CALLBACK (contact_widget_presence_notify_cb), self);
418
419       account = empathy_contact_get_account (self->priv->contact);
420       id = empathy_contact_get_id (self->priv->contact);
421     }
422
423   /* Update account widget */
424   if (account)
425     {
426       g_signal_handlers_block_by_func (self->priv->widget_account,
427                contact_widget_change_contact,
428                self);
429       empathy_account_chooser_set_account (
430           EMPATHY_ACCOUNT_CHOOSER (self->priv->widget_account), account);
431       g_signal_handlers_unblock_by_func (self->priv->widget_account,
432           contact_widget_change_contact, self);
433     }
434
435   /* Update id widget */
436   gtk_entry_set_text (GTK_ENTRY (self->priv->widget_id), id ? id : "");
437
438   /* Update other widgets */
439   if (self->priv->contact)
440     {
441       contact_widget_name_notify_cb (self);
442       contact_widget_presence_notify_cb (self);
443
444       gtk_widget_show (self->priv->label_alias);
445       gtk_widget_show (self->priv->widget_alias);
446       gtk_widget_show (self->priv->widget_avatar);
447
448       gtk_widget_set_visible (self->priv->hbox_presence, TRUE);
449     }
450   else
451     {
452       gtk_widget_hide (self->priv->label_alias);
453       gtk_widget_hide (self->priv->widget_alias);
454       gtk_widget_hide (self->priv->hbox_presence);
455       gtk_widget_hide (self->priv->widget_avatar);
456     }
457 }
458
459 static void
460 contact_widget_set_contact (EmpathyContactWidget *self,
461                             EmpathyContact *contact)
462 {
463   if (contact == self->priv->contact)
464     return;
465
466   contact_widget_remove_contact (self);
467   if (contact)
468     self->priv->contact = g_object_ref (contact);
469
470   /* set the selected account to be the account this contact came from */
471   if (contact && EMPATHY_IS_ACCOUNT_CHOOSER (self->priv->widget_account)) {
472       empathy_account_chooser_set_account (
473                       EMPATHY_ACCOUNT_CHOOSER (self->priv->widget_account),
474                       empathy_contact_get_account (contact));
475   }
476
477   /* Update self for widgets */
478   contact_widget_contact_update (self);
479   contact_widget_groups_update (self);
480   contact_widget_client_update (self);
481 }
482
483 static void
484 contact_widget_got_contact_cb (GObject *source,
485     GAsyncResult *result,
486     gpointer user_data)
487 {
488   EmpathyContactWidget *self = user_data;
489   GError *error = NULL;
490   EmpathyContact *contact;
491
492   contact = empathy_client_factory_dup_contact_by_id_finish (
493       EMPATHY_CLIENT_FACTORY (source), result, &error);
494
495   if (contact == NULL)
496     {
497       DEBUG ("Error: %s", error->message);
498       g_error_free (error);
499       goto out;
500     }
501
502   contact_widget_set_contact (self, contact);
503
504   g_object_unref (contact);
505 out:
506   g_object_unref (self);
507 }
508
509 static void
510 contact_widget_change_contact (EmpathyContactWidget *self)
511 {
512   TpConnection *connection;
513   const gchar *id;
514
515   connection = empathy_account_chooser_get_connection (
516       EMPATHY_ACCOUNT_CHOOSER (self->priv->widget_account));
517   if (!connection)
518       return;
519
520   id = gtk_entry_get_text (GTK_ENTRY (self->priv->widget_id));
521   if (!EMP_STR_EMPTY (id))
522     {
523       EmpathyClientFactory *factory;
524
525       factory = empathy_client_factory_dup ();
526
527       empathy_client_factory_dup_contact_by_id_async (factory, connection,
528           id, contact_widget_got_contact_cb, g_object_ref (self));
529
530       g_object_unref (factory);
531     }
532 }
533
534 static gboolean
535 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
536 {
537   contact_widget_change_contact (self);
538   return FALSE;
539 }
540
541 static void
542 contact_widget_id_changed_cb (GtkEntry *entry,
543                               EmpathyContactWidget *self)
544 {
545   if (self->priv->widget_id_timeout != 0)
546     {
547       g_source_remove (self->priv->widget_id_timeout);
548     }
549
550   self->priv->widget_id_timeout =
551     g_timeout_add_seconds (ID_CHANGED_TIMEOUT,
552         (GSourceFunc) contact_widget_id_activate_timeout, self);
553 }
554
555 static gboolean
556 contact_widget_id_focus_out_cb (GtkWidget *widget,
557                                 GdkEventFocus *event,
558                                 EmpathyContactWidget *self)
559 {
560   contact_widget_change_contact (self);
561   return FALSE;
562 }
563
564 static void
565 contact_widget_contact_setup (EmpathyContactWidget *self)
566 {
567   self->priv->label_status = gtk_label_new ("");
568   gtk_label_set_line_wrap_mode (GTK_LABEL (self->priv->label_status),
569                                 PANGO_WRAP_WORD_CHAR);
570   gtk_label_set_line_wrap (GTK_LABEL (self->priv->label_status),
571                            TRUE);
572   gtk_misc_set_alignment (GTK_MISC (self->priv->label_status), 0, 0.5);
573
574   gtk_label_set_selectable (GTK_LABEL (self->priv->label_status), TRUE);
575
576   gtk_box_pack_start (GTK_BOX (self->priv->hbox_presence),
577         self->priv->label_status, TRUE, TRUE, 0);
578   gtk_widget_show (self->priv->label_status);
579
580   /* Setup account chooser */
581   self->priv->widget_account = empathy_account_chooser_new ();
582   g_signal_connect_swapped (self->priv->widget_account, "changed",
583         G_CALLBACK (contact_widget_change_contact),
584         self);
585   gtk_grid_attach (GTK_GRID (self->priv->grid_contact),
586       self->priv->widget_account,
587       2, 0, 1, 1);
588   gtk_widget_show (self->priv->widget_account);
589
590   /* Set up avatar display */
591   self->priv->widget_avatar = empathy_avatar_image_new ();
592
593   g_signal_connect (self->priv->widget_avatar, "popup-menu",
594       G_CALLBACK (widget_avatar_popup_menu_cb), self);
595   g_signal_connect (self->priv->widget_avatar, "button-press-event",
596       G_CALLBACK (widget_avatar_button_press_event_cb), self);
597   gtk_box_pack_start (GTK_BOX (self->priv->vbox_avatar),
598           self->priv->widget_avatar,
599           FALSE, FALSE,
600           6);
601   gtk_widget_show (self->priv->widget_avatar);
602
603   /* Setup id entry */
604   self->priv->widget_id = gtk_entry_new ();
605   g_signal_connect (self->priv->widget_id, "focus-out-event",
606         G_CALLBACK (contact_widget_id_focus_out_cb),
607         self);
608   g_signal_connect (self->priv->widget_id, "changed",
609         G_CALLBACK (contact_widget_id_changed_cb),
610         self);
611   gtk_grid_attach (GTK_GRID (self->priv->grid_contact), self->priv->widget_id,
612       2, 1, 1, 1);
613   gtk_widget_set_hexpand (self->priv->widget_id, TRUE);
614
615   gtk_widget_show (self->priv->widget_id);
616
617   /* Setup alias entry */
618   self->priv->widget_alias = gtk_entry_new ();
619
620   g_signal_connect (self->priv->widget_alias, "focus-out-event",
621         G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
622         self);
623
624   /* Make return activate the window default (the Close button) */
625   gtk_entry_set_activates_default (GTK_ENTRY (self->priv->widget_alias),
626       TRUE);
627
628   gtk_grid_attach (GTK_GRID (self->priv->grid_contact),
629       self->priv->widget_alias, 2, 2, 1, 1);
630   gtk_widget_set_hexpand (self->priv->widget_alias, TRUE);
631
632   gtk_label_set_selectable (GTK_LABEL (self->priv->label_status), FALSE);
633   gtk_widget_show (self->priv->widget_alias);
634 }
635
636 static void
637 empathy_contact_widget_finalize (GObject *object)
638 {
639   EmpathyContactWidget *self = EMPATHY_CONTACT_WIDGET (object);
640   void (*chain_up) (GObject *) =
641       ((GObjectClass *) empathy_contact_widget_parent_class)->finalize;
642
643   contact_widget_remove_contact (self);
644
645   if (self->priv->widget_id_timeout != 0)
646     {
647       g_source_remove (self->priv->widget_id_timeout);
648     }
649
650
651   if (chain_up != NULL)
652     chain_up (object);
653 }
654
655 /**
656  * empathy_contact_widget_new:
657  * @contact: an #EmpathyContact
658  *
659  * Creates a new #EmpathyContactWidget.
660  *
661  * Return value: a new #EmpathyContactWidget
662  */
663 GtkWidget *
664 empathy_contact_widget_new (EmpathyContact *contact)
665 {
666   EmpathyContactWidget *self;
667   gchar *filename;
668   GtkWidget *main_vbox;
669   GtkBuilder *gui;
670
671   g_return_val_if_fail (contact == NULL || EMPATHY_IS_CONTACT (contact), NULL);
672
673   self = g_object_new (EMPATHY_TYPE_CONTACT_WIDGET, NULL);
674
675   filename = empathy_file_lookup ("empathy-contact-widget.ui",
676       "libempathy-gtk");
677   gui = empathy_builder_get_file (filename,
678        "vbox_contact_widget", &main_vbox,
679        "hbox_presence", &self->priv->hbox_presence,
680        "label_alias", &self->priv->label_alias,
681        "image_state", &self->priv->image_state,
682        "grid_contact", &self->priv->grid_contact,
683        "vbox_avatar", &self->priv->vbox_avatar,
684        "groups_widget", &self->priv->groups_widget,
685        "vbox_client", &self->priv->vbox_client,
686        "grid_client", &self->priv->grid_client,
687        "hbox_client_requested", &self->priv->hbox_client_requested,
688        "label_details", &self->priv->label_details,
689        "label_left_account", &self->priv->label_left_account,
690        NULL);
691   g_free (filename);
692
693   gtk_container_add (GTK_CONTAINER (self), main_vbox);
694   gtk_widget_show (GTK_WIDGET (main_vbox));
695
696   /* Create widgets */
697   contact_widget_contact_setup (self);
698   contact_widget_client_setup (self);
699
700   gtk_widget_hide (self->priv->label_details);
701
702   if (contact != NULL)
703     contact_widget_set_contact (self, contact);
704   else
705     contact_widget_change_contact (self);
706
707   g_object_unref (gui);
708
709   return GTK_WIDGET (self);
710 }
711
712 /**
713  * empathy_contact_widget_get_contact:
714  * @widget: an #EmpathyContactWidget
715  *
716  * Get the #EmpathyContact related with the #EmpathyContactWidget @widget.
717  *
718  * Returns: the #EmpathyContact associated with @widget
719  */
720 EmpathyContact *
721 empathy_contact_widget_get_contact (GtkWidget *widget)
722 {
723   EmpathyContactWidget *self = EMPATHY_CONTACT_WIDGET (widget);
724
725   return self->priv->contact;
726 }
727
728 const gchar *
729 empathy_contact_widget_get_alias (GtkWidget *widget)
730 {
731   EmpathyContactWidget *self = EMPATHY_CONTACT_WIDGET (widget);
732
733   return gtk_entry_get_text (GTK_ENTRY (self->priv->widget_alias));
734 }
735
736 /**
737  * empathy_contact_widget_set_contact:
738  * @widget: an #EmpathyContactWidget
739  * @contact: a different #EmpathyContact
740  *
741  * Change the #EmpathyContact related with the #EmpathyContactWidget @widget.
742  */
743 void
744 empathy_contact_widget_set_contact (GtkWidget *widget,
745                                     EmpathyContact *contact)
746 {
747   EmpathyContactWidget *self = EMPATHY_CONTACT_WIDGET (widget);
748
749   g_return_if_fail (EMPATHY_IS_CONTACT (contact));
750
751   contact_widget_set_contact (self, contact);
752 }
753
754 /**
755  * empathy_contact_widget_set_account_filter:
756  * @widget: an #EmpathyContactWidget
757  * @filter: a #EmpathyAccountChooserFilterFunc
758  * @user_data: user data to pass to @filter, or %NULL
759  *
760  * Set a filter on the #EmpathyAccountChooser included in the
761  * #EmpathyContactWidget.
762  */
763 void
764 empathy_contact_widget_set_account_filter (
765     GtkWidget *widget,
766     EmpathyAccountChooserFilterFunc filter,
767     gpointer user_data)
768 {
769   EmpathyContactWidget *self = EMPATHY_CONTACT_WIDGET (widget);
770   EmpathyAccountChooser *chooser;
771
772   chooser = EMPATHY_ACCOUNT_CHOOSER (self->priv->widget_account);
773   if (chooser)
774       empathy_account_chooser_set_filter (chooser, filter, user_data);
775 }
776
777 static void
778 empathy_contact_widget_class_init (
779     EmpathyContactWidgetClass *klass)
780 {
781   GObjectClass *oclass = G_OBJECT_CLASS (klass);
782
783   oclass->finalize = empathy_contact_widget_finalize;
784
785   g_type_class_add_private (klass, sizeof (EmpathyContactWidgetPriv));
786 }
787
788 static void
789 empathy_contact_widget_init (EmpathyContactWidget *self)
790 {
791   self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
792       EMPATHY_TYPE_CONTACT_WIDGET, EmpathyContactWidgetPriv);
793 }