1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Made version check a user preference

This commit is contained in:
James Booth 2012-10-24 01:35:36 +01:00
parent ff335f80a9
commit 2ca8f5b62e
5 changed files with 77 additions and 17 deletions

View File

@ -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_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_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_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_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_online(const char * const inp, struct cmd_help_t help);
static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help); static gboolean _cmd_dnd(const char * const inp, struct cmd_help_t help);
@ -272,6 +273,16 @@ static struct cmd_t setting_commands[] =
"Config file value : showsplash=true|false", "Config file value : showsplash=true|false",
NULL } } }, 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", { "/chlog",
_cmd_set_chlog, _cmd_set_chlog,
{ "/chlog on|off", "Enable/disable chat logging.", { "/chlog on|off", "Enable/disable chat logging.",
@ -812,6 +823,18 @@ _cmd_set_typing(const char * const inp, struct cmd_help_t help)
"Incoming typing notifications", prefs_set_typing); "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 static gboolean
_cmd_set_flash(const char * const inp, struct cmd_help_t help) _cmd_set_flash(const char * const inp, struct cmd_help_t help)
{ {

View File

@ -261,6 +261,19 @@ prefs_set_typing(gboolean value)
_save_prefs(); _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 gboolean
prefs_get_flash(void) prefs_get_flash(void)
{ {

View File

@ -58,6 +58,8 @@ gboolean prefs_get_showsplash(void);
void prefs_set_showsplash(gboolean value); void prefs_set_showsplash(gboolean value);
gint prefs_get_remind(void); gint prefs_get_remind(void);
void prefs_set_remind(gint value); void prefs_set_remind(gint value);
gboolean prefs_get_vercheck(void);
void prefs_set_vercheck(gboolean value);
void prefs_add_login(const char *jid); void prefs_add_login(const char *jid);

View File

@ -115,6 +115,7 @@ void cons_show(const char * const cmd, ...);
void cons_bad_show(const char * const cmd); void cons_bad_show(const char * const cmd);
void cons_highlight_show(const char * const cmd); void cons_highlight_show(const char * const cmd);
void cons_show_contacts(GSList * list); void cons_show_contacts(GSList * list);
void cons_check_version(gboolean not_available_msg);
// status bar actions // status bar actions
void status_bar_refresh(void); void status_bar_refresh(void);

View File

@ -543,6 +543,11 @@ cons_prefs(void)
else else
cons_show("Chat history : OFF"); 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(); gint remind_period = prefs_get_remind();
if (remind_period == 0) { if (remind_period == 0) {
cons_show("Message reminder period : OFF"); cons_show("Message reminder period : OFF");
@ -846,23 +851,8 @@ cons_about(void)
_win_show_time(_cons_win); _win_show_time(_cons_win);
wprintw(_cons_win, "\n"); wprintw(_cons_win, "\n");
// check for new version if this is a release build if (prefs_get_vercheck()) {
if (strcmp(PACKAGE_STATUS, "release") == 0) { cons_check_version(FALSE);
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);
wprintw(_cons_win, "RELEASE: %s", latest_release);
free(latest_release);
_win_show_time(_cons_win);
wprintw(_cons_win, "\n");
}
}
}
} }
prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1); prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1);
@ -870,6 +860,37 @@ cons_about(void)
dirty = TRUE; dirty = TRUE;
} }
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("");
}
}
}
}
}
static gboolean static gboolean
_new_release(char *found_version) _new_release(char *found_version)
{ {