#include "globals.h"
#include "vikmapslayer.h"
#include "vikrouting.h"
-#include "util.h"
+#include "vikutils.h"
#ifdef VIK_CONFIG_GEOCACHES
void a_datasource_gc_init();
gdk_threads_enter ();
// Ask for confirmation of default settings on first run
- set_auto_features_on_first_run ();
+ vu_set_auto_features_on_first_run ();
/* Create the first window */
first_window = vik_window_new_window();
- check_latest_version ( GTK_WINDOW(first_window) );
+ vu_check_latest_version ( GTK_WINDOW(first_window) );
while ( ++i < argc ) {
if ( strcmp(argv[i],"--") == 0 && !dashdash_already )
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+ /*
+ * Ideally dependencies should just be on Glib, Gtk,
+ * see vikutils for things that further depend on other Viking types
+ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "util.h"
#include "dialog.h"
-#include "globals.h"
-#include "download.h"
-#include "preferences.h"
-#include "vikmapslayer.h"
-#include "settings.h"
/*
#ifdef WINDOWS
return TRUE;
}
-
-typedef struct {
- GtkWindow *window; // Layer needed for redrawing
- gchar *version; // Image list
-} new_version_thread_data;
-
-static gboolean new_version_available_message ( new_version_thread_data *nvtd )
-{
- // Only a simple goto website option is offered
- // Trying to do an installation update is platform specific
- if ( a_dialog_yes_or_no ( nvtd->window,
- _("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/" );
-
- 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 redirects, as SF file is often served from different server
- DownloadMapOptions options = { FALSE, FALSE, NULL, 5, NULL, NULL, NULL };
- gchar *filename = a_download_uri_to_tmp_file ( "http://sourceforge.net/projects/viking/files/VERSION", &options );
- //gchar *filename = g_strdup ( "VERSION" );
- if ( !filename ) {
- return;
- }
-
- GMappedFile *mf = g_mapped_file_new ( filename, FALSE, NULL );
- if ( !mf )
- return;
-
- gchar *text = g_mapped_file_get_contents ( mf );
-
- gint latest_version = viking_version_to_number ( text );
- gint my_version = viking_version_to_number ( VIKING_VERSION );
-
- g_debug ( "The lastest version is: %s", text );
-
- if ( my_version < latest_version ) {
- new_version_thread_data *nvtd = g_malloc ( sizeof(new_version_thread_data) );
- nvtd->window = window;
- nvtd->version = g_strdup ( text );
- gdk_threads_add_idle ( (GSourceFunc) new_version_available_message, nvtd );
- }
- else
- g_debug ( "Running the lastest version: %s", VIKING_VERSION );
-
- g_mapped_file_unref ( mf );
- if ( filename ) {
- 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
- *
- */
-void check_latest_version ( GtkWindow *window )
-{
- 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 );
-#else
- g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL );
-#endif
- }
-}
-
-/**
- * set_auto_features_on_first_run:
- *
- * Ask the user's opinion to set some of Viking's default behaviour
- */
-void set_auto_features_on_first_run ( void )
-{
- gboolean auto_features = FALSE;
- if ( a_vik_very_first_run () ) {
-
- GtkWidget *win = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
-
- if ( a_dialog_yes_or_no ( GTK_WINDOW(win),
- _("This appears to be Viking's very first run.\n\nDo you wish to enable automatic internet features?\n\nIndividual settings can be controlled in the Preferences."), NULL ) )
- auto_features = TRUE;
- }
-
- if ( auto_features ) {
- // Set Maps to autodownload
- // Ensure the default is true
- maps_layer_set_autodownload_default ( TRUE );
-
- // Simplistic repeat of preference settings
- // Only the name & type are important for setting a preference via this 'external' way
-
- // Enable auto add map +
- // Enable IP lookup
- VikLayerParam pref_add_map[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "add_default_map_layer", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, NULL, NULL, NULL, }, };
- VikLayerParam pref_startup_method[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_method", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_COMBOBOX, NULL, NULL, NULL, NULL, NULL, NULL}, };
-
- VikLayerParamData vlp_data;
- vlp_data.b = TRUE;
- a_preferences_run_setparam ( vlp_data, pref_add_map );
-
- 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 ();
- }
-}
gboolean split_string_from_file_on_equals ( const gchar *buf, gchar **key, gchar **val );
-void check_latest_version ( GtkWindow *window );
-
-void set_auto_features_on_first_run ( void );
-
G_END_DECLS
#endif
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
+/*
+ * Dependencies in this file can be on anything.
+ * For functions with simple system dependencies put it in util.c
+ */
#include <math.h>
+#include <glib/gstdio.h>
#include <glib/gi18n.h>
+#include <gtk/gtk.h>
-#include "viking.h"
#include "vikutils.h"
+#include "globals.h"
+#include "download.h"
+#include "preferences.h"
+#include "vikmapslayer.h"
+#include "settings.h"
+#include "util.h"
#define FMT_MAX_NUMBER_CODES 9
return msg;
}
+
+typedef struct {
+ GtkWindow *window; // Layer needed for redrawing
+ gchar *version; // Image list
+} new_version_thread_data;
+
+static gboolean new_version_available_message ( new_version_thread_data *nvtd )
+{
+ // Only a simple goto website option is offered
+ // Trying to do an installation update is platform specific
+ if ( a_dialog_yes_or_no ( nvtd->window,
+ _("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/" );
+
+ 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 redirects, as SF file is often served from different server
+ DownloadMapOptions options = { FALSE, FALSE, NULL, 5, NULL, NULL, NULL };
+ gchar *filename = a_download_uri_to_tmp_file ( "http://sourceforge.net/projects/viking/files/VERSION", &options );
+ //gchar *filename = g_strdup ( "VERSION" );
+ if ( !filename ) {
+ return;
+ }
+
+ GMappedFile *mf = g_mapped_file_new ( filename, FALSE, NULL );
+ if ( !mf )
+ return;
+
+ gchar *text = g_mapped_file_get_contents ( mf );
+
+ gint latest_version = viking_version_to_number ( text );
+ gint my_version = viking_version_to_number ( VIKING_VERSION );
+
+ g_debug ( "The lastest version is: %s", text );
+
+ if ( my_version < latest_version ) {
+ new_version_thread_data *nvtd = g_malloc ( sizeof(new_version_thread_data) );
+ nvtd->window = window;
+ nvtd->version = g_strdup ( text );
+ gdk_threads_add_idle ( (GSourceFunc) new_version_available_message, nvtd );
+ }
+ else
+ g_debug ( "Running the lastest version: %s", VIKING_VERSION );
+
+ g_mapped_file_unref ( mf );
+ if ( filename ) {
+ 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"
+
+/**
+ * vu_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
+ *
+ */
+void vu_check_latest_version ( GtkWindow *window )
+{
+ 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 );
+#else
+ g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL );
+#endif
+ }
+}
+
+/**
+ * vu_set_auto_features_on_first_run:
+ *
+ * Ask the user's opinion to set some of Viking's default behaviour
+ */
+void vu_set_auto_features_on_first_run ( void )
+{
+ gboolean auto_features = FALSE;
+ if ( a_vik_very_first_run () ) {
+
+ GtkWidget *win = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
+
+ if ( a_dialog_yes_or_no ( GTK_WINDOW(win),
+ _("This appears to be Viking's very first run.\n\nDo you wish to enable automatic internet features?\n\nIndividual settings can be controlled in the Preferences."), NULL ) )
+ auto_features = TRUE;
+ }
+
+ if ( auto_features ) {
+ // Set Maps to autodownload
+ // Ensure the default is true
+ maps_layer_set_autodownload_default ( TRUE );
+
+ // Simplistic repeat of preference settings
+ // Only the name & type are important for setting a preference via this 'external' way
+
+ // Enable auto add map +
+ // Enable IP lookup
+ VikLayerParam pref_add_map[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "add_default_map_layer", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_CHECKBUTTON, NULL, NULL, NULL, NULL, NULL, NULL, }, };
+ VikLayerParam pref_startup_method[] = { { VIK_LAYER_NUM_TYPES, VIKING_PREFERENCES_STARTUP_NAMESPACE "startup_method", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, NULL, VIK_LAYER_WIDGET_COMBOBOX, NULL, NULL, NULL, NULL, NULL, NULL}, };
+
+ VikLayerParamData vlp_data;
+ vlp_data.b = TRUE;
+ a_preferences_run_setparam ( vlp_data, pref_add_map );
+
+ 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 ();
+ }
+}
gchar* vu_trackpoint_formatted_message ( gchar *format_code, VikTrackpoint *trkpt, VikTrackpoint *trkpt_prev, VikTrack *trk );
+void vu_check_latest_version ( GtkWindow *window );
+
+void vu_set_auto_features_on_first_run ( void );
+
G_END_DECLS
#endif