summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkazer_ <kazer_@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-05-29 20:15:44 +0000
committerkazer_ <kazer_@ffa7fe5e-494d-0410-b361-a75ebd5db220>2008-05-29 20:15:44 +0000
commit3decec7a3b810d23d8281575b61501a672eed9a3 (patch)
treecb47037a4def70ebd4cf5a040958a24275fcb478
parent799381edd3045241da6e6bdab44e4110018734b1 (diff)
downloadnavit-3decec7a3b810d23d8281575b61501a672eed9a3.tar.gz
Fix:Core:Fixes ticket #14 : Start navit with the view centered on last position | Thanks Andrew Snodgrass
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@1085 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--navit/coord.c30
-rw-r--r--navit/coord.h2
-rw-r--r--navit/main.c2
-rw-r--r--navit/navit.c66
4 files changed, 97 insertions, 3 deletions
diff --git a/navit/coord.c b/navit/coord.c
index 74b6a1041..9e554b276 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 62c45f5a9..e92ae9a8a 100644
--- a/navit/coord.h
+++ b/navit/coord.h
@@ -1,5 +1,6 @@
#ifndef NAVIT_COORD_H
#define NAVIT_COORD_H
+#include <stdio.h>
#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 cc9e8afd0..a7650ec61 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 f3efa04d9..52a7aec41 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_);
}