/soc/2012/sanket/statscollector-2.x.y: 691d736dfdf8: Add UI info...
Sanket Agarwal
sanket at soc.pidgin.im
Tue Jul 10 00:36:23 EDT 2012
Changeset: 691d736dfdf876b865a0f5cfcb2fb208be26a659
Author: Sanket Agarwal <sanket at soc.pidgin.im>
Date: 2012-05-22 07:49 +0000
Branch: soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/691d736dfdf8
Description:
Add UI information
UI's are majorly Pidgin/Finch for pidgin installation but could be Instantbird,
nullclient etc for other applications running on top of libpurple. Also there
is functionality to capture if the same libpurple config is used for more than
one UI(e.g. using Pidgin/Finch together).
Currently the plugin is tested majorly for Pidgin/Finch but I need to test
it for * a null client running on top of libpurple and possibly * adium and
* instantbird.
diffstat:
libpurple/plugins/statscollector.c | 102 +++++++++++++++++++++++++++++++++---
1 files changed, 93 insertions(+), 9 deletions(-)
diffs (193 lines):
diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -31,8 +31,8 @@
#define STATS_MAJOR_VERSION 1
#define STATS_MINOR_VERSION 0
-xmlnode *root_stats, *cpuinfo_xml;
-GHashTable *stats_acc_ht, *stats_plugins_ht;
+xmlnode *root_stats, *cpuinfo_xml, *ui_info;
+GHashTable *stats_acc_ht, *stats_plugins_ht, *stats_uis_ht;
int save_timer = 0;
/* Types of Operating Systems */
@@ -49,7 +49,7 @@
GHashTableIter iter;
gpointer key, value;
- xmlnode *nroot, *nacc, *nplugins, *node;
+ xmlnode *nroot, *nacc, *nplugins, *nuis, *node;
char *data;
nroot = xmlnode_new("stats");
@@ -57,8 +57,12 @@
/* Load CPUinfo strucutre */
xmlnode_insert_child(nroot, cpuinfo_xml);
+ /* Load UI info */
+ xmlnode_insert_child(nroot, ui_info);
+
nacc = xmlnode_new_child(nroot, "accounts");
nplugins = xmlnode_new_child(nroot, "plugins");
+ nuis = xmlnode_new_child(nroot, "uis");
/* Use the hash tables to populate acc and plugins */
@@ -81,6 +85,15 @@
}
+ g_hash_table_iter_init(&iter, stats_uis_ht);
+
+ while(g_hash_table_iter_next(&iter, &key, &value)){
+
+ node = xmlnode_from_str(value, -1);
+ xmlnode_insert_child(nuis, node);
+
+ }
+
data = xmlnode_to_formatted_str(nroot, NULL);
purple_util_write_data_to_file("stats.xml", data, -1);
@@ -104,12 +117,12 @@
/* Determines if the application is running in 32 or 64 bit mode */
int pt_size;
- xmlnode *bit_size;
+ xmlnode *bit_size_xml;
- pt_size = sizeof(int)*8;
- bit_size = xmlnode_new("app-bit");
- xmlnode_insert_data(bit_size, g_strdup_printf("%d",pt_size), -1);
- return bit_size;
+ pt_size = sizeof(int *)*8;
+ bit_size_xml = xmlnode_new("app-bit");
+ xmlnode_insert_data(bit_size_xml, g_strdup_printf("%d",pt_size), -1);
+ return bit_size_xml;
}
@@ -447,6 +460,58 @@
}
+static void
+get_ui_info(){
+
+ /* Obtains what UI and which version is being run by current client
+ * using libpurple.
+ */
+
+ GHashTable *ui_info_ht;
+ xmlnode *ui_info_xml, *ui_version_xml;
+ char *ui_name, *ui_version, *data;
+ GHashTableIter iter;
+ /* gpointer key, value; */
+
+ ui_info_ht = purple_core_get_ui_info();
+
+ ui_name = g_hash_table_lookup(ui_info_ht, "name");
+ ui_version = g_hash_table_lookup(ui_info_ht, "version");
+
+ /* If it's a null-client (?) then perhaps we should make it look like
+ * a client we don't perhaps know about!
+ */
+ if(!ui_name) ui_name = "other";
+ if(!ui_version) ui_version = "other";
+
+ /* Check if the UI info is already present in the hashtable */
+ if(g_hash_table_lookup(stats_uis_ht, ui_name)) return;
+
+ ui_info_xml = xmlnode_new("ui");
+ ui_version_xml = xmlnode_new("version");
+
+ xmlnode_set_attrib(ui_info_xml, "id", ui_name);
+ xmlnode_insert_data(ui_version_xml, ui_version, -1);
+ xmlnode_insert_child(ui_info_xml, ui_version_xml);
+
+ data = xmlnode_to_str(ui_info_xml, NULL);
+ g_hash_table_insert(stats_uis_ht, (void *)ui_name, (void *)data);
+
+ g_hash_table_iter_init(&iter, stats_uis_ht);
+
+ /* purple_debug_info("STATS UI", "starting ui info ... \\n %s: %s", ui_name, data); */
+
+ /* while(g_hash_table_iter_next(&iter, &key, &value)){ */
+
+ /* purple_debug_info("STATS UI", "%s: %s\\n", (char *)key, (char *)value); */
+
+ /* } */
+
+ schedule_stats_save();
+
+
+}
+
static const gchar *
md5(const guchar *str)
@@ -583,7 +648,7 @@
const char *id_node;
gsize length;
GError *error = NULL;
- xmlnode *stats_acc_xml, *stats_plugins_xml, *root, *start;
+ xmlnode *stats_acc_xml, *stats_plugins_xml, *stats_uis_xml, *root, *start;
/* Load the xml */
filename = g_build_filename(purple_user_dir(), "stats.xml", NULL);
@@ -593,6 +658,7 @@
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_uis_ht = g_hash_table_new(g_str_hash, g_str_equal);
if(!root){
@@ -614,6 +680,7 @@
stats_acc_xml = xmlnode_get_child(root, "accounts");
stats_plugins_xml = xmlnode_get_child(root, "plugins");
cpuinfo_xml = xmlnode_get_child(root, "cpuinfo");
+ stats_uis_xml = xmlnode_get_child(root, "uis");
purple_debug_info("STATS", "Accounts: %s", xmlnode_to_formatted_str(stats_acc_xml, NULL));
@@ -629,6 +696,7 @@
}
+ start = xmlnode_get_child(stats_plugins_xml, "plugin");
for(;start;start = xmlnode_get_next_twin(start)){
@@ -639,6 +707,17 @@
}
+ start = xmlnode_get_child(stats_uis_xml, "ui");
+
+ for(;start;start = xmlnode_get_next_twin(start)){
+
+ id_node = xmlnode_get_attrib((const xmlnode *)start, "id");
+
+ g_hash_table_insert(stats_uis_ht, (gpointer)id_node,
+ (char *)xmlnode_to_formatted_str(start, NULL));
+
+ }
+
}
@@ -651,7 +730,12 @@
g_list_foreach(loaded_plugins, (GFunc)plugin_load_event, NULL);
+ /* The newly loaded UI might be different from what the user used
+ * last time. It's a good idea to note the UI down because this'll be
+ * required only once -- we should probably do it here itself
+ */
+ get_ui_info();
/* Return the structure for modification */
return root;
More information about the Commits
mailing list