]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-menu.c
Merge commit 'jtellier/video-call-button-sensitivity'
[empathy.git] / libempathy-gtk / empathy-contact-menu.c
index a3cf1da26f71aeedf5874d1e26c48d96f6cec19c..0de7c1ca6afdd78c4ab7847db97c4aa6d7db8c23 100644 (file)
@@ -15,7 +15,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Authors: Xavier Claessens <xclaesse@gmail.com>
  */
 
 
 #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>
+#include <libempathy/empathy-contact-manager.h>
 
 #include "empathy-contact-menu.h"
 #include "empathy-images.h"
@@ -55,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);
@@ -62,9 +71,14 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
-       /* Call */
        if (features & EMPATHY_CONTACT_FEATURE_CALL) {
-               item = empathy_contact_call_menu_item_new (contact);
+               /* Audio Call */
+               item = empathy_contact_audio_call_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+
+               /* Video Call */
+               item = empathy_contact_video_call_menu_item_new (contact);
                gtk_menu_shell_append (shell, item);
                gtk_widget_show (item);
        }
@@ -111,6 +125,77 @@ empathy_contact_menu_new (EmpathyContact             *contact,
        return menu;
 }
 
+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;
+}
+
 static void
 empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
        EmpathyContact *contact)
@@ -118,7 +203,6 @@ empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
   empathy_dispatcher_chat_with_contact (contact, NULL, NULL);
 }
 
-
 GtkWidget *
 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
 {
@@ -136,39 +220,71 @@ empathy_contact_chat_menu_item_new (EmpathyContact *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,
+empathy_contact_audio_call_menu_item_activated (GtkMenuItem *item,
        EmpathyContact *contact)
 {
        EmpathyCallFactory *factory;
 
        factory = empathy_call_factory_get ();
-       empathy_call_factory_new_call (factory, contact);
+       empathy_call_factory_new_call_with_streams (factory, contact, TRUE, FALSE);
 }
 
 GtkWidget *
-empathy_contact_call_menu_item_new (EmpathyContact *contact)
+empathy_contact_audio_call_menu_item_new (EmpathyContact *contact)
 {
        GtkWidget *item;
        GtkWidget *image;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-       item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Call"));
+       item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Audio 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_set_sensitive (item, empathy_contact_can_voip_audio (contact));
+       gtk_widget_show (image);
+
+       g_signal_connect (item, "activate",
+                                 G_CALLBACK (empathy_contact_audio_call_menu_item_activated),
+                                 contact);
+
+       return item;
+}
+
+static void
+empathy_contact_video_call_menu_item_activated (GtkMenuItem *item,
+       EmpathyContact *contact)
+{
+       EmpathyCallFactory *factory;
+
+       factory = empathy_call_factory_get ();
+       empathy_call_factory_new_call_with_streams (factory, contact, TRUE, TRUE);
+}
+
+GtkWidget *
+empathy_contact_video_call_menu_item_new (EmpathyContact *contact)
+{
+       GtkWidget *item;
+       GtkWidget *image;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+       item = gtk_image_menu_item_new_with_mnemonic (C_("menu item", "_Video Call"));
+       image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_VIDEO_CALL,
+                                             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_video (contact));
        gtk_widget_show (image);
 
        g_signal_connect (item, "activate",
-                                 G_CALLBACK (empathy_contact_call_menu_item_activated),
+                                 G_CALLBACK (empathy_contact_video_call_menu_item_activated),
                                  contact);
-       
+
        return item;
 }
 
@@ -207,7 +323,7 @@ empathy_contact_log_menu_item_new (EmpathyContact *contact)
        g_signal_connect_swapped (item, "activate",
                                  G_CALLBACK (contact_log_menu_item_activate_cb),
                                  contact);
-       
+
        return item;
 }
 
@@ -256,7 +372,7 @@ empathy_contact_info_menu_item_new (EmpathyContact *contact)
        g_signal_connect_swapped (item, "activate",
                                  G_CALLBACK (contact_info_menu_item_activate_cb),
                                  contact);
-       
+
        return item;
 }
 
@@ -269,21 +385,40 @@ contact_edit_menu_item_activate_cb (EmpathyContact *contact)
 GtkWidget *
 empathy_contact_edit_menu_item_new (EmpathyContact *contact)
 {
+       EmpathyContactManager *manager;
        GtkWidget *item;
        GtkWidget *image;
+       gboolean enable = FALSE;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
+       if (empathy_contact_manager_initialized ()) {
+               TpConnection *connection;
+               EmpathyContactListFlags flags;
+
+               manager = empathy_contact_manager_dup_singleton ();
+               connection = empathy_contact_get_connection (contact);
+               flags = empathy_contact_manager_get_flags_for_connection (
+                               manager, connection);
+
+               enable = (flags & EMPATHY_CONTACT_LIST_CAN_ALIAS ||
+                         flags & EMPATHY_CONTACT_LIST_CAN_GROUP);
+
+               g_object_unref (manager);
+       }
+
        item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
        image = gtk_image_new_from_icon_name (GTK_STOCK_EDIT,
                                              GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_widget_show (image);
 
+       gtk_widget_set_sensitive (item, enable);
+
        g_signal_connect_swapped (item, "activate",
                                  G_CALLBACK (contact_edit_menu_item_activate_cb),
                                  contact);
-       
+
        return item;
 }
 
@@ -301,7 +436,6 @@ room_sub_menu_data_new (EmpathyContact *contact,
        data = g_slice_new (RoomSubMenuData);
        data->contact = g_object_ref (contact);
        data->chatroom = g_object_ref (chatroom);
-
        return data;
 }
 
@@ -381,7 +515,7 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
                                submenu = gtk_menu_new ();
 
                        room_item = create_room_sub_menu (contact, chatroom);
-                       gtk_menu_shell_append ((GtkMenuShell*)submenu, room_item);
+                       gtk_menu_shell_append ((GtkMenuShell *) submenu, room_item);
                        gtk_widget_show (room_item);
                }
        }