Fix prefs for stuff that was broken in the merge

Fri, 19 Aug 2016 23:51:13 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 19 Aug 2016 23:51:13 -0500
changeset 37904
5915afa891bd
parent 37903
caf372ae8882
child 37905
848e16508276

Fix prefs for stuff that was broken in the merge

libpurple/prefs.c file | annotate | diff | comparison | revisions
libpurple/prefs.h file | annotate | diff | comparison | revisions
--- a/libpurple/prefs.c	Fri Aug 19 23:38:43 2016 -0500
+++ b/libpurple/prefs.c	Fri Aug 19 23:51:13 2016 -0500
@@ -35,6 +35,17 @@
 #include "debug.h"
 #include "util.h"
 
+static PurplePrefsUiOps *prefs_ui_ops = NULL;
+
+struct _PurplePrefCallbackData {
+	PurplePrefCallback func;
+	gpointer data;
+	guint id;
+	void *handle;
+	void *ui_data;
+	char *name;
+};
+
 struct pref_cb {
 	PurplePrefCallback func;
 	gpointer data;
--- a/libpurple/prefs.h	Fri Aug 19 23:38:43 2016 -0500
+++ b/libpurple/prefs.h	Fri Aug 19 23:51:13 2016 -0500
@@ -74,8 +74,106 @@
 typedef void (*PurplePrefCallback) (const char *name, PurplePrefType type,
 		gconstpointer val, gpointer data);
 
+/**
+ * Opaque type to carry callback information
+ *
+ * @since 2.11.0
+ */
+typedef struct _PurplePrefCallbackData PurplePrefCallbackData;
+
+/** @copydoc _PurplePrefsUiOps */
+typedef struct _PurplePrefsUiOps PurplePrefsUiOps;
+
+/**
+ * Prefs UI operations. This allows overriding the prefs.xml storage with
+ * anything else. 
+ *
+ * Unless specified otherwise, each entry provides an implementation for the
+ * corresponding purple_prefs_* method, and disables the prefs.xml code for it.
+ * This means that to do anything useful, all the methods must be implemented.
+ *
+ * @since 2.11.0
+ */
+struct _PurplePrefsUiOps
+{
+	void (*add_none)(const char *name);
+	void (*add_bool)(const char *name, gboolean value);
+	void (*add_int)(const char *name, int value);
+	void (*add_string)(const char *name, const char *value);
+	void (*add_string_list)(const char *name, GList *value);
+
+	void (*set_bool)(const char *name, gboolean value);
+	void (*set_int)(const char *name, int value);
+	void (*set_string)(const char *name, const char *value);
+	void (*set_string_list)(const char *name, GList *value);
+
+	gboolean (*get_bool)(const char *name);
+	int (*get_int)(const char *name);
+	const char *(*get_string)(const char *name);
+	GList *(*get_string_list)(const char *name);
+
+	PurplePrefType (*get_type)(const char *name);
+	GList *(*get_children_names)(const char *name);
+
+	gboolean (*exists)(const char *name);
+	void (*remove)(const char *name);
+
+	void (*rename)(const char *oldname, const char *newname);
+	void (*rename_boolean_toggle)(const char *oldname, const char *newname);
+
+	gboolean (*load)(void);
+	void (*save)(void);
+	void (*schedule_save)(void);
+
+	/**
+	 * Called when a callback is added to a preference. The UI must keep
+	 * track of it and call #purple_prefs_trigger_callback_object with the
+	 * data attribute.
+	 *
+	 * @param name The preference name.
+	 * @param data The object to be passed when triggering the callback
+	 * @return A pointer to a ui_data object.
+	 * */
+	void *(*connect_callback)(const char *name, PurplePrefCallbackData *data);
+
+	/**
+	 * Called when a callback is removed from a preference. The ui_data
+	 * object is the one returned from connect_callback.
+	 *
+	 * @param name The preference name
+	 * @param ui_data The object that was returned from the
+	 * connect_callback UI OP.
+	 * */
+	void (*disconnect_callback)(const char *name, void *ui_data);
+
+	void (*_purple_reserved1)(void);
+	void (*_purple_reserved2)(void);
+	void (*_purple_reserved3)(void);
+	void (*_purple_reserved4)(void);
+};
+
 G_BEGIN_DECLS
 
+/******************************************************************************
+ * UI Registration Functions
+ *****************************************************************************/
+
+/**
+ * Sets the UI operations structure to be used for preferences.
+ *
+ * @param ops The UI operations structure.
+ * @since 2.11.0
+ */
+void purple_prefs_set_ui_ops(PurplePrefsUiOps *ops);
+
+/**
+ * Returns the UI operations structure used for preferences.
+ *
+ * @return The UI operations structure in use.
+ * @since 2.11.0
+ */
+PurplePrefsUiOps *purple_prefs_get_ui_ops(void);
+
 /**************************************************************************/
 /*  Prefs API
     Preferences are named according to a directory-like structure.
@@ -394,6 +492,14 @@
 void purple_prefs_trigger_callback(const char *name);
 
 /**
+ * Trigger callbacks as if the pref changed, taking a #PurplePrefCallbackData
+ * instead of a name
+ *
+ * @since 2.11.0
+ */
+void purple_prefs_trigger_callback_object(PurplePrefCallbackData *data);
+
+/**
  * purple_prefs_load:
  *
  * Read preferences

mercurial