about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-10-24 01:35:36 +0100
committerJames Booth <boothj5@gmail.com>2012-10-24 01:35:36 +0100
commit2ca8f5b62eb0d35e570a3c3c9418cf1c00a202fa (patch)
treea95eb2b88dccce9a48508ed1a06bd12f8e3f6402 /src
parentff335f80a9218a0d46d9b5790b452cc09125efa9 (diff)
downloadprofani-tty-2ca8f5b62eb0d35e570a3c3c9418cf1c00a202fa.tar.gz
Made version check a user preference
Diffstat (limited to 'src')
-rw-r--r--src/command.c23
-rw-r--r--src/preferences.c13
-rw-r--r--src/preferences.h2
-rw-r--r--src/ui.h1
-rw-r--r--src/windows.c53
5 files changed, 76 insertions, 16 deletions
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,
@@ -813,6 +824,18 @@ _cmd_set_typing(const char * const inp, struct cmd_help_t help)
 }
 
 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)
 {
     return _cmd_set_boolean_preference(inp, help, "/flash",
diff --git a/src/preferences.c b/src/preferences.c
index 67f9345a..706ad4d3 100644
--- a/src/preferences.c
+++ b/src/preferences.c
@@ -262,6 +262,19 @@ prefs_set_typing(gboolean value)
 }
 
 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)
 {
     return g_key_file_get_boolean(prefs, "ui", "flash", NULL);
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