[Xfce4-commits] [apps/xfce4-screensaver] 332/425: Tidy up xfcekbd-keyboard-config.{c, h}
noreply at xfce.org
noreply at xfce.org
Mon Oct 15 01:52:59 CEST 2018
This is an automated email from the git hooks/post-receive script.
b l u e s a b r e p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository apps/xfce4-screensaver.
commit c8106a83174a561e7309373be7e5e5e70128c5b7
Author: Sean Davis <smd.seandavis at gmail.com>
Date: Mon Oct 1 21:10:46 2018 -0400
Tidy up xfcekbd-keyboard-config.{c,h}
---
src/xfcekbd-config-private.h | 8 -
src/xfcekbd-keyboard-config.c | 474 +-----------------------------------------
src/xfcekbd-keyboard-config.h | 55 -----
3 files changed, 1 insertion(+), 536 deletions(-)
diff --git a/src/xfcekbd-config-private.h b/src/xfcekbd-config-private.h
index dc595ac..d0a8e1d 100644
--- a/src/xfcekbd-config-private.h
+++ b/src/xfcekbd-config-private.h
@@ -48,14 +48,6 @@ extern gboolean xfcekbd_keyboard_config_dump_settings (XfcekbdKeyboardConfig *
kbd_config,
const char *file_name);
-extern void xfcekbd_keyboard_config_start_listen (XfcekbdKeyboardConfig *
- kbd_config,
- GCallback func,
- gpointer user_data);
-
-extern void xfcekbd_keyboard_config_stop_listen (XfcekbdKeyboardConfig *
- kbd_config);
-
extern gboolean xfcekbd_keyboard_config_get_lv_descriptions (XklConfigRegistry
*
config_registry,
diff --git a/src/xfcekbd-keyboard-config.c b/src/xfcekbd-keyboard-config.c
index bf5d091..6583ece 100644
--- a/src/xfcekbd-keyboard-config.c
+++ b/src/xfcekbd-keyboard-config.c
@@ -52,31 +52,6 @@ const gchar *XFCEKBD_KEYBOARD_CONFIG_ACTIVE[] = {
* static common functions
*/
-static gboolean
-g_strv_equal (gchar ** l1, gchar ** l2)
-{
- if (l1 == l2)
- return TRUE;
- if (l1 == NULL)
- return g_strv_length (l2) == 0;
- if (l2 == NULL)
- return g_strv_length (l1) == 0;
-
- while ((*l1 != NULL) && (*l2 != NULL)) {
- if (*l1 != *l2) {
- if (*l1 && *l2) {
- if (g_ascii_strcasecmp (*l1, *l2))
- return FALSE;
- } else
- return FALSE;
- }
-
- l1++;
- l2++;
- }
- return (*l1 == NULL) && (*l2 == NULL);
-}
-
gboolean
xfcekbd_keyboard_config_get_lv_descriptions (XklConfigRegistry *
config_registry,
@@ -127,7 +102,7 @@ xfcekbd_keyboard_config_get_lv_descriptions (XklConfigRegistry *
/*
* extern common functions
*/
-const gchar *
+static const gchar *
xfcekbd_keyboard_config_merge_items (const gchar * parent,
const gchar * child)
{
@@ -244,165 +219,6 @@ xfcekbd_keyboard_config_copy_from_xkl_config (XfcekbdKeyboardConfig * kbd_config
}
}
-static void
-xfcekbd_keyboard_config_copy_to_xkl_config (XfcekbdKeyboardConfig * kbd_config,
- XklConfigRec * pdata)
-{
- int i;
- int num_layouts, num_options;
- pdata->model =
- (kbd_config->model ==
- NULL) ? NULL : g_strdup (kbd_config->model);
-
- num_layouts =
- (kbd_config->layouts_variants ==
- NULL) ? 0 : g_strv_length (kbd_config->layouts_variants);
- num_options =
- (kbd_config->options ==
- NULL) ? 0 : g_strv_length (kbd_config->options);
-
- xkl_debug (150, "Taking %d layouts\n", num_layouts);
- if (num_layouts != 0) {
- gchar **the_layout_variant = kbd_config->layouts_variants;
- char **p1 = pdata->layouts =
- g_new0 (char *, num_layouts + 1);
- char **p2 = pdata->variants =
- g_new0 (char *, num_layouts + 1);
- for (i = num_layouts; --i >= 0;) {
- char *layout, *variant;
- if (xfcekbd_keyboard_config_split_items
- (*the_layout_variant, &layout, &variant)
- && variant != NULL) {
- *p1 =
- (layout ==
- NULL) ? g_strdup ("") :
- g_strdup (layout);
- *p2 =
- (variant ==
- NULL) ? g_strdup ("") :
- g_strdup (variant);
- } else {
- *p1 =
- (*the_layout_variant ==
- NULL) ? g_strdup ("") :
- g_strdup (*the_layout_variant);
- *p2 = g_strdup ("");
- }
- xkl_debug (150, "Adding [%s]/%p and [%s]/%p\n",
- *p1 ? *p1 : "(nil)", *p1,
- *p2 ? *p2 : "(nil)", *p2);
- p1++;
- p2++;
- the_layout_variant++;
- }
- }
-
- if (num_options != 0) {
- gchar **the_option = kbd_config->options;
- char **p = pdata->options =
- g_new0 (char *, num_options + 1);
- for (i = num_options; --i >= 0;) {
- char *group, *option;
- if (xfcekbd_keyboard_config_split_items
- (*the_option, &group, &option)
- && option != NULL)
- *(p++) = g_strdup (option);
- else {
- *(p++) = g_strdup ("");
- xkl_debug (150, "Could not split [%s]\n",
- *the_option);
- }
- the_option++;
- }
- }
-}
-
-static void
-xfcekbd_keyboard_config_load_params (XfcekbdKeyboardConfig * kbd_config,
- const gchar * param_names[])
-{
- gchar *pc;
-
- pc = g_settings_get_string (kbd_config->settings, param_names[0]);
- if (pc == NULL) {
- xfcekbd_keyboard_config_model_set (kbd_config, NULL);
- } else {
- xfcekbd_keyboard_config_model_set (kbd_config, pc);
- g_free (pc);
- }
- xkl_debug (150, "Loaded Kbd model: [%s]\n",
- kbd_config->model ? kbd_config->model : "(null)");
-
- g_strfreev (kbd_config->layouts_variants);
-
- kbd_config->layouts_variants =
- g_settings_get_strv (kbd_config->settings, param_names[1]);
-
- if (kbd_config->layouts_variants != NULL
- && kbd_config->layouts_variants[0] == NULL) {
- g_strfreev (kbd_config->layouts_variants);
- kbd_config->layouts_variants = NULL;
- }
-
- g_strfreev (kbd_config->options);
-
- kbd_config->options =
- g_settings_get_strv (kbd_config->settings, param_names[2]);
-
- if (kbd_config->options != NULL && kbd_config->options[0] == NULL) {
- g_strfreev (kbd_config->options);
- kbd_config->options = NULL;
- }
-}
-
-static void
-xfcekbd_keyboard_config_save_params (XfcekbdKeyboardConfig * kbd_config,
- const gchar * param_names[])
-{
- gchar **pl;
-
- if (kbd_config->model)
- g_settings_set_string (kbd_config->settings, param_names[0],
- kbd_config->model);
- else
- g_settings_set_string (kbd_config->settings, param_names[0],
- NULL);
- xkl_debug (150, "Saved Kbd model: [%s]\n",
- kbd_config->model ? kbd_config->model : "(null)");
-
- if (kbd_config->layouts_variants) {
- pl = kbd_config->layouts_variants;
- while (*pl != NULL) {
- xkl_debug (150, "Saved Kbd layout: [%s]\n", *pl);
- pl++;
- }
- g_settings_set_strv (kbd_config->settings,
- param_names[1],
- (const gchar * const *)
- kbd_config->layouts_variants);
- } else {
- xkl_debug (150, "Saved Kbd layouts: []\n");
- g_settings_set_strv (kbd_config->settings,
- param_names[1], NULL);
- }
-
- if (kbd_config->options) {
- pl = kbd_config->options;
- while (*pl != NULL) {
- xkl_debug (150, "Saved Kbd option: [%s]\n", *pl);
- pl++;
- }
- g_settings_set_strv (kbd_config->settings,
- param_names[2],
- (const gchar *
- const *) kbd_config->options);
- } else {
- xkl_debug (150, "Saved Kbd options: []\n");
- g_settings_set_strv (kbd_config->settings,
- param_names[2], NULL);
- }
-}
-
/*
* extern XfcekbdKeyboardConfig config functions
*/
@@ -430,33 +246,6 @@ xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig * kbd_config)
}
void
-xfcekbd_keyboard_config_load_from_gsettings (XfcekbdKeyboardConfig * kbd_config,
- XfcekbdKeyboardConfig *
- kbd_config_default)
-{
- xfcekbd_keyboard_config_load_params (kbd_config,
- XFCEKBD_KEYBOARD_CONFIG_ACTIVE);
-
- if (kbd_config_default != NULL) {
-
- if (kbd_config->model == NULL)
- kbd_config->model =
- g_strdup (kbd_config_default->model);
-
- if (kbd_config->layouts_variants == NULL) {
- kbd_config->layouts_variants =
- g_strdupv
- (kbd_config_default->layouts_variants);
- }
-
- if (kbd_config->options == NULL) {
- kbd_config->options =
- g_strdupv (kbd_config_default->options);
- }
- }
-}
-
-void
xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig * kbd_config,
XklConfigRec * data)
{
@@ -476,108 +265,6 @@ xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig * kbd_config,
}
void
-xfcekbd_keyboard_config_load_from_x_initial (XfcekbdKeyboardConfig * kbd_config,
- XklConfigRec * data)
-{
- gboolean own_data = data == NULL;
- xkl_debug (150, "Copying config from X(initial)\n");
- if (own_data)
- data = xkl_config_rec_new ();
- if (xkl_config_rec_get_from_backup (data, kbd_config->engine))
- xfcekbd_keyboard_config_copy_from_xkl_config (kbd_config,
- data);
- else
- xkl_debug (150,
- "Could not load keyboard config from backup: [%s]\n",
- xkl_get_last_error ());
- if (own_data)
- g_object_unref (G_OBJECT (data));
-}
-
-static gboolean
-xfcekbd_keyboard_config_options_equals (XfcekbdKeyboardConfig * kbd_config1,
- XfcekbdKeyboardConfig * kbd_config2)
-{
- int num_options, num_options2;
-
- num_options =
- (kbd_config1->options ==
- NULL) ? 0 : g_strv_length (kbd_config1->options);
- num_options2 =
- (kbd_config2->options ==
- NULL) ? 0 : g_strv_length (kbd_config2->options);
-
- if (num_options != num_options2)
- return False;
-
- if (num_options != 0) {
- int i;
- char *group1, *option1;
-
- for (i = 0; i < num_options; i++) {
- int j;
- char *group2, *option2;
- gboolean are_equal = FALSE;
-
- if (!xfcekbd_keyboard_config_split_items
- (kbd_config1->options[i], &group1, &option1))
- continue;
-
- option1 = g_strdup (option1);
-
- for (j = 0; j < num_options && !are_equal; j++) {
- if (xfcekbd_keyboard_config_split_items
- (kbd_config2->options[j], &group2,
- &option2)) {
- are_equal =
- strcmp (option1, option2) == 0;
- }
- }
-
- g_free (option1);
-
- if (!are_equal)
- return False;
- }
- }
-
- return True;
-}
-
-gboolean
-xfcekbd_keyboard_config_equals (XfcekbdKeyboardConfig * kbd_config1,
- XfcekbdKeyboardConfig * kbd_config2)
-{
- if (kbd_config1 == kbd_config2)
- return True;
- if ((kbd_config1->model != kbd_config2->model) &&
- (kbd_config1->model != NULL) &&
- (kbd_config2->model != NULL) &&
- g_ascii_strcasecmp (kbd_config1->model, kbd_config2->model))
- return False;
- if (!g_strv_equal (kbd_config1->layouts_variants,
- kbd_config2->layouts_variants))
- return False;
-
- if (!xfcekbd_keyboard_config_options_equals
- (kbd_config1, kbd_config2))
- return False;
-
- return True;
-}
-
-void
-xfcekbd_keyboard_config_save_to_gsettings (XfcekbdKeyboardConfig * kbd_config)
-{
- g_settings_delay (kbd_config->settings);
-
- xfcekbd_keyboard_config_save_params (kbd_config,
- XFCEKBD_KEYBOARD_CONFIG_ACTIVE);
-
- g_settings_apply (kbd_config->settings);
-}
-
-void
xfcekbd_keyboard_config_model_set (XfcekbdKeyboardConfig * kbd_config,
const gchar * model_name)
{
@@ -622,62 +309,6 @@ xfcekbd_keyboard_config_options_is_set (XfcekbdKeyboardConfig * kbd_config,
return FALSE;
}
-gboolean
-xfcekbd_keyboard_config_activate (XfcekbdKeyboardConfig * kbd_config)
-{
- gboolean rv;
- XklConfigRec *data = xkl_config_rec_new ();
-
- xfcekbd_keyboard_config_copy_to_xkl_config (kbd_config, data);
- rv = xkl_config_rec_activate (data, kbd_config->engine);
- g_object_unref (G_OBJECT (data));
-
- return rv;
-}
-
-/**
- * xfcekbd_keyboard_config_start_listen:
- * @func: (scope notified): a function to call when settings are changed
- */
-void
-xfcekbd_keyboard_config_start_listen (XfcekbdKeyboardConfig * kbd_config,
- GCallback func,
- gpointer user_data)
-{
- kbd_config->config_listener_id =
- g_signal_connect (kbd_config->settings, "changed", func,
- user_data);
-}
-
-void
-xfcekbd_keyboard_config_stop_listen (XfcekbdKeyboardConfig * kbd_config)
-{
- g_signal_handler_disconnect (kbd_config->settings,
- kbd_config->config_listener_id);
- kbd_config->config_listener_id = 0;
-}
-
-gboolean
-xfcekbd_keyboard_config_get_descriptions (XklConfigRegistry * config_registry,
- const gchar * name,
- gchar ** layout_short_descr,
- gchar ** layout_descr,
- gchar ** variant_short_descr,
- gchar ** variant_descr)
-{
- char *layout_name = NULL, *variant_name = NULL;
- if (!xfcekbd_keyboard_config_split_items
- (name, &layout_name, &variant_name))
- return FALSE;
- return xfcekbd_keyboard_config_get_lv_descriptions (config_registry,
- layout_name,
- variant_name,
- layout_short_descr,
- layout_descr,
- variant_short_descr,
- variant_descr);
-}
-
const gchar *
xfcekbd_keyboard_config_format_full_layout (const gchar * layout_descr,
const gchar * variant_descr)
@@ -691,106 +322,3 @@ xfcekbd_keyboard_config_format_full_layout (const gchar * layout_descr,
layout_descr, variant_descr);
return full_descr;
}
-
-gchar *
-xfcekbd_keyboard_config_to_string (const XfcekbdKeyboardConfig * config)
-{
- gchar *layouts = NULL, *options = NULL;
- GString *buffer = g_string_new (NULL);
-
- gchar **iter;
- gint count;
- gchar *result;
-
- if (config->layouts_variants) {
- /* g_slist_length is "expensive", so we determinate the length on the fly */
- for (iter = config->layouts_variants, count = 0; *iter;
- iter++, ++count) {
- if (buffer->len)
- g_string_append (buffer, " ");
-
- g_string_append (buffer, *iter);
- }
-
- /* Translators: The count is related to the number of options. The %s
- * format specifier should not be modified, left "as is". */
- layouts =
- g_strdup_printf (ngettext
- ("layout \"%s\"", "layouts \"%s\"",
- count), buffer->str);
- g_string_truncate (buffer, 0);
- }
- if (config->options) {
- /* g_slist_length is "expensive", so we determinate the length on the fly */
- for (iter = config->options, count = 0; *iter;
- iter++, ++count) {
- if (buffer->len)
- g_string_append (buffer, " ");
-
- g_string_append (buffer, *iter);
- }
-
- /* Translators: The count is related to the number of options. The %s
- * format specifier should not be modified, left "as is". */
- options =
- g_strdup_printf (ngettext
- ("option \"%s\"", "options \"%s\"",
- count), buffer->str);
- g_string_truncate (buffer, 0);
- }
-
- g_string_free (buffer, TRUE);
-
- result =
- g_strdup_printf (_("model \"%s\", %s and %s"), config->model,
- layouts ? layouts : _("no layout"),
- options ? options : _("no options"));
-
- g_free (options);
- g_free (layouts);
-
- return result;
-}
-
-/**
- * xfcekbd_keyboard_config_add_default_switch_option_if_necessary:
- *
- * Returns: (transfer full) (array zero-terminated=1): List of options
- */
-gchar **
-xfcekbd_keyboard_config_add_default_switch_option_if_necessary (gchar **
- layouts_list,
- gchar **
- options_list,
- gboolean *was_appended)
-{
- *was_appended = FALSE;
- if (g_strv_length (layouts_list) >= 2) {
- gboolean any_switcher = False;
- if (*options_list != NULL) {
- gchar **option = options_list;
- while (*option != NULL) {
- char *g, *o;
- if (xfcekbd_keyboard_config_split_items
- (*option, &g, &o)) {
- if (!g_ascii_strcasecmp
- (g, GROUP_SWITCHERS_GROUP)) {
- any_switcher = True;
- break;
- }
- }
- option++;
- }
- }
- if (!any_switcher) {
- const gchar *id =
- xfcekbd_keyboard_config_merge_items
- (GROUP_SWITCHERS_GROUP,
- DEFAULT_GROUP_SWITCH);
- options_list =
- xfcekbd_strv_append (options_list, g_strdup (id));
- *was_appended = TRUE;
- }
- }
- return options_list;
-}
diff --git a/src/xfcekbd-keyboard-config.h b/src/xfcekbd-keyboard-config.h
index 3ce46ed..05d1e38 100644
--- a/src/xfcekbd-keyboard-config.h
+++ b/src/xfcekbd-keyboard-config.h
@@ -51,73 +51,18 @@ extern void xfcekbd_keyboard_config_init (XfcekbdKeyboardConfig * kbd_config,
XklEngine * engine);
extern void xfcekbd_keyboard_config_term (XfcekbdKeyboardConfig * kbd_config);
-extern void xfcekbd_keyboard_config_load_from_gsettings (XfcekbdKeyboardConfig *
- kbd_config,
- XfcekbdKeyboardConfig *
- kbd_config_default);
-
-extern void xfcekbd_keyboard_config_save_to_gsettings (XfcekbdKeyboardConfig *
- kbd_config);
-
-extern void xfcekbd_keyboard_config_load_from_x_initial (XfcekbdKeyboardConfig *
- kbd_config,
- XklConfigRec * buf);
-
extern void xfcekbd_keyboard_config_load_from_x_current (XfcekbdKeyboardConfig *
kbd_config,
XklConfigRec * buf);
-extern void xfcekbd_keyboard_config_start_listen (XfcekbdKeyboardConfig *
- kbd_config,
- GCallback func,
- gpointer user_data);
-
-extern void xfcekbd_keyboard_config_stop_listen (XfcekbdKeyboardConfig *
- kbd_config);
-
-extern gboolean xfcekbd_keyboard_config_equals (XfcekbdKeyboardConfig *
- kbd_config1,
- XfcekbdKeyboardConfig *
- kbd_config2);
-
-extern gboolean xfcekbd_keyboard_config_activate (XfcekbdKeyboardConfig *
- kbd_config);
-
-extern const gchar *xfcekbd_keyboard_config_merge_items (const gchar * parent,
- const gchar * child);
-
extern gboolean xfcekbd_keyboard_config_split_items (const gchar * merged,
gchar ** parent,
gchar ** child);
-extern gboolean xfcekbd_keyboard_config_get_descriptions (XklConfigRegistry *
- config_registry,
- const gchar * name,
- gchar **
- layout_short_descr,
- gchar **
- layout_descr,
- gchar **
- variant_short_descr,
- gchar **
- variant_descr);
-
extern const gchar *xfcekbd_keyboard_config_format_full_layout (const gchar
*
layout_descr,
const gchar *
variant_descr);
-extern gchar *xfcekbd_keyboard_config_to_string (const XfcekbdKeyboardConfig *
- config);
-
-extern gchar
- **xfcekbd_keyboard_config_add_default_switch_option_if_necessary (gchar **
- layouts_list,
- gchar **
- options_list,
- gboolean
- *
- was_appended);
-
#endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list