summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--test.c6
-rw-r--r--test2.c20
-rw-r--r--tp-gtk-contact-selector.c99
-rw-r--r--tp-gtk-contact-selector.h2
5 files changed, 127 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index fc19e61..44981a8 100644
--- a/Makefile
+++ b/Makefile
@@ -3,5 +3,10 @@ SOURCE = \
tp-gtk-roster-model-filter.c \
tp-gtk-roster-model.c
+all: test test2
+
test: $(SOURCE) test.c
gcc -o $@ -ggdb -O0 `pkg-config --cflags --libs gtk+-2.0 telepathy-glib` $^
+
+test2: $(SOURCE) test2.c
+ gcc -o $@ -ggdb -O0 `pkg-config --cflags --libs gtk+-2.0 telepathy-glib` $^
diff --git a/test.c b/test.c
index faf55a6..7e8f1be 100644
--- a/test.c
+++ b/test.c
@@ -11,6 +11,8 @@ main (int argc, char **argv)
GtkTreeModel *filter = tp_gtk_roster_model_filter_new (
TP_GTK_ROSTER_MODEL (model));
GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget *vbox = gtk_vbox_new (FALSE, 6);
+ GtkWidget *selector = tp_gtk_contact_selector_new (filter);
GtkWidget *treeview = gtk_tree_view_new_with_model (filter);
GtkCellRenderer *renderer;
@@ -30,7 +32,9 @@ main (int argc, char **argv)
"text", TP_GTK_ROSTER_MODEL_IDENTIFIER,
NULL);
- gtk_container_add (GTK_CONTAINER (window), treeview);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_box_pack_start (GTK_BOX (vbox), selector, FALSE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (vbox), treeview, TRUE, TRUE, 0);
gtk_widget_show_all (window);
g_signal_connect_swapped (window, "destroy",
diff --git a/test2.c b/test2.c
new file mode 100644
index 0000000..b035dec
--- /dev/null
+++ b/test2.c
@@ -0,0 +1,20 @@
+#include "tp-gtk-contact-selector.h"
+#include "tp-gtk-roster-model.h"
+#include "tp-gtk-roster-model-filter.h"
+
+int
+main (int argc, char **argv)
+{
+ gtk_init (&argc, &argv);
+
+ GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ GtkWidget *selector = tp_gtk_contact_selector_new (NULL);
+
+ gtk_container_add (GTK_CONTAINER (window), selector);
+ gtk_widget_show_all (window);
+
+ g_signal_connect_swapped (window, "destroy",
+ G_CALLBACK (gtk_main_quit), NULL);
+
+ gtk_main ();
+}
diff --git a/tp-gtk-contact-selector.c b/tp-gtk-contact-selector.c
index 8580b25..a723c77 100644
--- a/tp-gtk-contact-selector.c
+++ b/tp-gtk-contact-selector.c
@@ -10,10 +10,13 @@
*/
#include "tp-gtk-contact-selector.h"
+#include "tp-gtk-roster-model.h"
+#include "tp-gtk-roster-model-filter.h"
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), TP_GTK_TYPE_CONTACT_SELECTOR, TpGTKContactSelectorPrivate))
-G_DEFINE_TYPE (TpGtkContactSelector, tp_gtk_contact_selector, GTK_TYPE_COMBO_BOX_ENTRY);
+G_DEFINE_TYPE (TpGtkContactSelector, tp_gtk_contact_selector,
+ GTK_TYPE_COMBO_BOX_ENTRY);
typedef struct _TpGtkContactSelectorPrivate TpGtkContactSelectorPrivate;
struct _TpGtkContactSelectorPrivate
@@ -24,17 +27,107 @@ static void
tp_gtk_contact_selector_class_init (TpGtkContactSelectorClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ static gboolean style_set = FALSE;
+
+ if (!style_set)
+ {
+ gtk_rc_parse_string (
+ "style \"tp-gtk-contact-selector\" {\n"
+ " GtkComboBox::appears-as-list = 1\n"
+ "}"
+ "class \"TpGtkContactSelector\" style \"tp-gtk-contact-selector\"\n"
+ );
+ style_set = TRUE;
+ }
g_type_class_add_private (gobject_class, sizeof (TpGtkContactSelectorPrivate));
}
static void
+alias_column_data_func (GtkCellLayout *self,
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data)
+{
+ TpGtkRosterModelColumnType type;
+ char *alias, *identifier, *markup;
+
+ gtk_tree_model_get (model, iter,
+ TP_GTK_ROSTER_MODEL_COLUMN_TYPE, &type,
+ TP_GTK_ROSTER_MODEL_ALIAS, &alias,
+ TP_GTK_ROSTER_MODEL_IDENTIFIER, &identifier,
+ -1);
+
+ if (type == TP_GTK_ROSTER_MODEL_COLUMN_TYPE_GROUP)
+ {
+ markup = g_strdup_printf ("<b>%s</b>", alias);
+ }
+ else
+ {
+ markup = g_strdup_printf (
+ "%s\n<span size=\"small\" color=\"darkgray\">%s</span>",
+ alias, identifier);
+ }
+
+ g_object_set (renderer, "markup", markup, NULL);
+
+ g_free (alias);
+ g_free (identifier);
+ g_free (markup);
+}
+
+static void
tp_gtk_contact_selector_init (TpGtkContactSelector *self)
{
+ GtkCellRenderer *renderer;
+
+ /* set up the renderers */
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), renderer, FALSE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), renderer,
+ "icon-name", TP_GTK_ROSTER_MODEL_STATUS_ICON,
+ NULL);
+
+ renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), renderer, TRUE);
+ gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (self), renderer,
+ alias_column_data_func, NULL, NULL);
+
+ renderer = gtk_cell_renderer_pixbuf_new ();
+ gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (self), renderer, FALSE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (self), renderer,
+ "pixbuf", TP_GTK_ROSTER_MODEL_AVATAR,
+ NULL);
}
GtkWidget *
-tp_gtk_contact_selector_new (void)
+tp_gtk_contact_selector_new (GtkTreeModel *model)
{
- return g_object_new (TP_GTK_TYPE_CONTACT_SELECTOR, NULL);
+ GtkWidget *self;
+ GtkTreeModel *filter = NULL;
+
+ g_return_val_if_fail (model == NULL ||
+ TP_GTK_IS_ROSTER_MODEL (model) ||
+ TP_GTK_IS_ROSTER_MODEL_FILTER (model),
+ NULL);
+
+ if (model == NULL)
+ {
+
+ model = tp_gtk_roster_model_new ();
+ filter = tp_gtk_roster_model_filter_new (TP_GTK_ROSTER_MODEL (model));
+ g_object_unref (model);
+
+ model = filter;
+ }
+
+ self = g_object_new (TP_GTK_TYPE_CONTACT_SELECTOR,
+ "model", model,
+ NULL);
+
+ if (filter != NULL)
+ g_object_unref (filter);
+
+ return self;
}
diff --git a/tp-gtk-contact-selector.h b/tp-gtk-contact-selector.h
index 8ac374b..228a03f 100644
--- a/tp-gtk-contact-selector.h
+++ b/tp-gtk-contact-selector.h
@@ -37,7 +37,7 @@ struct _TpGtkContactSelectorClass
};
GType tp_gtk_contact_selector_get_type (void);
-GtkWidget *tp_gtk_contact_selector_new (void);
+GtkWidget *tp_gtk_contact_selector_new (GtkTreeModel *model);
G_END_DECLS