/pidgin/main: b34e47e69218: Merged in dequisdequis/pidgin/releas...
Gary Kramlich <[email protected]>
| Newsgroups | gmane.comp.gnome.gaim.cvs |
|---|---|
| Message-ID | <[email protected]> |
Changeset: b34e47e69218de23c205b7609f446b8aed9bbfbe Author: Gary Kramlich <[email protected]> Date: 2016-06-16 22:30 -0500 Branch: release-2.x.y URL: https://hg.pidgin.im/pidgin/main/rev/b34e47e69218 Description: Merged in dequisdequis/pidgin/release-2.x.y (pull request #71) Add PurplePrefsUiOps API from instantbird diffstat: ChangeLog.API | 4 +- libpurple/prefs.c | 384 ++++++++++++++++++++++++++++++++++++++++++++++++----- libpurple/prefs.h | 82 +++++++++++ 3 files changed, 430 insertions(+), 40 deletions(-) diffs (truncated from 835 to 300 lines): diff --git a/ChangeLog.API b/ChangeLog.API --- a/ChangeLog.API +++ b/ChangeLog.API @@ -6,7 +6,9 @@ version 2.11.0: * account-status-changing signal (account signals) * buddy-removed-from-group signal (blist signals) * PurpleCommandsUiOps, to allow the UI to override the - built-in handling of commands. + built-in handling of commands. + * PurplePrefsUiOps, to allow the UI to override the way global + preferences are stored. version 2.10.12: * No changes diff --git a/libpurple/prefs.c b/libpurple/prefs.c --- a/libpurple/prefs.c +++ b/libpurple/prefs.c @@ -40,11 +40,15 @@ #include "win32dep.h" #endif -struct pref_cb { +static PurplePrefsUiOps *prefs_ui_ops = NULL; + +struct _PurplePrefCallbackData { PurplePrefCallback func; gpointer data; guint id; void *handle; + void *ui_data; + char *name; }; /* TODO: This should use PurpleValues? */ @@ -78,6 +82,24 @@ static struct purple_pref prefs = { static GHashTable *prefs_hash = NULL; static guint save_timer = 0; static gboolean prefs_loaded = FALSE; +static GSList *ui_callbacks = NULL; + +#define PURPLE_PREFS_UI_OP_CALL(member, ...) \ + { \ + PurplePrefsUiOps *uiop = purple_prefs_get_ui_ops(); \ + if (uiop && uiop->member) { \ + uiop->member(__VA_ARGS__); \ + return; \ + } \ + } + +#define PURPLE_PREFS_UI_OP_CALL_RETURN(member, ...) \ + { \ + PurplePrefsUiOps *uiop = purple_prefs_get_ui_ops(); \ + if (uiop && uiop->member) { \ + return uiop->member(__VA_ARGS__); \ + } \ + } /********************************************************************* @@ -207,6 +229,8 @@ sync_prefs(void) return; } + PURPLE_PREFS_UI_OP_CALL(save); + node = prefs_to_xmlnode(); data = xmlnode_to_formatted_str(node, NULL); purple_util_write_data_to_file("prefs.xml", data, -1); @@ -225,6 +249,8 @@ save_cb(gpointer data) static void schedule_prefs_save(void) { + PURPLE_PREFS_UI_OP_CALL(schedule_save); + if (save_timer == 0) save_timer = purple_timeout_add_seconds(5, save_cb, NULL); } @@ -376,12 +402,21 @@ static GMarkupParser prefs_parser = { gboolean purple_prefs_load() { - gchar *filename = g_build_filename(purple_user_dir(), "prefs.xml", NULL); + gchar *filename; gchar *contents = NULL; gsize length; GMarkupParseContext *context; GError *error = NULL; + PurplePrefsUiOps *uiop = purple_prefs_get_ui_ops(); + + if (uiop && uiop->load) { + prefs_loaded = TRUE; + return uiop->load(); + } + + filename = g_build_filename(purple_user_dir(), "prefs.xml", NULL); + if (!filename) { prefs_loaded = TRUE; return FALSE; @@ -605,13 +640,19 @@ add_pref(PurplePrefType type, const char void purple_prefs_add_none(const char *name) { + PURPLE_PREFS_UI_OP_CALL(add_none, name); + add_pref(PURPLE_PREF_NONE, name); } void purple_prefs_add_bool(const char *name, gboolean value) { - struct purple_pref *pref = add_pref(PURPLE_PREF_BOOLEAN, name); + struct purple_pref *pref; + + PURPLE_PREFS_UI_OP_CALL(add_bool, name, value); + + pref = add_pref(PURPLE_PREF_BOOLEAN, name); if(!pref) return; @@ -622,7 +663,11 @@ purple_prefs_add_bool(const char *name, void purple_prefs_add_int(const char *name, int value) { - struct purple_pref *pref = add_pref(PURPLE_PREF_INT, name); + struct purple_pref *pref; + + PURPLE_PREFS_UI_OP_CALL(add_int, name, value); + + pref = add_pref(PURPLE_PREF_INT, name); if(!pref) return; @@ -640,6 +685,8 @@ purple_prefs_add_string(const char *name return; } + PURPLE_PREFS_UI_OP_CALL(add_string, name, value); + pref = add_pref(PURPLE_PREF_STRING, name); if(!pref) @@ -651,9 +698,13 @@ purple_prefs_add_string(const char *name void purple_prefs_add_string_list(const char *name, GList *value) { - struct purple_pref *pref = add_pref(PURPLE_PREF_STRING_LIST, name); + struct purple_pref *pref; GList *tmp; + PURPLE_PREFS_UI_OP_CALL(add_string_list, name, value); + + pref = add_pref(PURPLE_PREF_STRING_LIST, name); + if(!pref) return; @@ -670,7 +721,12 @@ purple_prefs_add_string_list(const char void purple_prefs_add_path(const char *name, const char *value) { - struct purple_pref *pref = add_pref(PURPLE_PREF_PATH, name); + struct purple_pref *pref; + + /* re-use the string UI OP */ + PURPLE_PREFS_UI_OP_CALL(add_string, name, value); + + pref = add_pref(PURPLE_PREF_PATH, name); if(!pref) return; @@ -681,9 +737,14 @@ purple_prefs_add_path(const char *name, void purple_prefs_add_path_list(const char *name, GList *value) { - struct purple_pref *pref = add_pref(PURPLE_PREF_PATH_LIST, name); + struct purple_pref *pref; GList *tmp; + /* re-use the string list UI OP */ + PURPLE_PREFS_UI_OP_CALL(add_string_list, name, value); + + pref = add_pref(PURPLE_PREF_PATH_LIST, name); + if(!pref) return; @@ -740,7 +801,11 @@ remove_pref(struct purple_pref *pref) void purple_prefs_remove(const char *name) { - struct purple_pref *pref = find_pref(name); + struct purple_pref *pref; + + PURPLE_PREFS_UI_OP_CALL(remove, name); + + pref = find_pref(name); if(!pref) return; @@ -761,16 +826,51 @@ do_callbacks(const char* name, struct pu struct purple_pref *cb_pref; for(cb_pref = pref; cb_pref; cb_pref = cb_pref->parent) { for(cbs = cb_pref->callbacks; cbs; cbs = cbs->next) { - struct pref_cb *cb = cbs->data; + PurplePrefCallbackData *cb = cbs->data; cb->func(name, pref->type, pref->value.generic, cb->data); } } } +static void +do_ui_callbacks(const char *name) +{ + GSList *cbs; + + purple_debug_misc("prefs", "trigger callback %s\n", name); + + for (cbs = ui_callbacks; cbs; cbs = cbs->next) { + PurplePrefCallbackData *cb = cbs->data; + const char *cb_name = cb->name; + size_t len = strlen(cb_name); + if (!strncmp(cb_name, name, len) && + (name[len] == 0 || name[len] == '/' || + (len && name[len - 1] == '/'))) { + /* This test should behave like this: + * name = /toto/tata + * cb_name = /toto/tata --> true + * cb_name = /toto/tatatiti --> false + * cb_name = / --> true + * cb_name = /toto --> true + * cb_name = /toto/ --> true + */ + purple_prefs_trigger_callback_object(cbs->data); + } + } +} + void purple_prefs_trigger_callback(const char *name) { - struct purple_pref *pref = find_pref(name); + struct purple_pref *pref; + PurplePrefsUiOps *uiop = purple_prefs_get_ui_ops(); + + if (uiop && uiop->connect_callback) { + do_ui_callbacks(name); + return; + } + + pref = find_pref(name); if(!pref) { purple_debug_error("prefs", @@ -781,6 +881,7 @@ purple_prefs_trigger_callback(const char do_callbacks(name, pref); } +/* this function is deprecated, so it doesn't get the new UI ops */ void purple_prefs_set_generic(const char *name, gpointer value) { @@ -799,7 +900,11 @@ purple_prefs_set_generic(const char *nam void purple_prefs_set_bool(const char *name, gboolean value) { - struct purple_pref *pref = find_pref(name); + struct purple_pref *pref; + + PURPLE_PREFS_UI_OP_CALL(set_bool, name, value); + + pref = find_pref(name); if(pref) { if(pref->type != PURPLE_PREF_BOOLEAN) { @@ -820,7 +925,11 @@ purple_prefs_set_bool(const char *name, void purple_prefs_set_int(const char *name, int value) { - struct purple_pref *pref = find_pref(name); + struct purple_pref *pref; + + PURPLE_PREFS_UI_OP_CALL(set_int, name, value); + + pref = find_pref(name); if(pref) { if(pref->type != PURPLE_PREF_INT) { @@ -841,13 +950,17 @@ purple_prefs_set_int(const char *name, i void purple_prefs_set_string(const char *name, const char *value) { - struct purple_pref *pref = find_pref(name); + struct purple_pref *pref; if(value != NULL && !g_utf8_validate(value, -1, NULL)) { purple_debug_error("prefs", "purple_prefs_set_string: Cannot store invalid UTF8 for string pref %s\n", name); return; } _______________________________________________ Commits mailing list [email protected] https://pidgin.im/cgi-bin/mailman/listinfo/commits