summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2012-10-26 13:00:09 +0200
committerBerke Viktor <bviktor@hexchat.org>2012-10-26 13:00:09 +0200
commit89252106da323a5c37502f3c7a0fb54b8de19981 (patch)
tree6e7bd702d6b50f4612889ab576da6cde8faac48e
parentbf42c2b60fa43e88ba58574b680a1a42fc981ee1 (diff)
Add configurable delay and check frequency for UPD and eliminate some warnings
-rw-r--r--plugins/upd/upd.c48
1 files changed, 37 insertions, 11 deletions
diff --git a/plugins/upd/upd.c b/plugins/upd/upd.c
index f6030910..afc3f167 100644
--- a/plugins/upd/upd.c
+++ b/plugins/upd/upd.c
@@ -25,10 +25,13 @@
 
 #include "hexchat-plugin.h"
 
+#define DEFAULT_DELAY 10	/* 10 seconds */
+#define DEFAULT_FREQ 360	/* 6 hours */
+
 static xchat_plugin *ph;   /* plugin handle */
-static const char name[] = "Update Checker";
-static const char desc[] = "Check for HexChat updates automatically";
-static const char version[] = "3.0";
+static char name[] = "Update Checker";
+static char desc[] = "Check for HexChat updates automatically";
+static char version[] = "4.0";
 
 static char*
 check_version ()
@@ -150,7 +153,7 @@ check_version ()
 }
 
 static int
-print_version ()
+print_version (char *word[], char *word_eol[], void *userdata)
 {
 	char *version = check_version ();
 
@@ -194,26 +197,49 @@ print_version_quiet (void *userdata)
 	return 1;
 }
 
+static int
+delayed_check (void *userdata)
+{
+	int freq = xchat_pluginpref_get_int (ph, "freq");
+
+	/* only start the timer if there's no update available during startup */
+	if (print_version_quiet (NULL))
+	{
+		/* check for updates, every 6 hours by default */
+		xchat_hook_timer (ph, freq * 1000 * 60, print_version_quiet, NULL);
+	}
+
+	return 0;	/* run delayed_check() only once */
+}
+
 int
 xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
 {
+	int delay;
 	ph = plugin_handle;
 
 	*plugin_name = name;
 	*plugin_desc = desc;
 	*plugin_version = version;
 
-	xchat_hook_command (ph, "UPDCHK", XCHAT_PRI_NORM, print_version, 0, 0);
-	xchat_command (ph, "MENU -ietc\\download.png ADD \"Help/Check for Updates\" \"UPDCHK\"");
-	xchat_printf (ph, "%s plugin loaded\n", name);
+	/* these are required for the very first run */
+	if (xchat_pluginpref_get_int (ph, "freq") == -1)
+	{
+		xchat_pluginpref_set_int (ph, "freq", DEFAULT_FREQ);
+	}
 
-	/* only start the timer if there's no update available during startup */
-	if (print_version_quiet (NULL))
+	delay = xchat_pluginpref_get_int (ph, "delay");
+	if (delay == -1)
 	{
-		/* check for updates every 6 hours */
-		xchat_hook_timer (ph, 21600000, print_version_quiet, NULL);
+		delay = DEFAULT_DELAY;
+		xchat_pluginpref_set_int (ph, "delay", DEFAULT_DELAY);
 	}
 
+	xchat_hook_command (ph, "UPDCHK", XCHAT_PRI_NORM, print_version, 0, 0);
+	xchat_hook_timer (ph, delay * 1000, delayed_check, NULL);
+	xchat_command (ph, "MENU -ietc\\download.png ADD \"Help/Check for Updates\" \"UPDCHK\"");
+	xchat_printf (ph, "%s plugin loaded\n", name);
+
 	return 1;       /* return 1 for success */
 }