aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-05-28 20:22:50 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2012-06-14 15:21:49 +0800
commit043d63caaf16e09c291f0dcd28068e0efbf97bdb (patch)
treef5a8bb5d2ba64939a6f586cca354ff24a0506446 /libempathy-gtk
parentb7e72c53ffe6a02482b57e5ee565881b313e4d43 (diff)
downloadgsoc2013-empathy-043d63caaf16e09c291f0dcd28068e0efbf97bdb.tar.gz
gsoc2013-empathy-043d63caaf16e09c291f0dcd28068e0efbf97bdb.tar.zst
gsoc2013-empathy-043d63caaf16e09c291f0dcd28068e0efbf97bdb.zip
add empathy-roster-group
Diffstat (limited to 'libempathy-gtk')
-rw-r--r--libempathy-gtk/Makefile.am2
-rw-r--r--libempathy-gtk/empathy-roster-group.c196
-rw-r--r--libempathy-gtk/empathy-roster-group.h62
-rw-r--r--libempathy-gtk/empathy-roster-view.c3
4 files changed, 263 insertions, 0 deletions
diff --git a/libempathy-gtk/Makefile.am b/libempathy-gtk/Makefile.am
index 7a9d01dfa..ac3d3c1c6 100644
--- a/libempathy-gtk/Makefile.am
+++ b/libempathy-gtk/Makefile.am
@@ -79,6 +79,7 @@ libempathy_gtk_handwritten_source = \
empathy-presence-chooser.c \
empathy-protocol-chooser.c \
empathy-roster-contact.c \
+ empathy-roster-group.c \
empathy-roster-view.c \
empathy-search-bar.c \
empathy-share-my-desktop.c \
@@ -149,6 +150,7 @@ libempathy_gtk_headers = \
empathy-presence-chooser.h \
empathy-protocol-chooser.h \
empathy-roster-contact.h \
+ empathy-roster-group.h \
empathy-roster-view.h \
empathy-search-bar.h \
empathy-share-my-desktop.h \
diff --git a/libempathy-gtk/empathy-roster-group.c b/libempathy-gtk/empathy-roster-group.c
new file mode 100644
index 000000000..bffd6a80d
--- /dev/null
+++ b/libempathy-gtk/empathy-roster-group.c
@@ -0,0 +1,196 @@
+#include "config.h"
+
+#include "empathy-roster-group.h"
+
+#include <telepathy-glib/telepathy-glib.h>
+
+G_DEFINE_TYPE (EmpathyRosterGroup, empathy_roster_group, GTK_TYPE_EXPANDER)
+
+enum
+{
+ PROP_NAME = 1,
+ N_PROPS
+};
+
+/*
+enum
+{
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL];
+*/
+
+struct _EmpathyRosterGroupPriv
+{
+ gchar *name;
+
+ /* Widgets associated with this group. EmpathyRosterGroup is not responsible
+ * of packing/displaying these widgets. This hash table is a just a set
+ * to keep track of them. */
+ GHashTable *widgets;
+};
+
+static void
+empathy_roster_group_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyRosterGroup *self = EMPATHY_ROSTER_GROUP (object);
+
+ switch (property_id)
+ {
+ case PROP_NAME:
+ g_value_set_string (value, self->priv->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_roster_group_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyRosterGroup *self = EMPATHY_ROSTER_GROUP (object);
+
+ switch (property_id)
+ {
+ case PROP_NAME:
+ g_assert (self->priv->name == NULL); /* construct-only */
+ self->priv->name = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_roster_group_constructed (GObject *object)
+{
+ EmpathyRosterGroup *self = EMPATHY_ROSTER_GROUP (object);
+ void (*chain_up) (GObject *) =
+ ((GObjectClass *) empathy_roster_group_parent_class)->constructed;
+ gchar *tmp;
+
+ if (chain_up != NULL)
+ chain_up (object);
+
+ g_assert (self->priv->name != NULL);
+
+ tmp = g_strdup_printf ("<b>%s</b>", self->priv->name);
+ gtk_expander_set_label (GTK_EXPANDER (self), tmp);
+ g_free (tmp);
+}
+
+static void
+empathy_roster_group_dispose (GObject *object)
+{
+ EmpathyRosterGroup *self = EMPATHY_ROSTER_GROUP (object);
+ void (*chain_up) (GObject *) =
+ ((GObjectClass *) empathy_roster_group_parent_class)->dispose;
+
+ tp_clear_pointer (&self->priv->widgets, g_hash_table_unref);
+
+ if (chain_up != NULL)
+ chain_up (object);
+}
+
+static void
+empathy_roster_group_finalize (GObject *object)
+{
+ EmpathyRosterGroup *self = EMPATHY_ROSTER_GROUP (object);
+ void (*chain_up) (GObject *) =
+ ((GObjectClass *) empathy_roster_group_parent_class)->finalize;
+
+ g_free (self->priv->name);
+
+ if (chain_up != NULL)
+ chain_up (object);
+}
+
+static void
+empathy_roster_group_class_init (
+ EmpathyRosterGroupClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GParamSpec *spec;
+
+ oclass->get_property = empathy_roster_group_get_property;
+ oclass->set_property = empathy_roster_group_set_property;
+ oclass->constructed = empathy_roster_group_constructed;
+ oclass->dispose = empathy_roster_group_dispose;
+ oclass->finalize = empathy_roster_group_finalize;
+
+ spec = g_param_spec_string ("name", "Name",
+ "Group name",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (oclass, PROP_NAME, spec);
+
+ g_type_class_add_private (klass, sizeof (EmpathyRosterGroupPriv));
+}
+
+static void
+empathy_roster_group_init (EmpathyRosterGroup *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_ROSTER_GROUP, EmpathyRosterGroupPriv);
+
+ self->priv->widgets = g_hash_table_new (NULL, NULL);
+}
+
+GtkWidget *
+empathy_roster_group_new (const gchar *name)
+{
+ return g_object_new (EMPATHY_TYPE_ROSTER_GROUP,
+ "name", name,
+ "use-markup", TRUE,
+ "expanded", TRUE,
+ NULL);
+}
+
+const gchar *
+empathy_roster_group_get_name (EmpathyRosterGroup *self)
+{
+ return self->priv->name;
+}
+
+guint
+empathy_roster_group_add_widget (EmpathyRosterGroup *self,
+ GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ g_hash_table_add (self->priv->widgets, widget);
+
+ return empathy_roster_group_get_widgets_count (self);
+}
+
+guint
+empathy_roster_group_remove_widget (EmpathyRosterGroup *self,
+ GtkWidget *widget)
+{
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), 0);
+
+ g_hash_table_remove (self->priv->widgets, widget);
+
+ return empathy_roster_group_get_widgets_count (self);
+}
+
+guint
+empathy_roster_group_get_widgets_count (EmpathyRosterGroup *self)
+{
+ return g_hash_table_size (self->priv->widgets);
+}
+
+GList *
+empathy_roster_group_get_widgets (EmpathyRosterGroup *self)
+{
+ return g_hash_table_get_keys (self->priv->widgets);
+}
diff --git a/libempathy-gtk/empathy-roster-group.h b/libempathy-gtk/empathy-roster-group.h
new file mode 100644
index 000000000..314ed3b58
--- /dev/null
+++ b/libempathy-gtk/empathy-roster-group.h
@@ -0,0 +1,62 @@
+#ifndef __EMPATHY_ROSTER_GROUP_H__
+#define __EMPATHY_ROSTER_GROUP_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EmpathyRosterGroup EmpathyRosterGroup;
+typedef struct _EmpathyRosterGroupClass EmpathyRosterGroupClass;
+typedef struct _EmpathyRosterGroupPriv EmpathyRosterGroupPriv;
+
+struct _EmpathyRosterGroupClass
+{
+ /*<private>*/
+ GtkExpanderClass parent_class;
+};
+
+struct _EmpathyRosterGroup
+{
+ /*<private>*/
+ GtkExpander parent;
+ EmpathyRosterGroupPriv *priv;
+};
+
+GType empathy_roster_group_get_type (void);
+
+/* TYPE MACROS */
+#define EMPATHY_TYPE_ROSTER_GROUP \
+ (empathy_roster_group_get_type ())
+#define EMPATHY_ROSTER_GROUP(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), \
+ EMPATHY_TYPE_ROSTER_GROUP, \
+ EmpathyRosterGroup))
+#define EMPATHY_ROSTER_GROUP_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), \
+ EMPATHY_TYPE_ROSTER_GROUP, \
+ EmpathyRosterGroupClass))
+#define EMPATHY_IS_ROSTER_GROUP(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), \
+ EMPATHY_TYPE_ROSTER_GROUP))
+#define EMPATHY_IS_ROSTER_GROUP_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), \
+ EMPATHY_TYPE_ROSTER_GROUP))
+#define EMPATHY_ROSTER_GROUP_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ EMPATHY_TYPE_ROSTER_GROUP, \
+ EmpathyRosterGroupClass))
+
+GtkWidget * empathy_roster_group_new (const gchar *name);
+
+const gchar * empathy_roster_group_get_name (EmpathyRosterGroup *self);
+
+guint empathy_roster_group_add_widget (EmpathyRosterGroup *self,
+ GtkWidget *widget);
+guint empathy_roster_group_remove_widget (EmpathyRosterGroup *self,
+ GtkWidget *widget);
+guint empathy_roster_group_get_widgets_count (EmpathyRosterGroup *self);
+GList * empathy_roster_group_get_widgets (EmpathyRosterGroup *self);
+
+G_END_DECLS
+
+#endif /* #ifndef __EMPATHY_ROSTER_GROUP_H__*/
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c
index fb41dfbe0..0212ee1aa 100644
--- a/libempathy-gtk/empathy-roster-view.c
+++ b/libempathy-gtk/empathy-roster-view.c
@@ -5,6 +5,7 @@
#include <glib/gi18n-lib.h>
#include <libempathy-gtk/empathy-roster-contact.h>
+#include <libempathy-gtk/empathy-roster-group.h>
G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX)
@@ -40,6 +41,8 @@ struct _EmpathyRosterViewPriv
* I prefer to stay coherent in the way this hash is managed.
*/
GHashTable *roster_contacts;
+ /* (gchar *group_name) -> EmpathyRosterGroup (borrowed) */
+ GHashTable *roster_groups;
gboolean show_offline;
gboolean show_groups;