]> git.0d.be Git - empathy.git/commitdiff
Determine if the contact is not in the Contact List and add a menu item as appropriate
authorDavyd Madeley <davyd@madeley.id.au>
Tue, 24 Feb 2009 05:34:26 +0000 (14:34 +0900)
committerDavyd Madeley <davyd@madeley.id.au>
Wed, 15 Jul 2009 10:12:15 +0000 (11:12 +0100)
libempathy-gtk/empathy-contact-menu.c
libempathy-gtk/empathy-contact-menu.h

index f6d1ca154a33abbe60bebd8b85a98919c7ee30ae..9969f3def34137195c040da7f1b73a18472c1eb6 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <libempathy/empathy-call-factory.h>
 #include <libempathy/empathy-log-manager.h>
+#include <libempathy/empathy-contact-manager.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-chatroom-manager.h>
@@ -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)
index 262ec9650ac7a8314e0915d455a76e7ea638f9a9..1c40d0e28c0e05c7c34373b742e51f600f140179 100644 (file)
@@ -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);