aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--libempathy-gtk/empathy-contact-dialogs.c39
-rw-r--r--libempathy-gtk/empathy-contact-widget.c146
-rw-r--r--libempathy-gtk/empathy-contact-widget.h1
-rw-r--r--libempathy/empathy-tp-contact-list.c45
-rw-r--r--libempathy/gossip-contact.c39
-rw-r--r--libempathy/gossip-contact.h4
7 files changed, 102 insertions, 185 deletions
diff --git a/ChangeLog b/ChangeLog
index c23cf83d7..9ec92383d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2007-06-08 Xavier Claessens <xclaesse@gmail.com>
+ * libempathy-gtk/empathy-contact-dialogs.c:
+ * libempathy-gtk/empathy-contact-widget.c:
+ * libempathy-gtk/empathy-contact-widget.h: Do not save when closing the
+ dialog. Update information in real-time and just provides a "Close"
+ button. That's more GNOME spirite.
+ * libempathy/empathy-tp-contact-list.c:
+ * libempathy/gossip-contact.h:
+ * libempathy/gossip-contact.c: New methods:
+ gossip_contact_add/remove_group(). This fixes leaks when a contact is
+ added/removed from a group.
+
+2007-06-08 Xavier Claessens <xclaesse@gmail.com>
+
* libempathy-gtk/gossip-chat.c: Fix build on 64bits arch.
Fixes bug #444680 (Matej Cepl).
diff --git a/libempathy-gtk/empathy-contact-dialogs.c b/libempathy-gtk/empathy-contact-dialogs.c
index e38eb84d1..ff2f87134 100644
--- a/libempathy-gtk/empathy-contact-dialogs.c
+++ b/libempathy-gtk/empathy-contact-dialogs.c
@@ -53,7 +53,6 @@ subscription_dialog_response_cb (GtkDialog *dialog,
manager = empathy_contact_manager_new ();
contact = empathy_contact_widget_get_contact (contact_widget);
- empathy_contact_widget_save (contact_widget);
if (response == GTK_RESPONSE_YES) {
empathy_contact_list_add (EMPATHY_CONTACT_LIST (manager),
@@ -131,11 +130,6 @@ contact_information_response_cb (GtkDialog *dialog,
GossipContact *contact;
contact = empathy_contact_widget_get_contact (contact_widget);
-
- if (response == GTK_RESPONSE_OK) {
- empathy_contact_widget_save (contact_widget);
- }
-
g_hash_table_remove (information_dialogs, contact);
}
@@ -163,35 +157,20 @@ empathy_contact_information_dialog_show (GossipContact *contact,
return;
}
+ /* Create dialog */
dialog = gtk_dialog_new ();
gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
- if (edit) {
- /* Cancel button */
- button = gtk_button_new_with_label (GTK_STOCK_CANCEL);
- gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
- button,
- GTK_RESPONSE_CANCEL);
- gtk_widget_show (button);
-
- button = gtk_button_new_with_label (GTK_STOCK_SAVE);
- gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
- button,
- GTK_RESPONSE_OK);
- gtk_widget_show (button);
- } else {
- /* Close button */
- button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
- gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
- gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
- button,
- GTK_RESPONSE_CLOSE);
- gtk_widget_show (button);
- }
+ /* Close button */
+ button = gtk_button_new_with_label (GTK_STOCK_CLOSE);
+ gtk_button_set_use_stock (GTK_BUTTON (button), TRUE);
+ gtk_dialog_add_action_widget (GTK_DIALOG (dialog),
+ button,
+ GTK_RESPONSE_CLOSE);
+ gtk_widget_show (button);
+ /* Contact infor widget */
contact_widget = empathy_contact_widget_new (contact, edit);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox),
contact_widget,
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index b8ed7efb0..58c800f6a 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -38,7 +38,6 @@ typedef struct {
GossipContact *contact;
gboolean is_user;
gboolean editable;
- gboolean changes_made;
GtkCellRenderer *renderer;
GtkWidget *vbox_contact_widget;
@@ -74,11 +73,6 @@ typedef struct {
GtkTreeIter found_iter;
} FindName;
-typedef struct {
- EmpathyContactWidget *information;
- GList *list;
-} FindSelected;
-
static void contact_widget_destroy_cb (GtkWidget *widget,
EmpathyContactWidget *information);
static void contact_widget_contact_setup (EmpathyContactWidget *information);
@@ -97,15 +91,11 @@ static gboolean contact_widget_model_find_name_foreach (GtkTreeModel
GtkTreePath *path,
GtkTreeIter *iter,
FindName *data);
-static GList * contact_widget_model_find_selected (EmpathyContactWidget *information);
-static gboolean contact_widget_model_find_selected_foreach (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- FindSelected *data);
static void contact_widget_cell_toggled (GtkCellRendererToggle *cell,
gchar *path_string,
EmpathyContactWidget *information);
-static void contact_widget_entry_alias_changed_cb (GtkEditable *editable,
+static void contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
+ GdkEventFocus *event,
EmpathyContactWidget *information);
static void contact_widget_entry_group_changed_cb (GtkEditable *editable,
EmpathyContactWidget *information);
@@ -185,32 +175,6 @@ empathy_contact_widget_new (GossipContact *contact,
return information->vbox_contact_widget;
}
-void
-empathy_contact_widget_save (GtkWidget *widget)
-{
- EmpathyContactWidget *information;
- const gchar *name;
- GList *groups;
-
- g_return_if_fail (GTK_IS_WIDGET (widget));
-
- information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
- if (!information ||
- !information->editable ||
- !information->changes_made) {
- return;
- }
-
- name = gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
- groups = contact_widget_model_find_selected (information);
-
- gossip_contact_set_name (information->contact, name);
- gossip_contact_set_groups (information->contact, groups);
-
- g_list_foreach (groups, (GFunc) g_free, NULL);
- g_list_free (groups);
-}
-
GossipContact *
empathy_contact_widget_get_contact (GtkWidget *widget)
{
@@ -270,8 +234,8 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
/* Setup alias entry or label */
if (information->editable) {
information->widget_alias = gtk_entry_new ();
- g_signal_connect (information->widget_alias, "changed",
- G_CALLBACK (contact_widget_entry_alias_changed_cb),
+ g_signal_connect (information->widget_alias, "focus-out-event",
+ G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
information);
} else {
information->widget_alias = gtk_label_new (NULL);
@@ -430,8 +394,7 @@ contact_widget_groups_populate_data (EmpathyContactWidget *information)
GtkTreeView *view;
GtkListStore *store;
GtkTreeIter iter;
- GList *groups, *l;
- GList *my_groups = NULL;
+ GList *my_groups, *l;
GList *all_groups;
view = GTK_TREE_VIEW (information->treeview_groups);
@@ -439,28 +402,14 @@ contact_widget_groups_populate_data (EmpathyContactWidget *information)
manager = empathy_contact_manager_new ();
all_groups = empathy_contact_manager_get_groups (manager);
- groups = gossip_contact_get_groups (information->contact);
+ my_groups = gossip_contact_get_groups (information->contact);
g_object_unref (manager);
- for (l = groups; l; l = l->next) {
- const gchar *group_str;
-
- group_str = l->data;
- if (strcmp (group_str, _("Unsorted")) == 0) {
- continue;
- }
-
- my_groups = g_list_append (my_groups, g_strdup (group_str));
- }
-
for (l = all_groups; l; l = l->next) {
const gchar *group_str;
gboolean enabled;
group_str = l->data;
- if (strcmp (group_str, _("Unsorted")) == 0) {
- continue;
- }
enabled = g_list_find_custom (my_groups,
group_str,
@@ -474,9 +423,6 @@ contact_widget_groups_populate_data (EmpathyContactWidget *information)
-1);
}
- g_list_foreach (my_groups, (GFunc) g_free, NULL);
- g_list_free (my_groups);
-
g_list_free (all_groups);
}
@@ -548,54 +494,6 @@ contact_widget_model_find_name_foreach (GtkTreeModel *model,
return FALSE;
}
-static GList *
-contact_widget_model_find_selected (EmpathyContactWidget *information)
-{
- GtkTreeView *view;
- GtkTreeModel *model;
- FindSelected data;
-
- data.information = information;
- data.list = NULL;
-
- view = GTK_TREE_VIEW (information->treeview_groups);
- model = gtk_tree_view_get_model (view);
-
- gtk_tree_model_foreach (model,
- (GtkTreeModelForeachFunc) contact_widget_model_find_selected_foreach,
- &data);
-
- return data.list;
-}
-
-static gboolean
-contact_widget_model_find_selected_foreach (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- FindSelected *data)
-{
- gchar *name;
- gboolean selected;
-
- gtk_tree_model_get (model, iter,
- COL_NAME, &name,
- COL_ENABLED, &selected,
- -1);
-
- if (!name) {
- return FALSE;
- }
-
- if (selected) {
- data->list = g_list_append (data->list, name);
- return FALSE;
- }
-
- g_free (name);
-
- return FALSE;
-}
-
static void
contact_widget_cell_toggled (GtkCellRendererToggle *cell,
gchar *path_string,
@@ -607,6 +505,7 @@ contact_widget_cell_toggled (GtkCellRendererToggle *cell,
GtkTreePath *path;
GtkTreeIter iter;
gboolean enabled;
+ gchar *group;
view = GTK_TREE_VIEW (information->treeview_groups);
model = gtk_tree_view_get_model (view);
@@ -615,21 +514,34 @@ contact_widget_cell_toggled (GtkCellRendererToggle *cell,
path = gtk_tree_path_new_from_string (path_string);
gtk_tree_model_get_iter (model, &iter, path);
- gtk_tree_model_get (model, &iter, COL_ENABLED, &enabled, -1);
-
- enabled ^= 1;
+ gtk_tree_model_get (model, &iter,
+ COL_ENABLED, &enabled,
+ COL_NAME, &group,
+ -1);
- gtk_list_store_set (store, &iter, COL_ENABLED, enabled, -1);
+ gtk_list_store_set (store, &iter, COL_ENABLED, !enabled, -1);
gtk_tree_path_free (path);
- information->changes_made = TRUE;
+ if (group) {
+ if (enabled) {
+ gossip_contact_remove_group (information->contact, group);
+ } else {
+ gossip_contact_add_group (information->contact, group);
+ }
+
+ g_free (group);
+ }
}
static void
-contact_widget_entry_alias_changed_cb (GtkEditable *editable,
- EmpathyContactWidget *information)
+contact_widget_entry_alias_focus_event_cb (GtkEditable *editable,
+ GdkEventFocus *event,
+ EmpathyContactWidget *information)
{
- information->changes_made = TRUE;
+ const gchar *name;
+
+ name = gtk_entry_get_text (GTK_ENTRY (editable));
+ gossip_contact_set_name (information->contact, name);
}
static void
@@ -677,7 +589,7 @@ contact_widget_button_group_clicked_cb (GtkButton *button,
COL_ENABLED, TRUE,
-1);
- information->changes_made = TRUE;
+ gossip_contact_add_group (information->contact, group);
}
static void
diff --git a/libempathy-gtk/empathy-contact-widget.h b/libempathy-gtk/empathy-contact-widget.h
index 4b7102e8f..3d33c4055 100644
--- a/libempathy-gtk/empathy-contact-widget.h
+++ b/libempathy-gtk/empathy-contact-widget.h
@@ -31,7 +31,6 @@ G_BEGIN_DECLS
GtkWidget * empathy_contact_widget_new (GossipContact *contact,
gboolean editable);
-void empathy_contact_widget_save (GtkWidget *widget);
GossipContact *empathy_contact_widget_get_contact (GtkWidget *widget);
G_END_DECLS
diff --git a/libempathy/empathy-tp-contact-list.c b/libempathy/empathy-tp-contact-list.c
index 3be79533a..97948a4f2 100644
--- a/libempathy/empathy-tp-contact-list.c
+++ b/libempathy/empathy-tp-contact-list.c
@@ -1470,24 +1470,12 @@ tp_contact_list_group_members_added_cb (GossipTelepathyGroup *group,
for (l = added_list; l; l = l->next) {
GossipContact *contact;
- GList *contact_groups;
contact = GOSSIP_CONTACT (l->data);
- contact_groups = gossip_contact_get_groups (contact);
-
- /* FIXME: this leaks */
- if (!g_list_find_custom (contact_groups,
- group_name,
- (GCompareFunc) strcmp)) {
- gossip_debug (DEBUG_DOMAIN, "Contact %s added to group '%s'",
- gossip_contact_get_name (contact),
- group_name);
- contact_groups = g_list_append (contact_groups,
- g_strdup (group_name));
- tp_contact_list_block_contact (list, contact);
- gossip_contact_set_groups (contact, contact_groups);
- tp_contact_list_unblock_contact (list, contact);
- }
+
+ tp_contact_list_block_contact (list, contact);
+ gossip_contact_add_group (contact, group_name);
+ tp_contact_list_unblock_contact (list, contact);
g_object_unref (contact);
}
@@ -1514,29 +1502,12 @@ tp_contact_list_group_members_removed_cb (GossipTelepathyGroup *group,
for (l = removed_list; l; l = l->next) {
GossipContact *contact;
- GList *contact_groups;
- GList *to_remove;
- /* FIXME: Does it leak ? */
- contact = GOSSIP_CONTACT (l->data);
- contact_groups = gossip_contact_get_groups (contact);
- contact_groups = g_list_copy (contact_groups);
-
- to_remove = g_list_find_custom (contact_groups,
- group_name,
- (GCompareFunc) strcmp);
- if (to_remove) {
- gossip_debug (DEBUG_DOMAIN, "Contact %d removed from group '%s'",
- gossip_contact_get_handle (contact),
- group_name);
- contact_groups = g_list_remove_link (contact_groups,
- to_remove);
- tp_contact_list_block_contact (list, contact);
- gossip_contact_set_groups (contact, contact_groups);
- tp_contact_list_unblock_contact (list, contact);
- }
+ contact = l->data;
- g_list_free (contact_groups);
+ tp_contact_list_block_contact (list, contact);
+ gossip_contact_remove_group (contact, group_name);
+ tp_contact_list_unblock_contact (list, contact);
g_object_unref (contact);
}
diff --git a/libempathy/gossip-contact.c b/libempathy/gossip-contact.c
index 267d86646..86b6ee6e0 100644
--- a/libempathy/gossip-contact.c
+++ b/libempathy/gossip-contact.c
@@ -592,6 +592,8 @@ gossip_contact_set_handle (GossipContact *contact,
{
GossipContactPriv *priv;
+ g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+
priv = GET_PRIV (contact);
priv->handle = handle;
@@ -599,6 +601,43 @@ gossip_contact_set_handle (GossipContact *contact,
g_object_notify (G_OBJECT (contact), "handle");
}
+void
+gossip_contact_add_group (GossipContact *contact,
+ const gchar *group)
+{
+ GossipContactPriv *priv;
+
+ g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+ g_return_if_fail (group != NULL);
+
+ priv = GET_PRIV (contact);
+
+ if (!g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp)) {
+ priv->groups = g_list_prepend (priv->groups, g_strdup (group));
+ g_object_notify (G_OBJECT (contact), "groups");
+ }
+}
+
+void
+gossip_contact_remove_group (GossipContact *contact,
+ const gchar *group)
+{
+ GossipContactPriv *priv;
+ GList *l;
+
+ g_return_if_fail (GOSSIP_IS_CONTACT (contact));
+ g_return_if_fail (group != NULL);
+
+ priv = GET_PRIV (contact);
+
+ l = g_list_find_custom (priv->groups, group, (GCompareFunc) strcmp);
+ if (l) {
+ g_free (l->data);
+ priv->groups = g_list_delete_link (priv->groups, l);
+ g_object_notify (G_OBJECT (contact), "groups");
+ }
+}
+
gboolean
gossip_contact_is_online (GossipContact *contact)
{
diff --git a/libempathy/gossip-contact.h b/libempathy/gossip-contact.h
index 3dc9bc76d..23da37538 100644
--- a/libempathy/gossip-contact.h
+++ b/libempathy/gossip-contact.h
@@ -85,6 +85,10 @@ void gossip_contact_set_subscription (GossipContact
GossipSubscription subscription);
void gossip_contact_set_handle (GossipContact *contact,
guint handle);
+void gossip_contact_add_group (GossipContact *contact,
+ const gchar *group);
+void gossip_contact_remove_group (GossipContact *contact,
+ const gchar *group);
gboolean gossip_contact_is_online (GossipContact *contact);
gboolean gossip_contact_is_in_group (GossipContact *contact,
const gchar *group);