]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-menu.c
Updated Polish translation
[empathy.git] / libempathy-gtk / empathy-contact-menu.c
index fdd9c34a1b50cb909228adbc48e75d86b94a3982..23522d40ea3251f9481fc282b53bed0c31b6df8d 100644 (file)
 
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
+#ifdef ENABLE_TPL
+#include <telepathy-logger/log-manager.h>
+#else
 
-#include <libempathy/empathy-call-factory.h>
 #include <libempathy/empathy-log-manager.h>
+#endif /* ENABLE_TPL */
+#include <libempathy/empathy-call-factory.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"
 #include "empathy-log-window.h"
 #include "empathy-contact-dialogs.h"
 #include "empathy-ui-utils.h"
+#include "empathy-share-my-desktop.h"
 
 GtkWidget *
 empathy_contact_menu_new (EmpathyContact             *contact,
@@ -55,6 +62,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);
@@ -91,6 +105,13 @@ empathy_contact_menu_new (EmpathyContact             *contact,
        gtk_menu_shell_append (shell, item);
        gtk_widget_show (item);
 
+       /* Share my desktop */
+       /* FIXME we should add the "Share my desktop" menu item if Vino is
+       a registered handler in MC5 */
+       item = empathy_contact_share_my_desktop_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)) {
@@ -113,9 +134,87 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
+#if HAVE_FAVOURITE_CONTACTS
+       /* Favorite checkbox */
+       item = empathy_contact_favourite_menu_item_new (contact);
+       gtk_menu_shell_append (shell, item);
+       gtk_widget_show (item);
+#endif
+
        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_is_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)
@@ -123,7 +222,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)
 {
@@ -141,7 +239,7 @@ empathy_contact_chat_menu_item_new (EmpathyContact *contact)
        g_signal_connect (item, "activate",
                                  G_CALLBACK (empathy_contact_chat_menu_item_activated),
                                  contact);
-       
+
        return item;
 }
 
@@ -167,7 +265,7 @@ empathy_contact_audio_call_menu_item_new (EmpathyContact *contact)
        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",
@@ -199,7 +297,7 @@ empathy_contact_video_call_menu_item_new (EmpathyContact *contact)
        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 (contact));
+       gtk_widget_set_sensitive (item, empathy_contact_can_voip_video (contact));
        gtk_widget_show (image);
 
        g_signal_connect (item, "activate",
@@ -220,21 +318,33 @@ contact_log_menu_item_activate_cb (EmpathyContact *contact)
 GtkWidget *
 empathy_contact_log_menu_item_new (EmpathyContact *contact)
 {
+#ifndef ENABLE_TPL
        EmpathyLogManager *manager;
+#else
+       TplLogManager     *manager;
+#endif /* ENABLE_TPL */
        gboolean           have_log;
        GtkWidget         *item;
        GtkWidget         *image;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
+#ifndef ENABLE_TPL
        manager = empathy_log_manager_dup_singleton ();
        have_log = empathy_log_manager_exists (manager,
                                               empathy_contact_get_account (contact),
                                               empathy_contact_get_id (contact),
                                               FALSE);
+#else
+       manager = tpl_log_manager_dup_singleton ();
+       have_log = tpl_log_manager_exists (manager,
+                                              empathy_contact_get_account (contact),
+                                              empathy_contact_get_id (contact),
+                                              FALSE);
+#endif /* ENABLE_TPL */
        g_object_unref (manager);
 
-       item = gtk_image_menu_item_new_with_mnemonic (_("_View Previous Conversations"));
+       item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
        image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_LOG,
                                              GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
@@ -244,7 +354,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;
 }
 
@@ -270,6 +380,71 @@ empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
        return item;
 }
 
+/* FIXME  we should check if the contact supports vnc stream tube */
+GtkWidget *
+empathy_contact_share_my_desktop_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 (_("Share my desktop"));
+       image = gtk_image_new_from_icon_name (GTK_STOCK_NETWORK,
+                                             GTK_ICON_SIZE_MENU);
+       gtk_widget_set_sensitive (item, empathy_contact_can_use_stream_tube (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_share_my_desktop_share_with_contact),
+                                 contact);
+
+       return item;
+}
+
+#if HAVE_FAVOURITE_CONTACTS
+static void
+favourite_menu_item_toggled_cb (GtkCheckMenuItem *item,
+       EmpathyContact *contact)
+{
+       EmpathyContactManager *manager;
+       EmpathyContactList *list;
+
+       manager = empathy_contact_manager_dup_singleton ();
+       list = EMPATHY_CONTACT_LIST (manager);
+
+       if (gtk_check_menu_item_get_active (item)) {
+               empathy_contact_list_add_to_favourites (list, contact);
+       } else {
+               empathy_contact_list_remove_from_favourites (list, contact);
+       }
+
+       g_object_unref (manager);
+}
+
+GtkWidget *
+empathy_contact_favourite_menu_item_new (EmpathyContact *contact)
+{
+       GtkWidget *item;
+       EmpathyContactManager *manager;
+
+       item = gtk_check_menu_item_new_with_label (_("Favorite"));
+
+       manager = empathy_contact_manager_dup_singleton ();
+       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
+               empathy_contact_list_is_favourite (EMPATHY_CONTACT_LIST (manager),
+                                                  contact));
+
+       g_signal_connect (item, "toggled",
+                         G_CALLBACK (favourite_menu_item_toggled_cb),
+                         contact);
+
+       g_object_unref (manager);
+       return item;
+}
+#endif
+
 static void
 contact_info_menu_item_activate_cb (EmpathyContact *contact)
 {
@@ -293,7 +468,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;
 }
 
@@ -306,21 +481,42 @@ 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);
 
-       item = gtk_image_menu_item_new_with_mnemonic (_("_Edit"));
+       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 (
+                                                    C_("Edit contact (contextual menu)",
+                                                       "_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;
 }
 
@@ -344,7 +540,6 @@ room_sub_menu_data_new (EmpathyContact *contact,
 static void
 room_sub_menu_data_free (RoomSubMenuData *data)
 {
-       /* FIXME: seems this is never called... */
        g_object_unref (data->contact);
        g_object_unref (data->chatroom);
        g_slice_free (RoomSubMenuData, data);
@@ -354,10 +549,7 @@ static void
 room_sub_menu_activate_cb (GtkWidget *item,
                           RoomSubMenuData *data)
 {
-       TpHandle handle;
-       GArray handles = {(gchar *) &handle, 1};
        EmpathyTpChat *chat;
-       TpChannel *channel;
 
        chat = empathy_chatroom_get_tp_chat (data->chatroom);
        if (chat == NULL) {
@@ -366,10 +558,8 @@ room_sub_menu_activate_cb (GtkWidget *item,
        }
 
        /* 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);
+       empathy_contact_list_add (EMPATHY_CONTACT_LIST (chat), data->contact,
+               _("Inviting you to this room"));
 }
 
 static GtkWidget *
@@ -400,7 +590,7 @@ empathy_contact_invite_menu_item_new (EmpathyContact *contact)
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-       item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chatroom"));
+       item = gtk_image_menu_item_new_with_mnemonic (_("_Invite to chat room"));
        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);