]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-menu.c
contact-menu: use tp-glib blocking API
[empathy.git] / libempathy-gtk / empathy-contact-menu.c
index 54bb4b28617a96c1b5a5f27896d109557412cf65..a6f5a209d14719e06be82c476fb5add0bbc42fe4 100644 (file)
 
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
-#ifdef ENABLE_TPL
 #include <telepathy-logger/log-manager.h>
-#else
 
-#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-request-util.h>
 #include <libempathy/empathy-utils.h>
 #include <libempathy/empathy-chatroom-manager.h>
 #include <libempathy/empathy-contact-manager.h>
@@ -44,6 +39,9 @@
 #include "empathy-contact-dialogs.h"
 #include "empathy-ui-utils.h"
 #include "empathy-share-my-desktop.h"
+#include "empathy-call-utils.h"
+
+static GtkWidget *empathy_contact_block_menu_item_new (EmpathyContact *);
 
 GtkWidget *
 empathy_contact_menu_new (EmpathyContact             *contact,
@@ -88,22 +86,17 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
-       /* Log */
-       if (features & EMPATHY_CONTACT_FEATURE_LOG) {
-               item = empathy_contact_log_menu_item_new (contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-       }
-
        /* Invite */
        item = empathy_contact_invite_menu_item_new (contact);
        gtk_menu_shell_append (shell, item);
        gtk_widget_show (item);
 
        /* File transfer */
-       item = empathy_contact_file_transfer_menu_item_new (contact);
-       gtk_menu_shell_append (shell, item);
-       gtk_widget_show (item);
+       if (features & EMPATHY_CONTACT_FEATURE_FT) {
+               item = empathy_contact_file_transfer_menu_item_new (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
@@ -127,6 +120,13 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
+       /* Log */
+       if (features & EMPATHY_CONTACT_FEATURE_LOG) {
+               item = empathy_contact_log_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
        /* Info */
        if (features & EMPATHY_CONTACT_FEATURE_INFO) {
                item = empathy_contact_info_menu_item_new (contact);
@@ -134,6 +134,19 @@ empathy_contact_menu_new (EmpathyContact             *contact,
                gtk_widget_show (item);
        }
 
+       /* Separator & Block */
+       if (features & EMPATHY_CONTACT_FEATURE_BLOCK &&
+           (item = empathy_contact_block_menu_item_new (contact)) != NULL) {
+               GtkWidget *sep;
+
+               sep = gtk_separator_menu_item_new ();
+               gtk_menu_shell_append (shell, sep);
+               gtk_widget_show (sep);
+
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
        return menu;
 }
 
@@ -208,11 +221,91 @@ empathy_contact_add_menu_item_new (EmpathyContact *contact)
        return item;
 }
 
+static void
+empathy_contact_block_menu_item_toggled (GtkCheckMenuItem *item,
+                                        EmpathyContact   *contact)
+{
+       static guint block_signal = 0;
+       gboolean blocked, abusive;
+       TpContact *tp_contact;
+
+       if (block_signal > 0)
+               return;
+
+       blocked = gtk_check_menu_item_get_active (item);
+
+       if (blocked) {
+               /* confirm the user really wishes to block the contact */
+               GtkWidget *parent;
+               GdkPixbuf *avatar;
+
+               /* gtk_menu_get_attach_widget () doesn't behave properly here
+                * for some reason */
+               parent = g_object_get_data (
+                       G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (item))),
+                       "window");
+
+               avatar = empathy_pixbuf_avatar_from_contact_scaled (contact, 48, 48);
+
+               if (!empathy_block_contact_dialog_show (GTK_WINDOW (parent),
+                                       contact, avatar, &abusive))
+                       return;
+       }
+
+       tp_contact = empathy_contact_get_tp_contact (contact);
+
+       if (blocked)
+               tp_contact_block_async (tp_contact, abusive, NULL, NULL);
+       else
+               tp_contact_unblock_async (tp_contact, NULL, NULL);
+
+       /* update the toggle with the blocked status */
+       block_signal++;
+       gtk_check_menu_item_set_active (item, blocked);
+       block_signal--;
+}
+
+static GtkWidget *
+empathy_contact_block_menu_item_new (EmpathyContact *contact)
+{
+       GtkWidget *item;
+       EmpathyContactManager *manager;
+       TpConnection *connection;
+       TpContact *tp_contact;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+       manager = empathy_contact_manager_dup_singleton ();
+
+       if (!empathy_contact_manager_initialized ()) {
+               return NULL;
+       }
+
+       connection = empathy_contact_get_connection (contact);
+
+       if (!tp_proxy_has_interface_by_id (connection,
+               TP_IFACE_QUARK_CONNECTION_INTERFACE_CONTACT_BLOCKING))
+               return NULL;
+
+       item = gtk_check_menu_item_new_with_mnemonic (_("_Block Contact"));
+
+       tp_contact = empathy_contact_get_tp_contact (contact);
+
+       gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
+                       tp_contact_is_blocked (tp_contact));
+
+       g_signal_connect (item, "toggled",
+                       G_CALLBACK (empathy_contact_block_menu_item_toggled),
+                       contact);
+
+       return item;
+}
+
 static void
 empathy_contact_chat_menu_item_activated (GtkMenuItem *item,
        EmpathyContact *contact)
 {
-  empathy_dispatcher_chat_with_contact (contact, NULL, NULL);
+       empathy_chat_with_contact (contact, empathy_get_current_action_time ());
 }
 
 GtkWidget *
@@ -227,6 +320,7 @@ empathy_contact_chat_menu_item_new (EmpathyContact *contact)
        image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_MESSAGE,
                                              GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
+       gtk_widget_set_sensitive (item, !empathy_contact_is_user (contact));
        gtk_widget_show (image);
 
        g_signal_connect (item, "activate",
@@ -240,10 +334,10 @@ static void
 empathy_contact_audio_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, FALSE);
+       empathy_call_new_with_streams (empathy_contact_get_id (contact),
+               empathy_contact_get_account (contact),
+               TRUE, FALSE,
+               empathy_get_current_action_time ());
 }
 
 GtkWidget *
@@ -258,7 +352,8 @@ 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_audio (contact));
+       gtk_widget_set_sensitive (item, empathy_contact_can_voip_audio (contact) &&
+                                       !empathy_contact_is_user (contact));
        gtk_widget_show (image);
 
        g_signal_connect (item, "activate",
@@ -272,10 +367,10 @@ 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);
+       empathy_call_new_with_streams (empathy_contact_get_id (contact),
+               empathy_contact_get_account (contact),
+               TRUE, TRUE,
+               empathy_get_current_action_time ());
 }
 
 GtkWidget *
@@ -290,7 +385,8 @@ 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_video (contact));
+       gtk_widget_set_sensitive (item, empathy_contact_can_voip_video (contact) &&
+                                       !empathy_contact_is_user (contact));
        gtk_widget_show (image);
 
        g_signal_connect (item, "activate",
@@ -311,30 +407,24 @@ 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 */
+       TplEntity         *entity;
        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 ();
+       entity = tpl_entity_new_from_tp_contact (empathy_contact_get_tp_contact (contact),
+                                                TPL_ENTITY_CONTACT);
+
        have_log = tpl_log_manager_exists (manager,
-                                              empathy_contact_get_account (contact),
-                                              empathy_contact_get_id (contact),
-                                              FALSE);
-#endif /* ENABLE_TPL */
+                                          empathy_contact_get_account (contact),
+                                          entity,
+                                          TPL_EVENT_MASK_TEXT);
+
+       g_object_unref (entity);
        g_object_unref (manager);
 
        item = gtk_image_menu_item_new_with_mnemonic (_("_Previous Conversations"));
@@ -359,10 +449,11 @@ empathy_contact_file_transfer_menu_item_new (EmpathyContact *contact)
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-       item = gtk_image_menu_item_new_with_mnemonic (_("Send file"));
+       item = gtk_image_menu_item_new_with_mnemonic (_("Send File"));
        image = gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
                                              GTK_ICON_SIZE_MENU);
-       gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact));
+       gtk_widget_set_sensitive (item, empathy_contact_can_send_files (contact) &&
+                                       !empathy_contact_is_user (contact));
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_widget_show (image);
 
@@ -373,7 +464,6 @@ 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)
 {
@@ -382,10 +472,11 @@ empathy_contact_share_my_desktop_menu_item_new (EmpathyContact *contact)
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
 
-       item = gtk_image_menu_item_new_with_mnemonic (_("Share my desktop"));
+       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_widget_set_sensitive (item, empathy_contact_can_use_rfb_stream_tube (
+               contact));
        gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
        gtk_widget_show (image);
 
@@ -541,11 +632,17 @@ 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 chat room"));
+       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);
 
+       if (empathy_contact_is_user (contact)) {
+               gtk_widget_set_sensitive (item, FALSE);
+               gtk_widget_show (image);
+               return item;
+       }
+
        mgr = empathy_chatroom_manager_dup_singleton (NULL);
        rooms = empathy_chatroom_manager_get_chatrooms (mgr,
                empathy_contact_get_account (contact));