/soc/2012/sanket/statscollector-2.x.y: d4bc93161352: Use request...

sanket sanket at soc.pidgin.im
Wed Aug 1 15:44:22 EDT 2012


Changeset: d4bc931613522400839e2b85d3dbdf3686f16545
Author:	 sanket <sanket at soc.pidgin.im>
Date:	 2012-08-01 12:43 +0530
Branch:	 soc.2012.statscollector
URL: http://hg.pidgin.im/soc/2012/sanket/statscollector-2.x.y/rev/d4bc93161352

Description:

Use request API to ask for first time confirmation of stats collection

After moving to pidgin/plugins, I am back to libpurple/plugins,
this time using the more versatile request API to create UI. The
UI for confirmation fires instantaniously, though it's a better idea
to put some lag to make the UI more responsive (?)

diffstat:

 libpurple/plugins/statscollector.c |  143 ++++++++++++++++++++++++++++++++----
 1 files changed, 127 insertions(+), 16 deletions(-)

diffs (221 lines):

diff --git a/libpurple/plugins/statscollector.c b/libpurple/plugins/statscollector.c
--- a/libpurple/plugins/statscollector.c
+++ b/libpurple/plugins/statscollector.c
@@ -1,7 +1,6 @@
 /* Log the activity of users */
 
 #include "internal.h"
-/* #include "pidgin.h" */
 
 #include "debug.h"
 #include "log.h"
@@ -13,9 +12,9 @@
 #include "prpl.h"
 #include "core.h"
 #include "accountopt.h"
+#include "request.h"
 
 #include <glib.h>
-/* #include <gtkplugin.h> */
 
 #ifdef _WIN32
 #include<windows.h>
@@ -27,6 +26,10 @@
 #include<sys/sysctl.h>
 #endif
 
+/* Allow/Deny Constants */
+#define ALLOW 0
+#define DENY 1
+#define ASK 2
 /* Timeout */
 #define RESEND_SEC (24*3600)
 
@@ -51,6 +54,7 @@
 # include <dlfcn.h>
 #endif
 
+PurplePlugin *plugin_g;
 xmlnode *root_stats, *cpuinfo_xml, *ui_info;
 GHashTable *stats_acc_ht, *stats_plugins_ht, *stats_uis_ht;
 int save_timer = 0, send_handle = 0;
@@ -61,6 +65,33 @@ enum BIT_32_64 {BIT_32, BIT_64};
 
 static void schedule_send(void);
 static gboolean send_stats();
+static gboolean plugin_load(PurplePlugin *);
+
+static void
+confirm_allow(){
+
+  /* Set the allow variable in prefs to ALLOW */
+  purple_prefs_set_int("/plugins/core/statscollector/allow", ALLOW);
+  plugin_load(plugin_g);
+
+}
+
+static void
+confirm_deny(){
+
+  /* Set the allow variable in prefs to ALLOW */
+  purple_prefs_set_int("/plugins/core/statscollector/allow", DENY);
+
+}
+
+static void
+confirm_later(){
+
+  /* No-op right now, but can contain logic wherein we have
+   * a timeout before the next callout for authorize/deny
+   */
+
+}
 
 static glong
 get_time_sec(){
@@ -801,7 +832,7 @@ url_callback(PurpleUtilFetchUrlData *url
    */
 
   int code = -1;
-  char *header = url_text;
+  char *header = (char *)url_text;
 
   if(header && strlen(header) >= 14) {
     header += 9;
@@ -1036,26 +1067,102 @@ init_stats(){
 }
 
 static gboolean
+show_confirm_dialog(gpointer data){
+
+  /* Display a confirmation dialog whether the user would like
+   * to collect the stats
+   */
+
+  /* PurpleRequestFields *request; */
+  /* PurpleRequestFieldGroup *group; */
+  /* PurpleRequestField *field; */
+
+  /* group = purple_request_field_group_new(NULL); */
+
+  /* field = purple_request_field_label_new("confirm_dialog", \\ */
+  /*     "Would you like to collect statistics anonymously?"); */
+  /*  field = purple_request_field_account_new("acct", _("Account"), NULL); */
+  /*  purple_request_field_account_set_filter(field, NULL); */
+  /* purple_request_field_account_set_show_all(field, FALSE); */
+  /* purple_request_field_group_add_field(group, field); */
+
+  /* field = purple_request_field_int_new("mins", _("Minutes"), 10); */
+  /* purple_request_field_group_add_field(group, field); */
+
+  /* request = purple_request_fields_new(); */
+  /* purple_request_fields_add_group(request, group); */
+
+  /* purple_request_fields(NULL, */
+  /*         "Statisitcs collection", */
+  /*         "Looks like this is the first time you are using the plugin!", */
+  /*         NULL, */
+  /*         request, */
+  /*         "Allow", confirm_allow, */
+  /*         "Deny", confirm_deny, */
+  /*         NULL, NULL, NULL, */
+  /*         NULL); */
+
+  purple_request_action(NULL,
+      "Statistics Collection Plugin",
+      "Do you wish pidgin to collect and send statistics anonymously",
+      "Policy and links follow here",
+      2,
+      NULL,
+      NULL,
+      NULL,
+      NULL,
+      3,
+      "_Allow", confirm_allow,
+      "_Deny",  confirm_deny,
+      "_Ask Later", confirm_later);
+
+  return FALSE;
+
+}
+
+static gboolean
 plugin_load(PurplePlugin *plugin) {
 
+  int check_ask;
+
   /* 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 */
+  /* Save a pointer to the plugin for global use */
+  plugin_g = plugin;
 
-  root_stats = init_stats();
+  /* Check if the allow is indeed ASK, in that case we *can* assume
+   * that this is the first time the user has used the plugin AND
+   * ask him to verify whether he would like to allow collecting stats
+   * I am not sure if this is the best way.
+   */
+  check_ask = purple_prefs_get_int("/plugins/core/statscollector/allow");
 
-  /* Register the account signals for sign-on */
-  purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
-                      plugin, PURPLE_CALLBACK(acc_sign_on_event), NULL);
+  if(check_ask == ASK){
 
-   /* Register the plugin signals for sign-on */
-  purple_signal_connect(purple_plugins_get_handle(), "plugin-load",
-                      plugin, PURPLE_CALLBACK(plugin_load_event), NULL);
+    /* purple_timeout_add_seconds(5, show_confirm_dialog, NULL); */
+    show_confirm_dialog(NULL);
 
-  /* Schedule the sending of statistics */
-  schedule_send();
+  }
+
+  else if(check_ask == ALLOW){
+
+    /* Load the stats file into a global variable for any updations */
+    root_stats = init_stats();
+
+    /* Register the account signals for sign-on */
+    purple_signal_connect(purple_accounts_get_handle(), "account-signed-on",
+                        plugin, PURPLE_CALLBACK(acc_sign_on_event), NULL);
+
+     /* Register the plugin signals for sign-on */
+    purple_signal_connect(purple_plugins_get_handle(), "plugin-load",
+                        plugin, PURPLE_CALLBACK(plugin_load_event), NULL);
+
+    /* Schedule the sending of statistics */
+    schedule_send();
+
+  }
 
  return TRUE;
 }
@@ -1113,16 +1220,20 @@ init_plugin(PurplePlugin *plugin)
   /* Set up the preferences for the plugin */
   purple_prefs_add_none("/plugins/core/statscollector");
 
-  /* Add public key information */
+  /* Add last-sent information */
   purple_prefs_add_int("/plugins/core/statscollector/last-sent", 0);
 
-  /* A random 16 byte string for identifying unique machines */
-  /* Unsure whether rand() is called when pidgin initializes
+  /* Add allow/deny preference */
+  purple_prefs_add_int("/plugins/core/statscollector/allow", ASK);
+
+  /* A random 16 byte string for identifying unique machines
+   * Unsure whether rand() is called when pidgin initializes
    * it on startup
    */
   g_rand_new_with_seed(time(NULL));
   purple_prefs_add_string("/plugins/core/statscollector/send-key", \
       purple_uuid_random());
+
 }
 
 PURPLE_INIT_PLUGIN(statscollector, init_plugin, info)



More information about the Commits mailing list