empathy r2805 - trunk/libempathy-gtk
- From: xclaesse svn gnome org
- To: svn-commits-list gnome org
- Subject: empathy r2805 - trunk/libempathy-gtk
- Date: Fri, 10 Apr 2009 16:56:03 +0000 (UTC)
Author: xclaesse
Date: Fri Apr 10 16:56:03 2009
New Revision: 2805
URL: http://svn.gnome.org/viewvc/empathy?rev=2805&view=rev
Log:
Initial empathy_contact_selector_set_visible implementation.
Signed-off-by: Jonny Lamb <jonny lamb collabora co uk>
Modified:
trunk/libempathy-gtk/empathy-contact-selector.c
trunk/libempathy-gtk/empathy-contact-selector.h
Modified: trunk/libempathy-gtk/empathy-contact-selector.c
==============================================================================
--- trunk/libempathy-gtk/empathy-contact-selector.c (original)
+++ trunk/libempathy-gtk/empathy-contact-selector.c Fri Apr 10 16:56:03 2009
@@ -45,6 +45,7 @@
{
EmpathyContactList *contact_list;
EmpathyContactListStore *store;
+ GtkTreeModel *model;
gboolean dispose_run;
} EmpathyContactSelectorPriv;
@@ -52,17 +53,17 @@
EmpathyContactSelector *selector);
static guint
-contact_selector_get_number_online_contacts (GtkTreeStore *store)
+contact_selector_get_number_online_contacts (GtkTreeModel *model)
{
GtkTreeIter tmp_iter;
gboolean is_online;
guint number_online_contacts = 0;
gboolean ok;
- for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &tmp_iter);
- ok; ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &tmp_iter))
+ for (ok = gtk_tree_model_get_iter_first (model, &tmp_iter);
+ ok; ok = gtk_tree_model_iter_next (model, &tmp_iter))
{
- gtk_tree_model_get (GTK_TREE_MODEL (store),
+ gtk_tree_model_get (model,
&tmp_iter, EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE,
&is_online, -1);
if (is_online)
@@ -73,7 +74,7 @@
}
static gboolean
-contact_selector_get_iter_for_blank_contact (GtkTreeStore *store,
+contact_selector_get_iter_for_blank_contact (GtkTreeModel *model,
GtkTreeIter *blank_iter)
{
GtkTreeIter tmp_iter;
@@ -81,10 +82,10 @@
gboolean is_present = FALSE;
gboolean ok;
- for (ok = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &tmp_iter);
- ok; ok = gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &tmp_iter))
+ for (ok = gtk_tree_model_get_iter_first (model, &tmp_iter);
+ ok; ok = gtk_tree_model_iter_next (model, &tmp_iter))
{
- gtk_tree_model_get (GTK_TREE_MODEL (store),
+ gtk_tree_model_get (model,
&tmp_iter, EMPATHY_CONTACT_LIST_STORE_COL_CONTACT,
&tmp_contact, -1);
if (tmp_contact == NULL)
@@ -106,7 +107,7 @@
GtkTreeIter blank_iter;
gtk_tree_store_insert_with_values (
- GTK_TREE_STORE (priv->store),&blank_iter, NULL, 0,
+ GTK_TREE_STORE (priv->store), &blank_iter, NULL, 0,
EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, NULL,
EMPATHY_CONTACT_LIST_STORE_COL_NAME, (_("Select a contact")),
EMPATHY_CONTACT_LIST_STORE_COL_IS_ONLINE, FALSE, -1);
@@ -123,8 +124,7 @@
EmpathyContactSelectorPriv *priv = GET_PRIV (selector);
GtkTreeIter blank_iter;
- if (contact_selector_get_iter_for_blank_contact (
- GTK_TREE_STORE (priv->store), &blank_iter))
+ if (contact_selector_get_iter_for_blank_contact (priv->model, &blank_iter))
gtk_tree_store_remove (GTK_TREE_STORE (priv->store), &blank_iter);
}
@@ -134,8 +134,7 @@
EmpathyContactSelectorPriv *priv = GET_PRIV (selector);
guint number_online_contacts;
- number_online_contacts = contact_selector_get_number_online_contacts (
- GTK_TREE_STORE (priv->store));
+ number_online_contacts = contact_selector_get_number_online_contacts (priv->model);
if (number_online_contacts != 0)
gtk_widget_set_sensitive (GTK_WIDGET (selector), TRUE);
@@ -202,8 +201,9 @@
G_CALLBACK (contact_selector_manage_blank_contact),
contact_selector);
- gtk_combo_box_set_model (GTK_COMBO_BOX (contact_selector),
- GTK_TREE_MODEL (priv->store));
+ priv->model = gtk_tree_model_filter_new (GTK_TREE_MODEL (priv->store), NULL);
+
+ gtk_combo_box_set_model (GTK_COMBO_BOX (contact_selector), priv->model);
gtk_widget_set_sensitive (GTK_WIDGET (contact_selector), FALSE);
renderer = gtk_cell_renderer_pixbuf_new ();
@@ -289,6 +289,12 @@
priv->contact_list = NULL;
}
+ if (priv->model)
+ {
+ g_object_unref (priv->model);
+ priv->model = NULL;
+ }
+
if (priv->store)
{
g_object_unref (priv->store);
@@ -337,8 +343,60 @@
if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (selector), &iter))
return NULL;
- gtk_tree_model_get (GTK_TREE_MODEL (priv->store), &iter,
+ gtk_tree_model_get (priv->model, &iter,
EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact, -1);
return contact;
}
+
+typedef struct
+{
+ EmpathyContactSelectorFilterFunc func;
+ gpointer user_data;
+} FilterData;
+
+static void
+filter_data_free (gpointer data)
+{
+ g_slice_free (FilterData, data);
+}
+
+static gboolean
+contact_selector_filter_visible_func (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer user_data)
+{
+ EmpathyContact *contact;
+ gboolean visible = FALSE;
+ FilterData *data = (FilterData *) user_data;
+
+ gtk_tree_model_get (model, iter, 0, &contact, -1);
+
+ if (contact != NULL)
+ {
+ visible = data->func(contact, data->user_data);
+
+ g_object_unref (contact);
+ }
+
+ return visible;
+
+}
+
+void
+empathy_contact_selector_set_visible (EmpathyContactSelector *selector,
+ EmpathyContactSelectorFilterFunc func,
+ gpointer user_data)
+{
+ EmpathyContactSelectorPriv *priv = GET_PRIV (selector);
+ FilterData *data;
+
+ data = g_slice_new0 (FilterData);
+ data->func = func;
+ data->user_data = user_data;
+
+ gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (priv->model),
+ contact_selector_filter_visible_func, data, filter_data_free);
+
+ gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->model));
+}
Modified: trunk/libempathy-gtk/empathy-contact-selector.h
==============================================================================
--- trunk/libempathy-gtk/empathy-contact-selector.h (original)
+++ trunk/libempathy-gtk/empathy-contact-selector.h Fri Apr 10 16:56:03 2009
@@ -63,6 +63,11 @@
EmpathyContact * empathy_contact_selector_dup_selected (EmpathyContactSelector *selector);
+typedef gboolean (*EmpathyContactSelectorFilterFunc) (EmpathyContact *contact, gpointer user_data);
+
+void empathy_contact_selector_set_visible (EmpathyContactSelector *selector,
+ EmpathyContactSelectorFilterFunc func, gpointer user_data);
+
G_END_DECLS
#endif /* __EMPATHY_CONTACT_SELECTOR_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]