Diff of /trunk/src/osm-gps-map.c

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

revision 32 by harbaum, Tue Jul 28 13:21:22 2009 UTC revision 83 by harbaum, Thu Aug 27 20:24:31 2009 UTC
# Line 33  Line 33 
33    
34  #include <gdk/gdk.h>  #include <gdk/gdk.h>
35  #include <glib.h>  #include <glib.h>
36    #include <glib/gstdio.h>
37  #include <glib/gprintf.h>  #include <glib/gprintf.h>
38  #include <libsoup/soup.h>  #include <libsoup/soup.h>
39    
# Line 48  Line 49 
49    
50  #define EXTRA_BORDER (TILESIZE / 2)  #define EXTRA_BORDER (TILESIZE / 2)
51    
52    #define OSM_GPS_MAP_SCROLL_STEP 10
53    
54    /* any defined key enables key support */
55    #if (defined(OSM_GPS_MAP_KEY_FULLSCREEN) || \
56         defined(OSM_GPS_MAP_KEY_ZOOMIN) || \
57         defined(OSM_GPS_MAP_KEY_ZOOMOUT) || \
58         defined(OSM_GPS_MAP_KEY_UP) || \
59         defined(OSM_GPS_MAP_KEY_DOWN) || \
60         defined(OSM_GPS_MAP_KEY_LEFT) || \
61         defined(OSM_GPS_MAP_KEY_RIGHT))
62    #define OSM_GPS_MAP_KEYS
63    #endif
64    
65    #ifdef OSM_GPS_MAP_KEYS
66    #include <gdk/gdkkeysyms.h>
67    #endif
68    
69  struct _OsmGpsMapPrivate  struct _OsmGpsMapPrivate
70  {  {
71      GHashTable *tile_queue;      GHashTable *tile_queue;
# Line 78  struct _OsmGpsMapPrivate Line 96  struct _OsmGpsMapPrivate
96    
97      //where downloaded tiles are cached      //where downloaded tiles are cached
98      char *cache_dir;      char *cache_dir;
     gboolean cache_dir_is_full_path;  
99    
100      //contains flags indicating the various special characters      //contains flags indicating the various special characters
101      //the uri string contains, that will be replaced when calculating      //the uri string contains, that will be replaced when calculating
102      //the uri to download.      //the uri to download.
103        OsmGpsMapSource_t map_source;
104      char *repo_uri;      char *repo_uri;
105        char *image_format;
106      int uri_format;      int uri_format;
107      //flag indicating if the map source is located on the google      //flag indicating if the map source is located on the google
108      gboolean the_google;      gboolean the_google;
# Line 95  struct _OsmGpsMapPrivate Line 114  struct _OsmGpsMapPrivate
114      coord_t *gps;      coord_t *gps;
115      gboolean gps_valid;      gboolean gps_valid;
116    
117    #ifdef ENABLE_BALLOON
118        //a balloon with additional info
119        struct {
120            coord_t *coo;
121            gboolean valid;
122            OsmGpsMapRect_t rect;
123            OsmGpsMapBalloonCallback cb;
124            gpointer data;
125        } balloon;
126    #endif
127    
128    #ifdef ENABLE_OSD
129        //the osd controls (if present)
130        osm_gps_map_osd_t *osd;
131    #ifdef OSD_DOUBLE_BUFFER
132        GdkPixmap *dbuf_pixmap;
133    #endif
134    #endif
135    
136    #ifdef OSM_GPS_MAP_KEY_FULLSCREEN
137        gboolean fullscreen;
138    #endif
139    
140      //additional images or tracks added to the map      //additional images or tracks added to the map
141      GSList *tracks;      GSList *tracks;
142      GSList *images;      GSList *images;
# Line 104  struct _OsmGpsMapPrivate Line 146  struct _OsmGpsMapPrivate
146      GdkGC *gc_map;      GdkGC *gc_map;
147    
148      //The tile painted when one cannot be found      //The tile painted when one cannot be found
149      //GdkPixbuf *missing_tile;      GdkPixbuf *null_tile;
150    
151      //For tracking click and drag      //For tracking click and drag
152      int drag_counter;      int drag_counter;
# Line 146  enum Line 188  enum
188      PROP_REPO_URI,      PROP_REPO_URI,
189      PROP_PROXY_URI,      PROP_PROXY_URI,
190      PROP_TILE_CACHE_DIR,      PROP_TILE_CACHE_DIR,
     PROP_TILE_CACHE_DIR_IS_FULL_PATH,  
191      PROP_ZOOM,      PROP_ZOOM,
192      PROP_MAX_ZOOM,      PROP_MAX_ZOOM,
193      PROP_MIN_ZOOM,      PROP_MIN_ZOOM,
# Line 157  enum Line 198  enum
198      PROP_TILES_QUEUED,      PROP_TILES_QUEUED,
199      PROP_GPS_TRACK_WIDTH,      PROP_GPS_TRACK_WIDTH,
200      PROP_GPS_POINT_R1,      PROP_GPS_POINT_R1,
201      PROP_GPS_POINT_R2      PROP_GPS_POINT_R2,
202        PROP_MAP_SOURCE,
203        PROP_IMAGE_FORMAT
204  };  };
205    
206  G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA);  G_DEFINE_TYPE (OsmGpsMap, osm_gps_map, GTK_TYPE_DRAWING_AREA);
# Line 171  static gchar    *replace_map_uri(OsmGpsM Line 214  static gchar    *replace_map_uri(OsmGpsM
214  static void     osm_gps_map_print_images (OsmGpsMap *map);  static void     osm_gps_map_print_images (OsmGpsMap *map);
215  static void     osm_gps_map_draw_gps_point (OsmGpsMap *map);  static void     osm_gps_map_draw_gps_point (OsmGpsMap *map);
216  static void     osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y);  static void     osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y);
217    #ifdef LIBSOUP22
218    static void     osm_gps_map_tile_download_complete (SoupMessage *msg, gpointer user_data);
219    #else
220    static void     osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data);
221    #endif
222  static void     osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw);  static void     osm_gps_map_download_tile (OsmGpsMap *map, int zoom, int x, int y, gboolean redraw);
223  static void     osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y);  static void     osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y);
224  static void     osm_gps_map_fill_tiles_pixel (OsmGpsMap *map);  static void     osm_gps_map_fill_tiles_pixel (OsmGpsMap *map);
# Line 420  my_log_handler (const gchar * log_domain Line 468  my_log_handler (const gchar * log_domain
468          g_log_default_handler (log_domain, log_level, message, user_data);          g_log_default_handler (log_domain, log_level, message, user_data);
469  }  }
470    
471    static float
472    osm_gps_map_get_scale_at_point(int zoom, float rlat, float rlon)
473    {
474        /* world at zoom 1 == 512 pixels */
475        return cos(rlat) * M_PI * OSM_EQ_RADIUS / (1<<(7+zoom));
476    }
477    
478  /* clears the trip list and all resources */  /* clears the trip list and all resources */
479  static void  static void
480  osm_gps_map_free_trip (OsmGpsMap *map)  osm_gps_map_free_trip (OsmGpsMap *map)
# Line 529  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 584  osm_gps_map_draw_gps_point (OsmGpsMap *m
584          int x, y;          int x, y;
585          int r = priv->ui_gps_point_inner_radius;          int r = priv->ui_gps_point_inner_radius;
586          int r2 = priv->ui_gps_point_outer_radius;          int r2 = priv->ui_gps_point_outer_radius;
587            // int lw = priv->ui_gps_track_width;
588          int mr = MAX(r,r2);          int mr = MAX(r,r2);
589    
590          map_x0 = priv->map_x - EXTRA_BORDER;          map_x0 = priv->map_x - EXTRA_BORDER;
# Line 539  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 595  osm_gps_map_draw_gps_point (OsmGpsMap *m
595          cairo_t *cr;          cairo_t *cr;
596          cairo_pattern_t *pat;          cairo_pattern_t *pat;
597  #else  #else
         int lw = priv->ui_gps_track_width;  
598          GdkColor color;          GdkColor color;
599          GdkGC *marker;          GdkGC *marker;
600  #endif  #endif
# Line 614  osm_gps_map_draw_gps_point (OsmGpsMap *m Line 669  osm_gps_map_draw_gps_point (OsmGpsMap *m
669                                      (mr*2)+lw+lw);                                      (mr*2)+lw+lw);
670  #endif  #endif
671      }      }
672    }
673    
674    #ifdef ENABLE_BALLOON
675    /* most visual effects are hardcoded by now, but may be made */
676    /* available via properties later */
677    #ifndef BALLOON_AREA_WIDTH
678    #define BALLOON_AREA_WIDTH           290
679    #endif
680    #ifndef BALLOON_AREA_HEIGHT
681    #define BALLOON_AREA_HEIGHT           75
682    #endif
683    #ifndef BALLOON_CORNER_RADIUS
684    #define BALLOON_CORNER_RADIUS         10
685    #endif
686    
687    #define BALLOON_BORDER               (BALLOON_CORNER_RADIUS/2)
688    #define BALLOON_WIDTH                (BALLOON_AREA_WIDTH + 2 * BALLOON_BORDER)
689    #define BALLOON_HEIGHT               (BALLOON_AREA_HEIGHT + 2 * BALLOON_BORDER)
690    #define BALLOON_TRANSPARENCY         0.8
691    #define POINTER_HEIGHT                20
692    #define POINTER_FOOT_WIDTH            20
693    #define POINTER_OFFSET               (BALLOON_CORNER_RADIUS*3/4)
694    #define BALLOON_SHADOW               (BALLOON_CORNER_RADIUS/2)
695    #define BALLOON_SHADOW_TRANSPARENCY  0.2
696    
697    #define CLOSE_BUTTON_RADIUS   (BALLOON_CORNER_RADIUS)
698    
699    
700    /* draw the bubble shape. this is used twice, once for the shape and once */
701    /* for the shadow */
702    static void
703    osm_gps_map_draw_balloon_shape (cairo_t *cr, int x0, int y0, int x1, int y1,
704           gboolean bottom, int px, int py, int px0, int px1) {
705    
706        cairo_move_to (cr, x0, y0 + BALLOON_CORNER_RADIUS);
707        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
708                   BALLOON_CORNER_RADIUS, -M_PI, -M_PI/2);
709        if(!bottom) {
710            /* insert top pointer */
711            cairo_line_to (cr, px1, y0);
712            cairo_line_to (cr, px, py);
713            cairo_line_to (cr, px0, y0);
714        }
715    
716        cairo_line_to (cr, x1 - BALLOON_CORNER_RADIUS, y0);
717        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y0 + BALLOON_CORNER_RADIUS,
718                   BALLOON_CORNER_RADIUS, -M_PI/2, 0);
719        cairo_line_to (cr, x1 , y1 - BALLOON_CORNER_RADIUS);
720        cairo_arc (cr, x1 - BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
721                   BALLOON_CORNER_RADIUS, 0, M_PI/2);
722        if(bottom) {
723            /* insert bottom pointer */
724            cairo_line_to (cr, px0, y1);
725            cairo_line_to (cr, px, py);
726            cairo_line_to (cr, px1, y1);
727        }
728    
729        cairo_line_to (cr, x0 + BALLOON_CORNER_RADIUS, y1);
730        cairo_arc (cr, x0 + BALLOON_CORNER_RADIUS, y1 - BALLOON_CORNER_RADIUS,
731                   BALLOON_CORNER_RADIUS, M_PI/2, M_PI);
732    
733        cairo_close_path (cr);
734    }
735    
736    static void
737    osm_gps_map_draw_balloon_int (OsmGpsMap *map)
738    {
739        OsmGpsMapPrivate *priv = map->priv;
740    
741        if (priv->balloon.valid) {
742    
743            /* ------- convert given coordinate into screen position --------- */
744            int x0 = lon2pixel(priv->map_zoom, priv->balloon.coo->rlon) -
745                priv->map_x + EXTRA_BORDER;
746            int y0 = lat2pixel(priv->map_zoom, priv->balloon.coo->rlat) -
747                priv->map_y + EXTRA_BORDER;
748    
749            /* check position of this relative to screen center to determine */
750            /* pointer direction ... */
751            int pointer_x = x0, pointer_x0, pointer_x1;
752            int pointer_y = y0;
753    
754            /* ... and calculate position */
755            if((x0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.width/2) {
756                x0 -= BALLOON_WIDTH - POINTER_OFFSET;
757                pointer_x0 = pointer_x - (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
758                pointer_x1 = pointer_x0 - POINTER_FOOT_WIDTH;
759            } else {
760                x0 -= POINTER_OFFSET;
761                pointer_x1 = pointer_x + (BALLOON_CORNER_RADIUS - POINTER_OFFSET);
762                pointer_x0 = pointer_x1 + POINTER_FOOT_WIDTH;
763            }
764    
765            gboolean bottom = FALSE;
766            if((y0 - EXTRA_BORDER) > GTK_WIDGET(map)->allocation.height/2) {
767                bottom = TRUE;
768                y0 -= BALLOON_HEIGHT + POINTER_HEIGHT;
769            } else
770                y0 += POINTER_HEIGHT;
771    
772            /* calculate bottom/right of box */
773            int x1 = x0 + BALLOON_WIDTH, y1 = y0 + BALLOON_HEIGHT;
774    
775            /* save balloon screen coordinates for later use */
776            priv->balloon.rect.x = x0 + BALLOON_BORDER;
777            priv->balloon.rect.y = y0 + BALLOON_BORDER;
778            priv->balloon.rect.w = x1 - x0 - 2*BALLOON_BORDER;
779            priv->balloon.rect.h = y1 - y0 - 2*BALLOON_BORDER;
780    
781    #ifdef USE_CAIRO
782            cairo_t *cr = gdk_cairo_create(priv->pixmap);
783    
784            /* --------- draw shadow --------------- */
785            osm_gps_map_draw_balloon_shape (cr,
786                        x0 + BALLOON_SHADOW, y0 + BALLOON_SHADOW,
787                        x1 + BALLOON_SHADOW, y1 + BALLOON_SHADOW,
788                        bottom, pointer_x, pointer_y,
789                        pointer_x0 + BALLOON_SHADOW, pointer_x1 + BALLOON_SHADOW);
790    
791            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_SHADOW_TRANSPARENCY);
792            cairo_fill_preserve (cr);
793            cairo_set_source_rgba (cr, 1, 0, 0, 1.0);
794            cairo_set_line_width (cr, 0);
795            cairo_stroke (cr);
796    
797            /* --------- draw main shape ----------- */
798            osm_gps_map_draw_balloon_shape (cr, x0, y0, x1, y1,
799                        bottom, pointer_x, pointer_y, pointer_x0, pointer_x1);
800    
801            cairo_set_source_rgba (cr, 1, 1, 1, BALLOON_TRANSPARENCY);
802            cairo_fill_preserve (cr);
803            cairo_set_source_rgba (cr, 0, 0, 0, BALLOON_TRANSPARENCY);
804            cairo_set_line_width (cr, 1);
805            cairo_stroke (cr);
806    
807    
808            /* ---------- draw close button --------- */
809    
810            int cx = x1 - BALLOON_BORDER - CLOSE_BUTTON_RADIUS;
811            int cy = y0 + BALLOON_BORDER + CLOSE_BUTTON_RADIUS;
812            int crad = CLOSE_BUTTON_RADIUS;
813    
814            cairo_arc (cr, cx, cy, crad, 0, 2 * M_PI);
815            cairo_set_source_rgba (cr, 0.8, 0, 0, 1.0);
816            cairo_fill_preserve (cr);
817            cairo_set_source_rgba (cr, 0.3, 0, 0, 1.0);
818            cairo_set_line_width (cr, 2);
819            cairo_stroke(cr);
820    
821            cairo_set_source_rgba (cr, 1, 1, 1, 1.0);
822            cairo_set_line_width (cr, BALLOON_CORNER_RADIUS/3.3);
823            cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
824            cairo_move_to (cr, cx - crad/2, cy - crad/2);
825            cairo_line_to (cr, cx + crad/2, cy + crad/2);
826            cairo_stroke (cr);
827            cairo_move_to (cr, cx + crad/2, cy - crad/2);
828            cairo_line_to (cr, cx - crad/2, cy + crad/2);
829            cairo_stroke (cr);
830    
831            if (priv->balloon.cb) {
832                /* clip in case application tries to draw in */
833                /* exceed of the balloon */
834                cairo_rectangle (cr, priv->balloon.rect.x, priv->balloon.rect.y,
835                                 priv->balloon.rect.w, priv->balloon.rect.h);
836                cairo_clip (cr);
837                cairo_new_path (cr);  /* current path is not
838                                         consumed by cairo_clip() */
839    
840                priv->balloon.cb(cr, &priv->balloon.rect, priv->balloon.data);
841            }
842    
843            cairo_destroy(cr);
844    
845            gtk_widget_queue_draw_area (GTK_WIDGET(map),
846                                        x0, y0, BALLOON_WIDTH,
847                                        BALLOON_HEIGHT + POINTER_HEIGHT);
848    #else
849    #warning "Balloon display lacks a non-cairo implementation!"
850    #endif
851        }
852    }
853    
854    /* the user clicked into the balloons main area. handle this */
855    static void
856    osm_gps_map_handle_balloon_click(OsmGpsMap *map, gint x, gint y)
857    {
858        OsmGpsMapPrivate *priv = map->priv;
859    
860        if (!priv->balloon.valid)
861            return;
862    
863        /* check if the close button was clicked */
864        if ((x > priv->balloon.rect.w - 2*CLOSE_BUTTON_RADIUS) &&
865            (x < priv->balloon.rect.w) &&
866            (y > 0) && (y < 2*CLOSE_BUTTON_RADIUS)) {
867    
868            priv->balloon.valid = FALSE;
869            osm_gps_map_map_redraw_idle(map);
870        }
871    }
872    
873    /* return true if balloon is being displayed and if */
874    /* the given coordinate is within this balloon */
875    static gboolean
876    osm_gps_map_in_balloon(OsmGpsMapPrivate *priv, gint x, gint y)
877    {
878        return (priv->balloon.valid &&
879                (x > priv->balloon.rect.x) &&
880                (x < priv->balloon.rect.x + priv->balloon.rect.w) &&
881                (y > priv->balloon.rect.y) &&
882                (y < priv->balloon.rect.y + priv->balloon.rect.h));
883  }  }
884    #endif // ENABLE_BALLOON
885    
886  static void  static void
887  osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y)  osm_gps_map_blit_tile(OsmGpsMap *map, GdkPixbuf *pixbuf, int offset_x, int offset_y)
888  {  {
889      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
890    
891      g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y,      g_debug("Queing redraw @ %d,%d (w:%d h:%d)", offset_x,offset_y, TILESIZE,TILESIZE);
             TILESIZE,TILESIZE);  
892    
893      /* draw pixbuf onto pixmap */      /* draw pixbuf onto pixmap */
894      gdk_draw_pixbuf (priv->pixmap,      gdk_draw_pixbuf (priv->pixmap,
# Line 654  static void Line 920  static void
920  osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data)  osm_gps_map_tile_download_complete (SoupSession *session, SoupMessage *msg, gpointer user_data)
921  #endif  #endif
922  {  {
923      int fd;      FILE *file;
924      tile_download_t *dl = (tile_download_t *)user_data;      tile_download_t *dl = (tile_download_t *)user_data;
925      OsmGpsMap *map = OSM_GPS_MAP(dl->map);      OsmGpsMap *map = OSM_GPS_MAP(dl->map);
926      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
# Line 667  osm_gps_map_tile_download_complete (Soup Line 933  osm_gps_map_tile_download_complete (Soup
933          {          {
934              if (g_mkdir_with_parents(dl->folder,0700) == 0)              if (g_mkdir_with_parents(dl->folder,0700) == 0)
935              {              {
936                  fd = open(dl->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);                  file = g_fopen(dl->filename, "wb");
937                  if (fd != -1)                  if (file != NULL)
938                  {                  {
939                      write (fd, MSG_RESPONSE_BODY(msg), MSG_RESPONSE_LEN(msg));                      fwrite (MSG_RESPONSE_BODY(msg), 1, MSG_RESPONSE_LEN(msg), file);
940                      file_saved = TRUE;                      file_saved = TRUE;
941                        g_debug("Wrote "MSG_RESPONSE_LEN_FORMAT" bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename);
942                        fclose (file);
943    
                     g_debug("Wrote " MSG_RESPONSE_LEN_FORMAT " bytes to %s", MSG_RESPONSE_LEN(msg), dl->filename);  
                     close (fd);  
944                  }                  }
945              }              }
946              else              else
947              {              {
948                  g_warning("Error creating tile download directory: %s", dl->folder);                  g_warning("Error creating tile download directory: %s",
949                              dl->folder);
950                    perror("perror:");
951              }              }
952          }          }
953    
# Line 687  osm_gps_map_tile_download_complete (Soup Line 955  osm_gps_map_tile_download_complete (Soup
955          {          {
956              GdkPixbuf *pixbuf = NULL;              GdkPixbuf *pixbuf = NULL;
957    
958                /* if the file was actually stored on disk, we can simply */
959                /* load and decode it from that file */
960              if (priv->cache_dir)              if (priv->cache_dir)
961              {              {
962                  if (file_saved)                  if (file_saved)
# Line 720  osm_gps_map_tile_download_complete (Soup Line 990  osm_gps_map_tile_download_complete (Soup
990                      g_warning("Error: Unable to determine image file format");                      g_warning("Error: Unable to determine image file format");
991                  }                  }
992              }              }
993    
994              /* Store the tile into the cache */              /* Store the tile into the cache */
995              if (G_LIKELY (pixbuf))              if (G_LIKELY (pixbuf))
996              {              {
# Line 735  osm_gps_map_tile_download_complete (Soup Line 1005  osm_gps_map_tile_download_complete (Soup
1005                   * we are using it as a key in the hash table */                   * we are using it as a key in the hash table */
1006                  dl->filename = NULL;                  dl->filename = NULL;
1007              }              }
   
1008              osm_gps_map_map_redraw_idle (map);              osm_gps_map_map_redraw_idle (map);
1009          }          }
1010          g_hash_table_remove(priv->tile_queue, dl->uri);          g_hash_table_remove(priv->tile_queue, dl->uri);
# Line 794  osm_gps_map_download_tile (OsmGpsMap *ma Line 1063  osm_gps_map_download_tile (OsmGpsMap *ma
1063          g_free(dl->uri);          g_free(dl->uri);
1064          g_free(dl);          g_free(dl);
1065      } else {      } else {
1066          dl->folder = g_strdup_printf("%s/%d/%d/",priv->cache_dir, zoom, x);          dl->folder = g_strdup_printf("%s%c%d%c%d%c",
1067          dl->filename = g_strdup_printf("%s/%d/%d/%d.png",priv->cache_dir, zoom, x, y);                              priv->cache_dir, G_DIR_SEPARATOR,
1068                                zoom, G_DIR_SEPARATOR,
1069                                x, G_DIR_SEPARATOR);
1070            dl->filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1071                                priv->cache_dir, G_DIR_SEPARATOR,
1072                                zoom, G_DIR_SEPARATOR,
1073                                x, G_DIR_SEPARATOR,
1074                                y,
1075                                priv->image_format);
1076          dl->map = map;          dl->map = map;
1077          dl->redraw = redraw;          dl->redraw = redraw;
1078    
# Line 813  osm_gps_map_download_tile (OsmGpsMap *ma Line 1090  osm_gps_map_download_tile (OsmGpsMap *ma
1090                      if (cookie) {                      if (cookie) {
1091                          g_debug("Adding Google Cookie");                          g_debug("Adding Google Cookie");
1092                          soup_message_headers_append(msg->request_headers, "Cookie", cookie);                          soup_message_headers_append(msg->request_headers, "Cookie", cookie);
   
1093                      }                      }
1094                  }                  }
1095              }              }
# Line 835  osm_gps_map_load_cached_tile (OsmGpsMap Line 1111  osm_gps_map_load_cached_tile (OsmGpsMap
1111  {  {
1112      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1113      gchar *filename;      gchar *filename;
1114      GdkPixbuf *pixbuf;      GdkPixbuf *pixbuf = NULL;
1115      OsmCachedTile *tile;      OsmCachedTile *tile;
1116    
1117      filename = g_strdup_printf("%s/%u/%u/%u.png",      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1118                                 priv->cache_dir,                  priv->cache_dir, G_DIR_SEPARATOR,
1119                                 zoom, x, y);                  zoom, G_DIR_SEPARATOR,
1120                    x, G_DIR_SEPARATOR,
1121                    y,
1122                    priv->image_format);
1123    
1124      tile = g_hash_table_lookup (priv->tile_cache, filename);      tile = g_hash_table_lookup (priv->tile_cache, filename);
1125      if (tile)      if (tile)
1126      {      {
1127          g_free (filename);          g_free (filename);
1128      }      }
1129      else if (priv->cache_dir)      else
1130      {      {
1131          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);          pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1132          if (pixbuf)          if (pixbuf)
# Line 863  osm_gps_map_load_cached_tile (OsmGpsMap Line 1142  osm_gps_map_load_cached_tile (OsmGpsMap
1142      {      {
1143          tile->redraw_cycle = priv->redraw_cycle;          tile->redraw_cycle = priv->redraw_cycle;
1144          pixbuf = g_object_ref (tile->pixbuf);          pixbuf = g_object_ref (tile->pixbuf);
1145      } else      }
         pixbuf = NULL;  
1146    
1147      return pixbuf;      return pixbuf;
1148  }  }
# Line 928  static void Line 1206  static void
1206  osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y)  osm_gps_map_load_tile (OsmGpsMap *map, int zoom, int x, int y, int offset_x, int offset_y)
1207  {  {
1208      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
1209        gchar *filename;
1210      GdkPixbuf *pixbuf;      GdkPixbuf *pixbuf;
1211    
1212      g_debug("Load tile %d,%d (%d,%d) z:%d", x, y, offset_x, offset_y, zoom);      g_debug("Load tile %d,%d (%d,%d) z:%d", x, y, offset_x, offset_y, zoom);
1213    
1214      /* try to get file from internal cache */      if (priv->map_source == OSM_GPS_MAP_SOURCE_NULL) {
1215      pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y);          osm_gps_map_blit_tile(map, priv->null_tile, offset_x,offset_y);
1216            return;
1217        }
1218    
1219      /* if a disk cache is being used, try to read the file from there */      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
1220      if (priv->cache_dir && !pixbuf)                  priv->cache_dir, G_DIR_SEPARATOR,
1221      {                  zoom, G_DIR_SEPARATOR,
1222          gchar *filename;                  x, G_DIR_SEPARATOR,
1223          filename = g_strdup_printf("%s/%u/%u/%u.png",                  y,
1224                                     priv->cache_dir,                  priv->image_format);
                                    zoom, x, y);  
   
         pixbuf = gdk_pixbuf_new_from_file (filename, NULL);  
         if (pixbuf)  
         {  
             g_debug("Found tile %s", filename);  
         }  
1225    
1226          g_free(filename);      /* try to get file from internal cache first */
1227      }      if(!(pixbuf = osm_gps_map_load_cached_tile(map, zoom, x, y)))
1228            pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
1229    
1230      if (G_LIKELY(pixbuf))      if(pixbuf)
1231      {      {
1232            g_debug("Found tile %s", filename);
1233          osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y);          osm_gps_map_blit_tile(map, pixbuf, offset_x,offset_y);
1234          g_object_unref (pixbuf);          g_object_unref (pixbuf);
1235      }      }
# Line 984  osm_gps_map_load_tile (OsmGpsMap *map, i Line 1260  osm_gps_map_load_tile (OsmGpsMap *map, i
1260                                  TRUE, offset_x, offset_y, TILESIZE, TILESIZE);                                  TRUE, offset_x, offset_y, TILESIZE, TILESIZE);
1261          }          }
1262      }      }
1263        g_free(filename);
1264  }  }
1265    
1266  static void  static void
# Line 1077  osm_gps_map_print_track (OsmGpsMap *map, Line 1354  osm_gps_map_print_track (OsmGpsMap *map,
1354    
1355      map_x0 = priv->map_x - EXTRA_BORDER;      map_x0 = priv->map_x - EXTRA_BORDER;
1356      map_y0 = priv->map_y - EXTRA_BORDER;      map_y0 = priv->map_y - EXTRA_BORDER;
   
1357      for(list = trackpoint_list; list != NULL; list = list->next)      for(list = trackpoint_list; list != NULL; list = list->next)
1358      {      {
1359          coord_t *tp = list->data;          coord_t *tp = list->data;
# Line 1132  osm_gps_map_print_tracks (OsmGpsMap *map Line 1408  osm_gps_map_print_tracks (OsmGpsMap *map
1408    
1409      if (priv->show_trip_history)      if (priv->show_trip_history)
1410          osm_gps_map_print_track (map, priv->trip_history);          osm_gps_map_print_track (map, priv->trip_history);
1411    
1412      if (priv->tracks)      if (priv->tracks)
1413      {      {
         g_debug("TRACK");  
1414          GSList* tmp = priv->tracks;          GSList* tmp = priv->tracks;
1415          while (tmp != NULL)          while (tmp != NULL)
1416          {          {
# Line 1144  osm_gps_map_print_tracks (OsmGpsMap *map Line 1420  osm_gps_map_print_tracks (OsmGpsMap *map
1420      }      }
1421  }  }
1422    
1423  static gboolean  static gboolean
1424  osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user)  osm_gps_map_purge_cache_check(gpointer key, gpointer value, gpointer user)
1425  {  {
1426      return(((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle);     return (((OsmCachedTile*)value)->redraw_cycle != ((OsmGpsMapPrivate*)user)->redraw_cycle);
1427  }  }
1428    
1429  static void  static void
1430  osm_gps_map_purge_cache (OsmGpsMap *map)  osm_gps_map_purge_cache (OsmGpsMap *map)
1431  {  {
1432      OsmGpsMapPrivate *priv = map->priv;     OsmGpsMapPrivate *priv = map->priv;
1433    
1434      if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size)     if (g_hash_table_size (priv->tile_cache) < priv->max_tile_cache_size)
1435          return;         return;
1436    
1437      /* run through the cache, and remove the tiles which have not been used     /* run through the cache, and remove the tiles which have not been used
1438       * during the last redraw operation */      * during the last redraw operation */
1439      g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv);     g_hash_table_foreach_remove(priv->tile_cache, osm_gps_map_purge_cache_check, priv);
1440  }  }
1441    
1442  static gboolean  static gboolean
# Line 1193  osm_gps_map_map_redraw (OsmGpsMap *map) Line 1469  osm_gps_map_map_redraw (OsmGpsMap *map)
1469      osm_gps_map_print_tracks(map);      osm_gps_map_print_tracks(map);
1470      osm_gps_map_draw_gps_point(map);      osm_gps_map_draw_gps_point(map);
1471      osm_gps_map_print_images(map);      osm_gps_map_print_images(map);
1472    #ifdef ENABLE_BALLOON
1473        osm_gps_map_draw_balloon_int(map);
1474    #endif
1475    
1476      //osm_gps_map_osd_speed(map, 1.5);      //osm_gps_map_osd_speed(map, 1.5);
1477      osm_gps_map_purge_cache(map);      osm_gps_map_purge_cache(map);
# Line 1210  osm_gps_map_map_redraw_idle (OsmGpsMap * Line 1489  osm_gps_map_map_redraw_idle (OsmGpsMap *
1489          priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map);          priv->idle_map_redraw = g_idle_add ((GSourceFunc)osm_gps_map_map_redraw, map);
1490  }  }
1491    
1492    #ifdef OSM_GPS_MAP_KEYS
1493    static gboolean
1494    on_window_key_press(GtkWidget *widget,
1495                             GdkEventKey *event, OsmGpsMapPrivate *priv) {
1496      gboolean handled = FALSE;
1497      int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP;
1498    
1499      printf("key event with keyval %x\n", event->keyval);
1500    
1501      // the map handles some keys on its own ...
1502      switch(event->keyval) {
1503    #ifdef OSM_GPS_MAP_KEY_FULLSCREEN
1504      case OSM_GPS_MAP_KEY_FULLSCREEN: {
1505          GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(widget));
1506          if(!priv->fullscreen)
1507              gtk_window_fullscreen(GTK_WINDOW(toplevel));
1508          else
1509              gtk_window_unfullscreen(GTK_WINDOW(toplevel));
1510    
1511          priv->fullscreen = !priv->fullscreen;
1512          handled = TRUE;
1513          } break;
1514    #endif
1515    
1516    #ifdef OSM_GPS_MAP_KEY_ZOOMIN
1517      case OSM_GPS_MAP_KEY_ZOOMIN:
1518          osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
1519          handled = TRUE;
1520          break;
1521    #endif
1522    
1523    #ifdef OSM_GPS_MAP_KEY_ZOOMOUT
1524      case OSM_GPS_MAP_KEY_ZOOMOUT:
1525          osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
1526          handled = TRUE;
1527          break;
1528    #endif
1529    
1530    #ifdef OSM_GPS_MAP_KEY_UP
1531      case OSM_GPS_MAP_KEY_UP:
1532          priv->map_y -= step;
1533          priv->center_coord_set = FALSE;
1534          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1535          handled = TRUE;
1536          break;
1537    #endif
1538    
1539    #ifdef OSM_GPS_MAP_KEY_DOWN
1540      case OSM_GPS_MAP_KEY_DOWN:
1541          priv->map_y += step;
1542          priv->center_coord_set = FALSE;
1543          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1544          handled = TRUE;
1545          break;
1546    #endif
1547    
1548    #ifdef OSM_GPS_MAP_KEY_LEFT
1549      case OSM_GPS_MAP_KEY_LEFT:
1550          priv->map_x -= step;
1551          priv->center_coord_set = FALSE;
1552          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1553          handled = TRUE;
1554          break;
1555    #endif
1556    
1557    #ifdef OSM_GPS_MAP_KEY_RIGHT
1558      case OSM_GPS_MAP_KEY_RIGHT:
1559          priv->map_x += step;
1560          priv->center_coord_set = FALSE;
1561          osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1562          handled = TRUE;
1563          break;
1564    #endif
1565    
1566      default:
1567          printf("unhandled key event with keyval %x\n", event->keyval);
1568          break;
1569      }
1570    
1571      return handled;
1572    }
1573    #endif
1574    
1575  static void  static void
1576  osm_gps_map_init (OsmGpsMap *object)  osm_gps_map_init (OsmGpsMap *object)
1577  {  {
# Line 1224  osm_gps_map_init (OsmGpsMap *object) Line 1586  osm_gps_map_init (OsmGpsMap *object)
1586      priv->gps = g_new0(coord_t, 1);      priv->gps = g_new0(coord_t, 1);
1587      priv->gps_valid = FALSE;      priv->gps_valid = FALSE;
1588    
1589    #ifdef ENABLE_BALLOON
1590        priv->balloon.coo = g_new0(coord_t, 1);
1591        priv->balloon.valid = FALSE;
1592        priv->balloon.cb = NULL;
1593    #endif
1594    
1595    #ifdef ENABLE_OSD
1596        priv->osd = NULL;
1597    #endif
1598    
1599    #ifdef OSM_GPS_MAP_BUTTON_FULLSCREEN
1600        priv->fullscreen = FALSE;
1601    #endif
1602    
1603      priv->tracks = NULL;      priv->tracks = NULL;
1604      priv->images = NULL;      priv->images = NULL;
1605    
# Line 1236  osm_gps_map_init (OsmGpsMap *object) Line 1612  osm_gps_map_init (OsmGpsMap *object)
1612      priv->uri_format = 0;      priv->uri_format = 0;
1613      priv->the_google = FALSE;      priv->the_google = FALSE;
1614    
1615        priv->map_source = -1;
1616    
1617  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1618      //Change naumber of concurrent connections option?      //Change naumber of concurrent connections option?
1619      priv->soup_session = soup_session_async_new_with_options(      priv->soup_session = soup_session_async_new_with_options(
# Line 1266  osm_gps_map_init (OsmGpsMap *object) Line 1644  osm_gps_map_init (OsmGpsMap *object)
1644      GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS);      GTK_WIDGET_SET_FLAGS (object, GTK_CAN_FOCUS);
1645    
1646      g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL);      g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MASK, my_log_handler, NULL);
 }  
1647    
1648  #ifndef G_CHECKSUM_MD5  #ifdef OSM_GPS_MAP_KEYS
1649  /* simple hash algorithm hack if md5 is not present */      //    GtkWidget *toplevel = gtk_widget_get_toplevel(GTK_WIDGET(object));
1650  static char *simple_hash(char *str) {      g_signal_connect(G_OBJECT(object), "key_press_event",
1651      union {                       G_CALLBACK(on_window_key_press), priv);
         char str[4];  
         gulong val;  
     } hash = { .val = 0x55555555 };  
   
     while(*str) {  
         hash.str[(int)str & 3] ^= *str;  
         str++;  
     }  
     return g_strdup_printf("%08lX", hash.val);  
 }  
1652  #endif  #endif
1653    }
1654    
1655  static GObject *  static GObject *
1656  osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties)  osm_gps_map_constructor (GType gtype, guint n_properties, GObjectConstructParam *properties)
1657  {  {
1658      GObject *object;      GObject *object;
1659      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
1660        OsmGpsMap *map;
1661        const char *uri;
1662    
1663      //Always chain up to the parent constructor      //Always chain up to the parent constructor
1664      object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);      object = G_OBJECT_CLASS(osm_gps_map_parent_class)->constructor(gtype, n_properties, properties);
1665        map = OSM_GPS_MAP(object);
1666      priv = OSM_GPS_MAP_PRIVATE(object);      priv = OSM_GPS_MAP_PRIVATE(object);
1667    
1668      if (!priv->cache_dir_is_full_path) {      //user can specify a map source ID, or a repo URI as the map source
1669  #ifdef G_CHECKSUM_MD5      uri = osm_gps_map_source_get_repo_uri(OSM_GPS_MAP_SOURCE_NULL);
1670          char *md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5, priv->repo_uri, -1);      if ( (priv->map_source == 0) || (strcmp(priv->repo_uri, uri) == 0) ) {
1671  #else          g_debug("Using null source");
1672          char *md5 = simple_hash(priv->repo_uri);          priv->map_source = OSM_GPS_MAP_SOURCE_NULL;
1673  #endif  
1674            priv->null_tile = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 256, 256);
1675          if (priv->cache_dir) {          gdk_pixbuf_fill(priv->null_tile, 0xcccccc00);
1676              char *old = priv->cache_dir;      }
1677              //the new cachedir is the given cache dir + the md5 of the repo_uri      else if (priv->map_source >= 0) {
1678              priv->cache_dir = g_strdup_printf("%s/%s", old, md5);          //check if the source given is valid
1679              g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);          uri = osm_gps_map_source_get_repo_uri(priv->map_source);
1680              g_free(old);          if (uri) {
1681                g_debug("Setting map source from ID");
1682                g_free(priv->repo_uri);
1683    
1684                priv->repo_uri = g_strdup(uri);
1685                priv->image_format = g_strdup(
1686                    osm_gps_map_source_get_image_format(priv->map_source));
1687                priv->max_zoom = osm_gps_map_source_get_max_zoom(priv->map_source);
1688                priv->min_zoom = osm_gps_map_source_get_min_zoom(priv->map_source);
1689          }          }
1690        }
1691    
1692          g_free(md5);      const char *fname = osm_gps_map_source_get_friendly_name(priv->map_source);
1693        if(!fname) fname = "_unknown_";
1694    
1695        if (priv->cache_dir) {
1696            char *old = priv->cache_dir;
1697            //the new cachedir is the given cache dir + the md5 of the repo_uri
1698            priv->cache_dir = g_strdup_printf("%s%c%s", old, G_DIR_SEPARATOR, fname);
1699            g_debug("Adjusting cache dir %s -> %s", old, priv->cache_dir);
1700            g_free(old);
1701      }      }
1702    
1703        inspect_map_uri(map);
1704    
1705      return object;      return object;
1706  }  }
1707    
# Line 1338  osm_gps_map_dispose (GObject *object) Line 1728  osm_gps_map_dispose (GObject *object)
1728      if(priv->pixmap)      if(priv->pixmap)
1729          g_object_unref (priv->pixmap);          g_object_unref (priv->pixmap);
1730    
1731        if (priv->null_tile)
1732            g_object_unref (priv->null_tile);
1733    
1734      if(priv->gc_map)      if(priv->gc_map)
1735          g_object_unref(priv->gc_map);          g_object_unref(priv->gc_map);
1736    
1737      if (priv->idle_map_redraw != 0)      if (priv->idle_map_redraw != 0)
1738          g_source_remove (priv->idle_map_redraw);          g_source_remove (priv->idle_map_redraw);
1739    
1740        g_free(priv->gps);
1741    
1742    #ifdef ENABLE_BALLOON
1743        g_free(priv->balloon.coo);
1744    #endif
1745    
1746    #ifdef ENABLE_OSD
1747        if(priv->osd)
1748            priv->osd->free(priv->osd);
1749    
1750    #ifdef OSD_DOUBLE_BUFFER
1751        if(priv->dbuf_pixmap)
1752            g_object_unref (priv->dbuf_pixmap);
1753    #endif
1754    #endif
1755    
1756      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);      G_OBJECT_CLASS (osm_gps_map_parent_class)->dispose (object);
1757  }  }
1758    
# Line 1355  osm_gps_map_finalize (GObject *object) Line 1764  osm_gps_map_finalize (GObject *object)
1764    
1765      g_free(priv->cache_dir);      g_free(priv->cache_dir);
1766      g_free(priv->repo_uri);      g_free(priv->repo_uri);
1767        g_free(priv->image_format);
1768    
1769      osm_gps_map_free_trip(map);      osm_gps_map_free_trip(map);
1770      osm_gps_map_free_tracks(map);      osm_gps_map_free_tracks(map);
# Line 1385  osm_gps_map_set_property (GObject *objec Line 1795  osm_gps_map_set_property (GObject *objec
1795              break;              break;
1796          case PROP_REPO_URI:          case PROP_REPO_URI:
1797              priv->repo_uri = g_value_dup_string (value);              priv->repo_uri = g_value_dup_string (value);
             inspect_map_uri(map);  
1798              break;              break;
1799          case PROP_PROXY_URI:          case PROP_PROXY_URI:
1800              if ( g_value_get_string(value) ) {              if ( g_value_get_string(value) ) {
   
1801                  priv->proxy_uri = g_value_dup_string (value);                  priv->proxy_uri = g_value_dup_string (value);
1802                  g_debug("Setting proxy server: %s", priv->proxy_uri);                  g_debug("Setting proxy server: %s", priv->proxy_uri);
1803    
1804  #ifndef LIBSOUP22  #ifndef LIBSOUP22
1805                  GValue val = {0};                  GValue val = {0};
1806    
1807                  SoupURI* uri = soup_uri_new(priv->proxy_uri);                  SoupURI* uri = soup_uri_new(priv->proxy_uri);
1808                  g_value_init(&val, SOUP_TYPE_URI);                  g_value_init(&val, SOUP_TYPE_URI);
1809                  g_value_take_boxed(&val, uri);                  g_value_take_boxed(&val, uri);
# Line 1403  osm_gps_map_set_property (GObject *objec Line 1813  osm_gps_map_set_property (GObject *objec
1813                  SoupUri* uri = soup_uri_new(priv->proxy_uri);                  SoupUri* uri = soup_uri_new(priv->proxy_uri);
1814                  g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL);                  g_object_set(G_OBJECT(priv->soup_session), SOUP_SESSION_PROXY_URI, uri, NULL);
1815  #endif  #endif
                 soup_uri_free(uri);  
1816              } else              } else
1817                  priv->proxy_uri = NULL;                  priv->proxy_uri = NULL;
1818    
1819              break;              break;
1820          case PROP_TILE_CACHE_DIR:          case PROP_TILE_CACHE_DIR:
1821              priv->cache_dir = g_value_dup_string (value);              if ( g_value_get_string(value) )
1822              break;                  priv->cache_dir = g_value_dup_string (value);
         case PROP_TILE_CACHE_DIR_IS_FULL_PATH:  
             priv->cache_dir_is_full_path = g_value_get_boolean (value);  
1823              break;              break;
1824          case PROP_ZOOM:          case PROP_ZOOM:
1825              priv->map_zoom = g_value_get_int (value);              priv->map_zoom = g_value_get_int (value);
# Line 1440  osm_gps_map_set_property (GObject *objec Line 1847  osm_gps_map_set_property (GObject *objec
1847          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1848              priv->ui_gps_point_outer_radius = g_value_get_int (value);              priv->ui_gps_point_outer_radius = g_value_get_int (value);
1849              break;              break;
1850            case PROP_MAP_SOURCE:
1851                priv->map_source = g_value_get_int (value);
1852                break;
1853            case PROP_IMAGE_FORMAT:
1854                priv->image_format = g_value_dup_string (value);
1855                break;
1856          default:          default:
1857              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1858              break;              break;
# Line 1477  osm_gps_map_get_property (GObject *objec Line 1890  osm_gps_map_get_property (GObject *objec
1890          case PROP_TILE_CACHE_DIR:          case PROP_TILE_CACHE_DIR:
1891              g_value_set_string(value, priv->cache_dir);              g_value_set_string(value, priv->cache_dir);
1892              break;              break;
         case PROP_TILE_CACHE_DIR_IS_FULL_PATH:  
             g_value_set_boolean(value, priv->cache_dir_is_full_path);  
             break;  
1893          case PROP_ZOOM:          case PROP_ZOOM:
1894              g_value_set_int(value, priv->map_zoom);              g_value_set_int(value, priv->map_zoom);
1895              break;              break;
# Line 1517  osm_gps_map_get_property (GObject *objec Line 1927  osm_gps_map_get_property (GObject *objec
1927          case PROP_GPS_POINT_R2:          case PROP_GPS_POINT_R2:
1928              g_value_set_int(value, priv->ui_gps_point_outer_radius);              g_value_set_int(value, priv->ui_gps_point_outer_radius);
1929              break;              break;
1930            case PROP_MAP_SOURCE:
1931                g_value_set_int(value, priv->map_source);
1932                break;
1933            case PROP_IMAGE_FORMAT:
1934                g_value_set_string(value, priv->image_format);
1935                break;
1936          default:          default:
1937              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);              G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1938              break;              break;
# Line 1524  osm_gps_map_get_property (GObject *objec Line 1940  osm_gps_map_get_property (GObject *objec
1940  }  }
1941    
1942  static gboolean  static gboolean
1943  _osm_gps_map_scroll (GtkWidget *widget, GdkEventScroll  *event)  osm_gps_map_scroll_event (GtkWidget *widget, GdkEventScroll  *event)
1944  {  {
1945      OsmGpsMap *map = OSM_GPS_MAP(widget);      OsmGpsMap *map = OSM_GPS_MAP(widget);
1946      OsmGpsMapPrivate *priv = map->priv;      OsmGpsMapPrivate *priv = map->priv;
# Line 1546  osm_gps_map_button_press (GtkWidget *wid Line 1962  osm_gps_map_button_press (GtkWidget *wid
1962  {  {
1963      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
1964    
1965    #ifdef ENABLE_BALLOON
1966        /* don't drag if the user clicked within the balloon */
1967        if (osm_gps_map_in_balloon(priv,
1968                       event->x + EXTRA_BORDER,
1969                       event->y + EXTRA_BORDER))
1970        {
1971            priv->drag_counter = -1;
1972            return FALSE;
1973        }
1974    #endif
1975    
1976    #ifdef ENABLE_OSD
1977        /* pressed inside OSD control? */
1978        if(priv->osd) {
1979            osd_button_t but = priv->osd->check(priv->osd, event->x, event->y);
1980            if(but != OSD_NONE)
1981            {
1982                int step = GTK_WIDGET(widget)->allocation.width/OSM_GPS_MAP_SCROLL_STEP;
1983                priv->drag_counter = -1;
1984    
1985                switch(but) {
1986                case OSD_UP:
1987                    priv->map_y -= step;
1988                    priv->center_coord_set = FALSE;
1989                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1990                    break;
1991    
1992                case OSD_DOWN:
1993                    priv->map_y += step;
1994                    priv->center_coord_set = FALSE;
1995                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
1996                    break;
1997    
1998                case OSD_LEFT:
1999                    priv->map_x -= step;
2000                    priv->center_coord_set = FALSE;
2001                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
2002                    break;
2003    
2004                case OSD_RIGHT:
2005                    priv->map_x += step;
2006                    priv->center_coord_set = FALSE;
2007                    osm_gps_map_map_redraw_idle(OSM_GPS_MAP(widget));
2008                    break;
2009    
2010                case OSD_IN:
2011                    osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom+1);
2012                    break;
2013    
2014                case OSD_OUT:
2015                    osm_gps_map_set_zoom(OSM_GPS_MAP(widget), priv->map_zoom-1);
2016                    break;
2017    
2018                default:
2019                    /* all custom buttons are forwarded to the application */
2020                    if(priv->osd->cb)
2021                        priv->osd->cb(but, priv->osd->data);
2022                    break;
2023                }
2024    
2025                return FALSE;
2026            }
2027        }
2028    #endif
2029    
2030      priv->drag_counter = 0;      priv->drag_counter = 0;
2031      priv->drag_start_mouse_x = (int) event->x;      priv->drag_start_mouse_x = (int) event->x;
2032      priv->drag_start_mouse_y = (int) event->y;      priv->drag_start_mouse_y = (int) event->y;
# Line 1560  osm_gps_map_button_release (GtkWidget *w Line 2041  osm_gps_map_button_release (GtkWidget *w
2041  {  {
2042      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2043    
2044    #ifdef ENABLE_BALLOON
2045        /* released inside the balloon? */
2046        if (osm_gps_map_in_balloon(priv,
2047                       event->x + EXTRA_BORDER,
2048                       event->y + EXTRA_BORDER))
2049        {
2050            osm_gps_map_handle_balloon_click(OSM_GPS_MAP(widget),
2051                 event->x - priv->balloon.rect.x + EXTRA_BORDER,
2052                 event->y - priv->balloon.rect.y + EXTRA_BORDER);
2053        }
2054    #endif
2055    
2056      if (priv->dragging)      if (priv->dragging)
2057      {      {
2058          priv->dragging = FALSE;          priv->dragging = FALSE;
# Line 1577  osm_gps_map_button_release (GtkWidget *w Line 2070  osm_gps_map_button_release (GtkWidget *w
2070    
2071      priv->drag_mouse_dx = 0;      priv->drag_mouse_dx = 0;
2072      priv->drag_mouse_dy = 0;      priv->drag_mouse_dy = 0;
2073      priv->drag_counter = 0;      priv->drag_counter = -1;
2074    
2075      return FALSE;      return FALSE;
2076  }  }
2077    
2078  static gboolean  static gboolean
2079    osm_gps_map_expose (GtkWidget *widget, GdkEventExpose  *event);
2080    
2081    static gboolean
2082  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)  osm_gps_map_motion_notify (GtkWidget *widget, GdkEventMotion  *event)
2083  {  {
2084      int x, y;      int x, y;
# Line 1602  osm_gps_map_motion_notify (GtkWidget *wi Line 2098  osm_gps_map_motion_notify (GtkWidget *wi
2098      if (!(state & GDK_BUTTON1_MASK))      if (!(state & GDK_BUTTON1_MASK))
2099          return FALSE;          return FALSE;
2100    
2101        if (priv->drag_counter < 0)
2102            return FALSE;
2103    
2104      priv->drag_counter++;      priv->drag_counter++;
2105    
2106      // we havent dragged more than 6 pixels      // we havent dragged more than 6 pixels
2107      if (priv->drag_counter < 6)      if (priv->drag_counter < 6)
2108          return FALSE;          return FALSE;
2109    
2110    #ifdef OSM_GPS_MAP_REFRESH
2111        /* reduce update frequency on maemo to keep screen update fluid */
2112        static guint32 last_time = 0;
2113    
2114        if(event->time - last_time < (1000/OSM_GPS_MAP_REFRESH)) return FALSE;
2115        last_time = event->time;
2116    #endif
2117    
2118      priv->dragging = TRUE;      priv->dragging = TRUE;
2119    
2120      if (priv->map_auto_center)      if (priv->map_auto_center)
# Line 1616  osm_gps_map_motion_notify (GtkWidget *wi Line 2123  osm_gps_map_motion_notify (GtkWidget *wi
2123      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;      priv->drag_mouse_dx = x - priv->drag_start_mouse_x;
2124      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;      priv->drag_mouse_dy = y - priv->drag_start_mouse_y;
2125    
2126      gdk_draw_drawable (      osm_gps_map_expose (widget, NULL);
                        widget->window,  
                        widget->style->fg_gc[GTK_WIDGET_STATE (widget)],  
                        priv->pixmap,  
                        0,0,  
                        priv->drag_mouse_dx - EXTRA_BORDER, priv->drag_mouse_dy - EXTRA_BORDER,  
                        -1,-1);  
   
     //Paint white outside of the map if dragging. Its less  
     //ugly than painting the corrupted map  
     if(priv->drag_mouse_dx>EXTRA_BORDER) {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, 0,  
                             priv->drag_mouse_dx - EXTRA_BORDER,  
                             widget->allocation.height);  
     }  
     else if (-priv->drag_mouse_dx > EXTRA_BORDER)  
     {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,  
                             -priv->drag_mouse_dx - EXTRA_BORDER,  
                             widget->allocation.height);  
     }  
   
     if (priv->drag_mouse_dy>EXTRA_BORDER) {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, 0,  
                             widget->allocation.width,  
                             priv->drag_mouse_dy - EXTRA_BORDER);  
     }  
     else if (-priv->drag_mouse_dy > EXTRA_BORDER)  
     {  
         gdk_draw_rectangle (  
                             widget->window,  
                             widget->style->white_gc,  
                             TRUE,  
                             0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,  
                             widget->allocation.width,  
                             -priv->drag_mouse_dy - EXTRA_BORDER);  
     }  
2127    
2128      return FALSE;      return FALSE;
2129  }  }
# Line 1679  osm_gps_map_configure (GtkWidget *widget Line 2138  osm_gps_map_configure (GtkWidget *widget
2138          g_object_unref (priv->pixmap);          g_object_unref (priv->pixmap);
2139    
2140      priv->pixmap = gdk_pixmap_new (      priv->pixmap = gdk_pixmap_new (
2141                                     widget->window,                          widget->window,
2142                                     widget->allocation.width + EXTRA_BORDER * 2,                          widget->allocation.width + EXTRA_BORDER * 2,
2143                                     widget->allocation.height + EXTRA_BORDER * 2,                          widget->allocation.height + EXTRA_BORDER * 2,
2144                                     -1);                          -1);
2145    
2146    #ifdef ENABLE_OSD
2147    
2148    #ifdef OSD_DOUBLE_BUFFER
2149        if (priv->dbuf_pixmap)
2150            g_object_unref (priv->dbuf_pixmap);
2151    
2152        priv->dbuf_pixmap = gdk_pixmap_new (
2153                            widget->window,
2154                            widget->allocation.width,
2155                            widget->allocation.height,
2156                            -1);
2157    #endif
2158    
2159        /* the osd needs some references to map internal objects */
2160        if(priv->osd)
2161            priv->osd->widget = widget;
2162    #endif
2163    
2164      /* and gc, used for clipping (I think......) */      /* and gc, used for clipping (I think......) */
2165      if(priv->gc_map)      if(priv->gc_map)
# Line 1700  osm_gps_map_expose (GtkWidget *widget, G Line 2177  osm_gps_map_expose (GtkWidget *widget, G
2177  {  {
2178      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);      OsmGpsMapPrivate *priv = OSM_GPS_MAP_PRIVATE(widget);
2179    
2180      gdk_draw_drawable (  #if defined(ENABLE_OSD) && defined(OSD_DOUBLE_BUFFER)
2181                         widget->window,      GdkDrawable *drawable = priv->dbuf_pixmap;
2182    #else
2183        GdkDrawable *drawable = widget->window;
2184    #endif
2185    
2186        if (!priv->dragging)
2187        {
2188            gdk_draw_drawable (drawable,
2189                               widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2190                               priv->pixmap,
2191                               event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,
2192                               event->area.x, event->area.y,
2193                               event->area.width, event->area.height);
2194        }
2195        else
2196        {
2197            gdk_draw_drawable (drawable,
2198                               widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2199                               priv->pixmap,
2200                               0,0,
2201                               priv->drag_mouse_dx - EXTRA_BORDER,
2202                               priv->drag_mouse_dy - EXTRA_BORDER,
2203                               -1,-1);
2204    
2205            //Paint white outside of the map if dragging. Its less
2206            //ugly than painting the corrupted map
2207            if(priv->drag_mouse_dx>EXTRA_BORDER) {
2208                gdk_draw_rectangle (drawable,
2209                                    widget->style->white_gc,
2210                                    TRUE,
2211                                    0, 0,
2212                                    priv->drag_mouse_dx - EXTRA_BORDER,
2213                                    widget->allocation.height);
2214            }
2215            else if (-priv->drag_mouse_dx > EXTRA_BORDER)
2216            {
2217                gdk_draw_rectangle (drawable,
2218                                    widget->style->white_gc,
2219                                    TRUE,
2220                                    priv->drag_mouse_dx + widget->allocation.width + EXTRA_BORDER, 0,
2221                                    -priv->drag_mouse_dx - EXTRA_BORDER,
2222                                    widget->allocation.height);
2223            }
2224    
2225            if (priv->drag_mouse_dy>EXTRA_BORDER) {
2226                gdk_draw_rectangle (drawable,
2227                                    widget->style->white_gc,
2228                                    TRUE,
2229                                    0, 0,
2230                                    widget->allocation.width,
2231                                    priv->drag_mouse_dy - EXTRA_BORDER);
2232            }
2233            else if (-priv->drag_mouse_dy > EXTRA_BORDER)
2234            {
2235                gdk_draw_rectangle (drawable,
2236                                    widget->style->white_gc,
2237                                    TRUE,
2238                                    0, priv->drag_mouse_dy + widget->allocation.height + EXTRA_BORDER,
2239                                    widget->allocation.width,
2240                                    -priv->drag_mouse_dy - EXTRA_BORDER);
2241            }
2242        }
2243    
2244    #ifdef ENABLE_OSD
2245        /* draw new OSD */
2246        if(priv->osd)
2247            priv->osd->draw (priv->osd, drawable);
2248    
2249    #ifdef OSD_DOUBLE_BUFFER
2250        gdk_draw_drawable (widget->window,
2251                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],                         widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
2252                         priv->pixmap,                         priv->dbuf_pixmap,
2253                         event->area.x + EXTRA_BORDER, event->area.y + EXTRA_BORDER,                         0,0,0,0,-1,-1);
2254                         event->area.x, event->area.y,  #endif
                        event->area.width, event->area.height);  
2255    
2256    #endif
2257    
2258      return FALSE;      return FALSE;
2259  }  }
2260    
# Line 1730  osm_gps_map_class_init (OsmGpsMapClass * Line 2277  osm_gps_map_class_init (OsmGpsMapClass *
2277      widget_class->button_press_event = osm_gps_map_button_press;      widget_class->button_press_event = osm_gps_map_button_press;
2278      widget_class->button_release_event = osm_gps_map_button_release;      widget_class->button_release_event = osm_gps_map_button_release;
2279      widget_class->motion_notify_event = osm_gps_map_motion_notify;      widget_class->motion_notify_event = osm_gps_map_motion_notify;
2280      widget_class->scroll_event = _osm_gps_map_scroll;      widget_class->scroll_event = osm_gps_map_scroll_event;
2281    
2282      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
2283                                       PROP_AUTO_CENTER,                                       PROP_AUTO_CENTER,
# Line 1768  osm_gps_map_class_init (OsmGpsMapClass * Line 2315  osm_gps_map_class_init (OsmGpsMapClass *
2315                                       PROP_REPO_URI,                                       PROP_REPO_URI,
2316                                       g_param_spec_string ("repo-uri",                                       g_param_spec_string ("repo-uri",
2317                                                            "repo uri",                                                            "repo uri",
2318                                                            "osm repo uri",                                                            "map source tile repository uri",
2319                                                            "http://tile.openstreetmap.org/#Z/#X/#Y.png",                                                            OSM_REPO_URI,
2320                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2321    
2322      g_object_class_install_property (object_class,       g_object_class_install_property (object_class,
2323                                       PROP_PROXY_URI,                                       PROP_PROXY_URI,
2324                                       g_param_spec_string ("proxy-uri",                                       g_param_spec_string ("proxy-uri",
2325                                                            "proxy uri",                                                            "proxy uri",
# Line 1785  osm_gps_map_class_init (OsmGpsMapClass * Line 2332  osm_gps_map_class_init (OsmGpsMapClass *
2332                                       g_param_spec_string ("tile-cache",                                       g_param_spec_string ("tile-cache",
2333                                                            "tile cache",                                                            "tile cache",
2334                                                            "osm local tile cache dir",                                                            "osm local tile cache dir",
2335                                                            "/tmp/Maps",                                                            NULL,
2336                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2337    
2338      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
                                      PROP_TILE_CACHE_DIR_IS_FULL_PATH,  
                                      g_param_spec_boolean ("tile-cache-is-full-path",  
                                                            "tile cache is full path",  
                                                            "if true, the path passed to tile-cache is interpreted as the full cache path",  
                                                            FALSE,  
                                                            G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));  
   
     g_object_class_install_property (object_class,  
2339                                       PROP_ZOOM,                                       PROP_ZOOM,
2340                                       g_param_spec_int ("zoom",                                       g_param_spec_int ("zoom",
2341                                                         "zoom",                                                         "zoom",
# Line 1813  osm_gps_map_class_init (OsmGpsMapClass * Line 2352  osm_gps_map_class_init (OsmGpsMapClass *
2352                                                         "maximum zoom level",                                                         "maximum zoom level",
2353                                                         MIN_ZOOM, /* minimum property value */                                                         MIN_ZOOM, /* minimum property value */
2354                                                         MAX_ZOOM, /* maximum property value */                                                         MAX_ZOOM, /* maximum property value */
2355                                                         17,                                                         OSM_MAX_ZOOM,
2356                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2357    
2358      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1823  osm_gps_map_class_init (OsmGpsMapClass * Line 2362  osm_gps_map_class_init (OsmGpsMapClass *
2362                                                         "minimum zoom level",                                                         "minimum zoom level",
2363                                                         MIN_ZOOM, /* minimum property value */                                                         MIN_ZOOM, /* minimum property value */
2364                                                         MAX_ZOOM, /* maximum property value */                                                         MAX_ZOOM, /* maximum property value */
2365                                                         1,                                                         OSM_MIN_ZOOM,
2366                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2367    
2368      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1893  osm_gps_map_class_init (OsmGpsMapClass * Line 2432  osm_gps_map_class_init (OsmGpsMapClass *
2432                                                         "radius of the gps point inner circle",                                                         "radius of the gps point inner circle",
2433                                                         0,           /* minimum property value */                                                         0,           /* minimum property value */
2434                                                         G_MAXINT,    /* maximum property value */                                                         G_MAXINT,    /* maximum property value */
2435                                                         5,                                                         10,
2436                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2437    
2438      g_object_class_install_property (object_class,      g_object_class_install_property (object_class,
# Line 1906  osm_gps_map_class_init (OsmGpsMapClass * Line 2445  osm_gps_map_class_init (OsmGpsMapClass *
2445                                                         20,                                                         20,
2446                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));                                                         G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT));
2447    
2448        g_object_class_install_property (object_class,
2449                                         PROP_MAP_SOURCE,
2450                                         g_param_spec_int ("map-source",
2451                                                           "map source",
2452                                                           "map source ID",
2453                                                           -1,           /* minimum property value */
2454                                                           G_MAXINT,    /* maximum property value */
2455                                                           -1,
2456                                                           G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2457    
2458        g_object_class_install_property (object_class,
2459                                         PROP_IMAGE_FORMAT,
2460                                         g_param_spec_string ("image-format",
2461                                                              "image format",
2462                                                              "map source tile repository image format (jpg, png)",
2463                                                              OSM_IMAGE_FORMAT,
2464                                                              G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
2465    }
2466    
2467    const char*
2468    osm_gps_map_source_get_friendly_name(OsmGpsMapSource_t source)
2469    {
2470        switch(source)
2471        {
2472            case OSM_GPS_MAP_SOURCE_NULL:
2473                return "None";
2474            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2475                return "OpenStreetMap";
2476            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2477                return "OpenStreetMap Renderer";
2478            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2479                return "OpenAerialMap";
2480            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2481                return "Maps-For-Free";
2482            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2483                return "Google Maps";
2484            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2485                return "Google Satellite";
2486            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2487                return "Google Hybrid";
2488            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2489                return "Virtual Earth";
2490            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2491                return "Virtual Earth Satellite";
2492            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2493                return "Virtual Earth Hybrid";
2494            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2495                return "Yahoo Maps";
2496            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2497                return "Yahoo Satellite";
2498            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2499                return "Yahoo Hybrid";
2500            default:
2501                return NULL;
2502        }
2503        return NULL;
2504    }
2505    
2506    //http://www.internettablettalk.com/forums/showthread.php?t=5209
2507    //https://garage.maemo.org/plugins/scmsvn/viewcvs.php/trunk/src/maps.c?root=maemo-mapper&view=markup
2508    //http://www.ponies.me.uk/maps/GoogleTileUtils.java
2509    //http://www.mgmaps.com/cache/MapTileCacher.perl
2510    const char*
2511    osm_gps_map_source_get_repo_uri(OsmGpsMapSource_t source)
2512    {
2513        switch(source)
2514        {
2515            case OSM_GPS_MAP_SOURCE_NULL:
2516                return "none://";
2517            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2518                return OSM_REPO_URI;
2519            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2520                return "http://tah.openstreetmap.org/Tiles/tile/#Z/#X/#Y.png";
2521            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2522                return "http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/#Z/#X/#Y.jpg";
2523            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2524                return "http://maps-for-free.com/layer/relief/z#Z/row#Y/#Z_#X-#Y.jpg";
2525            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2526                return "http://mt#R.google.com/vt/v=w2.97&x=#X&y=#Y&z=#Z";
2527            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2528                return "http://khm#R.google.com/kh?n=404&v=3&t=#Q";
2529            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2530                return NULL; /* No longer working  "http://mt#R.google.com/mt?n=404&v=w2t.99&x=#X&y=#Y&zoom=#S" */
2531            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2532                return "http://a#R.ortho.tiles.virtualearth.net/tiles/r#W.jpeg?g=50";
2533            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2534                return "http://a#R.ortho.tiles.virtualearth.net/tiles/a#W.jpeg?g=50";
2535            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2536                return "http://a#R.ortho.tiles.virtualearth.net/tiles/h#W.jpeg?g=50";
2537            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2538            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2539            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2540                /* TODO: Implement signed Y, aka U
2541                 * http://us.maps3.yimg.com/aerial.maps.yimg.com/ximg?v=1.7&t=a&s=256&x=%d&y=%-d&z=%d
2542                 *  x = tilex,
2543                 *  y = (1 << (MAX_ZOOM - zoom)) - tiley - 1,
2544                 *  z = zoom - (MAX_ZOOM - 17));
2545                 */
2546                return NULL;
2547            default:
2548                return NULL;
2549        }
2550        return NULL;
2551    }
2552    
2553    const char *
2554    osm_gps_map_source_get_image_format(OsmGpsMapSource_t source)
2555    {
2556        switch(source) {
2557            case OSM_GPS_MAP_SOURCE_NULL:
2558            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2559            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2560                return "png";
2561            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2562            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2563            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2564            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2565            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2566            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2567            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2568            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2569            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2570            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2571            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2572                return "jpg";
2573            default:
2574                return "bin";
2575        }
2576        return "bin";
2577    }
2578    
2579    
2580    int
2581    osm_gps_map_source_get_min_zoom(OsmGpsMapSource_t source)
2582    {
2583        return 1;
2584    }
2585    
2586    int
2587    osm_gps_map_source_get_max_zoom(OsmGpsMapSource_t source)
2588    {
2589        switch(source) {
2590            case OSM_GPS_MAP_SOURCE_NULL:
2591                return 18;
2592            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP:
2593                return OSM_MAX_ZOOM;
2594            case OSM_GPS_MAP_SOURCE_OPENSTREETMAP_RENDERER:
2595            case OSM_GPS_MAP_SOURCE_OPENAERIALMAP:
2596            case OSM_GPS_MAP_SOURCE_GOOGLE_STREET:
2597            case OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID:
2598            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_STREET:
2599            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_SATELLITE:
2600            case OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID:
2601            case OSM_GPS_MAP_SOURCE_YAHOO_STREET:
2602            case OSM_GPS_MAP_SOURCE_YAHOO_SATELLITE:
2603            case OSM_GPS_MAP_SOURCE_YAHOO_HYBRID:
2604                return 17;
2605            case OSM_GPS_MAP_SOURCE_MAPS_FOR_FREE:
2606                return 11;
2607            case OSM_GPS_MAP_SOURCE_GOOGLE_SATELLITE:
2608                return 18;
2609            default:
2610                return 17;
2611        }
2612        return 17;
2613  }  }
2614    
2615  void  void
# Line 1938  osm_gps_map_download_maps (OsmGpsMap *ma Line 2642  osm_gps_map_download_maps (OsmGpsMap *ma
2642                  for(j=y1; j<=y2; j++)                  for(j=y1; j<=y2; j++)
2643                  {                  {
2644                      // x = i, y = j                      // x = i, y = j
2645                      filename = g_strdup_printf("%s/%u/%u/%u.png", priv->cache_dir, zoom, i, j);                      filename = g_strdup_printf("%s%c%d%c%d%c%d.%s",
2646                      if (!priv->cache_dir || !g_file_test(filename, G_FILE_TEST_EXISTS))                                      priv->cache_dir, G_DIR_SEPARATOR,
2647                                        zoom, G_DIR_SEPARATOR,
2648                                        i, G_DIR_SEPARATOR,
2649                                        j,
2650                                        priv->image_format);
2651                        if (!g_file_test(filename, G_FILE_TEST_EXISTS))
2652                      {                      {
2653                          osm_gps_map_download_tile(map, zoom, i, j, FALSE);                          osm_gps_map_download_tile(map, zoom, i, j, FALSE);
2654                          num_tiles++;                          num_tiles++;
# Line 2001  int Line 2710  int
2710  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)  osm_gps_map_set_zoom (OsmGpsMap *map, int zoom)
2711  {  {
2712      int zoom_old;      int zoom_old;
2713      double factor = 1.0;      double factor = 0.0;
2714      int width_center, height_center;      int width_center, height_center;
2715      OsmGpsMapPrivate *priv;      OsmGpsMapPrivate *priv;
2716    
# Line 2072  osm_gps_map_add_image (OsmGpsMap *map, f Line 2781  osm_gps_map_add_image (OsmGpsMap *map, f
2781          //cache w/h for speed, and add image to list          //cache w/h for speed, and add image to list
2782          im = g_new0(image_t,1);          im = g_new0(image_t,1);
2783          im->w = gdk_pixbuf_get_width(image);          im->w = gdk_pixbuf_get_width(image);
2784          im->h = gdk_pixbuf_get_width(image);          im->h = gdk_pixbuf_get_height(image);
2785          im->pt.rlat = deg2rad(latitude);          im->pt.rlat = deg2rad(latitude);
2786          im->pt.rlon = deg2rad(longitude);          im->pt.rlon = deg2rad(longitude);
2787    
# Line 2085  osm_gps_map_add_image (OsmGpsMap *map, f Line 2794  osm_gps_map_add_image (OsmGpsMap *map, f
2794      }      }
2795  }  }
2796    
2797  void  gboolean
2798  osm_gps_map_clear_images (OsmGpsMap *map)  osm_gps_map_remove_image (OsmGpsMap *map, GdkPixbuf *image)
2799  {  {
2800      g_return_if_fail (OSM_IS_GPS_MAP (map));      OsmGpsMapPrivate *priv = map->priv;
2801        if (priv->images) {
2802      osm_gps_map_free_images(map);          GSList *list;
2803      osm_gps_map_map_redraw_idle(map);          for(list = priv->images; list != NULL; list = list->next)
2804            {
2805                image_t *im = list->data;
2806                    if (im->image == image)
2807                    {
2808                            priv->images = g_slist_remove_link(priv->images, list);
2809                            g_object_unref(im->image);
2810                            g_free(im);
2811                            osm_gps_map_map_redraw_idle(map);
2812                            return TRUE;
2813                    }
2814            }
2815        }
2816        return FALSE;
2817  }  }
2818    
2819  void  void
2820  osm_gps_map_osd_speed (OsmGpsMap *map, float speed)  osm_gps_map_clear_images (OsmGpsMap *map)
2821  {  {
     OsmGpsMapPrivate *priv;  
   
     PangoContext        *context = NULL;  
     PangoLayout     *layout  = NULL;  
     PangoFontDescription    *desc    = NULL;  
   
     GdkColor color;  
     GdkGC *gc;  
   
     gchar *buffer;  
     //static int x = 10, y = 10;  
     static int width = 0, height = 0;  
   
2822      g_return_if_fail (OSM_IS_GPS_MAP (map));      g_return_if_fail (OSM_IS_GPS_MAP (map));
     priv = map->priv;  
   
     buffer = g_strdup_printf("%.0f", speed);  
   
     /* pango initialisation */  
     context = gtk_widget_get_pango_context (GTK_WIDGET(map));  
     layout  = pango_layout_new (context);  
     desc    = pango_font_description_new();  
   
     pango_font_description_set_size (desc, 40 * PANGO_SCALE);  
     pango_layout_set_font_description (layout, desc);  
     pango_layout_set_text (layout, buffer, strlen(buffer));  
   
     gc = gdk_gc_new (GTK_WIDGET(map)->window);  
   
     color.red = (0 > 50) ? 0xffff : 0;  
     color.green = 0;  
     color.blue = 0;  
2823    
2824      gdk_gc_set_rgb_fg_color (gc, &color);      osm_gps_map_free_images(map);
2825        osm_gps_map_map_redraw_idle(map);
     /* faster / less flicker alternative:*/  
     gdk_draw_drawable (  
                        GTK_WIDGET(map)->window,  
                        GTK_WIDGET(map)->style->fg_gc[GTK_WIDGET_STATE(map)],  
                        priv->pixmap,  
                        0,0,  
                        0,0,  
                        width+10,width+10);  
   
     gdk_draw_layout(GTK_WIDGET(map)->window,  
                     gc,  
                     0, 0,  
                     layout);  
   
     /* set width and height */  
     pango_layout_get_pixel_size(layout, &width, &height);  
   
     g_free(buffer);  
     pango_font_description_free (desc);  
     g_object_unref (layout);  
     g_object_unref (gc);  
2826  }  }
2827    
2828  void  void
# Line 2276  osm_gps_map_scroll (OsmGpsMap *map, gint Line 2946  osm_gps_map_scroll (OsmGpsMap *map, gint
2946      osm_gps_map_map_redraw_idle (map);      osm_gps_map_map_redraw_idle (map);
2947  }  }
2948    
2949    float
2950    osm_gps_map_get_scale(OsmGpsMap *map)
2951    {
2952        OsmGpsMapPrivate *priv;
2953    
2954        g_return_val_if_fail (OSM_IS_GPS_MAP (map), OSM_NAN);
2955        priv = map->priv;
2956    
2957        return osm_gps_map_get_scale_at_point(priv->map_zoom, priv->center_rlat, priv->center_rlon);
2958    }
2959    
2960    #ifdef ENABLE_BALLOON
2961    void
2962    osm_gps_map_draw_balloon (OsmGpsMap *map, float latitude, float longitude,
2963                              OsmGpsMapBalloonCallback cb, gpointer data)
2964    {
2965        OsmGpsMapPrivate *priv;
2966    
2967        /* remove and previously installed balloon */
2968        osm_gps_map_clear_balloon (map);
2969    
2970        g_return_if_fail (OSM_IS_GPS_MAP (map));
2971        priv = map->priv;
2972    
2973        priv->balloon.coo->rlat = deg2rad(latitude);
2974        priv->balloon.coo->rlon = deg2rad(longitude);
2975        priv->balloon.valid = TRUE;
2976    
2977        priv->balloon.cb = cb;
2978        priv->balloon.data = data;
2979    
2980        // this redraws the map
2981        osm_gps_map_map_redraw_idle(map);
2982    }
2983    
2984    void
2985    osm_gps_map_clear_balloon (OsmGpsMap *map)
2986    {
2987        OsmGpsMapPrivate *priv;
2988    
2989        g_return_if_fail (OSM_IS_GPS_MAP (map));
2990        priv = map->priv;
2991    
2992        priv->balloon.valid = FALSE;
2993    
2994        osm_gps_map_map_redraw_idle(map);
2995    }
2996    #endif
2997    
2998    #ifdef ENABLE_OSD
2999    
3000    void
3001    osm_gps_map_redraw (OsmGpsMap *map)
3002    {
3003        osm_gps_map_map_redraw_idle(map);
3004    }
3005    
3006    osm_gps_map_osd_t *osm_gps_map_osd_get(OsmGpsMap *map) {
3007        g_return_val_if_fail (OSM_IS_GPS_MAP (map), NULL);
3008        return map->priv->osd;
3009    }
3010    
3011    void osm_gps_map_register_osd(OsmGpsMap *map, osm_gps_map_osd_t *osd) {
3012        OsmGpsMapPrivate *priv;
3013    
3014        g_return_if_fail (OSM_IS_GPS_MAP (map));
3015    
3016        priv = map->priv;
3017        g_return_if_fail (!priv->osd);
3018    
3019        priv->osd = osd;
3020    }
3021    
3022    #endif

Legend:
Removed from v.32  
changed lines
  Added in v.83