mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
gtk: add localTurn column; format date
This commit is contained in:
parent
1d1e971120
commit
c4efebad71
3 changed files with 40 additions and 26 deletions
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
||||
/* -*- compile-command: "make MEMDEBUG=TRUE -j5"; -*- */
|
||||
/*
|
||||
* Copyright 2000-2013 by Eric House (xwords@eehouse.org). All rights
|
||||
* Copyright 2000 - 2016 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -54,6 +54,7 @@ openGamesDB( const char* dbName )
|
|||
",connvia VARCHAR(32)"
|
||||
",ended INT(1)"
|
||||
",turn INT(2)"
|
||||
",local INT(1)"
|
||||
",nmoves INT"
|
||||
",seed INT"
|
||||
",gameid INT"
|
||||
|
@ -197,7 +198,8 @@ summarize( CommonGlobals* cGlobals )
|
|||
{
|
||||
XP_S16 nMoves = model_getNMoves( cGlobals->game.model );
|
||||
XP_Bool gameOver = server_getGameIsOver( cGlobals->game.server );
|
||||
XP_S16 turn = server_getCurrentTurn( cGlobals->game.server, NULL );
|
||||
XP_Bool isLocal;
|
||||
XP_S16 turn = server_getCurrentTurn( cGlobals->game.server, &isLocal );
|
||||
XP_U32 lastMoveTime = server_getLastMoveTime( cGlobals->game.server );
|
||||
XP_U16 seed = 0;
|
||||
XP_S16 nMissing = 0;
|
||||
|
@ -243,12 +245,13 @@ summarize( CommonGlobals* cGlobals )
|
|||
}
|
||||
|
||||
const char* fmt = "UPDATE games "
|
||||
" SET room='%s', ended=%d, turn=%d, ntotal=%d, nmissing=%d, nmoves=%d, seed=%d, "
|
||||
" gameid=%d, connvia='%s', lastMoveTime=%d"
|
||||
" SET room='%s', ended=%d, turn=%d, local=%d, ntotal=%d, nmissing=%d, "
|
||||
" nmoves=%d, seed=%d, gameid=%d, connvia='%s', lastMoveTime=%d"
|
||||
" WHERE rowid=%lld";
|
||||
XP_UCHAR buf[256];
|
||||
snprintf( buf, sizeof(buf), fmt, room, gameOver?1:0, turn, nTotal, nMissing,
|
||||
nMoves, seed, gameID, connvia, lastMoveTime, cGlobals->selRow );
|
||||
snprintf( buf, sizeof(buf), fmt, room, gameOver?1:0, turn, isLocal?1:0,
|
||||
nTotal, nMissing, nMoves, seed, gameID, connvia, lastMoveTime,
|
||||
cGlobals->selRow );
|
||||
XP_LOGF( "query: %s", buf );
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
int result = sqlite3_prepare_v2( cGlobals->pDb, buf, -1, &stmt, NULL );
|
||||
|
@ -301,7 +304,7 @@ XP_Bool
|
|||
getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
|
||||
{
|
||||
XP_Bool success = XP_FALSE;
|
||||
const char* fmt = "SELECT room, ended, turn, nmoves, ntotal, nmissing, "
|
||||
const char* fmt = "SELECT room, ended, turn, local, nmoves, ntotal, nmissing, "
|
||||
"seed, connvia, gameid, lastMoveTime, snap "
|
||||
"FROM games WHERE rowid = %lld";
|
||||
XP_UCHAR query[256];
|
||||
|
@ -316,20 +319,21 @@ getGameInfo( sqlite3* pDb, sqlite3_int64 rowid, GameInfo* gib )
|
|||
getColumnText( ppStmt, 0, gib->room, sizeof(gib->room) );
|
||||
gib->gameOver = 1 == sqlite3_column_int( ppStmt, 1 );
|
||||
gib->turn = sqlite3_column_int( ppStmt, 2 );
|
||||
gib->nMoves = sqlite3_column_int( ppStmt, 3 );
|
||||
gib->nTotal = sqlite3_column_int( ppStmt, 4 );
|
||||
gib->nMissing = sqlite3_column_int( ppStmt, 5 );
|
||||
gib->seed = sqlite3_column_int( ppStmt, 6 );
|
||||
getColumnText( ppStmt, 7, gib->conn, sizeof(gib->conn) );
|
||||
gib->gameID = sqlite3_column_int( ppStmt, 8 );
|
||||
gib->lastMoveTime = sqlite3_column_int( ppStmt, 9 );
|
||||
gib->turnLocal = 1 == sqlite3_column_int( ppStmt, 3 );
|
||||
gib->nMoves = sqlite3_column_int( ppStmt, 4 );
|
||||
gib->nTotal = sqlite3_column_int( ppStmt, 5 );
|
||||
gib->nMissing = sqlite3_column_int( ppStmt, 6 );
|
||||
gib->seed = sqlite3_column_int( ppStmt, 7 );
|
||||
getColumnText( ppStmt, 8, gib->conn, sizeof(gib->conn) );
|
||||
gib->gameID = sqlite3_column_int( ppStmt, 9 );
|
||||
gib->lastMoveTime = sqlite3_column_int( ppStmt, 10 );
|
||||
snprintf( gib->name, sizeof(gib->name), "Game %lld", rowid );
|
||||
|
||||
/* Load the snapshot */
|
||||
GdkPixbuf* snap = NULL;
|
||||
const XP_U8* ptr = sqlite3_column_blob( ppStmt, 10 );
|
||||
const XP_U8* ptr = sqlite3_column_blob( ppStmt, 11 );
|
||||
if ( !!ptr ) {
|
||||
int size = sqlite3_column_bytes( ppStmt, 10 );
|
||||
int size = sqlite3_column_bytes( ppStmt, 11 );
|
||||
/* Skip the version that's written in */
|
||||
ptr += sizeof(XP_U16); size -= sizeof(XP_U16);
|
||||
GInputStream* istr = g_memory_input_stream_new_from_data( ptr, size, NULL );
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
||||
/* -*- compile-command: "make MEMDEBUG=TRUE -j5"; -*- */
|
||||
/*
|
||||
* Copyright 2000-2012 by Eric House (xwords@eehouse.org). All rights
|
||||
* Copyright 2000 - 2016 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -35,6 +35,7 @@ typedef struct _GameInfo {
|
|||
XP_U32 gameID;
|
||||
XP_S16 nMoves;
|
||||
XP_Bool gameOver;
|
||||
XP_Bool turnLocal;
|
||||
XP_S16 turn;
|
||||
XP_U16 nTotal;
|
||||
XP_S16 nMissing;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
||||
/* -*- compile-command: "make MEMDEBUG=TRUE -j5"; -*- */
|
||||
/*
|
||||
* Copyright 2000-2013 by Eric House (xwords@eehouse.org). All rights
|
||||
* Copyright 2000 - 2016 by Eric House (xwords@eehouse.org). All rights
|
||||
* reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
|
@ -76,8 +76,8 @@ findOpenGame( const GtkAppGlobals* apg, sqlite3_int64 rowid )
|
|||
}
|
||||
|
||||
enum { ROW_ITEM, ROW_THUMB, NAME_ITEM, ROOM_ITEM, GAMEID_ITEM, SEED_ITEM,
|
||||
CONN_ITEM, OVER_ITEM, TURN_ITEM, NMOVES_ITEM, NTOTAL_ITEM, MISSING_ITEM,
|
||||
LASTTURN_ITEM, N_ITEMS };
|
||||
CONN_ITEM, OVER_ITEM, TURN_ITEM, LOCAL_ITEM, NMOVES_ITEM, NTOTAL_ITEM,
|
||||
MISSING_ITEM, LASTTURN_ITEM, N_ITEMS };
|
||||
|
||||
static void
|
||||
foreachProc( GtkTreeModel* model, GtkTreePath* XP_UNUSED(path),
|
||||
|
@ -169,6 +169,7 @@ init_games_list( GtkAppGlobals* apg )
|
|||
addTextColumn( list, "Conn. via", CONN_ITEM );
|
||||
addTextColumn( list, "Ended", OVER_ITEM );
|
||||
addTextColumn( list, "Turn", TURN_ITEM );
|
||||
addTextColumn( list, "Local", LOCAL_ITEM );
|
||||
addTextColumn( list, "NMoves", NMOVES_ITEM );
|
||||
addTextColumn( list, "NTotal", NTOTAL_ITEM );
|
||||
addTextColumn( list, "NMissing", MISSING_ITEM );
|
||||
|
@ -184,10 +185,11 @@ init_games_list( GtkAppGlobals* apg )
|
|||
G_TYPE_STRING, /* CONN_ITEM */
|
||||
G_TYPE_BOOLEAN, /* OVER_ITEM */
|
||||
G_TYPE_INT, /* TURN_ITEM */
|
||||
G_TYPE_STRING, /* LOCAL_ITEM */
|
||||
G_TYPE_INT, /* NMOVES_ITEM */
|
||||
G_TYPE_INT, /* NTOTAL_ITEM */
|
||||
G_TYPE_INT, /* MISSING_ITEM */
|
||||
G_TYPE_INT /* LASTTURN_ITEM */
|
||||
G_TYPE_STRING /* LASTTURN_ITEM */
|
||||
);
|
||||
gtk_tree_view_set_model( GTK_TREE_VIEW(list), GTK_TREE_MODEL(store) );
|
||||
g_object_unref( store );
|
||||
|
@ -224,6 +226,11 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew,
|
|||
}
|
||||
}
|
||||
}
|
||||
gchar* localString = 0 <= gib->turn ? gib->turnLocal ? "YES"
|
||||
: "NO" : "";
|
||||
|
||||
GTimeVal timeval = { tv_sec: gib->lastMoveTime, tv_usec: 0 };
|
||||
gchar* timeStr = g_time_val_to_iso8601( &timeval );
|
||||
gtk_list_store_set( store, &iter,
|
||||
ROW_ITEM, rowid,
|
||||
ROW_THUMB, gib->snap,
|
||||
|
@ -232,13 +239,15 @@ add_to_list( GtkWidget* list, sqlite3_int64 rowid, XP_Bool isNew,
|
|||
GAMEID_ITEM, gib->gameID,
|
||||
SEED_ITEM, gib->seed,
|
||||
CONN_ITEM, gib->conn,
|
||||
OVER_ITEM, gib->gameOver,
|
||||
TURN_ITEM, gib->turn,
|
||||
OVER_ITEM, gib->gameOver,
|
||||
LOCAL_ITEM, localString,
|
||||
NMOVES_ITEM, gib->nMoves,
|
||||
NTOTAL_ITEM, gib->nTotal,
|
||||
MISSING_ITEM, gib->nMissing,
|
||||
LASTTURN_ITEM, gib->lastMoveTime,
|
||||
LASTTURN_ITEM, timeStr,
|
||||
-1 );
|
||||
g_free( timeStr );
|
||||
XP_LOGF( "DONE adding" );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue