mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
now games are displayed in lists. Next: open them.
This commit is contained in:
parent
8238d45350
commit
a8014a855b
5 changed files with 92 additions and 11 deletions
|
@ -88,3 +88,43 @@ writeToDB( XWStreamCtxt* stream, void* closure )
|
|||
sqlite3_finalize( stmt );
|
||||
}
|
||||
}
|
||||
|
||||
GSList*
|
||||
listGames( GTKGamesGlobals* gg )
|
||||
{
|
||||
GSList* list = NULL;
|
||||
|
||||
sqlite3_stmt *ppStmt;
|
||||
int result = sqlite3_prepare_v2( gg->pDb,
|
||||
"SELECT rowid FROM games ORDER BY rowid", -1,
|
||||
&ppStmt, NULL );
|
||||
XP_ASSERT( SQLITE_OK == result );
|
||||
while ( NULL != ppStmt ) {
|
||||
switch( sqlite3_step( ppStmt ) ) {
|
||||
case SQLITE_ROW: /* have data */
|
||||
{
|
||||
sqlite3_int64* data = g_malloc( sizeof( *data ) );
|
||||
*data = sqlite3_column_int64( ppStmt, 0 );
|
||||
XP_LOGF( "%s: got a row; id=%lld", __func__, *data );
|
||||
list = g_slist_append( list, data );
|
||||
}
|
||||
break;
|
||||
case SQLITE_DONE:
|
||||
sqlite3_finalize( ppStmt );
|
||||
ppStmt = NULL;
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT( 0 );
|
||||
break;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
void
|
||||
getGameName( GTKGamesGlobals* XP_UNUSED(gg), const sqlite3_int64* rowid,
|
||||
XP_UCHAR* buf, XP_U16 len )
|
||||
{
|
||||
snprintf( buf, len, "Game %lld", *rowid );
|
||||
LOG_RETURNF( "%s", buf );
|
||||
}
|
||||
|
|
|
@ -22,7 +22,9 @@
|
|||
#define _GAMESDB_H_
|
||||
|
||||
#include <sqlite3.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "comtypes.h"
|
||||
|
||||
sqlite3* openGamesDB( void );
|
||||
|
@ -30,4 +32,10 @@ void closeGamesDB( sqlite3* dbp );
|
|||
|
||||
void writeToDB( XWStreamCtxt* stream, void* closure );
|
||||
|
||||
/* Return GSList whose data is (ptrs to) rowids */
|
||||
GSList* listGames( GTKGamesGlobals* gg );
|
||||
void getGameName( GTKGamesGlobals* gg, const sqlite3_int64* rowid,
|
||||
XP_UCHAR* buf, XP_U16 len );
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -41,9 +41,9 @@ init_list( GtkWidget* list )
|
|||
}
|
||||
|
||||
static void
|
||||
add_to_list( GtkWidget *list, const gchar *str )
|
||||
add_to_list( GtkWidget* list, const gchar* str )
|
||||
{
|
||||
GtkListStore *store =
|
||||
GtkListStore* store =
|
||||
GTK_LIST_STORE( gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
|
||||
GtkTreeIter iter;
|
||||
gtk_list_store_append( store, &iter );
|
||||
|
|
|
@ -25,26 +25,45 @@
|
|||
#include "gtkboard.h"
|
||||
#include "linuxmain.h"
|
||||
|
||||
enum { ROW_ITEM, N_ITEMS };
|
||||
|
||||
typedef struct _GTKGamesGlobals {
|
||||
sqlite3* pDb;
|
||||
LaunchParams* params;
|
||||
} GTKGamesGlobals;
|
||||
enum { ROW_ITEM, NAME_ITEM, N_ITEMS };
|
||||
|
||||
static void
|
||||
init_games_list( GtkWidget* list )
|
||||
{
|
||||
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
|
||||
GtkTreeViewColumn* column =
|
||||
gtk_tree_view_column_new_with_attributes( "Games", renderer,
|
||||
"row", ROW_ITEM, NULL );
|
||||
gtk_tree_view_column_new_with_attributes( "Row", renderer, "text",
|
||||
ROW_ITEM, NULL );
|
||||
gtk_tree_view_append_column( GTK_TREE_VIEW(list), column );
|
||||
GtkListStore* store = gtk_list_store_new( N_ITEMS, G_TYPE_STRING );
|
||||
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
column = gtk_tree_view_column_new_with_attributes( "Name", renderer, "text",
|
||||
NAME_ITEM, NULL );
|
||||
gtk_tree_view_append_column( GTK_TREE_VIEW(list), column );
|
||||
|
||||
GtkListStore* store = gtk_list_store_new( N_ITEMS, // G_TYPE_INT64,
|
||||
G_TYPE_STRING, G_TYPE_STRING );
|
||||
gtk_tree_view_set_model( GTK_TREE_VIEW(list), GTK_TREE_MODEL(store) );
|
||||
g_object_unref( store );
|
||||
}
|
||||
|
||||
static void
|
||||
add_to_list( GtkWidget* list, sqlite3_int64* rowid, const gchar* str )
|
||||
{
|
||||
GtkListStore* store =
|
||||
GTK_LIST_STORE( gtk_tree_view_get_model(GTK_TREE_VIEW(list)));
|
||||
GtkTreeIter iter;
|
||||
gtk_list_store_append( store, &iter );
|
||||
XP_LOGF( "adding %lld, %s", *rowid, str );
|
||||
gchar buf[16];
|
||||
snprintf( buf, sizeof(buf), "%lld", *rowid );
|
||||
gtk_list_store_set( store, &iter,
|
||||
ROW_ITEM, buf,
|
||||
NAME_ITEM, str,
|
||||
-1 );
|
||||
XP_LOGF( "DONE adding" );
|
||||
}
|
||||
|
||||
static void
|
||||
handle_newgame_button( GtkWidget* XP_UNUSED(widget), void* closure )
|
||||
{
|
||||
|
@ -97,6 +116,15 @@ makeGamesWindow( GTKGamesGlobals* gg )
|
|||
init_games_list( list );
|
||||
gtk_widget_show( list );
|
||||
|
||||
GSList* games = listGames( gg );
|
||||
for ( GSList* iter = games; !!iter; iter = iter->next ) {
|
||||
XP_UCHAR name[128];
|
||||
sqlite3_int64* rowid = (sqlite3_int64*)iter->data;
|
||||
getGameName( gg, rowid, name, VSIZE(name) );
|
||||
add_to_list( list, rowid, name );
|
||||
}
|
||||
g_slist_free( games );
|
||||
|
||||
GtkWidget* hbox = gtk_hbox_new( FALSE, 0 );
|
||||
gtk_widget_show( hbox );
|
||||
gtk_container_add( GTK_CONTAINER(vbox), hbox );
|
||||
|
|
|
@ -209,4 +209,9 @@ struct CommonGlobals {
|
|||
XP_U16 curSaveToken;
|
||||
};
|
||||
|
||||
typedef struct _GTKGamesGlobals {
|
||||
sqlite3* pDb;
|
||||
LaunchParams* params;
|
||||
} GTKGamesGlobals;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue