/pidgin/main: 2e00aa78cb1f: Add PurplePrefsUiOps API from instan...

dx dx at dxzone.com.ar
Thu Jun 16 23:31:07 EDT 2016


Changeset: 2e00aa78cb1f19bb96b9a4b8e483d56e143c186b
Author:	 dx <dx at dxzone.com.ar>
Date:	 2016-06-15 04:59 -0300
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/2e00aa78cb1f

Description:

Add PurplePrefsUiOps API from instantbird

This allows overriding the prefs.xml storage with anything else.

The instantbird version had fewer methods, things like add_string_list or
rename_boolean_toggle which are rarely used in libpurple and that instantbird
just removed from their fork.

The add_observer and remove_observer methods are not implemented yet.

diffstat:

 libpurple/prefs.c |  188 +++++++++++++++++++++++++++++++++++++++++++++++------
 libpurple/prefs.h |   70 ++++++++++++++++++++
 2 files changed, 234 insertions(+), 24 deletions(-)

diffs (truncated from 524 to 300 lines):

diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -40,6 +40,8 @@
 #include "win32dep.h"
 #endif
 
+static PurplePrefsUiOps *prefs_ui_ops = NULL;
+
 struct pref_cb {
 	PurplePrefCallback func;
 	gpointer data;
@@ -79,6 +81,23 @@ static GHashTable *prefs_hash = NULL;
 static guint       save_timer = 0;
 static gboolean    prefs_loaded = FALSE;
 
+#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__); \
+		} \
+	}
+
 
 /*********************************************************************
  * Private utility functions                                         *
@@ -207,6 +226,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 +246,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 +399,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 +637,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 +660,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 +682,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 +695,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 +718,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 +734,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 +798,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;
@@ -781,6 +843,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 +862,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 +887,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 +912,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;
 	}
 
+	PURPLE_PREFS_UI_OP_CALL(set_string, name, value);
+
+	pref = find_pref(name);
+
 	if(pref) {
 		if(pref->type != PURPLE_PREF_STRING && pref->type != PURPLE_PREF_PATH) {
 			purple_debug_error("prefs",
@@ -868,7 +943,12 @@ purple_prefs_set_string(const char *name
 void
 purple_prefs_set_string_list(const char *name, GList *value)
 {
-	struct purple_pref *pref = find_pref(name);
+	struct purple_pref *pref;
+
+	PURPLE_PREFS_UI_OP_CALL(set_string_list, name, value);
+
+	pref = find_pref(name);
+
 	if(pref) {
 		GList *tmp;
 
@@ -903,7 +983,11 @@ purple_prefs_set_string_list(const char 
 void
 purple_prefs_set_path(const char *name, const char *value)
 {
-	struct purple_pref *pref = find_pref(name);
+	struct purple_pref *pref;
+
+	PURPLE_PREFS_UI_OP_CALL(set_string, name, value);
+
+	pref = find_pref(name);
 
 	if(pref) {
 		if(pref->type != PURPLE_PREF_PATH) {
@@ -925,7 +1009,12 @@ purple_prefs_set_path(const char *name, 
 void
 purple_prefs_set_path_list(const char *name, GList *value)
 {
-	struct purple_pref *pref = find_pref(name);
+	struct purple_pref *pref;
+
+	PURPLE_PREFS_UI_OP_CALL(set_string_list, name, value);
+
+	pref = find_pref(name);
+
 	if(pref) {
 		GList *tmp;
 
@@ -956,7 +1045,11 @@ purple_prefs_set_path_list(const char *n
 gboolean
 purple_prefs_exists(const char *name)
 {
-	struct purple_pref *pref = find_pref(name);
+	struct purple_pref *pref;
+
+	PURPLE_PREFS_UI_OP_CALL_RETURN(exists, name);
+
+	pref = find_pref(name);
 
 	if (pref != NULL)
 		return TRUE;
@@ -967,7 +1060,11 @@ purple_prefs_exists(const char *name)
 PurplePrefType
 purple_prefs_get_type(const char *name)
 {
-	struct purple_pref *pref = find_pref(name);
+	struct purple_pref *pref;
+
+	PURPLE_PREFS_UI_OP_CALL_RETURN(get_type, name);
+
+	pref = find_pref(name);
 
 	if (pref == NULL)
 		return PURPLE_PREF_NONE;
@@ -978,7 +1075,11 @@ purple_prefs_get_type(const char *name)
 gboolean



More information about the Commits mailing list