gobjectification: b5667993: Re-add groups cache and fix compilation.

darkrain42 at pidgin.im darkrain42 at pidgin.im
Sun Jul 19 01:05:48 EDT 2009


-----------------------------------------------------------------
Revision: b56679931786ba0a6aaaaa42b76c93bd101f5bec
Ancestor: 535650f52ce2d662980c109a589863d499b4f962
Author: darkrain42 at pidgin.im
Date: 2009-07-19T02:59:11
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/b56679931786ba0a6aaaaa42b76c93bd101f5bec

Modified files:
        libpurple/account.c libpurple/blist.c

ChangeLog: 

Re-add groups cache and fix compilation.

-------------- next part --------------
============================================================
--- libpurple/account.c	ef78d06e8426ea1cc606d9bc7007ef6bf1a46208
+++ libpurple/account.c	8c895528783b0437f7f24a203c72769eb1e53298
@@ -114,6 +114,8 @@ static void set_current_error(PurpleAcco
 
 static void set_current_error(PurpleAccount *account,
 	PurpleConnectionErrorInfo *new_err);
+static void purple_account_set_protocol(PurpleAccount *account,
+	PurplePlugin *prpl);
 
 static void
 schedule_accounts_save(void)
@@ -469,12 +471,9 @@ purple_account_set_property(GObject *obj
 			purple_account_set_connection(account,
 				PURPLE_CONNECTION(g_value_get_object(value)));
 			break;
-		case PROP_PRPL: {
+		case PROP_PRPL:
 #warning use _object when the prpls are GObjects
-				PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
-				priv->prpl = g_value_get_pointer(value);
-				priv->protocol_id = g_strdup(purple_plugin_get_id(priv->prpl));
-			}
+			purple_account_set_protocol(account, g_value_get_pointer(value));
 			break;
 		case PROP_USER_INFO:
 			purple_account_set_user_info(account, g_value_get_string(value));
@@ -509,6 +508,7 @@ migrate_yahoo_japan(PurpleAccount *accou
 
 	if(purple_strequal(purple_account_get_protocol_id(account), "prpl-yahoo")) {
 		if(purple_account_get_bool(account, "yahoojp", FALSE)) {
+			PurplePlugin *prpl;
 			const char *serverjp = purple_account_get_string(account, "serverjp", NULL);
 			const char *xferjp_host = purple_account_get_string(account, "xferjp_host", NULL);
 
@@ -518,7 +518,10 @@ migrate_yahoo_japan(PurpleAccount *accou
 			purple_account_set_string(account, "server", serverjp);
 			purple_account_set_string(account, "xfer_host", xferjp_host);
 
-			purple_account_set_protocol_id(account, "prpl-yahoojp");
+			prpl = purple_find_prpl("prpl-yahoojp");
+			g_return_if_fail(prpl != NULL);
+
+			purple_account_set_protocol(account, prpl);
 		}
 
 		/* these should always be nuked */
@@ -1621,12 +1624,15 @@ void
 }
 
 void
-purple_account_remove_setting(PurpleAccount *account, const char *setting)
+purple_account_remove_setting(PurpleAccount *account, const char *name)
 {
-	g_return_if_fail(account != NULL);
-	g_return_if_fail(setting != NULL);
+	PurpleAccountPrivate *priv;
 
-	g_hash_table_remove(account->settings, setting);
+	g_return_if_fail(PURPLE_IS_ACCOUNT(account));
+	g_return_if_fail(name != NULL);
+
+	priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+	g_hash_table_remove(priv->settings, name);
 }
 
 void
@@ -1934,6 +1940,17 @@ purple_account_get_buddy_icon_path(const
 	return PURPLE_ACCOUNT_GET_PRIVATE(account)->buddy_icon_path;
 }
 
+static void
+purple_account_set_protocol(PurpleAccount *account, PurplePlugin *prpl)
+{
+	PurpleAccountPrivate *priv = PURPLE_ACCOUNT_GET_PRIVATE(account);
+
+	g_free(priv->protocol_id);
+
+	priv->prpl = prpl;
+	priv->protocol_id = g_strdup(purple_plugin_get_id(prpl));
+}
+
 const char *
 purple_account_get_protocol_id(const PurpleAccount *account)
 {
@@ -2818,9 +2835,6 @@ purple_accounts_uninit(void)
 {
 	gpointer handle = purple_accounts_get_handle();
 
-	for (; accounts; accounts = g_list_delete_link(accounts, accounts))
-		purple_account_destroy(accounts->data);
-
 	purple_signals_disconnect_by_handle(handle);
 	purple_signals_unregister_by_instance(handle);
 }
============================================================
--- libpurple/blist.c	bad55fe4d2388cd76ad5ce462372cd804440efa5
+++ libpurple/blist.c	d53bdad83daa4d14cf54adb9a834b705d664a078
@@ -57,6 +57,12 @@ struct _PurpleBuddyList {
 	 */
 	GHashTable *buddies_cache;
 
+	/**
+	 * A hash table used for efficient lookups of groups by name.
+	 * UTF-8 collate-key => PurpleGroup*.
+	 */
+	GHashTable *groups_cache;
+
 	guint save_timer;
 	gboolean blist_loaded;
 	void *ui_data;                /**< UI-specific data. */
@@ -497,6 +503,9 @@ void purple_blist_rename_group(PurpleGro
 		source = dest;
 		g_free(new_name);
 	} else {
+		PurpleBuddyList *list = purple_blist_get_list();
+		gchar *key;
+
 		/* A simple rename */
 		moved_buddies = purple_group_get_buddies(source);
 
@@ -504,11 +513,11 @@ void purple_blist_rename_group(PurpleGro
 		source->name = new_name;
 
 		key = g_utf8_collate_key(old_name, -1);
-		g_hash_table_remove(groups_cache, key);
+		g_hash_table_remove(list->groups_cache, key);
 		g_free(key);
 
 		key = g_utf8_collate_key(new_name, -1);
-		g_hash_table_insert(groups_cache, key, source);
+		g_hash_table_insert(list->groups_cache, key, source);
 	}
 
 	/* Save our changes */
@@ -756,6 +765,7 @@ void purple_blist_add_group(PurpleGroup 
 	PurpleBlistUiOps *ops;
 	PurpleBlistNode *gnode = PURPLE_BLIST_NODE(group);
 	PurpleBuddyList *list = purple_blist_get_list();
+	gchar *key;
 
 	g_return_if_fail(group != NULL);
 	g_return_if_fail(PURPLE_IS_GROUP(PURPLE_BLIST_NODE(group)));
@@ -773,6 +783,9 @@ void purple_blist_add_group(PurpleGroup 
 			ops->remove(PURPLE_BLIST_NODE(group));
 
 		purple_blist_node_remove(gnode);
+	} else {
+		key = g_utf8_collate_key(group->name, -1);
+		g_hash_table_insert(list->groups_cache, key, group);
 	}
 
 	if (node) {
@@ -918,10 +931,11 @@ purple_blist_remove_group(PurpleGroup *g
 static void
 purple_blist_remove_group(PurpleGroup *group)
 {
+	PurpleBuddyList *list = purple_blist_get_list();
 	PurpleBlistUiOps *ops = purple_blist_get_ui_ops();
 	PurpleBlistNode *node;
 	GList *l;
-	gchar* key;
+	gchar *key;
 
 	g_return_if_fail(group != NULL);
 
@@ -930,6 +944,10 @@ purple_blist_remove_group(PurpleGroup *g
 	if (purple_blist_node_is_empty(PURPLE_BLIST_NODE(group)))
 		return;
 
+	key = g_utf8_collate_key(group->name, -1);
+	g_hash_table_remove(list->groups_cache, key);
+	g_free(key);
+
 	/* Update the UI */
 	if (ops && ops->remove)
 		ops->remove(node);
@@ -949,16 +967,19 @@ PurpleGroup *purple_find_group(const cha
 
 PurpleGroup *purple_find_group(const char *name)
 {
-	PurpleBlistNode *node;
+	PurpleBuddyList *list;
+	PurpleGroup *group;
+	gchar *key;
 
 	g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL);
-	
-	for (; node != NULL; node = node->next) {
-		if (!purple_utf8_strcasecmp(((PurpleGroup *)node)->name, name))
-			return (PurpleGroup *)node;
-	}
 
-	return NULL;
+	list = purple_blist_get_list();
+
+	key = g_utf8_collate_key(name, -1);
+	group = g_hash_table_lookup(list->groups_cache, key);
+	g_free(key);
+
+	return group;
 }
 
 PurpleBuddy *purple_find_buddy(PurpleAccount *account, const char *name)
@@ -1583,6 +1604,7 @@ purple_blist_uninit(void)
 
 	g_hash_table_destroy(list->buddies);
 	g_hash_table_destroy(list->buddies_cache);
+	g_hash_table_destroy(list->groups_cache);
 
 	purple_signals_disconnect_by_handle(purple_blist_get_handle());
 	purple_signals_unregister_by_instance(purple_blist_get_handle());
@@ -1767,7 +1789,10 @@ purple_blist_instance_init(GTypeInstance
 	gbl->buddies_cache = g_hash_table_new_full(g_direct_hash, g_direct_equal,
 					 NULL, (GDestroyNotify)g_hash_table_destroy);
 
-		gbl->save_timer = 0;
+	gbl->groups_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
+					 (GDestroyNotify)g_free, NULL);
+
+	gbl->save_timer = 0;
 	gbl->blist_loaded = FALSE;
 
 	purple_blist_load();


More information about the Commits mailing list