From cdcaf41c6bb6275fb40f59ad1b32a4485525c489 Mon Sep 17 00:00:00 2001 From: Quy Tonthat Date: Tue, 23 Jan 2007 02:18:19 +0000 Subject: [PATCH] Merged branch modular (r146:173) to trunk --- AUTHORS | 2 +- ChangeLog | 26 +++++++-- NEWS | 6 +++ README | 3 ++ configure.ac | 41 +++++++++++++- src/Makefile.am | 23 ++++++-- src/expedia.c | 7 +++ src/expedia.h | 2 + src/google.c | 11 ++++ src/google.h | 2 + src/googlemaps.c | 7 +++ src/googlemaps.h | 2 + src/khmaps.c | 7 +++ src/khmaps.h | 2 + src/main.c | 5 ++ src/mapcoord.h | 3 +- src/modules.c | 48 +++++++++++++++++ src/modules.h | 27 ++++++++++ src/terraserver.c | 13 +++++ src/terraserver.h | 2 + src/viklayer.c | 10 ++-- src/viklayer.h | 6 +-- src/vikmapslayer.c | 126 ++++++++++++++++++++++++++------------------ src/vikmapslayer.h | 16 ++++++ src/vikradiogroup.c | 16 +++--- src/vikradiogroup.h | 2 +- 26 files changed, 338 insertions(+), 77 deletions(-) create mode 100644 src/modules.c create mode 100644 src/modules.h diff --git a/AUTHORS b/AUTHORS index 0dd3b263..8afc9e04 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,5 +1,5 @@ Evan Battaglia ** Concept and main design/coding Alex Foobarian ** DND, icons, various other features/bugfixes -Guilhem BONNEFILLE ** Autotools +Guilhem BONNEFILLE ** Autotools Few other bugfixes/minor patches from various contributors. See ChangeLog for details. diff --git a/ChangeLog b/ChangeLog index 31ef3b22..214561fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-01-23 +Quy Tonthat : + * Merged branch modular to trunk. + 2007-01-05 Quy Tonthat : * Bug fix: main menu edit->delete and edit->cut did not work with @@ -21,19 +25,35 @@ Quy Tonthat : * gpslayer: Unexpose interface functions. * Layers now can have their say on what pop up menu items they want. -2007-01-01 +2007-01-02 Guilhem Bonnefille - * Make all .h self sufficient - + * Add ability to disable Terraserver stuff + * Add ability to disable Expedia stuff + 2007-01-01 Quy Tonthat : * gpslayer: fix bugs that causes crashes when click "Cancel" on layer creation dialog. +2007-01-01 +Guilhem Bonnefille + * Make all .h self sufficient + * Add ability to disable Google stuff + 2006-12-31 Quy Tonthat : * Added gps layer +2007-01-02 +Guilhem Bonnefille + * Add ability to disable Terraserver stuff + * Add ability to disable Expedia stuff + +2007-01-01 +Guilhem Bonnefille + * Make all .h self sufficient + * Add ability to disable Google stuff + 2006-12-26 Quy Tonthat : * Fix a google version number change (at least in Australia). diff --git a/NEWS b/NEWS index dcd0c900..1020d447 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,9 @@ +Viking modularized (2007-01-14) +- new configure options: + * --disable-google + * --disable-terraserver + * --disable-expedia + Viking 0.1.1 (2006-06-11) - more map sources such as google - drag and drop of layers and way/trackpoints diff --git a/README b/README index 9896ad2c..50119821 100644 --- a/README +++ b/README @@ -7,6 +7,9 @@ Next, or if you downloaded a tarball, you have to: $ ./configure $ make +Check output of "./configure --help" for configuration options. +In particular, it is possible to disable some features, like --disable-google in order to disable any Google stuff. + If you whish to install viking, you have to (as root): # make install diff --git a/configure.ac b/configure.ac index 21c9e773..51da3119 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.59) -AC_INIT(viking, 0.1.1) +AC_INIT(viking, modular.1) AM_INIT_AUTOMAKE() dnl AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([src/config.h]) @@ -49,6 +49,45 @@ case $ac_cv_enable_alpha_trw in ;; esac +AC_ARG_ENABLE(google, AC_HELP_STRING([--enable-google], + [enable Google stuff (default is enable)]), + [ac_cv_enable_google=$enableval], + [ac_cv_enable_google=yes]) +AC_CACHE_CHECK([whether to enable Google stuff], + [ac_cv_enable_google], [ac_cv_enable_google=yes]) +case $ac_cv_enable_google in + yes) + AC_DEFINE(VIK_CONFIG_GOOGLE, [], [GOOGLE STUFF]) + ;; +esac +AM_CONDITIONAL([GOOGLE], [test x$ac_cv_enable_google = xyes]) + +AC_ARG_ENABLE(terraserver, AC_HELP_STRING([--enable-terraserver], + [enable Terraserver stuff (default is enable)]), + [ac_cv_enable_terraserver=$enableval], + [ac_cv_enable_terraserver=yes]) +AC_CACHE_CHECK([whether to enable Terraserver stuff], + [ac_cv_enable_terraserver], [ac_cv_enable_terraserver=yes]) +case $ac_cv_enable_terraserver in + yes) + AC_DEFINE(VIK_CONFIG_TERRASERVER, [], [TERRASERVER STUFF]) + ;; +esac +AM_CONDITIONAL([TERRASERVER], [test x$ac_cv_enable_terraserver = xyes]) + +AC_ARG_ENABLE(expedia, AC_HELP_STRING([--enable-expedia], + [enable Expedia stuff (default is enable)]), + [ac_cv_enable_expedia=$enableval], + [ac_cv_enable_expedia=yes]) +AC_CACHE_CHECK([whether to enable Expedia stuff], + [ac_cv_enable_expedia], [ac_cv_enable_expedia=yes]) +case $ac_cv_enable_expedia in + yes) + AC_DEFINE(VIK_CONFIG_EXPEDIA, [], [EXPEDIA STUFF]) + ;; +esac +AM_CONDITIONAL([EXPEDIA], [test x$ac_cv_enable_expedia = xyes]) + AC_ARG_WITH(mapcache, [AC_HELP_STRING([--with-mapcache], [specify the size of the map cache (default is 50331648)])], diff --git a/src/Makefile.am b/src/Makefile.am index 91e37b51..89cc866c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,6 +6,7 @@ SUBDIRS = icons bin_PROGRAMS = viking viking_SOURCES = main.c \ + modules.h modules.c \ menu.xml.h \ degrees_converters.c degrees_converters.h \ viking.h globals.h mapcoord.h config.h \ @@ -36,14 +37,9 @@ viking_SOURCES = main.c \ background.c background.h \ vikradiogroup.c vikradiogroup.h \ vikcoord.c vikcoord.h \ - expedia.c expedia.h \ mapcache.c mapcache.h \ vikmapslayer.c vikmapslayer.h vikmapslayer_pixmap.h \ - terraserver.c terraserver.h \ - google.c google.h \ - googlemaps.c googlemaps.h \ gtkcellrendererprogress.c gtkcellrendererprogress.h \ - khmaps.c khmaps.h \ gpx.c gpx.h \ garminsymbols.c garminsymbols.h \ acquire.c acquire.h \ @@ -53,6 +49,23 @@ viking_SOURCES = main.c \ datasource_gc.c \ datasources.h +if GOOGLE +viking_SOURCES += \ + khmaps.c khmaps.h \ + google.c google.h \ + googlemaps.c googlemaps.h +endif + +if TERRASERVER +viking_SOURCES += \ + terraserver.c terraserver.h +endif + +if EXPEDIA +viking_SOURCES += \ + expedia.c expedia.h +endif + INCLUDES = @GTK_CFLAGS@ @EXPAT_CFLAGS@ LDADD = @GTK_LIBS@ @EXPAT_LIBS@ AM_CFLAGS = -Wall -g diff --git a/src/expedia.c b/src/expedia.c index 1d3b1c2e..55397632 100644 --- a/src/expedia.c +++ b/src/expedia.c @@ -29,7 +29,14 @@ #include "vikcoord.h" #include "mapcoord.h" #include "http.h" +#include "vikmapslayer.h" +#include "expedia.h" + +void expedia_init() { + VikMapsLayer_MapType map_type = { 5, 0, 0, VIK_VIEWPORT_DRAWMODE_EXPEDIA, expedia_coord_to_mapcoord, expedia_mapcoord_to_center_coord, expedia_download }; + maps_layer_register_type("Expedia Street Maps", 5, &map_type); +} #define EXPEDIA_SITE "expedia.com" #define MPP_MARGIN_OF_ERROR 0.01 diff --git a/src/expedia.h b/src/expedia.h index 69d1531e..24aa96fd 100644 --- a/src/expedia.h +++ b/src/expedia.h @@ -27,6 +27,8 @@ #include "vikcoord.h" #include "mapcoord.h" +void expedia_init(); + gboolean expedia_coord_to_mapcoord ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); void expedia_mapcoord_to_center_coord ( MapCoord *src, VikCoord *dest ); void expedia_download ( MapCoord *src, const gchar *dest_fn ); diff --git a/src/google.c b/src/google.c index c4375434..a75a63e1 100644 --- a/src/google.c +++ b/src/google.c @@ -28,6 +28,17 @@ #include "http.h" #include "globals.h" #include "google.h" +#include "vikmapslayer.h" + +void google_init () { + VikMapsLayer_MapType google_1 = { 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download }; + VikMapsLayer_MapType google_2 = { 10, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_trans_download }; + VikMapsLayer_MapType google_3 = { 11, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_kh_download }; + + maps_layer_register_type("Google Maps", 7, &google_1); + maps_layer_register_type("Transparent Google Maps", 10, &google_2); + maps_layer_register_type("Google Satellite Images", 11, &google_3); +} /* 1 << (x) is like a 2**(x) */ #define GZ(x) ((1< +#include "modules.h" + #define MAX_WINDOWS 1024 static guint window_count = 0; @@ -87,6 +89,9 @@ int main( int argc, char *argv[] ) gtk_init (&argc, &argv); + /* Init modules/plugins */ + modules_init(); + a_mapcache_init (); a_background_init (); diff --git a/src/mapcoord.h b/src/mapcoord.h index 9f274350..36b71ecf 100644 --- a/src/mapcoord.h +++ b/src/mapcoord.h @@ -19,7 +19,6 @@ * */ - #ifndef __MAP_COORD_H #define __MAP_COORD_H @@ -34,5 +33,5 @@ typedef struct { guint scale; } MapCoord; - #endif + diff --git a/src/modules.c b/src/modules.c new file mode 100644 index 00000000..2b56aeff --- /dev/null +++ b/src/modules.c @@ -0,0 +1,48 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2006-2007, Guilhem Bonnefille + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "modules.h" + +#include "google.h" +#include "googlemaps.h" +#include "terraserver.h" +#include "khmaps.h" +#include "expedia.h" + +void modules_init() +{ +#ifdef VIK_CONFIG_GOOGLE + google_init(); + googlemaps_init(); + khmaps_init(); +#endif +#ifdef VIK_CONFIG_EXPEDIA + expedia_init(); +#endif +#ifdef VIK_CONFIG_TERRASERVER + terraserver_init(); +#endif +} + diff --git a/src/modules.h b/src/modules.h new file mode 100644 index 00000000..f36fa559 --- /dev/null +++ b/src/modules.h @@ -0,0 +1,27 @@ +/* + * viking -- GPS Data and Topo Analyzer, Explorer, and Manager + * + * Copyright (C) 2006-2007, Guilhem Bonnefille + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef __VIKING_MODULES_H +#define __VIKING_MODULES_H + +void modules_init(); + +#endif diff --git a/src/terraserver.c b/src/terraserver.c index 9ddcb1af..f50039c7 100644 --- a/src/terraserver.c +++ b/src/terraserver.c @@ -25,6 +25,19 @@ #include "vikcoord.h" #include "mapcoord.h" #include "http.h" +#include "vikmapslayer.h" + +#include "terraserver.h" + +void terraserver_init () { + VikMapsLayer_MapType map_type_1 = { 2, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_topo_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_topo_download }; + VikMapsLayer_MapType map_type_2 = { 1, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_aerial_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_aerial_download }; + VikMapsLayer_MapType map_type_3 = { 4, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_urban_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_urban_download }; + + maps_layer_register_type("Terraserver Topos", 2, &map_type_1); + maps_layer_register_type("Terraserver Aerials", 1, &map_type_2); + maps_layer_register_type("Terraserver Urban Areas", 4, &map_type_3); +} #define TERRASERVER_SITE "terraserver-usa.com" #define MARGIN_OF_ERROR 0.001 diff --git a/src/terraserver.h b/src/terraserver.h index b9434857..c54f01df 100644 --- a/src/terraserver.h +++ b/src/terraserver.h @@ -27,6 +27,8 @@ #include "vikcoord.h" #include "mapcoord.h" +void terraserver_init(); + gboolean terraserver_topo_coord_to_mapcoord ( const VikCoord *src, gdouble xmpp, gdouble ympp, MapCoord *dest ); void terraserver_topo_download ( MapCoord *src, const gchar *dest_fn ); diff --git a/src/viklayer.c b/src/viklayer.c index aef7a9cb..ef612e97 100644 --- a/src/viklayer.c +++ b/src/viklayer.c @@ -405,7 +405,7 @@ void vik_layer_post_read ( VikLayer *layer, gpointer vp ) static GtkWidget *properties_widget_new_widget ( VikLayerParam *param, VikLayerParamData data ) { - GtkWidget *rv; + GtkWidget *rv = NULL; switch ( param->widget_type ) { case VIK_LAYER_WIDGET_COLOR: @@ -444,13 +444,15 @@ static GtkWidget *properties_widget_new_widget ( VikLayerParam *param, VikLayerP break; #endif case VIK_LAYER_WIDGET_RADIOGROUP: + /* widget_data and extra_widget_data are GList */ if ( param->type == VIK_LAYER_PARAM_UINT && param->widget_data ) { - rv = vik_radio_group_new ( (const gchar **) param->widget_data ); + rv = vik_radio_group_new ( param->widget_data ); if ( param->extra_widget_data ) /* map of alternate uint values for options */ { int i; - for ( i = 0; ((const char **)param->widget_data)[i]; i++ ) + int nb_elem = g_list_length(param->widget_data); + for ( i = 0; i < nb_elem; i++ ) if ( ((guint *)param->extra_widget_data)[i] == data.u ) { vik_radio_group_set_selected ( VIK_RADIO_GROUP(rv), i ); @@ -521,7 +523,7 @@ static VikLayerParamData properties_widget_get_value ( GtkWidget *widget, VikLay case VIK_LAYER_WIDGET_RADIOGROUP: rv.u = vik_radio_group_get_selected(VIK_RADIO_GROUP(widget)); if ( param->extra_widget_data ) - rv.u = ((guint *)param->extra_widget_data)[rv.u]; + rv.u = (guint *)g_list_nth_data(param->extra_widget_data, rv.u); break; case VIK_LAYER_WIDGET_SPINBUTTON: if ( param->type == VIK_LAYER_PARAM_UINT ) diff --git a/src/viklayer.h b/src/viklayer.h index 543da016..f08658ae 100644 --- a/src/viklayer.h +++ b/src/viklayer.h @@ -25,8 +25,8 @@ #include #include #include -#include "vikwindow.h" +#include "vikwindow.h" #include "viktreeview.h" #include "vikviewport.h" @@ -115,8 +115,8 @@ typedef struct { gint16 group; const gchar *title; guint8 widget_type; - const gpointer widget_data; - const gpointer extra_widget_data; + gpointer widget_data; + gpointer extra_widget_data; } VikLayerParam; enum { diff --git a/src/vikmapslayer.c b/src/vikmapslayer.c index ad488a1e..eeb093b3 100644 --- a/src/vikmapslayer.c +++ b/src/vikmapslayer.c @@ -3,6 +3,7 @@ * * Copyright (C) 2005, Evan Battaglia * UTM multi-zone stuff by Kit Transue + * Dynamic map type by Guilhem Bonnefille * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -59,34 +60,18 @@ #include "khmaps.h" #include "expedia.h" -typedef struct { - guint8 uniq_id; - guint16 tilesize_x; - guint16 tilesize_y; - guint drawmode; - gboolean (*coord_to_mapcoord) ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); - void (*mapcoord_to_center_coord) ( MapCoord *src, VikCoord *dest ); - void (*download) ( MapCoord *src, const gchar *dest_fn ); - /* TODO: constant size (yay!) */ -} VikMapsLayer_MapType; - /****** MAP TYPES ******/ -static const VikMapsLayer_MapType __map_types[] = { - -{ 2, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_topo_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_topo_download }, -{ 1, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_aerial_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_aerial_download }, -{ 4, 200, 200, VIK_VIEWPORT_DRAWMODE_UTM, terraserver_urban_coord_to_mapcoord, terraserver_mapcoord_to_center_coord, terraserver_urban_download }, -{ 5, 0, 0, VIK_VIEWPORT_DRAWMODE_EXPEDIA, expedia_coord_to_mapcoord, expedia_mapcoord_to_center_coord, expedia_download }, -{ 9, 128, 128, VIK_VIEWPORT_DRAWMODE_GOOGLE, googlemaps_coord_to_mapcoord, googlemaps_mapcoord_to_center_coord, googlemaps_download }, -{ 8, 256, 256, VIK_VIEWPORT_DRAWMODE_KH, khmaps_coord_to_mapcoord, khmaps_mapcoord_to_center_coord, khmaps_download }, -{ 7, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_download }, -{ 10, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_trans_download }, -{ 11, 256, 256, VIK_VIEWPORT_DRAWMODE_MERCATOR, google_coord_to_mapcoord, google_mapcoord_to_center_coord, google_kh_download }, -}; +static GList *__map_types = NULL; + +#define NUM_MAP_TYPES g_list_length(__map_types) -#define NUM_MAP_TYPES (sizeof(__map_types)/sizeof(__map_types[0])) +/* List of label for each map type */ +static GList *params_maptypes = NULL; + +/* Corresponding IDS. (Cf. field uniq_id in VikMapsLayer struct) */ +static GList *params_maptypes_ids = NULL; /******** MAPZOOMS *********/ @@ -94,8 +79,6 @@ static gchar *params_mapzooms[] = { "Use Viking Zoom Level", "0.25", "1", "2", " static gdouble __mapzooms_x[] = { 0.0, 0.25, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 1.016, 2.4384, 2.54, 5.08, 10.16, 20.32, 25.4 }; static gdouble __mapzooms_y[] = { 0.0, 0.25, 1.0, 2.0, 4.0, 8.0, 16.0, 32.0, 64.0, 128.0, 256.0, 512.0, 1024.0, 1.016, 2.4384, 2.54, 5.08, 10.16, 20.32, 25.4 }; -static gchar *params_maptypes[] = { "Terraserver Topos", "Terraserver Aerials", "Terraserver Urban Areas", "Expedia Street Maps", "Old Google Maps", "Old KH Satellite Images", "Google Maps", "Transparent Google Maps", "Google Satellite Images" }; -static guint params_maptypes_ids[] = { 2, 1, 4, 5, 9, 8, 7, 10, 11 }; #define NUM_MAPZOOMS (sizeof(params_mapzooms)/sizeof(params_mapzooms[0]) - 1) /**************************/ @@ -123,7 +106,7 @@ static VikLayerParamScale params_scales[] = { }; VikLayerParam maps_layer_params[] = { - { "mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, "Map Type:", VIK_LAYER_WIDGET_RADIOGROUP, params_maptypes, params_maptypes_ids }, + { "mode", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, "Map Type:", VIK_LAYER_WIDGET_RADIOGROUP, NULL, NULL }, { "directory", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, "Maps Directory (Optional):", VIK_LAYER_WIDGET_FILEENTRY }, { "alpha", VIK_LAYER_PARAM_UINT, VIK_LAYER_GROUP_NONE, "Alpha:", VIK_LAYER_WIDGET_HSCALE, params_scales }, { "autodownload", VIK_LAYER_PARAM_BOOLEAN, VIK_LAYER_GROUP_NONE, "Autodownload maps:", VIK_LAYER_WIDGET_CHECKBUTTON }, @@ -206,6 +189,43 @@ struct _VikMapsLayer { enum { REDOWNLOAD_NONE = 0, REDOWNLOAD_BAD, REDOWNLOAD_ALL }; +/****************************************/ +/******** MAPS LAYER TYPES **************/ +/****************************************/ + +void maps_layer_register_type ( const char *label, guint id, VikMapsLayer_MapType *map_type ) +{ + g_assert(label != NULL); + g_assert(map_type != NULL); + g_assert(id == map_type->uniq_id); + + /* Add the label */ + params_maptypes = g_list_append(params_maptypes, g_strdup(label)); + + /* Add the id */ + params_maptypes_ids = g_list_append(params_maptypes_ids, (gpointer)id); + + /* We have to clone */ + VikMapsLayer_MapType *clone = g_memdup(map_type, sizeof(VikMapsLayer_MapType)); + /* Register the clone in the list */ + __map_types = g_list_append(__map_types, clone); + + /* Hack + We have to ensure the mode LayerParam reference the up-to-date + GLists. + */ + /* + memcpy(&maps_layer_params[0].widget_data, ¶ms_maptypes, sizeof(gpointer)); + memcpy(&maps_layer_params[0].extra_widget_data, ¶ms_maptypes_ids, sizeof(gpointer)); + */ + maps_layer_params[0].widget_data = params_maptypes; + maps_layer_params[0].extra_widget_data = params_maptypes_ids; +} + +#define MAPS_LAYER_NTH_LABEL(n) ((gchar*)g_list_nth_data(params_maptypes, (n))) +#define MAPS_LAYER_NTH_ID(n) ((guint)g_list_nth_data(params_maptypes_ids, (n))) +#define MAPS_LAYER_NTH_TYPE(n) ((VikMapsLayer_MapType*)g_list_nth_data(__map_types, (n))) + /****************************************/ /******** CACHE DIR STUFF ***************/ /****************************************/ @@ -324,14 +344,14 @@ GType vik_maps_layer_get_type () static guint map_index_to_uniq_id (guint8 index) { g_assert ( index < NUM_MAP_TYPES ); - return __map_types[index].uniq_id; + return MAPS_LAYER_NTH_TYPE(index)->uniq_id; } static guint map_uniq_id_to_index ( guint uniq_id ) { gint i; for ( i = 0; i < NUM_MAP_TYPES; i++ ) - if ( __map_types[i].uniq_id == uniq_id ) + if ( MAPS_LAYER_NTH_TYPE(i)->uniq_id == uniq_id ) return i; return NUM_MAP_TYPES; /* no such thing */ } @@ -492,7 +512,7 @@ static GdkPixbuf *get_pixbuf( VikMapsLayer *vml, gint mode, MapCoord *mapcoord, pixbuf = pixbuf_shrink ( pixbuf, xshrinkfactor, yshrinkfactor ); a_mapcache_add ( pixbuf, mapcoord->x, mapcoord->y, - mapcoord->z, __map_types[vml->maptype].uniq_id, + mapcoord->z, MAPS_LAYER_NTH_TYPE(vml->maptype)->uniq_id, mapcoord->scale, vml->alpha, xshrinkfactor, yshrinkfactor ); } } @@ -521,14 +541,15 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo } /* coord -> ID */ - if ( __map_types[vml->maptype].coord_to_mapcoord ( ul, xzoom, yzoom, &ulm ) && - __map_types[vml->maptype].coord_to_mapcoord ( br, xzoom, yzoom, &brm ) ) { + VikMapsLayer_MapType *map_type = MAPS_LAYER_NTH_TYPE(vml->maptype); + if ( map_type->coord_to_mapcoord ( ul, xzoom, yzoom, &ulm ) && + map_type->coord_to_mapcoord ( br, xzoom, yzoom, &brm ) ) { /* loop & draw */ gint x, y; gint xmin = MIN(ulm.x, brm.x), xmax = MAX(ulm.x, brm.x); gint ymin = MIN(ulm.y, brm.y), ymax = MAX(ulm.y, brm.y); - gint mode = __map_types[vml->maptype].uniq_id; + gint mode = map_type->uniq_id; VikCoord coord; gint xx, yy, width, height; @@ -540,7 +561,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo if ( vml->autodownload ) start_download_thread ( vml, vvp, ul, br, REDOWNLOAD_NONE ); - if ( __map_types[vml->maptype].tilesize_x == 0 ) { + if ( map_type->tilesize_x == 0 ) { for ( x = xmin; x <= xmax; x++ ) { for ( y = ymin; y <= ymax; y++ ) { ulm.x = x; @@ -550,7 +571,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo width = gdk_pixbuf_get_width ( pixbuf ); height = gdk_pixbuf_get_height ( pixbuf ); - __map_types[vml->maptype].mapcoord_to_center_coord ( &ulm, &coord ); + map_type->mapcoord_to_center_coord ( &ulm, &coord ); vik_viewport_coord_to_screen ( vvp, &coord, &xx, &yy ); xx -= (width/2); yy -= (height/2); @@ -560,8 +581,8 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo } } } else { /* tilesize is known, don't have to keep converting coords */ - gdouble tilesize_x = __map_types[vml->maptype].tilesize_x * xshrinkfactor; - gdouble tilesize_y = __map_types[vml->maptype].tilesize_y * yshrinkfactor; + gdouble tilesize_x = map_type->tilesize_x * xshrinkfactor; + gdouble tilesize_y = map_type->tilesize_y * yshrinkfactor; /* ceiled so tiles will be maximum size in the case of funky shrinkfactor */ gint tilesize_x_ceil = ceil ( tilesize_x ); gint tilesize_y_ceil = ceil ( tilesize_y ); @@ -572,7 +593,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo xend = (xinc == 1) ? (xmax+1) : (xmin-1); yend = (yinc == 1) ? (ymax+1) : (ymin-1); - __map_types[vml->maptype].mapcoord_to_center_coord ( &ulm, &coord ); + map_type->mapcoord_to_center_coord ( &ulm, &coord ); vik_viewport_coord_to_screen ( vvp, &coord, &xx_tmp, &yy_tmp ); xx = xx_tmp; yy = yy_tmp; /* above trick so xx,yy doubles. this is so shrinkfactors aren't rounded off @@ -601,7 +622,7 @@ static void maps_layer_draw_section ( VikMapsLayer *vml, VikViewport *vvp, VikCo static void maps_layer_draw ( VikMapsLayer *vml, VikViewport *vvp ) { - if ( __map_types[vml->maptype].drawmode == vik_viewport_get_drawmode ( vvp ) ) + if ( MAPS_LAYER_NTH_TYPE(vml->maptype)->drawmode == vik_viewport_get_drawmode ( vvp ) ) { VikCoord ul, br; @@ -657,7 +678,7 @@ static void map_download_thread ( MapDownloadInfo *mdi, gpointer threaddata ) for ( y = mdi->y0; y <= mdi->yf; y++ ) { g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE, - mdi->cache_dir, __map_types[mdi->maptype].uniq_id, + mdi->cache_dir, MAPS_LAYER_NTH_TYPE(mdi->maptype)->uniq_id, mdi->mapcoord.scale, mdi->mapcoord.z, x, y ); if ( mdi->redownload == REDOWNLOAD_ALL) @@ -678,7 +699,7 @@ static void map_download_thread ( MapDownloadInfo *mdi, gpointer threaddata ) if ( access ( mdi->filename_buf, F_OK ) != 0 ) { mdi->mapcoord.x = x; mdi->mapcoord.y = y; - __map_types[mdi->maptype].download ( &(mdi->mapcoord), mdi->filename_buf ); + MAPS_LAYER_NTH_TYPE(mdi->maptype)->download ( &(mdi->mapcoord), mdi->filename_buf ); mdi->mapcoord.x = mdi->mapcoord.y = 0; /* we're temporarily between downloads */ if ( mdi->redownload !=- REDOWNLOAD_NONE ) @@ -697,7 +718,7 @@ static void mdi_cancel_cleanup ( MapDownloadInfo *mdi ) if ( mdi->mapcoord.x || mdi->mapcoord.y ) { g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE, - mdi->cache_dir, __map_types[mdi->maptype].uniq_id, + mdi->cache_dir, MAPS_LAYER_NTH_TYPE(mdi->maptype)->uniq_id, mdi->mapcoord.scale, mdi->mapcoord.z, mdi->mapcoord.x, mdi->mapcoord.y ); if ( access ( mdi->filename_buf, F_OK ) == 0) { @@ -711,8 +732,9 @@ static void start_download_thread ( VikMapsLayer *vml, VikViewport *vvp, const V gdouble xzoom = vml->xmapzoom ? vml->xmapzoom : vik_viewport_get_xmpp ( vvp ); gdouble yzoom = vml->ymapzoom ? vml->ymapzoom : vik_viewport_get_ympp ( vvp ); MapCoord ulm, brm; - if ( __map_types[vml->maptype].coord_to_mapcoord ( ul, xzoom, yzoom, &ulm ) - && __map_types[vml->maptype].coord_to_mapcoord ( br, xzoom, yzoom, &brm ) ) + VikMapsLayer_MapType *map_type = MAPS_LAYER_NTH_TYPE(vml->maptype); + if ( map_type->coord_to_mapcoord ( ul, xzoom, yzoom, &ulm ) + && map_type->coord_to_mapcoord ( br, xzoom, yzoom, &brm ) ) { MapDownloadInfo *mdi = g_malloc ( sizeof(MapDownloadInfo) ); gint a, b; @@ -743,7 +765,7 @@ static void start_download_thread ( VikMapsLayer *vml, VikViewport *vvp, const V for ( b = mdi->y0; b <= mdi->yf; b++ ) { g_snprintf ( mdi->filename_buf, mdi->maxlen, DIRSTRUCTURE, - vml->cache_dir, __map_types[vml->maptype].uniq_id, ulm.scale, + vml->cache_dir, map_type->uniq_id, ulm.scale, ulm.z, a, b ); if ( access ( mdi->filename_buf, F_OK ) != 0) mdi->mapstoget++; @@ -755,7 +777,7 @@ static void start_download_thread ( VikMapsLayer *vml, VikViewport *vvp, const V if ( mdi->mapstoget ) { - gchar *tmp = g_strdup_printf ( "%s %s%d %s %s...", redownload ? "Redownloading" : "Downloading", redownload == REDOWNLOAD_BAD ? "up to " : "", mdi->mapstoget, params_maptypes[vml->maptype], (mdi->mapstoget == 1) ? "map" : "maps" ); + gchar *tmp = g_strdup_printf ( "%s %s%d %s %s...", redownload ? "Redownloading" : "Downloading", redownload == REDOWNLOAD_BAD ? "up to " : "", mdi->mapstoget, MAPS_LAYER_NTH_LABEL(vml->maptype), (mdi->mapstoget == 1) ? "map" : "maps" ); /* launch the thread */ a_background_thread ( VIK_GTK_WINDOW_FROM_LAYER(vml), /* parent window */ @@ -835,8 +857,9 @@ static gboolean maps_layer_download_click ( VikMapsLayer *vml, GdkEventButton *e MapCoord tmp; if (!vml || vml->vl.type != VIK_LAYER_MAPS) return FALSE; - if ( __map_types[vml->maptype].drawmode == vik_viewport_get_drawmode ( vvp ) && - __map_types[vml->maptype].coord_to_mapcoord ( vik_viewport_get_center ( vvp ), + VikMapsLayer_MapType *map_type = MAPS_LAYER_NTH_TYPE(vml->maptype); + if ( map_type->drawmode == vik_viewport_get_drawmode ( vvp ) && + map_type->coord_to_mapcoord ( vik_viewport_get_center ( vvp ), vml->xmapzoom ? vml->xmapzoom : vik_viewport_get_xmpp ( vvp ), vml->ymapzoom ? vml->ymapzoom : vik_viewport_get_ympp ( vvp ), &tmp ) ) { @@ -884,9 +907,10 @@ static void maps_layer_download_onscreen_maps ( gpointer vml_vvp[2] ) vik_viewport_screen_to_coord ( vvp, 0, 0, &ul ); vik_viewport_screen_to_coord ( vvp, vik_viewport_get_width(vvp), vik_viewport_get_height(vvp), &br ); - if ( __map_types[vml->maptype].drawmode == vik_viewport_get_drawmode ( vvp ) && - __map_types[vml->maptype].coord_to_mapcoord ( &ul, xzoom, yzoom, &ulm ) && - __map_types[vml->maptype].coord_to_mapcoord ( &br, xzoom, yzoom, &brm ) ) + VikMapsLayer_MapType *map_type = MAPS_LAYER_NTH_TYPE(vml->maptype); + if ( map_type->drawmode == vik_viewport_get_drawmode ( vvp ) && + map_type->coord_to_mapcoord ( &ul, xzoom, yzoom, &ulm ) && + map_type->coord_to_mapcoord ( &br, xzoom, yzoom, &brm ) ) start_download_thread ( vml, vvp, &ul, &br, REDOWNLOAD_NONE ); else a_dialog_error_msg ( VIK_GTK_WINDOW_FROM_LAYER(vml), "Wrong drawmode / zoom level for this map." ); diff --git a/src/vikmapslayer.h b/src/vikmapslayer.h index 3df9e9d1..db157c02 100644 --- a/src/vikmapslayer.h +++ b/src/vikmapslayer.h @@ -22,7 +22,10 @@ #ifndef _VIKING_MAPSLAYER_H #define _VIKING_MAPSLAYER_H +#include "vikcoord.h" #include "viklayer.h" +#include "vikviewport.h" +#include "mapcoord.h" #define VIK_MAPS_LAYER_TYPE (vik_maps_layer_get_type ()) #define VIK_MAPS_LAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_MAPS_LAYER_TYPE, VikMapsLayer)) @@ -40,4 +43,17 @@ GType vik_maps_layer_get_type (); typedef struct _VikMapsLayer VikMapsLayer; +typedef struct { + guint8 uniq_id; + guint16 tilesize_x; + guint16 tilesize_y; + guint drawmode; + gboolean (*coord_to_mapcoord) ( const VikCoord *src, gdouble xzoom, gdouble yzoom, MapCoord *dest ); + void (*mapcoord_to_center_coord) ( MapCoord *src, VikCoord *dest ); + void (*download) ( MapCoord *src, const gchar *dest_fn ); + /* TODO: constant size (yay!) */ +} VikMapsLayer_MapType; + +void maps_layer_register_type ( const char *label, guint id, VikMapsLayer_MapType *map_type ); + #endif diff --git a/src/vikradiogroup.c b/src/vikradiogroup.c index 5b17df5b..12d25d32 100644 --- a/src/vikradiogroup.c +++ b/src/vikradiogroup.c @@ -70,27 +70,31 @@ static void radio_group_class_init ( VikRadioGroupClass *klass ) parent_class = g_type_class_peek_parent (klass); } -GtkWidget *vik_radio_group_new ( const gchar **options ) +GtkWidget *vik_radio_group_new ( GList *options ) { VikRadioGroup *vrg; GtkWidget *t; + gchar *label; + GList *option = options; - if ( ! *options ) + if ( ! options ) return NULL; vrg = VIK_RADIO_GROUP ( g_object_new ( VIK_RADIO_GROUP_TYPE, NULL ) ); - t = gtk_radio_button_new_with_label ( NULL, options[0] ); + label = g_list_nth_data(options, 0); + t = gtk_radio_button_new_with_label ( NULL, label ); gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(t), TRUE ); gtk_box_pack_start ( GTK_BOX(vrg), t, FALSE, FALSE, 0 ); vrg->radios = g_slist_append ( NULL, t ); vrg->options_count = 1; - for ( options++ ; *options ; options++ ) + while ( ( option = g_list_next(option) ) != NULL ) { - t = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(vrg->radios->data), *options ); - g_slist_append( vrg->radios, t ); + label = option->data; + t = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(vrg->radios->data), label ); + vrg->radios = g_slist_append( vrg->radios, t ); gtk_box_pack_start ( GTK_BOX(vrg), GTK_WIDGET(t), FALSE, FALSE, 0 ); vrg->options_count++; } diff --git a/src/vikradiogroup.h b/src/vikradiogroup.h index 82940718..47f54d1c 100644 --- a/src/vikradiogroup.h +++ b/src/vikradiogroup.h @@ -44,7 +44,7 @@ struct _VikRadioGroupClass GType vik_radio_group_get_type (); -GtkWidget *vik_radio_group_new ( const gchar **options ); +GtkWidget *vik_radio_group_new ( GList *options ); void vik_radio_group_set_selected ( VikRadioGroup *vrg, guint8 i ); guint8 vik_radio_group_get_selected ( VikRadioGroup *vrg ); -- 2.39.5