summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-02-28 16:19:12 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-03-01 23:09:12 -0800
commitd1c394e51f7ab792650246dff74677609a9e7ea8 (patch)
treeed47932024d4f5c3420da9964081f7e40dcc9b14
parentb24d0f2f60fc8a7c0bbe2cf4ceac584f9ef24878 (diff)
downloadsubsurface-d1c394e51f7ab792650246dff74677609a9e7ea8.tar.gz
Make the map provider choice a preference
Not all of the providers seem to work for me (Yahoo Satellite doesn't appear to give me any data), but for now I'll leave most of them in. We can later decide to offer only some of them. It might be more fun to be able to pick the provider directly from the map widget. But for now I kept this in the preferences which seemed to be a good place for it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--gps.c8
-rw-r--r--gtk-gui.c48
-rw-r--r--main.c6
-rw-r--r--pref.h1
-rw-r--r--prefs.c17
5 files changed, 66 insertions, 14 deletions
diff --git a/gps.c b/gps.c
index 494eed52d..a3806dee8 100644
--- a/gps.c
+++ b/gps.c
@@ -17,12 +17,6 @@
static GtkWidget *window = NULL;
static OsmGpsMap *map = NULL;
-/* Several map providers are available, such as OSM_GPS_MAP_SOURCE_OPENSTREETMAP
- and OSM_GPS_MAP_SOURCE_GOOGLE_STREET. We should make more of
- them available from e.g. a pull-down menu */
-static OsmGpsMapSource_t opt_map_provider = OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID;
-
-
static void on_close(GtkWidget *widget, gpointer user_data)
{
GtkWidget **window = user_data;
@@ -168,7 +162,7 @@ OsmGpsMap *init_map(void)
cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO);
map = g_object_new(OSM_TYPE_GPS_MAP,
- "map-source", opt_map_provider,
+ "map-source", prefs.map_provider,
"tile-cache", cachedir,
"tile-cache-base", cachebasedir,
"proxy-uri", g_getenv("http_proxy"),
diff --git a/gtk-gui.c b/gtk-gui.c
index 0e7b6da8a..0bce10c17 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -29,6 +29,10 @@
#include <gdk-pixbuf/gdk-pixdata.h>
#include "subsurface-icon.h"
+#if HAVE_OSM_GPS_MAP
+#include <osm-gps-map-source.h>
+#endif
+
GtkWidget *main_window;
GtkWidget *main_vbox;
GtkWidget *error_info_bar;
@@ -639,10 +643,27 @@ static void pick_default_file(GtkWidget *w, GtkButton *button)
gtk_widget_set_sensitive(parent, TRUE);
}
+#if HAVE_OSM_GPS_MAP
+static GtkWidget * map_provider_widget()
+{
+ OsmGpsMapSource_t i;
+ GtkWidget *combobox = gtk_combo_box_text_new();
+
+ /* several of the providers seem to be redundant or non-functional;
+ * we may have to skip more than just the last three eventually */
+ for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i < OSM_GPS_MAP_SOURCE_LAST; i++)
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combobox), osm_gps_map_source_get_friendly_name(i));
+ /* we don't offer choice 0 (none), so the index here is off by one */
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combobox), prefs.map_provider - 1);
+ return combobox;
+}
+#endif
+
static void preferences_dialog(GtkWidget *w, gpointer data)
{
int result;
- GtkWidget *dialog, *notebook, *font, *frame, *box, *vbox, *button, *xmlfile_button;
+ GtkWidget *dialog, *notebook, *font, *frame, *box, *hbox, *vbox, *button;
+ GtkWidget *xmlfile_button, *map_provider;
GtkWidget *entry_po2, *entry_pn2, *entry_phe, *entry_mod, *entry_gflow, *entry_gfhigh;
const char *current_default, *new_default;
char threshold_text[10], mod_text[10], utf8_buf[128];
@@ -745,14 +766,19 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
frame = gtk_frame_new(_("Default XML Data File"));
gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5);
- box = gtk_hbox_new(FALSE, 6);
- gtk_container_add(GTK_CONTAINER(frame), box);
+ hbox = gtk_hbox_new(FALSE, 6);
+ gtk_container_add(GTK_CONTAINER(frame), hbox);
current_default = prefs.default_filename;
xmlfile_button = gtk_button_new_with_label(current_default);
g_signal_connect(G_OBJECT(xmlfile_button), "clicked",
G_CALLBACK(pick_default_file), xmlfile_button);
- gtk_box_pack_start(GTK_BOX(box), xmlfile_button, FALSE, FALSE, 6);
-
+ gtk_box_pack_start(GTK_BOX(hbox), xmlfile_button, FALSE, FALSE, 6);
+#if HAVE_OSM_GPS_MAP
+ frame = gtk_frame_new(_("Map provider"));
+ map_provider = map_provider_widget();
+ gtk_container_add(GTK_CONTAINER(frame), map_provider);
+ gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
+#endif
/* vbox that holds the second notebook page */
vbox = gtk_vbox_new(FALSE, 6);
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
@@ -940,11 +966,19 @@ static void preferences_dialog(GtkWidget *w, gpointer data)
existing_filename = strdup(new_default);
}
}
-
if (strcmp(current_default, new_default)) {
prefs.default_filename = new_default;
}
-
+#if HAVE_OSM_GPS_MAP
+ /* get the map provider selected */
+ OsmGpsMapSource_t i;
+ char *provider = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(map_provider));
+ for (i = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; i <= OSM_GPS_MAP_SOURCE_YAHOO_STREET; i++)
+ if (!strcmp(provider,osm_gps_map_source_get_friendly_name(i))) {
+ prefs.map_provider = i;
+ break;
+ }
+#endif
save_preferences();
} else if (result == GTK_RESPONSE_CANCEL) {
prefs = oldprefs;
diff --git a/main.c b/main.c
index fd5c78e82..3b6e00449 100644
--- a/main.c
+++ b/main.c
@@ -10,6 +10,9 @@
#include "dive.h"
#include "divelist.h"
+#if HAVE_OSM_GPS_MAP
+#include <osm-gps-map.h>
+#endif
#ifdef DEBUGFILE
char *debugfilename;
FILE *debugfile;
@@ -35,6 +38,9 @@ struct preferences default_prefs = {
.calc_ceiling_3m_incr = FALSE,
.gflow = 0.30,
.gfhigh = 0.75,
+#if HAVE_OSM_GPS_MAP
+ .map_provider = OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID,
+#endif
};
/* random helper functions, used here or elsewhere */
diff --git a/pref.h b/pref.h
index c4287aa3b..60fe1104c 100644
--- a/pref.h
+++ b/pref.h
@@ -33,6 +33,7 @@ struct preferences {
gboolean calc_ceiling_3m_incr;
double gflow;
double gfhigh;
+ int map_provider;
const char *divelist_font;
const char *default_filename;
};
diff --git a/prefs.c b/prefs.c
index 7c833116f..7d41c0cf6 100644
--- a/prefs.c
+++ b/prefs.c
@@ -60,8 +60,18 @@ static void save_double_conf(char *name, double _val, double _def)
subsurface_set_conf(name, string);
}
+static void save_int_conf(char *name, int value, int def)
+{
+ if (value == def) {
+ subsurface_unset_conf(name);
+ return;
+ }
+ subsurface_set_conf_int(name, value);
+}
+
#define SAVE_DOUBLE(name, field) save_double_conf(name, prefs.field, default_prefs.field)
#define SAVE_PERCENT(name, field) save_double_conf(name, prefs.field*100, default_prefs.field*100)
+#define SAVE_INT(name, field) save_int_conf(name, prefs.field, default_prefs.field)
void save_preferences(void)
{
@@ -102,6 +112,8 @@ void save_preferences(void)
SAVE_STRING("default_filename", default_filename);
+ SAVE_INT("map_provider", map_provider);
+
/* Flush the changes out to the system */
subsurface_flush_conf();
}
@@ -122,6 +134,7 @@ static gboolean get_bool(char *name, gboolean def)
void load_preferences(void)
{
const char *conf_value;
+ int int_value;
GET_UNIT("feet", length, METERS, FEET);
GET_UNIT("psi", pressure, BAR, PSI);
@@ -189,4 +202,8 @@ void load_preferences(void)
conf_value = subsurface_get_conf("default_filename");
if (conf_value)
prefs.default_filename = conf_value;
+
+ int_value = subsurface_get_conf_int("map_provider");
+ if(int_value >= 0)
+ prefs.map_provider = int_value;
}