2 #include "empathy-roster-group.h"
4 #include <telepathy-glib/telepathy-glib.h>
6 G_DEFINE_TYPE (EmpathyRosterGroup
, empathy_roster_group
, GTK_TYPE_LIST_BOX_ROW
)
21 static guint signals[LAST_SIGNAL];
24 struct _EmpathyRosterGroupPriv
29 /* Widgets associated with this group. EmpathyRosterGroup is not responsible
30 * of packing/displaying these widgets. This hash table is a just a set
31 * to keep track of them. */
36 empathy_roster_group_get_property (GObject
*object
,
41 EmpathyRosterGroup
*self
= EMPATHY_ROSTER_GROUP (object
);
46 g_value_set_string (value
, self
->priv
->name
);
49 g_value_set_string (value
, self
->priv
->icon_name
);
52 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
58 empathy_roster_group_set_property (GObject
*object
,
63 EmpathyRosterGroup
*self
= EMPATHY_ROSTER_GROUP (object
);
68 g_assert (self
->priv
->name
== NULL
); /* construct-only */
69 self
->priv
->name
= g_value_dup_string (value
);
72 g_assert (self
->priv
->icon_name
== NULL
); /* construct-only */
73 self
->priv
->icon_name
= g_value_dup_string (value
);
76 G_OBJECT_WARN_INVALID_PROPERTY_ID (object
, property_id
, pspec
);
82 empathy_roster_group_constructed (GObject
*object
)
84 EmpathyRosterGroup
*self
= EMPATHY_ROSTER_GROUP (object
);
85 void (*chain_up
) (GObject
*) =
86 ((GObjectClass
*) empathy_roster_group_parent_class
)->constructed
;
88 GtkWidget
*box
, *label
;
93 g_assert (self
->priv
->name
!= NULL
);
95 box
= gtk_box_new (GTK_ORIENTATION_HORIZONTAL
, 6);
98 if (!tp_str_empty (self
->priv
->icon_name
))
102 icon
= gtk_image_new_from_icon_name (self
->priv
->icon_name
,
106 gtk_box_pack_start (GTK_BOX (box
), icon
, FALSE
, FALSE
, 0);
110 tmp
= g_strdup_printf ("<b>%s</b>", self
->priv
->name
);
111 label
= gtk_label_new (tmp
);
114 gtk_label_set_use_markup (GTK_LABEL (label
), TRUE
);
115 gtk_box_pack_start (GTK_BOX (box
), label
, TRUE
, TRUE
, 0);
117 gtk_widget_show_all (box
);
119 gtk_expander_set_label_widget (self
->expander
, box
);
123 empathy_roster_group_dispose (GObject
*object
)
125 EmpathyRosterGroup
*self
= EMPATHY_ROSTER_GROUP (object
);
126 void (*chain_up
) (GObject
*) =
127 ((GObjectClass
*) empathy_roster_group_parent_class
)->dispose
;
129 tp_clear_pointer (&self
->priv
->widgets
, g_hash_table_unref
);
131 if (chain_up
!= NULL
)
136 empathy_roster_group_finalize (GObject
*object
)
138 EmpathyRosterGroup
*self
= EMPATHY_ROSTER_GROUP (object
);
139 void (*chain_up
) (GObject
*) =
140 ((GObjectClass
*) empathy_roster_group_parent_class
)->finalize
;
142 g_free (self
->priv
->name
);
143 g_free (self
->priv
->icon_name
);
145 if (chain_up
!= NULL
)
150 empathy_roster_group_class_init (
151 EmpathyRosterGroupClass
*klass
)
153 GObjectClass
*oclass
= G_OBJECT_CLASS (klass
);
156 oclass
->get_property
= empathy_roster_group_get_property
;
157 oclass
->set_property
= empathy_roster_group_set_property
;
158 oclass
->constructed
= empathy_roster_group_constructed
;
159 oclass
->dispose
= empathy_roster_group_dispose
;
160 oclass
->finalize
= empathy_roster_group_finalize
;
162 spec
= g_param_spec_string ("name", "Name",
165 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
);
166 g_object_class_install_property (oclass
, PROP_NAME
, spec
);
168 spec
= g_param_spec_string ("icon", "Icon",
171 G_PARAM_READWRITE
| G_PARAM_CONSTRUCT_ONLY
| G_PARAM_STATIC_STRINGS
);
172 g_object_class_install_property (oclass
, PROP_ICON
, spec
);
174 g_type_class_add_private (klass
, sizeof (EmpathyRosterGroupPriv
));
178 empathy_roster_group_init (EmpathyRosterGroup
*self
)
180 self
->priv
= G_TYPE_INSTANCE_GET_PRIVATE (self
,
181 EMPATHY_TYPE_ROSTER_GROUP
, EmpathyRosterGroupPriv
);
183 self
->priv
->widgets
= g_hash_table_new (NULL
, NULL
);
185 self
->expander
= GTK_EXPANDER (gtk_expander_new (NULL
));
186 gtk_expander_set_use_markup (self
->expander
, TRUE
);
187 gtk_expander_set_expanded (self
->expander
, TRUE
);
188 gtk_widget_show (GTK_WIDGET (self
->expander
));
190 gtk_container_add (GTK_CONTAINER (self
), GTK_WIDGET (self
->expander
));
194 empathy_roster_group_new (const gchar
*name
,
197 return g_object_new (EMPATHY_TYPE_ROSTER_GROUP
,
204 empathy_roster_group_get_name (EmpathyRosterGroup
*self
)
206 return self
->priv
->name
;
210 empathy_roster_group_add_widget (EmpathyRosterGroup
*self
,
213 g_return_val_if_fail (GTK_IS_WIDGET (widget
), 0);
215 g_hash_table_add (self
->priv
->widgets
, widget
);
217 return empathy_roster_group_get_widgets_count (self
);
221 empathy_roster_group_remove_widget (EmpathyRosterGroup
*self
,
224 g_return_val_if_fail (GTK_IS_WIDGET (widget
), 0);
226 g_hash_table_remove (self
->priv
->widgets
, widget
);
228 return empathy_roster_group_get_widgets_count (self
);
232 empathy_roster_group_get_widgets_count (EmpathyRosterGroup
*self
)
234 return g_hash_table_size (self
->priv
->widgets
);
238 empathy_roster_group_get_widgets (EmpathyRosterGroup
*self
)
240 return g_hash_table_get_keys (self
->priv
->widgets
);