From 4f34f4403e85f285edcb8a354958ebc93a38d7d9 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 5 May 2008 15:24:36 +0300 Subject: [PATCH] Split the map tile repository management UI from reposity data --- src/Makefile.am | 2 ++ src/config-gconf.c | 18 +++++++----- src/map-repo.c | 67 ++++++++++++------------------------------ src/map-repo.h | 27 ++--------------- src/map-tile-repo.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ src/map-tile-repo.h | 35 ++++++++++++++++++++++ 6 files changed, 139 insertions(+), 81 deletions(-) create mode 100644 src/map-tile-repo.c create mode 100644 src/map-tile-repo.h diff --git a/src/Makefile.am b/src/Makefile.am index 9ddad6a..e8f1cb2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -77,6 +77,8 @@ mapper_SOURCES = \ map-download.h \ map-poi.c \ map-poi.h \ + map-tile-repo.c \ + map-tile-repo.h \ map-repo.c \ map-repo.h \ map.c \ diff --git a/src/config-gconf.c b/src/config-gconf.c index 0af66a5..1fc3b83 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -55,6 +55,7 @@ #include "gpx.h" #include "filter.h" #include "dialogs.h" +#include "map-tile-repo.h" #define PROXY_PORT (8080) @@ -128,8 +129,9 @@ config_parse_repo(gchar * str) * 5. view_zoom_steps */ gchar *token, *error_check; +RepoData *rd; -RepoData *rd = g_new0(RepoData, 1); +rd=map_tile_repo_new(); /* Parse name. */ token = strsep(&str, "\n\t"); @@ -149,7 +151,7 @@ if (token) /* Parse download zoom steps. */ token = strsep(&str, "\n\t"); if (!token || !*token || !(rd->dl_zoom_steps = atoi(token))) - rd->dl_zoom_steps = 2; + rd->dl_zoom_steps = 1; /* Parse view zoom steps. */ token = strsep(&str, "\n\t"); @@ -167,17 +169,19 @@ if (!token || !*token || (rd->nextable = strtol(token, &error_check, 10), token == str)) rd->nextable = TRUE; -set_repo_type(rd); +map_tile_repo_set_type(rd); return rd; } static void config_default_repo(void) { +RepoData *repo; + g_assert(gconf_client); /* We have no repositories - create a default one. */ -RepoData *repo = g_new(RepoData, 1); +repo=map_tile_repo_new(); /* Get Map Cache Dir. Default is REPO_DEFAULT_CACHE_DIR. */ repo->cache_dir = gconf_client_get_string(gconf_client, GCONF_KEY_MAP_DIR_NAME, NULL); @@ -199,9 +203,9 @@ repo->name = g_strdup(REPO_DEFAULT_NAME); repo->view_zoom_steps = REPO_DEFAULT_VIEW_ZOOM_STEPS; repo->double_size = FALSE; repo->nextable = TRUE; -set_repo_type(repo); +map_tile_repo_set_type(repo); -_repo_list = g_list_append(_repo_list, repo); +_repo_list=g_list_append(_repo_list, repo); repo_set_curr(repo); } @@ -224,7 +228,7 @@ for (curr = list; curr != NULL; curr = curr->next) { } g_slist_free(list); -if (_repo_list == NULL) +if (_repo_list==NULL) config_default_repo(); return TRUE; diff --git a/src/map-repo.c b/src/map-repo.c index e8bbb9d..e7c69ae 100644 --- a/src/map-repo.c +++ b/src/map-repo.c @@ -51,6 +51,7 @@ #include "dialogs.h" #include "help.h" #include "map-repo.h" +#include "map-tile-repo.h" #define MAP_REPO_LIST_URL "http://www.gnuite.com/nokia770/maemo-mapper/repos.txt" @@ -101,47 +102,17 @@ struct _MapmanInfo { GtkWidget *chk_zoom_levels[MAX_ZOOM]; }; -void set_repo_type(RepoData * repo) -{ -if (repo->url && *repo->url) { - gchar *url = g_utf8_strdown(repo->url, -1); - - /* Determine type of repository. */ - if (strstr(url, "service=wms")) - repo->type = REPOTYPE_WMS; - else if (strstr(url, "%s")) - repo->type = REPOTYPE_QUAD_QRST; - else if (strstr(url, "%0d")) - repo->type = REPOTYPE_XYZ_INV; - else if (strstr(url, "%0s")) - repo->type = REPOTYPE_QUAD_ZERO; - else - repo->type = REPOTYPE_XYZ; - - g_free(url); -} else - repo->type = REPOTYPE_NONE; -} - -gboolean -repo_make_cache_dir(gchar * name, const gchar * cache_dir, GtkWidget * parent) +gboolean +repo_set_curr(RepoData *rd) { -if (g_mkdir_with_parents(cache_dir, 0755)) { - /* Failed to create Map Cache directory. */ +_curr_repo=rd; +if (map_tile_repo_make_cache_dir(rd)==FALSE) { gchar buffer[BUFFER_SIZE]; - g_snprintf(buffer, sizeof(buffer), "%s: %s", - _("Unable to create cache directory for repository"), name); - popup_error(parent, buffer); + g_snprintf(buffer, sizeof(buffer), "%s: %s", _("Unable to create cache directory for repository"), rd->name); + popup_error(_window, buffer); return FALSE; } -return g_file_test(cache_dir, G_FILE_TEST_EXISTS); -} - -gboolean -repo_set_curr(RepoData * rd) -{ -_curr_repo = rd; -return repo_make_cache_dir(rd->name, rd->cache_dir, _window); +return TRUE; } static gboolean @@ -157,9 +128,7 @@ repoman_dialog_browse(GtkWidget * widget, BrowseInfo * browse_info) { GtkWidget *dialog; -dialog = GTK_WIDGET(hildon_file_chooser_dialog_new - (GTK_WINDOW(browse_info->dialog), - GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)); +dialog = GTK_WIDGET(hildon_file_chooser_dialog_new(GTK_WINDOW(browse_info->dialog), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)); gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dialog), TRUE); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), gtk_entry_get_text(GTK_ENTRY(browse_info->txt))); @@ -224,9 +193,7 @@ if (gtk_tree_model_iter_n_children(GTK_TREE_MODEL(gtk_combo_box_get_model(GTK_CO return TRUE; } -g_snprintf(buffer, sizeof(buffer), "%s:\n%s\n", - _("Confirm delete of repository"), - gtk_combo_box_get_active_text(GTK_COMBO_BOX(rmi->cmb_repos))); +g_snprintf(buffer, sizeof(buffer), "%s:\n%s\n", _("Confirm delete of repository"), gtk_combo_box_get_active_text(GTK_COMBO_BOX(rmi->cmb_repos))); confirm = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer); if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { @@ -515,7 +482,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(rmi.dialog))) { for (i = 0, curr = rmi.repo_edits; verified && curr; curr = curr->next, i++) { RepoEditInfo *rei = curr->data; gchar *expanded = gnome_vfs_expand_initial_tilde(gtk_entry_get_text(GTK_ENTRY(rei->txt_cache_dir))); - verified = repo_make_cache_dir(rei->name, expanded, rmi.dialog); + verified = map_tile_repo_make_cache_dir(rei); g_free(expanded); } if (!verified) { @@ -539,7 +506,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(rmi.dialog))) { rd->view_zoom_steps = hildon_controlbar_get_value(HILDON_CONTROLBAR(rei->num_view_zoom_steps)); rd->double_size = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rei->chk_double_size)); rd->nextable = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rei->chk_nextable)); - set_repo_type(rd); + map_tile_repo_set_type(rd); _repo_list = g_list_append(_repo_list, rd); @@ -787,10 +754,12 @@ gboolean menu_cb_mapman(GtkAction * action) gtk_box_pack_start(GTK_BOX(vbox), hbox = gtk_hbox_new(FALSE, 4), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), mapman_info.rad_download = gtk_radio_button_new_with_label(NULL, _("Download Maps")), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), label = gtk_alignment_new(0.f, 0.5f, 0.f, 0.f), FALSE, FALSE, 0); - gtk_container_add(GTK_CONTAINER(label), mapman_info.chk_overwrite = - gtk_check_button_new_with_label(_("Overwrite"))), - gtk_box_pack_start(GTK_BOX(vbox), mapman_info.rad_delete = - gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(mapman_info.rad_download), _("Delete Maps")), FALSE, FALSE, 0); + mapman_info.chk_overwrite = gtk_check_button_new_with_label(_("Overwrite")); + gtk_toggle_button_set_active(mapman_info.chk_overwrite, TRUE); + mapman_info.rad_delete = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(mapman_info.rad_download), _("Delete Maps")); + + gtk_container_add(GTK_CONTAINER(label), mapman_info.chk_overwrite); + gtk_box_pack_start(GTK_BOX(vbox), mapman_info.rad_delete, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), gtk_hseparator_new(), FALSE, FALSE, 0); diff --git a/src/map-repo.h b/src/map-repo.h index b4b843c..00eb68a 100644 --- a/src/map-repo.h +++ b/src/map-repo.h @@ -1,32 +1,9 @@ #ifndef _MAP_REPO_H #define _MAP_REPO_H -/** This enumerated type defines the supported types of repositories. */ -typedef enum { - REPOTYPE_NONE, /* No URL set. */ - REPOTYPE_XYZ, /* x=%d, y=%d, and zoom=%d */ - REPOTYPE_XYZ_INV, /* zoom=%0d, x=%d, y=%d */ - REPOTYPE_QUAD_QRST, /* t=%s (%s = {qrst}*) */ - REPOTYPE_QUAD_ZERO, /* t=%0s (%0s = {0123}*) */ - REPOTYPE_WMS /* "service=wms" */ -} RepoType; +#include "map-tile-repo.h" -/** Data regarding a map repository. */ -typedef struct _RepoData RepoData; -struct _RepoData { - gchar *name; - gchar *url; - gchar *cache_dir; - guint dl_zoom_steps; - guint view_zoom_steps; - gboolean double_size; - gboolean nextable; - RepoType type; - GtkWidget *menu_item; -}; - -/** Data used during the asynchronous progress update phase of automatic map - * downloading. */ +/** Data used during the asynchronous progress update phase of automatic map downloading. */ typedef struct _ProgressUpdateInfo ProgressUpdateInfo; struct _ProgressUpdateInfo { gchar *src_str; diff --git a/src/map-tile-repo.c b/src/map-tile-repo.c new file mode 100644 index 0000000..d7d60e0 --- /dev/null +++ b/src/map-tile-repo.c @@ -0,0 +1,71 @@ +/* + * This file is part of mapper + * + * Copyright (C) 2007 Kaj-Michael Lang + * Copyright (C) 2006-2007 John Costigan. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include + +#include "map-tile-repo.h" + +RepoData * +map_tile_repo_new(void) +{ +return g_new0(RepoData, 1); +} + +void +map_tile_repo_free(RepoData *rd) +{ +g_free(rd); +} + +void +map_tile_repo_set_type(RepoData *rd) +{ +if (rd->url && *rd->url) { + gchar *url = g_utf8_strdown(rd->url, -1); + + /* Determine type of repository. */ + if (strstr(url, "service=wms")) + rd->type = REPOTYPE_WMS; + else if (strstr(url, "%s")) + rd->type = REPOTYPE_QUAD_QRST; + else if (strstr(url, "%0d")) + rd->type = REPOTYPE_XYZ_INV; + else if (strstr(url, "%0s")) + rd->type = REPOTYPE_QUAD_ZERO; + else + rd->type = REPOTYPE_XYZ; + + g_free(url); +} else + rd->type = REPOTYPE_NONE; +} + +gboolean +map_tile_repo_make_cache_dir(RepoData *rd) +{ +if (g_mkdir_with_parents(rd->cache_dir, 0755)) + return FALSE; +return g_file_test(rd->cache_dir, G_FILE_TEST_EXISTS); +} + diff --git a/src/map-tile-repo.h b/src/map-tile-repo.h new file mode 100644 index 0000000..3e7c191 --- /dev/null +++ b/src/map-tile-repo.h @@ -0,0 +1,35 @@ +#ifndef _MAP_TILE_REPO_H +#define _MAP_TILE_REPO_H + +#include +#include + +/** This enumerated type defines the supported types of repositories. */ +typedef enum { + REPOTYPE_NONE, /* No URL set. */ + REPOTYPE_XYZ, /* x=%d, y=%d, and zoom=%d */ + REPOTYPE_XYZ_INV, /* zoom=%0d, x=%d, y=%d */ + REPOTYPE_QUAD_QRST, /* t=%s (%s = {qrst}*) */ + REPOTYPE_QUAD_ZERO, /* t=%0s (%0s = {0123}*) */ + REPOTYPE_WMS /* "service=wms" */ +} RepoType; + +/** Data regarding a map repository. */ +typedef struct _RepoData RepoData; +struct _RepoData { + gchar *name; + gchar *url; + gchar *cache_dir; + guint dl_zoom_steps; + guint view_zoom_steps; + gboolean double_size; + gboolean nextable; + RepoType type; + GtkWidget *menu_item; +}; + +RepoData *map_tile_repo_new(void); +void map_tile_repo_free(RepoData *rd); +void map_tile_repo_set_type(RepoData *rd); + +#endif -- 2.39.5