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

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

revision 33 by harbaum, Tue Jul 28 13:21:40 2009 UTC revision 35 by harbaum, Thu Jul 30 08:29:52 2009 UTC
# Line 18  Line 18 
18   */   */
19    
20  #include "gpxview.h"  #include "gpxview.h"
21    #include <math.h>    // for isnan
22    
23  #ifdef ENABLE_OSM_GPS_MAP  #ifdef ENABLE_OSM_GPS_MAP
24  #include "osm-gps-map.h"  #include "osm-gps-map.h"
25  #endif  #endif
26    
27  typedef struct {  typedef struct {
28      appdata_t *appdata;
29    GtkWidget *widget;    GtkWidget *widget;
30    GtkWidget *zoomin, *zoomout, *gps;    GtkWidget *zoomin, *zoomout, *gps;
31    gint handler_id;    gint handler_id;
32  } map_context_t;  } map_context_t;
33    
34  static const char *get_proxy_uri(void) {  #define PROXY_KEY  "/system/http_proxy/"
35    static char proxy_buffer[64];  
36    static const char *get_proxy_uri(appdata_t *appdata) {
37      static char proxy_buffer[64] = "";
38    
39    /* use environment settings if preset */    /* use environment settings if preset */
40    const char *proxy = g_getenv("http_proxy");    const char *proxy = g_getenv("http_proxy");
# Line 39  static const char *get_proxy_uri(void) { Line 43  static const char *get_proxy_uri(void) {
43      return proxy;      return proxy;
44    }    }
45    
46  #if 0    /* ------------- get proxy settings -------------------- */
47    /* otherwise try settings */    if(gconf_client_get_bool(appdata->gconf_client,
48    if(!settings || !settings->proxy ||                             PROXY_KEY "use_http_proxy", NULL)) {
49       !settings->proxy->host) return NULL;  
50        /* we can savely ignore things like "ignore_hosts" since we */
51    snprintf(proxy_buffer, sizeof(proxy_buffer), "%s%s:%u",      /* are pretty sure not inside the net of one of our map renderers */
52             strncmp(settings->proxy->host, "http://", 7)?"http://":"",      /* (unless the user works at google :-) */
53             settings->proxy->host, settings->proxy->port);  
54        /* get basic settings */
55    proxy_buffer[sizeof(proxy_buffer)-1] = 0;      char *host =
56    printf("gconf_proxy: %s\n", proxy_buffer);        gconf_client_get_string(appdata->gconf_client, PROXY_KEY "host", NULL);
57  #endif      if(host) {
58          int port =
59            gconf_client_get_int(appdata->gconf_client, PROXY_KEY "port", NULL);
60    
61          snprintf(proxy_buffer, sizeof(proxy_buffer),
62                   "http://%s:%u", host, port);
63    
64          g_free(host);
65        }
66        return proxy_buffer;
67      }
68    
69    return proxy_buffer;    return NULL;
70  }  }
71    
72  static void map_zoom(map_context_t *context, int step) {  static void map_zoom(map_context_t *context, int step) {
# Line 80  cb_map_zoomout(GtkButton *button, map_co Line 94  cb_map_zoomout(GtkButton *button, map_co
94    
95  static gboolean  static gboolean
96  cb_map_gps(GtkButton *button, map_context_t *context) {  cb_map_gps(GtkButton *button, map_context_t *context) {
97      pos_t *refpos = get_pos(context->appdata);
98    //  osm_gps_map_set_center(OSM_GPS_MAP(context->widget),    if(refpos && !isnan(refpos->lat) && !isnan(refpos->lon)) {
99    //                     DEG2RAD(pos.lat), DEG2RAD(pos.lon));      osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
100                                  refpos->lat, refpos->lon, 14);
101      } else {
102        /* no coordinates given: display the entire world */
103        osm_gps_map_set_mapcenter(OSM_GPS_MAP(context->widget),
104                                  0.0, 0.0, 1);
105      }
106    
107    return FALSE;    return FALSE;
108  }  }
# Line 103  static GtkWidget Line 123  static GtkWidget
123  static gboolean map_gps_update(gpointer data) {  static gboolean map_gps_update(gpointer data) {
124    map_context_t *context = (map_context_t*)data;    map_context_t *context = (map_context_t*)data;
125    
126    //  gtk_widget_set_sensitive(context->map.gps, gps_fix);    pos_t *refpos = get_pos(context->appdata);
127      gboolean ok = (refpos!= NULL) && !isnan(refpos->lat) && !isnan(refpos->lon);
128    
129      /* get reference position and go there */
130      gtk_widget_set_sensitive(context->gps, ok);
131    
132    return TRUE;    return TRUE;
133  }  }
134    
135    static gboolean on_map_configure(GtkWidget *widget,
136                                     GdkEventConfigure *event,
137                                     map_context_t *context) {
138    
139      cb_map_gps(NULL, context);
140    
141      return FALSE;
142    }
143    
144  void map(appdata_t *appdata) {  void map(appdata_t *appdata) {
145    map_context_t context;    map_context_t context;
146      context.appdata = appdata;
147    
148    GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Map"),    GtkWidget *dialog = gtk_dialog_new_with_buttons(_("Map"),
149                            GTK_WINDOW(appdata->window),                            GTK_WINDOW(appdata->window),
# Line 127  void map(appdata_t *appdata) { Line 160  void map(appdata_t *appdata) {
160    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);    GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
161    
162    char *path = g_strdup_printf("%s/map/", appdata->image_path);    char *path = g_strdup_printf("%s/map/", appdata->image_path);
163      const char *proxy = get_proxy_uri(appdata);
164    
165    context.widget = g_object_new(OSM_TYPE_GPS_MAP,    context.widget = g_object_new(OSM_TYPE_GPS_MAP,
166                  "repo-uri", MAP_SOURCE_OPENSTREETMAP,                  "repo-uri", MAP_SOURCE_OPENSTREETMAP,
                 "proxy-uri", get_proxy_uri(),  
167                  "tile-cache", path,                  "tile-cache", path,
168                    proxy?"proxy-uri":NULL, proxy,
169                   NULL);                   NULL);
170    
171    g_free(path);    g_free(path);
172    
173      g_signal_connect(G_OBJECT(context.widget), "configure-event",
174                       G_CALLBACK(on_map_configure), &context);
175  #if 0  #if 0
176    g_signal_connect(G_OBJECT(context.widget), "button-release-event",    g_signal_connect(G_OBJECT(context.widget), "button-release-event",
177                     G_CALLBACK(on_map_button_release_event), &context);                     G_CALLBACK(on_map_button_release_event), &context);
# Line 173  void map(appdata_t *appdata) { Line 209  void map(appdata_t *appdata) {
209    
210    gtk_dialog_run(GTK_DIALOG(dialog));    gtk_dialog_run(GTK_DIALOG(dialog));
211    
212      gtk_timeout_remove(context.handler_id);
213    
214    gtk_widget_destroy(dialog);    gtk_widget_destroy(dialog);
   
215  }  }

Legend:
Removed from v.33  
changed lines
  Added in v.35