From fac3f031d33d41237ec86e810ffad81cd63c6ec3 Mon Sep 17 00:00:00 2001 From: Davyd Madeley Date: Tue, 24 Feb 2009 14:34:26 +0900 Subject: [PATCH] Determine if the contact is not in the Contact List and add a menu item as appropriate --- libempathy-gtk/empathy-contact-menu.c | 43 +++++++++++++++++++++++++++ libempathy-gtk/empathy-contact-menu.h | 1 + 2 files changed, 44 insertions(+) diff --git a/libempathy-gtk/empathy-contact-menu.c b/libempathy-gtk/empathy-contact-menu.c index f6d1ca15..9969f3de 100644 --- a/libempathy-gtk/empathy-contact-menu.c +++ b/libempathy-gtk/empathy-contact-menu.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -56,6 +57,13 @@ empathy_contact_menu_new (EmpathyContact *contact, menu = gtk_menu_new (); shell = GTK_MENU_SHELL (menu); + /* Add Contact */ + item = empathy_contact_add_menu_item_new (contact); + if (item) { + gtk_menu_shell_append (shell, item); + gtk_widget_show (item); + } + /* Chat */ if (features & EMPATHY_CONTACT_FEATURE_CHAT) { item = empathy_contact_chat_menu_item_new (contact); @@ -124,6 +132,41 @@ empathy_contact_chat_menu_item_activated (GtkMenuItem *item, empathy_dispatcher_chat_with_contact (contact, NULL, NULL); } +GtkWidget * +empathy_contact_add_menu_item_new (EmpathyContact *contact) +{ + GtkWidget *item; + GtkWidget *image; + EmpathyContactManager *manager; + GList *l, *members; + gboolean found = FALSE; + + g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL); + + manager = empathy_contact_manager_dup_singleton (); + members = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (manager)); + for (l = members; l; l = l->next) { + if (!found && empathy_contact_equal (l->data, contact)) { + found = TRUE; + /* we keep iterating so that we don't leak contact + * refs */ + } + + g_object_unref (l->data); + } + g_list_free (members); + + if (found) return NULL; + + item = gtk_image_menu_item_new_with_mnemonic (_("_Add Contact...")); + image = gtk_image_new_from_icon_name (GTK_STOCK_ADD, + GTK_ICON_SIZE_MENU); + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); + + /* FIXME - callback */ + + return item; +} GtkWidget * empathy_contact_chat_menu_item_new (EmpathyContact *contact) diff --git a/libempathy-gtk/empathy-contact-menu.h b/libempathy-gtk/empathy-contact-menu.h index 262ec965..1c40d0e2 100644 --- a/libempathy-gtk/empathy-contact-menu.h +++ b/libempathy-gtk/empathy-contact-menu.h @@ -40,6 +40,7 @@ typedef enum { GtkWidget * empathy_contact_menu_new (EmpathyContact *contact, EmpathyContactFeatureFlags features); +GtkWidget * empathy_contact_add_menu_item_new (EmpathyContact *contact); GtkWidget * empathy_contact_chat_menu_item_new (EmpathyContact *contact); GtkWidget * empathy_contact_audio_call_menu_item_new (EmpathyContact *contact); GtkWidget * empathy_contact_video_call_menu_item_new (EmpathyContact *contact); -- 2.39.2