]> Pileus Git - grits/blobdiff - src/tile-test.c
Remove deprecated thread functions
[grits] / src / tile-test.c
index 66e105d1ed499f32bc5a35fbb0d78c662a1bebb5..aeb01ff7dd939415911edaebc7300add854c2523 100644 (file)
 #include <gtk/gtk.h>
 #include <gdk/gdkkeysyms.h>
 
-#include "gis-util.h"
-#include "data/gis-wms.h"
-#include "objects/gis-tile.h"
+#include "grits-util.h"
+#include "data/grits-wms.h"
+#include "data/grits-tms.h"
+#include "objects/grits-tile.h"
 
 struct CacheState {
        GtkWidget *image;
@@ -32,7 +33,7 @@ struct CacheState {
 void chunk_callback(gsize cur, gsize total, gpointer _state)
 {
        struct CacheState *state = _state;
-       g_message("chunk_callback: %d/%d", cur, total);
+       g_message("chunk_callback: %ld/%ld", (glong)cur, (glong)total);
 
        if (state->progress == NULL) {
                state->progress = gtk_progress_bar_new();
@@ -50,15 +51,15 @@ gpointer do_bmng_cache(gpointer _image)
 {
        GtkImage *image = _image;
        g_message("Creating bmng tile");
-       GisTile *tile = gis_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
-       tile->children[0][1] = gis_tile_new(tile, NORTH, 0, 0, WEST);
+       GritsTile *tile = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
+       tile->children[0][1] = grits_tile_new(tile, NORTH, 0, 0, WEST);
        tile = tile->children[0][1];
 
        g_message("Fetching bmng image");
-       GisWms *bmng_wms = gis_wms_new(
+       GritsWms *bmng_wms = grits_wms_new(
                "http://www.nasa.network.com/wms", "bmng200406", "image/jpeg",
                "bmng_test/", "jpg", 512, 256);
-       const char *path = gis_wms_fetch(bmng_wms, tile, GIS_ONCE, NULL, NULL);
+       const char *path = grits_wms_fetch(bmng_wms, tile, GRITS_ONCE, NULL, NULL);
 
        g_message("Loading bmng image: [%s]", path);
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
@@ -67,8 +68,8 @@ gpointer do_bmng_cache(gpointer _image)
        gdk_threads_leave();
 
        g_message("Cleaning bmng up");
-       gis_wms_free(bmng_wms);
-       gis_tile_free(tile, NULL, NULL);
+       grits_wms_free(bmng_wms);
+       grits_tile_free(tile, NULL, NULL);
        return NULL;
 }
 
@@ -76,15 +77,15 @@ gpointer do_osm_cache(gpointer _image)
 {
        GtkImage *image = _image;
        g_message("Creating osm tile");
-       GisTile *tile = gis_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
-       tile->children[0][1] = gis_tile_new(tile, NORTH, 0, 0, WEST);
+       GritsTile *tile = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
+       tile->children[0][1] = grits_tile_new(tile, NORTH, 0, 0, WEST);
        tile = tile->children[0][1];
 
        g_message("Fetching osm image");
-       GisWms *osm_wms = gis_wms_new(
+       GritsWms *osm_wms = grits_wms_new(
                "http://labs.metacarta.com/wms/vmap0", "basic", "image/png",
                "osm_test/", "png", 512, 256);
-       const char *path = gis_wms_fetch(osm_wms, tile, GIS_ONCE, NULL, NULL);
+       const char *path = grits_wms_fetch(osm_wms, tile, GRITS_ONCE, NULL, NULL);
 
        g_message("Loading osm image: [%s]", path);
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
@@ -93,11 +94,37 @@ gpointer do_osm_cache(gpointer _image)
        gdk_threads_leave();
 
        g_message("Cleaning osm up");
-       gis_wms_free(osm_wms);
-       gis_tile_free(tile, NULL, NULL);
+       grits_wms_free(osm_wms);
+       grits_tile_free(tile, NULL, NULL);
        return NULL;
 }
 
+gpointer do_osm2_cache(gpointer _image)
+{
+       GtkImage *image = _image;
+       g_message("Creating osm2 tile");
+       GritsTile *tile = grits_tile_new(NULL, 85.0511, -85.0511, EAST, WEST);
+       tile->children[0][1] = grits_tile_new(tile, 85.0511, 0, 0, WEST);
+       tile = tile->children[0][1];
+
+       g_message("Fetching osm2 image");
+       GritsTms *osm2_tms = grits_tms_new("http://tile.openstreetmap.org",
+                       "tms_test/", "png");
+       const char *path = grits_tms_fetch(osm2_tms, tile, GRITS_ONCE, NULL, NULL);
+
+       g_message("Loading osm2 image: [%s]", path);
+       GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
+       gdk_threads_enter();
+       gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
+       gdk_threads_leave();
+
+       g_message("Cleaning osm2 up");
+       grits_tms_free(osm2_tms);
+       grits_tile_free(tile, NULL, NULL);
+       return NULL;
+}
+
+
 gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 {
        if (event->keyval == GDK_q)
@@ -107,7 +134,6 @@ gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
 
 int main(int argc, char **argv)
 {
-       g_thread_init(NULL);
        gdk_threads_init();
        gtk_init(&argc, &argv);
 
@@ -119,20 +145,23 @@ int main(int argc, char **argv)
        GtkWidget *bmng_image = gtk_image_new();
        GtkWidget *srtm_image = gtk_image_new();
        GtkWidget *osm_image  = gtk_image_new();
+       GtkWidget *osm2_image = gtk_image_new();
        gtk_container_add(GTK_CONTAINER(win), vbox1);
        gtk_box_pack_start(GTK_BOX(vbox1), scroll, TRUE, TRUE, 0);
        gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox2);
        gtk_box_pack_start(GTK_BOX(vbox2), bmng_image, TRUE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(vbox2), srtm_image, TRUE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(vbox2), osm_image,  TRUE, TRUE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox2), osm2_image, TRUE, TRUE, 0);
        gtk_box_pack_start(GTK_BOX(vbox1), status, FALSE, FALSE, 0);
        g_signal_connect(win, "key-press-event", G_CALLBACK(key_press_cb), NULL);
        g_signal_connect(win, "destroy", gtk_main_quit, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 
-       g_thread_create(do_bmng_cache, bmng_image, FALSE, NULL);
-       g_thread_create(do_osm_cache,  osm_image,  FALSE, NULL);
+       g_thread_new("bmng-thread", do_bmng_cache, bmng_image);
+       g_thread_new("osm-thread",  do_osm_cache,  osm_image);
+       g_thread_new("osm2-thread", do_osm2_cache, osm2_image);
 
        gtk_widget_show_all(win);
        gtk_main();