+static void maps_layer_redownload_new ( VikMapsLayer *vml )
+{
+ start_download_thread ( vml, vml->redownload_vvp, &(vml->redownload_ul), &(vml->redownload_br), REDOWNLOAD_NEW );
+}
+
+/**
+ * Display a simple dialog with information about this particular map tile
+ */
+static void maps_layer_tile_info ( VikMapsLayer *vml )
+{
+ VikMapSource *map = MAPS_LAYER_NTH_TYPE(vml->maptype);
+
+ gdouble xzoom = vml->xmapzoom ? vml->xmapzoom : vik_viewport_get_xmpp ( vml->redownload_vvp );
+ gdouble yzoom = vml->ymapzoom ? vml->ymapzoom : vik_viewport_get_ympp ( vml->redownload_vvp );
+ MapCoord ulm;
+
+ if ( !vik_map_source_coord_to_mapcoord ( map, &(vml->redownload_ul), xzoom, yzoom, &ulm ) )
+ return;
+
+ gchar *filename = NULL;
+ gchar *source = NULL;
+
+ if ( vik_map_source_is_direct_file_access ( map ) ) {
+ if ( vik_map_source_is_mbtiles ( map ) ) {
+ filename = g_strdup ( vml->filename );
+#ifdef HAVE_SQLITE3_H
+ // And whether to bother going into the SQL to check it's really there or not...
+ gchar *exists = NULL;
+ gint zoom = 17 - ulm.scale;
+ if ( vml->mbtiles ) {
+ GdkPixbuf *pixbuf = get_pixbuf_sql_exec ( vml->mbtiles, ulm.x, ulm.y, zoom );
+ if ( pixbuf ) {
+ exists = g_strdup ( _("YES") );
+ g_object_unref ( G_OBJECT(pixbuf) );
+ }
+ else {
+ exists = g_strdup ( _("NO") );
+ }
+ }
+ else
+ exists = g_strdup ( _("NO") );
+ gint flip_y = (gint) pow(2, zoom)-1 - ulm.y;
+ // NB Also handles .jpg automatically due to pixbuf_new_from () support - although just print png for now.
+ source = g_strdup_printf ( "Source: %s (%d%s%d%s%d.%s %s)", filename, zoom, G_DIR_SEPARATOR_S, ulm.x, G_DIR_SEPARATOR_S, flip_y, "png", exists );
+ g_free ( exists );
+#else
+ source = g_strdup ( _("Source: Not available") );
+#endif
+ }
+ else if ( vik_map_source_is_osm_meta_tiles ( map ) ) {
+ char path[PATH_MAX];
+ xyz_to_meta(path, sizeof(path), vml->cache_dir, ulm.x, ulm.y, 17-ulm.scale );
+ source = g_strdup ( path );
+ filename = g_strdup ( path );
+ }
+ else {
+ guint max_path_len = strlen(vml->cache_dir) + 40;
+ filename = g_malloc ( max_path_len * sizeof(char) );
+ get_filename ( vml->cache_dir, VIK_MAPS_CACHE_LAYOUT_OSM,
+ vik_map_source_get_uniq_id(map),
+ NULL,
+ ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len,
+ vik_map_source_get_file_extension(map) );
+ source = g_strconcat ( "Source: file://", filename, NULL );
+ }
+ }
+ else {
+ guint max_path_len = strlen(vml->cache_dir) + 40;
+ filename = g_malloc ( max_path_len * sizeof(char) );
+ get_filename ( vml->cache_dir, vml->cache_layout,
+ vik_map_source_get_uniq_id(map),
+ vik_map_source_get_name(map),
+ ulm.scale, ulm.z, ulm.x, ulm.y, filename, max_path_len,
+ vik_map_source_get_file_extension(map) );
+ source = g_strdup_printf ( "Source: http://%s%s",
+ vik_map_source_default_get_hostname ( VIK_MAP_SOURCE_DEFAULT(map) ),
+ vik_map_source_default_get_uri ( VIK_MAP_SOURCE_DEFAULT(map), &ulm ) );
+ }
+
+ GArray *array = g_array_new (FALSE, TRUE, sizeof(gchar*));
+ g_array_append_val ( array, source );
+
+ gchar *filemsg = NULL;
+ gchar *timemsg = NULL;
+
+ if ( g_file_test ( filename, G_FILE_TEST_EXISTS ) ) {
+ filemsg = g_strconcat ( "Tile File: ", filename, NULL );
+ // Get some timestamp information of the tile
+ struct stat stat_buf;
+ if ( g_stat ( filename, &stat_buf ) == 0 ) {
+ gchar time_buf[64];
+ strftime ( time_buf, sizeof(time_buf), "%c", gmtime((const time_t *)&stat_buf.st_mtime) );
+ timemsg = g_strdup_printf ( _("Tile File Timestamp: %s"), time_buf );
+ }
+ else {
+ timemsg = g_strdup ( _("Tile File Timestamp: Not Available") );
+ }
+ g_array_append_val ( array, filemsg );
+ g_array_append_val ( array, timemsg );
+ }
+ else {
+ filemsg = g_strdup_printf ( "Tile File: %s [Not Available]", filename );
+ g_array_append_val ( array, filemsg );
+ }
+
+ a_dialog_list ( VIK_GTK_WINDOW_FROM_LAYER(vml), _("Tile Information"), array, 5 );
+ g_array_free ( array, FALSE );
+
+ g_free ( timemsg );
+ g_free ( filemsg );
+ g_free ( source );
+ g_free ( filename );
+}
+