soc.2012.statscollector: 11bccdc4: Add languages used by the user
sanket at sanketagarwal.com
sanket at sanketagarwal.com
Mon May 14 13:27:50 EDT 2012
----------------------------------------------------------------------
Revision: 11bccdc4e26cf03ef07c1dac41a7387f3dc4ce0f
Parent: f4ee3efc2f4ba4b4454523a880d22e2319b3f665
Author: sanket at sanketagarwal.com
Date: 05/14/12 05:47:22
Branch: im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/11bccdc4e26cf03ef07c1dac41a7387f3dc4ce0f
Changelog:
Add languages used by the user
Languages are considered to be "CPUinfo" components. My definition of CPUinfo
is that ``static'' data which is unlikely to change (well ofcourse user can
change his hardware or language preferences). The better distinction could be
to keep userinfo and hardware info etc.
Changes against parent f4ee3efc2f4ba4b4454523a880d22e2319b3f665
patched pidgin/plugins/statscollector.c
-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c ed33c8898f25c70f385323b43eaee850a70a0f0d
+++ pidgin/plugins/statscollector.c d46ca27bcb741f00ed1e2e840832ec7130cdfbdd
@@ -16,7 +16,7 @@
#define STATS_MAJOR_VERSION 1
#define STATS_MINOR_VERSION 0
-xmlnode *root_stats;
+xmlnode *root_stats, *cpuinfo_xml;
GHashTable *stats_acc_ht, *stats_plugins_ht;
int save_timer = 0;
@@ -28,12 +28,13 @@ save_xml(){
* final modified XML out of it to be flushed
*/
- GHashTableIter iter;
+ GHashTableIter * iter;
gpointer key, value;
xmlnode *nroot, *nacc, *nplugins, *node;
char *data;
nroot = xmlnode_new("stats");
+
nacc = xmlnode_new_child(nroot, "accounts");
nplugins = xmlnode_new_child(nroot, "plugins");
@@ -59,6 +60,9 @@ save_xml(){
}
+ /* Load CPUinfo strucutre */
+ xmlnode_insert_child(nroot, cpuinfo_xml);
+
data = xmlnode_to_formatted_str(nroot, NULL);
purple_util_write_data_to_file("stats.xml", data, -1);
@@ -77,6 +81,40 @@ schedule_stats_save(void){
save_timer = purple_timeout_add_seconds(5, save_cb, NULL);
}
+static xmlnode *
+get_cpuinfo_xml(){
+
+ /* Obtains a XML node containing the CPU info */
+
+ xmlnode *root, *languages, *hardware, *node;
+ const char * const * langs;
+ int i;
+
+ root = xmlnode_new("cpuinfo");
+
+ /* Languages */
+
+ langs = g_get_language_names();
+
+ languages = xmlnode_new("languages");
+ xmlnode_insert_child(root, languages);
+
+ for(i=0;langs[i];i++){
+
+ purple_debug_info("STATS", "Langs: %s\n", langs[i]);
+ node = xmlnode_new("language");
+ xmlnode_insert_data(node, langs[i], -1);
+ xmlnode_insert_child(languages, node);
+
+ }
+
+ purple_debug_info("STATS", "%s\n", xmlnode_to_formatted_str(root, NULL));
+
+ return root;
+
+}
+
+
static void
sign_on_event(PurpleAccount *account){
@@ -133,7 +171,7 @@ plugin_load_event(PurplePlugin *plugin){
plugin_type = (PurplePluginType) plugin->info->type;
- purple_debug_info("STATS", "Plugin %s %d\n", plugin_id, plugin_type);
+ /* purple_debug_info("STATS", "Plugin %s %d\\n", plugin_id, plugin_type); */
/* check if the account already exist in our XML file */
@@ -164,6 +202,7 @@ plugin_load_event(PurplePlugin *plugin){
schedule_stats_save();
}
+
static xmlnode *
init_stats(){
@@ -175,26 +214,24 @@ init_stats(){
/* GHashTableIter *iter; */
GList *loaded_plugins;
- char *data;
xmlnode *stats_acc_xml, *stats_plugins_xml;
xmlnode *start, *u_node;
+
/* Load the xml */
xmlnode *root = purple_util_read_xml_from_file("stats.xml",
"stats-collection");
- if(!root){
+ stats_acc_ht = g_hash_table_new(g_str_hash, g_str_equal);
+ stats_plugins_ht = g_hash_table_new(g_str_hash, g_str_equal);
- purple_debug_info("STATS", "failed to load stats.xml");
- /* Create an empty structure for the XML */
- root = xmlnode_new("stats");
+ if(!root){
- xmlnode_new_child(root, "accounts");
- xmlnode_new_child(root, "plugins");
+ purple_debug_info("STATS", "failed to load stats.xml");
- /* Write the structure back (init) */
- data = xmlnode_to_formatted_str(root, NULL);
- purple_util_write_data_to_file("stats.xml", data, -1);
+ /* Populate CPU info only on start as this will not change often */
+ cpuinfo_xml = get_cpuinfo_xml();
+ schedule_stats_save();
}
@@ -202,11 +239,9 @@ init_stats(){
/* Populate the hash tables with account and plugin information */
- stats_acc_ht = g_hash_table_new(g_str_hash, g_str_equal);
- stats_plugins_ht = g_hash_table_new(g_str_hash, g_str_equal);
-
stats_acc_xml = xmlnode_get_child(root, "accounts");
stats_plugins_xml = xmlnode_get_child(root, "plugins");
+ cpuinfo_xml = xmlnode_get_child(root, "cpuinfo");
purple_debug_info("STATS", "Accounts: %s", xmlnode_to_formatted_str(stats_acc_xml, NULL));
@@ -241,19 +276,20 @@ init_stats(){
}
- /* It's a good idea to get all loaded plugins and insert them
- * since, we might miss a few if users are already using them
- * and then enable our plugin
- */
- loaded_plugins = purple_plugins_get_loaded();
+ }
- g_list_foreach(loaded_plugins, (GFunc)plugin_load_event, NULL);
+ /* It's a good idea to get all loaded plugins and insert them
+ * since, we might miss a few if users are already using them
+ * and then enable our plugin
+ */
+ loaded_plugins = purple_plugins_get_loaded();
+ g_list_foreach(loaded_plugins, (GFunc)plugin_load_event, NULL);
- }
+
/* Return the structure for modification */
return root;
}
More information about the Commits
mailing list