]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-groups-widget.c
Reorder header inclusions accordingly to the Telepathy coding style
[empathy.git] / libempathy-gtk / empathy-groups-widget.c
index 7e50dfbe258eb2158b8865beaee79f83c051a4a6..d1a6febfade8829a1539ee2a1431781567e7e817 100644 (file)
  *          Philip Withnall <philip.withnall@collabora.co.uk>
  */
 
-#include <config.h>
-
-#include <string.h>
-#include <stdlib.h>
+#include "config.h"
+#include "empathy-groups-widget.h"
 
-#include <gtk/gtk.h>
 #include <glib/gi18n-lib.h>
 
-#include <telepathy-glib/util.h>
-
-#include <folks/folks.h>
-
-#include <libempathy/empathy-utils.h>
-#include <libempathy/empathy-contact-manager.h>
-
-#include "empathy-groups-widget.h"
-#include "empathy-ui-utils.h"
+#include "empathy-utils.h"
+#include "empathy-connection-aggregator.h"
 
 /**
  * SECTION:empathy-groups-widget
  * @title:EmpathyGroupsWidget
- * @short_description: A widget used to edit the groups of a #FolksGroups
+ * @short_description: A widget used to edit the groups of a #FolksGroupDetails
  * @include: libempathy-gtk/empathy-groups-widget.h
  *
- * #EmpathyGroupsWidget is a widget which lists the groups of a #FolksGroups
- * (i.e. a #FolksPersona or a #FolksIndividual) and allows them to be added and
- * removed.
+ * #EmpathyGroupsWidget is a widget which lists the groups of a
+ * #FolksGroupDetails (i.e. a #FolksPersona or a #FolksIndividual) and allows
+ * them to be added and removed.
  */
 
 /**
  * EmpathyGroupsWidget:
  * @parent: parent object
  *
- * Widget which displays and allows editing of the groups of a #FolksGroups
- * (i.e. a #FolksPersona or #FolksIndividual).
+ * Widget which displays and allows editing of the groups of a
+ * #FolksGroupDetails (i.e. a #FolksPersona or #FolksIndividual).
  */
 
 /* Delay before updating the widget when the id entry changed (seconds) */
@@ -64,7 +54,7 @@
 typedef struct
 {
   /* The object we're actually changing the groups of */
-  FolksGroups *groupable; /* owned */
+  FolksGroupDetails *group_details; /* owned */
   GtkListStore *group_store; /* owned */
 
   GtkWidget *add_group_entry; /* child widget */
@@ -72,7 +62,7 @@ typedef struct
 } EmpathyGroupsWidgetPriv;
 
 enum {
-  PROP_GROUPABLE = 1,
+  PROP_GROUP_DETAILS = 1,
 };
 
 enum {
@@ -150,39 +140,36 @@ static void
 populate_data (EmpathyGroupsWidget *self)
 {
   EmpathyGroupsWidgetPriv *priv = GET_PRIV (self);
-  EmpathyContactManager *manager;
-  GtkTreeIter iter;
-  GHashTable *my_groups;
+  EmpathyConnectionAggregator *aggregator;
+  GeeSet *member_groups;
   GList *all_groups, *l;
 
   /* Remove the old groups */
   gtk_list_store_clear (priv->group_store);
 
-  /* FIXME: We have to get the whole group list from EmpathyContactManager, as
-   * libfolks hasn't grown API to get the whole group list yet. (bgo#627398) */
-  manager = empathy_contact_manager_dup_singleton ();
-  all_groups = empathy_contact_list_get_all_groups (
-      EMPATHY_CONTACT_LIST (manager));
-  g_object_unref (manager);
+  /* FIXME: We have to get the whole group list from
+   * EmpathyConnectionAggregator, as libfolks hasn't grown API to get the whole
+   * group list yet. (bgo#627398) */
+  aggregator = empathy_connection_aggregator_dup_singleton ();
+  all_groups = empathy_connection_aggregator_get_all_groups (aggregator);
+  g_object_unref (aggregator);
 
-  /* Get the list of groups that this #FolksGroups is currently in */
-  my_groups = folks_groups_get_groups (priv->groupable);
+  /* Get the list of groups that this #FolksGroupDetails is currently in */
+  member_groups = folks_group_details_get_groups (priv->group_details);
 
   for (l = all_groups; l != NULL; l = l->next)
     {
       const gchar *group_str = l->data;
       gboolean enabled;
 
-      enabled = GPOINTER_TO_UINT (g_hash_table_lookup (my_groups, group_str));
+      enabled = gee_collection_contains (GEE_COLLECTION (member_groups),
+          group_str);
 
-      gtk_list_store_append (priv->group_store, &iter);
-      gtk_list_store_set (priv->group_store, &iter,
+      gtk_list_store_insert_with_values (priv->group_store, NULL, -1,
           COL_NAME, group_str,
           COL_EDITABLE, TRUE,
           COL_ENABLED, enabled,
           -1);
-
-      g_free (l->data);
     }
 
   g_list_free (all_groups);
@@ -217,13 +204,13 @@ add_group_entry_activate_cb (GtkEntry *entry,
 }
 
 static void
-change_group_cb (FolksGroups *groupable,
+change_group_cb (FolksGroupDetails *group_details,
     GAsyncResult *async_result,
     EmpathyGroupsWidget *self)
 {
   GError *error = NULL;
 
-  folks_groups_change_group_finish (groupable, async_result, &error);
+  folks_group_details_change_group_finish (group_details, async_result, &error);
 
   if (error != NULL)
     {
@@ -237,18 +224,16 @@ add_group_button_clicked_cb (GtkButton *button,
    EmpathyGroupsWidget *self)
 {
   EmpathyGroupsWidgetPriv *priv = GET_PRIV (self);
-  GtkTreeIter iter;
   const gchar *group;
 
   group = gtk_entry_get_text (GTK_ENTRY (priv->add_group_entry));
 
-  gtk_list_store_append (priv->group_store, &iter);
-  gtk_list_store_set (priv->group_store, &iter,
+  gtk_list_store_insert_with_values (priv->group_store, NULL, -1,
       COL_NAME, group,
       COL_ENABLED, TRUE,
       -1);
 
-  folks_groups_change_group (priv->groupable, group, TRUE,
+  folks_group_details_change_group (priv->group_details, group, TRUE,
       (GAsyncReadyCallback) change_group_cb, self);
 }
 
@@ -280,15 +265,15 @@ cell_toggled_cb (GtkCellRendererToggle *cell,
 
   if (group != NULL)
     {
-      folks_groups_change_group (priv->groupable, group, !was_enabled,
-          (GAsyncReadyCallback) change_group_cb, self);
+      folks_group_details_change_group (priv->group_details, group,
+          !was_enabled, (GAsyncReadyCallback) change_group_cb, self);
       g_free (group);
     }
 }
 
 
 static void
-groupable_group_changed_cb (FolksGroups *groups,
+group_details_group_changed_cb (FolksGroupDetails *groups,
     const gchar *group,
     gboolean is_member,
     EmpathyGroupsWidget *self)
@@ -339,7 +324,7 @@ set_up (EmpathyGroupsWidget *self)
   alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
   gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 12, 0);
 
-  vbox = GTK_BOX (gtk_vbox_new (FALSE, 6));
+  vbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 6));
 
   label = gtk_label_new (_("Select the groups you want this contact to appear "
       "in.  Note that you can select more than one group or no groups."));
@@ -349,7 +334,7 @@ set_up (EmpathyGroupsWidget *self)
   gtk_box_pack_start (vbox, label, FALSE, FALSE, 0);
   gtk_widget_show (label);
 
-  hbox = GTK_BOX (gtk_hbox_new (FALSE, 12));
+  hbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12));
 
   priv->add_group_entry = gtk_entry_new ();
   g_signal_connect (priv->add_group_entry, "changed",
@@ -394,7 +379,8 @@ set_up (EmpathyGroupsWidget *self)
   renderer = gtk_cell_renderer_toggle_new ();
   g_signal_connect (renderer, "toggled", (GCallback) cell_toggled_cb, self);
 
-  column = gtk_tree_view_column_new_with_attributes (_("Select"), renderer,
+  column = gtk_tree_view_column_new_with_attributes (
+      C_("verb in a column header displaying group names", "Select"), renderer,
       "active", COL_ENABLED,
       NULL);
 
@@ -452,8 +438,8 @@ get_property (GObject *object,
 
   switch (param_id)
     {
-      case PROP_GROUPABLE:
-        g_value_set_object (value, priv->groupable);
+      case PROP_GROUP_DETAILS:
+        g_value_set_object (value, priv->group_details);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -467,14 +453,10 @@ set_property (GObject *object,
     const GValue *value,
     GParamSpec *pspec)
 {
-  EmpathyGroupsWidgetPriv *priv;
-
-  priv = GET_PRIV (object);
-
   switch (param_id)
     {
-      case PROP_GROUPABLE:
-        empathy_groups_widget_set_groupable (EMPATHY_GROUPS_WIDGET (object),
+      case PROP_GROUP_DETAILS:
+        empathy_groups_widget_set_group_details (EMPATHY_GROUPS_WIDGET (object),
             g_value_get_object (value));
         break;
       default:
@@ -488,7 +470,8 @@ dispose (GObject *object)
 {
   EmpathyGroupsWidgetPriv *priv = GET_PRIV (object);
 
-  empathy_groups_widget_set_groupable (EMPATHY_GROUPS_WIDGET (object), NULL);
+  empathy_groups_widget_set_group_details (EMPATHY_GROUPS_WIDGET (object),
+      NULL);
   tp_clear_object (&priv->group_store);
 
   G_OBJECT_CLASS (empathy_groups_widget_parent_class)->dispose (object);
@@ -504,16 +487,16 @@ empathy_groups_widget_class_init (EmpathyGroupsWidgetClass *klass)
   object_class->dispose = dispose;
 
   /**
-   * EmpathyGroupsWidget:groupable:
+   * EmpathyGroupsWidget:group_details:
    *
-   * The #FolksGroups whose group membership is to be edited by the
+   * The #FolksGroupDetails whose group membership is to be edited by the
    * #EmpathyGroupsWidget.
    */
-  g_object_class_install_property (object_class, PROP_GROUPABLE,
-      g_param_spec_object ("groupable",
-          "Groupable",
-          "The #FolksGroups whose groups are being edited.",
-          FOLKS_TYPE_GROUPS,
+  g_object_class_install_property (object_class, PROP_GROUP_DETAILS,
+      g_param_spec_object ("group-details",
+          "Group Details",
+          "The #FolksGroupDetails whose groups are being edited.",
+          FOLKS_TYPE_GROUP_DETAILS,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
   g_type_class_add_private (object_class, sizeof (EmpathyGroupsWidgetPriv));
@@ -521,80 +504,83 @@ empathy_groups_widget_class_init (EmpathyGroupsWidgetClass *klass)
 
 /**
  * empathy_groups_widget_new:
- * @groupable: a #FolksGroups, or %NULL
+ * @group_details: a #FolksGroupDetails, or %NULL
  *
  * Creates a new #EmpathyGroupsWidget to edit the groups of the given
- * @groupable.
+ * @group_details.
  *
  * Return value: a new #EmpathyGroupsWidget
  */
 GtkWidget *
-empathy_groups_widget_new (FolksGroups *groupable)
+empathy_groups_widget_new (FolksGroupDetails *group_details)
 {
-  g_return_val_if_fail (groupable == NULL || FOLKS_IS_GROUPS (groupable),
+  g_return_val_if_fail (
+      group_details == NULL || FOLKS_IS_GROUP_DETAILS (group_details),
       NULL);
 
   return GTK_WIDGET (g_object_new (EMPATHY_TYPE_GROUPS_WIDGET,
-      "groupable", groupable,
+      "group-details", group_details,
       NULL));
 }
 
 /**
- * empathy_groups_widget_get_groupable:
+ * empathy_groups_widget_get_group_details:
  * @self: an #EmpathyGroupsWidget
  *
- * Get the #FolksGroups whose group membership is being edited by the
+ * Get the #FolksGroupDetails whose group membership is being edited by the
  * #EmpathyGroupsWidget.
  *
- * Returns: the #FolksGroups associated with @widget, or %NULL
+ * Returns: the #FolksGroupDetails associated with @widget, or %NULL
  */
-FolksGroups *
-empathy_groups_widget_get_groupable (EmpathyGroupsWidget *self)
+FolksGroupDetails *
+empathy_groups_widget_get_group_details (EmpathyGroupsWidget *self)
 {
   g_return_val_if_fail (EMPATHY_IS_GROUPS_WIDGET (self), NULL);
 
-  return GET_PRIV (self)->groupable;
+  return GET_PRIV (self)->group_details;
 }
 
 /**
- * empathy_groups_widget_set_groupable:
+ * empathy_groups_widget_set_group_details:
  * @self: an #EmpathyGroupsWidget
- * @groupable: the #FolksGroups whose membership is to be edited, or %NULL
+ * @group_details: the #FolksGroupDetails whose membership is to be edited, or
+ * %NULL
  *
- * Change the #FolksGroups whose group membership is to be edited by the
+ * Change the #FolksGroupDetails whose group membership is to be edited by the
  * #EmpathyGroupsWidget.
  */
 void
-empathy_groups_widget_set_groupable (EmpathyGroupsWidget *self,
-    FolksGroups *groupable)
+empathy_groups_widget_set_group_details (EmpathyGroupsWidget *self,
+    FolksGroupDetails *group_details)
 {
   EmpathyGroupsWidgetPriv *priv;
 
   g_return_if_fail (EMPATHY_IS_GROUPS_WIDGET (self));
-  g_return_if_fail (groupable == NULL || FOLKS_IS_GROUPS (groupable));
+  g_return_if_fail (
+      group_details == NULL || FOLKS_IS_GROUP_DETAILS (group_details));
 
   priv = GET_PRIV (self);
 
-  if (groupable == priv->groupable)
+  if (group_details == priv->group_details)
     return;
 
-  if (priv->groupable != NULL)
+  if (priv->group_details != NULL)
     {
-      g_signal_handlers_disconnect_by_func (priv->groupable,
-          groupable_group_changed_cb, self);
+      g_signal_handlers_disconnect_by_func (priv->group_details,
+          group_details_group_changed_cb, self);
     }
 
-  tp_clear_object (&priv->groupable);
+  tp_clear_object (&priv->group_details);
 
-  if (groupable != NULL)
+  if (group_details != NULL)
     {
-      priv->groupable = g_object_ref (groupable);
+      priv->group_details = g_object_ref (group_details);
 
-      g_signal_connect (priv->groupable, "group-changed",
-          (GCallback) groupable_group_changed_cb, self);
+      g_signal_connect (priv->group_details, "group-changed",
+          (GCallback) group_details_group_changed_cb, self);
 
       populate_data (self);
     }
 
-  g_object_notify (G_OBJECT (self), "groupable");
+  g_object_notify (G_OBJECT (self), "group-details");
 }