]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-individual-view.c
sort contacts by most recent event
[empathy.git] / libempathy-gtk / empathy-individual-view.c
index c048124157f12e6ffa8a330645220bc8e1ce8ea7..9e64f4b9ff04d3064e54ccb3b8978283aa198d94 100644 (file)
  */
 
 #include "config.h"
-
-#include <string.h>
+#include "empathy-individual-view.h"
 
 #include <glib/gi18n-lib.h>
-#include <gdk/gdkkeysyms.h>
-#include <gtk/gtk.h>
-
-#include <telepathy-glib/account-manager.h>
-#include <telepathy-glib/util.h>
-
-#include <folks/folks.h>
-#include <folks/folks-telepathy.h>
+#include <tp-account-widgets/tpaw-pixbuf-utils.h>
+#include <tp-account-widgets/tpaw-utils.h>
 
-#include <libempathy/empathy-connection-aggregator.h>
-#include <libempathy/empathy-individual-manager.h>
-#include <libempathy/empathy-contact-groups.h>
-#include <libempathy/empathy-request-util.h>
-#include <libempathy/empathy-utils.h>
-
-#include "empathy-individual-view.h"
-#include "empathy-individual-menu.h"
-#include "empathy-individual-store.h"
-#include "empathy-individual-edit-dialog.h"
-#include "empathy-individual-dialogs.h"
-#include "empathy-images.h"
+#include "empathy-cell-renderer-activatable.h"
 #include "empathy-cell-renderer-expander.h"
 #include "empathy-cell-renderer-text.h"
-#include "empathy-cell-renderer-activatable.h"
-#include "empathy-ui-utils.h"
+#include "empathy-connection-aggregator.h"
+#include "empathy-contact-groups.h"
 #include "empathy-gtk-enum-types.h"
+#include "empathy-images.h"
+#include "empathy-individual-edit-dialog.h"
+#include "empathy-individual-manager.h"
+#include "empathy-request-util.h"
+#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
-#include <libempathy/empathy-debug.h>
+#include "empathy-debug.h"
 
 /* Active users are those which have recently changed state
  * (e.g. online, offline or from normal to a busy state).
@@ -1083,12 +1071,14 @@ individual_view_call_activated_cb (EmpathyCellRendererActivatable *cell,
   shell = GTK_MENU_SHELL (menu);
 
   /* audio */
-  item = empathy_individual_audio_call_menu_item_new (individual);
+  item = empathy_individual_audio_call_menu_item_new_individual (NULL,
+      individual);
   gtk_menu_shell_append (shell, item);
   gtk_widget_show (item);
 
   /* video */
-  item = empathy_individual_video_call_menu_item_new (individual);
+  item = empathy_individual_video_call_menu_item_new_individual (NULL,
+      individual);
   gtk_menu_shell_append (shell, item);
   gtk_widget_show (item);
 
@@ -1174,12 +1164,12 @@ individual_view_group_icon_cell_data_func (GtkTreeViewColumn *tree_column,
 
   if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
     {
-      pixbuf = empathy_pixbuf_from_icon_name ("emblem-favorite",
+      pixbuf = tpaw_pixbuf_from_icon_name ("emblem-favorite",
           GTK_ICON_SIZE_MENU);
     }
   else if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY))
     {
-      pixbuf = empathy_pixbuf_from_icon_name ("im-local-xmpp",
+      pixbuf = tpaw_pixbuf_from_icon_name ("im-local-xmpp",
           GTK_ICON_SIZE_MENU);
     }
 
@@ -1341,7 +1331,7 @@ individual_view_start_search_cb (EmpathyIndividualView *view,
 }
 
 static void
-individual_view_search_text_notify_cb (EmpathyLiveSearch *search,
+individual_view_search_text_notify_cb (TpawLiveSearch *search,
     GParamSpec *pspec,
     EmpathyIndividualView *view)
 {
@@ -1434,7 +1424,7 @@ individual_view_search_key_navigation_cb (GtkWidget *search,
 }
 
 static void
-individual_view_search_hide_cb (EmpathyLiveSearch *search,
+individual_view_search_hide_cb (TpawLiveSearch *search,
     EmpathyIndividualView *view)
 {
   EmpathyIndividualViewPriv *priv = GET_PRIV (view);
@@ -1503,7 +1493,7 @@ individual_view_search_hide_cb (EmpathyLiveSearch *search,
 }
 
 static void
-individual_view_search_show_cb (EmpathyLiveSearch *search,
+individual_view_search_show_cb (TpawLiveSearch *search,
     EmpathyIndividualView *view)
 {
   /* block expand or collapse handlers during expand all, they would
@@ -1609,7 +1599,7 @@ individual_view_row_has_child_toggled_cb (GtkTreeModel *model,
       EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
       -1);
 
-  if (!is_group || EMP_STR_EMPTY (name))
+  if (!is_group || TPAW_STR_EMPTY (name))
     {
       g_free (name);
       return;
@@ -1653,7 +1643,7 @@ individual_view_is_visible_individual (EmpathyIndividualView *self,
     guint event_count)
 {
   EmpathyIndividualViewPriv *priv = GET_PRIV (self);
-  EmpathyLiveSearch *live = EMPATHY_LIVE_SEARCH (priv->search_widget);
+  TpawLiveSearch *live = TPAW_LIVE_SEARCH (priv->search_widget);
   GeeSet *personas;
   GeeIterator *iter;
   gboolean is_favorite;
@@ -1705,8 +1695,8 @@ individual_view_is_visible_individual (EmpathyIndividualView *self,
   }
 
   return empathy_individual_match_string (individual,
-      empathy_live_search_get_text (live),
-      empathy_live_search_get_words (live));
+      tpaw_live_search_get_text (live),
+      tpaw_live_search_get_words (live));
 }
 
 static gchar *
@@ -1982,7 +1972,7 @@ individual_view_constructed (GObject *object)
 
 static void
 individual_view_set_view_features (EmpathyIndividualView *view,
-    EmpathyIndividualFeatureFlags features)
+    EmpathyIndividualViewFeatureFlags features)
 {
   EmpathyIndividualViewPriv *priv = GET_PRIV (view);
   gboolean has_tooltip;
@@ -2331,15 +2321,12 @@ enum
 {
   REMOVE_DIALOG_RESPONSE_CANCEL = 0,
   REMOVE_DIALOG_RESPONSE_DELETE,
-  REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK,
 };
 
 static int
 individual_view_remove_dialog_show (GtkWindow *parent,
     const gchar *message,
-    const gchar *secondary_text,
-    gboolean block_button,
-    GdkPixbuf *avatar)
+    const gchar *secondary_text)
 {
   GtkWidget *dialog;
   gboolean res;
@@ -2347,28 +2334,6 @@ individual_view_remove_dialog_show (GtkWindow *parent,
   dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
       GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message);
 
-  if (avatar != NULL)
-    {
-      GtkWidget *image = gtk_image_new_from_pixbuf (avatar);
-      gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
-      gtk_widget_show (image);
-    }
-
-  if (block_button)
-    {
-      GtkWidget *button;
-
-      /* gtk_dialog_add_button() doesn't allow us to pass a string with a
-       * mnemonic so we have to create the button manually. */
-      button = gtk_button_new_with_mnemonic (
-          _("Delete and _Block"));
-
-      gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button,
-          REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK);
-
-      gtk_widget_show (button);
-    }
-
   gtk_dialog_add_buttons (GTK_DIALOG (dialog),
       GTK_STOCK_CANCEL, REMOVE_DIALOG_RESPONSE_CANCEL,
       GTK_STOCK_DELETE, REMOVE_DIALOG_RESPONSE_DELETE, NULL);
@@ -2398,9 +2363,9 @@ individual_view_group_remove_activate_cb (GtkMenuItem *menuitem,
       text =
           g_strdup_printf (_("Do you really want to remove the group '%s'?"),
           group);
-      parent = empathy_get_toplevel_window (GTK_WIDGET (view));
+      parent = tpaw_get_toplevel_window (GTK_WIDGET (view));
       if (individual_view_remove_dialog_show (parent, _("Removing group"),
-              text, FALSE, NULL) == REMOVE_DIALOG_RESPONSE_DELETE)
+              text) == REMOVE_DIALOG_RESPONSE_DELETE)
         {
           EmpathyIndividualManager *manager =
               empathy_individual_manager_dup_singleton ();
@@ -2491,142 +2456,12 @@ empathy_individual_view_get_group_menu (EmpathyIndividualView *view)
   return menu;
 }
 
-static void
-got_avatar (GObject *source_object,
-    GAsyncResult *result,
-    gpointer user_data)
-{
-  FolksIndividual *individual = FOLKS_INDIVIDUAL (source_object);
-  EmpathyIndividualView *view = user_data;
-  EmpathyIndividualViewPriv *priv = GET_PRIV (view);
-  GdkPixbuf *avatar;
-  EmpathyIndividualManager *manager;
-  gchar *text;
-  GtkWindow *parent;
-  GeeSet *personas;
-  guint persona_count = 0;
-  gboolean can_block;
-  GError *error = NULL;
-  gint res;
-
-  avatar = empathy_pixbuf_avatar_from_individual_scaled_finish (individual,
-      result, &error);
-
-  if (error != NULL)
-    {
-      DEBUG ("Could not get avatar: %s", error->message);
-      g_error_free (error);
-    }
-
-  /* We couldn't retrieve the avatar, but that isn't a fatal error,
-   * so we still display the remove dialog. */
-
-  personas = folks_individual_get_personas (individual);
-
-  if (priv->show_uninteresting)
-    {
-      persona_count = gee_collection_get_size (GEE_COLLECTION (personas));
-    }
-  else
-    {
-      GeeIterator *iter;
-
-      iter = gee_iterable_iterator (GEE_ITERABLE (personas));
-      while (persona_count < 2 && gee_iterator_next (iter))
-        {
-          FolksPersona *persona = gee_iterator_get (iter);
-
-          if (empathy_folks_persona_is_interesting (persona))
-            persona_count++;
-
-          g_clear_object (&persona);
-        }
-      g_clear_object (&iter);
-    }
-
-  /* If we have more than one TpfPersona, display a different message
-   * ensuring the user knows that *all* of the meta-contacts' personas will
-   * be removed. */
-
-  if (persona_count < 2)
-    {
-      /* Not a meta-contact */
-      text =
-          g_strdup_printf (
-              _("Do you really want to remove the contact '%s'?"),
-              folks_alias_details_get_alias (
-                  FOLKS_ALIAS_DETAILS (individual)));
-    }
-  else
-    {
-      /* Meta-contact */
-      text =
-          g_strdup_printf (
-              _("Do you really want to remove the linked contact '%s'? "
-                "Note that this will remove all the contacts which make up "
-                "this linked contact."),
-              folks_alias_details_get_alias (
-                  FOLKS_ALIAS_DETAILS (individual)));
-    }
-
-
-  manager = empathy_individual_manager_dup_singleton ();
-  can_block = empathy_individual_manager_supports_blocking (manager,
-      individual);
-  parent = empathy_get_toplevel_window (GTK_WIDGET (view));
-  res = individual_view_remove_dialog_show (parent, _("Removing contact"),
-          text, can_block, avatar);
-
-  if (res == REMOVE_DIALOG_RESPONSE_DELETE ||
-      res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
-    {
-      gboolean abusive;
-
-      if (res == REMOVE_DIALOG_RESPONSE_DELETE_AND_BLOCK)
-        {
-          if (!empathy_block_individual_dialog_show (parent, individual,
-                avatar, &abusive))
-            goto finally;
-
-          empathy_individual_manager_set_blocked (manager, individual,
-              TRUE, abusive);
-        }
-
-      empathy_individual_manager_remove (manager, individual, "");
-    }
-
- finally:
-  g_free (text);
-  g_object_unref (manager);
-}
-
-static void
-individual_view_remove_activate_cb (GtkMenuItem *menuitem,
-    EmpathyIndividualView *view)
-{
-  FolksIndividual *individual;
-
-  individual = empathy_individual_view_dup_selected (view);
-
-  if (individual != NULL)
-    {
-      empathy_pixbuf_avatar_from_individual_scaled_async (individual,
-          48, 48, NULL, got_avatar, view);
-      g_object_unref (individual);
-    }
-}
-
 GtkWidget *
 empathy_individual_view_get_individual_menu (EmpathyIndividualView *view)
 {
   EmpathyIndividualViewPriv *priv = GET_PRIV (view);
   FolksIndividual *individual;
   GtkWidget *menu = NULL;
-  GtkWidget *item;
-  GtkWidget *image;
-  gboolean can_remove = FALSE;
-  GeeSet *personas;
-  GeeIterator *iter;
 
   g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view), NULL);
 
@@ -2641,54 +2476,8 @@ empathy_individual_view_get_individual_menu (EmpathyIndividualView *view)
   if (!empathy_folks_individual_contains_contact (individual))
     goto out;
 
-  /* If any of the Individual's personas can be removed, add an option to
-   * remove. This will act as a best-effort option. If any Personas cannot be
-   * removed from the server, then this option will just be inactive upon
-   * subsequent menu openings */
-  personas = folks_individual_get_personas (individual);
-  iter = gee_iterable_iterator (GEE_ITERABLE (personas));
-  while (!can_remove && gee_iterator_next (iter))
-    {
-      FolksPersona *persona = gee_iterator_get (iter);
-      FolksPersonaStore *store = folks_persona_get_store (persona);
-      FolksMaybeBool maybe_can_remove =
-          folks_persona_store_get_can_remove_personas (store);
-
-      if (maybe_can_remove == FOLKS_MAYBE_BOOL_TRUE)
-        can_remove = TRUE;
-
-      g_clear_object (&persona);
-    }
-  g_clear_object (&iter);
-
-  menu = empathy_individual_menu_new (individual, priv->individual_features,
-      priv->store);
-
-  /* Remove contact */
-  if ((priv->view_features &
-      EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_REMOVE) &&
-      can_remove)
-    {
-      /* create the menu if required, or just add a separator */
-      if (menu == NULL)
-        menu = gtk_menu_new ();
-      else
-        {
-          item = gtk_separator_menu_item_new ();
-          gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-          gtk_widget_show (item);
-        }
-
-      /* Remove */
-      item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
-      image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
-          GTK_ICON_SIZE_MENU);
-      gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
-      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-      gtk_widget_show (item);
-      g_signal_connect (item, "activate",
-          G_CALLBACK (individual_view_remove_activate_cb), view);
-    }
+  menu = empathy_individual_menu_new (individual, NULL,
+      priv->individual_features, priv->store);
 
 out:
   g_object_unref (individual);
@@ -2698,7 +2487,7 @@ out:
 
 void
 empathy_individual_view_set_live_search (EmpathyIndividualView *view,
-    EmpathyLiveSearch *search)
+    TpawLiveSearch *search)
 {
   EmpathyIndividualViewPriv *priv = GET_PRIV (view);