Skip to content

Commit

Permalink
hidden modes: enable working multiple mode/unhide with dbus api
Browse files Browse the repository at this point in the history
Allow to add and remove modes to a list with multiple hidden modes
through the dbus api.

Signed-off-by: Philippe De Swert <philippedeswert@gmail.com>
  • Loading branch information
philippedeswert committed Dec 26, 2015
1 parent 1fd247a commit b0122c4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
51 changes: 49 additions & 2 deletions src/usb_moded-config.c
Expand Up @@ -409,11 +409,58 @@ set_config_result_t set_mode_setting(const char *mode)
return (set_config_setting(MODE_SETTING_ENTRY, MODE_SETTING_KEY, mode));
}

/* Builds the string used for hidden modes, when hide set to one builds the
new string of hidden modes when adding one, otherwise it will remove one */
static const char * make_hidden_modes_string(const char *hidden, int hide)
{
GString *modelist_str;
char *hidden_modes_list;
gchar **hidden_mode_split;
int i;


hidden_modes_list = get_hidden_modes();
if(hidden_modes_list)
{
hidden_mode_split = g_strsplit(hidden_modes_list, ",", 0);
}
else
{
/* no hidden modes yet. So just return the original string */
return hidden;
}

modelist_str = g_string_new(NULL);

for(i = 0; hidden_mode_split[i] != NULL; i++)
{
if(!strcmp(hidden_mode_split[i], hidden))
{
/* if hiding a mode that is already hidden do nothing */
if(hide)
return(NULL);
if(!hide)
continue;
}
modelist_str = g_string_append(modelist_str, hidden_mode_split[i]);
if(hidden_mode_split[i+1] != NULL)
modelist_str = g_string_append(modelist_str, ",");
}
if(hide)
{
modelist_str = g_string_append(modelist_str, ",");
modelist_str = g_string_append(modelist_str, hidden);
}

g_strfreev(hidden_mode_split);
return(g_string_free(modelist_str, FALSE));
}

set_config_result_t set_hide_mode_setting(const char *mode)
{
set_config_result_t ret;

ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, mode);
ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 1));
if(ret == SET_CONFIG_UPDATED)
send_supported_modes_signal();
return(ret);
Expand All @@ -423,7 +470,7 @@ set_config_result_t set_unhide_mode_setting(const char *mode)
{
set_config_result_t ret;

ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, "");
ret = set_config_setting(MODE_SETTING_ENTRY, MODE_HIDE_KEY, make_hidden_modes_string(mode, 0));
if(ret == SET_CONFIG_UPDATED)
send_supported_modes_signal();
return(ret);
Expand Down
8 changes: 7 additions & 1 deletion src/usb_moded.c
Expand Up @@ -433,7 +433,7 @@ gchar *get_mode_list(void)

GString *modelist_str;
char *hidden_modes_list;
gchar **hidden_mode_split;
gchar **hidden_mode_split = NULL;
int hiddenmode = 0, i;


Expand All @@ -445,6 +445,9 @@ gchar *get_mode_list(void)

modelist_str = g_string_new(NULL);

if(!hidden_mode_split)
goto nomodelist;

if(!diag_mode)
{
/* check dynamic modes */
Expand Down Expand Up @@ -472,6 +475,9 @@ gchar *get_mode_list(void)
}
}

g_strfreev(hidden_mode_split);

nomodelist:
/* end with charging mode */
g_string_append(modelist_str, MODE_CHARGING);
return(g_string_free(modelist_str, FALSE));
Expand Down

0 comments on commit b0122c4

Please sign in to comment.