]> git.0d.be Git - empathy.git/commitdiff
More flexible API for EmpathyContactWidget, we now have flags to set
authorXavier Claessens <xclaesse@gmail.com>
Tue, 9 Oct 2007 18:07:57 +0000 (18:07 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Tue, 9 Oct 2007 18:07:57 +0000 (18:07 +0000)
2007-10-09  Xavier Claessens  <xclaesse@gmail.com>

* libempathy-gtk/empathy-main-window.c:
* libempathy-gtk/empathy-contact-dialogs.c:
* libempathy-gtk/empathy-contact-list-view.c:
* libempathy-gtk/empathy-contact-dialogs.h:
* libempathy-gtk/empathy-contact-widget.c:
* libempathy-gtk/empathy-contact-widget.h:
* libempathy-gtk/empathy-chat-window.c:
* megaphone/src/megaphone-applet.c: More flexible API for
EmpathyContactWidget, we now have flags to set editable each fields.
Implement personal information menu item in main window.

svn path=/trunk/; revision=365

ChangeLog
libempathy-gtk/empathy-chat-window.c
libempathy-gtk/empathy-contact-dialogs.c
libempathy-gtk/empathy-contact-dialogs.h
libempathy-gtk/empathy-contact-list-view.c
libempathy-gtk/empathy-contact-widget.c
libempathy-gtk/empathy-contact-widget.h
libempathy-gtk/empathy-main-window.c
megaphone/src/megaphone-applet.c

index 32c92b5ba19fdb37aa4b2fba17061f940b41642c..df710c326b43204f19a2d3b212645d3e5ae90c9f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2007-10-09  Xavier Claessens  <xclaesse@gmail.com>
+
+       * libempathy-gtk/empathy-main-window.c:
+       * libempathy-gtk/empathy-contact-dialogs.c:
+       * libempathy-gtk/empathy-contact-list-view.c:
+       * libempathy-gtk/empathy-contact-dialogs.h:
+       * libempathy-gtk/empathy-contact-widget.c:
+       * libempathy-gtk/empathy-contact-widget.h:
+       * libempathy-gtk/empathy-chat-window.c:
+       * megaphone/src/megaphone-applet.c: More flexible API for
+       EmpathyContactWidget, we now have flags to set editable each fields.
+       Implement personal information menu item in main window.
+
 2007-10-09  Xavier Claessens  <xclaesse@gmail.com>
 
        * libempathy-gtk/empathy-contact-widget.glade:
index 911fc51f3091686fe0915084eea829e61233ab8c..6535500de864d2bfc0142f40aefdad96fb08e55c 100644 (file)
@@ -914,7 +914,7 @@ chat_window_info_activate_cb (GtkWidget        *menuitem,
 
        empathy_contact_information_dialog_show (contact,
                                                 GTK_WINDOW (priv->dialog),
-                                                FALSE);
+                                                FALSE, FALSE);
 }
 
 static gboolean
index 553f85bcc4241ea7ca7f7d6e66504478a4943f1e..d032eab5a146a0eb21ed22dec9302afe29306e21 100644 (file)
@@ -110,7 +110,8 @@ empathy_subscription_dialog_show (EmpathyContact *contact,
                                      NULL);
 
        contact_widget = empathy_contact_widget_new (contact,
-                                                    CONTACT_WIDGET_TYPE_SUBSCRIPTION);
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
        gtk_box_pack_end (GTK_BOX (hbox_subscription),
                          contact_widget,
                          TRUE, TRUE,
@@ -146,13 +147,14 @@ contact_information_response_cb (GtkDialog *dialog,
 void
 empathy_contact_information_dialog_show (EmpathyContact *contact,
                                         GtkWindow      *parent,
-                                        gboolean        edit)
+                                        gboolean        edit,
+                                        gboolean        edit_groups)
 {
        GtkWidget                *dialog;
        GtkWidget                *button;
        GtkWidget                *contact_widget;
        GList                    *l;
-       EmpathyContactWidgetType  type;
+       EmpathyContactWidgetFlags flags = 0;
 
        g_return_if_fail (EMPATHY_IS_CONTACT (contact));
 
@@ -164,8 +166,6 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
                return;
        }
 
-       type = edit ? CONTACT_WIDGET_TYPE_EDIT : CONTACT_WIDGET_TYPE_SHOW;
-
        /* Create dialog */
        dialog = gtk_dialog_new ();
        gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
@@ -179,9 +179,19 @@ empathy_contact_information_dialog_show (EmpathyContact *contact,
                                      button,
                                      GTK_RESPONSE_CLOSE);
        gtk_widget_show (button);
-       
+
        /* Contact info widget */
-       contact_widget = empathy_contact_widget_new (contact, type);
+       if (edit) {
+               flags |= EMPATHY_CONTACT_WIDGET_EDIT_ALIAS;
+               if (empathy_contact_is_user (contact)) {
+                       flags |= EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
+                                EMPATHY_CONTACT_WIDGET_EDIT_AVATAR;
+               }
+       }
+       if (edit_groups) {
+               flags |= EMPATHY_CONTACT_WIDGET_EDIT_GROUPS;
+       }
+       contact_widget = empathy_contact_widget_new (contact, flags);
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                            contact_widget,
                            TRUE, TRUE, 0);
@@ -261,7 +271,11 @@ empathy_new_contact_dialog_show (GtkWindow *parent)
        gtk_widget_show (button);
 
        /* Contact info widget */
-       contact_widget = empathy_contact_widget_new (NULL, CONTACT_WIDGET_TYPE_ADD);
+       contact_widget = empathy_contact_widget_new (NULL,
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_ALIAS |
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT |
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_ID |
+                                                    EMPATHY_CONTACT_WIDGET_EDIT_GROUPS);
        gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
                            contact_widget,
                            TRUE, TRUE, 0);
index 560ae8f2b5327ebabd6fbf9ea4287501e45b5ce7..65ded4e7e3cfa338de900a70fc127367ddfc4697 100644 (file)
@@ -33,7 +33,8 @@ void empathy_subscription_dialog_show        (EmpathyContact *contact,
                                              GtkWindow     *parent);
 void empathy_contact_information_dialog_show (EmpathyContact *contact,
                                              GtkWindow     *parent,
-                                             gboolean       edit);
+                                             gboolean       edit,
+                                             gboolean       edit_groups);
 void empathy_new_contact_dialog_show         (GtkWindow     *parent);
 
 G_END_DECLS
index 70a2b0c0aaf033fee0d44227ddb52cf888725a8b..e3816dda7ba8a5159db5e410e0de02531935940b 100644 (file)
@@ -1402,10 +1402,10 @@ contact_list_view_action_cb (GtkAction             *action,
                contact_list_view_voip_activated (view, contact);
        }
        else if (contact && strcmp (name, "Information") == 0) {
-               empathy_contact_information_dialog_show (contact, parent, FALSE);
+               empathy_contact_information_dialog_show (contact, parent, FALSE, FALSE);
        }
        else if (contact && strcmp (name, "Edit") == 0) {
-               empathy_contact_information_dialog_show (contact, parent, TRUE);
+               empathy_contact_information_dialog_show (contact, parent, TRUE, TRUE);
        }
        else if (contact && strcmp (name, "Remove") == 0) {
                /* FIXME: Ask for confirmation */
index 2d26f4a4bc99e8201a6056f809d89b0dc90fb93c..afd434f3f31e0133ba2535904e33ac6ea1b385ff 100644 (file)
@@ -49,7 +49,7 @@ typedef struct {
        EmpathyContactFactory    *factory;
        EmpathyContactManager    *manager;
        EmpathyContact           *contact;
-       EmpathyContactWidgetType  type;
+       EmpathyContactWidgetFlags flags;
        GtkCellRenderer          *renderer;
        guint                     widget_id_timeout;
 
@@ -100,7 +100,7 @@ static void     contact_widget_set_contact                (EmpathyContactWidget
                                                           EmpathyContact         *contact);
 static void     contact_widget_contact_setup              (EmpathyContactWidget  *information);
 static void     contact_widget_contact_update             (EmpathyContactWidget  *information);
-static gboolean contact_widget_update_contact             (EmpathyContactWidget  *information);
+static void     contact_widget_change_contact             (EmpathyContactWidget  *information);
 static void     contact_widget_avatar_changed_cb          (EmpathyAvatarChooser  *chooser,
                                                           EmpathyContactWidget  *information);
 static void     contact_widget_account_changed_cb         (GtkComboBox           *widget,
@@ -150,16 +150,13 @@ enum {
 
 GtkWidget *
 empathy_contact_widget_new (EmpathyContact           *contact,
-                           EmpathyContactWidgetType  type)
+                           EmpathyContactWidgetFlags flags)
 {
        EmpathyContactWidget *information;
        GladeXML             *glade;
 
        information = g_slice_new0 (EmpathyContactWidget);
-       if (type == CONTACT_WIDGET_TYPE_EDIT && empathy_contact_is_user (contact)) {
-               type = CONTACT_WIDGET_TYPE_EDIT_USER;
-       }
-       information->type = type;
+       information->flags = flags;
        information->factory = empathy_contact_factory_new ();
 
        glade = empathy_glade_get_file ("empathy-contact-widget.glade",
@@ -319,7 +316,7 @@ contact_widget_can_add_contact_to_account (McAccount *account,
 static gboolean
 contact_widget_id_activate_timeout (EmpathyContactWidget *self)
 {
-       contact_widget_update_contact (self);
+       contact_widget_change_contact (self);
        return FALSE;
 }
 
@@ -340,7 +337,7 @@ contact_widget_id_changed_cb (GtkEntry             *entry,
 static void
 contact_widget_contact_setup (EmpathyContactWidget *information)
 {
-       if (information->type == CONTACT_WIDGET_TYPE_EDIT_USER) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR) {
                information->widget_avatar = empathy_avatar_chooser_new ();
                g_signal_connect (information->widget_avatar, "changed",
                                  G_CALLBACK (contact_widget_avatar_changed_cb),
@@ -355,7 +352,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
        gtk_widget_show (information->widget_avatar);
 
        /* Setup account label/chooser */
-       if (information->type == CONTACT_WIDGET_TYPE_ADD) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
                information->widget_account = empathy_account_chooser_new ();
                empathy_account_chooser_set_filter (
                        EMPATHY_ACCOUNT_CHOOSER (information->widget_account),
@@ -376,7 +373,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
        gtk_widget_show (information->widget_account);
 
        /* Setup id label/entry */
-       if (information->type == CONTACT_WIDGET_TYPE_ADD) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID) {
                information->widget_id = gtk_entry_new ();
                g_signal_connect (information->widget_id, "focus-out-event",
                                  G_CALLBACK (contact_widget_id_focus_out_cb),
@@ -395,7 +392,7 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
        gtk_widget_show (information->widget_id);
 
        /* Setup alias label/entry */
-       if (information->type > CONTACT_WIDGET_TYPE_SHOW) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS) {
                information->widget_alias = gtk_entry_new ();
                g_signal_connect (information->widget_alias, "focus-out-event",
                                  G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
@@ -434,7 +431,7 @@ contact_widget_contact_update (EmpathyContactWidget *information)
        }
 
        /* Update account widget */
-       if (information->type == CONTACT_WIDGET_TYPE_ADD) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT) {
                if (account) {
                        g_signal_handlers_block_by_func (information->widget_account,
                                                         contact_widget_account_changed_cb,
@@ -445,9 +442,6 @@ contact_widget_contact_update (EmpathyContactWidget *information)
                                                           contact_widget_account_changed_cb,
                                                           information);
                }
-               if (!G_STR_EMPTY (id)) {
-                       gtk_entry_set_text (GTK_ENTRY (information->widget_id), id);
-               }
        } else {
                if (account) {
                        const gchar *name;
@@ -455,9 +449,14 @@ contact_widget_contact_update (EmpathyContactWidget *information)
                        name = mc_account_get_display_name (account);
                        gtk_label_set_label (GTK_LABEL (information->widget_account), name);
                }
-               gtk_label_set_label (GTK_LABEL (information->widget_id), id);
        }
 
+       /* Update id widget */
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID) {
+               gtk_entry_set_text (GTK_ENTRY (information->widget_id), id ? id : "");
+       } else {
+               gtk_label_set_label (GTK_LABEL (information->widget_id), id ? id : "");
+       }
        /* Update other widgets */
        if (information->contact) {
                contact_widget_name_notify_cb (information);
@@ -476,28 +475,36 @@ contact_widget_contact_update (EmpathyContactWidget *information)
        }
 }
 
-static gboolean
-contact_widget_update_contact (EmpathyContactWidget *information)
+static void
+contact_widget_change_contact (EmpathyContactWidget *information)
 {
-       McAccount   *account;
-       const gchar *id;
+       EmpathyContact *contact;
+       McAccount      *account;
 
        account = empathy_account_chooser_get_account (EMPATHY_ACCOUNT_CHOOSER (information->widget_account));
-       id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
+       if (!account) {
+               return;
+       }
 
-       if (account && !G_STR_EMPTY (id)) {
-               EmpathyContact *contact;
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ID) {
+               const gchar *id;
+
+               id = gtk_entry_get_text (GTK_ENTRY (information->widget_id));
+               if (G_STR_EMPTY (id)) {
+                       return;
+               }
 
                contact = empathy_contact_factory_get_from_id (information->factory,
                                                               account, id);
-               contact_widget_set_contact (information, contact);
-
-               if (contact) {
-                       g_object_unref (contact);
-               }
+       } else {
+               contact = empathy_contact_factory_get_user (information->factory,
+                                                           account);
        }
 
-       return FALSE;
+       if (contact) {
+               contact_widget_set_contact (information, contact);
+               g_object_unref (contact);
+       }
 }
 
 static void
@@ -518,7 +525,7 @@ static void
 contact_widget_account_changed_cb (GtkComboBox          *widget,
                                   EmpathyContactWidget *information)
 {
-       contact_widget_update_contact (information);
+       contact_widget_change_contact (information);
 }
 
 static gboolean
@@ -526,7 +533,7 @@ contact_widget_id_focus_out_cb (GtkWidget            *widget,
                                GdkEventFocus        *event,
                                EmpathyContactWidget *information)
 {
-       contact_widget_update_contact (information);
+       contact_widget_change_contact (information);
        return FALSE;
 }
 
@@ -578,7 +585,7 @@ contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
        if (information->contact) {
                avatar = empathy_contact_get_avatar (information->contact);
        }
-       if (information->type == CONTACT_WIDGET_TYPE_EDIT_USER) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_AVATAR) {
                g_signal_handlers_block_by_func (information->widget_avatar,
                                                 contact_widget_avatar_changed_cb,
                                                 information);
@@ -596,7 +603,7 @@ contact_widget_avatar_notify_cb (EmpathyContactWidget *information)
 static void
 contact_widget_groups_setup (EmpathyContactWidget *information)
 {
-       if (information->type > CONTACT_WIDGET_TYPE_SHOW) {
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS) {
                information->manager = empathy_contact_manager_new ();
                contact_widget_model_setup (information);
        }
@@ -605,7 +612,7 @@ contact_widget_groups_setup (EmpathyContactWidget *information)
 static void
 contact_widget_groups_update (EmpathyContactWidget *information)
 {
-       if (information->type > CONTACT_WIDGET_TYPE_SHOW &&
+       if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS &&
            information->contact) {
                g_signal_connect_swapped (information->contact, "notify::groups",
                                          G_CALLBACK (contact_widget_groups_notify_cb),
index 71fc06acb742c8f876dadec53cc9193a3a219f12..3a2aed996dbdcdb7ae6cabee30a0ff3ae5e4c428 100644 (file)
 G_BEGIN_DECLS
 
 typedef enum {
-       CONTACT_WIDGET_TYPE_SHOW,         /* used to show contact information */
-       CONTACT_WIDGET_TYPE_EDIT,         /* used to edit contact information */
-       CONTACT_WIDGET_TYPE_ADD,          /* used to add a new contact */
-       CONTACT_WIDGET_TYPE_SUBSCRIPTION, /* used to accepte/reject a new contact */
-       CONTACT_WIDGET_TYPE_EDIT_USER     /* used to edit our own information */
-} EmpathyContactWidgetType;
+       EMPATHY_CONTACT_WIDGET_EDIT_ALIAS   = 1 << 0,
+       EMPATHY_CONTACT_WIDGET_EDIT_AVATAR  = 1 << 1,
+       EMPATHY_CONTACT_WIDGET_EDIT_ACCOUNT = 1 << 2,
+       EMPATHY_CONTACT_WIDGET_EDIT_ID      = 1 << 3,
+       EMPATHY_CONTACT_WIDGET_EDIT_GROUPS  = 1 << 4,
+} EmpathyContactWidgetFlags;
 
-GtkWidget *     empathy_contact_widget_new         (EmpathyContact           *contact,
-                                                   EmpathyContactWidgetType  type);
-EmpathyContact *empathy_contact_widget_get_contact (GtkWidget                *widget);
+GtkWidget *     empathy_contact_widget_new         (EmpathyContact            *contact,
+                                                   EmpathyContactWidgetFlags  flags);
+EmpathyContact *empathy_contact_widget_get_contact (GtkWidget                 *widget);
 
 G_END_DECLS
+
 #endif /*  __EMPATHY_CONTACT_WIDGET_H__ */
index 7867b949cab176ec0b0b320781b8cf5b78ecb9ab..7543c456e9e67374ad71225c8ff5ef0a1a9cd569 100644 (file)
@@ -35,6 +35,7 @@
 #include <libempathy/empathy-chatroom.h>
 #include <libempathy/empathy-contact-list.h>
 #include <libempathy/empathy-contact-manager.h>
+#include <libempathy/empathy-contact-factory.h>
 
 #include "empathy-main-window.h"
 #include "empathy-contact-dialogs.h"
@@ -67,7 +68,7 @@
 typedef struct {
        EmpathyContactListView  *list_view;
        EmpathyContactListStore *list_store;
-       MissionControl         *mc;
+       MissionControl          *mc;
        EmpathyChatroomManager  *chatroom_manager;
 
        /* Main widgets */
@@ -662,7 +663,24 @@ static void
 main_window_edit_personal_information_cb (GtkWidget         *widget,
                                          EmpathyMainWindow *window)
 {
-       //empathy_vcard_dialog_show (GTK_WINDOW (window->window));
+       GSList *accounts;
+
+       accounts = mission_control_get_online_connections (window->mc, NULL);
+       if (accounts) {
+               EmpathyContactFactory *factory;
+               EmpathyContact        *contact;
+               McAccount             *account;
+
+               account = accounts->data;
+               factory = empathy_contact_factory_new ();
+               contact = empathy_contact_factory_get_user (factory, account);
+               empathy_contact_information_dialog_show (contact,
+                                                        GTK_WINDOW (window->window),
+                                                        TRUE, FALSE);
+               g_slist_foreach (accounts, (GFunc) g_object_unref, NULL);
+               g_slist_free (accounts);
+               g_object_unref (factory);
+       }
 }
 
 static void
index c4e56da6e7cad3644d280491c10b35dcd2247b4e..993c68744ba31cdde5ee52e35408179bcf719c92 100644 (file)
@@ -395,7 +395,7 @@ megaphone_applet_information_cb (BonoboUIComponent *uic,
 
        /* FIXME: We should grey out the menu item if there are no available contact */
        if (priv->contact) {
-               empathy_contact_information_dialog_show (priv->contact, NULL, FALSE);
+               empathy_contact_information_dialog_show (priv->contact, NULL, FALSE, FALSE);
        }
 }