/pidgin/main: 77c21aabb081: Add PurpleAccountPrefsUiOps API, der...

dx <[email protected]>
Newsgroups gmane.comp.gnome.gaim.cvs
Message-ID <[email protected]>
Changeset: 77c21aabb081ce8978a989ecb3cf744cb165db5a
Author:	 dx <[email protected]>
Date:	 2016-06-16 14:04 -0300
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/77c21aabb081

Description:

Add PurpleAccountPrefsUiOps API, derived from instantbird

Derived, because instantbird just added three setters to the accounts ui ops.
I added a separate struct to have more methods, such as load/save, which are
used to override the accounts.xml code, which instantbird just removed in their
fork.

diffstat:

 ChangeLog.API       |   2 +
 libpurple/account.c |  60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 libpurple/account.h |  39 ++++++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+), 0 deletions(-)

diffs (226 lines):

diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -9,6 +9,8 @@ version 2.11.0:
 		  built-in handling of commands.
 		* PurplePrefsUiOps, to allow the UI to override the way global
 		  preferences are stored.
+		* PurpleAccountPrefsUiOps, to allow the UI to handle storage
+		  of account preferences.
 		* purple_media_set_encryption_parameters
 		* purple_media_set_decryption_parameters
 		* purple_xfer_write_file
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -84,6 +84,7 @@ typedef struct
 } PurpleAccountRequestInfo;
 
 static PurpleAccountUiOps *account_ui_ops = NULL;
+static PurpleAccountPrefsUiOps *account_prefs_ui_ops = NULL;
 
 static GList   *accounts = NULL;
 static guint    save_timer = 0;
@@ -480,6 +481,7 @@ accounts_to_xmlnode(void)
 static void
 sync_accounts(void)
 {
+	PurpleAccountPrefsUiOps *ui_ops;
 	xmlnode *node;
 	char *data;
 
@@ -490,6 +492,13 @@ sync_accounts(void)
 		return;
 	}
 
+	ui_ops = purple_account_prefs_get_ui_ops();
+
+	if (ui_ops != NULL && ui_ops->save != NULL) {
+		ui_ops->save();
+		return;
+	}
+
 	node = accounts_to_xmlnode();
 	data = xmlnode_to_formatted_str(node, NULL);
 	purple_util_write_data_to_file("accounts.xml", data, -1);
@@ -508,6 +517,15 @@ save_cb(gpointer data)
 static void
 schedule_accounts_save(void)
 {
+	PurpleAccountPrefsUiOps *ui_ops;
+
+	ui_ops = purple_account_prefs_get_ui_ops();
+
+	if (ui_ops != NULL && ui_ops->schedule_save != NULL) {
+		ui_ops->schedule_save();
+		return;
+	}
+
 	if (save_timer == 0)
 		save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
 }
@@ -1019,10 +1037,19 @@ parse_account(xmlnode *node)
 static void
 load_accounts(void)
 {
+	PurpleAccountPrefsUiOps *ui_ops;
 	xmlnode *node, *child;
 
 	accounts_loaded = TRUE;
 
+	ui_ops = purple_account_prefs_get_ui_ops();
+
+	if (ui_ops != NULL && ui_ops->load != NULL) {
+		ui_ops->load();
+		_purple_buddy_icons_account_loaded_cb();
+		return;
+	}
+
 	node = purple_util_read_xml_from_file("accounts.xml", _("accounts"));
 
 	if (node == NULL)
@@ -2036,6 +2063,7 @@ void
 purple_account_set_int(PurpleAccount *account, const char *name, int value)
 {
 	PurpleAccountSetting *setting;
+	PurpleAccountPrefsUiOps *ui_ops;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
@@ -2047,6 +2075,12 @@ purple_account_set_int(PurpleAccount *ac
 
 	g_hash_table_insert(account->settings, g_strdup(name), setting);
 
+	ui_ops = purple_account_prefs_get_ui_ops();
+
+	if (ui_ops != NULL && ui_ops->set_int != NULL) {
+		ui_ops->set_int(account, name, value);
+	}
+
 	schedule_accounts_save();
 }
 
@@ -2055,6 +2089,7 @@ purple_account_set_string(PurpleAccount 
 						const char *value)
 {
 	PurpleAccountSetting *setting;
+	PurpleAccountPrefsUiOps *ui_ops;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
@@ -2066,6 +2101,12 @@ purple_account_set_string(PurpleAccount 
 
 	g_hash_table_insert(account->settings, g_strdup(name), setting);
 
+	ui_ops = purple_account_prefs_get_ui_ops();
+
+	if (ui_ops != NULL && ui_ops->set_string != NULL) {
+		ui_ops->set_string(account, name, value);
+	}
+
 	schedule_accounts_save();
 }
 
@@ -2073,6 +2114,7 @@ void
 purple_account_set_bool(PurpleAccount *account, const char *name, gboolean value)
 {
 	PurpleAccountSetting *setting;
+	PurpleAccountPrefsUiOps *ui_ops;
 
 	g_return_if_fail(account != NULL);
 	g_return_if_fail(name    != NULL);
@@ -2084,6 +2126,12 @@ purple_account_set_bool(PurpleAccount *a
 
 	g_hash_table_insert(account->settings, g_strdup(name), setting);
 
+	ui_ops = purple_account_prefs_get_ui_ops();
+
+	if (ui_ops != NULL && ui_ops->set_bool != NULL) {
+		ui_ops->set_bool(account, name, value);
+	}
+
 	schedule_accounts_save();
 }
 
@@ -3150,6 +3198,18 @@ purple_accounts_get_ui_ops(void)
 	return account_ui_ops;
 }
 
+void
+purple_account_prefs_set_ui_ops(PurpleAccountPrefsUiOps *ops)
+{
+	account_prefs_ui_ops = ops;
+}
+
+PurpleAccountPrefsUiOps *
+purple_account_prefs_get_ui_ops(void)
+{
+	return account_prefs_ui_ops;
+}
+
 void *
 purple_accounts_get_handle(void)
 {
diff --git a/libpurple/account.h b/libpurple/account.h
--- a/libpurple/account.h
+++ b/libpurple/account.h
@@ -32,6 +32,8 @@
 
 /** @copydoc _PurpleAccountUiOps */
 typedef struct _PurpleAccountUiOps PurpleAccountUiOps;
+/** @copydoc _PurpleAccountPrefsUiOps */
+typedef struct _PurpleAccountPrefsUiOps PurpleAccountPrefsUiOps;
 /** @copydoc _PurpleAccount */
 typedef struct _PurpleAccount      PurpleAccount;
 
@@ -121,6 +123,29 @@ struct _PurpleAccountUiOps
 	void (*_purple_reserved4)(void);
 };
 
+/**  Account prefs UI operations, to allow the UI to catch account preference
+ *   changes. Unlike the #PurplePrefsUiOps API, these are always stored
+ *   internally in a hash table. If the UI wants to handle accounts settings,
+ *   it must set them to the account on load and handle changes with set_
+ *   methods. Implementing load/save/schedule_save disables the built-in
+ *   accounts.xml code.
+ */
+struct _PurpleAccountPrefsUiOps
+{
+	void (*set_int)(PurpleAccount *account, const char *name, int value);
+	void (*set_string)(PurpleAccount *account, const char *name, const char *value);
+	void (*set_bool)(PurpleAccount *account, const char *name, gboolean value);
+
+	void (*load)(void);
+	void (*save)(void);
+	void (*schedule_save)(void);
+
+	void (*_purple_reserved1)(void);
+	void (*_purple_reserved2)(void);
+	void (*_purple_reserved3)(void);
+	void (*_purple_reserved4)(void);
+};
+
 /** Structure representing an account.
  */
 struct _PurpleAccount
@@ -1160,6 +1185,20 @@ void purple_accounts_set_ui_ops(PurpleAc
  */
 PurpleAccountUiOps *purple_accounts_get_ui_ops(void);
 
+/**
+ * Sets the UI operations structure to be used for account preferences.
+ *
+ * @param ops The UI operations structure.
+ */
+void purple_account_prefs_set_ui_ops(PurpleAccountPrefsUiOps *ops);
+
+/**
+ * Returns the UI operations structure used for account preferences.
+ *
+ * @return The UI operations structure in use.
+ */
+PurpleAccountPrefsUiOps *purple_account_prefs_get_ui_ops(void);
+
 /*@}*/
 
 

_______________________________________________
Commits mailing list
[email protected]
https://pidgin.im/cgi-bin/mailman/listinfo/commits
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.