All pastes #47113 Raw Edit

Someone

public c v1 · immutable
#47113 ·published 2006-03-27 03:02 UTC
rendered paste body
#include <gtk/gtk.h>#include <gtk/gtksignal.h>#include <gtk/gtktreeview.h>#include <gtk/gtktreestore.h>#include "gmroster.h"enum {  ADDENTRY_SIGNAL,  DELENTRY_SIGNAL,  LAST_SIGNAL};enum {  COLUMN_PIXBUF,  COLUMN_PIXBUF_VISIBLE,  COLUMN_NAME,  COLUMN_WEIGHT,  NUM_COLUMS_ENTRIES};static voidgmroster_class_init (GMRosterClass* klass);static voidgmroster_init (GMRoster* roster);gbooleangmroaster_entry_exists (GMRoster* roster, GMPseudoContact *contact);voidgmroster_addgroup (GMRoster* roster, gchar * groupname);gbooleangmroster_group_exists (GMRoster* roster, gchar * groupname);voidgmroster_debug_dump_group_list (GMRoster* roster);static guint gmroster_signals [LAST_SIGNAL] = { 0 };GTypegmroster_get_type (void) {  static GType gmroster_type = 0;  if (!gmroster_type) {    static const GTypeInfo gmroster_info =      {	sizeof (GMRosterClass),	NULL,	NULL,	(GClassInitFunc) gmroster_class_init,	NULL,	NULL,	sizeof (GMRoster),	0,	(GInstanceInitFunc) gmroster_init,      };    gmroster_type =      g_type_register_static (GTK_TYPE_TREE_VIEW,			      "GMRoster",			      &gmroster_info, 0);  }  return gmroster_type;}static voidgmroster_class_init (GMRosterClass* klass) {}static voidgmroster_init (GMRoster* roster) {  GtkTreeStore* model = NULL;  GtkCellRenderer *cell = NULL;  GtkTreeSelection *selection = NULL;  GtkTreeViewColumn *column = NULL;  /* initialize the lists for groups and contacts to NULL */  roster->groups = NULL;  roster->contacts = NULL;  model = gtk_tree_store_new (NUM_COLUMS_ENTRIES,			      GDK_TYPE_PIXBUF,			      G_TYPE_INT,			      G_TYPE_STRING,			      G_TYPE_INT);  gtk_tree_view_set_model (&roster->treeview,			   GTK_TREE_MODEL (model));  gtk_tree_view_set_headers_visible (&roster->treeview, FALSE);  column = gtk_tree_view_column_new ();  cell = gtk_cell_renderer_pixbuf_new ();  gtk_tree_view_column_pack_start (column, cell, FALSE);  gtk_tree_view_column_set_attributes (column, cell,				       "pixbuf", COLUMN_PIXBUF,				       "visible", COLUMN_PIXBUF_VISIBLE,				       NULL);  cell = gtk_cell_renderer_text_new ();  gtk_tree_view_column_pack_start (column, cell, FALSE);  gtk_tree_view_column_set_attributes (column, cell,				       "text", COLUMN_NAME,				       "weight", COLUMN_WEIGHT,				       NULL);  gtk_tree_view_append_column (&roster->treeview,			       GTK_TREE_VIEW_COLUMN (column));}GtkWidget*gmroster_new (void) {  return GTK_WIDGET (g_object_new (gmroster_get_type (), NULL));}gbooleangmroaster_entry_exists (GMRoster* roster, GMPseudoContact* contact) {  return FALSE;}voidgmroster_addgroup (GMRoster* roster, gchar* groupname) {  GtkTreeModel* model;  GtkTreeIter iter;  g_return_if_fail (roster != NULL);  model =    gtk_tree_view_get_model (&roster->treeview);  g_return_if_fail (model != NULL);  /* append the new group name to our "groups" list */  g_message ("appending \"%s\" to groups list", groupname);  roster->groups = g_slist_append (roster->groups, (gpointer) groupname);  gmroster_debug_dump_group_list (roster);    gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);  gtk_tree_store_set (GTK_TREE_STORE (model),		      &iter,		      COLUMN_NAME, groupname,		      COLUMN_PIXBUF_VISIBLE, FALSE,		      COLUMN_WEIGHT, PANGO_WEIGHT_BOLD,		      -1);}gbooleangmroster_group_exists (GMRoster* roster, gchar* groupname) {  gchar* comparestr = NULL;  gboolean found = FALSE;  GSList* groups_iter;  g_message ("GROUP_EXISTS");  gmroster_debug_dump_group_list (roster);  /* if the list is empty, I guess we can assume that the group   * isn't in the list... */  if (!roster->groups) return FALSE;  /*  for (groups_iter = roster->groups;       groups_iter != NULL;       groups_iter = g_slist_next (groups_iter)) {    comparestr = (gchar*) groups_iter->data;    g_message ("Comparing \"%s\" to \"%s\"", groupname, comparestr);    if (g_ascii_strcasecmp (comparestr, groupname) == 0) found = TRUE;    comparestr = NULL;  }  g_message ("\"%s\" was %s", groupname, found?"found":"not found"); */  return found;}voidgmroster_debug_dump_group_list (GMRoster* roster) {  GSList* groups_iter;  gint index = 0;  gchar* somestr = NULL;  for (groups_iter = roster->groups;       groups_iter != NULL;       groups_iter = g_slist_next (groups_iter), index++) {    somestr = (gchar*) groups_iter->data;    g_message ("gmroster_debug_dump_group_list: groups[%d]=\"%s\"", index, somestr);    somestr = NULL;  }}voidgmroster_addentry (GMRoster* roster, GMPseudoContact* contact) {  gchar* groupname = NULL;  GtkTreeModel* model = NULL;   model = gtk_tree_view_get_model (&roster->treeview);  g_return_if_fail (roster != NULL);  g_return_if_fail (contact != NULL);  g_return_if_fail (model != NULL);  groupname = g_strdup (contact->group);  gmroster_addgroup (roster, groupname);  g_free (groupname);}voidgmroster_delentry (GMRoster * roster, GMPseudoContact *contact) {}