mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
Add checkbox to each type tab indicating whther the game will use that
addressing type to communicate.
This commit is contained in:
parent
9b336bde49
commit
1ca5515b07
1 changed files with 76 additions and 42 deletions
|
@ -24,6 +24,12 @@
|
||||||
#include "gtkutils.h"
|
#include "gtkutils.h"
|
||||||
#include "linuxbt.h"
|
#include "linuxbt.h"
|
||||||
|
|
||||||
|
typedef struct _PageData {
|
||||||
|
CommsConnType pageType;
|
||||||
|
gboolean doUse;
|
||||||
|
const char* label;
|
||||||
|
} PageData;
|
||||||
|
|
||||||
typedef struct _GtkConnsState {
|
typedef struct _GtkConnsState {
|
||||||
GtkGameGlobals* globals;
|
GtkGameGlobals* globals;
|
||||||
CommsAddrRec* addr;
|
CommsAddrRec* addr;
|
||||||
|
@ -41,7 +47,7 @@ typedef struct _GtkConnsState {
|
||||||
|
|
||||||
GtkWidget* notebook;
|
GtkWidget* notebook;
|
||||||
|
|
||||||
CommsConnType pageTypes[COMMS_CONN_NTYPES];
|
PageData pageData[COMMS_CONN_NTYPES];
|
||||||
|
|
||||||
gboolean cancelled;
|
gboolean cancelled;
|
||||||
gboolean readOnly;
|
gboolean readOnly;
|
||||||
|
@ -53,23 +59,17 @@ conTypeToPageNum( const GtkConnsState* state, CommsConnType conType )
|
||||||
gint pageNum = 0; /* default */
|
gint pageNum = 0; /* default */
|
||||||
int ii;
|
int ii;
|
||||||
for ( ii = 0; ; ++ii ) {
|
for ( ii = 0; ; ++ii ) {
|
||||||
CommsConnType thisType = state->pageTypes[ii];
|
const PageData* pageData = &state->pageData[ii];
|
||||||
|
CommsConnType thisType = pageData->pageType;
|
||||||
if ( thisType == COMMS_CONN_NONE || thisType == conType ) {
|
if ( thisType == COMMS_CONN_NONE || thisType == conType ) {
|
||||||
pageNum = ii;
|
pageNum = ii;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
XP_ASSERT( ii < VSIZE(state->pageTypes) );
|
XP_ASSERT( ii < VSIZE(state->pageData) );
|
||||||
}
|
}
|
||||||
return pageNum;
|
return pageNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CommsConnType
|
|
||||||
pageNoToConnType( const GtkConnsState* state, gint page )
|
|
||||||
{
|
|
||||||
XP_ASSERT( page < VSIZE(state->pageTypes) );
|
|
||||||
return state->pageTypes[page];
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure )
|
handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure )
|
||||||
{
|
{
|
||||||
|
@ -78,11 +78,17 @@ handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure )
|
||||||
const gchar* txt;
|
const gchar* txt;
|
||||||
|
|
||||||
for ( gint page = 0; ; ++page ) {
|
for ( gint page = 0; ; ++page ) {
|
||||||
CommsConnType conType = pageNoToConnType( state, page );
|
PageData* data = &state->pageData[page];
|
||||||
if ( COMMS_CONN_NONE == conType ) {
|
CommsConnType conType = data->pageType;
|
||||||
|
if ( COMMS_CONN_NONE == conType ) { /* signals end */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ( ! data->doUse ) {
|
||||||
|
addr_rmType( state->addr, conType );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
addr_addType( state->addr, conType );
|
||||||
switch ( conType ) {
|
switch ( conType ) {
|
||||||
#ifdef XWFEATURE_DIRECTIP
|
#ifdef XWFEATURE_DIRECTIP
|
||||||
case COMMS_CONN_IP_DIRECT:
|
case COMMS_CONN_IP_DIRECT:
|
||||||
|
@ -124,11 +130,6 @@ handle_ok( GtkWidget* XP_UNUSED(widget), gpointer closure )
|
||||||
XP_ASSERT( 0 ); /* keep compiler happy */
|
XP_ASSERT( 0 ); /* keep compiler happy */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* PENDING: This will add them all, when what's needed is an
|
|
||||||
interface to let user choose which will be used to attempt to
|
|
||||||
connect. */
|
|
||||||
addr_addType( state->addr, conType );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +166,31 @@ handle_cancel( GtkWidget* XP_UNUSED(widget), void* closure )
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
useCheckToggled( GtkWidget* item, PageData* data )
|
||||||
|
{
|
||||||
|
gboolean checked = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(item) );
|
||||||
|
data->doUse = checked;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GtkWidget*
|
||||||
|
boxWithUseCheck( GtkConnsState* state, PageData* data )
|
||||||
|
{
|
||||||
|
XP_Bool set = addr_hasType( state->addr, data->pageType );
|
||||||
|
data->doUse = set;
|
||||||
|
|
||||||
|
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
||||||
|
|
||||||
|
GtkWidget* check = gtk_check_button_new_with_label( data->label );
|
||||||
|
g_signal_connect( GTK_OBJECT(check),
|
||||||
|
"toggled", G_CALLBACK(useCheckToggled), data );
|
||||||
|
gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(check), set );
|
||||||
|
gtk_box_pack_start( GTK_BOX(vbox), check, FALSE, TRUE, 0);
|
||||||
|
|
||||||
|
return vbox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Invite: _____
|
* Invite: _____
|
||||||
* Relay: _____
|
* Relay: _____
|
||||||
|
@ -173,9 +199,9 @@ handle_cancel( GtkWidget* XP_UNUSED(widget), void* closure )
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
makeRelayPage( GtkConnsState* state )
|
makeRelayPage( GtkConnsState* state, PageData* data )
|
||||||
{
|
{
|
||||||
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
GtkWidget* vbox = boxWithUseCheck( state, data );
|
||||||
const gchar* hint = NULL;
|
const gchar* hint = NULL;
|
||||||
|
|
||||||
if ( SERVER_ISSERVER == state->role ) {
|
if ( SERVER_ISSERVER == state->role ) {
|
||||||
|
@ -221,12 +247,12 @@ makeRelayPage( GtkConnsState* state )
|
||||||
} /* makeRelayPage */
|
} /* makeRelayPage */
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
makeBTPage( GtkConnsState* state )
|
makeBTPage( GtkConnsState* state, PageData* data )
|
||||||
{
|
{
|
||||||
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
GtkWidget* vbox = boxWithUseCheck( state, data );
|
||||||
|
|
||||||
GtkWidget* hbox = makeLabeledField( "Host device", &state->bthost, NULL );
|
GtkWidget* hbox = makeLabeledField( "Host device", &state->bthost, NULL );
|
||||||
if ( addr_hasType( state->addr, COMMS_CONN_BT ) ) {
|
if ( addr_hasType( state->addr, data->pageType ) ) {
|
||||||
gtk_entry_set_text( GTK_ENTRY(state->bthost), state->addr->u.bt.hostName );
|
gtk_entry_set_text( GTK_ENTRY(state->bthost), state->addr->u.bt.hostName );
|
||||||
}
|
}
|
||||||
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
|
||||||
|
@ -243,14 +269,14 @@ makeBTPage( GtkConnsState* state )
|
||||||
|
|
||||||
#ifdef XWFEATURE_DIRECTIP
|
#ifdef XWFEATURE_DIRECTIP
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
makeIPDirPage( GtkConnsState* state )
|
makeIPDirPage( GtkConnsState* state, PageData* data )
|
||||||
{
|
{
|
||||||
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
GtkWidget* vbox = boxWithUseCheck( state, data );
|
||||||
|
|
||||||
/* XP_UCHAR hostName_ip[MAX_HOSTNAME_LEN + 1]; */
|
/* XP_UCHAR hostName_ip[MAX_HOSTNAME_LEN + 1]; */
|
||||||
/* XP_U16 port_ip; */
|
/* XP_U16 port_ip; */
|
||||||
|
|
||||||
XP_Bool hasIP = addr_hasType( state->addr, COMMS_CONN_IP_DIRECT );
|
XP_Bool hasIP = addr_hasType( state->addr, data->pageType );
|
||||||
const gchar* name = hasIP ?
|
const gchar* name = hasIP ?
|
||||||
state->addr->u.ip.hostName_ip : state->globals->cGlobals.params->connInfo.ip.hostName;
|
state->addr->u.ip.hostName_ip : state->globals->cGlobals.params->connInfo.ip.hostName;
|
||||||
GtkWidget* hbox = makeLabeledField( "Hostname", &state->iphost, name );
|
GtkWidget* hbox = makeLabeledField( "Hostname", &state->iphost, name );
|
||||||
|
@ -269,11 +295,10 @@ makeIPDirPage( GtkConnsState* state )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
makeSMSPage( GtkConnsState* state )
|
makeSMSPage( GtkConnsState* state, PageData* data )
|
||||||
{
|
{
|
||||||
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
GtkWidget* vbox = boxWithUseCheck( state, data );
|
||||||
|
XP_Bool hasSMS = addr_hasType( state->addr, data->pageType );
|
||||||
XP_Bool hasSMS = addr_hasType( state->addr, COMMS_CONN_SMS );
|
|
||||||
const gchar* phone = hasSMS ?
|
const gchar* phone = hasSMS ?
|
||||||
state->addr->u.sms.phone : state->globals->cGlobals.params->connInfo.sms.phone;
|
state->addr->u.sms.phone : state->globals->cGlobals.params->connInfo.sms.phone;
|
||||||
GtkWidget* hbox = makeLabeledField( "Host phone", &state->smsphone, phone );
|
GtkWidget* hbox = makeLabeledField( "Host phone", &state->smsphone, phone );
|
||||||
|
@ -311,33 +336,42 @@ gtkConnsDlg( GtkGameGlobals* globals, CommsAddrRec* addr, DeviceRole role,
|
||||||
GtkWidget* hbox;
|
GtkWidget* hbox;
|
||||||
|
|
||||||
state.notebook = gtk_notebook_new();
|
state.notebook = gtk_notebook_new();
|
||||||
|
PageData* data;
|
||||||
|
|
||||||
#ifdef XWFEATURE_RELAY
|
#ifdef XWFEATURE_RELAY
|
||||||
state.pageTypes[nTypes++] = COMMS_CONN_RELAY;
|
data = &state.pageData[nTypes++];
|
||||||
|
data->pageType = COMMS_CONN_RELAY;
|
||||||
|
data->label = "Relay";
|
||||||
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
||||||
makeRelayPage(&state),
|
makeRelayPage( &state, data ),
|
||||||
gtk_label_new( "Relay" ) );
|
gtk_label_new( data->label ) );
|
||||||
#endif
|
#endif
|
||||||
#ifdef XWFEATURE_BLUETOOTH
|
#ifdef XWFEATURE_BLUETOOTH
|
||||||
state.pageTypes[nTypes++] = COMMS_CONN_BT;
|
data = &state.pageData[nTypes++];
|
||||||
|
data->pageType = COMMS_CONN_BT;
|
||||||
|
data->label = "Bluetooth";
|
||||||
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
||||||
makeBTPage(&state),
|
makeBTPage( &state, data ),
|
||||||
gtk_label_new( "Bluetooth" ) );
|
gtk_label_new( data->label ) );
|
||||||
#endif
|
#endif
|
||||||
#ifdef XWFEATURE_DIRECTIP
|
#ifdef XWFEATURE_DIRECTIP
|
||||||
state.pageTypes[nTypes++] = COMMS_CONN_IP_DIRECT;
|
data = &state.pageData[nTypes++];
|
||||||
|
data->pageType = COMMS_CONN_IP_DIRECT;
|
||||||
|
data->label = "Direct";
|
||||||
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
||||||
makeIPDirPage(&state),
|
makeIPDirPage(&state, data),
|
||||||
gtk_label_new( "Direct" ) );
|
gtk_label_new( data->label ) );
|
||||||
#endif
|
#endif
|
||||||
state.pageTypes[nTypes++] = COMMS_CONN_SMS;
|
data = &state.pageData[nTypes++];
|
||||||
|
data->pageType = COMMS_CONN_SMS;
|
||||||
|
data->label = "SMS";
|
||||||
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
(void)gtk_notebook_append_page( GTK_NOTEBOOK(state.notebook),
|
||||||
makeSMSPage(&state),
|
makeSMSPage( &state, data ),
|
||||||
gtk_label_new( "SMS" ) );
|
gtk_label_new( data->label ) );
|
||||||
|
|
||||||
vbox = gtk_vbox_new( FALSE, 0 );
|
vbox = gtk_vbox_new( FALSE, 0 );
|
||||||
gtk_box_pack_start( GTK_BOX(vbox), state.notebook, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(vbox), state.notebook, FALSE, TRUE, 0 );
|
||||||
state.pageTypes[nTypes++] = COMMS_CONN_NONE; /* mark end of list */
|
state.pageData[nTypes++].pageType = COMMS_CONN_NONE; /* mark end of list */
|
||||||
|
|
||||||
/* Set page to the first we actually have */
|
/* Set page to the first we actually have */
|
||||||
XP_U32 st = 0;
|
XP_U32 st = 0;
|
||||||
|
|
Loading…
Reference in a new issue