Trying to improve profile handling
This commit is contained in:
parent
40a0ce9faa
commit
28843108cd
|
@ -37,6 +37,7 @@ typedef struct _PhonePluginHelper
|
|||
char const * variable);
|
||||
int (*config_set)(Phone * phone, char const * section,
|
||||
char const * variable, char const * value);
|
||||
int (*confirm)(Phone * phone, char const * message);
|
||||
int (*error)(Phone * phone, char const * message, int ret);
|
||||
void (*about_dialog)(Phone * phone);
|
||||
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);
|
||||
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,
|
||||
GCallback callback);
|
||||
|
||||
|
@ -398,6 +400,7 @@ Phone * phone_new(char const * plugin, int retry)
|
|||
phone->helper.config_foreach = _phone_config_foreach;
|
||||
phone->helper.config_get = _phone_config_get;
|
||||
phone->helper.config_set = _phone_config_set;
|
||||
phone->helper.confirm = _phone_helper_confirm;
|
||||
phone->helper.error = phone_error;
|
||||
phone->helper.about_dialog = _phone_about;
|
||||
phone->helper.event = phone_event;
|
||||
|
@ -3310,10 +3313,12 @@ static int _phone_confirm(Phone * phone, GtkWidget * window,
|
|||
char const * message)
|
||||
{
|
||||
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;
|
||||
|
||||
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
|
||||
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
dialog = gtk_message_dialog_new(w, flags,
|
||||
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
|
||||
#if GTK_CHECK_VERSION(2, 6, 0)
|
||||
"%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 */
|
||||
static void _phone_info(Phone * phone, GtkWidget * window, char const * message,
|
||||
GCallback callback)
|
||||
|
|
|
@ -38,6 +38,15 @@
|
|||
/* Profiles */
|
||||
/* private */
|
||||
/* 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
|
||||
{
|
||||
PROFILE_VOLUME_SILENT = 0,
|
||||
|
@ -82,7 +91,7 @@ typedef struct _Profiles
|
|||
} Profiles;
|
||||
|
||||
/* variables */
|
||||
static ProfileDefinition _profiles_definitions[] =
|
||||
static ProfileDefinition _profiles_definitions[PROFILE_TYPE_COUNT] =
|
||||
{
|
||||
{ "General", TRUE, PROFILE_VOLUME_ASC, TRUE },
|
||||
{ "Silent", TRUE, PROFILE_VOLUME_SILENT, TRUE },
|
||||
|
@ -90,11 +99,15 @@ static ProfileDefinition _profiles_definitions[] =
|
|||
};
|
||||
|
||||
/* prototypes */
|
||||
/* plug-in */
|
||||
static int _profiles_init(PhonePlugin * plugin);
|
||||
static void _profiles_destroy(PhonePlugin * plugin);
|
||||
static int _profiles_event(PhonePlugin * plugin, PhoneEvent * event);
|
||||
static void _profiles_settings(PhonePlugin * plugin);
|
||||
|
||||
/* useful */
|
||||
static void _profile_switch(PhonePlugin * plugin, ProfileType type);
|
||||
|
||||
|
||||
/* public */
|
||||
/* variables */
|
||||
|
@ -212,6 +225,7 @@ static void _profiles_destroy(PhonePlugin * plugin)
|
|||
/* profiles_event */
|
||||
static int _event_key_tone(PhonePlugin * plugin);
|
||||
static int _event_starting(PhonePlugin * plugin);
|
||||
static int _event_stopping(PhonePlugin * plugin);
|
||||
#if 0
|
||||
static void _event_call_incoming_do(PhonePlugin * plugin);
|
||||
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);
|
||||
case PHONE_EVENT_TYPE_STARTING:
|
||||
return _event_starting(plugin);
|
||||
case PHONE_EVENT_TYPE_STOPPING:
|
||||
return _event_stopping(plugin);
|
||||
#if 0
|
||||
case PHONE_EVENT_TYPE_SMS_RECEIVED:
|
||||
if(profiles->pao == NULL)
|
||||
|
@ -280,32 +296,30 @@ static int _event_key_tone(PhonePlugin * plugin)
|
|||
|
||||
static int _event_starting(PhonePlugin * plugin)
|
||||
{
|
||||
PhonePluginHelper * helper = plugin->helper;
|
||||
Profiles * profiles = plugin->priv;
|
||||
ProfileDefinition * definition = &profiles->profiles[
|
||||
profiles->profiles_cur];
|
||||
GtkWidget * dialog;
|
||||
int res;
|
||||
|
||||
if(definition->online)
|
||||
return 0;
|
||||
dialog = gtk_message_dialog_new(NULL, 0, GTK_MESSAGE_QUESTION,
|
||||
GTK_BUTTONS_YES_NO,
|
||||
#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)
|
||||
if(helper->confirm(helper->phone, "You are currently offline.\n"
|
||||
"Do you want to go online?") == 0)
|
||||
return 1;
|
||||
profiles->profiles_cur = 0;
|
||||
plugin->helper->config_set(plugin->helper->phone, "profiles", "default",
|
||||
profiles->profiles[profiles->profiles_cur].name);
|
||||
_profile_switch(plugin, 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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* 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