/soc/2013/bhaskar/plugins-window: 5bde69398ca4: Added preference...
Bhaskar Kandiyal
bkandiyal at gmail.com
Mon Sep 2 17:20:22 EDT 2013
Changeset: 5bde69398ca46ef89cfe7017bab8fbbecd0e5463
Author: Bhaskar Kandiyal <bkandiyal at gmail.com>
Date: 2013-09-03 02:32 +0530
Branch: soc.2013.plugins_window
URL: https://hg.pidgin.im/soc/2013/bhaskar/plugins-window/rev/5bde69398ca4
Description:
Added preferences for plugin updation and fixed some bugs in auto-update timer
diffstat:
pidgin/gtkmain.c | 85 +++++++++++++++++++++++++++------------------
pidgin/gtkplugin-updater.c | 5 +-
pidgin/gtkplugin-updater.h | 7 +++
pidgin/gtkprefs.c | 37 ++++++++++++++++++++
4 files changed, 97 insertions(+), 37 deletions(-)
diffs (220 lines):
diff --git a/pidgin/gtkmain.c b/pidgin/gtkmain.c
--- a/pidgin/gtkmain.c
+++ b/pidgin/gtkmain.c
@@ -456,6 +456,8 @@ int main(int argc, char *argv[])
GStatBuf st;
GDateTime *gdt_cur, *gdt_future, *gdt_last;
GTimeVal last_time, cur_time, future_time;
+ gint update_pref;
+ gchar *last_updated;
struct option long_options[] = {
{"config", required_argument, NULL, 'c'},
@@ -790,49 +792,62 @@ int main(int argc, char *argv[])
}
/* check for updates */
- if(purple_prefs_get_string("/purple/updater/last_updated"))
+ if((update_pref = purple_prefs_get_int(PIDGIN_PREFS_ROOT "/updater/update_prefs")) != UPDATER_PREF_NO_UPDATES)
{
- gdt_cur = g_date_time_new_now_local();
- g_time_val_from_iso8601(purple_prefs_get_string("/purple/updater/last_updated"), &last_time);
- gdt_last = g_date_time_new_from_timeval_local(&last_time);
- gdt_future = g_date_time_add_weeks(gdt_last, 1);
+ if((last_updated = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/updater/last_updated"))
+ && g_utf8_strlen(last_updated, -1) > 0)
+ {
+ gdt_cur = g_date_time_new_now_local();
+ g_time_val_from_iso8601(last_updated, &last_time);
+ gdt_last = g_date_time_new_from_timeval_local(&last_time);
+ gdt_future = g_date_time_add_weeks(gdt_last, 1);
- /* check if 1 week has elapsed from last update, if so, call the update method */
- if (g_date_time_compare(gdt_cur, gdt_future) >= 0)
- {
- pidgin_plugin_updater_check_for_updates(FALSE);
- g_date_time_to_timeval(gdt_cur, &cur_time);
- purple_prefs_set_string("/purple/updater/last_updated", g_time_val_to_iso8601(&cur_time));
+ /* check if 1 week has elapsed from last update, if so, call the update method */
+ if (g_date_time_compare(gdt_cur, gdt_future) >= 0)
+ {
+ if(update_pref == UPDATER_PREF_AUTOMATIC)
+ pidgin_plugin_updater_check_for_updates(FALSE);
+ else
+ pidgin_plugin_updater_check_for_updates(TRUE);
+ g_date_time_to_timeval(gdt_cur, &cur_time);
+ purple_prefs_set_string(PIDGIN_PREFS_ROOT "/updater/last_updated", g_time_val_to_iso8601(&cur_time));
+
+ g_date_time_unref(gdt_future);
+ gdt_future = g_date_time_add_weeks(gdt_cur, 1);
+ g_date_time_to_timeval(gdt_future, &future_time);
+ purple_timeout_add(g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
+
+ purple_debug_info("gtkmain", "Adding timer for %ld seconds\n", g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND);
+ }
+ else
+ {
+ /* if time still remains add a timer for when the next update is due */
+ purple_timeout_add(g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
+ purple_debug_info("gtkmain", "Adding remaining timer for %d seconds\n", g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND);
+ }
+
+ g_date_time_unref(gdt_cur);
+ g_date_time_unref(gdt_last);
g_date_time_unref(gdt_future);
- gdt_future = g_date_time_add_weeks(gdt_cur, 1);
- g_date_time_to_timeval(gdt_future, &future_time);
- purple_timeout_add(future_time.tv_sec, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
}
else
{
- /* if time still remains add a timer to when the next update is due */
- purple_timeout_add(g_date_time_difference(gdt_future, gdt_cur), pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
+ if(update_pref == UPDATER_PREF_AUTOMATIC)
+ pidgin_plugin_updater_check_for_updates(FALSE);
+ else
+ pidgin_plugin_updater_check_for_updates(TRUE);
+
+ gdt_cur = g_date_time_new_now_local();
+ g_date_time_to_timeval(gdt_cur, &cur_time);
+
+ gdt_future = g_date_time_add_weeks(gdt_cur, 1);
+ g_date_time_to_timeval(gdt_future, &future_time);
+
+ purple_prefs_set_string(PIDGIN_PREFS_ROOT "/updater/last_updated", g_time_val_to_iso8601(&cur_time));
+ purple_timeout_add(g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
+ purple_debug_info("gtkmain", "Adding timer for %d seconds ##\n", g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND);
}
-
- g_date_time_unref(gdt_cur);
- g_date_time_unref(gdt_last);
- g_date_time_unref(gdt_future);
- }
- else
- {
- pidgin_plugin_updater_check_for_updates(FALSE);
-
- gdt_cur = g_date_time_new_now_local();
- g_date_time_to_timeval(gdt_cur, &cur_time);
-
- purple_prefs_add_none("/purple/updater");
- purple_prefs_add_string("/purple/updater/last_updaterupdated", g_time_val_to_iso8601(&cur_time));
-
- gdt_future = g_date_time_add_weeks(gdt_cur, 1);
- g_date_time_to_timeval(gdt_future, &future_time);
-
- purple_timeout_add(future_time.tv_sec, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
}
/* load plugins we had when we quit */
diff --git a/pidgin/gtkplugin-updater.c b/pidgin/gtkplugin-updater.c
--- a/pidgin/gtkplugin-updater.c
+++ b/pidgin/gtkplugin-updater.c
@@ -31,6 +31,7 @@
#include "prefs.h"
#include "http.h"
#include "gtkplugin-updater.h"
+#include "pidgin.h"
#include <gtk/gtk.h>
#include <sys/utsname.h>
@@ -482,11 +483,11 @@ pidgin_plugin_updater_check_for_updates_
gdt_cur = g_date_time_new_now_local();
g_date_time_to_timeval(gdt_cur, &cur_time);
- purple_prefs_set_string("/purple/updater/last_updated", g_time_val_to_iso8601(&cur_time));
+ purple_prefs_set_string(PIDGIN_PREFS_ROOT "/updater/last_updated", g_time_val_to_iso8601(&cur_time));
gdt_future = g_date_time_add_weeks(gdt_cur, 1);
g_date_time_to_timeval(gdt_future, &future_time);
- purple_timeout_add(future_time.tv_sec, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
+ purple_timeout_add(g_date_time_difference(gdt_future, gdt_cur) / G_TIME_SPAN_SECOND, pidgin_plugin_updater_check_for_updates_timeout_cb, NULL);
g_date_time_unref(gdt_cur);
g_date_time_unref(gdt_future);
diff --git a/pidgin/gtkplugin-updater.h b/pidgin/gtkplugin-updater.h
--- a/pidgin/gtkplugin-updater.h
+++ b/pidgin/gtkplugin-updater.h
@@ -32,6 +32,13 @@
/*const gchar* PURPLE_UPDATE_URI = "http://bhaskar-kandiyal.rhcloud.com";*/
static const gchar* PIDGIN_PLUGIN_WEBSITE_URI = "http://127.0.0.1:8000"; /* For local debugging only */
+typedef enum
+{
+ UPDATER_PREF_AUTOMATIC = 1,
+ UPDATER_PREF_NOTIFY = 2,
+ UPDATER_PREF_NO_UPDATES = 3,
+} UpdaterPref;
+
G_BEGIN_DECLS
/**
diff --git a/pidgin/gtkprefs.c b/pidgin/gtkprefs.c
--- a/pidgin/gtkprefs.c
+++ b/pidgin/gtkprefs.c
@@ -51,6 +51,7 @@
#include "gtkdebug.h"
#include "gtkdialogs.h"
#include "gtkprefs.h"
+#include "gtkplugin-updater.h"
#include "gtksavedstatuses.h"
#include "gtksound.h"
#include "gtkstatus-icon-theme.h"
@@ -4086,6 +4087,35 @@ vv_page(void)
}
#endif
+static GtkWidget *
+updates_page(void)
+{
+ GtkWidget *ret;
+ GtkSizeGroup *sg;
+ GtkWidget *vbox;
+ GtkWidget *dd;
+
+ ret = gtk_vbox_new(FALSE, PIDGIN_HIG_CAT_SPACE);
+ gtk_container_set_border_width(GTK_CONTAINER(ret), PIDGIN_HIG_BORDER);
+
+ sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
+
+ vbox = pidgin_make_frame(ret, _("Automatic Plugin Updates"));
+ dd = pidgin_prefs_dropdown(vbox, _("Choose how you wish to update your plugins"),
+ PURPLE_PREF_INT, PIDGIN_PREFS_ROOT "/updater/update_prefs",
+ _("Automatically install updates"), UPDATER_PREF_AUTOMATIC,
+ _("Notify me when updates are available"), UPDATER_PREF_NOTIFY,
+ _("Do not install any updates"), UPDATER_PREF_NO_UPDATES);
+
+ gtk_size_group_add_widget(sg, dd);
+ gtk_misc_set_alignment(GTK_MISC(dd), 0, 0.5);
+
+ gtk_widget_show_all(ret);
+ g_object_unref(sg);
+
+ return ret;
+}
+
static int
prefs_notebook_add_page(const char *text, GtkWidget *page, int ind)
{
@@ -4113,6 +4143,8 @@ prefs_notebook_init(void)
prefs_notebook_add_page(_("Sounds"), sound_page(), notebook_page++);
prefs_notebook_add_page(_("Status / Idle"), away_page(), notebook_page++);
prefs_notebook_add_page(_("Themes"), theme_page(), notebook_page++);
+ prefs_notebook_add_page(_("Updates"), updates_page(), notebook_page++);
+
#ifdef USE_VV
prefs_notebook_add_page(_("Voice/Video"), vv_page(), notebook_page++);
#endif
@@ -4267,6 +4299,11 @@ pidgin_prefs_init(void)
purple_prefs_add_string(PIDGIN_PREFS_ROOT "/vvconfig/video/sink/device", "");
#endif
+ /* Plugin Updater */
+ purple_prefs_add_none(PIDGIN_PREFS_ROOT "/updater");
+ purple_prefs_add_string(PIDGIN_PREFS_ROOT "/updater/last_updated", "");
+ purple_prefs_add_int(PIDGIN_PREFS_ROOT "/updater/update_prefs", UPDATER_PREF_AUTOMATIC);
+
pidgin_prefs_update_old();
}
More information about the Commits
mailing list