/soc/2013/ankitkv/gobjectification: 19850cd1b2de: Begun GObjecti...
Ankit Vani
a at nevitus.org
Mon Jun 17 09:27:40 EDT 2013
Changeset: 19850cd1b2ded8146b4f561c8f05a329c417cdd0
Author: Ankit Vani <a at nevitus.org>
Date: 2013-06-17 18:57 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/19850cd1b2de
Description:
Begun GObjectification of PurpleAccount. Moved things around, see details.
* Created accounts.[ch] for purple_accounts_* API, account.[ch] belongs to the PurpleAccount object.
* Removed privacy.[ch]. These were basically PurpleAccount methods and appropriately belong to the object's account.[ch] file.
* purple_privacy_* functions are now purple_account_privacy_* functions.
* PurplePrivacyType is now PurpleAccountPrivacyType
diffstat:
libpurple/Makefile.am | 6 +-
libpurple/account.c | 831 ++++++++++++++++++++++++++-----------------------
libpurple/account.h | 370 +++++++++------------
libpurple/accounts.c | 414 ++++++++++++++++++++++++
libpurple/accounts.h | 218 +++++++++++++
libpurple/privacy.c | 411 ------------------------
libpurple/privacy.h | 190 -----------
7 files changed, 1232 insertions(+), 1208 deletions(-)
diffs (truncated from 2597 to 300 lines):
diff --git a/libpurple/Makefile.am b/libpurple/Makefile.am
--- a/libpurple/Makefile.am
+++ b/libpurple/Makefile.am
@@ -38,6 +38,7 @@ SUBDIRS = $(GCONF_DIR) plugins protocols
purple_coresources = \
account.c \
+ accounts.c \
accountopt.c \
blist.c \
buddyicon.c \
@@ -75,7 +76,6 @@ purple_coresources = \
pluginpref.c \
pounce.c \
prefs.c \
- privacy.c \
proxy.c \
prpl.c \
request.c \
@@ -108,6 +108,7 @@ purple_builtsources = \
purple_coreheaders = \
account.h \
+ accounts.h \
accountopt.h \
blist.h \
buddyicon.h \
@@ -141,7 +142,6 @@ purple_coreheaders = \
pluginpref.h \
pounce.h \
prefs.h \
- privacy.h \
proxy.h \
prpl.h \
request.h \
@@ -203,7 +203,7 @@ CLEANFILES = \
dbus_sources = dbus-server.c dbus-useful.c
dbus_headers = dbus-bindings.h dbus-purple.h dbus-server.h dbus-useful.h dbus-define-api.h dbus-types.h
-dbus_exported = dbus-useful.h dbus-define-api.h account.h blist.h buddyicon.h \
+dbus_exported = dbus-useful.h dbus-define-api.h account.h accounts.h blist.h buddyicon.h \
connection.h conversation.h core.h ft.h log.h notify.h prefs.h roomlist.h \
savedstatuses.h smiley.h status.h server.h util.h xmlnode.h prpl.h
diff --git a/libpurple/account.c b/libpurple/account.c
--- a/libpurple/account.c
+++ b/libpurple/account.c
@@ -24,7 +24,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
*/
#include "internal.h"
-#include "account.h"
+#include "accounts.h"
#include "core.h"
#include "dbus-maybe.h"
#include "debug.h"
@@ -42,6 +42,57 @@
#include "util.h"
#include "xmlnode.h"
+#define PURPLE_ACCOUNT_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE((obj), PURPLE_TYPE_ACCOUNT, PurpleAccountPrivate))
+
+typedef struct
+{
+ char *username; /**< The username. */
+ char *alias; /**< How you appear to yourself. */
+ char *password; /**< The account password. */
+ char *user_info; /**< User information. */
+
+ char *buddy_icon_path; /**< The buddy icon's non-cached path. */
+
+ gboolean remember_pass; /**< Remember the password. */
+
+ char *protocol_id; /**< The ID of the protocol. */
+
+ PurpleConnection *gc; /**< The connection handle. */
+ gboolean disconnecting; /**< The account is currently disconnecting */
+
+ GHashTable *settings; /**< Protocol-specific settings. */
+ GHashTable *ui_settings; /**< UI-specific settings. */
+
+ PurpleProxyInfo *proxy_info; /**< Proxy information. This will be set */
+ /* to NULL when the account inherits */
+ /* proxy settings from global prefs. */
+
+ /*
+ * TODO: Supplementing the next two linked lists with hash tables
+ * should help performance a lot when these lists are long. This
+ * matters quite a bit for protocols like MSN, where all your
+ * buddies are added to your permit list. Currently we have to
+ * iterate through the entire list if we want to check if someone
+ * is permitted or denied. We should do this for 3.0.0.
+ * Or maybe use a GTree.
+ */
+ GSList *permit; /**< Permit list. */
+ GSList *deny; /**< Deny list. */
+ PurpleAccountPrivacyType perm_deny; /**< The permit/deny setting. */
+
+ GList *status_types; /**< Status types. */
+
+ PurplePresence *presence; /**< Presence. */
+ PurpleLog *system_log; /**< The system log */
+
+ void *ui_data; /**< The UI can put data here. */
+ PurpleAccountRegistrationCb registration_cb;
+ void *registration_cb_user_data;
+
+ PurpleConnectionErrorInfo *current_error; /**< Errors */
+} PurpleAccountPrivate;
+
/* TODO: Should use PurpleValue instead of this? What about "ui"? */
typedef struct
{
@@ -1858,7 +1909,7 @@ purple_account_set_proxy_info(PurpleAcco
}
void
-purple_account_set_privacy_type(PurpleAccount *account, PurplePrivacyType privacy_type)
+purple_account_set_privacy_type(PurpleAccount *account, PurpleAccountPrivacyType privacy_type)
{
g_return_if_fail(account != NULL);
@@ -2402,7 +2453,7 @@ purple_account_get_proxy_info(const Purp
return account->proxy_info;
}
-PurplePrivacyType
+PurpleAccountPrivacyType
purple_account_get_privacy_type(const PurpleAccount *account)
{
g_return_val_if_fail(account != NULL, PURPLE_PRIVACY_ALLOW_ALL);
@@ -2410,6 +2461,371 @@ purple_account_get_privacy_type(const Pu
return account->perm_deny;
}
+gboolean
+purple_account_privacy_permit_add(PurpleAccount *account, const char *who,
+ gboolean local_only)
+{
+ GSList *l;
+ char *name;
+ PurpleBuddy *buddy;
+ PurpleBlistUiOps *blist_ops;
+
+ g_return_val_if_fail(account != NULL, FALSE);
+ g_return_val_if_fail(who != NULL, FALSE);
+
+ name = g_strdup(purple_normalize(account, who));
+
+ for (l = account->permit; l != NULL; l = l->next) {
+ if (g_str_equal(name, l->data))
+ /* This buddy already exists */
+ break;
+ }
+
+ if (l != NULL)
+ {
+ /* This buddy already exists, so bail out */
+ g_free(name);
+ return FALSE;
+ }
+
+ account->permit = g_slist_append(account->permit, name);
+
+ if (!local_only && purple_account_is_connected(account))
+ serv_add_permit(purple_account_get_connection(account), who);
+
+ if (privacy_ops != NULL && privacy_ops->permit_added != NULL)
+ privacy_ops->permit_added(account, who);
+
+ blist_ops = purple_blist_get_ui_ops();
+ if (blist_ops != NULL && blist_ops->save_account != NULL)
+ blist_ops->save_account(account);
+
+ /* This lets the UI know a buddy has had its privacy setting changed */
+ buddy = purple_find_buddy(account, name);
+ if (buddy != NULL) {
+ purple_signal_emit(purple_blist_get_handle(),
+ "buddy-privacy-changed", buddy);
+ }
+ return TRUE;
+}
+
+gboolean
+purple_account_privacy_permit_remove(PurpleAccount *account, const char *who,
+ gboolean local_only)
+{
+ GSList *l;
+ const char *name;
+ PurpleBuddy *buddy;
+ char *del;
+ PurpleBlistUiOps *blist_ops;
+
+ g_return_val_if_fail(account != NULL, FALSE);
+ g_return_val_if_fail(who != NULL, FALSE);
+
+ name = purple_normalize(account, who);
+
+ for (l = account->permit; l != NULL; l = l->next) {
+ if (g_str_equal(name, l->data))
+ /* We found the buddy we were looking for */
+ break;
+ }
+
+ if (l == NULL)
+ /* We didn't find the buddy we were looking for, so bail out */
+ return FALSE;
+
+ /* We should not free l->data just yet. There can be occasions where
+ * l->data == who. In such cases, freeing l->data here can cause crashes
+ * later when who is used. */
+ del = l->data;
+ account->permit = g_slist_delete_link(account->permit, l);
+
+ if (!local_only && purple_account_is_connected(account))
+ serv_rem_permit(purple_account_get_connection(account), who);
+
+ if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
+ privacy_ops->permit_removed(account, who);
+
+ blist_ops = purple_blist_get_ui_ops();
+ if (blist_ops != NULL && blist_ops->save_account != NULL)
+ blist_ops->save_account(account);
+
+ buddy = purple_find_buddy(account, name);
+ if (buddy != NULL) {
+ purple_signal_emit(purple_blist_get_handle(),
+ "buddy-privacy-changed", buddy);
+ }
+ g_free(del);
+ return TRUE;
+}
+
+gboolean
+purple_account_privacy_deny_add(PurpleAccount *account, const char *who,
+ gboolean local_only)
+{
+ GSList *l;
+ char *name;
+ PurpleBuddy *buddy;
+ PurpleBlistUiOps *blist_ops;
+
+ g_return_val_if_fail(account != NULL, FALSE);
+ g_return_val_if_fail(who != NULL, FALSE);
+
+ name = g_strdup(purple_normalize(account, who));
+
+ for (l = account->deny; l != NULL; l = l->next) {
+ if (g_str_equal(name, l->data))
+ /* This buddy already exists */
+ break;
+ }
+
+ if (l != NULL)
+ {
+ /* This buddy already exists, so bail out */
+ g_free(name);
+ return FALSE;
+ }
+
+ account->deny = g_slist_append(account->deny, name);
+
+ if (!local_only && purple_account_is_connected(account))
+ serv_add_deny(purple_account_get_connection(account), who);
+
+ if (privacy_ops != NULL && privacy_ops->deny_added != NULL)
+ privacy_ops->deny_added(account, who);
+
+ blist_ops = purple_blist_get_ui_ops();
+ if (blist_ops != NULL && blist_ops->save_account != NULL)
+ blist_ops->save_account(account);
+
+ buddy = purple_find_buddy(account, name);
+ if (buddy != NULL) {
+ purple_signal_emit(purple_blist_get_handle(),
+ "buddy-privacy-changed", buddy);
+ }
+ return TRUE;
+}
+
+gboolean
+purple_account_privacy_deny_remove(PurpleAccount *account, const char *who,
+ gboolean local_only)
+{
+ GSList *l;
+ const char *normalized;
+ char *name;
+ PurpleBuddy *buddy;
+ PurpleBlistUiOps *blist_ops;
+
+ g_return_val_if_fail(account != NULL, FALSE);
+ g_return_val_if_fail(who != NULL, FALSE);
+
+ normalized = purple_normalize(account, who);
+
+ for (l = account->deny; l != NULL; l = l->next) {
+ if (g_str_equal(normalized, l->data))
+ /* We found the buddy we were looking for */
+ break;
More information about the Commits
mailing list