]> git.street.me.uk Git - andy/viking.git/commitdiff
Merged branch modular (r146:173) to trunk
authorQuy Tonthat <qtonthat@gmail.com>
Tue, 23 Jan 2007 02:18:19 +0000 (02:18 +0000)
committerQuy Tonthat <qtonthat@gmail.com>
Tue, 23 Jan 2007 02:18:19 +0000 (02:18 +0000)
26 files changed:
AUTHORS
ChangeLog
NEWS
README
configure.ac
src/Makefile.am
src/expedia.c
src/expedia.h
src/google.c
src/google.h
src/googlemaps.c
src/googlemaps.h
src/khmaps.c
src/khmaps.h
src/main.c
src/mapcoord.h
src/modules.c [new file with mode: 0644]
src/modules.h [new file with mode: 0644]
src/terraserver.c
src/terraserver.h
src/viklayer.c
src/viklayer.h
src/vikmapslayer.c
src/vikmapslayer.h
src/vikradiogroup.c
src/vikradiogroup.h

diff --git a/AUTHORS b/AUTHORS
index 0dd3b263d53209470c3aaa57d41658e6d317a512..8afc9e048d59839cd55c5353a18262e0b8a36581 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,5 +1,5 @@
 Evan Battaglia <gtoevan@gmx.net> ** Concept and main design/coding
 Alex Foobarian <foobarian@gmail.com> ** DND, icons, various other features/bugfixes
-Guilhem BONNEFILLE  <guilhem.bonnefille@laposte.net> ** Autotools
+Guilhem BONNEFILLE  <guilhem.bonnefille@gmail.com> ** Autotools
 
 Few other bugfixes/minor patches from various contributors. See ChangeLog for details.
index 31ef3b223acd12f8f8681f2c186ea8da98abc052..214561fa8c9eb77256ac2dee17de2d1977061d90 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2007-01-23
+Quy Tonthat <qtonthat@gmail.com>:
+       * Merged branch modular to trunk.
+
 2007-01-05
 Quy Tonthat <qtonthat@gmail.com>:
        * Bug fix: main menu edit->delete and edit->cut did not work with
@@ -21,19 +25,35 @@ Quy Tonthat <qtonthat@gmail.com>:
        * 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 <guilhem.bonnefille@gmail.com>
-       * Make all .h self sufficient
-       
+       * Add ability to disable Terraserver stuff
+       * Add ability to disable Expedia stuff
+
 2007-01-01
 Quy Tonthat <qtonthat@gmail.com>:
        * gpslayer: fix bugs that causes crashes when click "Cancel" on layer
        creation dialog.
 
+2007-01-01
+Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+       * Make all .h self sufficient
+       * Add ability to disable Google stuff
+       
 2006-12-31
 Quy Tonthat <qtonthat@gmail.com>:
        * Added gps layer
 
+2007-01-02
+Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+       * Add ability to disable Terraserver stuff
+       * Add ability to disable Expedia stuff
+
+2007-01-01
+Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+       * Make all .h self sufficient
+       * Add ability to disable Google stuff
+       
 2006-12-26
 Quy Tonthat <qtonthat@gmail.com>:
        * Fix a google version number change (at least in Australia).
diff --git a/NEWS b/NEWS
index dcd0c900c2d7d2af2df0bb7f693dd826aff56566..1020d447abc636860ea13a090517cfa3ca92122b 100644 (file)
--- 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 9896ad2c9c15b406610fdafbef69385ccef6aec0..5011982159f0e292ebb781e112ffcd493fc8b1fa 100644 (file)
--- 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
 
index 21c9e773d01840076786b0bc9ad700c4cd2a9f4e..51da31195355c1387b22d213ebee9acfd5fd9ae6 100644 (file)
@@ -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)])],
index 91e37b51d8b7d80218db945e2285eaae7173c206..89cc866c30d74e865f60fdc2cae3b173daeecbc4 100644 (file)
@@ -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
index 1d3b1c2e3f0da3bb2aa5a12f82f29de3bfd7f6e5..553976328952eb9ed9441395b0327876cbcef0bd 100644 (file)
 #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
index 69d1531e9d5cdd52c3eb45f55d311878e7d1232f..24aa96fd330c47833adfe73efd65cd1c6685bb7c 100644 (file)
@@ -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 );
index c4375434f750474feab09695e19491e960d41bd7..a75a63e1a98b78565d1e8d517f3e3512038bacac 100644 (file)
 #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<<x))
index d34482a19947cda2a0c7f46f25282ace786e37cf..adde53888323e2ea048c82eaa5ab02a92ef15cea 100644 (file)
@@ -27,6 +27,8 @@
 #include "vikcoord.h"
 #include "mapcoord.h"
 
+void google_init();
+
 guint8 google_zoom ( gdouble mpp );
 
 /* a bit misleading, this is the "mpp" (really just set zoom level, very
index ce5e4bc8171af1beb6468603e87f1f205d6026bc..f72670a92f4ab9da08ff12df0dda4f6decac7671 100644 (file)
 #include "vikcoord.h"
 #include "mapcoord.h"
 #include "http.h"
+#include "vikmapslayer.h"
 
 #include "googlemaps.h"
 
+/* initialisation */
+void googlemaps_init () {
+  VikMapsLayer_MapType map_type = { 9, 128, 128, VIK_VIEWPORT_DRAWMODE_GOOGLE, googlemaps_coord_to_mapcoord, googlemaps_mapcoord_to_center_coord, googlemaps_download };
+  maps_layer_register_type("Old Google Maps", 9, &map_type);
+}
+
 /* 1 << (x-1) is like a 2**(x-1) */
 #define GZ(x) ((1<<(x-1))*GOOGLEMAPS_ZOOM_ONE_MPP)
 
index 3654b327f15f279fb02d4b7b0d1b1f82c373ef83..1ae833fd4e8257739f94dc53e9fb80193fdf003b 100644 (file)
@@ -27,6 +27,8 @@
 #include "vikcoord.h"
 #include "mapcoord.h"
 
+void googlemaps_init ();
+
 guint8 googlemaps_zoom ( gdouble mpp );
 
 /* a bit misleading, this is the "mpp" (really just set zoom level, very
index 6c860c8da83d4178a3a19285a309cd4998a912e7..2896e69f97d7755bf8669c621e6ada1a3c3cfcb1 100644 (file)
 #include "vikcoord.h"
 #include "mapcoord.h"
 #include "http.h"
+#include "vikmapslayer.h"
 
 #include "khmaps.h"
 
+void khmaps_init () {
+  VikMapsLayer_MapType map_type = { 8, 256, 256, VIK_VIEWPORT_DRAWMODE_KH, khmaps_coord_to_mapcoord, khmaps_mapcoord_to_center_coord, khmaps_download };
+
+  maps_layer_register_type("Old KH Satellite Images", 8, &map_type);
+}
+
 /* 1 << (x-1) is like a 2**(x-1) */
 #define KH(x) ((1<<(x-1)))
 
index 827b4074f562e5dc5668e2ca238c27b9269bbe1f..da348a1d35d9ba9f9e4fc0393f9f3532cd02fec6 100644 (file)
@@ -27,6 +27,8 @@
 #include "vikcoord.h"
 #include "mapcoord.h"
 
+void khmaps_init ();
+
 guint8 khmaps_zoom ( gdouble mpp );
 
 /* a bit misleading, this is the "mpp" (really just set zoom level, very
index 2331314ab983a4c876f5293070d0d2dc2bfde1d4..babcadc6b0cb9c9c043310c90379431d22572d51 100644 (file)
@@ -25,6 +25,8 @@
 
 #include <string.h>
 
+#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 ();
 
index 9f274350b0d65888632e31f4860a1dab9cc2ef77..36b71ecf572a508c722d74877ac62d4584cc9886 100644 (file)
@@ -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 (file)
index 0000000..2b56aef
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2006-2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * 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 (file)
index 0000000..f36fa55
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2006-2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * 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
index 9ddcb1af63728cda292abe65ae66520702267e1b..f50039c78d77f3f07e434ed7818a7bd99176aadb 100644 (file)
 #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
index b9434857e54676de223bd212d883158525f90ef3..c54f01df80c7bdace111e2b8848fbb130460c6df 100644 (file)
@@ -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 );
 
index aef7a9cb54cb7b591f2c22f1ed0574d765b38d5d..ef612e97003582aae2ce1582d0f66ecdcbee10fc 100644 (file)
@@ -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 )
index 543da016671e16ec05703db971919915dc311855..f08658aec4c8fcf86f200d9c4e6f607df514bfb9 100644 (file)
@@ -25,8 +25,8 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #include <gdk-pixbuf/gdk-pixdata.h>
-#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 {
index ad488a1e9a11cd0b65fd1beaa70842904c2a441d..eeb093b3ac582814f0f92515136da673e2c41dd0 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2005, Evan Battaglia <viking@greentorch.org>
  * UTM multi-zone stuff by Kit Transue <notlostyet@didactek.com>
+ * Dynamic map type by Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
  *
  * 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
 #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, &params_maptypes, sizeof(gpointer));
+  memcpy(&maps_layer_params[0].extra_widget_data, &params_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." );
index 3df9e9d1b8b16facee26c6db6cdfd4df5d3872a0..db157c02767bd398beb23843a664d0a562e62f0d 100644 (file)
 #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
index 5b17df5bbe46d91019dda7a3a9030343e5754c22..12d25d320a4814437f6995962f3befc7d0ed25f2 100644 (file)
@@ -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++;
   }
index 829407183f5b7b2f36796137742497917f117cb4..47f54d1c9b3870118652e65e519680ce02ff22c1 100644 (file)
@@ -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 );