Trying to improve profile handling
This commit is contained in:
parent
40a0ce9faa
commit
28843108cd
|
@ -37,6 +37,7 @@ typedef struct _PhonePluginHelper
|
||||||
char const * variable);
|
char const * variable);
|
||||||
int (*config_set)(Phone * phone, char const * section,
|
int (*config_set)(Phone * phone, char const * section,
|
||||||
char const * variable, char const * value);
|
char const * variable, char const * value);
|
||||||
|
int (*confirm)(Phone * phone, char const * message);
|
||||||
int (*error)(Phone * phone, char const * message, int ret);
|
int (*error)(Phone * phone, char const * message, int ret);
|
||||||
void (*about_dialog)(Phone * phone);
|
void (*about_dialog)(Phone * phone);
|
||||||
int (*event)(Phone * phone, PhoneEvent * event);
|
int (*event)(Phone * phone, PhoneEvent * event);
|
||||||
|
|
16
src/phone.c
16
src/phone.c
|
@ -302,6 +302,8 @@ static int _phone_confirm(Phone * phone, GtkWidget * window,
|
||||||
char const * message);
|
char const * message);
|
||||||
static int _phone_error(GtkWidget * window, char const * message, int ret);
|
static int _phone_error(GtkWidget * window, char const * message, int ret);
|
||||||
|
|
||||||
|
static int _phone_helper_confirm(Phone * phone, char const * message);
|
||||||
|
|
||||||
static void _phone_info(Phone * phone, GtkWidget * window, char const * message,
|
static void _phone_info(Phone * phone, GtkWidget * window, char const * message,
|
||||||
GCallback callback);
|
GCallback callback);
|
||||||
|
|
||||||
|
@ -398,6 +400,7 @@ Phone * phone_new(char const * plugin, int retry)
|
||||||
phone->helper.config_foreach = _phone_config_foreach;
|
phone->helper.config_foreach = _phone_config_foreach;
|
||||||
phone->helper.config_get = _phone_config_get;
|
phone->helper.config_get = _phone_config_get;
|
||||||
phone->helper.config_set = _phone_config_set;
|
phone->helper.config_set = _phone_config_set;
|
||||||
|
phone->helper.confirm = _phone_helper_confirm;
|
||||||
phone->helper.error = phone_error;
|
phone->helper.error = phone_error;
|
||||||
phone->helper.about_dialog = _phone_about;
|
phone->helper.about_dialog = _phone_about;
|
||||||
phone->helper.event = phone_event;
|
phone->helper.event = phone_event;
|
||||||
|
@ -3310,10 +3313,12 @@ static int _phone_confirm(Phone * phone, GtkWidget * window,
|
||||||
char const * message)
|
char const * message)
|
||||||
{
|
{
|
||||||
GtkWidget * dialog;
|
GtkWidget * dialog;
|
||||||
|
GtkWindow * w = (window != NULL) ? GTK_WINDOW(window) : NULL;
|
||||||
|
int flags = (window != NULL)
|
||||||
|
? GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT : 0;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
|
dialog = gtk_message_dialog_new(w, flags,
|
||||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
||||||
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
|
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
|
||||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||||
"%s", _("Question"));
|
"%s", _("Question"));
|
||||||
|
@ -3352,6 +3357,13 @@ static int _phone_error(GtkWidget * window, char const * message, int ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* phone_helper_confirm */
|
||||||
|
static int _phone_helper_confirm(Phone * phone, char const * message)
|
||||||
|
{
|
||||||
|
return _phone_confirm(phone, NULL, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* phone_info */
|
/* phone_info */
|
||||||
static void _phone_info(Phone * phone, GtkWidget * window, char const * message,
|
static void _phone_info(Phone * phone, GtkWidget * window, char const * message,
|
||||||
GCallback callback)
|
GCallback callback)
|
||||||
|
|
|
@ -38,6 +38,15 @@
|
||||||
/* Profiles */
|
/* Profiles */
|
||||||
/* private */
|
/* private */
|
||||||
/* types */
|
/* types */
|
||||||
|
typedef enum _ProfileType
|
||||||
|
{
|
||||||
|
PROFILE_TYPE_GENERAL = 0,
|
||||||
|
PROFILE_TYPE_SILENT,
|
||||||
|
PROFILE_TYPE_OFFLINE
|
||||||
|
} ProfileType;
|
||||||
|
#define PROFILE_TYPE_LAST PROFILE_TYPE_OFFLINE
|
||||||
|
#define PROFILE_TYPE_COUNT (PROFILE_TYPE_LAST + 1)
|
||||||
|
|
||||||
typedef enum _ProfileVolume
|
typedef enum _ProfileVolume
|
||||||
{
|
{
|
||||||
PROFILE_VOLUME_SILENT = 0,
|
PROFILE_VOLUME_SILENT = 0,
|
||||||
|
@ -82,7 +91,7 @@ typedef struct _Profiles
|
||||||
} Profiles;
|
} Profiles;
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
static ProfileDefinition _profiles_definitions[] =
|
static ProfileDefinition _profiles_definitions[PROFILE_TYPE_COUNT] =
|
||||||
{
|
{
|
||||||
{ "General", TRUE, PROFILE_VOLUME_ASC, TRUE },
|
{ "General", TRUE, PROFILE_VOLUME_ASC, TRUE },
|
||||||
{ "Silent", TRUE, PROFILE_VOLUME_SILENT, TRUE },
|
{ "Silent", TRUE, PROFILE_VOLUME_SILENT, TRUE },
|
||||||
|
@ -90,11 +99,15 @@ static ProfileDefinition _profiles_definitions[] =
|
||||||
};
|
};
|
||||||
|
|
||||||
/* prototypes */
|
/* prototypes */
|
||||||
|
/* plug-in */
|
||||||
static int _profiles_init(PhonePlugin * plugin);
|
static int _profiles_init(PhonePlugin * plugin);
|
||||||
static void _profiles_destroy(PhonePlugin * plugin);
|
static void _profiles_destroy(PhonePlugin * plugin);
|
||||||
static int _profiles_event(PhonePlugin * plugin, PhoneEvent * event);
|
static int _profiles_event(PhonePlugin * plugin, PhoneEvent * event);
|
||||||
static void _profiles_settings(PhonePlugin * plugin);
|
static void _profiles_settings(PhonePlugin * plugin);
|
||||||
|
|
||||||
|
/* useful */
|
||||||
|
static void _profile_switch(PhonePlugin * plugin, ProfileType type);
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
/* public */
|
||||||
/* variables */
|
/* variables */
|
||||||
|
@ -212,6 +225,7 @@ static void _profiles_destroy(PhonePlugin * plugin)
|
||||||
/* profiles_event */
|
/* profiles_event */
|
||||||
static int _event_key_tone(PhonePlugin * plugin);
|
static int _event_key_tone(PhonePlugin * plugin);
|
||||||
static int _event_starting(PhonePlugin * plugin);
|
static int _event_starting(PhonePlugin * plugin);
|
||||||
|
static int _event_stopping(PhonePlugin * plugin);
|
||||||
#if 0
|
#if 0
|
||||||
static void _event_call_incoming_do(PhonePlugin * plugin);
|
static void _event_call_incoming_do(PhonePlugin * plugin);
|
||||||
static gboolean _event_call_incoming_timeout(gpointer data);
|
static gboolean _event_call_incoming_timeout(gpointer data);
|
||||||
|
@ -231,6 +245,8 @@ static int _profiles_event(PhonePlugin * plugin, PhoneEvent * event)
|
||||||
return _event_key_tone(plugin);
|
return _event_key_tone(plugin);
|
||||||
case PHONE_EVENT_TYPE_STARTING:
|
case PHONE_EVENT_TYPE_STARTING:
|
||||||
return _event_starting(plugin);
|
return _event_starting(plugin);
|
||||||
|
case PHONE_EVENT_TYPE_STOPPING:
|
||||||
|
return _event_stopping(plugin);
|
||||||
#if 0
|
#if 0
|
||||||
case PHONE_EVENT_TYPE_SMS_RECEIVED:
|
case PHONE_EVENT_TYPE_SMS_RECEIVED:
|
||||||
if(profiles->pao == NULL)
|
if(profiles->pao == NULL)
|
||||||
|
@ -280,32 +296,30 @@ static int _event_key_tone(PhonePlugin * plugin)
|
||||||
|
|
||||||
static int _event_starting(PhonePlugin * plugin)
|
static int _event_starting(PhonePlugin * plugin)
|
||||||
{
|
{
|
||||||
|
PhonePluginHelper * helper = plugin->helper;
|
||||||
Profiles * profiles = plugin->priv;
|
Profiles * profiles = plugin->priv;
|
||||||
ProfileDefinition * definition = &profiles->profiles[
|
ProfileDefinition * definition = &profiles->profiles[
|
||||||
profiles->profiles_cur];
|
profiles->profiles_cur];
|
||||||
GtkWidget * dialog;
|
|
||||||
int res;
|
|
||||||
|
|
||||||
if(definition->online)
|
if(definition->online)
|
||||||
return 0;
|
return 0;
|
||||||
dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION,
|
if(helper->confirm(helper->phone, "You are currently offline.\n"
|
||||||
GTK_BUTTONS_YES_NO,
|
"Do you want to go online?") == 0)
|
||||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
|
||||||
"%s", "Question");
|
|
||||||
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
|
|
||||||
#endif
|
|
||||||
"%s", "You are currently offline."
|
|
||||||
" Do you want to go online?");
|
|
||||||
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
||||||
gtk_widget_destroy(dialog);
|
|
||||||
if(res != GTK_RESPONSE_YES)
|
|
||||||
return 1;
|
return 1;
|
||||||
profiles->profiles_cur = 0;
|
_profile_switch(plugin, 0);
|
||||||
plugin->helper->config_set(plugin->helper->phone, "profiles", "default",
|
|
||||||
profiles->profiles[profiles->profiles_cur].name);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _event_stopping(PhonePlugin * plugin)
|
||||||
|
{
|
||||||
|
Profiles * profiles = plugin->priv;
|
||||||
|
ProfileDefinition * definition = &profiles->profiles[
|
||||||
|
profiles->profiles_cur];
|
||||||
|
|
||||||
|
/* prevent stopping the modem except if we're going offline */
|
||||||
|
return definition->online ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
static void _event_call_incoming_do(PhonePlugin * plugin)
|
static void _event_call_incoming_do(PhonePlugin * plugin)
|
||||||
{
|
{
|
||||||
|
@ -522,3 +536,18 @@ static void _on_settings_ok(gpointer data)
|
||||||
plugin->helper->request(plugin->helper->phone, &request);
|
plugin->helper->request(plugin->helper->phone, &request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* profile_switch */
|
||||||
|
static void _profile_switch(PhonePlugin * plugin, ProfileType type)
|
||||||
|
{
|
||||||
|
PhonePluginHelper * helper = plugin->helper;
|
||||||
|
Profiles * profiles = plugin->priv;
|
||||||
|
|
||||||
|
if(type > profiles->profiles_cnt)
|
||||||
|
/* XXX report error */
|
||||||
|
return;
|
||||||
|
profiles->profiles_cur = type;
|
||||||
|
helper->config_set(helper->phone, "profiles", "default",
|
||||||
|
profiles->profiles[profiles->profiles_cur].name);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user