+static void
+empathy_contact_add_menu_item_activated (GtkMenuItem *item,
+ EmpathyContact *contact)
+{
+ GtkWidget *toplevel;
+
+ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (item));
+ if (!GTK_WIDGET_TOPLEVEL (toplevel) || !GTK_IS_WINDOW (toplevel)) {
+ toplevel = NULL;
+ }
+
+ empathy_new_contact_dialog_show_with_contact (GTK_WINDOW (toplevel),
+ contact);
+}
+
+GtkWidget *
+empathy_contact_add_menu_item_new (EmpathyContact *contact)
+{
+ GtkWidget *item;
+ GtkWidget *image;
+ EmpathyContactManager *manager;
+ TpConnection *connection;
+ GList *l, *members;
+ gboolean found = FALSE;
+ EmpathyContactListFlags flags;
+
+ g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+ if (!empathy_contact_manager_initialized ()) {
+ return NULL;
+ }
+
+ manager = empathy_contact_manager_dup_singleton ();
+ connection = empathy_contact_get_connection (contact);
+
+ flags = empathy_contact_manager_get_flags_for_connection (manager,
+ connection);
+
+ if (!(flags & EMPATHY_CONTACT_LIST_CAN_ADD)) {
+ return NULL;
+ }
+
+ 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);
+ g_object_unref (manager);
+
+ 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);
+
+ g_signal_connect (item, "activate",
+ G_CALLBACK (empathy_contact_add_menu_item_activated),
+ contact);
+
+ return item;
+}
+