diff options
author | Giovanni Campagna <gcampagna@src.gnome.org> | 2013-08-16 22:16:54 +0200 |
---|---|---|
committer | Jiří Techet <techet@gmail.com> | 2013-08-19 19:36:06 +0200 |
commit | 3adb78f718e63aeb3ca5c15b59c1469f8cbc9e12 (patch) | |
tree | 1681c907001a36b23cdd8fb5ce80e55ff3acbd9c /demos/launcher-gtk.c | |
parent | 801b23da32e51c0f146329efa199a8488db2236d (diff) | |
download | libchamplain-3adb78f718e63aeb3ca5c15b59c1469f8cbc9e12.tar.gz |
Add demo of the new overlay sources
Allow to add overlay sources in the demo app.
https://bugzilla.gnome.org/show_bug.cgi?id=704645
Diffstat (limited to 'demos/launcher-gtk.c')
-rw-r--r-- | demos/launcher-gtk.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/demos/launcher-gtk.c b/demos/launcher-gtk.c index 730f237..80fbdcd 100644 --- a/demos/launcher-gtk.c +++ b/demos/launcher-gtk.c @@ -210,13 +210,65 @@ append_point (ChamplainPathLayer *layer, gdouble lon, gdouble lat) champlain_path_layer_add_node (layer, CHAMPLAIN_LOCATION (coord)); } +static void +add_clicked (GtkButton *button, + ChamplainView *view) +{ + GtkWidget *window, *dialog, *vbox, *combo; + GtkResponseType response; + + window = g_object_get_data (G_OBJECT (view), "window"); + dialog = gtk_dialog_new_with_buttons ("Add secondary map source", + GTK_WINDOW (window), + GTK_DIALOG_MODAL, + "Add", + GTK_RESPONSE_OK, + "Cancel", + GTK_RESPONSE_CANCEL, + NULL); + + combo = gtk_combo_box_new (); + build_combo_box (GTK_COMBO_BOX (combo)); + gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0); + + vbox = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); + gtk_container_add (GTK_CONTAINER (vbox), combo); + + gtk_widget_show_all (dialog); + + response = gtk_dialog_run (GTK_DIALOG (dialog)); + + if (response == GTK_RESPONSE_OK) { + GtkTreeModel *model; + GtkTreeIter iter; + ChamplainMapSource *source; + ChamplainMapSourceFactory *factory; + char *id; + + if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)) + return; + + model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo)); + + gtk_tree_model_get (model, &iter, COL_ID, &id, -1); + + factory = champlain_map_source_factory_dup_default (); + source = champlain_map_source_factory_create_memcached_source (factory, id); + + champlain_view_add_overlay_source (view, source, 0.6 * 255); + g_object_unref (factory); + g_free (id); + } + + gtk_widget_destroy (dialog); +} int main (int argc, char *argv[]) { GtkWidget *window; - GtkWidget *widget, *vbox, *bbox, *button, *viewport; + GtkWidget *widget, *vbox, *bbox, *button, *image, *viewport; ChamplainView *view; ChamplainMarkerLayer *layer; ClutterActor *scale; @@ -253,6 +305,8 @@ main (int argc, "kinetic-mode", TRUE, "zoom-level", 5, NULL); + + g_object_set_data (G_OBJECT (view), "window", window); scale = champlain_scale_new (); champlain_scale_connect_view (CHAMPLAIN_SCALE (scale), view); @@ -316,6 +370,12 @@ main (int argc, button); gtk_container_add (GTK_CONTAINER (bbox), button); + button = gtk_button_new (); + image = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_LARGE_TOOLBAR); + gtk_container_add (GTK_CONTAINER (button), image); + g_signal_connect (button, "clicked", G_CALLBACK (add_clicked), view); + gtk_container_add (GTK_CONTAINER (bbox), button); + button = gtk_image_new (); gtk_widget_set_size_request (button, 22, -1); g_signal_connect (view, "notify::state", G_CALLBACK (view_state_changed), |