/soc/2013/ankitkv/gobjectification: 579e9a8dbd5f: Moved methods ...
Ankit Vani
a at nevitus.org
Tue Jul 9 06:18:46 EDT 2013
Changeset: 579e9a8dbd5fe99bccb26d5be65f4b060fd98ec2
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-09 15:42 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/579e9a8dbd5f
Description:
Moved methods from buddylist.[ch] to the appropriate object files
diffstat:
libpurple/blistnodes.c | 11 +
libpurple/blistnodes.h | 7 +
libpurple/blistnodetypes.c | 408 +++++++++++++++++++++++++++++++++++-
libpurple/blistnodetypes.h | 26 ++-
libpurple/buddylist.c | 491 +-------------------------------------------
libpurple/buddylist.h | 76 +------
6 files changed, 454 insertions(+), 565 deletions(-)
diffs (truncated from 1288 to 300 lines):
diff --git a/libpurple/blistnodes.c b/libpurple/blistnodes.c
--- a/libpurple/blistnodes.c
+++ b/libpurple/blistnodes.c
@@ -325,6 +325,17 @@ purple_blist_node_get_extended_menu(Purp
return menu;
}
+void
+purple_blist_node_update(PurpleBListNode *node)
+{
+ PurpleBListUiOps *ops = purple_blist_get_ui_ops();
+
+ g_return_if_fail(node != NULL);
+
+ if (ops && ops->update)
+ ops->update(purple_blist_get_buddy_list(), node);
+}
+
static void
purple_blist_node_setting_free(gpointer data)
{
diff --git a/libpurple/blistnodes.h b/libpurple/blistnodes.h
--- a/libpurple/blistnodes.h
+++ b/libpurple/blistnodes.h
@@ -312,6 +312,13 @@ gboolean purple_blist_node_get_dont_save
*/
GList *purple_blist_node_get_extended_menu(PurpleBListNode *n);
+/**
+ * Updates a node's UI, such as when its custom icon has been changed.
+ *
+ * @param node The PurpleBListNode that is to be updated.
+ */
+void purple_blist_node_update(PurpleBListNode *node);
+
/*@}*/
/**************************************************************************/
diff --git a/libpurple/blistnodetypes.c b/libpurple/blistnodetypes.c
--- a/libpurple/blistnodetypes.c
+++ b/libpurple/blistnodetypes.c
@@ -129,6 +129,13 @@ enum
static PurpleBListNode *blistnode_parent_class;
static PurpleCountingNode *counting_parent_class;
+static gboolean
+purple_strings_are_different(const char *one, const char *two)
+{
+ return !((one && two && g_utf8_collate(one, two) == 0) ||
+ ((one == NULL || *one == '\0') && (two == NULL || *two == '\0')));
+}
+
/**************************************************************************/
/* Buddy API */
/**************************************************************************/
@@ -148,7 +155,7 @@ purple_buddy_set_icon(PurpleBuddy *buddy
purple_signal_emit(purple_blist_get_handle(), "buddy-icon-changed", buddy);
- purple_blist_update_node_icon(PURPLE_BLIST_NODE(buddy));
+ purple_blist_update_node(PURPLE_BLIST_NODE(buddy));
}
PurpleBuddyIcon *
@@ -178,8 +185,15 @@ purple_buddy_set_name(PurpleBuddy *buddy
g_return_if_fail(priv != NULL);
+ purple_blist_update_cache(buddy, name);
+
g_free(priv->name);
priv->name = purple_utf8_strip_unprintables(name);
+
+ if (ops && ops->save_node)
+ ops->save_node(PURPLE_BLIST_NODE(buddy));
+
+ purple_blist_node_update(PURPLE_BLIST_NODE(buddy));
}
const char *
@@ -276,12 +290,44 @@ const char *purple_buddy_get_alias(Purpl
void
purple_buddy_set_local_alias(PurpleBuddy *buddy, const char *alias)
{
+ PurpleBListUiOps *ops = purple_blist_get_ui_ops();
+ PurpleIMConversation *im;
+ char *old_alias;
+ char *new_alias = NULL;
PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
- g_return_if_fail(priv != NULL);
+ g_return_if_fail(buddy != NULL);
- g_free(priv->local_alias);
- priv->local_alias = purple_utf8_strip_unprintables(alias);
+ if ((alias != NULL) && (*alias != '\0'))
+ new_alias = purple_utf8_strip_unprintables(alias);
+
+ if (!purple_strings_are_different(priv->alias, new_alias)) {
+ g_free(new_alias);
+ return;
+ }
+
+ old_alias = priv->alias;
+
+ if ((new_alias != NULL) && (*new_alias != '\0'))
+ priv->alias = new_alias;
+ else {
+ priv->alias = NULL;
+ g_free(new_alias); /* could be "\0" */
+ }
+
+ if (ops && ops->save_node)
+ ops->save_node(PURPLE_BLIST_NODE(buddy));
+
+ purple_blist_node_update(PURPLE_BLIST_NODE(buddy));
+
+ im = purple_conversations_find_im_with_account(priv->name,
+ priv->account);
+ if (im)
+ purple_conversation_autoset_title(PURPLE_CONVERSATION(im));
+
+ purple_signal_emit(purple_blist_get_handle(), "blist-node-aliased",
+ buddy, old_alias);
+ g_free(old_alias);
}
const char *purple_buddy_get_local_alias(PurpleBuddy *buddy)
@@ -294,17 +340,46 @@ const char *purple_buddy_get_local_alias
}
void
-purple_buddy_set_server_alias(PurpleBuddy *buddy, const char *server_alias)
+purple_buddy_set_server_alias(PurpleBuddy *buddy, const char *alias)
{
+ PurpleBListUiOps *ops = purple_blist_get_ui_ops();
+ PurpleIMConversation *im;
+ char *old_alias;
+ char *new_alias = NULL;
PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
g_return_if_fail(priv != NULL);
- g_free(priv->server_alias);
- priv->server_alias = NULL;
+ if ((alias != NULL) && (*alias != '\0') && g_utf8_validate(alias, -1, NULL))
+ new_alias = purple_utf8_strip_unprintables(alias);
- if ((server_alias) && (*server_alias))
- priv->server_alias = purple_utf8_strip_unprintables(server_alias);
+ if (!purple_strings_are_different(priv->server_alias, new_alias)) {
+ g_free(new_alias);
+ return;
+ }
+
+ old_alias = priv->server_alias;
+
+ if ((new_alias != NULL) && (*new_alias != '\0'))
+ priv->server_alias = new_alias;
+ else {
+ priv->server_alias = NULL;
+ g_free(new_alias); /* could be "\0"; */
+ }
+
+ if (ops && ops->save_node)
+ ops->save_node(PURPLE_BLIST_NODE(buddy));
+
+ purple_blist_node_update(PURPLE_BLIST_NODE(buddy));
+
+ im = purple_conversations_find_im_with_account(priv->name,
+ priv->account);
+ if (im)
+ purple_conversation_autoset_title(PURPLE_CONVERSATION(im));
+
+ purple_signal_emit(purple_blist_get_handle(), "blist-node-aliased",
+ buddy, old_alias);
+ g_free(old_alias);
}
const char *purple_buddy_get_server_alias(PurpleBuddy *buddy)
@@ -335,6 +410,70 @@ PurplePresence *purple_buddy_get_presenc
return priv->presence;
}
+void
+purple_blist_update_buddy_status(PurpleBuddy *buddy, PurpleStatus *old_status)
+{
+ PurpleBListUiOps *ops = purple_blist_get_ui_ops();
+ PurpleStatus *status;
+ PurpleBListNode *cnode;
+ PurpleContact *contact;
+ PurpleCountingNode *contact_counter, *group_counter;
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+
+ g_return_if_fail(priv != NULL);
+
+ status = purple_presence_get_active_status(priv->presence);
+
+ purple_debug_info("blist", "Updating buddy status for %s (%s)\n",
+ priv->name, purple_account_get_protocol_name(priv->account));
+
+ if (purple_status_is_online(status) &&
+ !purple_status_is_online(old_status)) {
+
+ purple_signal_emit(purple_blist_get_handle(), "buddy-signed-on", buddy);
+
+ cnode = PURPLE_BLIST_NODE(buddy)->parent;
+ contact = PURPLE_CONTACT(cnode);
+ contact_counter = PURPLE_COUNTING_NODE(contact);
+ group_counter = PURPLE_COUNTING_NODE(cnode->parent);
+
+ purple_counting_node_change_online_count(contact_counter, +1);
+ if (purple_counting_node_get_online_count(contact_counter) == 1)
+ purple_counting_node_change_online_count(group_counter, +1);
+ } else if (!purple_status_is_online(status) &&
+ purple_status_is_online(old_status)) {
+
+ purple_blist_node_set_int(PURPLE_BLIST_NODE(buddy), "last_seen", time(NULL));
+ purple_signal_emit(purple_blist_get_handle(), "buddy-signed-off", buddy);
+
+ cnode = PURPLE_BLIST_NODE(buddy)->parent;
+ contact = PURPLE_CONTACT(cnode);
+ contact_counter = PURPLE_COUNTING_NODE(contact);
+ group_counter = PURPLE_COUNTING_NODE(cnode->parent);
+
+ purple_counting_node_change_online_count(contact_counter, -1);
+ if (purple_counting_node_get_online_count(contact_counter) == 0)
+ purple_counting_node_change_online_count(group_counter, -1);
+ } else {
+ purple_signal_emit(purple_blist_get_handle(),
+ "buddy-status-changed", buddy, old_status,
+ status);
+ }
+
+ /*
+ * This function used to only call the following two functions if one of
+ * the above signals had been triggered, but that's not good, because
+ * if someone's away message changes and they don't go from away to back
+ * to away then no signal is triggered.
+ *
+ * It's a safe assumption that SOMETHING called this function. PROBABLY
+ * because something, somewhere changed. Calling the stuff below
+ * certainly won't hurt anything. Unless you're on a K6-2 300.
+ */
+ purple_contact_invalidate_priority_buddy(purple_buddy_get_contact(buddy));
+ purple_blist_node_update(PURPLE_BLIST_NODE(buddy));
+}
+
PurpleMediaCaps purple_buddy_get_media_caps(const PurpleBuddy *buddy)
{
PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
@@ -665,12 +804,50 @@ purple_contact_get_group(const PurpleCon
void
purple_contact_set_alias(PurpleContact *contact, const char *alias)
{
+ PurpleBListUiOps *ops = purple_blist_get_ui_ops();
+ PurpleIMConversation *im;
+ PurpleBListNode *bnode;
+ char *old_alias;
+ char *new_alias = NULL;
PurpleContactPrivate *priv = PURPLE_CONTACT_GET_PRIVATE(contact);
g_return_if_fail(priv != NULL);
- g_free(priv->alias);
- priv->alias = purple_utf8_strip_unprintables(alias);
+ if ((alias != NULL) && (*alias != '\0'))
+ new_alias = purple_utf8_strip_unprintables(alias);
+
+ if (!purple_strings_are_different(priv->alias, new_alias)) {
+ g_free(new_alias);
+ return;
+ }
+
+ old_alias = priv->alias;
+
+ if ((new_alias != NULL) && (*new_alias != '\0'))
+ priv->alias = new_alias;
+ else {
+ priv->alias = NULL;
+ g_free(new_alias); /* could be "\0" */
+ }
+
+ if (ops && ops->save_node)
+ ops->save_node(PURPLE_BLIST_NODE(contact));
+
+ purple_blist_node_update(PURPLE_BLIST_NODE(contact));
+
+ for(bnode = PURPLE_BLIST_NODE(contact)->child; bnode != NULL; bnode = bnode->next)
+ {
+ PurpleBuddy *buddy = PURPLE_BUDDY(bnode);
+
+ im = purple_conversations_find_im_with_account(purple_buddy_get_name(buddy),
+ purple_buddy_get_account(buddy));
+ if (im)
+ purple_conversation_autoset_title(PURPLE_CONVERSATION(im));
+ }
+
+ purple_signal_emit(purple_blist_get_handle(), "blist-node-aliased",
+ contact, old_alias);
More information about the Commits
mailing list