/soc/2012/sanket/statscollector-2.x.y: 821aed4e1ef8: Add basic X...

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


Changeset: 821aed4e1ef8318aefefda71b7fda6b8b07ae688
Author:	 Sanket Agarwal <sanket at soc.pidgin.im>
Date:	 2012-05-12 13:02 +0000
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/821aed4e1ef8

Description:

Add basic XML read/write functionality

The plugin can read and write basic content from stats.xml in user home
directory.

diffstat:

 pidgin/plugins/statscollector.c |  81 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 78 insertions(+), 3 deletions(-)

diffs (99 lines):

diff --git a/pidgin/plugins/statscollector.c b/pidgin/plugins/statscollector.c
--- a/pidgin/plugins/statscollector.c
+++ b/pidgin/plugins/statscollector.c
@@ -5,17 +5,92 @@
 #include "notify.h"
 #include "plugin.h"
 #include "version.h"
+#include "debug.h"
 
 #include "internal.h"
 
 #include <gtkplugin.h>
 
+#define STATS_MAJOR_VERSION 1
+#define STATS_MINOR_VERSION 0
+
+xmlnode *root_stats;
+
+static void
+sign_on_event(PurpleAccount *account){
+
+  /* Store information about logging on of an account. The following
+   * measures should be taken:
+   * 1. Check if we already have such an account in our database
+   * 1.1 If no, then add the account to the list of accounts used
+   */
+
+  xmlnode *fetch;
+
+  purple_debug_info("XX-STATS",
+      "Logged into a account %s with protocol %s",
+      purple_account_get_username(account),
+      purple_account_get_protocol_id(account));
+
+}
+
+static xmlnode *
+init_stats(){
+
+  /* This function loads the stats.xml into a global object.
+   * Other functionalities include:
+   * 1. Check if the file is corrupt (bad XML) or missing
+   * 2. In case plugin versions change the XML format, handle that
+   */
+
+  /* Load the xml */
+  char *data;
+  xmlnode *root = purple_util_read_xml_from_file("stats.xml",
+      "stats-collection");
+
+  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, "cpuinfo");
+    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);
+
+  }
+
+  /* Check if the XML format version is compatible with current XML */
+
+  /* Return the structure for modification */
+  return root;
+}
+
 static gboolean
 plugin_load(PurplePlugin *plugin) {
-    purple_notify_message(plugin, PURPLE_NOTIFY_MSG_INFO, "Hello World!",
-                                "This is the Status Message 4! plugin :)", NULL, NULL, NULL);
 
-    return TRUE;
+  /* This function does the minimal requirements of registering on
+   * signals currently. Storing of information can hence be done
+   * on various activities */
+
+  /* Load the stats file into a global variable for any updations */
+
+  root_stats = init_stats();
+
+  /* Spit the current stats */
+  purple_debug_info("STATS", "%s",xmlnode_to_formatted_str(root_stats, NULL));
+
+  /* Register the account signals for sign-on/off */
+
+  /* purple_signal_connect(purple_accounts_get_handle(), "account-signed-on", */
+  /*                     plugin, PURPLE_CALLBACK(sign_on_event), NULL); */
+
+  return TRUE;
 }
 
 static PurplePluginInfo info =



More information about the Commits mailing list