]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-menu.c
- Split info/edit/personal dialogs into different functions.
[empathy.git] / libempathy-gtk / empathy-contact-menu.c
index fb01052a15af460fa2bff0c93d6b9c6bc296d029..a3cf1da26f71aeedf5874d1e26c48d96f6cec19c 100644 (file)
 
 #include <string.h>
 
-#include <glib/gi18n.h>
+#include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
+#include <libempathy/empathy-call-factory.h>
 #include <libempathy/empathy-log-manager.h>
 #include <libempathy/empathy-dispatcher.h>
 #include <libempathy/empathy-utils.h>
@@ -75,8 +76,8 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
-  /* Invite */
-  item = empathy_contact_invite_menu_item_new (contact);
+       /* Invite */
+       item = empathy_contact_invite_menu_item_new (contact);
        gtk_menu_shell_append (shell, item);
        gtk_widget_show (item);
 
@@ -110,6 +111,14 @@ empathy_contact_menu_new (EmpathyContact             *contact,
        return menu;
 }
 
+static void
+empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
+       EmpathyContact *contact)
+{
+  empathy_dispatcher_chat_with_contact (contact, NULL, NULL);
+}
+
+
 GtkWidget *
 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
 {
@@ -124,13 +133,23 @@ empathy_contact_chat_menu_item_new (EmpathyContact *contact)
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_widget_show (image);
 
-       g_signal_connect_swapped (item, "activate",
-                                 G_CALLBACK (empathy_dispatcher_chat_with_contact),
+       g_signal_connect (item, "activate",
+                                 G_CALLBACK (empathy_contact_chat_menu_item_activated),
                                  contact);
        
        return item;
 }
 
+static void
+empathy_contact_call_menu_item_activated (GtkMenuItem *item,
+       EmpathyContact *contact)
+{
+       EmpathyCallFactory *factory;
+
+       factory = empathy_call_factory_get ();
+       empathy_call_factory_new_call (factory, contact);
+}
+
 GtkWidget *
 empathy_contact_call_menu_item_new (EmpathyContact *contact)
 {
@@ -139,15 +158,15 @@ empathy_contact_call_menu_item_new (EmpathyContact *contact)
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-       item = gtk_image_menu_item_new_with_mnemonic (_("_Call"));
+       item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Call"));
        image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VOIP,
                                              GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_widget_set_sensitive (item, empathy_contact_can_voip (contact));
        gtk_widget_show (image);
 
-       g_signal_connect_swapped (item, "activate",
-                                 G_CALLBACK (empathy_dispatcher_call_with_contact),
+       g_signal_connect (item, "activate",
+                                 G_CALLBACK (empathy_contact_call_menu_item_activated),
                                  contact);
        
        return item;
@@ -171,7 +190,7 @@ empathy_contact_log_menu_item_new (EmpathyContact *contact)
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-       manager = empathy_log_manager_new ();
+       manager = empathy_log_manager_dup_singleton ();
        have_log = empathy_log_manager_exists (manager,
                                               empathy_contact_get_account (contact),
                                               empathy_contact_get_id (contact),
@@ -192,13 +211,6 @@ empathy_contact_log_menu_item_new (EmpathyContact *contact)
        return item;
 }
 
-static void
-contact_file_transfer_menu_item_activate_cb (EmpathyContact *contact)
-{
-       g_return_if_fail (EMPATHY_IS_CONTACT (contact));
-       empathy_send_file_with_file_chooser (contact);
-}
-
 GtkWidget *
 empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
 {
@@ -215,7 +227,7 @@ empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
        gtk_widget_show (image);
 
        g_signal_connect_swapped (item, "activate",
-                                 G_CALLBACK (contact_file_transfer_menu_item_activate_cb),
+                                 G_CALLBACK (empathy_send_file_with_file_chooser),
                                  contact);
 
        return item;
@@ -224,7 +236,7 @@ empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
 static void
 contact_info_menu_item_activate_cb (EmpathyContact *contact)
 {
-       empathy_contact_information_dialog_show (contact, NULL, FALSE, FALSE);
+       empathy_contact_information_dialog_show (contact, NULL);
 }
 
 GtkWidget *
@@ -251,7 +263,7 @@ empathy_contact_info_menu_item_new (EmpathyContact *contact)
 static void
 contact_edit_menu_item_activate_cb (EmpathyContact *contact)
 {
-       empathy_contact_information_dialog_show (contact, NULL, TRUE, FALSE);
+       empathy_contact_edit_dialog_show (contact, NULL);
 }
 
 GtkWidget *
@@ -275,79 +287,67 @@ empathy_contact_edit_menu_item_new (EmpathyContact *contact)
        return item;
 }
 
-typedef struct 
-{
-  EmpathyContact *contact;
-  EmpathyChatroom *chatroom;
-} contact_room_sub_menu_item_activate_cb_ctx;
+typedef struct  {
+       EmpathyContact *contact;
+       EmpathyChatroom *chatroom;
+} RoomSubMenuData;
 
-static contact_room_sub_menu_item_activate_cb_ctx *
-contact_room_sub_menu_item_activate_cb_ctx_new (EmpathyContact *contact,
-                                                EmpathyChatroom *chatroom)
+static RoomSubMenuData *
+room_sub_menu_data_new (EmpathyContact *contact,
+                       EmpathyChatroom *chatroom)
 {
-  contact_room_sub_menu_item_activate_cb_ctx *ctx;
+       RoomSubMenuData *data;
 
-  ctx = g_slice_new (contact_room_sub_menu_item_activate_cb_ctx);
+       data = g_slice_new (RoomSubMenuData);
+       data->contact = g_object_ref (contact);
+       data->chatroom = g_object_ref (chatroom);
 
-  ctx->contact = g_object_ref (contact);
-  ctx->chatroom = g_object_ref (chatroom);
-
-  return ctx;
+       return data;
 }
 
 static void
-contact_room_sub_menu_item_activate_cb_ctx_free (
-    contact_room_sub_menu_item_activate_cb_ctx *ctx)
+room_sub_menu_data_free (RoomSubMenuData *data)
 {
-  /* FIXME: seems this is never called... */
-  g_object_unref (ctx->contact);
-  g_object_unref (ctx->chatroom);
-
-  g_slice_free (contact_room_sub_menu_item_activate_cb_ctx, ctx);
+       /* FIXME: seems this is never called... */
+       g_object_unref (data->contact);
+       g_object_unref (data->chatroom);
+       g_slice_free (RoomSubMenuData, data);
 }
 
 static void
-contact_room_sub_menu_item_activate_cb (
-    GtkWidget *item,
-    contact_room_sub_menu_item_activate_cb_ctx *ctx)
+room_sub_menu_activate_cb (GtkWidget *item,
+                          RoomSubMenuData *data)
 {
-  GArray *handles;
-  TpHandle handle;
-  TpChannel *channel;
-
-  g_object_get (ctx->chatroom, "tp-channel", &channel, NULL);
-  if (channel == NULL)
-    /* channel was invalidated. Ignoring */
-    return;
-
-  /* send invitation */
-  handles = g_array_new (FALSE, FALSE, sizeof (TpHandle));
-  handle = empathy_contact_get_handle (ctx->contact);
-  g_array_append_val (handles, handle);
-
-  tp_cli_channel_interface_group_call_add_members (channel, -1, handles,
-      _("Inviting to this room"), NULL, NULL, NULL, NULL);
+       TpHandle handle;
+       GArray handles = {(gchar *) &handle, 1};
+       EmpathyTpChat *chat;
+       TpChannel *channel;
+
+       chat = empathy_chatroom_get_tp_chat (data->chatroom);
+       if (chat == NULL) {
+               /* channel was invalidated. Ignoring */
+               return;
+       }
 
-  g_array_free (handles, TRUE);
-  g_object_unref (channel);
+       /* send invitation */
+       handle = empathy_contact_get_handle (data->contact);
+       channel = empathy_tp_chat_get_channel (chat);
+       tp_cli_channel_interface_group_call_add_members (channel, -1, &handles,
+               _("Inviting to this room"), NULL, NULL, NULL, NULL);
 }
 
 static GtkWidget *
-create_room_sub_menu_item (EmpathyContact *contact,
-                           EmpathyChatroom *chatroom)
+create_room_sub_menu (EmpathyContact *contact,
+                      EmpathyChatroom *chatroom)
 {
        GtkWidget *item;
-  contact_room_sub_menu_item_activate_cb_ctx *ctx;
-
-       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
-
-  item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
+       RoomSubMenuData *data;
 
-  ctx = contact_room_sub_menu_item_activate_cb_ctx_new (contact, chatroom);
-
-  g_signal_connect_data (item, "activate",
-      G_CALLBACK (contact_room_sub_menu_item_activate_cb), ctx,
-      (GClosureNotify) contact_room_sub_menu_item_activate_cb_ctx_free, 0);
+       item = gtk_menu_item_new_with_label (empathy_chatroom_get_name (chatroom));
+       data = room_sub_menu_data_new (contact, chatroom);
+       g_signal_connect_data (item, "activate",
+                              G_CALLBACK (room_sub_menu_activate_cb), data,
+                              (GClosureNotify) room_sub_menu_data_free, 0);
 
        return item;
 }
@@ -357,12 +357,10 @@ 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;
+       GtkWidget *room_item;
+       EmpathyChatroomManager *mgr;
+       GList *rooms, *l;
+       GtkWidget *submenu = NULL;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
@@ -371,46 +369,34 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
                                              GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
 
-  mgr = empathy_chatroom_manager_new (NULL);
-  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 *chatroom = l->data;
-      TpChannel *channel;
-
-      g_object_get (chatroom, "tp-channel", &channel, NULL);
-      if (channel != NULL)
-        {
-          have_rooms = TRUE;
-
-          room_item = create_room_sub_menu_item (contact, chatroom);
-          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);
-    }
+       mgr = empathy_chatroom_manager_dup_singleton (NULL);
+       rooms = empathy_chatroom_manager_get_chatrooms (mgr,
+               empathy_contact_get_account (contact));
+
+       for (l = rooms; l != NULL; l = g_list_next (l)) {
+               EmpathyChatroom *chatroom = l->data;
+
+               if (empathy_chatroom_get_tp_chat (chatroom) != NULL) {
+                       if (G_UNLIKELY (submenu == NULL))
+                               submenu = gtk_menu_new ();
+
+                       room_item = create_room_sub_menu (contact, chatroom);
+                       gtk_menu_shell_append ((GtkMenuShell*)submenu, room_item);
+                       gtk_widget_show (room_item);
+               }
+       }
+
+       if (submenu) {
+               gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+       } else {
+               gtk_widget_set_sensitive (item, FALSE);
+       }
 
        gtk_widget_show (image);
 
-  g_object_unref (mgr);
-  g_list_free (rooms);
+       g_object_unref (mgr);
+       g_list_free (rooms);
 
        return item;
 }
+