Remove unused code and constants; fix to compile with relay; don't

show connection type dialog unless more than IR is available and
supported, and then build the dropdown dynamically based on what's
compiled-in and available on the device.  This means you don't see the
BT option at all if you don't have BT.
This commit is contained in:
ehouse 2007-12-08 18:11:42 +00:00
parent 348111ece2
commit 75a3c36ad6
10 changed files with 142 additions and 76 deletions

View file

@ -29,6 +29,7 @@
#include "palmutil.h"
#include "palmir.h"
#include "palmbt.h"
#include "LocalizedStrIncludes.h"
/* When user pops up via Host gadget, we want to get the port to listen on.
* When pops up via the Guest gadget, we want to get the port and IP address
@ -37,8 +38,18 @@
* expect state to live as long as the parent dialog isn't exited.
*/
typedef struct XportEntry {
XP_U16 resID;
CommsConnType conType;
} XportEntry;
#define MAX_XPORTS 3
typedef struct ConnsDlgState {
ListPtr connTypesList;
ListData sLd;
XportEntry xports[MAX_XPORTS];
XP_U16 nXports;
XP_U16 serverRole;
XP_Bool isNewGame;
CommsConnType conType;
@ -121,8 +132,8 @@ static void
updateFormCtls( FormPtr form, ConnsDlgState* state )
{
const XP_U16 relayCtls[] = {
XW_CONNS_RELAY_LABEL_ID ,
#ifdef XWFEATURE_RELAY
XW_CONNS_RELAY_LABEL_ID ,
XW_CONNS_RELAY_FIELD_ID,
XW_CONNS_PORT_LABEL_ID,
XW_CONNS_PORT_FIELD_ID,
@ -173,36 +184,17 @@ updateFormCtls( FormPtr form, ConnsDlgState* state )
static void
cleanupExit( PalmAppGlobals* globals )
{
freeListData( MPPARM(globals->mpool) &globals->connState->sLd );
XP_FREE( globals->mpool, globals->connState );
globals->connState = NULL;
FrmReturnToForm( 0 );
} /* cleanupExit */
static XP_U16
conTypeToSel( CommsConnType conType )
{
XP_U16 result = 0;
switch ( conType ) {
case COMMS_CONN_BT: /* result = 0; */break;
case COMMS_CONN_IR: result = 1; break;
case COMMS_CONN_RELAY: result = 2; break;
default:
XP_ASSERT(0);
}
return result;
} /* conTypeToSel */
static CommsConnType
selToConType( XP_U16 sel )
selToConType( const ConnsDlgState* state, XP_U16 sel )
{
CommsConnType conType = COMMS_CONN_BT;
switch( sel ) {
case 0: /* conType = COMMS_CONN_BT; */break;
case 1: conType = COMMS_CONN_IR; break;
case 2: conType = COMMS_CONN_RELAY; break;
default: XP_ASSERT(0);
}
return conType;
XP_ASSERT( sel < state->nXports );
return state->xports[sel].conType;
} /* selToConType */
#ifdef XWFEATURE_BLUETOOTH
@ -220,6 +212,58 @@ browseForDeviceName( PalmAppGlobals* globals, ConnsDlgState* state )
} /* browseForDeviceName */
#endif
static void
setupXportList( PalmAppGlobals* globals, ConnsDlgState* state )
{
ListData* sLd = &state->sLd;
XP_U16 i;
XP_S16 selSel = -1;
const XP_UCHAR* selName = NULL;
if ( state->nXports >= 2 ) {
state->connTypesList = getActiveObjectPtr( XW_CONNS_TYPE_LIST_ID );
initListData( MPPARM(globals->mpool) sLd, state->nXports );
for ( i = 0; i < state->nXports; ++i ) {
const XP_UCHAR* xname = getResString( globals,
state->xports[i].resID );
addListTextItem( MPPARM(globals->mpool) sLd, xname );
if ( state->conType == state->xports[i].conType ) {
selName = xname;
selSel = i;
}
}
XP_ASSERT( !!selName );
setListSelection( sLd, selName );
setListChoices( sLd, state->connTypesList, NULL );
setSelectorFromList( XW_CONNS_TYPE_TRIGGER_ID, state->connTypesList,
selSel );
}
} /* setupXportList */
static void
buildXportData( ConnsDlgState* state )
{
#ifdef XWFEATURE_IR
state->xports[state->nXports].conType = COMMS_CONN_IR;
state->xports[state->nXports].resID = STR_IR_XPORTNAME;
++state->nXports;
#endif
#ifdef XWFEATURE_BLUETOOTH
state->xports[state->nXports].conType = COMMS_CONN_BT;
state->xports[state->nXports].resID = STR_BT_XPORTNAME;
++state->nXports;
#endif
#ifdef XWFEATURE_RELAY
state->xports[state->nXports].conType = COMMS_CONN_RELAY;
state->xports[state->nXports].resID = STR_RELAY_XPORTNAME;
++state->nXports;
#endif
XP_ASSERT( state->nXports >= 2 ); /* no need for dropdown otherwise!! */
}
Boolean
ConnsFormHandleEvent( EventPtr event )
{
@ -254,12 +298,8 @@ ConnsFormHandleEvent( EventPtr event )
ctlsFromState( globals, state );
/* setup connection popup */
state->connTypesList = getActiveObjectPtr( XW_CONNS_TYPE_LIST_ID );
XP_ASSERT( state->conType == COMMS_CONN_IR
|| state->conType == COMMS_CONN_RELAY
|| state->conType == COMMS_CONN_BT );
setSelectorFromList( XW_CONNS_TYPE_TRIGGER_ID, state->connTypesList,
conTypeToSel(state->conType) );
buildXportData( state );
setupXportList( globals, state );
updateFormCtls( form, state );
@ -286,7 +326,7 @@ ConnsFormHandleEvent( EventPtr event )
if ( chosen >= 0 ) {
setSelectorFromList( XW_CONNS_TYPE_TRIGGER_ID,
state->connTypesList, chosen );
state->conType = selToConType( chosen );
state->conType = selToConType( state, chosen );
updateFormCtls( form, state );
}
}

View file

@ -123,6 +123,7 @@
{ "STR_TOTALPLAYERS", "Total players" },
#ifdef XWFEATURE_RELAY
{ "STR_RELAY_XPORTNAME", "Internet" },
{ "STR_RELAY_TIMEOUT", "Relay error: Other devices failed to "
"connect." },
{ "STR_RELAY_LOST_OTHER", "Relay error: another device has lost its "
@ -130,7 +131,12 @@
{ "STR_RELAY_GENERIC", "Relay error: something's wrong." },
#endif
#ifdef XWFEATURE_IR
{ "STR_IR_XPORTNAME", "Beaming" },
#endif
#ifdef XWFEATURE_BLUETOOTH
{ "STR_BT_XPORTNAME", "Bluetooth" },
{ "STR_BT_NOINIT", "Bluetooth appears to be off. Please turn it "
"on if you want Crosswords to use it." },
{ "STRS_BT_NOHOST", "Bluetooth messages are not reaching Crosswords on %s. "
@ -158,6 +164,6 @@
"1610 NW 14th Place\n" \
"Corvallis, OR 97330 USA\n\n"
"Developed on Debian GNU/Linux using the prc-tools "\
"suite." \
"Thanks to Debian GNU/Linux for the development "\
"tools and to KT for the time." \
},

View file

@ -182,7 +182,7 @@ END
#define SERVER_HEIGHT 12
FORM ID XW_NEWGAMES_FORM AT (2 FORM_TOP 156 FORM_HEIGHT)
USABLE MODAL SAVEBEHIND DEFAULTBTNID XW_OK_BUTTON_ID
USABLE MODAL SAVEBEHIND DEFAULTBTNID XW_CANCEL_BUTTON_ID
BEGIN
TITLE "Game options"
@ -291,18 +291,13 @@ BEGIN
POPUPTRIGGER "" ID XW_CONNS_TYPE_TRIGGER_ID
AT (PREVRIGHT+5 PREVTOP 72 12) LEFTANCHOR
LIST
"Bluetooth" "Beaming" "Internet" ID XW_CONNS_TYPE_LIST_ID
PREVLEFT PREVTOP 72 12 VISIBLEITEMS 3
"" ID XW_CONNS_TYPE_LIST_ID
PREVLEFT PREVTOP 72 12 VISIBLEITEMS 2
NONUSABLE POPUPLIST XW_CONNS_TYPE_TRIGGER_ID XW_CONNS_TYPE_LIST_ID
/* Bluetooth stuff must be here even if XWFEATURE_BLUETOOTH is not defined
since, e.g. ARM and 68K share these resources yet may not both support
BT */
LABEL "No bluetooth on Arm (yet)." XW_CONNS_BT_NOTSUPPORT_LABEL_ID
AT ( LEFTCOL+10 LOCALIP_TOP ) NONUSABLE
#ifdef XWFEATURE_BLUETOOTH
LABEL "Host name:" XW_CONNS_BT_HOSTNAME_LABEL_ID
AT ( PREVLEFT PREVTOP+3 ) NONUSABLE
AT ( LEFTCOL LOCALIP_TOP ) NONUSABLE
SELECTORTRIGGER "Find host..." XW_CONNS_BT_HOSTTRIGGER_ID \
AT (CONNS_FIELD_LEFT PREVTOP 70 AUTO) NONUSABLE LEFTANCHOR
#endif
@ -323,9 +318,6 @@ BEGIN
AT ( LEFTCOL+10 PREVBOTTOM + 2 )
FIELD XW_CONNS_COOKIE_FIELD_ID CONNS_FIELD_LEFT PREVTOP 70 AUTO \
SINGLELINE EDITABLE UNDERLINED MAXCHARS 32
#else
LABEL "Connect via internet disabled" XW_CONNS_RELAY_LABEL_ID
AT ( LEFTCOL+10 LOCALIP_TOP )
#endif
BUTTON "Cancel" XW_CONNS_CANCEL_BUTTON_ID 42 75 AUTO AUTO

View file

@ -129,13 +129,6 @@ newGameHandleEvent( EventPtr event )
result = true;
break;
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
case connsSettingChgEvent:
XP_ASSERT( globals->isNewGame );
state->connsSettingChanged = XP_TRUE;
break;
#endif
#ifdef XWFEATURE_FIVEWAY
/* docs say to return HANDLED for both take and lost if the right
object */
@ -280,6 +273,10 @@ newGameHandleEvent( EventPtr event )
setNameThatFits( state );
break;
case appStopEvent: /* I get these on older palms */
unloadNewGameState( globals );
result = false;
default:
break;
}
@ -375,8 +372,8 @@ changeGadgetHilite( PalmAppGlobals* globals, UInt16 hiliteID )
#if defined XWFEATURE_BLUETOOTH || defined XWFEATURE_RELAY
/* Even if it didn't change, pop the connections form. It's only
informational in the non-new-game case; nothing can be changed. */
if ( hiliteID != SERVER_STANDALONE ) {
if ( isNewGame || hiliteID==globals->newGameState.curServerHilite ) {
if ( (hiliteID != SERVER_STANDALONE) && (state->nXPorts > 1) ) {
if ( isNewGame || (hiliteID==globals->newGameState.curServerHilite) ) {
PopupConnsForm( globals, hiliteID, &state->addr );
}
}
@ -669,6 +666,24 @@ handleRemoteChanged( PalmNewGameState* state, XP_U16 controlID, XP_Bool on )
}
#endif
XP_U16
countXPorts( const PalmAppGlobals* globals )
{
XP_U16 xports = 0;
#ifdef XWFEATURE_IR
++xports;
#endif
#ifdef XWFEATURE_BLUETOOTH
if ( globals->hasBTLib ) {
++xports;
}
#endif
#ifdef XWFEATURE_RELAY
++xports;
#endif
return xports;
}
static void
loadNewGameState( PalmAppGlobals* globals )
{
@ -677,7 +692,9 @@ loadNewGameState( PalmAppGlobals* globals )
state->dictName = copyString( globals->mpool, gi->dictName );
state->playerNumList = getActiveObjectPtr( XW_NPLAYERS_LIST_ID );
state->nXPorts = countXPorts( globals );
XP_ASSERT( !state->ngc );
state->ngc = newg_make( MPPARM(globals->mpool)
globals->isNewGame,
&globals->util,

View file

@ -194,15 +194,14 @@ frmObjId_2str( XP_U16 id )
CASESTR( XW_CONNS_OK_BUTTON_ID );
CASESTR( XW_CONNS_TYPE_TRIGGER_ID );
CASESTR( XW_CONNS_TYPE_LIST_ID );
CASESTR( XW_CONNS_RELAY_LABEL_ID );
#ifdef XWFEATURE_RELAY
CASESTR( XW_CONNS_RELAY_LABEL_ID );
CASESTR( XW_CONNS_COOKIE_FIELD_ID );
CASESTR( XW_CONNS_COOKIE_LABEL_ID );
CASESTR( XW_CONNS_PORT_LABEL_ID );
CASESTR( XW_CONNS_RELAY_FIELD_ID );
CASESTR( XW_CONNS_PORT_FIELD_ID );
#endif
CASESTR( XW_CONNS_BT_NOTSUPPORT_LABEL_ID );
#ifdef XWFEATURE_BLUETOOTH
CASESTR( XW_CONNS_BT_HOSTNAME_LABEL_ID );
CASESTR( XW_CONNS_BT_HOSTTRIGGER_ID );

View file

@ -219,19 +219,13 @@ romVersion( void )
{
UInt32 dwOSVer;
UInt16 result;
Err err;
FtrGet(sysFtrCreator, sysFtrNumROMVersion, &dwOSVer );
err = FtrGet(sysFtrCreator, sysFtrNumROMVersion, &dwOSVer );
XP_ASSERT( errNone == err );
/* should turn 3 and 5 into 35 */
result = (sysGetROMVerMajor(dwOSVer)*10) + sysGetROMVerMinor(dwOSVer);
/* Sprint Treo650 is returning 0036 */
#if defined XWFEATURE_BLUETOOTH && defined MEM_DEBUG
XP_ASSERT( errNone == FtrGet( sysFileCBtLib, btLibFeatureVersion, &dwOSVer ) );
XP_LOGF( "sysFileCBtLib version: %lx", dwOSVer );
/* Treo 700 on VWZ: sysFileCBtLib version: 00000003 */
/* Treo 650 on Sprint: sysFileCBtLib version: 00000001 */
#endif
return result;
} /* romVersion */
@ -984,8 +978,8 @@ initHighResGlobals( PalmAppGlobals* globals )
# ifndef hsFtrIDNavigationSupported
# define hsFtrIDNavigationSupported 14
# endif
/* sysFtrNumUIHardwareFlags unavailable on PalmOS 4 */
err = FtrGet( sysFtrCreator, sysFtrNumUIHardwareFlags, &vers );
XP_ASSERT( errNone == err );
globals->generatesKeyUp = ( (err == errNone) &&
((vers & sysFtrNumUIHardwareHasKbd) != 0) )
|| globals->isZodiac;
@ -1071,6 +1065,7 @@ startApplication( PalmAppGlobals** globalsP )
Boolean leftyFlag;
Int16 vers;
UInt32 ignore;
Err err;
MPSLOT;
#if defined FOR_GREMLINS
@ -1096,6 +1091,22 @@ startApplication( PalmAppGlobals** globalsP )
globals->runningOnPOSE = FtrGet( 'pose', 0, &ignore) != ftrErrNoSuchFeature;
#if defined XWFEATURE_BLUETOOTH
err = FtrGet( btLibFeatureCreator, btLibFeatureVersion, &ignore );
/* could expand the test to skip version 1 and the Treo650 :-) */
globals->hasBTLib = ftrErrNoSuchFeature != err;
# ifdef MEM_DEBUG
if ( errNone == err ) {
/* Sprint Treo650 is returning 0036 */
/* Treo 700 on VWZ: sysFileCBtLib version: 00000003 */
/* Treo 650 on Sprint: sysFileCBtLib version: 00000001 */
XP_LOGF( "sysFileCBtLib version: %lx", ignore );
} else {
XP_LOGF( "no sysFileCBtLib via FtrGet: OS too old?" );
}
# endif
#endif
globals->vtMgr = make_vtablemgr( MPPARM_NOCOMMA(globals->mpool) );
globals->romVersion = romVersion();
@ -3836,7 +3847,7 @@ palm_util_setTimer( XW_UtilCtxt* uc, XWTimerReason why,
now += PALM_TIMER_DELAY;
} else if ( why == TIMER_TIMERTICK ) {
now += SysTicksPerSecond();
#if defined XWFEATURE_RELAY || defined COMMS_HEARTBEAT
#if defined RELAY_HEARTBEAT || defined COMMS_HEARTBEAT
} else if ( why == TIMER_HEARTBEAT ) {
now += (secsFromNow * SysTicksPerSecond());
#endif

View file

@ -195,6 +195,7 @@ typedef struct PalmNewGameState {
FormPtr form;
ListPtr playerNumList;
NewGameCtx* ngc;
XP_U16 nXPorts;
XP_UCHAR passwds[MAX_PASSWORD_LENGTH+1][MAX_NUM_PLAYERS];
XP_UCHAR* dictName;
XP_UCHAR shortDictName[32]; /* as long as a dict name can be */
@ -203,7 +204,6 @@ typedef struct PalmNewGameState {
DeviceRole curServerHilite;
#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH || defined XWFEATURE_IR
CommsAddrRec addr;
XP_Bool connsSettingChanged;
#endif
} PalmNewGameState;
@ -287,6 +287,7 @@ struct PalmAppGlobals {
#endif
#ifdef XWFEATURE_BLUETOOTH
XP_Bool userCancelledBT;
XP_Bool hasBTLib;
#endif
GraphicsAbility able;

View file

@ -242,7 +242,7 @@ initListData( MPFORMAL ListData* ld, XP_U16 nItems )
} /* initListData */
void
addListTextItem( MPFORMAL ListData* ld, XP_UCHAR* txt )
addListTextItem( MPFORMAL ListData* ld, const XP_UCHAR* txt )
{
XP_U16 curLen = ld->storageLen;
XP_U16 strLen = XP_STRLEN( txt ) + 1; /* null byte */
@ -289,7 +289,7 @@ setListChoices( ListData* ld, ListPtr list, void* closure )
* no harm in calling it again.
****************************************************************************/
void
setListSelection( ListData* ld, char* selName )
setListSelection( ListData* ld, const char* selName )
{
ld->selIndex = 0;
XP_ASSERT( !ld->choicesSet );
@ -520,7 +520,6 @@ drawGadgetsFromList( ListPtr list, XP_U16 idLow, XP_U16 idHigh,
XP_U16 hiliteItem )
{
XP_U16 i;
LOG_FUNC();
XP_ASSERT( idLow <= idHigh );
for ( i = 0; idLow <= idHigh; ++i, ++idLow ) {
@ -528,7 +527,6 @@ drawGadgetsFromList( ListPtr list, XP_U16 idLow, XP_U16 idHigh,
Boolean hilite = idLow == hiliteItem;
drawOneGadget( idLow, text, hilite );
}
LOG_RETURN_VOID();
} /* drawGadgetsFromList */
void

View file

@ -55,13 +55,16 @@ void setBooleanCtrl( UInt16 objectID, Boolean isSet );
Boolean getBooleanCtrl( UInt16 objectID );
void setFieldStr( XP_U16 id, const XP_UCHAR* buf );
#ifdef XWFEATURE_RELAY
void getFieldStr( XP_U16 id, XP_UCHAR* buf, XP_U16 max );
#endif
void setFieldEditable( UInt16 objectID, Boolean editable );
/* list item stuff */
void initListData( MPFORMAL ListData* ld, XP_U16 nItems );
void addListTextItem( MPFORMAL ListData* ld, XP_UCHAR* txt );
void addListTextItem( MPFORMAL ListData* ld, const XP_UCHAR* txt );
void setListChoices( ListData* ld, ListPtr list, void* closure );
void setListSelection( ListData* ld, char* selName );
void setListSelection( ListData* ld, const char* selName );
void sortList( ListData* ld );
void freeListData( MPFORMAL ListData* ld );

View file

@ -342,8 +342,8 @@
#define XW_CONNS_OK_BUTTON_ID 2901
#define XW_CONNS_TYPE_TRIGGER_ID 2902
#define XW_CONNS_TYPE_LIST_ID 2903
#define XW_CONNS_RELAY_LABEL_ID 2904
#ifdef XWFEATURE_RELAY
# define XW_CONNS_RELAY_LABEL_ID 2904
# define XW_CONNS_COOKIE_FIELD_ID 2905
# define XW_CONNS_COOKIE_LABEL_ID 2906
# define XW_CONNS_PORT_LABEL_ID 2907
@ -351,7 +351,6 @@
# define XW_CONNS_PORT_FIELD_ID 2909
#endif
#define XW_CONNS_BT_NOTSUPPORT_LABEL_ID 2910
#ifdef XWFEATURE_BLUETOOTH
# define XW_CONNS_BT_HOSTNAME_LABEL_ID 2911
# define XW_CONNS_BT_HOSTTRIGGER_ID 2912