{ VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_method", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, N_("Startup Method:"), VIK_LAYER_WIDGET_COMBOBOX, params_startup_methods, NULL, NULL, NULL },
{ VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_file", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("Startup File:"), VIK_LAYER_WIDGET_FILEENTRY, NULL, NULL,
N_("The default file to load on startup. Only applies when the startup method is set to 'Specified File'"), NULL, },
+ { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "check_version", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, N_("Check For New Version:"), VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL,
+ N_("Periodically check to see if a new version of Viking is available"), NULL, },
};
/* End of Options static stuff */
tmp.s = "";
a_preferences_register(&startup_prefs[3], tmp, VIKING_PREFERENCES_STARTUP_GROUP_KEY);
+ tmp.b = FALSE;
+ a_preferences_register(&startup_prefs[4], tmp, VIKING_PREFERENCES_STARTUP_GROUP_KEY);
+
// New Tab
a_preferences_register_group ( VIKING_PREFERENCES_IO_GROUP_KEY, _("Export/External") );
{
return a_preferences_get(VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_file")->s;
}
+
+gboolean a_vik_get_check_version ( )
+{
+ return a_preferences_get(VIKING_PREFERENCES_STARTUP_NAMESPACE "check_version")->b;
+}
#include "download.h"
#include "preferences.h"
#include "vikmapslayer.h"
+#include "settings.h"
/*
#ifdef WINDOWS
_("There is a newer version of Viking available: %s\n\nDo you wish to go to Viking's website now?"), nvtd->version ) )
// NB 'VIKING_URL' redirects to the Wiki, here we want to go the main site.
open_url ( nvtd->window, "http://sourceforge.net/projects/viking/" );
- //else
- // increase amount of time between performing version checks
+
g_free ( nvtd->version );
g_free ( nvtd );
return FALSE;
}
+#define VIK_SETTINGS_VERSION_CHECKED_DATE "version_checked_date"
+
static void latest_version_thread ( GtkWindow *window )
{
- // Need to allow a few of redirects, as SF file is often served from different server
+ // Need to allow a few redirects, as SF file is often served from different server
DownloadMapOptions options = { FALSE, FALSE, NULL, 5, NULL, NULL };
gchar *filename = a_download_uri_to_tmp_file ( "http://sourceforge.net/projects/viking/files/VERSION", &options );
//gchar *filename = g_strdup ( "VERSION" );
g_remove ( filename );
g_free ( filename );
}
+
+ // Update last checked time
+ GTimeVal time;
+ g_get_current_time ( &time );
+ a_settings_set_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, g_time_val_to_iso8601(&time) );
}
+#define VIK_SETTINGS_VERSION_CHECK_PERIOD "version_check_period_days"
+
/**
* check_latest_version:
* @window: Somewhere where we may need use the display to inform the user about the version status
*
* Periodically checks the released latest VERSION file on the website to compare with the running version
*
- * ATM the plan is for a 1.4.2 release to be always on *just* for Windows platforms
- * Then in 1.5.X it will made entirely optional (default on for Windows)
- * with a longer periodic check (enabled via state saving using the soon to be released 'settings' code)
- *
*/
void check_latest_version ( GtkWindow *window )
{
-#ifdef WINDOWS
+ if ( ! a_vik_get_check_version () )
+ return;
+
+ gboolean do_check = FALSE;
+
+ gint check_period;
+ if ( ! a_settings_get_integer ( VIK_SETTINGS_VERSION_CHECK_PERIOD, &check_period ) ) {
+ check_period = 14;
+ }
+
+ // Get last checked date...
+ GDate *gdate_last = g_date_new();
+ GDate *gdate_now = g_date_new();
+ GTimeVal time_last;
+ gchar *last_checked_date = NULL;
+
+ // When no previous date available - set to do the version check
+ if ( a_settings_get_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, &last_checked_date) ) {
+ if ( g_time_val_from_iso8601 ( last_checked_date, &time_last ) ) {
+ g_date_set_time_val ( gdate_last, &time_last );
+ }
+ else
+ do_check = TRUE;
+ }
+ else
+ do_check = TRUE;
+
+ GTimeVal time_now;
+ g_get_current_time ( &time_now );
+ g_date_set_time_val ( gdate_now, &time_now );
+
+ if ( ! do_check ) {
+ // Dates available so do the comparison
+ g_date_add_days ( gdate_last, check_period );
+ if ( g_date_compare ( gdate_last, gdate_now ) < 0 )
+ do_check = TRUE;
+ }
+
+ g_date_free ( gdate_last );
+ g_date_free ( gdate_now );
+
+ if ( do_check ) {
#if GLIB_CHECK_VERSION (2, 32, 0)
- g_thread_try_new ( "latest_version_thread", (GThreadFunc)latest_version_thread, window, NULL );
+ g_thread_try_new ( "latest_version_thread", (GThreadFunc)latest_version_thread, window, NULL );
#else
- g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL );
-#endif
+ g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL );
#endif
+ }
}
/**
vlp_data.u = VIK_STARTUP_METHOD_AUTO_LOCATION;
a_preferences_run_setparam ( vlp_data, pref_startup_method );
+ // Only on Windows make checking for the latest version on by default
+ // For other systems it's expected a Package manager or similar controls the installation, so leave it off
+#ifdef WINDOWS
+ VikLayerParam pref_startup_version_check[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "check_version", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, NULL, }, };
+ vlp_data.b = TRUE;
+ a_preferences_run_setparam ( vlp_data, pref_startup_version_check );
+#endif
+
// Ensure settings are saved for next time
a_preferences_save_to_file ();
}