Parent Directory | Revision Log
osm-gps-map integration
1 | /* |
2 | * Copyright (C) 2008 Till Harbaum <till@harbaum.org>. |
3 | * |
4 | * This file is part of GPXView. |
5 | * |
6 | * GPXView is free software: you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License as published by |
8 | * the Free Software Foundation, either version 3 of the License, or |
9 | * (at your option) any later version. |
10 | * |
11 | * GPXView is distributed in the hope that it will be useful, |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | * GNU General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU General Public License |
17 | * along with GPXView. If not, see <http://www.gnu.org/licenses/>. |
18 | */ |
19 | |
20 | #include "gpxview.h" |
21 | |
22 | #ifdef ENABLE_OSM_GPS_MAP |
23 | #include "osm-gps-map.h" |
24 | #endif |
25 | |
26 | typedef struct { |
27 | GtkWidget *widget; |
28 | GtkWidget *zoomin, *zoomout, *gps; |
29 | gint handler_id; |
30 | } map_context_t; |
31 | |
32 | static const char *get_proxy_uri(void) { |
33 | static char proxy_buffer[64]; |
34 | |
35 | /* use environment settings if preset */ |
36 | const char *proxy = g_getenv("http_proxy"); |
37 | if(proxy) { |
38 | printf("http_proxy: %s\n", proxy); |
39 | return proxy; |
40 | } |
41 | |
42 | #if 0 |
43 | /* otherwise try settings */ |
44 | if(!settings || !settings->proxy || |
45 | !settings->proxy->host) return NULL; |
46 | |
47 | snprintf(proxy_buffer, sizeof(proxy_buffer), "%s%s:%u", |
48 | strncmp(settings->proxy->host, "http://", 7)?"http://":"", |
49 | settings->proxy->host, settings->proxy->port); |
50 | |
51 | proxy_buffer[sizeof(proxy_buffer)-1] = 0; |
52 | printf("gconf_proxy: %s\n", proxy_buffer); |
53 | #endif |
54 | |
55 | return proxy_buffer; |
56 | } |
57 | |
58 | static void map_zoom(map_context_t *context, int step) { |
59 | int zoom; |
60 | OsmGpsMap *map = OSM_GPS_MAP(context->widget); |
61 | g_object_get(map, "zoom", &zoom, NULL); |
62 | zoom = osm_gps_map_set_zoom(map, zoom+step); |
63 | |
64 | /* enable/disable zoom buttons as required */ |
65 | gtk_widget_set_sensitive(context->zoomin, zoom<17); |
66 | gtk_widget_set_sensitive(context->zoomout, zoom>1); |
67 | } |
68 | |
69 | static gboolean |
70 | cb_map_zoomin(GtkButton *button, map_context_t *context) { |
71 | map_zoom(context, +1); |
72 | return FALSE; |
73 | } |
74 | |
75 | static gboolean |
76 | cb_map_zoomout(GtkButton *button, map_context_t *context) { |
77 | map_zoom(context, -1); |
78 | return FALSE; |
79 | } |
80 | |
81 | static gboolean |
82 | cb_map_gps(GtkButton *button, map_context_t *context) { |
83 | |
84 | // osm_gps_map_set_center(OSM_GPS_MAP(context->widget), |
85 | // DEG2RAD(pos.lat), DEG2RAD(pos.lon)); |
86 | |
87 | return FALSE; |
88 | } |
89 | |
90 | static GtkWidget |
91 | *map_add_button(const gchar *icon, GCallback cb, gpointer data, |
92 | char *tooltip) { |
93 | GtkWidget *button = gtk_button_new(); |
94 | gtk_button_set_image(GTK_BUTTON(button), |
95 | gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU)); |
96 | g_signal_connect(button, "clicked", cb, data); |
97 | #ifndef USE_MAEMO |
98 | gtk_widget_set_tooltip_text(button, tooltip); |
99 | #endif |
100 | return button; |
101 | } |
102 | |
103 | static gboolean map_gps_update(gpointer data) { |
104 | map_context_t *context = (map_context_t*)data; |
105 | |
106 | // gtk_widget_set_sensitive(context->map.gps, gps_fix); |
107 | |
108 | return TRUE; |
109 | } |
110 | |
111 | |
112 | void map(appdata_t *appdata) { |
113 | map_context_t context; |
114 | |
115 | GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Map"), |
116 | GTK_WINDOW(appdata->window), |
117 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, |
118 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, |
119 | NULL); |
120 | |
121 | #ifndef USE_MAEMO |
122 | gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 350); |
123 | #else |
124 | gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); |
125 | #endif |
126 | |
127 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
128 | |
129 | char *path = g_strdup_printf("%s/map/", appdata->image_path); |
130 | |
131 | context.widget = g_object_new(OSM_TYPE_GPS_MAP, |
132 | "repo-uri", MAP_SOURCE_OPENSTREETMAP, |
133 | "proxy-uri", get_proxy_uri(), |
134 | "tile-cache", path, |
135 | NULL); |
136 | |
137 | g_free(path); |
138 | |
139 | #if 0 |
140 | g_signal_connect(G_OBJECT(context.widget), "button-release-event", |
141 | G_CALLBACK(on_map_button_release_event), &context); |
142 | #endif |
143 | |
144 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context.widget); |
145 | /* zoom button box */ |
146 | GtkWidget *vbox = gtk_vbox_new(FALSE,0); |
147 | |
148 | context.zoomin = |
149 | map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
150 | &context, _("Zoom in")); |
151 | gtk_box_pack_start(GTK_BOX(vbox), context.zoomin, FALSE, FALSE, 0); |
152 | |
153 | context.zoomout = |
154 | map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
155 | &context, _("Zoom out")); |
156 | gtk_box_pack_start(GTK_BOX(vbox), context.zoomout, FALSE, FALSE, 0); |
157 | |
158 | context.gps = |
159 | map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_gps), |
160 | &context, _("Jump to GPS position")); |
161 | gtk_widget_set_sensitive(context.gps, FALSE); |
162 | /* install handler for timed updates of the gps button */ |
163 | context.handler_id = gtk_timeout_add(1000, map_gps_update, &context); |
164 | gtk_box_pack_start(GTK_BOX(vbox), context.gps, FALSE, FALSE, 0); |
165 | |
166 | gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); |
167 | |
168 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
169 | |
170 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); |
171 | |
172 | gtk_widget_show_all(dialog); |
173 | |
174 | gtk_dialog_run(GTK_DIALOG(dialog)); |
175 | |
176 | gtk_widget_destroy(dialog); |
177 | |
178 | } |