From 1ca021f84b9f2982c9c684777cb494e27759b145 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Tue, 3 Mar 2009 00:02:04 +0200 Subject: [PATCH] Introduce champlain_settings to hold global settings. Should probably be transformed on a GObject. --- champlain/Makefile.am | 9 ++++++--- champlain/champlain-map-source.c | 3 ++- champlain/champlain-map.c | 2 +- champlain/champlain-map.h | 2 +- champlain/champlain-private.h | 5 ++--- champlain/champlain-settings.c | 34 ++++++++++++++++++++++++++++++++ champlain/champlain-settings.h | 31 +++++++++++++++++++++++++++++ champlain/champlain-view.c | 8 +++----- champlain/champlain.h | 1 + 9 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 champlain/champlain-settings.c create mode 100644 champlain/champlain-settings.h diff --git a/champlain/Makefile.am b/champlain/Makefile.am index 92e4dec..281aae0 100644 --- a/champlain/Makefile.am +++ b/champlain/Makefile.am @@ -23,7 +23,8 @@ libchamplain_headers = \ champlain-zoom-level.h \ champlain-enum-types.h \ champlain-tile.h \ - champlain-map-source.h + champlain-map-source.h \ + champlain-settings.h libchamplain_0_3_la_SOURCES = \ @@ -36,7 +37,8 @@ libchamplain_0_3_la_SOURCES = \ champlain-map.c \ champlain-zoom-level.c \ champlain-tile.c \ - champlain-map-source.c + champlain-map-source.c \ + champlain-settings.c noinst_HEADERS = \ champlain-debug.h \ @@ -57,7 +59,8 @@ libchamplain_include_HEADERS = \ champlain-map-source.h \ champlain-tile.h \ champlain-zoom-level.h \ - champlain-marker.h + champlain-marker.h \ + champlain-settings.h libchamplain_0_3_la_LIBADD = $(DEPS_LIBS) ../tidy/libtidy-1.0.la diff --git a/champlain/champlain-map-source.c b/champlain/champlain-map-source.c index 41f2d0d..56bdbcb 100644 --- a/champlain/champlain-map-source.c +++ b/champlain/champlain-map-source.c @@ -27,6 +27,7 @@ #include "champlain-map-source.h" #include "champlain-marshal.h" #include "champlain-private.h" +#include "champlain-settings.h" #include "champlain-zoom-level.h" #include @@ -642,7 +643,7 @@ champlain_map_source_get_tile (ChamplainMapSource *map_source, g_object_unref (tile); g_object_unref (zoom_level); } - else /* if (!offline) */ + else if (champlain_settings_is_online ()) { SoupMessage *msg; gchar *uri; diff --git a/champlain/champlain-map.c b/champlain/champlain-map.c index cc9b3da..1f8b013 100644 --- a/champlain/champlain-map.c +++ b/champlain/champlain-map.c @@ -54,7 +54,7 @@ map_load_level(Map *map, ChamplainMapSource *map_source, gint zoom_level) } void -map_load_visible_tiles (Map *map, ChamplainView *view, ChamplainMapSource *source, ChamplainRectangle viewport, gboolean offline) +map_load_visible_tiles (Map *map, ChamplainView *view, ChamplainMapSource *source, ChamplainRectangle viewport) { gint size; diff --git a/champlain/champlain-map.h b/champlain/champlain-map.h index 011e0b8..6a0902e 100644 --- a/champlain/champlain-map.h +++ b/champlain/champlain-map.h @@ -37,7 +37,7 @@ struct _Map Map *map_new (); -void map_load_visible_tiles (Map *map, ChamplainView * view, ChamplainMapSource *source, ChamplainRectangle viewport, gboolean offline); +void map_load_visible_tiles (Map *map, ChamplainView * view, ChamplainMapSource *source, ChamplainRectangle viewport); void map_free (Map *map); diff --git a/champlain/champlain-private.h b/champlain/champlain-private.h index e476778..5c053eb 100644 --- a/champlain/champlain-private.h +++ b/champlain/champlain-private.h @@ -25,7 +25,7 @@ typedef struct _Map Map; -typedef struct +typedef struct { gint x; gint y; @@ -38,7 +38,7 @@ struct _ChamplainMarkerPrivate gdouble lat; }; -typedef struct +typedef struct { gint x; gint y; @@ -46,5 +46,4 @@ typedef struct gint height; } ChamplainRectangle; - #endif diff --git a/champlain/champlain-settings.c b/champlain/champlain-settings.c new file mode 100644 index 0000000..73a3c84 --- /dev/null +++ b/champlain/champlain-settings.c @@ -0,0 +1,34 @@ + +/* + * Copyright (C) 2009 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "champlain-settings.h" + +static gboolean global_offline = TRUE; + +gboolean +champlain_settings_is_online () +{ + return global_offline; +} + +gboolean +champlain_settings_set_online (gboolean value) +{ + global_offline = value; +} diff --git a/champlain/champlain-settings.h b/champlain/champlain-settings.h new file mode 100644 index 0000000..2544c76 --- /dev/null +++ b/champlain/champlain-settings.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#if !defined (__CHAMPLAIN_CHAMPLAIN_H_INSIDE__) && !defined (CHAMPLAIN_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef CHAMPLAIN_SETTINGS_H +#define CHAMPLAIN_SETTINGS_H + +#include + +gboolean champlain_settings_is_online (); +gboolean champlain_settings_set_online (gboolean value); + +#endif diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c index b97d5b5..41a7013 100644 --- a/champlain/champlain-view.c +++ b/champlain/champlain-view.c @@ -119,7 +119,6 @@ struct _ChamplainViewPrivate Map *map; - gboolean offline; gboolean keep_center_on_resize; gboolean show_license; }; @@ -452,7 +451,7 @@ champlain_view_get_property (GObject *object, g_value_set_enum (value, priv->scroll_mode); break; case PROP_OFFLINE: - g_value_set_boolean (value, priv->offline); + g_value_set_boolean (value, !champlain_settings_is_online ()); break; case PROP_DECEL_RATE: { @@ -566,7 +565,7 @@ champlain_view_set_property (GObject *object, priv->scroll_mode, NULL); break; case PROP_OFFLINE: - priv->offline = g_value_get_boolean (value); + champlain_settings_set_online (!g_value_get_boolean (value)); break; case PROP_DECEL_RATE: { @@ -749,7 +748,6 @@ champlain_view_init (ChamplainView *view) priv->map_source = champlain_map_source_new_osm_mapnik (); priv->zoom_level = 0; - priv->offline = FALSE; priv->keep_center_on_resize = TRUE; priv->show_license = TRUE; priv->license_actor = NULL; @@ -1195,7 +1193,7 @@ view_load_visible_tiles (ChamplainView *view) viewport.x += priv->anchor.x; viewport.y += priv->anchor.y; - map_load_visible_tiles (priv->map, view, priv->map_source, viewport, priv->offline); + map_load_visible_tiles (priv->map, view, priv->map_source, viewport); } static void diff --git a/champlain/champlain.h b/champlain/champlain.h index 19144cc..0128fb5 100644 --- a/champlain/champlain.h +++ b/champlain/champlain.h @@ -34,6 +34,7 @@ #include "champlain/champlain-view.h" #include "champlain/champlain-enum-types.h" #include "champlain/champlain-map-source.h" +#include "champlain/champlain-settings.h" #undef __CHAMPLAIN_CHAMPLAIN_H_INSIDE__ -- 2.39.5