mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
progress on inviting via SMS
This commit is contained in:
parent
1b5bda5da8
commit
5f97f8197c
8 changed files with 193 additions and 3 deletions
|
@ -177,6 +177,7 @@ GTK_OBJS = \
|
|||
$(BUILD_PLAT_DIR)/gtkboard.o \
|
||||
$(BUILD_PLAT_DIR)/gtkdraw.o \
|
||||
$(BUILD_PLAT_DIR)/gtkask.o \
|
||||
$(BUILD_PLAT_DIR)/gtkaskm.o \
|
||||
$(BUILD_PLAT_DIR)/gtkletterask.o \
|
||||
$(BUILD_PLAT_DIR)/gtkpasswdask.o \
|
||||
$(BUILD_PLAT_DIR)/gtknewgame.o \
|
||||
|
|
|
@ -52,6 +52,7 @@ void deleteGame( sqlite3* pDb, sqlite3_int64 rowid );
|
|||
|
||||
#define KEY_RDEVID "RDEVID"
|
||||
#define KEY_LDEVID "LDEVID"
|
||||
#define KEY_SMSPHONE "SMSPHONE"
|
||||
|
||||
void db_store( sqlite3* dbp, const gchar* key, const gchar* value );
|
||||
XP_Bool db_fetch( sqlite3* dbp, const gchar* key, gchar* buf, gint buflen );
|
||||
|
|
92
xwords4/linux/gtkaskm.c
Normal file
92
xwords4/linux/gtkaskm.c
Normal file
|
@ -0,0 +1,92 @@
|
|||
/* -*-mode: C; fill-column: 78; compile-command: "make MEMDEBUG=TRUE"; -*- */
|
||||
|
||||
/*
|
||||
* Copyright 2013 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifdef PLATFORM_GTK
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "gtkaskm.h"
|
||||
#include "gtkutils.h"
|
||||
|
||||
typedef struct _AskMState {
|
||||
GtkWidget* okButton;
|
||||
GtkWidget* cancelButton;
|
||||
gboolean cancelled;
|
||||
} AskMState;
|
||||
|
||||
static void
|
||||
button_clicked( GtkWidget* widget, gpointer closure )
|
||||
{
|
||||
AskMState* state = (AskMState*)closure;
|
||||
state->cancelled = widget == state->cancelButton;
|
||||
XP_LOGF( "%s: cancelled = %d", __func__, state->cancelled );
|
||||
gtk_main_quit();
|
||||
}
|
||||
|
||||
XP_Bool
|
||||
gtkaskm( const gchar* message, AskMInfo* infos, int nInfos )
|
||||
{
|
||||
AskMState state = {0};
|
||||
GtkWidget* dialog = gtk_dialog_new();
|
||||
GtkWidget* fields[nInfos];
|
||||
gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE );
|
||||
|
||||
gtk_window_set_title( GTK_WINDOW(dialog), message );
|
||||
|
||||
int ii;
|
||||
GtkWidget* vbox = gtk_vbox_new( FALSE, 0 );
|
||||
for ( ii = 0; ii < nInfos; ++ii ) {
|
||||
AskMInfo* info = &infos[ii];
|
||||
GtkWidget* row = makeLabeledField( info->label, &fields[ii] );
|
||||
gtk_box_pack_start( GTK_BOX(vbox), row, FALSE, TRUE, 0 );
|
||||
gtk_widget_show( row );
|
||||
}
|
||||
|
||||
GtkWidget* hbox = gtk_hbox_new( FALSE, 0 );
|
||||
state.okButton = gtk_button_new_with_label( "Ok" );
|
||||
g_signal_connect( GTK_OBJECT(state.okButton), "clicked",
|
||||
G_CALLBACK(button_clicked), &state );
|
||||
gtk_box_pack_start( GTK_BOX(hbox), state.okButton, FALSE, TRUE, 0 );
|
||||
state.cancelButton = gtk_button_new_with_label( "Cancel" );
|
||||
g_signal_connect( GTK_OBJECT(state.cancelButton), "clicked",
|
||||
G_CALLBACK(button_clicked), &state );
|
||||
gtk_box_pack_start( GTK_BOX(hbox), state.cancelButton, FALSE, TRUE, 0 );
|
||||
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
|
||||
|
||||
gtk_container_add( GTK_CONTAINER( GTK_DIALOG(dialog)->action_area), vbox);
|
||||
gtk_widget_show_all( dialog );
|
||||
|
||||
gtk_main();
|
||||
|
||||
if ( !state.cancelled ) {
|
||||
for ( ii = 0; ii < nInfos; ++ii ) {
|
||||
const gchar* txt = gtk_entry_get_text( GTK_ENTRY(fields[ii]) );
|
||||
XP_LOGF( "%s: got text %s", __func__, txt );
|
||||
AskMInfo* info = &infos[ii];
|
||||
*info->result = g_strdup( txt );
|
||||
}
|
||||
}
|
||||
|
||||
gtk_widget_destroy( dialog );
|
||||
|
||||
return !state.cancelled;
|
||||
// return response == GTK_RESPONSE_OK || response == GTK_RESPONSE_YES;
|
||||
} /* gtkask */
|
||||
|
||||
#endif
|
38
xwords4/linux/gtkaskm.h
Normal file
38
xwords4/linux/gtkaskm.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
|
||||
/*
|
||||
* Copyright 2000 by Eric House (xwords@eehouse.org). All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifdef PLATFORM_GTK
|
||||
|
||||
#ifndef _GTKASKM_H_
|
||||
#define _GTKASKM_H_
|
||||
|
||||
#include "gtkboard.h"
|
||||
|
||||
/* Returns true for "yes" or "ok" answer, false otherwise.
|
||||
*/
|
||||
typedef struct _AskMInfo {
|
||||
const char* label;
|
||||
gchar** result;
|
||||
} AskMInfo;
|
||||
|
||||
XP_Bool gtkaskm( const gchar *message, AskMInfo* infos, int nInfos );
|
||||
|
||||
#endif
|
||||
#endif /* PLATFORM_GTK */
|
|
@ -54,6 +54,7 @@
|
|||
#include "draw.h"
|
||||
#include "game.h"
|
||||
#include "gtkask.h"
|
||||
#include "gtkaskm.h"
|
||||
#include "gtkchat.h"
|
||||
#include "gtknewgame.h"
|
||||
#include "gtkletterask.h"
|
||||
|
@ -1454,7 +1455,35 @@ handle_commit_button( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
|
|||
static void
|
||||
handle_invite_button( GtkWidget* XP_UNUSED(widget), GtkGameGlobals* globals )
|
||||
{
|
||||
XP_USE( globals );
|
||||
CommsAddrRec addr;
|
||||
CommsCtxt* comms = globals->cGlobals.game.comms;
|
||||
XP_ASSERT( comms );
|
||||
comms_getAddr( comms, &addr );
|
||||
switch ( comms_getConType( comms ) ) {
|
||||
#ifdef XWFEATURE_SMS
|
||||
case COMMS_CONN_SMS: {
|
||||
gchar* phone = NULL;
|
||||
gchar* portstr = NULL;
|
||||
AskMInfo infos[] = {
|
||||
{ "Remote phone#", &phone },
|
||||
{ "Remote port", &portstr },
|
||||
};
|
||||
if ( gtkaskm( "Invite whom?", infos, VSIZE(infos) ) ) {
|
||||
int port = atoi( portstr );
|
||||
XP_LOGF( "need to invite using number %s and port %d", phone, port );
|
||||
XP_ASSERT( 0 != port );
|
||||
linux_sms2_invite( globals->cGlobals.params,
|
||||
globals->cGlobals.gi, phone, port );
|
||||
}
|
||||
g_free( phone );
|
||||
g_free( portstr );
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
XP_ASSERT( 0 );
|
||||
break;
|
||||
}
|
||||
} /* handle_commit_button */
|
||||
|
||||
static void
|
||||
|
|
|
@ -609,7 +609,14 @@ gtkmain( LaunchParams* params )
|
|||
}
|
||||
|
||||
#ifdef XWFEATURE_SMS
|
||||
if ( !!params->connInfo.sms.phone ) {
|
||||
gchar buf[32];
|
||||
const gchar* phone = params->connInfo.sms.phone;
|
||||
if ( !!phone ) {
|
||||
db_store( params->pDb, KEY_SMSPHONE, phone );
|
||||
} else if ( !phone && db_fetch( params->pDb, KEY_SMSPHONE, buf, VSIZE(buf) ) ) {
|
||||
phone = buf;
|
||||
}
|
||||
if ( !!phone ) {
|
||||
SMSProcs smsProcs = {
|
||||
.socketChanged = gtkSocketChanged,
|
||||
};
|
||||
|
@ -625,7 +632,9 @@ gtkmain( LaunchParams* params )
|
|||
|
||||
closeGamesDB( params->pDb );
|
||||
relaycon_cleanup( params );
|
||||
|
||||
#ifdef XWFEATURE_SMS
|
||||
linux_sms2_cleanup( params );
|
||||
#endif
|
||||
return 0;
|
||||
} /* gtkmain */
|
||||
|
||||
|
|
|
@ -415,6 +415,23 @@ linux_sms2_init( LaunchParams* params, const SMSProcs* procs,
|
|||
(*procs->socketChanged)( procClosure, fd, -1, sms2_receive, params );
|
||||
} /* linux_sms2_init */
|
||||
|
||||
void
|
||||
linux_sms2_invite( LaunchParams* params, const CurGameInfo* info, const gchar* phone,
|
||||
int port )
|
||||
{
|
||||
LOG_FUNC();
|
||||
XP_USE( params );
|
||||
XP_USE( info );
|
||||
XP_USE( phone );
|
||||
XP_USE( port );
|
||||
}
|
||||
|
||||
void
|
||||
linux_sms2_cleanup( LaunchParams* params )
|
||||
{
|
||||
XP_FREEP( params->mpool, ¶ms->sms2Storage );
|
||||
}
|
||||
|
||||
static LinSMS2Data*
|
||||
getStorage( LaunchParams* params )
|
||||
{
|
||||
|
|
|
@ -46,6 +46,9 @@ typedef struct _SMSProcs {
|
|||
|
||||
void linux_sms2_init( LaunchParams* params, const SMSProcs* procs,
|
||||
void* procClosure );
|
||||
void linux_sms2_invite( LaunchParams* params, const CurGameInfo* info, const gchar* phone,
|
||||
int port );
|
||||
void linux_sms2_cleanup( LaunchParams* params );
|
||||
|
||||
#endif /* XWFEATURE_SMS */
|
||||
#endif /* #ifndef _LINUXSMS_H_ */
|
||||
|
|
Loading…
Add table
Reference in a new issue