]> saetta.ns0.it Git - libgtkmapserver/commitdiff
Added function ::set_home (and showing the home map).
authorAndrea Zagli <andrea.zagli@email.it>
Tue, 18 Aug 2015 20:08:17 +0000 (22:08 +0200)
committerAndrea Zagli <andrea.zagli@email.it>
Tue, 18 Aug 2015 20:08:17 +0000 (22:08 +0200)
src/gtkmapserver.c
src/gtkmapserver.h
tests/gtkmapserver.c

index 59519d6e5199e9ffb9f9850c66ce49732cf074a5..cb55098df966ebce6fc0b44eb9cf280f5e00a34d 100644 (file)
@@ -32,6 +32,8 @@
        #include <windows.h>
 #endif
 
+#include <libsoup/soup.h>
+
 #include "gtkmapserver.h"
 
 static void gtk_mapserver_class_init (GtkMapserverClass *klass);
@@ -51,7 +53,9 @@ static void gtk_mapserver_get_property (GObject *object,
 typedef struct _GtkMapserverPrivate GtkMapserverPrivate;
 struct _GtkMapserverPrivate
        {
-               gpointer nothing;
+               GooCanvasItem *root;
+               GooCanvasItem *img;
+               SoupSession *soup_session;
        };
 
 G_DEFINE_TYPE (GtkMapserver, gtk_mapserver, GOO_TYPE_CANVAS)
@@ -90,6 +94,8 @@ static void
 gtk_mapserver_init (GtkMapserver *gtk_mapserver)
 {
        GtkMapserverPrivate *priv = GTK_MAPSERVER_GET_PRIVATE (gtk_mapserver);
+
+       priv->img = NULL;
 }
 
 GtkWidget
@@ -138,16 +144,85 @@ GtkWidget
                                  "background-color", "white",
                                  NULL);
 
-       GooCanvasItem *root = goo_canvas_get_root_item (GOO_CANVAS (gtk_mapserver));
+       priv->root = goo_canvas_get_root_item (GOO_CANVAS (gtk_mapserver));
+
+       priv->img = goo_canvas_image_new (priv->root,
+                                                                         NULL,
+                                                                         0, 0,
+                                                                         NULL);
 
-       /* Add a few simple items. */
-       goo_canvas_path_new (root,
-                                               "M 100 100 L 500 100 L 500 500 L 100 500 z",
-                               NULL);
+       /* Soup */
+       priv->soup_session = soup_session_sync_new_with_options (SOUP_SESSION_SSL_CA_FILE, NULL,
+                                                                                                                        SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_CONTENT_DECODER,
+                                                                                                                        SOUP_SESSION_ADD_FEATURE_BY_TYPE, SOUP_TYPE_COOKIE_JAR,
+                                                                                                                        SOUP_SESSION_USER_AGENT, "get ",
+                                                                                                                        SOUP_SESSION_ACCEPT_LANGUAGE_AUTO, TRUE,
+                                                                                                                        SOUP_SESSION_USE_NTLM, FALSE,
+                                                                                                                        NULL);
 
        return gtk_mapserver;
 }
 
+void
+gtk_mapserver_set_home (GtkMapserver *gtkm,
+                                               const gchar *url)
+{
+       GError *error;
+       SoupMessage *msg;
+       GdkPixbufLoader *pxb_loader;
+
+       GtkMapserverPrivate *priv = GTK_MAPSERVER_GET_PRIVATE (gtkm);
+
+       msg = soup_message_new (SOUP_METHOD_GET, url);
+       if (SOUP_IS_MESSAGE (msg))
+               {
+                       soup_message_set_flags (msg, SOUP_MESSAGE_NO_REDIRECT);
+                       soup_session_send_message (priv->soup_session, msg);
+               }
+
+       if (!SOUP_IS_MESSAGE (msg) || !SOUP_STATUS_IS_SUCCESSFUL (msg->status_code))
+               {
+                       g_warning ("Error on retrieving url.");
+                       pxb_loader = NULL;
+               }
+       else
+               {
+                       error = NULL;
+                       pxb_loader = gdk_pixbuf_loader_new ();
+                       if (!gdk_pixbuf_loader_write (pxb_loader,
+                                                                                 msg->response_body->data,
+                                                                                 msg->response_body->length,
+                                                                                 &error)
+                               || error != NULL)
+                               {
+                                       g_warning ("Error on retrieving map image: %s.",
+                                                          error != NULL && error->message != NULL ? error->message : "no details");
+                                       g_object_unref (pxb_loader);
+                                       pxb_loader = NULL;
+                               }
+                       else
+                               {
+                                       gdk_pixbuf_loader_close (pxb_loader, NULL);
+                               }
+               }
+       g_object_unref (msg);
+       if (pxb_loader != NULL)
+               {
+                       g_object_set (G_OBJECT (priv->img),
+                                                 "pixbuf", gdk_pixbuf_loader_get_pixbuf (pxb_loader),
+                                                 NULL);
+
+                       g_object_unref (pxb_loader);
+                       pxb_loader = NULL;
+               }
+       else
+               {
+                       g_object_set (G_OBJECT (priv->img),
+                                                 "pixbuf", NULL,
+                                                 NULL);
+               }
+}
+
 /* PRIVATE */
 static void
 gtk_mapserver_set_property (GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
index 4d572f86b3bde484d0ade869ee35ef23cdfe045f..0d50ceecf492e9985a10ed2e6f05dfeaec0138fc 100644 (file)
@@ -59,6 +59,8 @@ GType gtk_mapserver_get_type (void) G_GNUC_CONST;
 
 GtkWidget *gtk_mapserver_new (void);
 
+void gtk_mapserver_set_home (GtkMapserver *gtkm, const gchar *url);
+
 
 G_END_DECLS
 
index 9b556bbdccc287dc7274a6f8924a482c85ddda68..762551f35824997616e18c5f2dc554618f37de81 100644 (file)
@@ -51,6 +51,8 @@ main (int argc, char **argv)
 
        gtk_widget_show_all (window);
 
+       gtk_mapserver_set_home (GTK_MAPSERVER (gtkmap), "http://atlante/cgi-bin/mapserv?map=/var/www_mapper/www_pm4/config/cdu/RU_cdu.map&mode=map&layers=catasto");
+
        /* Pass control to the GTK+ main event loop. */
        gtk_main ();