2 * This file is part of mapper
4 * Copyright (C) 2007 Kaj-Michael Lang
5 * Copyright (C) 2006-2007 John Costigan.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #include "map-tile-repo.h"
30 map_tile_repo_new(void)
32 return g_new0(RepoData, 1);
36 map_tile_repo_new_from_string(gchar *str)
38 gchar *token, *error_check;
41 /* Parse each part of a repo, delimited by newline characters:
49 rd=map_tile_repo_new();
52 token = strsep(&str, "\n\t");
54 rd->name = g_strdup(token);
56 /* Parse URL format. */
57 token = strsep(&str, "\n\t");
59 rd->url = g_strdup(token);
61 /* Parse cache dir. */
62 token = strsep(&str, "\n\t");
64 rd->cache_dir = gnome_vfs_expand_initial_tilde(token);
66 /* Parse download zoom steps. */
67 token = strsep(&str, "\n\t");
68 if (!token || !*token || !(rd->dl_zoom_steps = atoi(token)))
69 rd->dl_zoom_steps = 1;
71 /* Parse view zoom steps. */
72 token = strsep(&str, "\n\t");
73 if (!token || !*token || !(rd->view_zoom_steps = atoi(token)))
74 rd->view_zoom_steps = 1;
76 /* Parse double-size. */
77 token = strsep(&str, "\n\t");
79 rd->double_size = atoi(token); /* Default is zero (FALSE) */
81 /* Parse next-able. */
82 token = strsep(&str, "\n\t");
83 if (!token || !*token || (rd->nextable = strtol(token, &error_check, 10), token == str))
86 map_tile_repo_set_type(rd);
92 map_tile_repo_free(RepoData *rd)
99 g_free(rd->cache_dir);
105 map_tile_repo_set_type(RepoData *rd)
107 if (rd->url && *rd->url) {
108 gchar *url = g_utf8_strdown(rd->url, -1);
110 /* Determine type of repository. */
111 if (strstr(url, "service=wms"))
112 rd->type = REPOTYPE_WMS;
113 else if (strstr(url, "%s"))
114 rd->type = REPOTYPE_QUAD_QRST;
115 else if (strstr(url, "%0d"))
116 rd->type = REPOTYPE_XYZ_INV;
117 else if (strstr(url, "%0s"))
118 rd->type = REPOTYPE_QUAD_ZERO;
120 rd->type = REPOTYPE_XYZ;
124 rd->type = REPOTYPE_NONE;
128 map_tile_repo_make_cache_dir(RepoData *rd)
130 if (g_mkdir_with_parents(rd->cache_dir, 0755))
132 return g_file_test(rd->cache_dir, G_FILE_TEST_EXISTS);