]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-widget.c
Merge commit 'staz/dnd'
[empathy.git] / libempathy-gtk / empathy-contact-widget.c
index 773aa6130765069baeb460715f2e8935d81de8db..82a5ac703bd976f85aea77b6a82b241db01eec77 100644 (file)
@@ -47,6 +47,7 @@
 #include "empathy-avatar-chooser.h"
 #include "empathy-avatar-image.h"
 #include "empathy-ui-utils.h"
+#include "empathy-string-parser.h"
 #include "empathy-kludge-label.h"
 
 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
@@ -81,6 +82,7 @@ typedef struct
   EmpathyContact *contact;
   EmpathyContactWidgetFlags flags;
   guint widget_id_timeout;
+  gulong fav_sig_id;
 
   GtkWidget *vbox_contact_widget;
 
@@ -99,6 +101,7 @@ typedef struct
   GtkWidget *label_status;
   GtkWidget *table_contact;
   GtkWidget *vbox_avatar;
+  GtkWidget *favourite_checkbox;
 
   /* Location */
   GtkWidget *vbox_location;
@@ -447,7 +450,6 @@ contact_widget_groups_setup (EmpathyContactWidget *information)
 {
   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_GROUPS)
     {
-      information->manager = empathy_contact_manager_dup_singleton ();
       contact_widget_model_setup (information);
     }
 }
@@ -552,6 +554,7 @@ contact_widget_location_update (EmpathyContactWidget *information)
   };
   int i;
   const gchar *skey;
+  gboolean display_map = FALSE;
 
   if (!(information->flags & EMPATHY_CONTACT_WIDGET_SHOW_LOCATION))
     {
@@ -666,20 +669,30 @@ contact_widget_location_update (EmpathyContactWidget *information)
       row++;
     }
 
-  if (row == 0)
+#if HAVE_LIBCHAMPLAIN
+  if (has_position &&
+      !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
+    {
+      /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
+       * windows */
+      display_map = TRUE;
+    }
+#endif
+
+  if (row > 0)
+    {
+      /* We can display some fields */
+      gtk_widget_show (information->table_location);
+    }
+  else if (!display_map)
     {
+      /* Can't display either fields or map */
       gtk_widget_hide (information->vbox_location);
       return;
     }
 
-  gtk_widget_show (information->table_location);
-
 #if HAVE_LIBCHAMPLAIN
-  /* Cannot be displayed in tooltips until Clutter-Gtk can deal with such
-   * windows
-   */
-  if (has_position &&
-      !(information->flags & EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP))
+  if (display_map)
     {
       ClutterActor *marker;
       ChamplainLayer *layer;
@@ -690,8 +703,10 @@ contact_widget_location_update (EmpathyContactWidget *information)
 
       gtk_container_add (GTK_CONTAINER (information->viewport_map),
           information->map_view_embed);
-      g_object_set (G_OBJECT (information->map_view), "show-license", FALSE,
+      g_object_set (G_OBJECT (information->map_view),
+          "show-license", TRUE,
           "scroll-mode", CHAMPLAIN_SCROLL_MODE_KINETIC,
+          "zoom-level", 10,
           NULL);
 
       layer = champlain_layer_new ();
@@ -826,9 +841,10 @@ popup_avatar_menu (EmpathyContactWidget *information,
       event_time = gtk_get_current_event_time ();
     }
 
-  gtk_menu_attach_to_widget (GTK_MENU (menu), parent, NULL);
   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
       button, event_time);
+  g_object_ref_sink (menu);
+  g_object_unref (menu);
 }
 
 static gboolean
@@ -934,14 +950,36 @@ contact_widget_name_notify_cb (EmpathyContactWidget *information)
 static void
 contact_widget_presence_notify_cb (EmpathyContactWidget *information)
 {
-  gtk_label_set_text (GTK_LABEL (information->label_status),
-      empathy_contact_get_status (information->contact));
+  const gchar *status;
+  gchar *markup_text = NULL;
+
+  status = empathy_contact_get_status (information->contact);
+  if (status != NULL)
+    markup_text = empathy_add_link_markup (status);
+  gtk_label_set_markup (GTK_LABEL (information->label_status), markup_text);
+  g_free (markup_text);
+
   gtk_image_set_from_icon_name (GTK_IMAGE (information->image_state),
       empathy_icon_name_for_contact (information->contact),
       GTK_ICON_SIZE_BUTTON);
   gtk_widget_show (information->image_state);
 }
 
+#if HAVE_FAVOURITE_CONTACTS
+static void
+contact_widget_favourites_changed_cb (EmpathyContactManager *manager,
+    EmpathyContact *contact,
+    gboolean is_favourite,
+    EmpathyContactWidget *information)
+{
+  if (contact != information->contact)
+    return;
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (
+            information->favourite_checkbox), is_favourite);
+}
+#endif
+
 static void
 contact_widget_remove_contact (EmpathyContactWidget *information)
 {
@@ -1030,6 +1068,20 @@ contact_widget_contact_update (EmpathyContactWidget *information)
       contact_widget_presence_notify_cb (information);
       contact_widget_avatar_notify_cb (information);
 
+#if HAVE_FAVOURITE_CONTACTS
+      if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
+        {
+          gboolean is_favourite;
+
+          is_favourite = empathy_contact_list_is_favourite (
+              EMPATHY_CONTACT_LIST (information->manager),
+              information->contact);
+
+          contact_widget_favourites_changed_cb (information->manager,
+              information->contact, is_favourite, information);
+        }
+#endif
+
       gtk_widget_show (information->label_alias);
       gtk_widget_show (information->widget_alias);
       gtk_widget_show (information->hbox_presence);
@@ -1159,6 +1211,28 @@ contact_widget_id_focus_out_cb (GtkWidget *widget,
   return FALSE;
 }
 
+#if HAVE_FAVOURITE_CONTACTS
+static void
+favourite_toggled_cb (GtkToggleButton *button,
+    EmpathyContactWidget *information)
+{
+  gboolean active;
+
+  active = gtk_toggle_button_get_active (button);
+
+  if (active)
+    {
+      empathy_contact_list_add_to_favourites (
+          EMPATHY_CONTACT_LIST (information->manager), information->contact);
+    }
+  else
+    {
+      empathy_contact_list_remove_from_favourites (
+          EMPATHY_CONTACT_LIST (information->manager), information->contact);
+    }
+}
+#endif
+
 static void
 contact_widget_contact_setup (EmpathyContactWidget *information)
 {
@@ -1271,9 +1345,12 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
   if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_ALIAS)
     {
       information->widget_alias = gtk_entry_new ();
-      g_signal_connect (information->widget_alias, "focus-out-event",
-            G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
-            information);
+
+      if (!(information->flags & EMPATHY_CONTACT_WIDGET_NO_SET_ALIAS))
+        g_signal_connect (information->widget_alias, "focus-out-event",
+              G_CALLBACK (contact_widget_entry_alias_focus_event_cb),
+              information);
+
       /* Make return activate the window default (the Close button) */
       gtk_entry_set_activates_default (GTK_ENTRY (information->widget_alias),
           TRUE);
@@ -1293,6 +1370,27 @@ contact_widget_contact_setup (EmpathyContactWidget *information)
     gtk_label_set_selectable (GTK_LABEL (information->label_status), FALSE);
   }
   gtk_widget_show (information->widget_alias);
+
+#if HAVE_FAVOURITE_CONTACTS
+  /* Favorite */
+  if (information->flags & EMPATHY_CONTACT_WIDGET_EDIT_FAVOURITE)
+    {
+      information->favourite_checkbox = gtk_check_button_new_with_label (
+          _("Favorite"));
+
+      g_signal_connect (information->favourite_checkbox, "toggled",
+          G_CALLBACK (favourite_toggled_cb), information);
+
+      gtk_table_attach_defaults (GTK_TABLE (information->table_contact),
+           information->favourite_checkbox, 0, 2, 3, 4);
+
+      information->fav_sig_id = g_signal_connect (information->manager,
+          "favourites-changed",
+          G_CALLBACK (contact_widget_favourites_changed_cb), information);
+
+      gtk_widget_show (information->favourite_checkbox);
+    }
+#endif
 }
 
 static void
@@ -1305,10 +1403,11 @@ contact_widget_destroy_cb (GtkWidget *widget,
     {
       g_source_remove (information->widget_id_timeout);
     }
-  if (information->manager)
-    {
-      g_object_unref (information->manager);
-    }
+
+  if (information->fav_sig_id != 0)
+    g_signal_handler_disconnect (information->manager, information->fav_sig_id);
+
+  g_object_unref (information->manager);
 
   g_slice_free (EmpathyContactWidget, information);
 }
@@ -1376,6 +1475,8 @@ empathy_contact_widget_new (EmpathyContact *contact,
       "EmpathyContactWidget",
       information);
 
+  information->manager = empathy_contact_manager_dup_singleton ();
+
   /* Create widgets */
   contact_widget_contact_setup (information);
   contact_widget_groups_setup (information);
@@ -1414,6 +1515,20 @@ empathy_contact_widget_get_contact (GtkWidget *widget)
   return information->contact;
 }
 
+const gchar *
+empathy_contact_widget_get_alias (GtkWidget *widget)
+{
+  EmpathyContactWidget *information;
+
+  g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+  information = g_object_get_data (G_OBJECT (widget), "EmpathyContactWidget");
+  if (!information)
+      return NULL;
+
+  return gtk_entry_get_text (GTK_ENTRY (information->widget_alias));
+}
+
 /**
  * empathy_contact_widget_set_contact:
  * @widget: an #EmpathyContactWidget