type tree model column correctly

This commit is contained in:
Eric House 2013-01-07 20:51:59 -08:00
parent 76f3bb3413
commit 1cb959c86d

View file

@ -56,18 +56,13 @@ enum { ROW_ITEM, NAME_ITEM, N_ITEMS };
static void static void
tree_selection_changed_cb( GtkTreeSelection* selection, gpointer data ) tree_selection_changed_cb( GtkTreeSelection* selection, gpointer data )
{ {
LOG_FUNC();
GTKGamesGlobals* gg = (GTKGamesGlobals*)data; GTKGamesGlobals* gg = (GTKGamesGlobals*)data;
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
gchar *row;
if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) { if ( gtk_tree_selection_get_selected( selection, &model, &iter ) ) {
gtk_tree_model_get( model, &iter, ROW_ITEM, &row, -1 ); gtk_tree_model_get( model, &iter, ROW_ITEM, &gg->selRow, -1 );
sscanf( row, "%lld", &gg->selRow );
g_print ("You selected row %s (parsed: %lld)\n", row, gg->selRow );
g_free( row );
} }
} }
@ -86,8 +81,8 @@ init_games_list( GTKGamesGlobals* gg )
NAME_ITEM, NULL ); NAME_ITEM, NULL );
gtk_tree_view_append_column( GTK_TREE_VIEW(list), column ); gtk_tree_view_append_column( GTK_TREE_VIEW(list), column );
GtkListStore* store = gtk_list_store_new( N_ITEMS, // G_TYPE_INT64, GtkListStore* store = gtk_list_store_new( N_ITEMS, G_TYPE_INT64,
G_TYPE_STRING, G_TYPE_STRING ); G_TYPE_STRING );
gtk_tree_view_set_model( GTK_TREE_VIEW(list), GTK_TREE_MODEL(store) ); gtk_tree_view_set_model( GTK_TREE_VIEW(list), GTK_TREE_MODEL(store) );
g_object_unref( store ); g_object_unref( store );
@ -106,11 +101,11 @@ add_to_list( GtkWidget* list, sqlite3_int64* rowid, const gchar* str )
GTK_LIST_STORE( gtk_tree_view_get_model(GTK_TREE_VIEW(list))); GTK_LIST_STORE( gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
GtkTreeIter iter; GtkTreeIter iter;
gtk_list_store_append( store, &iter ); gtk_list_store_append( store, &iter );
XP_LOGF( "adding %lld, %s", *rowid, str ); /* XP_LOGF( "adding %lld, %s", *rowid, str ); */
gchar buf[16]; /* gchar buf[16]; */
snprintf( buf, sizeof(buf), "%lld", *rowid ); /* snprintf( buf, sizeof(buf), "%lld", *rowid ); */
gtk_list_store_set( store, &iter, gtk_list_store_set( store, &iter,
ROW_ITEM, buf, ROW_ITEM, *rowid,
NAME_ITEM, str, NAME_ITEM, str,
-1 ); -1 );
XP_LOGF( "DONE adding" ); XP_LOGF( "DONE adding" );