From: kazer_ Date: Thu, 29 May 2008 20:15:44 +0000 (+0000) Subject: Fix:Core:Fixes ticket #14 : Start navit with the view centered on last position ... X-Git-Url: http://git.maemo.org/git/?a=commitdiff_plain;h=a2262759132f72b7d54dbc3c8c0d3d136c613f1a;p=navit-package Fix:Core:Fixes ticket #14 : Start navit with the view centered on last position | Thanks Andrew Snodgrass git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk/navit@1085 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/coord.c b/navit/coord.c index 74b6a10..9e554b2 100644 --- a/navit/coord.c +++ b/navit/coord.c @@ -162,8 +162,8 @@ coord_parse(const char *c_str, enum projection pro, struct coord *c_ret) while (*s == ' ') { s++; } - if (!strncmp(str, "0x", 2) || !strncmp(str,"-0x", 3)) { - args=sscanf(str, "%x %x%n",&c.x, &c.y, &ret); + if (!strncmp(s, "0x", 2) || !strncmp(s, "-0x", 3)) { + args=sscanf(str, "%i %i%n",&c.x, &c.y, &ret); if (args < 2) goto out; dbg(1,"str='%s' x=0x%x y=0x%x c=%d\n", str, c.x, c.y, ret); @@ -222,4 +222,30 @@ out: return ret; } +void +coord_print(enum projection pro, struct coord *c, FILE *out) { + unsigned int x; + unsigned int y; + char *sign_x = ""; + char *sign_y = ""; + + if ( c->x < 0 ) { + x = -c->x; + sign_x = "-"; + } else { + x = c->x; + } + if ( c->y < 0 ) { + y = -c->y; + sign_y = "-"; + } else { + y = c->y; + } + fprintf( out, "%s: %s0x%x %s0x%x\n", + projection_to_name( pro ), + sign_x, x, + sign_y, y ); + return; +} + /** @} */ diff --git a/navit/coord.h b/navit/coord.h index 62c45f5..e92ae9a 100644 --- a/navit/coord.h +++ b/navit/coord.h @@ -1,5 +1,6 @@ #ifndef NAVIT_COORD_H #define NAVIT_COORD_H +#include #include "projection.h" /*! A integer mercator coordinate */ @@ -45,6 +46,7 @@ struct coord * coord_get(unsigned char **p); struct coord * coord_new(int x, int y); void coord_destroy(struct coord *c); int coord_parse(const char *c_str, enum projection pro, struct coord *c_ret); +void coord_print(enum projection pro, struct coord *c, FILE *out); struct coord_rect * coord_rect_new(struct coord *lu, struct coord *rl); void coord_rect_destroy(struct coord_rect *r); int coord_rect_overlap(struct coord_rect *r1, struct coord_rect *r2); diff --git a/navit/main.c b/navit/main.c index cc9e8af..a7650ec 100644 --- a/navit/main.c +++ b/navit/main.c @@ -40,7 +40,7 @@ static void sigchld(int sig) } -static gchar *get_home_directory(void) +gchar *get_home_directory(void) { static gchar *homedir = NULL; diff --git a/navit/navit.c b/navit/navit.c index f3efa04..52a7aec 100644 --- a/navit/navit.c +++ b/navit/navit.c @@ -584,6 +584,70 @@ navit_set_destination_from_bookmark(struct navit *this_, void *offset_p) navit_set_destination_from_file(this_, "bookmark.txt", 1, (int)offset_p); } +static void +navit_set_center_from_file(struct navit *this_, char *file) +{ + FILE *f; + char *line = NULL; + + size_t line_size = 0; + enum projection pro; + struct coord *center; + + file = g_strjoin(NULL, get_home_directory(), "/.navit/", file, NULL); + if (!file_exists(file)) { + g_free(file); + return; + } + f = fopen(file, "r"); + getline(&line, &line_size, f); + fclose(f); + g_free(file); + if (line) { + center = transform_center(this_->trans); + pro = transform_get_projection(this_->trans); + coord_parse(g_strchomp(line), pro, center); + free(line); + } + return; +} + +static void +navit_write_center_to_file(struct navit *this_, char *file) +{ + FILE *f; + enum projection pro; + struct coord *center; + char *directory; + + directory = g_strjoin(NULL, get_home_directory(), "/.navit/", NULL); + if (!file_exists(directory)) { + if (mkdir(directory, + S_IRUSR|S_IWUSR|S_IXUSR| + S_IRGRP|S_IXGRP| + S_IROTH|S_IXOTH) == -1) { + perror(directory); + g_free(directory); + return; + } + } + + file = g_strjoin(NULL, directory, file, NULL); + g_free(directory); + f = fopen(file, "w+"); + if (f) { + center = transform_center(this_->trans); + pro = transform_get_projection(this_->trans); + coord_print(pro, center, f); + fclose(f); + } else { + perror(file); + } + g_free(file); + return; +} + + /** * Start the route computing to a given set of coordinates * @@ -1075,6 +1139,7 @@ navit_init(struct navit *this_) this_->nav_speech_cb=callback_new_1(callback_cast(navit_speak), this_); navigation_register_callback(this_->navigation, attr_navigation_speech, this_->nav_speech_cb); } + navit_set_center_from_file(this_, "center.txt"); #if 0 if (this_->menubar) { men=menu_add(this_->menubar, "Data", menu_type_submenu, NULL); @@ -1577,6 +1642,7 @@ navit_destroy(struct navit *this_) { /* TODO: destroy objects contained in this_ */ main_remove_navit(this_); + navit_write_center_to_file(this_, "center.txt"); g_free(this_); }