]> err.no Git - libchamplain/commitdiff
Offline mode
authorPierre-Luc Beaudoin <pierre-luc@squidy.info>
Thu, 28 Aug 2008 18:47:45 +0000 (14:47 -0400)
committerroot <root@carbon.(none)>
Thu, 28 Aug 2008 18:47:45 +0000 (14:47 -0400)
champlain/champlainview.c
champlain/error.svg [new file with mode: 0644]
champlain/map.c
champlain/map.h
champlain/tile.c

index 8ec6305d96d6cfbb63be9a8311cd80ded35ec713..698a358186f96e2f613d6b18f4003f5b45177146 100644 (file)
@@ -49,12 +49,14 @@ enum
   PROP_LONGITUDE,
   PROP_LATITUDE,
   PROP_ZOOM_LEVEL,
-  PROP_MAP_SOURCE
+  PROP_MAP_SOURCE,
+  PROP_OFFLINE
 };
 
 static guint champlain_view_signals[LAST_SIGNAL] = { 0, };
 
 #define CHAMPLAIN_VIEW_GET_PRIVATE(obj)    (G_TYPE_INSTANCE_GET_PRIVATE((obj), CHAMPLAIN_TYPE_VIEW, ChamplainViewPrivate))
+
 #define CHAMPLAIN_PARAM_READABLE     \
         (G_PARAM_READABLE |     \
          G_PARAM_STATIC_NICK | G_PARAM_STATIC_NAME | G_PARAM_STATIC_BLURB)
@@ -74,6 +76,8 @@ struct _ChamplainViewPrivate
   ClutterActor *fingerScroll;
   GdkRectangle viewportSize;
   Map *map;
+
+  gboolean offline;
 };
 
 
@@ -160,6 +164,9 @@ champlain_view_get_property(GObject* object, guint prop_id, GValue* value, GPara
         case PROP_MAP_SOURCE:
           g_value_set_int(value, priv->mapSource);
           break;
+        case PROP_OFFLINE:
+          g_value_set_boolean(value, priv->offline);
+          break;
         default:
           G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
       }
@@ -232,12 +239,14 @@ champlain_view_set_property(GObject* object, guint prop_id, const GValue* value,
                   currentLevel = priv->map->zoom_levels;
                   
                 map_load_level(priv->map, currentLevel);
-                map_load_visible_tiles (priv->map, priv->viewportSize);
+                map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
                 clutter_container_add_actor (CLUTTER_CONTAINER (priv->viewport), priv->map->current_level->group);
               }
             }
           break;
         }
+      case PROP_OFFLINE:
+        priv->offline = g_value_get_boolean(value);
         break;
       default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
@@ -304,12 +313,12 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass)
   */
   g_object_class_install_property(objectClass, PROP_ZOOM_LEVEL,
                                   g_param_spec_int("zoom-level",
-                                                     "Zoom level",
-                                                     "The level of zoom of the map",
-                                                     0,
-                                                     20,
-                                                     1.0f,
-                                                     CHAMPLAIN_PARAM_READWRITE));
+                                                   "Zoom level",
+                                                   "The level of zoom of the map",
+                                                   0,
+                                                   20,
+                                                   1.0f,
+                                                   CHAMPLAIN_PARAM_READWRITE));
 
 
   /**
@@ -321,26 +330,40 @@ champlain_view_class_init (ChamplainViewClass *champlainViewClass)
   */
    g_object_class_install_property(objectClass, PROP_MAP_SOURCE,
                                   g_param_spec_int("map-source",
-                                                     "Map source",
-                                                     "The map source being displayed",
-                                                     0,
-                                                     CHAMPLAIN_MAP_SOURCE_COUNT,
-                                                     CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP,
-                                                     CHAMPLAIN_PARAM_READWRITE)); 
+                                                   "Map source",
+                                                   "The map source being displayed",
+                                                   0,
+                                                   CHAMPLAIN_MAP_SOURCE_COUNT,
+                                                   CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP,
+                                                   CHAMPLAIN_PARAM_READWRITE)); 
+
+  /**
+  * ChamplainView:offline:
+  *
+  * If true, will fetch tiles from the Internet, otherwise, will only use cached content.
+  *
+  * Since: 0.2
+  */
+   g_object_class_install_property(objectClass, PROP_OFFLINE,
+                                  g_param_spec_boolean("offline",
+                                                       "Offline Mode",
+                                                       "If viewer is in offline mode.",
+                                                       FALSE,
+                                                       CHAMPLAIN_PARAM_READWRITE)); 
 }
 
 static void
 champlain_view_init (ChamplainView *champlainView)
 {
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
+
   priv->mapSource = CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP;
   priv->zoomLevel = 0;
+  priv->offline = FALSE;
 }
 
 static void 
-viewport_x_changed_cb(GObject    *gobject,
-                           GParamSpec *arg1,
-                           ChamplainView *champlainView)
+viewport_x_changed_cb(GObject *gobject, GParamSpec *arg1, ChamplainView *champlainView)
 {
   ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (champlainView);
   
@@ -356,7 +379,7 @@ viewport_x_changed_cb(GObject    *gobject,
   priv->viewportSize.x = rect.x;
   priv->viewportSize.y = rect.y;
   
-  map_load_visible_tiles (priv->map, priv->viewportSize);
+  map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
   
   g_object_notify(G_OBJECT(champlainView), "longitude");
   g_object_notify(G_OBJECT(champlainView), "latitude");
@@ -371,7 +394,7 @@ view_size_allocated_cb (GtkWidget *view, GtkAllocation *allocation, ChamplainVie
   priv->viewportSize.height = allocation->height;
   
   resize_viewport(champlainView);
-  map_load_visible_tiles (priv->map, priv->viewportSize);
+  map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
 }
 
 /**
@@ -446,7 +469,7 @@ champlain_view_center_on (ChamplainView *champlainView, gdouble longitude, gdoub
   g_object_notify(G_OBJECT(champlainView), "longitude");
   g_object_notify(G_OBJECT(champlainView), "latitude");
   
-  map_load_visible_tiles (priv->map, priv->viewportSize);
+  map_load_visible_tiles (priv->map, priv->viewportSize, priv->offline);
 }
 
 /**
diff --git a/champlain/error.svg b/champlain/error.svg
new file mode 100644 (file)
index 0000000..3664ca0
--- /dev/null
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:xlink="http://www.w3.org/1999/xlink"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="256"
+   height="256"
+   id="svg2"
+   sodipodi:version="0.32"
+   inkscape:version="0.46"
+   version="1.0"
+   sodipodi:docname="error.svg"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape">
+  <defs
+     id="defs4">
+    <linearGradient
+       id="linearGradient3200">
+      <stop
+         style="stop-color:#b3b3b3;stop-opacity:1;"
+         offset="0"
+         id="stop3202" />
+      <stop
+         style="stop-color:#ececec;stop-opacity:1;"
+         offset="1"
+         id="stop3204" />
+    </linearGradient>
+    <inkscape:perspective
+       sodipodi:type="inkscape:persp3d"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       id="perspective10" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3200"
+       id="linearGradient3206"
+       x1="122.23481"
+       y1="0.032388873"
+       x2="257.81464"
+       y2="135.61221"
+       gradientUnits="userSpaceOnUse"
+       spreadMethod="reflect" />
+  </defs>
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="1.235"
+     inkscape:cx="150.26644"
+     inkscape:cy="92.575521"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:window-width="1023"
+     inkscape:window-height="719"
+     inkscape:window-x="1"
+     inkscape:window-y="49" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Calque 1"
+     inkscape:groupmode="layer"
+     id="layer1">
+    <rect
+       style="opacity:1;fill:url(#linearGradient3206);fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.25000000000000000;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+       id="rect3198"
+       width="256"
+       height="256"
+       x="0"
+       y="0"
+       rx="0"
+       ry="0" />
+    <path
+       style="opacity:1;fill:#6c1414;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.25;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
+       d="M 17.691061,21.608585 C 15.787881,23.511765 15.809981,26.577605 17.713151,28.480785 L 25.734401,36.502025 L 17.713151,44.523265 C 15.809981,46.426445 15.787881,49.492285 17.691061,51.395465 L 19.989151,53.693555 C 21.892331,55.596735 24.958171,55.574635 26.861351,53.671465 L 34.882591,45.650215 L 42.903831,53.671465 C 44.807011,55.574635 47.872851,55.596735 49.776031,53.693555 L 52.074121,51.395465 C 53.977301,49.492285 53.955201,46.426445 52.052031,44.523265 L 44.030781,36.502025 L 52.052031,28.480785 C 53.955201,26.577605 53.977301,23.511765 52.074121,21.608585 L 49.776031,19.310495 C 47.872851,17.407315 44.807021,17.429405 42.903831,19.332585 L 34.882591,27.353835 L 26.861351,19.332585 C 24.958171,17.429415 21.892331,17.407315 19.989151,19.310495 L 17.691061,21.608585 z"
+       id="rect2383" />
+  </g>
+</svg>
index bf61494ebcbd2f25cb4b3b2eb7ceb89cb329d4ed..e5256d7709ca0cc82eb82e53a74f5549e8c0722d 100644 (file)
@@ -63,7 +63,7 @@ map_load_level(Map* map, gint zoom_level)
 }
 
 void
-map_load_visible_tiles (Map* map, GdkRectangle viewport)
+map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline)
 {
   gint x_count = ceil((float)viewport.width / map->tile_size) + 1;
   gint y_count = ceil((float)viewport.height / map->tile_size) + 1;
@@ -92,7 +92,7 @@ map_load_visible_tiles (Map* map, GdkRectangle viewport)
 
           if(!exist)
             {
-              Tile* tile = tile_load(map, map->current_level->level, i, j);
+              Tile* tile = tile_load(map, map->current_level->level, i, j, offline);
               g_ptr_array_add (map->current_level->tiles, tile);
             }
         }
index 8de4e8657b9223a1e1c3175a601774ab59edcc62..7893ce49f598629d7b2a0881e25c0b228f4cc8fd 100644 (file)
@@ -54,7 +54,7 @@ struct _Map
 
 Map* map_new (ChamplainMapSource source);
 
-void map_load_visible_tiles (Map* map, GdkRectangle viewport);
+void map_load_visible_tiles (Map* map, GdkRectangle viewport, gboolean offline);
 
 void map_free (Map* map);
 
index 888487159998d564e1a136ab0a8cc57378ac1ff2..fd4deb49e4ac2ce8488105c6838696b6de24386b 100644 (file)
@@ -147,7 +147,7 @@ file_loaded_cb (SoupSession *session,
 }
 
 Tile* 
-tile_load (Map* map, guint zoom_level, guint x, guint y)
+tile_load (Map* map, guint zoom_level, guint x, guint y, gboolean offline)
 {
   static SoupSession * session;
   gchar* filename, *map_filename;
@@ -177,7 +177,7 @@ tile_load (Map* map, guint zoom_level, guint x, guint y)
       
       clutter_container_add (CLUTTER_CONTAINER (map->current_level->group), tile->actor, NULL);
     }
-  else 
+  else if (!offline)
     {
       SoupMessage *msg;
       if (!session)
@@ -188,7 +188,8 @@ tile_load (Map* map, guint zoom_level, guint x, guint y)
       soup_session_queue_message (session, msg,
                                   file_loaded_cb,
                                   ptr);
-    }
+    } 
+  // If a tile is neither in cache or can be fetched, do nothing, it'll show up as empty
     
   g_free (filename);
   g_free (map_filename);