diff options
author | Roland Knall <roland.knall@br-automation.com> | 2016-01-21 13:41:42 +0100 |
---|---|---|
committer | Roland Knall <rknall@gmail.com> | 2016-01-26 16:37:06 +0000 |
commit | 1c822e713034d06944315c138d093aa720ab5752 (patch) | |
tree | 0ba13bd0af2d3369f73cc7073a3515f450b53dc3 | |
parent | 7e72253c0ec259c46546bd45fc27e1d045bfdf55 (diff) |
prefutils: Add convenience function
This is a convenience function for allowing multiple
key/values to be saved to the preference system, without
having to reference pref_t or the real underlying value.
It is used by the extcap save functionality, to store the
saved values
Change-Id: I1c8bf787db8ed2d17628024ec1cd19073e49d017
Reviewed-on: https://code.wireshark.org/review/13471
Petri-Dish: Roland Knall <rknall@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Roland Knall <rknall@gmail.com>
-rw-r--r-- | ui/preference_utils.c | 47 | ||||
-rw-r--r-- | ui/preference_utils.h | 16 |
2 files changed, 61 insertions, 2 deletions
diff --git a/ui/preference_utils.c b/ui/preference_utils.c index 95abc5c03b..ca0a70c7a3 100644 --- a/ui/preference_utils.c +++ b/ui/preference_utils.c @@ -273,8 +273,8 @@ prefs_main_write(void) } } -gboolean -prefs_store_ext(const char * module_name, const char *pref_name, const char *pref_value) +static gboolean +prefs_store_ext_helper(const char * module_name, const char *pref_name, const char *pref_value) { module_t * module = NULL; pref_t * pref = NULL; @@ -305,6 +305,49 @@ prefs_store_ext(const char * module_name, const char *pref_name, const char *pre } } + return pref_changed; +} + +gboolean +prefs_store_ext(const char * module_name, const char *pref_name, const char *pref_value) +{ + if ( prefs_store_ext_helper(module_name, pref_name, pref_value) ) + { + prefs_main_write(); + prefs_apply_all(); + prefs_to_capture_opts(); + return TRUE; + } + + return FALSE; +} + +gboolean +prefs_store_ext_multiple(const char * module, GHashTable * pref_values) +{ + gboolean pref_changed = FALSE; + GList * keys = NULL; + + if ( ! prefs_is_registered_protocol(module)) + return pref_changed; + + keys = g_hash_table_get_keys(pref_values); + if ( ! keys ) + return pref_changed; + + while ( keys != NULL ) + { + gchar * pref_name = (gchar *)keys->data; + gchar * pref_value = (gchar *) g_hash_table_lookup(pref_values, keys->data); + + if ( pref_name && pref_value ) + { + if ( prefs_store_ext_helper(module, pref_name, pref_value) ) + pref_changed = TRUE; + } + keys = g_list_next(keys); + } + if ( pref_changed ) { prefs_main_write(); diff --git a/ui/preference_utils.h b/ui/preference_utils.h index a0b345d043..d85a4ea9e1 100644 --- a/ui/preference_utils.h +++ b/ui/preference_utils.h @@ -82,6 +82,9 @@ extern void prefs_main_write(void); /** Convenient function for plugin_if * + * Note: The preferences must exist, it is not possible to create entries + * using this function + * * @param module the module for the preference * @param key the key for the preference * @param value the new value as string for the preference @@ -90,6 +93,19 @@ extern void prefs_main_write(void); */ extern gboolean prefs_store_ext(const char * module, const char * key, const char * value); +/** Convenient function for the writing of multiple preferences, without + * explicitly having prefs_t variables. + * + * Note: The preferences must exist, it is not possible to create entries + * using this function + * + * @param module the module for the preference + * @param pref_values a hash table + * + * @return true if the value has been stored successfully + */ +extern gboolean prefs_store_ext_multiple(const char * module, GHashTable * pref_values); + /** Add a custom column. * * @param fmt column format |