]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-persona-view.c
Use gtk_list_store_insert_with_values ()
[empathy.git] / libempathy-gtk / empathy-persona-view.c
index 289f6fac9e22400dbb784b16c37477a88ec76a93..7df94a630ea1871b692315b54ab200162d05b806 100644 (file)
@@ -46,7 +46,6 @@
 #include "empathy-cell-renderer-text.h"
 #include "empathy-cell-renderer-activatable.h"
 #include "empathy-gtk-enum-types.h"
-#include "empathy-gtk-marshal.h"
 #include "empathy-ui-utils.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
@@ -84,30 +83,30 @@ enum
   PROP_FEATURES,
 };
 
-enum DndDragType
+typedef enum
 {
-  DND_DRAG_TYPE_INDIVIDUAL_ID,
+  DND_DRAG_TYPE_UNKNOWN = -1,
+  DND_DRAG_TYPE_INDIVIDUAL_ID = 0,
   DND_DRAG_TYPE_PERSONA_ID,
   DND_DRAG_TYPE_STRING,
-};
+} DndDragType;
 
 #define DRAG_TYPE(T,I) \
   { (gchar *) T, 0, I }
 
 static const GtkTargetEntry drag_types_dest[] = {
-  DRAG_TYPE ("text/individual-id", DND_DRAG_TYPE_INDIVIDUAL_ID),
+  DRAG_TYPE ("text/x-individual-id", DND_DRAG_TYPE_INDIVIDUAL_ID),
   DRAG_TYPE ("text/plain", DND_DRAG_TYPE_STRING),
   DRAG_TYPE ("STRING", DND_DRAG_TYPE_STRING),
 };
 
 static const GtkTargetEntry drag_types_source[] = {
-  DRAG_TYPE ("text/persona-id", DND_DRAG_TYPE_PERSONA_ID),
+  DRAG_TYPE ("text/x-persona-id", DND_DRAG_TYPE_PERSONA_ID),
 };
 
 #undef DRAG_TYPE
 
 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
-static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
 
 enum
 {
@@ -174,6 +173,7 @@ query_tooltip_cb (EmpathyPersonaView *self,
 {
   EmpathyPersonaViewPriv *priv = GET_PRIV (self);
   FolksPersona *persona;
+  TpContact *tp_contact;
   EmpathyContact *contact;
   GtkTreeModel *model;
   GtkTreeIter iter;
@@ -201,8 +201,14 @@ query_tooltip_cb (EmpathyPersonaView *self,
   if (persona == NULL)
     goto OUT;
 
-  contact = empathy_contact_dup_from_tp_contact (tpf_persona_get_contact (
-      TPF_PERSONA (persona)));
+  tp_contact = tpf_persona_get_contact (TPF_PERSONA (persona));
+  if (tp_contact == NULL)
+    {
+      g_clear_object (&persona);
+      goto OUT;
+    }
+
+  contact = empathy_contact_dup_from_tp_contact (tp_contact);
 
   if (priv->tooltip_widget == NULL)
     {
@@ -408,10 +414,22 @@ drag_motion (GtkWidget *widget,
 {
   EmpathyPersonaView *self = EMPATHY_PERSONA_VIEW (widget);
   GdkAtom target;
+  guint i;
+  DndDragType drag_type = DND_DRAG_TYPE_UNKNOWN;
 
   target = gtk_drag_dest_find_target (GTK_WIDGET (self), context, NULL);
 
-  if (target == drag_atoms_dest[DND_DRAG_TYPE_INDIVIDUAL_ID])
+  /* Determine the DndDragType of the data */
+  for (i = 0; i < G_N_ELEMENTS (drag_atoms_dest); i++)
+    {
+      if (target == drag_atoms_dest[i])
+        {
+          drag_type = drag_types_dest[i].info;
+          break;
+        }
+    }
+
+  if (drag_type == DND_DRAG_TYPE_INDIVIDUAL_ID)
     {
       GtkTreePath *path;
 
@@ -457,7 +475,8 @@ drag_data_get (GtkWidget *widget,
     return;
 
   persona_uid = folks_persona_get_uid (persona);
-  gtk_selection_data_set (selection, drag_atoms_source[info], 8,
+  gtk_selection_data_set (selection,
+      gdk_atom_intern ("text/x-persona-id", FALSE), 8,
       (guchar *) persona_uid, strlen (persona_uid) + 1);
 
   g_object_unref (persona);
@@ -605,9 +624,6 @@ constructed (GObject *object)
   /* Drag & Drop. */
   for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i)
     drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target, FALSE);
-
-  for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i)
-    drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target, FALSE);
 }
 
 static void
@@ -698,7 +714,7 @@ empathy_persona_view_class_init (EmpathyPersonaViewClass *klass)
       G_SIGNAL_RUN_LAST,
       G_STRUCT_OFFSET (EmpathyPersonaViewClass, drag_individual_received),
       NULL, NULL,
-      _empathy_gtk_marshal_BOOLEAN__UINT_OBJECT,
+      g_cclosure_marshal_generic,
       G_TYPE_BOOLEAN, 2, G_TYPE_UINT, FOLKS_TYPE_INDIVIDUAL);
 
   /* We override the "model" property so that we can wrap it in a