summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-20 17:02:21 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-01-20 17:07:07 -0800
commit980ba9cb509d74a59fdb1145028b13c1beab6e49 (patch)
tree82736391ef7cc8b1065fc542d106f5eacf1bed44
parent4ea90fcb0b7d64bccda5afa239d8e00567e8210f (diff)
downloadsubsurface-980ba9cb509d74a59fdb1145028b13c1beab6e49.tar.gz
Reuse map windows
Instead of opening a new window / new map for every dive site we now have only two windows / maps. One for the overview of all the dive sites, the other one that is used to show the map for a specific dive site. This also switches the position preference from CENTER to MOUSE - this way it's less likely that the two map windows will be drawn exactly on top of each other. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--gps.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/gps.c b/gps.c
index 87c8a99ea..0d7a666a9 100644
--- a/gps.c
+++ b/gps.c
@@ -19,7 +19,9 @@ static OsmGpsMapSource_t opt_map_provider = OSM_GPS_MAP_SOURCE_GOOGLE_STREET;
static void on_close (GtkWidget *widget, gpointer user_data)
{
+ GtkWidget **window = user_data;
gtk_widget_destroy(widget);
+ *window = NULL;
}
static void add_gps_point(OsmGpsMap *map, float latitude, float longitude)
@@ -62,43 +64,41 @@ OsmGpsMap *init_map()
return map;
}
-void show_map(OsmGpsMap *map)
+void show_map(OsmGpsMap *map, GtkWidget **window)
{
- GtkWidget *window;
-
- /* Enable keyboard navigation */
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_F11);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_UP, GDK_Up);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_DOWN, GDK_Down);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_LEFT, GDK_Left);
- osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_RIGHT, GDK_Right);
-
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
-
- gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
- gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
- gtk_window_set_title(GTK_WINDOW(window), _("Dives locations"));
- gtk_container_set_border_width(GTK_CONTAINER(window), 5);
- GTK_WINDOW(window)->allow_shrink = TRUE;
-
- gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(map));
-
- g_signal_connect (window, "destroy", G_CALLBACK (on_close), (gpointer) map);
-
- gtk_widget_show_all (window);
+ if (!*window) {
+ /* Enable keyboard navigation */
+ osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_F11);
+ osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_UP, GDK_Up);
+ osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_DOWN, GDK_Down);
+ osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_LEFT, GDK_Left);
+ osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_RIGHT, GDK_Right);
+
+ *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_position(GTK_WINDOW(*window), GTK_WIN_POS_MOUSE);
+ gtk_window_set_default_size(GTK_WINDOW(*window), 640, 480);
+ gtk_window_set_title(GTK_WINDOW(*window), _("Dives locations"));
+ gtk_container_set_border_width(GTK_CONTAINER(*window), 5);
+ GTK_WINDOW(*window)->allow_shrink = TRUE;
+ gtk_container_add(GTK_CONTAINER (*window), GTK_WIDGET(map));
+ g_signal_connect(*window, "destroy", G_CALLBACK (on_close), (gpointer)window);
+ }
+ gtk_widget_show_all(*window);
+ gtk_window_present(GTK_WINDOW(*window));
}
void show_gps_location(struct dive *dp)
{
- OsmGpsMap *map;
- GError *gerror = NULL;
+ static GtkWidget *window = NULL;
+ static OsmGpsMap *map = NULL;
GdkPixbuf *picture;
+ GError *gerror = NULL;
double lat = dp->latitude.udeg / 1000000.0;
double lng = dp->longitude.udeg / 1000000.0;
- map = init_map();
-
+ if (!map || !window)
+ map = init_map();
if (lat != 0 || lng != 0) {
add_gps_point(map, lat, lng);
osm_gps_map_set_center_and_zoom(map, lat, lng, 8);
@@ -108,20 +108,21 @@ void show_gps_location(struct dive *dp)
} else {
printf("error message: %s\n", gerror->message);
}
-
} else {
osm_gps_map_set_center_and_zoom(map, 0, 0, 2);
}
- show_map(map);
+ show_map(map, &window);
}
void show_gps_locations()
{
- OsmGpsMap *map;
+ static OsmGpsMap *map = NULL;
+ static GtkWidget *window = NULL;
struct dive *dp;
int idx;
- map = init_map();
+ if (!window || !map)
+ map = init_map();
for (idx = 0; idx < dive_table.nr; idx++) {
dp = dive_table.dives[idx];
@@ -132,5 +133,5 @@ void show_gps_locations()
}
osm_gps_map_set_center_and_zoom(map, 0, 0, 2);
- show_map(map);
+ show_map(map, &window);
}