2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <gdk/gdkkeysyms.h>
21 #include "grits-util.h"
22 #include "data/grits-wms.h"
23 #include "objects/grits-tile.h"
32 void chunk_callback(gsize cur, gsize total, gpointer _state)
34 struct CacheState *state = _state;
35 g_message("chunk_callback: %ld/%ld", (glong)cur, (glong)total);
37 if (state->progress == NULL) {
38 state->progress = gtk_progress_bar_new();
39 gtk_box_pack_end(GTK_BOX(state->status), state->progress, FALSE, FALSE, 0);
40 gtk_widget_show(state->progress);
44 gtk_widget_destroy(state->progress);
46 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(state->progress), (gdouble)cur/total);
49 gpointer do_bmng_cache(gpointer _image)
51 GtkImage *image = _image;
52 g_message("Creating bmng tile");
53 GritsTile *tile = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
54 tile->children[0][1] = grits_tile_new(tile, NORTH, 0, 0, WEST);
55 tile = tile->children[0][1];
57 g_message("Fetching bmng image");
58 GritsWms *bmng_wms = grits_wms_new(
59 "http://www.nasa.network.com/wms", "bmng200406", "image/jpeg",
60 "bmng_test/", "jpg", 512, 256);
61 const char *path = grits_wms_fetch(bmng_wms, tile, GRITS_ONCE, NULL, NULL);
63 g_message("Loading bmng image: [%s]", path);
64 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
66 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
69 g_message("Cleaning bmng up");
70 grits_wms_free(bmng_wms);
71 grits_tile_free(tile, NULL, NULL);
75 gpointer do_osm_cache(gpointer _image)
77 GtkImage *image = _image;
78 g_message("Creating osm tile");
79 GritsTile *tile = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
80 tile->children[0][1] = grits_tile_new(tile, NORTH, 0, 0, WEST);
81 tile = tile->children[0][1];
83 g_message("Fetching osm image");
84 GritsWms *osm_wms = grits_wms_new(
85 "http://labs.metacarta.com/wms/vmap0", "basic", "image/png",
86 "osm_test/", "png", 512, 256);
87 const char *path = grits_wms_fetch(osm_wms, tile, GRITS_ONCE, NULL, NULL);
89 g_message("Loading osm image: [%s]", path);
90 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
92 gtk_image_set_from_pixbuf(GTK_IMAGE(image), pixbuf);
95 g_message("Cleaning osm up");
96 grits_wms_free(osm_wms);
97 grits_tile_free(tile, NULL, NULL);
101 gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
103 if (event->keyval == GDK_q)
108 int main(int argc, char **argv)
112 gtk_init(&argc, &argv);
114 GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
115 GtkWidget *vbox1 = gtk_vbox_new(FALSE, 0);
116 GtkWidget *vbox2 = gtk_vbox_new(FALSE, 0);
117 GtkWidget *status = gtk_statusbar_new();
118 GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
119 GtkWidget *bmng_image = gtk_image_new();
120 GtkWidget *srtm_image = gtk_image_new();
121 GtkWidget *osm_image = gtk_image_new();
122 gtk_container_add(GTK_CONTAINER(win), vbox1);
123 gtk_box_pack_start(GTK_BOX(vbox1), scroll, TRUE, TRUE, 0);
124 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox2);
125 gtk_box_pack_start(GTK_BOX(vbox2), bmng_image, TRUE, TRUE, 0);
126 gtk_box_pack_start(GTK_BOX(vbox2), srtm_image, TRUE, TRUE, 0);
127 gtk_box_pack_start(GTK_BOX(vbox2), osm_image, TRUE, TRUE, 0);
128 gtk_box_pack_start(GTK_BOX(vbox1), status, FALSE, FALSE, 0);
129 g_signal_connect(win, "key-press-event", G_CALLBACK(key_press_cb), NULL);
130 g_signal_connect(win, "destroy", gtk_main_quit, NULL);
131 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
132 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
134 g_thread_create(do_bmng_cache, bmng_image, FALSE, NULL);
135 g_thread_create(do_osm_cache, osm_image, FALSE, NULL);
137 gtk_widget_show_all(win);