soc.2012.statscollector: 333323d6: Add basic XML read/write functionality
sanket at sanketagarwal.com
sanket at sanketagarwal.com
Mon May 14 13:27:52 EDT 2012
----------------------------------------------------------------------
Revision: 333323d642e81d7caaafcfda6b0979a7513b8b76
Parent: 4ba48ce4cd83b77d1014f7436b6395c1c992a92e
Author: sanket at sanketagarwal.com
Date: 05/12/12 09:02:43
Branch: im.pidgin.soc.2012.statscollector
URL: http://d.pidgin.im/viewmtn/revision/info/333323d642e81d7caaafcfda6b0979a7513b8b76
Changelog:
Add basic XML read/write functionality
The plugin can read and write basic content from stats.xml in user home
directory.
Changes against parent 4ba48ce4cd83b77d1014f7436b6395c1c992a92e
patched pidgin/plugins/statscollector.c
-------------- next part --------------
============================================================
--- pidgin/plugins/statscollector.c 7717c348a1c71c2fcf57117dbc210662765c7db2
+++ pidgin/plugins/statscollector.c 3e8ae838ef14f58691b2cd7397341e51d67492d3
@@ -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