Began to implement a debugging mode
This commit is contained in:
parent
d2b8972d76
commit
e3ae841bf0
102
src/phone.c
102
src/phone.c
@ -95,6 +95,12 @@ struct _Phone
|
||||
GtkListStore * co_store;
|
||||
GtkWidget * co_view;
|
||||
|
||||
#ifdef DEBUG
|
||||
/* debugging */
|
||||
GtkWidget * de_window;
|
||||
GtkWidget * de_gsm;
|
||||
#endif
|
||||
|
||||
/* dialer */
|
||||
GtkWidget * di_window;
|
||||
GtkWidget * di_entry;
|
||||
@ -154,6 +160,12 @@ static gboolean _phone_timeout_track(gpointer data);
|
||||
|
||||
|
||||
/* public */
|
||||
#ifdef DEBUG
|
||||
/* prototypes */
|
||||
void phone_show_debug(Phone * phone, gboolean show);
|
||||
|
||||
|
||||
#endif
|
||||
/* functions */
|
||||
/* phone_new */
|
||||
static gboolean _new_idle(gpointer data);
|
||||
@ -190,6 +202,9 @@ Phone * phone_new(char const * device, unsigned int baudrate, int retry,
|
||||
phone->co_window = NULL;
|
||||
phone->co_store = gtk_list_store_new(3, G_TYPE_UINT, G_TYPE_STRING,
|
||||
G_TYPE_STRING);
|
||||
#ifdef DEBUG
|
||||
phone->de_window = NULL;
|
||||
#endif
|
||||
phone->di_window = NULL;
|
||||
phone->me_window = NULL;
|
||||
phone->me_store = gtk_list_store_new(2, G_TYPE_UINT, G_TYPE_STRING);
|
||||
@ -238,6 +253,9 @@ static gboolean _new_idle(gpointer data)
|
||||
|
||||
phone_show_call(phone, FALSE);
|
||||
phone_show_contacts(phone, FALSE);
|
||||
#ifdef DEBUG
|
||||
phone_show_debug(phone, TRUE);
|
||||
#endif
|
||||
phone_show_dialer(phone, FALSE);
|
||||
phone_show_messages(phone, FALSE);
|
||||
phone_show_write(phone, FALSE);
|
||||
@ -771,6 +789,90 @@ void phone_show_contacts(Phone * phone, gboolean show)
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
/* phone_show_debug */
|
||||
static struct
|
||||
{
|
||||
char const * name;
|
||||
int (*callback)(GSM * gsm);
|
||||
} _debug_gsm_commands[] =
|
||||
{
|
||||
{ "Answer call", gsm_call_answer },
|
||||
{ "Contact list", gsm_fetch_contact_list },
|
||||
{ "Hangup call", gsm_call_hangup },
|
||||
{ "Message list", gsm_fetch_message_list },
|
||||
{ "Operator", gsm_fetch_operator },
|
||||
{ "Phone active", gsm_is_phone_active },
|
||||
{ "Phone functional", gsm_is_functional },
|
||||
{ "Registered", gsm_is_registered },
|
||||
{ "Registration", gsm_fetch_registration },
|
||||
{ "Signal level", gsm_fetch_signal_level },
|
||||
{ "SIM PIN status", gsm_is_pin_needed },
|
||||
{ "SIM PIN valid", gsm_is_pin_valid },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
static void _on_debug_gsm_execute(gpointer data);
|
||||
|
||||
void phone_show_debug(Phone * phone, gboolean show)
|
||||
{
|
||||
GtkWidget * vbox;
|
||||
GtkWidget * hbox;
|
||||
GtkWidget * widget;
|
||||
size_t i;
|
||||
|
||||
if(phone->de_window == NULL)
|
||||
{
|
||||
phone->de_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_default_size(GTK_WINDOW(phone->de_window), 200,
|
||||
300);
|
||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||
gtk_window_set_icon_name(GTK_WINDOW(phone->de_window),
|
||||
"stock_compile");
|
||||
#endif
|
||||
gtk_window_set_title(GTK_WINDOW(phone->de_window), "Debugging");
|
||||
vbox = gtk_vbox_new(FALSE, 0);
|
||||
/* gsm commands */
|
||||
hbox = gtk_hbox_new(FALSE, 0);
|
||||
phone->de_gsm = gtk_combo_box_new_text();
|
||||
for(i = 0; _debug_gsm_commands[i].name != NULL; i++)
|
||||
gtk_combo_box_append_text(GTK_COMBO_BOX(phone->de_gsm),
|
||||
_debug_gsm_commands[i].name);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), phone->de_gsm, TRUE, TRUE, 4);
|
||||
widget = gtk_button_new_from_stock(GTK_STOCK_EXECUTE);
|
||||
gtk_button_set_relief(GTK_BUTTON(widget), GTK_RELIEF_NONE);
|
||||
g_signal_connect_swapped(G_OBJECT(widget), "clicked",
|
||||
G_CALLBACK(_on_debug_gsm_execute), phone);
|
||||
gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 4);
|
||||
gtk_container_add(GTK_CONTAINER(phone->de_window), vbox);
|
||||
gtk_widget_show_all(vbox);
|
||||
}
|
||||
if(show)
|
||||
gtk_window_present(GTK_WINDOW(phone->de_window));
|
||||
else
|
||||
gtk_widget_hide(phone->de_window);
|
||||
}
|
||||
|
||||
static void _on_debug_gsm_execute(gpointer data)
|
||||
{
|
||||
Phone * phone = data;
|
||||
gchar * text;
|
||||
size_t i;
|
||||
|
||||
if((text = gtk_combo_box_get_active_text(GTK_COMBO_BOX(phone->de_gsm)))
|
||||
== NULL)
|
||||
return;
|
||||
for(i = 0; _debug_gsm_commands[i].name != NULL; i++)
|
||||
if(strcmp(_debug_gsm_commands[i].name, text) == 0)
|
||||
break;
|
||||
g_free(text);
|
||||
if(_debug_gsm_commands[i].callback != NULL)
|
||||
_debug_gsm_commands[i].callback(phone->gsm);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* phone_show_dialer */
|
||||
void phone_show_dialer(Phone * phone, gboolean show)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user