/soc/2012/sanket/statscollector-2.x.y: 89c0bf901c36: Add languag...

Sanket Agarwal sanket at soc.pidgin.im
Tue Jul 10 00:36:22 EDT 2012


Changeset: 89c0bf901c36964821b01162c1774c9e8b5afee6
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-14 09:47 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/89c0bf901c36

Description:

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.

diffstat:

 pidgin/plugins/statscollector.c |  88 ++++++++++++++++++++++++++++------------
 1 files changed, 62 insertions(+), 26 deletions(-)

diffs (174 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -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 @@
    * 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 @@
 
   }
 
+  /* 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 @@
     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_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 @@
   schedule_stats_save();
 
 }
+
 static xmlnode *
 init_stats(){
 
@@ -175,26 +214,24 @@
 
   /* 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");
 
+  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);
+
+
   if(!root){
 
     purple_debug_info("STATS", "failed to load stats.xml");
 
-    /* Create an empty structure for the XML */
-    root = xmlnode_new("stats");
-
-    xmlnode_new_child(root, "accounts");
-    xmlnode_new_child(root, "plugins");
-
-    /* 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 @@
 
     /* 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 @@
 
     }
 
-    /* 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