]> git.0d.be Git - empathy.git/commitdiff
Display invite menu entry in the contact menu
authorXavier Claessens <xclaesse@src.gnome.org>
Mon, 13 Oct 2008 08:04:24 +0000 (08:04 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Mon, 13 Oct 2008 08:04:24 +0000 (08:04 +0000)
svn path=/trunk/; revision=1581

libempathy-gtk/empathy-contact-menu.c
libempathy-gtk/empathy-contact-menu.h

index 81c94a6dbabebb40f8ecc665b04ab725d42026e0..209664766a6cd66482a43a82f1e18fc18af3c7ff 100644 (file)
@@ -29,6 +29,7 @@
 #include <libempathy/empathy-log-manager.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-utils.h>
+#include <libempathy/empathy-chatroom-manager.h>
 
 #include "empathy-contact-menu.h"
 #include "empathy-images.h"
@@ -73,6 +74,11 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
+  /* Invite */
+  item = empathy_contact_invite_menu_item_new (contact);
+       gtk_menu_shell_append (shell, item);
+       gtk_widget_show (item);
+
        /* Separator */
        if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
                        EMPATHY_CONTACT_FEATURE_INFO)) {
@@ -234,3 +240,89 @@ empathy_contact_edit_menu_item_new (EmpathyContact *contact)
        return item;
 }
 
+static void
+contact_room_sub_menu_item_activate_cb (EmpathyContact *contact)
+{
+  /* TODO */
+}
+
+static GtkWidget *
+create_room_sub_menu_item (EmpathyContact *contact,
+                           EmpathyChatroom *chatroom)
+{
+       GtkWidget *item;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+       g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL);
+
+  item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
+
+       g_signal_connect_swapped (item, "activate",
+                                 G_CALLBACK (contact_room_sub_menu_item_activate_cb),
+                                 contact);
+       
+       return item;
+}
+
+GtkWidget *
+empathy_contact_invite_menu_item_new (EmpathyContact *contact)
+{
+       GtkWidget *item;
+       GtkWidget *image;
+  GtkWidget *room_item;
+  EmpathyChatroomManager *mgr;
+  GList *rooms, *l;
+  GtkWidget *submenu;
+  GtkMenuShell *submenu_shell;
+  gboolean have_rooms = FALSE;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+       item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to..."));
+       image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_GROUP_MESSAGE,
+                                             GTK_ICON_SIZE_MENU);
+       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+
+  mgr = empathy_chatroom_manager_new ();
+  rooms = empathy_chatroom_manager_get_chatrooms (mgr,
+      empathy_contact_get_account (contact));
+
+  /* create rooms sub menu */
+  submenu = gtk_menu_new ();
+  submenu_shell = GTK_MENU_SHELL (submenu);
+
+  for (l = rooms; l != NULL; l = g_list_next (l))
+    {
+      EmpathyChatroom *room = l->data;
+      TpChannel *channel;
+
+      g_object_get (room, "tp-channel", &channel, NULL);
+      if (channel != NULL)
+        {
+          have_rooms = TRUE;
+
+          room_item = create_room_sub_menu_item (contact, room);
+          gtk_menu_shell_append (submenu_shell, room_item);
+          gtk_widget_show (room_item);
+
+          g_object_unref (channel);
+        }
+    }
+
+  if (have_rooms)
+    {
+      gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+    }
+  else
+    {
+      gtk_widget_set_sensitive (item, FALSE);
+      gtk_widget_destroy (submenu);
+    }
+
+       gtk_widget_show (image);
+
+  g_object_unref (mgr);
+  g_list_free (rooms);
+
+       return item;
+}
index dd8d16147e2b3bdba1e5c3ea0d356e11f303a2ca..16324979c9d49f42769caa088382d63051b22218 100644 (file)
@@ -45,6 +45,7 @@ GtkWidget * empathy_contact_call_menu_item_new (EmpathyContact             *cont
 GtkWidget * empathy_contact_log_menu_item_new  (EmpathyContact             *contact);
 GtkWidget * empathy_contact_info_menu_item_new (EmpathyContact             *contact);
 GtkWidget * empathy_contact_edit_menu_item_new (EmpathyContact             *contact);
+GtkWidget * empathy_contact_invite_menu_item_new (EmpathyContact *contact);
 
 G_END_DECLS