gobjectification: ea249c11: Moved static members into the blist

aluink at soc.pidgin.im aluink at soc.pidgin.im
Wed Jun 17 22:45:31 EDT 2009


-----------------------------------------------------------------
Revision: ea249c11e7db598e9f5065f1108f036aafaf902b
Ancestor: c49679fe2f258d93fee76c0b93a443ba80d13348
Author: aluink at soc.pidgin.im
Date: 2009-06-18T02:42:56
Branch: im.pidgin.gobjectification
URL: http://d.pidgin.im/viewmtn/revision/info/ea249c11e7db598e9f5065f1108f036aafaf902b

Modified files:
        libpurple/blist-node.c libpurple/blist.c libpurple/blist.h
        libpurple/buddy.c

ChangeLog: 

Moved static members into the blist

-------------- next part --------------
============================================================
--- libpurple/blist-node.c	16a8a85a3bbccef21285847d7720542d36835ec9
+++ libpurple/blist-node.c	012ebcef37b491e77286755a9c9ae5b67424ea86
@@ -320,7 +320,7 @@ void purple_blist_add_buddy(PurpleBuddy 
 			hb->group = bnode->parent->parent;
 			g_hash_table_remove(purplebuddylist->buddies, hb);
 
-			account_buddies = g_hash_table_lookup(purple_blist_get_buddies_cache(), buddy->account);
+			account_buddies = g_hash_table_lookup(purplebuddylist->buddies_cache, buddy->account);
 			g_hash_table_remove(account_buddies, hb);
 
 			g_free(hb->name);
@@ -369,7 +369,7 @@ void purple_blist_add_buddy(PurpleBuddy 
 
 	g_hash_table_replace(purplebuddylist->buddies, hb, buddy);
 
-	account_buddies = g_hash_table_lookup(purple_blist_get_buddies_cache(), buddy->account);
+	account_buddies = g_hash_table_lookup(purplebuddylist->buddies_cache, buddy->account);
 
 	hb2 = g_new(struct _purple_hbuddy, 1);
 	hb2->name = g_strdup(hb->name);
============================================================
--- libpurple/blist.c	6864a498c29b33e946e5c40bfe2bb1c86b74d175
+++ libpurple/blist.c	f7225321b42f1a8b1ec6274cd18f57a27ad79101
@@ -42,16 +42,7 @@ PurpleBuddyList *purplebuddylist = NULL;
 
 PurpleBuddyList *purplebuddylist = NULL;
 
-/**
- * A hash table used for efficient lookups of buddies by name.
- * PurpleAccount* => GHashTable*, with the inner hash table being
- * struct _purple_hbuddy => PurpleBuddy*
- */
-static GHashTable *buddies_cache = NULL;
 
-static guint          save_timer = 0;
-static gboolean       blist_loaded = FALSE;
-
 /*********************************************************************
  * Private utility functions                                         *
  *********************************************************************/
@@ -78,33 +69,15 @@ purple_blist_buddies_cache_add_account(P
 	GHashTable *account_buddies = g_hash_table_new_full((GHashFunc)_purple_blist_hbuddy_hash,
 						(GEqualFunc)_purple_blist_hbuddy_equal,
 						(GDestroyNotify)_purple_blist_hbuddy_free_key, NULL);
-	g_hash_table_insert(buddies_cache, account, account_buddies);
+	g_hash_table_insert(purplebuddylist->buddies_cache, account, account_buddies);
 }
 
 static void
 purple_blist_buddies_cache_remove_account(const PurpleAccount *account)
 {
-	g_hash_table_remove(buddies_cache, account);
+	g_hash_table_remove(purplebuddylist->buddies_cache, account);
 }
 
-GHashTable* 
-purple_blist_get_buddies_cache(void)
-{
-  return buddies_cache;
-}
-
-guint 
-purple_blist_get_save_timer(void)
-{
-  return save_timer;
-}
-
-gboolean 
-purple_blist_get_blist_loaded(void)
-{
-  return blist_loaded;
-}
-
 /*********************************************************************
  * Writing to disk                                                   *
  *********************************************************************/
@@ -220,7 +193,7 @@ purple_blist_sync(void)
 	xmlnode *node;
 	char *data;
 
-	if (!blist_loaded)
+	if (!purplebuddylist->blist_loaded)
 	{
 		purple_debug_error("blist", "Attempted to save buddy list before it "
 						 "was read!\n");
@@ -238,15 +211,15 @@ save_cb(gpointer data)
 save_cb(gpointer data)
 {
 	purple_blist_sync();
-	save_timer = 0;
+	purplebuddylist->save_timer = 0;
 	return FALSE;
 }
 
 void
 purple_blist_schedule_save()
 {
-	if (save_timer == 0)
-		save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
+	if (purplebuddylist->save_timer == 0)
+		purplebuddylist->save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
 }
 
 
@@ -260,7 +233,7 @@ purple_blist_load()
 {
 	xmlnode *purple, *blist, *privacy;
 
-	blist_loaded = TRUE;
+	purplebuddylist->blist_loaded = TRUE;
 
 	purple = purple_util_read_xml_from_file("blist.xml", _("buddy list"));
 
@@ -348,7 +321,7 @@ PurpleBuddyList *purple_blist_new()
 					 (GEqualFunc)_purple_blist_hbuddy_equal,
 					 (GDestroyNotify)_purple_blist_hbuddy_free_key, NULL);
 
-	buddies_cache = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+	gbl->buddies_cache = g_hash_table_new_full(g_direct_hash, g_direct_equal,
 					 NULL, (GDestroyNotify)g_hash_table_destroy);
 
 	for (account = purple_accounts_get_all(); account != NULL; account = account->next)
@@ -359,6 +332,9 @@ PurpleBuddyList *purple_blist_new()
 	if (ui_ops != NULL && ui_ops->new_list != NULL)
 		ui_ops->new_list(gbl);
 
+  gbl->save_timer = 0;
+  gbl->blist_loaded = FALSE;
+
 	return gbl;
 }
 
@@ -480,7 +456,7 @@ void purple_blist_add_contact(PurpleCont
 
 				g_hash_table_remove(purplebuddylist->buddies, hb);
 
-				account_buddies = g_hash_table_lookup(buddies_cache, b->account);
+				account_buddies = g_hash_table_lookup(purplebuddylist->buddies_cache, b->account);
 				g_hash_table_remove(account_buddies, hb);
 
 				if (!purple_find_buddy_in_group(b->account, b->name, g)) {
@@ -729,7 +705,7 @@ void purple_blist_remove_buddy(PurpleBud
 	hb.group = gnode;
 	g_hash_table_remove(purplebuddylist->buddies, &hb);
 
-	account_buddies = g_hash_table_lookup(buddies_cache, buddy->account);
+	account_buddies = g_hash_table_lookup(purplebuddylist->buddies_cache, buddy->account);
 	g_hash_table_remove(account_buddies, &hb);
 
 	g_free(hb.name);
@@ -895,7 +871,7 @@ GSList *purple_find_buddies(PurpleAccoun
 		g_free(hb.name);
 	} else {
 		GSList *list = NULL;
-		GHashTable *buddies = g_hash_table_lookup(buddies_cache, account);
+		GHashTable *buddies = g_hash_table_lookup(purplebuddylist->buddies_cache, account);
 		g_hash_table_foreach(buddies, find_acct_buddies, &list);
 		ret = list;
 	}
@@ -1230,9 +1206,9 @@ purple_blist_uninit(void)
 	if (purplebuddylist == NULL)
 		return;
 
-	if (save_timer != 0) {
-		purple_timeout_remove(save_timer);
-		save_timer = 0;
+	if (purplebuddylist->save_timer != 0) {
+		purple_timeout_remove(purplebuddylist->save_timer);
+		purplebuddylist->save_timer = 0;
 		purple_blist_sync();
 	}
 
@@ -1245,7 +1221,7 @@ purple_blist_uninit(void)
 	purplebuddylist->root = NULL;
 	
 	g_hash_table_destroy(purplebuddylist->buddies);
-	g_hash_table_destroy(buddies_cache);
+	g_hash_table_destroy(purplebuddylist->buddies_cache);
 
 	purple_signals_disconnect_by_handle(purple_blist_get_handle());
 	purple_signals_unregister_by_instance(purple_blist_get_handle());
============================================================
--- libpurple/blist.h	a3fbc83380d88ef0c1afbead0448998de91444d6
+++ libpurple/blist.h	933584f74e0bda74d03dfb0311c4ef52e01cebed
@@ -193,6 +193,16 @@ struct _PurpleBuddyList {
 struct _PurpleBuddyList {
 	PurpleBlistNode *root;          /**< The first node in the buddy list */
 	GHashTable *buddies;          /**< Every buddy in this list */
+  
+  /**
+   * A hash table used for efficient lookups of buddies by name.
+   * PurpleAccount* => GHashTable*, with the inner hash table being
+   * struct _purple_hbuddy => PurpleBuddy*
+   */
+  GHashTable *buddies_cache;
+
+  guint          save_timer;
+  gboolean       blist_loaded;
 	void *ui_data;                /**< UI-specific data. */
 };
 
@@ -258,9 +268,7 @@ extern PurpleBuddyList* purplebuddylist;
 };
 
 extern PurpleBuddyList* purplebuddylist;
-GHashTable* purple_blist_get_buddies_cache(void);
-guint purple_blist_get_save_timer(void);
-gboolean purple_blist_get_blist_loaded(void);
+
 void purple_blist_node_initialize_settings(PurpleBlistNode *node);
 void purple_blist_node_destroy(PurpleBlistNode* node);
 
============================================================
--- libpurple/buddy.c	6af89162c92ca26e2d32b05c472069606033921d
+++ libpurple/buddy.c	675bf8a5ec6d986afd72d68467c94bd5392d2ca6
@@ -179,7 +179,7 @@ void purple_blist_rename_buddy(PurpleBud
 	hb->group = ((PurpleBlistNode *)buddy)->parent->parent;
 	g_hash_table_remove(purplebuddylist->buddies, hb);
 	
-	account_buddies = g_hash_table_lookup(purple_blist_get_buddies_cache(), buddy->account);
+	account_buddies = g_hash_table_lookup(purplebuddylist->buddies_cache, buddy->account);
 	g_hash_table_remove(account_buddies, hb);
 
 	g_free(hb->name);


More information about the Commits mailing list