Diff of /trunk/src/map-tool.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 41 by harbaum, Mon Aug 3 14:21:57 2009 UTC revision 57 by harbaum, Sun Aug 16 19:29:01 2009 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.   * Copyright (C) 2008-2009 Till Harbaum <till@harbaum.org>.
3   *   *
4   * This file is part of GPXView.   * This file is part of GPXView.
5   *   *
# Line 24  Line 24 
24  #include "osm-gps-map.h"  #include "osm-gps-map.h"
25  #endif  #endif
26    
27  typedef struct {  #define MAP_SOURCE  OSM_GPS_MAP_SOURCE_OPENSTREETMAP
28    appdata_t *appdata;  #define GPS_DEFAULT_ZOOM 13
29    GtkWidget *widget;  
30    GtkWidget *zoomin, *zoomout, *gps;  /* equatorial radius in meters */
31    gint handler_id;  #define EQ_RADIUS     (6378137.0)
32  #if MAEMO_VERSION_MAJOR == 5  
33    GtkWidget *old_view;  #define RAD2DEG(a)  (((a)*180.0)/M_PI)
34  #endif  #define DEG2RAD(a)  (((a)*M_PI)/180.0)
 } map_context_t;  
35    
36  #define PROXY_KEY  "/system/http_proxy/"  #define PROXY_KEY  "/system/http_proxy/"
37    
# Line 73  static const char *get_proxy_uri(appdata Line 72  static const char *get_proxy_uri(appdata
72  }  }
73    
74  static void map_zoom(map_context_t *context, int step) {  static void map_zoom(map_context_t *context, int step) {
75    int zoom;    gint zoom;
76    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
77    g_object_get(map, "zoom", &zoom, NULL);    g_object_get(map, "zoom", &zoom, NULL);
78    zoom = osm_gps_map_set_zoom(map, zoom+step);    zoom = osm_gps_map_set_zoom(map, zoom+step);
79    
80    /* enable/disable zoom buttons as required */    /* enable/disable zoom buttons as required */
81    gtk_widget_set_sensitive(context->zoomin, zoom<17);    gtk_widget_set_sensitive(context->zoomin,
82    gtk_widget_set_sensitive(context->zoomout, zoom>1);             zoom < osm_gps_map_source_get_max_zoom(MAP_SOURCE));
83      gtk_widget_set_sensitive(context->zoomout,
84               zoom > osm_gps_map_source_get_min_zoom(MAP_SOURCE));
85    
86      /* hmm ... this doesn't really work */
87      osm_gps_map_osd_speed(map, zoom);
88    
89      /* save new zoom */
90      context->appdata->map.zoom = zoom;
91  }  }
92    
93  static gboolean  static gboolean
# Line 100  cb_map_gps(GtkButton *button, map_contex Line 107  cb_map_gps(GtkButton *button, map_contex
107    pos_t *refpos = get_pos(context->appdata);    pos_t *refpos = get_pos(context->appdata);
108    if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {    if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
109      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
110                                refpos->lat, refpos->lon, 14);                        refpos->lat, refpos->lon, GPS_DEFAULT_ZOOM);
111    } else {    } else {
112      /* no coordinates given: display the entire world */      /* no coordinates given: display the entire world */
113      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
# Line 111  cb_map_gps(GtkButton *button, map_contex Line 118  cb_map_gps(GtkButton *button, map_contex
118  }  }
119    
120  static GtkWidget  static GtkWidget
121  *map_add_button(const gchar *icon, GCallback cb, gpointer data,  *map_add_button(int icon, GCallback cb, gpointer data,
122                  char *tooltip) {                  char *tooltip) {
123    GtkWidget *button = gtk_button_new();    GtkWidget *button = gtk_button_new();
124    gtk_button_set_image(GTK_BUTTON(button),    gtk_button_set_image(GTK_BUTTON(button), icon_get_widget(ICON_MISC, icon));
                        gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU));  
125    g_signal_connect(button, "clicked", cb, data);    g_signal_connect(button, "clicked", cb, data);
126  #ifndef USE_MAEMO  #ifndef USE_MAEMO
127    gtk_widget_set_tooltip_text(button, tooltip);    gtk_widget_set_tooltip_text(button, tooltip);
# Line 123  static GtkWidget Line 129  static GtkWidget
129    return button;    return button;
130  }  }
131    
132    static int dist2pixel(map_context_t *context, float km, float lat) {
133      return 1000.0*km/osm_gps_map_get_scale(OSM_GPS_MAP(context->widget));
134    }
135    
136  static gboolean map_gps_update(gpointer data) {  static gboolean map_gps_update(gpointer data) {
137    map_context_t *context = (map_context_t*)data;    map_context_t *context = (map_context_t*)data;
138    
139      /* get reference position ... */
140    pos_t *refpos = get_pos(context->appdata);    pos_t *refpos = get_pos(context->appdata);
141    gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);    gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);
142    
143    /* get reference position and go there */    /* ... and enable "goto" button if it's valid */
144    gtk_widget_set_sensitive(context->gps, ok);    gtk_widget_set_sensitive(context->gps, ok);
145    
146      if(ok) {
147        float heading = NAN;
148        int radius = 0;
149    
150        if(context->appdata->use_gps) {
151          heading = gps_get_heading(context->appdata);
152    
153          /* get error */
154          float eph = gps_get_eph(context->appdata);
155          if(!isnan(eph))
156            radius = dist2pixel(context, eph/1000, refpos->lat);
157        }
158    
159        g_object_set(context->widget, "gps-track-highlight-radius", radius, NULL);
160        osm_gps_map_draw_gps(OSM_GPS_MAP(context->widget),
161                             refpos->lat, refpos->lon, heading);
162      } else
163        osm_gps_map_clear_gps(OSM_GPS_MAP(context->widget));
164    
165    return TRUE;    return TRUE;
166  }  }
167    
# Line 139  static gboolean on_map_configure(GtkWidg Line 169  static gboolean on_map_configure(GtkWidg
169                                   GdkEventConfigure *event,                                   GdkEventConfigure *event,
170                                   map_context_t *context) {                                   map_context_t *context) {
171    
172    cb_map_gps(NULL, context);    /* set default values if they are invalid */
173      if(!context->appdata->map.zoom ||
174         isnan(context->appdata->map.pos.lat) ||
175         isnan(context->appdata->map.pos.lon)) {
176        printf("no valid map position found\n");
177    
178        pos_t *refpos = get_pos(context->appdata);
179        if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
180          /* use gps position if present */
181          context->appdata->map.pos = *refpos;
182          context->appdata->map.zoom = GPS_DEFAULT_ZOOM;
183        } else {
184          /* use world map otherwise */
185          context->appdata->map.pos.lat = 0.0;
186          context->appdata->map.pos.lon = 0.0;
187          context->appdata->map.zoom = 1;
188        }
189      }
190    
191      /* jump to initial position */
192      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
193                                context->appdata->map.pos.lat,
194                                context->appdata->map.pos.lon,
195                                context->appdata->map.zoom);
196    
197    return FALSE;    return FALSE;
198  }  }
199    
# Line 155  static void map_draw_cachelist(GtkWidget Line 208  static void map_draw_cachelist(GtkWidget
208    }    }
209  }  }
210    
 /* draw a nice popup */  
 typedef struct {  
   appdata_t *appdata;  
   GtkWidget *window;  
   GMainLoop *loop;  
 } popup_context_t;  
   
   
 #ifndef USE_HILDON  
 #define POPUP_WIDTH  300  
 #define POPUP_HEIGHT 100  
 #else  
 #define POPUP_WIDTH  600  
 #define POPUP_HEIGHT 200  
 #endif  
   
 static gboolean  
 pointer_in_window(GtkWidget *widget, gint x_root, gint y_root) {  
   if(GTK_WIDGET_MAPPED(gtk_widget_get_toplevel(widget))) {  
     gint window_x, window_y;  
   
     gdk_window_get_position(gtk_widget_get_toplevel(widget)->window,  
                             &window_x, &window_y);  
   
     if(x_root >= window_x && x_root < window_x + widget->allocation.width &&  
         y_root >= window_y && y_root < window_y + widget->allocation.height)  
       return TRUE;  
   }  
   
   return FALSE;  
 }  
   
 static gboolean  
 on_button_press_event(GtkWidget *widget,  
                           GdkEventButton *event, popup_context_t *context) {  
   gboolean in = pointer_in_window(widget, event->x_root, event->y_root);  
   
   printf("overlay button press(in = %d)\n", in);  
   return !in;  
 }  
   
 static gboolean  
 on_button_release_event(GtkWidget *widget,  
                           GdkEventButton *event, popup_context_t *context) {  
   gboolean in = pointer_in_window(widget, event->x_root, event->y_root);  
   
   printf("overlay button release(in = %d)\n", in);  
   
   if(!in) {  
     printf("destroying popup\n");  
     gtk_widget_destroy(gtk_widget_get_toplevel(widget));  
   }  
   
   return !in;  
 }  
   
 static void  
 shutdown_loop(popup_context_t *context) {  
   if(g_main_loop_is_running(context->loop))  
     g_main_loop_quit(context->loop);  
 }  
   
 static gint  
 run_delete_handler(GtkWindow *window, GdkEventAny *event,  
                    popup_context_t *context) {  
   shutdown_loop(context);  
   return TRUE; /* Do not destroy */  
 }  
   
 static void  
 run_destroy_handler(GtkWindow *window, popup_context_t *context) {  
   /* shutdown_loop will be called by run_unmap_handler */  
   printf("popup destroyed\n");  
 }  
   
 static void  
 run_unmap_handler(GtkWindow *window, popup_context_t *context) {  
   shutdown_loop(context);  
 }  
   
 void cache_popup(appdata_t *appdata, cache_t *cache) {  
   popup_context_t context;  
   context.appdata = appdata;  
   
   context.window = gtk_window_new(GTK_WINDOW_POPUP);  
   gtk_widget_realize(context.window);  
   gtk_window_set_default_size(GTK_WINDOW(context.window),  
                               POPUP_WIDTH, POPUP_HEIGHT);  
   gtk_window_resize(GTK_WINDOW(context.window),  
                     POPUP_WIDTH, POPUP_HEIGHT);  
   //  gtk_window_set_resizable(GTK_WINDOW(context.window), FALSE);  
   gtk_window_set_transient_for(GTK_WINDOW(context.window),  
                                GTK_WINDOW(appdata->window));  
   gtk_window_set_keep_above(GTK_WINDOW(context.window), TRUE);  
   gtk_window_set_destroy_with_parent(GTK_WINDOW(context.window), TRUE);  
   gtk_window_set_gravity(GTK_WINDOW(context.window), GDK_GRAVITY_STATIC);  
   gtk_window_set_modal(GTK_WINDOW(context.window), TRUE);  
   
   /* connect events */  
   g_signal_connect(G_OBJECT(context.window), "button-press-event",  
                    G_CALLBACK(on_button_press_event), &context);  
   g_signal_connect(G_OBJECT(context.window), "button-release-event",  
                    G_CALLBACK(on_button_release_event), &context);  
   g_signal_connect(G_OBJECT(context.window), "delete-event",  
                    G_CALLBACK(run_delete_handler), &context);  
   g_signal_connect(G_OBJECT(context.window), "destroy",  
                    G_CALLBACK(run_destroy_handler), &context);  
   g_signal_connect(G_OBJECT(context.window), "unmap",  
                    G_CALLBACK(run_unmap_handler), &context);  
   
   gdk_pointer_grab(context.window->window, TRUE,  
      GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK,  
                    NULL, NULL, GDK_CURRENT_TIME);  
   gtk_grab_add(context.window);  
   
   //  gint x, y;  
   //  gdk_window_get_origin(button->window, &x, &y);  
   
   //  gtk_window_move(GTK_WINDOW(context.window),  
   //              x + button->allocation.x,  
   //              y + button->allocation.y - HEIGHT);  
   
   
   gtk_window_move(GTK_WINDOW(context.window),  
                   100,  
                   100);  
   
   /* a frame with a vscale inside */  
   GtkWidget *frame = gtk_frame_new(NULL);  
   gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_OUT);  
   
   gtk_container_add(GTK_CONTAINER(frame), gtk_label_new(cache->name));  
   gtk_container_add(GTK_CONTAINER(context.window), frame);  
   
   gtk_widget_show_all(context.window);  
   
   /* handle this popup until it's gone */  
   
   context.loop = g_main_loop_new(NULL, FALSE);  
   
   GDK_THREADS_LEAVE();  
   g_main_loop_run(context.loop);  
   GDK_THREADS_ENTER();  
   
   g_main_loop_unref(context.loop);  
   
   printf("cache popup removed\n");  
 }  
   
 #define RAD2DEG(a)  (((a)*180.0)/M_PI)  
   
211  static void  static void
212  map_cachelist_nearest(cache_t *cache, pos_t *pos,  map_cachelist_nearest(cache_t *cache, pos_t *pos,
213                        cache_t **result, float *distance) {                        cache_t **result, float *distance) {
# Line 354  pos_t coord2pos(coord_t coo) { Line 256  pos_t coord2pos(coord_t coo) {
256    return pos;    return pos;
257  }  }
258    
259    #define CLICK_FUZZ (24)
260    
261  static gboolean  static gboolean
262  on_map_button_press_event(GtkWidget *widget,  on_map_button_press_event(GtkWidget *widget,
263                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
264    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
265    
266    pos_t pos =    /* got a press event without release event? eat it! */
267      coord2pos(osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y));    if(context->press_on != NULL) {
268        printf("PRESS: already\n");
269        return TRUE;
270      }
271    
272    printf("clicked at %f/%f\n", pos.lat, pos.lon);    pos_t pos =
273        coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y));
274    
275      cache_t *nearest = map_closest(context, &pos);
276      if(nearest) {
277        float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
278        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ)
279          context->press_on = nearest;
280      }
281    
282    return FALSE;    return FALSE;
283  }  }
284    
# Line 372  on_map_button_release_event(GtkWidget *w Line 287  on_map_button_release_event(GtkWidget *w
287                              GdkEventButton *event, map_context_t *context) {                              GdkEventButton *event, map_context_t *context) {
288    OsmGpsMap *map = OSM_GPS_MAP(context->widget);    OsmGpsMap *map = OSM_GPS_MAP(context->widget);
289    
290    pos_t pos =    if(context->press_on) {
291      coord2pos(osm_gps_map_get_co_ordinates(map, (int)event->x, (int)event->y));      coord_t coo;
292        coo = osm_gps_map_get_co_ordinates(map, event->x, event->y);
293    printf("released at %f/%f\n", pos.lat, pos.lon);  
294        pos_t pos =
295    /* return true if we clicked a cache */        coord2pos(osm_gps_map_get_co_ordinates(map, event->x, event->y));
296    /* ... */  
297        cache_t *nearest = map_closest(context, &pos);
298    cache_t *nearest = map_closest(context, &pos);      if(nearest && nearest == context->press_on) {
299          float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);
300    if(nearest) {        if(dist2pixel(context, dist, nearest->pos.lat) < CLICK_FUZZ) {
301      float dist = gpx_pos_get_distance(pos, nearest->pos, FALSE);  
302            osm_gps_map_draw_balloon(map, nearest->pos.lat, nearest->pos.lon);
303      printf("nearest = %s, distance = %fkm\n", nearest->name, dist);        }
304        }
305      cache_popup(context->appdata, nearest);      context->press_on = NULL;
306      } else {
307      return TRUE;      /* save new map position */
308        gfloat lat, lon;
309        g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
310        context->appdata->map.pos.lat = lat;
311        context->appdata->map.pos.lon = lon;
312    }    }
313    
314    return FALSE;    return FALSE;
315  }  }
316    
 #if MAEMO_VERSION_MAJOR == 5  
317  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {  static void on_window_destroy(GtkWidget *widget, map_context_t *context) {
318    printf("destroy map view\n");    appdata_t *appdata = context->appdata;
319    
320      printf("destroy map window\n");
321    
322      /* save map parameters */
323      OsmGpsMap *map = OSM_GPS_MAP(context->widget);
324      gint zoom;
325      g_object_get(map, "zoom", &zoom, NULL);
326      context->appdata->map.zoom = zoom;
327    
328      gfloat lat, lon;
329      g_object_get(map, "latitude", &lat, "longitude", &lon, NULL);
330      context->appdata->map.pos.lat = lat;
331      context->appdata->map.pos.lon = lon;
332    
333    #if MAEMO_VERSION_MAJOR == 5
334    /* restore cur_view */    /* restore cur_view */
335    context->appdata->cur_view = context->old_view;    context->appdata->cur_view = context->old_view;
336    #endif
337    
338    gtk_timeout_remove(context->handler_id);    gtk_timeout_remove(context->handler_id);
339    
340    g_free(context);    g_free(context);
341      appdata->map.context = NULL;
342  }  }
 #endif  
343    
344  void map(appdata_t *appdata) {  void map(appdata_t *appdata) {
345    map_context_t *context = g_new0(map_context_t, 1);    map_context_t *context = NULL;
346    
347      /* if the map window already exists, just raise it */
348      if(appdata->map.context) {
349        gtk_window_present(GTK_WINDOW(appdata->map.context->window));
350        return;
351      }
352    
353      context = appdata->map.context = g_new0(map_context_t, 1);
354    context->appdata = appdata;    context->appdata = appdata;
355    
356    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
# Line 417  void map(appdata_t *appdata) { Line 359  void map(appdata_t *appdata) {
359    const char *proxy = get_proxy_uri(appdata);    const char *proxy = get_proxy_uri(appdata);
360    
361    context->widget = g_object_new(OSM_TYPE_GPS_MAP,    context->widget = g_object_new(OSM_TYPE_GPS_MAP,
362                  "repo-uri", MAP_SOURCE_OPENSTREETMAP,                   "map-source",               MAP_SOURCE,
363                  "tile-cache", path,                   "tile-cache",               path,
364                  proxy?"proxy-uri":NULL, proxy,                   "auto-center",              FALSE,
365                     "record-trip-history",      FALSE,
366                     "show-trip-history",        FALSE,
367                     proxy?"proxy-uri":NULL,     proxy,
368                   NULL);                   NULL);
369    
370    g_free(path);    g_free(path);
# Line 438  void map(appdata_t *appdata) { Line 383  void map(appdata_t *appdata) {
383  #ifdef USE_MAEMO  #ifdef USE_MAEMO
384    } else {    } else {
385      map_draw_cachelist(context->widget, appdata->cur_gpx->cache);      map_draw_cachelist(context->widget, appdata->cur_gpx->cache);
386      name = g_strdup(_("appdata->cur_gpx->name"));      name = g_strdup(appdata->cur_gpx->name);
387    }    }
388  #endif  #endif
389    
390    char *title = g_strdup_printf(_("Map - %s"), name);    char *title = g_strdup_printf(_("Map - %s"), name);
391    g_free(name);    g_free(name);
392    
393  #if MAEMO_VERSION_MAJOR == 5  #ifdef USE_MAEMO
394    GtkWidget *window = hildon_stackable_window_new();  #ifdef USE_STACKABLE_WINDOW
395    gtk_window_set_title(GTK_WINDOW(window), title);    context->window = hildon_stackable_window_new();
396  #else  #else
397    GtkWidget *dialog = gtk_dialog_new_with_buttons(title,    context->window = hildon_window_new();
398                            GTK_WINDOW(appdata->window),  #endif
                           GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,  
                           GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,  
                           NULL);  
   
 #ifndef USE_MAEMO  
   gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 350);  
399  #else  #else
400    gtk_window_set_default_size(GTK_WINDOW(dialog), 800, 480);    context->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
401  #endif  #endif
402    
403      gtk_window_set_title(GTK_WINDOW(context->window), title);
404    
405    #ifndef USE_MAEMO
406      gtk_window_set_default_size(GTK_WINDOW(context->window), 640, 480);
407  #endif  #endif
408    
409    g_free(title);    g_free(title);
# Line 478  void map(appdata_t *appdata) { Line 422  void map(appdata_t *appdata) {
422    GtkWidget *vbox = gtk_vbox_new(FALSE,0);    GtkWidget *vbox = gtk_vbox_new(FALSE,0);
423    
424    context->zoomin =    context->zoomin =
425      map_add_button(GTK_STOCK_ZOOM_IN, G_CALLBACK(cb_map_zoomin),      map_add_button(10, G_CALLBACK(cb_map_zoomin),
426                     context, _("Zoom in"));                     context, _("Zoom in"));
427    gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(vbox), context->zoomin, FALSE, FALSE, 0);
428    
429    context->zoomout =    context->zoomout =
430      map_add_button(GTK_STOCK_ZOOM_OUT, G_CALLBACK(cb_map_zoomout),      map_add_button(11, G_CALLBACK(cb_map_zoomout),
431                     context, _("Zoom out"));                     context, _("Zoom out"));
432    gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(vbox), context->zoomout, FALSE, FALSE, 0);
433    
434    context->gps =    context->gps =
435      map_add_button(GTK_STOCK_HOME, G_CALLBACK(cb_map_gps),      map_add_button(9, G_CALLBACK(cb_map_gps),
436                     context, _("Jump to GPS position"));                     context, _("Jump to GPS position"));
437    gtk_widget_set_sensitive(context->gps, FALSE);    gtk_widget_set_sensitive(context->gps, FALSE);
438    
439    /* install handler for timed updates of the gps button */    /* install handler for timed updates of the gps button */
440    context->handler_id = gtk_timeout_add(1000, map_gps_update, context);    context->handler_id = gtk_timeout_add(1000, map_gps_update, context);
441    gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0);    gtk_box_pack_start(GTK_BOX(vbox), context->gps, FALSE, FALSE, 0);
# Line 501  void map(appdata_t *appdata) { Line 446  void map(appdata_t *appdata) {
446    /* prevent some of the main screen things */    /* prevent some of the main screen things */
447    context->old_view = appdata->cur_view;    context->old_view = appdata->cur_view;
448    appdata->cur_view = NULL;    appdata->cur_view = NULL;
449    #endif
450    
451    g_signal_connect(G_OBJECT(window), "destroy",    g_signal_connect(G_OBJECT(context->window), "destroy",
452                     G_CALLBACK(on_window_destroy), context);                     G_CALLBACK(on_window_destroy), context);
453    
454    gtk_container_add(GTK_CONTAINER(window), hbox);    gtk_container_add(GTK_CONTAINER(context->window), hbox);
455    gtk_widget_show_all(GTK_WIDGET(window));    gtk_widget_show_all(GTK_WIDGET(context->window));
   
 #else  
   gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox);  
   gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE);  
   gtk_widget_show_all(dialog);  
   gtk_dialog_run(GTK_DIALOG(dialog));  
   gtk_timeout_remove(context->handler_id);  
   gtk_widget_destroy(dialog);  
   g_free(context);  
 #endif  
456  }  }

Legend:
Removed from v.41  
changed lines
  Added in v.57