/pidgin/main: 5915afa891bd: Fix prefs for stuff that was broken ...

Gary Kramlich <[email protected]> Sat, 20 Aug 2016 14:36:48 -0400
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 5915afa891bdf6105aea541f4b31d6213dd83706
Author:	 Gary Kramlich <[email protected]>
Date:	 2016-08-19 23:51 -0500
Branch:	 default
URL: https://hg.pidgin.im/pidgin/main/rev/5915afa891bd

Description:

Fix prefs for stuff that was broken in the merge

diffstat:

 libpurple/prefs.c |   11 +++++
 libpurple/prefs.h |  106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+), 0 deletions(-)

diffs (146 lines):

diff --git a/libpurple/prefs.c b/libpurple/prefs.c
--- a/libpurple/prefs.c
+++ b/libpurple/prefs.c
@@ -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;
diff --git a/libpurple/prefs.h b/libpurple/prefs.h
--- a/libpurple/prefs.h
+++ b/libpurple/prefs.h
@@ -74,8 +74,106 @@ typedef enum
 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_disconnect_by_handle(v
 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

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits