From 2ca8f5b62eb0d35e570a3c3c9418cf1c00a202fa Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 24 Oct 2012 01:35:36 +0100 Subject: Made version check a user preference --- src/command.c | 23 +++++++++++++++++++++++ src/preferences.c | 13 +++++++++++++ src/preferences.h | 2 ++ src/ui.h | 1 + src/windows.c | 53 +++++++++++++++++++++++++++++++++++++---------------- 5 files changed, 76 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index 2ae038c5..adf3ddf0 100644 --- a/src/command.c +++ b/src/command.c @@ -76,6 +76,7 @@ static gboolean _cmd_set_showsplash(const char * const inp, struct cmd_help_t he static gboolean _cmd_set_chlog(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_history(const char * const inp, struct cmd_help_t help); static gboolean _cmd_set_remind(const char * const inp, struct cmd_help_t help); +static gboolean _cmd_vercheck(const char * const inp, struct cmd_help_t help); static gboolean _cmd_away(const char * const inp, struct cmd_help_t help); static gboolean _cmd_online(const char * const inp, struct cmd_help_t help); static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help); @@ -271,6 +272,16 @@ static struct cmd_t setting_commands[] = "Config file section : [ui]", "Config file value : showsplash=true|false", NULL } } }, + + { "/vercheck", + _cmd_vercheck, + { "/vercheck [on|off]", "Check for a new release.", + { "/vercheck [on|off]", + "------------------", + "Without a parameter will check for a new release.", + "Switching on or off will enable/disable a version check when Profanity starts,", + "and each time the /about command is run.", + NULL } } }, { "/chlog", _cmd_set_chlog, @@ -812,6 +823,18 @@ _cmd_set_typing(const char * const inp, struct cmd_help_t help) "Incoming typing notifications", prefs_set_typing); } +static gboolean +_cmd_vercheck(const char * const inp, struct cmd_help_t help) +{ + if (strcmp(inp, "/vercheck") == 0) { + cons_check_version(TRUE); + return TRUE; + } else { + return _cmd_set_boolean_preference(inp, help, "/vercheck", + "Version checking", prefs_set_vercheck); + } +} + static gboolean _cmd_set_flash(const char * const inp, struct cmd_help_t help) { diff --git a/src/preferences.c b/src/preferences.c index 67f9345a..706ad4d3 100644 --- a/src/preferences.c +++ b/src/preferences.c @@ -261,6 +261,19 @@ prefs_set_typing(gboolean value) _save_prefs(); } +gboolean +prefs_get_vercheck(void) +{ + return g_key_file_get_boolean(prefs, "ui", "vercheck", NULL); +} + +void +prefs_set_vercheck(gboolean value) +{ + g_key_file_set_boolean(prefs, "ui", "vercheck", value); + _save_prefs(); +} + gboolean prefs_get_flash(void) { diff --git a/src/preferences.h b/src/preferences.h index e816b7c0..885b895d 100644 --- a/src/preferences.h +++ b/src/preferences.h @@ -58,6 +58,8 @@ gboolean prefs_get_showsplash(void); void prefs_set_showsplash(gboolean value); gint prefs_get_remind(void); void prefs_set_remind(gint value); +gboolean prefs_get_vercheck(void); +void prefs_set_vercheck(gboolean value); void prefs_add_login(const char *jid); diff --git a/src/ui.h b/src/ui.h index 9d32602a..df42a191 100644 --- a/src/ui.h +++ b/src/ui.h @@ -115,6 +115,7 @@ void cons_show(const char * const cmd, ...); void cons_bad_show(const char * const cmd); void cons_highlight_show(const char * const cmd); void cons_show_contacts(GSList * list); +void cons_check_version(gboolean not_available_msg); // status bar actions void status_bar_refresh(void); diff --git a/src/windows.c b/src/windows.c index ff11bb7f..bd06165d 100644 --- a/src/windows.c +++ b/src/windows.c @@ -543,6 +543,11 @@ cons_prefs(void) else cons_show("Chat history : OFF"); + if (prefs_get_vercheck()) + cons_show("Version checking : ON"); + else + cons_show("Version checking : OFF"); + gint remind_period = prefs_get_remind(); if (remind_period == 0) { cons_show("Message reminder period : OFF"); @@ -846,28 +851,44 @@ cons_about(void) _win_show_time(_cons_win); wprintw(_cons_win, "\n"); - // check for new version if this is a release build - if (strcmp(PACKAGE_STATUS, "release") == 0) { - char *latest_release = release_get_latest(); + if (prefs_get_vercheck()) { + cons_check_version(FALSE); + } - if (latest_release != NULL) { - gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); + + dirty = TRUE; +} - if (relase_valid) { - if (_new_release(latest_release)) { - _win_show_time(_cons_win); - wprintw(_cons_win, "RELEASE: %s", latest_release); - free(latest_release); - _win_show_time(_cons_win); - wprintw(_cons_win, "\n"); +void +cons_check_version(gboolean not_available_msg) +{ + char *latest_release = release_get_latest(); + + if (latest_release != NULL) { + gboolean relase_valid = g_regex_match_simple("^\\d+\\.\\d+\\.\\d+$", latest_release, 0, 0); + + if (relase_valid) { + if (_new_release(latest_release)) { + _win_show_time(_cons_win); + wattron(_cons_win, COLOUR_ONLINE); + wprintw(_cons_win, "A new version of Profanity is available: %s", latest_release); + wattroff(_cons_win, COLOUR_ONLINE); + _win_show_time(_cons_win); + wattron(_cons_win, COLOUR_ONLINE); + wprintw(_cons_win, "Check http://www.boothj5.com/profanity.shtml for details.\n"); + wattroff(_cons_win, COLOUR_ONLINE); + free(latest_release); + _win_show_time(_cons_win); + wprintw(_cons_win, "\n"); + } else { + if (not_available_msg) { + cons_show("No new version available."); + cons_show(""); } } } } - - prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); - - dirty = TRUE; } static gboolean -- cgit 1.4.1-2-gfad0