mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-17 18:12:01 +01:00
rest of what I just meant to commit.
This commit is contained in:
parent
4af30c534c
commit
e0dc83ed70
10 changed files with 217 additions and 109 deletions
|
@ -78,19 +78,21 @@ checkIsText( MemPoolEntry* entry )
|
||||||
{
|
{
|
||||||
unsigned char* txt = (unsigned char*)entry->ptr;
|
unsigned char* txt = (unsigned char*)entry->ptr;
|
||||||
XP_U32 len = entry->size;
|
XP_U32 len = entry->size;
|
||||||
|
char* result = NULL;
|
||||||
|
|
||||||
while ( len-- ) {
|
if ( 0 < len ) {
|
||||||
unsigned char c = *txt++;
|
while ( len-- ) {
|
||||||
if ( c < 32 || c > 127 ) {
|
unsigned char c = *txt++;
|
||||||
if ( len == 0 && c == '\0' ) {
|
if ( c < 32 || c > 127 ) {
|
||||||
return (char*)entry->ptr;
|
if ( len == 0 && c == '\0' ) {
|
||||||
} else {
|
result = (char*)entry->ptr;
|
||||||
return (char*)NULL;
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (char*)NULL;
|
return result;
|
||||||
} /* checkIsText */
|
} /* checkIsText */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
/* -*-mode: compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
||||||
/*
|
/*
|
||||||
* Copyright 2000-2012 by Eric House (xwords@eehouse.org). All rights
|
* Copyright 2000-2013 by Eric House (xwords@eehouse.org). All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -18,10 +18,8 @@
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sqlite3.h>
|
|
||||||
|
|
||||||
#include "comtypes.h"
|
|
||||||
#include "gamesdb.h"
|
#include "gamesdb.h"
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
#define DB_NAME "games.db"
|
#define DB_NAME "games.db"
|
||||||
|
|
||||||
|
@ -51,3 +49,42 @@ closeGamesDB( sqlite3* pDb )
|
||||||
sqlite3_close( pDb );
|
sqlite3_close( pDb );
|
||||||
XP_LOGF( "%s finished", __func__ );
|
XP_LOGF( "%s finished", __func__ );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
writeToDB( XWStreamCtxt* stream, void* closure )
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
CommonGlobals* cGlobals = (CommonGlobals*)closure;
|
||||||
|
sqlite3_int64 rowid = cGlobals->rowid;
|
||||||
|
sqlite3* pDb = cGlobals->pDb;
|
||||||
|
XP_U16 len = stream_getSize( stream );
|
||||||
|
|
||||||
|
sqlite3_stmt* stmt = NULL;
|
||||||
|
if ( 0 == rowid ) { /* new row; need to insert blob first */
|
||||||
|
const char* txt = "INSERT INTO games (game) VALUES (?)";
|
||||||
|
result = sqlite3_prepare_v2( pDb, txt, -1, &stmt, NULL );
|
||||||
|
XP_ASSERT( SQLITE_OK == result );
|
||||||
|
result = sqlite3_bind_zeroblob( stmt, 1 /*col 0 ??*/, len );
|
||||||
|
XP_ASSERT( SQLITE_OK == result );
|
||||||
|
result = sqlite3_step( stmt );
|
||||||
|
XP_ASSERT( SQLITE_DONE == result );
|
||||||
|
|
||||||
|
rowid = sqlite3_last_insert_rowid( pDb );
|
||||||
|
XP_LOGF( "%s: new rowid: %lld", __func__, rowid );
|
||||||
|
cGlobals->rowid = rowid;
|
||||||
|
sqlite3_finalize( stmt );
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlite3_blob* blob;
|
||||||
|
result = sqlite3_blob_open( pDb, "main", "games", "game",
|
||||||
|
rowid, 1 /*flags: writeable*/, &blob );
|
||||||
|
XP_ASSERT( SQLITE_OK == result );
|
||||||
|
const XP_U8* ptr = stream_getPtr( stream );
|
||||||
|
result = sqlite3_blob_write( blob, ptr, len, 0 );
|
||||||
|
XP_ASSERT( SQLITE_OK == result );
|
||||||
|
result = sqlite3_blob_close( blob );
|
||||||
|
XP_ASSERT( SQLITE_OK == result );
|
||||||
|
if ( !!stmt ) {
|
||||||
|
sqlite3_finalize( stmt );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,7 +23,11 @@
|
||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
#include "comtypes.h"
|
||||||
|
|
||||||
sqlite3* openGamesDB( void );
|
sqlite3* openGamesDB( void );
|
||||||
void closeGamesDB( sqlite3* dbp );
|
void closeGamesDB( sqlite3* dbp );
|
||||||
|
|
||||||
|
void writeToDB( XWStreamCtxt* stream, void* closure );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -395,8 +395,6 @@ createOrLoadObjects( GtkAppGlobals* globals )
|
||||||
XP_Bool opened = XP_FALSE;
|
XP_Bool opened = XP_FALSE;
|
||||||
|
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
DeviceRole serverRole = globals->cGlobals.params->serverRole;
|
|
||||||
XP_Bool isServer = serverRole != SERVER_ISCLIENT;
|
|
||||||
#endif
|
#endif
|
||||||
LaunchParams* params = globals->cGlobals.params;
|
LaunchParams* params = globals->cGlobals.params;
|
||||||
|
|
||||||
|
@ -500,15 +498,20 @@ createOrLoadObjects( GtkAppGlobals* globals )
|
||||||
params->gi.allowHintRect = params->allowHintRect;
|
params->gi.allowHintRect = params->allowHintRect;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
if ( params->needsNewGame ) {
|
if ( params->needsNewGame ) {
|
||||||
new_game_impl( globals, XP_FALSE );
|
new_game_impl( globals, XP_FALSE );
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
} else if ( !isServer ) {
|
} else {
|
||||||
XWStreamCtxt* stream =
|
DeviceRole serverRole = globals->cGlobals.params->gi.serverRole;
|
||||||
mem_stream_make( MEMPOOL params->vtMgr, &globals->cGlobals, CHANNEL_NONE,
|
if ( serverRole == SERVER_ISCLIENT ) {
|
||||||
sendOnClose );
|
XWStreamCtxt* stream =
|
||||||
server_initClientConnection( globals->cGlobals.game.server,
|
mem_stream_make( MEMPOOL params->vtMgr,
|
||||||
stream );
|
&globals->cGlobals, CHANNEL_NONE,
|
||||||
|
sendOnClose );
|
||||||
|
server_initClientConnection( globals->cGlobals.game.server,
|
||||||
|
stream );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -670,9 +673,12 @@ handle_client_event( GtkWidget *widget, GdkEventClient *event,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void
|
static void
|
||||||
quit( void )
|
destroy_window( GtkWidget* XP_UNUSED(widget), gpointer data )
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
LOG_FUNC();
|
||||||
|
GtkAppGlobals* globals = (GtkAppGlobals*)data;
|
||||||
|
saveGame( &globals->cGlobals );
|
||||||
|
// gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -786,9 +792,9 @@ new_game_impl( GtkAppGlobals* globals, XP_Bool fireConnDlg )
|
||||||
comms_getInitialAddr( &addr, RELAY_NAME_DEFAULT, RELAY_PORT_DEFAULT );
|
comms_getInitialAddr( &addr, RELAY_NAME_DEFAULT, RELAY_PORT_DEFAULT );
|
||||||
}
|
}
|
||||||
|
|
||||||
success = newGameDialog( globals, &addr, XP_TRUE, fireConnDlg );
|
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
||||||
|
success = newGameDialog( globals, gi, &addr, XP_TRUE, fireConnDlg );
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
||||||
#endif
|
#endif
|
||||||
|
@ -803,22 +809,22 @@ new_game_impl( GtkAppGlobals* globals, XP_Bool fireConnDlg )
|
||||||
if ( !game_reset( MEMPOOL &globals->cGlobals.game, gi,
|
if ( !game_reset( MEMPOOL &globals->cGlobals.game, gi,
|
||||||
globals->cGlobals.params->util,
|
globals->cGlobals.params->util,
|
||||||
&globals->cGlobals.cp, &procs ) ) {
|
&globals->cGlobals.cp, &procs ) ) {
|
||||||
if ( NULL == globals->draw ) {
|
/* if ( NULL == globals->draw ) { */
|
||||||
globals->draw = (GtkDrawCtx*)gtkDrawCtxtMake( globals->drawing_area,
|
/* globals->draw = (GtkDrawCtx*)gtkDrawCtxtMake( globals->drawing_area, */
|
||||||
globals );
|
/* globals ); */
|
||||||
}
|
/* } */
|
||||||
game_makeNewGame( MEMPOOL &globals->cGlobals.game, gi,
|
/* game_makeNewGame( MEMPOOL &globals->cGlobals.game, gi, */
|
||||||
globals->cGlobals.params->util,
|
/* globals->cGlobals.params->util, */
|
||||||
(DrawCtx*)globals->draw,
|
/* (DrawCtx*)globals->draw, */
|
||||||
&globals->cGlobals.cp, &procs,
|
/* &globals->cGlobals.cp, &procs, */
|
||||||
globals->cGlobals.params->gameSeed );
|
/* globals->cGlobals.params->gameSeed ); */
|
||||||
ModelCtxt* model = globals->cGlobals.game.model;
|
/* ModelCtxt* model = globals->cGlobals.game.model; */
|
||||||
if ( NULL == model_getDictionary( model ) ) {
|
/* if ( NULL == model_getDictionary( model ) ) { */
|
||||||
DictionaryCtxt* dict =
|
/* DictionaryCtxt* dict = */
|
||||||
linux_dictionary_make( MEMPOOL globals->cGlobals.params,
|
/* linux_dictionary_make( MEMPOOL globals->cGlobals.params, */
|
||||||
gi->dictName, XP_TRUE );
|
/* gi->dictName, XP_TRUE ); */
|
||||||
model_setDictionary( model, dict );
|
/* model_setDictionary( model, dict ); */
|
||||||
}
|
/* } */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
@ -858,7 +864,8 @@ game_info( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
||||||
|
|
||||||
/* Anything to do if OK is clicked? Changed names etc. already saved. Try
|
/* Anything to do if OK is clicked? Changed names etc. already saved. Try
|
||||||
server_do in case one's become a robot. */
|
server_do in case one's become a robot. */
|
||||||
if ( newGameDialog( globals, &addr, XP_FALSE, XP_FALSE ) ) {
|
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
||||||
|
if ( newGameDialog( globals, gi, &addr, XP_FALSE, XP_FALSE ) ) {
|
||||||
if ( server_do( globals->cGlobals.game.server ) ) {
|
if ( server_do( globals->cGlobals.game.server ) ) {
|
||||||
board_draw( globals->cGlobals.game.board );
|
board_draw( globals->cGlobals.game.board );
|
||||||
}
|
}
|
||||||
|
@ -868,11 +875,13 @@ game_info( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
|
||||||
static void
|
static void
|
||||||
load_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
load_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
||||||
{
|
{
|
||||||
|
XP_ASSERT(0);
|
||||||
} /* load_game */
|
} /* load_game */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
save_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
save_game( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* XP_UNUSED(globals) )
|
||||||
{
|
{
|
||||||
|
XP_ASSERT(0);
|
||||||
} /* save_game */
|
} /* save_game */
|
||||||
|
|
||||||
#ifdef XWFEATURE_CHANGEDICT
|
#ifdef XWFEATURE_CHANGEDICT
|
||||||
|
@ -1478,7 +1487,7 @@ gtk_util_notifyGameOver( XW_UtilCtxt* uc, XP_S16 quitter )
|
||||||
|
|
||||||
if ( cGlobals->params->quitAfter >= 0 ) {
|
if ( cGlobals->params->quitAfter >= 0 ) {
|
||||||
sleep( cGlobals->params->quitAfter );
|
sleep( cGlobals->params->quitAfter );
|
||||||
quit();
|
destroy_window( NULL, globals );
|
||||||
} else if ( cGlobals->params->undoWhenDone ) {
|
} else if ( cGlobals->params->undoWhenDone ) {
|
||||||
server_handleUndo( cGlobals->game.server, 0 );
|
server_handleUndo( cGlobals->game.server, 0 );
|
||||||
board_draw( cGlobals->game.board );
|
board_draw( cGlobals->game.board );
|
||||||
|
@ -2298,25 +2307,25 @@ handle_sigintterm( int XP_UNUSED(sig) )
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
/* int */
|
||||||
board_main( LaunchParams* params )
|
/* board_main( LaunchParams* params ) */
|
||||||
{
|
/* { */
|
||||||
GtkAppGlobals globals;
|
/* GtkAppGlobals globals; */
|
||||||
initGlobals( &globals, params );
|
/* initGlobals( &globals, params ); */
|
||||||
|
|
||||||
if ( !!params->pipe && !!params->fileName ) {
|
/* if ( !!params->pipe && !!params->fileName ) { */
|
||||||
read_pipe_then_close( &globals.cGlobals, NULL );
|
/* read_pipe_then_close( &globals.cGlobals, NULL ); */
|
||||||
} else {
|
/* } else { */
|
||||||
gtk_widget_show( globals.window );
|
/* gtk_widget_show( globals.window ); */
|
||||||
|
|
||||||
gtk_main();
|
/* gtk_main(); */
|
||||||
}
|
/* } */
|
||||||
/* MONCONTROL(1); */
|
/* /\* MONCONTROL(1); *\/ */
|
||||||
|
|
||||||
cleanup( &globals );
|
/* cleanup( &globals ); */
|
||||||
|
|
||||||
return 0;
|
/* return 0; */
|
||||||
} /* gtkmain */
|
/* } */
|
||||||
|
|
||||||
void
|
void
|
||||||
initGlobals( GtkAppGlobals* globals, LaunchParams* params )
|
initGlobals( GtkAppGlobals* globals, LaunchParams* params )
|
||||||
|
@ -2379,7 +2388,7 @@ initGlobals( GtkAppGlobals* globals, LaunchParams* params )
|
||||||
gtk_widget_show( vbox );
|
gtk_widget_show( vbox );
|
||||||
|
|
||||||
g_signal_connect( G_OBJECT (window), "destroy",
|
g_signal_connect( G_OBJECT (window), "destroy",
|
||||||
G_CALLBACK( quit ), &globals );
|
G_CALLBACK( destroy_window ), globals );
|
||||||
|
|
||||||
menubar = makeMenus( globals );
|
menubar = makeMenus( globals );
|
||||||
gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
|
gtk_box_pack_start( GTK_BOX(vbox), menubar, FALSE, TRUE, 0);
|
||||||
|
@ -2387,7 +2396,7 @@ initGlobals( GtkAppGlobals* globals, LaunchParams* params )
|
||||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
dropCheck = gtk_check_button_new_with_label( "drop incoming messages" );
|
dropCheck = gtk_check_button_new_with_label( "drop incoming messages" );
|
||||||
g_signal_connect( GTK_OBJECT(dropCheck),
|
g_signal_connect( GTK_OBJECT(dropCheck),
|
||||||
"toggled", G_CALLBACK(drop_msg_toggle), &globals );
|
"toggled", G_CALLBACK(drop_msg_toggle), globals );
|
||||||
gtk_box_pack_start( GTK_BOX(vbox), dropCheck, FALSE, TRUE, 0);
|
gtk_box_pack_start( GTK_BOX(vbox), dropCheck, FALSE, TRUE, 0);
|
||||||
gtk_widget_show( dropCheck );
|
gtk_widget_show( dropCheck );
|
||||||
#endif
|
#endif
|
||||||
|
@ -2479,7 +2488,21 @@ freeGlobals( GtkAppGlobals* globals )
|
||||||
XP_Bool
|
XP_Bool
|
||||||
makeNewGame( GtkAppGlobals* globals )
|
makeNewGame( GtkAppGlobals* globals )
|
||||||
{
|
{
|
||||||
return new_game_impl( globals, XP_FALSE );
|
CommsAddrRec addr;
|
||||||
|
if ( !!globals->cGlobals.game.comms ) {
|
||||||
|
comms_getAddr( globals->cGlobals.game.comms, &addr );
|
||||||
|
} else {
|
||||||
|
comms_getInitialAddr( &addr, RELAY_NAME_DEFAULT, RELAY_PORT_DEFAULT );
|
||||||
|
}
|
||||||
|
|
||||||
|
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
||||||
|
XP_Bool success = newGameDialog( globals, gi, &addr, XP_TRUE, XP_FALSE );
|
||||||
|
if ( success && !!gi->dictName && !globals->cGlobals.params->dict ) {
|
||||||
|
globals->cGlobals.params->dict =
|
||||||
|
linux_dictionary_make( MEMPOOL globals->cGlobals.params,
|
||||||
|
gi->dictName, XP_TRUE );
|
||||||
|
}
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* PLATFORM_GTK */
|
#endif /* PLATFORM_GTK */
|
||||||
|
|
|
@ -25,22 +25,20 @@
|
||||||
#include "gtkboard.h"
|
#include "gtkboard.h"
|
||||||
#include "linuxmain.h"
|
#include "linuxmain.h"
|
||||||
|
|
||||||
enum { NAME_ITEM, N_ITEMS };
|
enum { ROW_ITEM, N_ITEMS };
|
||||||
|
|
||||||
typedef struct _GTKGamesGlobals {
|
typedef struct _GTKGamesGlobals {
|
||||||
sqlite3* pDb;
|
sqlite3* pDb;
|
||||||
GtkAppGlobals globals;
|
|
||||||
LaunchParams* params;
|
LaunchParams* params;
|
||||||
} GTKGamesGlobals;
|
} GTKGamesGlobals;
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_games_list( GtkWidget* list )
|
init_games_list( GtkWidget* list )
|
||||||
{
|
{
|
||||||
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
|
GtkCellRenderer* renderer = gtk_cell_renderer_text_new();
|
||||||
GtkTreeViewColumn* column =
|
GtkTreeViewColumn* column =
|
||||||
gtk_tree_view_column_new_with_attributes( "Games", renderer,
|
gtk_tree_view_column_new_with_attributes( "Games", renderer,
|
||||||
"text", NAME_ITEM, NULL );
|
"row", ROW_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_STRING );
|
GtkListStore* store = gtk_list_store_new( N_ITEMS, 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) );
|
||||||
|
@ -53,21 +51,43 @@ handle_newgame_button( GtkWidget* XP_UNUSED(widget), void* closure )
|
||||||
GTKGamesGlobals* gg = (GTKGamesGlobals*)closure;
|
GTKGamesGlobals* gg = (GTKGamesGlobals*)closure;
|
||||||
XP_LOGF( "%s called", __func__ );
|
XP_LOGF( "%s called", __func__ );
|
||||||
GtkAppGlobals* globals = malloc( sizeof(*globals) );
|
GtkAppGlobals* globals = malloc( sizeof(*globals) );
|
||||||
|
gg->params->needsNewGame = XP_FALSE;
|
||||||
initGlobals( globals, gg->params );
|
initGlobals( globals, gg->params );
|
||||||
if ( !makeNewGame( globals ) ) {
|
if ( !makeNewGame( globals ) ) {
|
||||||
freeGlobals( globals );
|
freeGlobals( globals );
|
||||||
} else {
|
} else {
|
||||||
GtkWidget* gameWindow = globals->window;
|
GtkWidget* gameWindow = globals->window;
|
||||||
|
globals->cGlobals.pDb = gg->pDb;
|
||||||
gtk_widget_show( gameWindow );
|
gtk_widget_show( gameWindow );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_quit_button( GtkWidget* XP_UNUSED(widget), gpointer data )
|
||||||
|
{
|
||||||
|
GTKGamesGlobals* gg = (GTKGamesGlobals*)data;
|
||||||
|
gg = gg;
|
||||||
|
gtk_main_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
handle_destroy( GtkWidget* XP_UNUSED(widget), gpointer data )
|
||||||
|
{
|
||||||
|
LOG_FUNC();
|
||||||
|
GTKGamesGlobals* gg = (GTKGamesGlobals*)data;
|
||||||
|
gg = gg;
|
||||||
|
gtk_main_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
makeGamesWindow( GTKGamesGlobals* gg )
|
makeGamesWindow( GTKGamesGlobals* gg )
|
||||||
{
|
{
|
||||||
GtkWidget* window;
|
GtkWidget* window;
|
||||||
|
|
||||||
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
window = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
||||||
|
g_signal_connect( G_OBJECT(window), "destroy",
|
||||||
|
G_CALLBACK(handle_destroy), gg );
|
||||||
|
|
||||||
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
||||||
gtk_container_add( GTK_CONTAINER(window), vbox );
|
gtk_container_add( GTK_CONTAINER(window), vbox );
|
||||||
|
@ -75,12 +95,23 @@ makeGamesWindow( GTKGamesGlobals* gg )
|
||||||
GtkWidget* list = gtk_tree_view_new();
|
GtkWidget* list = gtk_tree_view_new();
|
||||||
gtk_container_add( GTK_CONTAINER(vbox), list );
|
gtk_container_add( GTK_CONTAINER(vbox), list );
|
||||||
init_games_list( list );
|
init_games_list( list );
|
||||||
|
gtk_widget_show( list );
|
||||||
|
|
||||||
|
GtkWidget* hbox = gtk_hbox_new( FALSE, 0 );
|
||||||
|
gtk_widget_show( hbox );
|
||||||
|
gtk_container_add( GTK_CONTAINER(vbox), hbox );
|
||||||
GtkWidget* button = gtk_button_new_with_label( "New Game" );
|
GtkWidget* button = gtk_button_new_with_label( "New Game" );
|
||||||
gtk_container_add( GTK_CONTAINER(vbox), button );
|
gtk_container_add( GTK_CONTAINER(hbox), button );
|
||||||
g_signal_connect( GTK_OBJECT(button), "clicked",
|
g_signal_connect( GTK_OBJECT(button), "clicked",
|
||||||
G_CALLBACK(handle_newgame_button), gg );
|
G_CALLBACK(handle_newgame_button), gg );
|
||||||
gtk_widget_show( button );
|
gtk_widget_show( button );
|
||||||
|
|
||||||
|
button = gtk_button_new_with_label( "Quit" );
|
||||||
|
gtk_container_add( GTK_CONTAINER(hbox), button );
|
||||||
|
g_signal_connect( GTK_OBJECT(button), "clicked",
|
||||||
|
G_CALLBACK(handle_quit_button), gg );
|
||||||
|
gtk_widget_show( button );
|
||||||
|
|
||||||
gtk_widget_show( window );
|
gtk_widget_show( window );
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2008 by Eric House (xwords@eehouse.org). All rights
|
* Copyright 2001-2013 by Eric House (xwords@eehouse.org). All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
typedef struct GtkNewGameState {
|
typedef struct GtkNewGameState {
|
||||||
GtkAppGlobals* globals;
|
GtkAppGlobals* globals;
|
||||||
|
CurGameInfo* gi;
|
||||||
NewGameCtx* newGameCtxt;
|
NewGameCtx* newGameCtxt;
|
||||||
|
|
||||||
CommsAddrRec addr;
|
CommsAddrRec addr;
|
||||||
|
@ -248,7 +249,7 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
nPlayersCombo = gtk_combo_box_new_text();
|
nPlayersCombo = gtk_combo_box_new_text();
|
||||||
state->nPlayersCombo = nPlayersCombo;
|
state->nPlayersCombo = nPlayersCombo;
|
||||||
|
|
||||||
gi = &state->globals->cGlobals.params->gi;
|
gi = state->gi;
|
||||||
|
|
||||||
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
|
for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
|
||||||
char buf[2] = { ii + '1', '\0' };
|
char buf[2] = { ii + '1', '\0' };
|
||||||
|
@ -352,16 +353,21 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), dictCombo, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), dictCombo, FALSE, TRUE, 0 );
|
||||||
|
|
||||||
GSList* dicts = listDicts( state->globals->cGlobals.params );
|
GSList* dicts = listDicts( state->globals->cGlobals.params );
|
||||||
for ( GSList* iter = dicts; !!iter; iter = iter->next ) {
|
GSList* iter;
|
||||||
gtk_combo_box_append_text( GTK_COMBO_BOX(dictCombo), iter->data );
|
for ( iter = dicts, ii = 0; !!iter; iter = iter->next, ++ii ) {
|
||||||
|
const gchar* name = iter->data;
|
||||||
|
gtk_combo_box_append_text( GTK_COMBO_BOX(dictCombo), name );
|
||||||
|
if ( !!gi->dictName && !strcmp( name, gi->dictName ) ) {
|
||||||
|
gtk_combo_box_set_active( GTK_COMBO_BOX(dictCombo), ii );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
g_slist_free( dicts );
|
g_slist_free( dicts );
|
||||||
|
|
||||||
if ( !!gi->dictName ) {
|
/* if ( !!gi->dictName ) { */
|
||||||
gtk_box_pack_start( GTK_BOX(hbox),
|
/* gtk_box_pack_start( GTK_BOX(hbox), */
|
||||||
gtk_label_new(gi->dictName),
|
/* gtk_label_new(gi->dictName), */
|
||||||
FALSE, TRUE, 0 );
|
/* FALSE, TRUE, 0 ); */
|
||||||
}
|
/* } */
|
||||||
|
|
||||||
gtk_widget_show( hbox );
|
gtk_widget_show( hbox );
|
||||||
|
|
||||||
|
@ -538,13 +544,14 @@ gtk_newgame_attr_set( void* closure, NewGameAttr attr, NGValue value )
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
newGameDialog( GtkAppGlobals* globals, CommsAddrRec* addr, XP_Bool isNewGame,
|
newGameDialog( GtkAppGlobals* globals, CurGameInfo* gi, CommsAddrRec* addr,
|
||||||
XP_Bool fireConnDlg )
|
XP_Bool isNewGame, XP_Bool fireConnDlg )
|
||||||
{
|
{
|
||||||
GtkNewGameState state;
|
GtkNewGameState state;
|
||||||
XP_MEMSET( &state, 0, sizeof(state) );
|
XP_MEMSET( &state, 0, sizeof(state) );
|
||||||
|
|
||||||
state.globals = globals;
|
state.globals = globals;
|
||||||
|
state.gi = gi;
|
||||||
state.newGameCtxt = newg_make( MPPARM(globals->cGlobals.params
|
state.newGameCtxt = newg_make( MPPARM(globals->cGlobals.params
|
||||||
->util->mpool)
|
->util->mpool)
|
||||||
isNewGame,
|
isNewGame,
|
||||||
|
@ -564,25 +571,22 @@ newGameDialog( GtkAppGlobals* globals, CommsAddrRec* addr, XP_Bool isNewGame,
|
||||||
|
|
||||||
state.revert = FALSE;
|
state.revert = FALSE;
|
||||||
state.loaded = XP_FALSE;
|
state.loaded = XP_FALSE;
|
||||||
state.nCols = globals->cGlobals.params->gi.boardSize;
|
state.nCols = gi->boardSize;
|
||||||
state.role = globals->cGlobals.params->gi.serverRole;
|
state.role = gi->serverRole;
|
||||||
|
|
||||||
XP_MEMCPY( &state.addr, addr, sizeof(state.addr) );
|
XP_MEMCPY( &state.addr, addr, sizeof(state.addr) );
|
||||||
|
|
||||||
dialog = makeNewGameDialog( &state );
|
dialog = makeNewGameDialog( &state );
|
||||||
|
|
||||||
newg_load( state.newGameCtxt,
|
newg_load( state.newGameCtxt, gi );
|
||||||
&globals->cGlobals.params->gi );
|
|
||||||
state.loaded = XP_TRUE;
|
state.loaded = XP_TRUE;
|
||||||
|
|
||||||
gtk_main();
|
gtk_main();
|
||||||
if ( !state.cancelled && !state.revert ) {
|
if ( !state.cancelled && !state.revert ) {
|
||||||
if ( newg_store( state.newGameCtxt, &globals->cGlobals.params->gi,
|
if ( newg_store( state.newGameCtxt, gi, XP_TRUE ) ) {
|
||||||
XP_TRUE ) ) {
|
gi->boardSize = state.nCols;
|
||||||
globals->cGlobals.params->gi.boardSize = state.nCols;
|
|
||||||
replaceStringIfDifferent( globals->cGlobals.params->util->mpool,
|
replaceStringIfDifferent( globals->cGlobals.params->util->mpool,
|
||||||
&globals->cGlobals.params->gi.dictName,
|
&gi->dictName, state.dict );
|
||||||
state.dict );
|
|
||||||
} else {
|
} else {
|
||||||
/* Do it again if we warned user of inconsistency. */
|
/* Do it again if we warned user of inconsistency. */
|
||||||
state.revert = XP_TRUE;
|
state.revert = XP_TRUE;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/* -*- compile-command: "make MEMDEBUG=TRUE"; -*- */
|
/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */
|
||||||
/*
|
/*
|
||||||
* Copyright 2000-2009 by Eric House (xwords@eehouse.org). All rights
|
* Copyright 2000-2013 by Eric House (xwords@eehouse.org). All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software; you can redistribute it and/or
|
||||||
|
@ -26,8 +26,9 @@
|
||||||
|
|
||||||
#include "gtkboard.h"
|
#include "gtkboard.h"
|
||||||
|
|
||||||
gboolean newGameDialog( GtkAppGlobals* globals, CommsAddrRec* addr,
|
gboolean newGameDialog( GtkAppGlobals* globals, CurGameInfo* gi,
|
||||||
XP_Bool isNewGame, XP_Bool fireConnDlg );
|
CommsAddrRec* addr, XP_Bool isNewGame,
|
||||||
|
XP_Bool fireConnDlg );
|
||||||
|
|
||||||
#endif /* _GTKNEWGAME_H_ */
|
#endif /* _GTKNEWGAME_H_ */
|
||||||
#endif /* PLATFORM_GTK */
|
#endif /* PLATFORM_GTK */
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
#include "linuxudp.h"
|
#include "linuxudp.h"
|
||||||
#include "dictiter.h"
|
#include "dictiter.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "gamesdb.h"
|
||||||
#ifdef PLATFORM_NCURSES
|
#ifdef PLATFORM_NCURSES
|
||||||
# include "cursesmain.h"
|
# include "cursesmain.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -130,7 +131,8 @@ streamFromDB( CommonGlobals* cGlobals, void* closure )
|
||||||
XP_U8 buf[size];
|
XP_U8 buf[size];
|
||||||
res = sqlite3_blob_read( ppBlob, buf, size, 0 );
|
res = sqlite3_blob_read( ppBlob, buf, size, 0 );
|
||||||
if ( SQLITE_OK == res ) {
|
if ( SQLITE_OK == res ) {
|
||||||
stream = mem_stream_make( MPPARM(params->util->mpool) params->vtMgr,
|
stream = mem_stream_make( MPPARM(params->util->mpool)
|
||||||
|
params->vtMgr,
|
||||||
closure, CHANNEL_NONE, NULL );
|
closure, CHANNEL_NONE, NULL );
|
||||||
stream_putBytes( stream, buf, size );
|
stream_putBytes( stream, buf, size );
|
||||||
}
|
}
|
||||||
|
@ -255,23 +257,26 @@ strFromStream( XWStreamCtxt* stream )
|
||||||
void
|
void
|
||||||
saveGame( CommonGlobals* cGlobals )
|
saveGame( CommonGlobals* cGlobals )
|
||||||
{
|
{
|
||||||
if ( !!cGlobals->params->fileName ) {
|
LOG_FUNC();
|
||||||
|
if ( !!cGlobals->params->fileName || !!cGlobals->pDb ) {
|
||||||
XP_Bool doSave = XP_TRUE;
|
XP_Bool doSave = XP_TRUE;
|
||||||
if ( 0 < cGlobals->params->saveFailPct
|
XP_Bool newGame = !file_exists( cGlobals->params->fileName )
|
||||||
/* don't fail to save first time! */
|
|| 0 == cGlobals->rowid;
|
||||||
&& file_exists( cGlobals->params->fileName ) ) {
|
/* don't fail to save first time! */
|
||||||
|
if ( 0 < cGlobals->params->saveFailPct && !newGame ) {
|
||||||
XP_U16 pct = XP_RANDOM() % 100;
|
XP_U16 pct = XP_RANDOM() % 100;
|
||||||
doSave = pct >= cGlobals->params->saveFailPct;
|
doSave = pct >= cGlobals->params->saveFailPct;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( doSave ) {
|
if ( doSave ) {
|
||||||
XWStreamCtxt* outStream;
|
XWStreamCtxt* outStream;
|
||||||
|
MemStreamCloseCallback onClose = !!cGlobals->pDb?
|
||||||
|
writeToDB : writeToFile;
|
||||||
outStream =
|
outStream =
|
||||||
mem_stream_make_sized( MPPARM(cGlobals->params->util->mpool)
|
mem_stream_make_sized( MPPARM(cGlobals->params->util->mpool)
|
||||||
cGlobals->params->vtMgr,
|
cGlobals->params->vtMgr,
|
||||||
cGlobals->lastStreamSize,
|
cGlobals->lastStreamSize,
|
||||||
cGlobals, 0, writeToFile );
|
cGlobals, 0, onClose );
|
||||||
stream_open( outStream );
|
stream_open( outStream );
|
||||||
|
|
||||||
game_saveToStream( &cGlobals->game,
|
game_saveToStream( &cGlobals->game,
|
||||||
|
@ -1507,14 +1512,13 @@ listDicts( const LaunchParams *params )
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
initParams( LaunchParams* params )
|
initParams( LaunchParams* params )
|
||||||
{
|
{
|
||||||
memset( params, 0, sizeof(*params) );
|
memset( params, 0, sizeof(*params) );
|
||||||
|
|
||||||
params->util = malloc( sizeof(params->util) );
|
params->util = calloc( 1, sizeof(*params->util) );
|
||||||
|
/* XP_MEMSET( params->util, 0, sizeof(params->util) ); */
|
||||||
XP_MEMSET( params->util, 0, sizeof(params->util) );
|
|
||||||
|
|
||||||
#ifdef MEM_DEBUG
|
#ifdef MEM_DEBUG
|
||||||
params->util->mpool = mpool_make();
|
params->util->mpool = mpool_make();
|
||||||
|
@ -1529,11 +1533,11 @@ initParams( LaunchParams* params )
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
freeParams( LaunchParams* params )
|
freeParams( LaunchParams* params )
|
||||||
{
|
{
|
||||||
vtmgr_destroy( MPPARM(params->util->mpool) params->vtMgr );
|
|
||||||
linux_util_vt_destroy( params->util );
|
linux_util_vt_destroy( params->util );
|
||||||
|
vtmgr_destroy( MPPARM(params->util->mpool) params->vtMgr );
|
||||||
|
|
||||||
mpool_destroy( params->util->mpool );
|
mpool_destroy( params->util->mpool );
|
||||||
|
|
||||||
|
@ -1596,8 +1600,6 @@ main( int argc, char** argv )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
initParams( &mainParams );
|
initParams( &mainParams );
|
||||||
/* fprintf( stdout, "press <RET> to start\n" ); */
|
|
||||||
/* (void)fgetc( stdin ); */
|
|
||||||
|
|
||||||
/* defaults */
|
/* defaults */
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
|
|
|
@ -94,7 +94,7 @@ void setOneSecondTimer( CommonGlobals* cGlobals );
|
||||||
# define setOneSecondTimer( cGlobals )
|
# define setOneSecondTimer( cGlobals )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void initParams( LaunchParams* params );
|
/* void initParams( LaunchParams* params ); */
|
||||||
void freeParams( LaunchParams* params );
|
/* void freeParams( LaunchParams* params ); */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,6 +25,8 @@
|
||||||
# include <bluetooth/bluetooth.h> /* for bdaddr_t, which should move */
|
# include <bluetooth/bluetooth.h> /* for bdaddr_t, which should move */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#include "comtypes.h"
|
#include "comtypes.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
@ -167,9 +169,11 @@ struct CommonGlobals {
|
||||||
CommonPrefs cp;
|
CommonPrefs cp;
|
||||||
|
|
||||||
XWGame game;
|
XWGame game;
|
||||||
|
sqlite3_int64 rowid;
|
||||||
XP_U16 lastNTilesToUse;
|
XP_U16 lastNTilesToUse;
|
||||||
XP_U16 lastStreamSize;
|
XP_U16 lastStreamSize;
|
||||||
XP_Bool manualFinal; /* use asked for final scores */
|
XP_Bool manualFinal; /* use asked for final scores */
|
||||||
|
sqlite3* pDb;
|
||||||
|
|
||||||
SocketChangedFunc socketChanged;
|
SocketChangedFunc socketChanged;
|
||||||
void* socketChangedClosure;
|
void* socketChangedClosure;
|
||||||
|
|
Loading…
Reference in a new issue