Parent Directory | Revision Log
more map work
1 | harbaum | 33 | /* |
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 | harbaum | 34 | #include <math.h> // for isnan |
22 | harbaum | 33 | |
23 | #ifdef ENABLE_OSM_GPS_MAP | ||
24 | #include "osm-gps-map.h" | ||
25 | #endif | ||
26 | |||
27 | harbaum | 42 | /* equatorial radius in meters */ |
28 | #define EQ_RADIUS (6378137.0) | ||
29 | |||
30 | #define RAD2DEG(a) (((a)*180.0)/M_PI) | ||
31 | #define DEG2RAD(a) (((a)*M_PI)/180.0) | ||
32 | |||
33 | harbaum | 33 | typedef struct { |
34 | harbaum | 34 | appdata_t *appdata; |
35 | harbaum | 33 | GtkWidget *widget; |
36 | GtkWidget *zoomin, *zoomout, *gps; | ||
37 | gint handler_id; | ||
38 | harbaum | 42 | cache_t *press_on; |
39 | harbaum | 40 | #if MAEMO_VERSION_MAJOR == 5 |
40 | GtkWidget *old_view; | ||
41 | #endif | ||
42 | harbaum | 33 | } map_context_t; |
43 | |||
44 | harbaum | 34 | #define PROXY_KEY "/system/http_proxy/" |
45 | |||
46 | static const char *get_proxy_uri(appdata_t *appdata) { | ||
47 | static char proxy_buffer[64] = ""; | ||
48 | harbaum | 33 | |
49 | /* use environment settings if preset */ | ||
50 | const char *proxy = g_getenv("http_proxy"); | ||
51 | if(proxy) { | ||
52 | printf("http_proxy: %s\n", proxy); | ||
53 | return proxy; | ||
54 | } | ||
55 | |||
56 | harbaum | 34 | /* ------------- get proxy settings -------------------- */ |
57 | if(gconf_client_get_bool(appdata->gconf_client, | ||
58 | PROXY_KEY "use_http_proxy", NULL)) { | ||
59 | harbaum | 33 | |
60 | harbaum | 34 | /* we can savely ignore things like "ignore_hosts" since we */ |
61 | /* are pretty sure not inside the net of one of our map renderers */ | ||
62 | /* (unless the user works at google :-) */ | ||
63 | |||
64 | /* get basic settings */ | ||
65 | char *host = | ||
66 | gconf_client_get_string(appdata->gconf_client, PROXY_KEY "host", NULL); | ||
67 | if(host) { | ||
68 | int port = | ||
69 | gconf_client_get_int(appdata->gconf_client, PROXY_KEY "port", NULL); | ||
70 | harbaum | 33 | |
71 | harbaum | 34 | snprintf(proxy_buffer, sizeof(proxy_buffer), |
72 | "http://%s:%u", host, port); | ||
73 | harbaum | 33 | |
74 | harbaum | 34 | g_free(host); |
75 | } | ||
76 | harbaum | 35 | return proxy_buffer; |
77 | harbaum | 34 | } |
78 | |||
79 | harbaum | 35 | return NULL; |
80 | harbaum | 33 | } |
81 | |||
82 | static void map_zoom(map_context_t *context, int step) { | ||
83 | int zoom; | ||
84 | OsmGpsMap *map = OSM_GPS_MAP(context->widget); | ||
85 | g_object_get(map, "zoom", &zoom, NULL); | ||
86 | zoom = osm_gps_map_set_zoom(map, zoom+step); | ||
87 | |||
88 | /* enable/disable zoom buttons as required */ | ||
89 | gtk_widget_set_sensitive(context->zoomin, zoom<17); | ||
90 | gtk_widget_set_sensitive(context->zoomout, zoom>1); | ||
91 | } | ||
92 | |||
93 | static gboolean | ||
94 | cb_map_zoomin(GtkButton *button, map_context_t *context) { | ||
95 | map_zoom(context, +1); | ||
96 | return FALSE; | ||
97 | } | ||
98 | |||
99 | static gboolean | ||
100 | cb_map_zoomout(GtkButton *button, map_context_t *context) { | ||
101 | map_zoom(context, -1); | ||
102 | return FALSE; | ||
103 | } | ||
104 | |||
105 | static gboolean | ||
106 | cb_map_gps(GtkButton *button, map_context_t *context) { | ||
107 | harbaum | 34 | pos_t *refpos = get_pos(context->appdata); |
108 | if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) { | ||
109 | harbaum | 35 | osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), |
110 | refpos->lat, refpos->lon, 14); | ||
111 | } else { | ||
112 | /* no coordinates given: display the entire world */ | ||
113 | osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget), | ||
114 | 0.0, 0.0, 1); | ||
115 | harbaum | 34 | } |
116 | harbaum | 33 | |
117 | return FALSE; | ||
118 | } | ||
119 | |||
120 | static GtkWidget | ||
121 | *map_add_button(const gchar *icon, GCallback cb, gpointer data, | ||
122 | char *tooltip) { | ||
123 | GtkWidget *button = gtk_button_new(); | ||
124 | gtk_button_set_image(GTK_BUTTON(button), | ||
125 | gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU)); | ||
126 | g_signal_connect(button, "clicked", cb, data); | ||
127 | #ifndef USE_MAEMO | ||
128 | gtk_widget_set_tooltip_text(button, tooltip); | ||
129 | #endif | ||
130 | return button; | ||
131 | } | ||
132 | |||
133 | static gboolean map_gps_update(gpointer data) { | ||
134 | map_context_t *context = (map_context_t*)data; | ||
135 | |||
136 | harbaum | 34 | pos_t *refpos = get_pos(context->appdata); |
137 | gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon); | ||
138 | harbaum | 33 | |
139 | harbaum | 34 | /* get reference position and go there */ |
140 | gtk_widget_set_sensitive(context->gps, ok); | ||
141 | |||
142 | harbaum | 33 | return TRUE; |
143 | } | ||
144 | |||
145 | harbaum | 35 | static gboolean on_map_configure(GtkWidget *widget, |
146 | GdkEventConfigure *event, | ||
147 | map_context_t *context) { | ||
148 | harbaum | 33 | |
149 | harbaum | 35 | cb_map_gps(NULL, context); |
150 | |||
151 | return FALSE; | ||
152 | } | ||
153 | |||
154 | harbaum | 38 | static void map_draw_cachelist(GtkWidget *map, cache_t *cache) { |
155 | while(cache) { | ||
156 | GdkPixbuf *icon = icon_get(ICON_CACHE_TYPE, cache->type); | ||
157 | |||
158 | osm_gps_map_add_image(OSM_GPS_MAP(map), | ||
159 | cache->pos.lat, cache->pos.lon, icon); | ||
160 | |||
161 | cache = cache->next; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | harbaum | 41 | /* draw a nice popup */ |
166 | typedef struct { | ||
167 | appdata_t *appdata; | ||
168 | GtkWidget *window; | ||
169 | GMainLoop *loop; | ||
170 | } popup_context_t; | ||
171 | |||
172 | |||
173 | #ifndef USE_HILDON | ||
174 | #define POPUP_WIDTH 300 | ||
175 | #define POPUP_HEIGHT 100 | ||
176 | #else | ||
177 | #define POPUP_WIDTH 600 | ||
178 | #define POPUP_HEIGHT 200 | ||
179 | #endif | ||
180 | |||
181 | static gboolean | ||
182 | pointer_in_window(GtkWidget *widget, gint x_root, gint y_root) { | ||
183 | if(GTK_WIDGET_MAPPED(gtk_widget_get_toplevel(widget))) { | ||
184 | gint window_x, window_y; | ||
185 | |||
186 | gdk_window_get_position(gtk_widget_get_toplevel(widget)->window, | ||
187 | &window_x, &window_y); | ||
188 | |||
189 | if(x_root >= window_x && x_root < window_x + widget->allocation.width && | ||
190 | y_root >= window_y && y_root < window_y + widget->allocation.height) | ||
191 | return TRUE; | ||
192 | } | ||
193 | |||
194 | return FALSE; | ||
195 | } | ||
196 | |||
197 | static gboolean | ||
198 | on_button_press_event(GtkWidget *widget, | ||
199 | GdkEventButton *event, popup_context_t *context) { | ||
200 | gboolean in = pointer_in_window(widget, event->x_root, event->y_root); | ||
201 | |||
202 | printf("overlay button press(in = %d)\n", in); | ||
203 | return !in; | ||
204 | } | ||
205 | |||
206 | static gboolean | ||
207 | on_button_release_event(GtkWidget *widget, | ||
208 | GdkEventButton *event, popup_context_t *context) { | ||
209 | gboolean in = pointer_in_window(widget, event->x_root, event->y_root); | ||
210 | |||
211 | printf("overlay button release(in = %d)\n", in); | ||
212 | |||
213 | if(!in) { | ||
214 | printf("destroying popup\n"); | ||
215 | gtk_widget_destroy(gtk_widget_get_toplevel(widget)); | ||
216 | } | ||
217 | |||
218 | return !in; | ||
219 | } | ||
220 | |||
221 | static void | ||
222 | shutdown_loop(popup_context_t *context) { | ||
223 | if(g_main_loop_is_running(context->loop)) | ||
224 | g_main_loop_quit(context->loop); | ||
225 | } | ||
226 | |||
227 | static gint | ||
228 | run_delete_handler(GtkWindow *window, GdkEventAny *event, | ||
229 | popup_context_t *context) { | ||
230 | shutdown_loop(context); | ||
231 | return TRUE; /* Do not destroy */ | ||
232 | } | ||
233 | |||
234 | static void | ||
235 | run_destroy_handler(GtkWindow *window, popup_context_t *context) { | ||
236 | /* shutdown_loop will be called by run_unmap_handler */ | ||
237 | printf("popup destroyed\n"); | ||
238 | } | ||
239 | |||
240 | static void | ||
241 | run_unmap_handler(GtkWindow *window, popup_context_t *context) { | ||
242 | shutdown_loop(context); | ||
243 | } | ||
244 | |||
245 | harbaum | 42 | void cache_popup(map_context_t *mcontext, cache_t *cache) { |
246 | popup_context_t pcontext; | ||
247 | pcontext.appdata = mcontext->appdata; | ||
248 | harbaum | 41 | |
249 | harbaum | 42 | pcontext.window = gtk_window_new(GTK_WINDOW_POPUP); |
250 | gtk_widget_realize(pcontext.window); | ||
251 | gtk_window_set_default_size(GTK_WINDOW(pcontext.window), | ||
252 | harbaum | 41 | POPUP_WIDTH, POPUP_HEIGHT); |
253 | harbaum | 42 | gtk_window_resize(GTK_WINDOW(pcontext.window), |
254 | harbaum | 41 | POPUP_WIDTH, POPUP_HEIGHT); |
255 | harbaum | 42 | // gtk_window_set_resizable(GTK_WINDOW(pcontext.window), FALSE); |
256 | gtk_window_set_transient_for(GTK_WINDOW(pcontext.window), | ||
257 | GTK_WINDOW(mcontext->appdata->window)); | ||
258 | gtk_window_set_keep_above(GTK_WINDOW(pcontext.window), TRUE); | ||
259 | gtk_window_set_destroy_with_parent(GTK_WINDOW(pcontext.window), TRUE); | ||
260 | gtk_window_set_gravity(GTK_WINDOW(pcontext.window), GDK_GRAVITY_STATIC); | ||
261 | gtk_window_set_modal(GTK_WINDOW(pcontext.window), TRUE); | ||
262 | harbaum | 41 | |
263 | /* connect events */ | ||
264 | harbaum | 42 | g_signal_connect(G_OBJECT(pcontext.window), "button-press-event", |
265 | G_CALLBACK(on_button_press_event), &pcontext); | ||
266 | g_signal_connect(G_OBJECT(pcontext.window), "button-release-event", | ||
267 | G_CALLBACK(on_button_release_event), &pcontext); | ||
268 | g_signal_connect(G_OBJECT(pcontext.window), "delete-event", | ||
269 | G_CALLBACK(run_delete_handler), &pcontext); | ||
270 | g_signal_connect(G_OBJECT(pcontext.window), "destroy", | ||
271 | G_CALLBACK(run_destroy_handler), &pcontext); | ||
272 | g_signal_connect(G_OBJECT(pcontext.window), "unmap", | ||
273 | G_CALLBACK(run_unmap_handler), &pcontext); | ||
274 | harbaum | 41 | |
275 | harbaum | 42 | gdk_pointer_grab(pcontext.window->window, TRUE, |
276 | harbaum | 41 | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK, |
277 | NULL, NULL, GDK_CURRENT_TIME); | ||
278 | harbaum | 42 | gtk_grab_add(pcontext.window); |
279 | harbaum | 41 | |
280 | harbaum | 42 | /* check whether cache is in upper or lower half of window */ |
281 | gint x, y; | ||
282 | osm_gps_map_geographic_to_screen(OSM_GPS_MAP(mcontext->widget), | ||
283 | cache->pos.lat, cache->pos.lon, | ||
284 | &x, &y); | ||
285 | |||
286 | printf("screen pos %d/%d\n", x, y); | ||
287 | |||
288 | gdk_window_get_origin(mcontext->widget->window, &x, &y); | ||
289 | printf("window = %d/%d %d/%d\n", x, y, | ||
290 | mcontext->widget->allocation.x, | ||
291 | mcontext->widget->allocation.y); | ||
292 | |||
293 | // gtk_window_move(GTK_WINDOW(pcontext.window), | ||
294 | harbaum | 41 | // x + button->allocation.x, |
295 | // y + button->allocation.y - HEIGHT); | ||
296 | |||
297 | |||
298 | harbaum | 42 | gtk_window_move(GTK_WINDOW(pcontext.window), |
299 | harbaum | 41 | 100, |
300 | 100); | ||
301 | |||
302 | /* a frame with a vscale inside */ | ||
303 | GtkWidget *frame = gtk_frame_new(NULL); | ||
304 | gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT); | ||
305 | |||
306 | gtk_container_add(GTK_CONTAINER(frame), gtk_label_new(cache->name)); | ||
307 | harbaum | 42 | gtk_container_add(GTK_CONTAINER(pcontext.window), frame); |
308 | harbaum | 41 | |
309 | harbaum | 42 | gtk_widget_show_all(pcontext.window); |
310 | harbaum | 41 | |
311 | /* handle this popup until it's gone */ | ||
312 | |||
313 | harbaum | 42 | pcontext.loop = g_main_loop_new(NULL, FALSE); |
314 | harbaum | 41 | |
315 | GDK_THREADS_LEAVE(); | ||
316 | harbaum | 42 | g_main_loop_run(pcontext.loop); |
317 | harbaum | 41 | GDK_THREADS_ENTER(); |
318 | |||
319 | harbaum | 42 | g_main_loop_unref(pcontext.loop); |
320 | harbaum | 41 | |
321 | printf("cache popup removed\n"); | ||
322 | } | ||
323 | |||
324 | static void | ||
325 | map_cachelist_nearest(cache_t *cache, pos_t *pos, | ||
326 | cache_t **result, float *distance) { | ||
327 | while(cache) { | ||
328 | float dist = | ||
329 | pow(cache->pos.lat - pos->lat, 2) + | ||
330 | pow(cache->pos.lon - pos->lon, 2); | ||
331 | |||
332 | if(!(dist > *distance)) { | ||
333 | *result = cache; | ||
334 | *distance = dist; | ||
335 | } | ||
336 | |||
337 | cache = cache->next; | ||
338 | } | ||
339 | } | ||
340 | |||
341 | static cache_t *map_closest(map_context_t *context, pos_t *pos) { | ||
342 | cache_t *result = NULL; | ||
343 | float distance = NAN; | ||
344 | |||
345 | #ifdef USE_MAEMO | ||
346 | if(!context->appdata->cur_gpx) { | ||
347 | #endif | ||
348 | /* search all geocaches */ | ||
349 | gpx_t *gpx = context->appdata->gpx; | ||
350 | while(gpx) { | ||
351 | map_cachelist_nearest(gpx->cache, pos, &result, &distance); | ||
352 | gpx = gpx->next; | ||
353 | } | ||
354 | #ifdef USE_MAEMO | ||
355 | } else { | ||
356 | map_cachelist_nearest(context->appdata->cur_gpx->cache, | ||
357 | pos, &result, &distance); | ||
358 | } | ||
359 | #endif | ||
360 | |||
361 | return result; | ||
362 | } | ||
363 | |||
364 | /* translate between osm-gps-map positions and gpxview ones */ | ||
365 | pos_t coord2pos(coord_t coo) { | ||
366 | pos_t pos; | ||
367 | pos.lat = RAD2DEG(coo.rlat); | ||
368 | pos.lon = RAD2DEG(coo.rlon); | ||
369 | return pos; | ||
370 | } | ||
371 | |||
372 | harbaum | 42 | static int dist2pixel(map_context_t *context, float km, float lat) { |
373 | int zoom; | ||
374 | g_object_get(OSM_GPS_MAP(context->widget), "zoom", &zoom, NULL); | ||
375 | |||
376 | /* world at zoom 1 == 512 pixels */ | ||
377 | float m_per_pix = | ||
378 | cos(DEG2RAD(lat))*2*M_PI*EQ_RADIUS/(1<<(8+zoom)); | ||
379 | |||
380 | return 1000.0*km/m_per_pix; | ||
381 | } | ||
382 | |||
383 | #define CLICK_FUZZ (10) | ||
384 | |||
385 | harbaum | 41 | static gboolean |
386 | on_map_button_press_event(GtkWidget *widget, | ||
387 | GdkEventButton *event, map_context_t *context) { | ||
388 | OsmGpsMap *map = OSM_GPS_MAP(context->widget); | ||
389 | |||
390 | pos_t pos = | ||
391 | harbaum | 42 | coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); |
392 | harbaum | 41 | |
393 | harbaum | 42 | cache_t *nearest = map_closest(context, &pos); |
394 | if(nearest) { | ||
395 | float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); | ||
396 | if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { | ||
397 | context->press_on = nearest; | ||
398 | return TRUE; | ||
399 | } | ||
400 | } | ||
401 | harbaum | 41 | |
402 | harbaum | 42 | context->press_on = NULL; |
403 | harbaum | 41 | return FALSE; |
404 | } | ||
405 | |||
406 | static gboolean | ||
407 | on_map_button_release_event(GtkWidget *widget, | ||
408 | GdkEventButton *event, map_context_t *context) { | ||
409 | harbaum | 42 | if(context->press_on) { |
410 | OsmGpsMap *map = OSM_GPS_MAP(context->widget); | ||
411 | harbaum | 41 | |
412 | harbaum | 42 | pos_t pos = |
413 | coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y)); | ||
414 | harbaum | 41 | |
415 | harbaum | 42 | cache_t *nearest = map_closest(context, &pos); |
416 | if(nearest && nearest == context->press_on) { | ||
417 | float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE); | ||
418 | if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) { | ||
419 | |||
420 | cache_popup(context, nearest); | ||
421 | |||
422 | context->press_on = NULL; | ||
423 | return TRUE; | ||
424 | } | ||
425 | } | ||
426 | harbaum | 41 | } |
427 | |||
428 | harbaum | 42 | context->press_on = NULL; |
429 | harbaum | 41 | return FALSE; |
430 | } | ||
431 | |||
432 | harbaum | 40 | #if MAEMO_VERSION_MAJOR == 5 |
433 | static void on_window_destroy(GtkWidget *widget, map_context_t *context) { | ||
434 | printf("destroy map view\n"); | ||
435 | |||
436 | /* restore cur_view */ | ||
437 | context->appdata->cur_view = context->old_view; | ||
438 | |||
439 | gtk_timeout_remove(context->handler_id); | ||
440 | g_free(context); | ||
441 | } | ||
442 | #endif | ||
443 | |||
444 | harbaum | 33 | void map(appdata_t *appdata) { |
445 | harbaum | 40 | map_context_t *context = g_new0(map_context_t, 1); |
446 | context->appdata = appdata; | ||
447 | harbaum | 33 | |
448 | harbaum | 41 | GtkWidget *hbox = gtk_hbox_new(FALSE, 0); |
449 | |||
450 | char *path = g_strdup_printf("%s/map/", appdata->image_path); | ||
451 | const char *proxy = get_proxy_uri(appdata); | ||
452 | |||
453 | context->widget = g_object_new(OSM_TYPE_GPS_MAP, | ||
454 | "repo-uri", MAP_SOURCE_OPENSTREETMAP, | ||
455 | "tile-cache", path, | ||
456 | proxy?"proxy-uri":NULL, proxy, | ||
457 | NULL); | ||
458 | |||
459 | g_free(path); | ||
460 | |||
461 | char *name = NULL; | ||
462 | #ifdef USE_MAEMO | ||
463 | if(!appdata->cur_gpx) { | ||
464 | #endif | ||
465 | /* draw all geocaches */ | ||
466 | gpx_t *gpx = appdata->gpx; | ||
467 | while(gpx) { | ||
468 | map_draw_cachelist(context->widget, gpx->cache); | ||
469 | gpx = gpx->next; | ||
470 | } | ||
471 | name = g_strdup(_("all geocaches")); | ||
472 | #ifdef USE_MAEMO | ||
473 | } else { | ||
474 | map_draw_cachelist(context->widget, appdata->cur_gpx->cache); | ||
475 | name = g_strdup(_("appdata->cur_gpx->name")); | ||
476 | } | ||
477 | #endif | ||
478 | |||
479 | char *title = g_strdup_printf(_("Map - %s"), name); | ||
480 | g_free(name); | ||
481 | |||
482 | harbaum | 40 | #if MAEMO_VERSION_MAJOR == 5 |
483 | GtkWidget *window = hildon_stackable_window_new(); | ||
484 | harbaum | 41 | gtk_window_set_title(GTK_WINDOW(window), title); |
485 | harbaum | 40 | #else |
486 | harbaum | 41 | GtkWidget *dialog = gtk_dialog_new_with_buttons(title, |
487 | harbaum | 33 | GTK_WINDOW(appdata->window), |
488 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | ||
489 | GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | ||
490 | NULL); | ||
491 | |||
492 | #ifndef USE_MAEMO | ||
493 | gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 350); | ||
494 | #else | ||
495 | gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480); | ||
496 | #endif | ||
497 | harbaum | 40 | #endif |
498 | harbaum | 33 | |
499 | harbaum | 41 | g_free(title); |
500 | harbaum | 33 | |
501 | harbaum | 41 | g_signal_connect(G_OBJECT(context->widget), "configure-event", |
502 | G_CALLBACK(on_map_configure), context); | ||
503 | harbaum | 33 | |
504 | harbaum | 41 | g_signal_connect(G_OBJECT(context->widget), "button-press-event", |
505 | G_CALLBACK(on_map_button_press_event), context); | ||
506 | harbaum | 33 | |
507 | harbaum | 40 | g_signal_connect(G_OBJECT(context->widget), "button-release-event", |
508 | G_CALLBACK(on_map_button_release_event), context); | ||
509 | harbaum | 33 | |
510 | harbaum | 40 | gtk_box_pack_start_defaults(GTK_BOX(hbox), context->widget); |
511 | harbaum | 33 | /* zoom button box */ |
512 | GtkWidget *vbox = gtk_vbox_new(FALSE,0); | ||
513 | |||
514 | harbaum | 40 | context->zoomin = |
515 | harbaum | 33 | map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin), |
516 | harbaum | 40 | context, _("Zoom in")); |
517 | gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0); | ||
518 | harbaum | 33 | |
519 | harbaum | 40 | context->zoomout = |
520 | harbaum | 33 | map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout), |
521 | harbaum | 40 | context, _("Zoom out")); |
522 | gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0); | ||
523 | harbaum | 33 | |
524 | harbaum | 40 | context->gps = |
525 | harbaum | 33 | map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_gps), |
526 | harbaum | 40 | context, _("Jump to GPS position")); |
527 | gtk_widget_set_sensitive(context->gps, FALSE); | ||
528 | harbaum | 33 | /* install handler for timed updates of the gps button */ |
529 | harbaum | 40 | context->handler_id = gtk_timeout_add(1000, map_gps_update, context); |
530 | gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0); | ||
531 | harbaum | 33 | |
532 | gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0); | ||
533 | |||
534 | harbaum | 40 | #if MAEMO_VERSION_MAJOR == 5 |
535 | /* prevent some of the main screen things */ | ||
536 | context->old_view = appdata->cur_view; | ||
537 | appdata->cur_view = NULL; | ||
538 | |||
539 | g_signal_connect(G_OBJECT(window), "destroy", | ||
540 | G_CALLBACK(on_window_destroy), context); | ||
541 | |||
542 | gtk_container_add(GTK_CONTAINER(window), hbox); | ||
543 | gtk_widget_show_all(GTK_WIDGET(window)); | ||
544 | |||
545 | #else | ||
546 | harbaum | 33 | gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox); |
547 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE); | ||
548 | gtk_widget_show_all(dialog); | ||
549 | gtk_dialog_run(GTK_DIALOG(dialog)); | ||
550 | harbaum | 40 | gtk_timeout_remove(context->handler_id); |
551 | harbaum | 33 | gtk_widget_destroy(dialog); |
552 | harbaum | 40 | g_free(context); |
553 | #endif | ||
554 | harbaum | 33 | } |