From f115082ffd491711c6a0f56fd479f1172be4f2e3 Mon Sep 17 00:00:00 2001 From: akashihi Date: Wed, 3 Mar 2010 15:18:33 +0000 Subject: [PATCH] Add:Core:Added basement for bookmarks manager. Most of the bookmarking related code moved from navit.c to bookmarks.c git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@2977 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- navit/navit/Makefile.am | 2 +- navit/navit/bookmarks.c | 293 ++++++++++++++++++++++++++++++++ navit/navit/bookmarks.h | 45 +++++ navit/navit/gui/gtk/destination.c | 3 +- navit/navit/gui/gtk/gui_gtk_window.c | 2 +- navit/navit/gui/internal/gui_internal.c | 3 +- navit/navit/navit.c | 274 +++-------------------------- navit/navit/navit.h | 3 +- navit/navit/popup.c | 3 +- 9 files changed, 375 insertions(+), 253 deletions(-) create mode 100644 navit/navit/bookmarks.c create mode 100644 navit/navit/bookmarks.h diff --git a/navit/navit/Makefile.am b/navit/navit/Makefile.am index c54f046..8e8b37a 100644 --- a/navit/navit/Makefile.am +++ b/navit/navit/Makefile.am @@ -42,7 +42,7 @@ EXTRA_DIST = navit_shipped.xml navit.dtd libnavit_la_SOURCES = announcement.c atom.c attr.c cache.c callback.c command.c compass.c config_.c coord.c country.c data_window.c debug.c \ event.c event_glib.h file.c graphics.c gui.c item.c layout.c log.c main.c map.c \ - linguistics.c mapset.c maptype.c menu.c messages.c navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \ + linguistics.c mapset.c maptype.c menu.c messages.c bookmarks.c bookmarks.h navit.c navigation.c osd.c param.c phrase.c plugin.c popup.c \ profile.c projection.c roadprofile.c route.c routech.c search.c speech.c start_real.c transform.c track.c \ util.c vehicle.c vehicleprofile.c xmlconfig.c announcement.h atom.h attr.h attr_def.h cache.h callback.h color.h command.h compass.h config_.h coord.h country.h \ data.h data_window.h data_window_int.h debug.h destination.h draw_info.h endianess.h event.h \ diff --git a/navit/navit/bookmarks.c b/navit/navit/bookmarks.c new file mode 100644 index 0000000..894ab01 --- /dev/null +++ b/navit/navit/bookmarks.c @@ -0,0 +1,293 @@ +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2010 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * 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 "file.h" +#include "debug.h" +#include "projection.h" +#include "coord.h" +#include "transform.h" +#include "callback.h" +#include "map.h" +#include "bookmarks.h" + +struct bookmarks { + //data storage + struct map *bookmark; + GHashTable *bookmarks_hash; + + //Refs to other objects + struct transformation *trans; + struct attr **attrs; + struct callback_list *attr_cbl; + struct attr *parent; +}; + +struct bookmarks *bookmarks_new(struct attr *parent, /*struct attr **attrs,*/struct transformation *trans) { + struct bookmarks *this_; + + this_ = g_new0(struct bookmarks,1); + this_->attr_cbl=callback_list_new(); + this_->parent=parent; + //this_->attrs=attr_list_dup(attrs); + this_->trans=trans; + + this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + + return this_; +} + +void bookmarks_destroy(struct bookmarks *this_) { + map_destroy(this_->bookmark); + g_hash_table_destroy(this_->bookmarks_hash); + callback_list_destroy(this_->attr_cbl); + g_free(this_); +} + +struct map* bookmarks_get_map(struct bookmarks *this_) { + return this_->bookmark; +} +/* + * bookmarks_get_user_data_directory + * + * returns the directory used to store user data files (center.txt, + * destination.txt, bookmark.txt, ...) + * + * arg: gboolean create: create the directory if it does not exist + */ +char* +bookmarks_get_user_data_directory(gboolean create) { + char *dir; + dir = getenv("NAVIT_USER_DATADIR"); + if (create && !file_exists(dir)) { + dbg(0,"creating dir %s\n", dir); + if (file_mkdir(dir,0)) { + dbg(0,"failed creating dir %s\n", dir); + return NULL; + } + } + + return dir; +} + + /* + * bookmarks_get_bookmark_file + * + * returns the name of the file used to store bookmarks with its + * full path + * + * arg: gboolean create: create the directory where the file is stored + * if it does not exist + */ +char* +bookmarks_get_bookmark_file(gboolean create) +{ + return g_strjoin(NULL, bookmarks_get_user_data_directory(create), "/bookmark.txt", NULL); +} + +/* + * bookmarks_get_destination_file + * + * returns the name of the file used to store destinations with its + * full path + * + * arg: gboolean create: create the directory where the file is stored + * if it does not exist + */ +char* +bookmarks_get_destination_file(gboolean create) +{ + return g_strjoin(NULL, bookmarks_get_user_data_directory(create), "/destination.txt", NULL); +} + +/* + * bookmarks_get_center_file + * + * returns the name of the file used to store the center file with its + * full path + * + * arg: gboolean create: create the directory where the file is stored + * if it does not exist + */ +char* +bookmarks_get_center_file(gboolean create) +{ + return g_strjoin(NULL, bookmarks_get_user_data_directory(create), "/center.txt", NULL); +} + +void +bookmarks_set_center_from_file(struct bookmarks *this_, char *file) +{ +#ifndef HAVE_API_ANDROID + FILE *f; + char *line = NULL; + + size_t line_size = 0; + enum projection pro; + struct coord *center; + + f = fopen(file, "r"); + if (! f) + return; + getline(&line, &line_size, f); + fclose(f); + if (line) { + center = transform_center(this_->trans); + pro = transform_get_projection(this_->trans); + coord_parse(g_strchomp(line), pro, center); + free(line); + } + return; +#endif +} + +void +bookmarks_write_center_to_file(struct bookmarks *this_, char *file) +{ + FILE *f; + enum projection pro; + struct coord *center; + + 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); + } + return; +} + +/** + * Record the given set of coordinates as a bookmark + * + * @param navit The navit instance + * @param c The coordinate to store + * @param description A label which allows the user to later identify this bookmark + * @returns nothing + */ +void +bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *c, const char *description) +{ + char *bookmark_file = bookmarks_get_bookmark_file(TRUE); + bookmarks_append_coord(this_,bookmark_file, c, "bookmark", description, this_->bookmarks_hash,0); + g_free(bookmark_file); + + callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map); +} + +void +bookmarks_add_bookmarks_from_file(struct bookmarks *this_) +{ + char *bookmark_file = bookmarks_get_bookmark_file(FALSE); + struct attr type={attr_type, {"textfile"}}, data={attr_data, {bookmark_file}}; + struct attr *attrs[]={&type, &data, NULL}; + + this_->bookmark=map_new(this_->parent, attrs); + g_free(bookmark_file); +} + +/** + * @param limit Limits the number of entries in the "backlog". Set to 0 for "infinite" + */ +void +bookmarks_append_coord(struct bookmarks *this_, char *file, struct pcoord *c, const char *type, const char *description, GHashTable *h, int limit) +{ + FILE *f; + int offset=0; + char *buffer; + int ch,prev,lines=0; + int numc,readc; + int fd; + const char *prostr; + + f=fopen(file, "r"); + if (!f) + goto new_file; + if (limit != 0) { + prev = '\n'; + while ((ch = fgetc(f)) != EOF) { + if ((ch == '\n') && (prev != '\n')) { + lines++; + } + prev = ch; + } + + if (prev != '\n') { // Last line did not end with a newline + lines++; + } + + fclose(f); + f = fopen(file, "r+"); + fd = fileno(f); + while (lines >= limit) { // We have to "scroll up" + rewind(f); + numc = 0; // Counts how many bytes we have in our line to scroll up + while ((ch = fgetc(f)) != EOF) { + numc++; + if (ch == '\n') { + break; + } + } + + buffer=g_malloc(numc); + offset = numc; // Offset holds where we currently are + + do { + fseek(f,offset,SEEK_SET); + readc = fread(buffer,1,numc,f); + + fseek(f,-(numc+readc),SEEK_CUR); + fwrite(buffer,1,readc,f); + + offset += readc; + } while (readc == numc); + + g_free(buffer); + fflush(f); + ftruncate(fd,(offset-numc)); +#ifdef HAVE_FSYNC + fsync(fd); +#endif + + lines--; + } + fclose(f); + } + +new_file: + f=fopen(file, "a"); + if (f) { + if (c) { + prostr = projection_to_name(c->pro,NULL); + fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\"\n", + prostr, *prostr ? ":" : "", + c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x, + c->y >= 0 ? "":"-", c->y >= 0 ? c->y : -c->y, + type, description); + } else + fprintf(f,"\n"); + } + fclose(f); +} + diff --git a/navit/navit/bookmarks.h b/navit/navit/bookmarks.h new file mode 100644 index 0000000..e33bf22 --- /dev/null +++ b/navit/navit/bookmarks.h @@ -0,0 +1,45 @@ +/** + * Navit, a modular navigation system. + * Copyright (C) 2005-2010 Navit Team + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + * 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. + */ + + #ifndef NAVIT_BOOKMARKS_H + #define NAVIT_BOOKMARKS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* prototypes */ +struct bookmarks; +struct bookmarks *bookmarks_new(struct attr *parent,/* struct attr **attrs,*/ struct transformation *trans); +void bookmarks_destroy(struct bookmarks *this_); +void bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *c, const char *description); +struct map* bookmarks_get_map(struct bookmarks *this_); +char* bookmarks_get_destination_file(gboolean create); +void bookmarks_add_bookmarks_from_file(struct bookmarks *this_); +void bookmarks_set_center_from_file(struct bookmarks *this_, char *file); +char* bookmarks_get_center_file(gboolean create); +void bookmarks_write_center_to_file(struct bookmarks *this_, char *file); +void bookmarks_append_coord(struct bookmarks *this_, char *file, struct pcoord *c, const char *type, const char *description, GHashTable *h, int limit); +/* end of prototypes */ + +#ifdef __cplusplus +} +#endif + + #endif /* NAVIT_BOOKMARKS_H */ diff --git a/navit/navit/gui/gtk/destination.c b/navit/navit/gui/gtk/destination.c index 1b1cf61..652db31 100644 --- a/navit/navit/gui/gtk/destination.c +++ b/navit/navit/gui/gtk/destination.c @@ -32,6 +32,7 @@ #include "search.h" #include "projection.h" #include "navit_nls.h" +#include "bookmarks.h" #define COL_COUNT 8 @@ -117,7 +118,7 @@ static void button_bookmark(GtkWidget *widget, struct search_param *search) gtk_tree_model_get (GTK_TREE_MODEL (search->liststore2), &iter, COL_COUNT, &c, -1); if (c) { desc=description(search, &iter); - navit_add_bookmark(search->nav, c, desc); + bookmarks_add_bookmark(navit_get_bookmarks(search->nav), c, desc); g_free(desc); } } diff --git a/navit/navit/gui/gtk/gui_gtk_window.c b/navit/navit/gui/gtk/gui_gtk_window.c index a95b8e1..095aac2 100644 --- a/navit/navit/gui/gtk/gui_gtk_window.c +++ b/navit/navit/gui/gtk/gui_gtk_window.c @@ -221,7 +221,7 @@ gui_gtk_set_graphics(struct gui_priv *this, struct graphics *gra) static void gui_gtk_add_bookmark_do(struct gui_priv *gui) { - navit_add_bookmark(gui->nav, &gui->dialog_coord, gtk_entry_get_text(GTK_ENTRY(gui->dialog_entry))); + bookmarks_add_bookmark(navit_get_bookmarks(gui->nav), &gui->dialog_coord, gtk_entry_get_text(GTK_ENTRY(gui->dialog_entry))); gtk_widget_destroy(gui->dialog_win); } diff --git a/navit/navit/gui/internal/gui_internal.c b/navit/navit/gui/internal/gui_internal.c index 1972022..dc566e8 100644 --- a/navit/navit/gui/internal/gui_internal.c +++ b/navit/navit/gui/internal/gui_internal.c @@ -70,6 +70,7 @@ #include "command.h" #include "xmlconfig.h" #include "util.h" +#include "bookmarks.h" extern char *version; @@ -1870,7 +1871,7 @@ gui_internal_cmd_add_bookmark_do(struct gui_priv *this, struct widget *widget) GList *l; dbg(0,"text='%s'\n", widget->text); if (widget->text && strlen(widget->text)) - navit_add_bookmark(this->nav, &widget->c, widget->text); + bookmarks_add_bookmark(navit_get_bookmarks(this->nav), &widget->c, widget->text); g_free(widget->text); widget->text=NULL; l=g_list_previous(g_list_last(this->root.children)); diff --git a/navit/navit/navit.c b/navit/navit/navit.c index 2f74047..6ea83f4 100644 --- a/navit/navit/navit.c +++ b/navit/navit/navit.c @@ -61,6 +61,7 @@ #include "messages.h" #include "vehicleprofile.h" #include "sunriset.h" +#include "bookmarks.h" /** * @defgroup navit the navit core instance. navit is the object containing nearly everything: A set of maps, one or more vehicle, a graphics object for rendering the map, a gui object for displaying the user interface, a route object, a navigation object and so on. Be warned that it is theoretically possible to have more than one navit object @@ -109,9 +110,7 @@ struct navit { struct callback_list *attr_cbl; struct callback *nav_speech_cb, *roadbook_callback, *popup_callback, *route_cb; struct datawindow *roadbook_window; - struct map *bookmark; struct map *former_destination; - GHashTable *bookmarks_hash; struct point pressed, last, current; int button_pressed,moved,popped,zoomed; int center_timeout; @@ -138,6 +137,7 @@ struct navit { int prevTs; int graphics_flags; int zoom_min, zoom_max; + struct bookmarks *bookmarks; }; struct gui *main_loop_gui; @@ -160,6 +160,8 @@ static void navit_cmd_set_center_cursor(struct navit *this_); static void navit_cmd_announcer_toggle(struct navit *this_); static void navit_set_vehicle(struct navit *this_, struct navit_vehicle *nv); +struct navit *global_navit; + void navit_add_mapset(struct navit *this_, struct mapset *ms) { @@ -700,8 +702,6 @@ navit_new(struct attr *parent, struct attr **attrs) this_->self.u.navit=this_; this_->attr_cbl=callback_list_new(); - this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); - this_->orientation=-1; this_->tracking_flag=1; this_->recentdest_count=10; @@ -722,9 +722,12 @@ navit_new(struct attr *parent, struct attr **attrs) center.y=co.y; center.pro = pro; + transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0); + + this_->bookmarks=bookmarks_new(&this_->self, this_->trans); + this_->prevTs=0; - transform_setup(this_->trans, ¢er, zoom, (this_->orientation != -1) ? this_->orientation : 0); for (;*attrs; attrs++) { navit_set_attr_do(this_, *attrs, 1); } @@ -813,205 +816,6 @@ navit_projection_set(struct navit *this_, enum projection pro, int draw) } /** - * @param limit Limits the number of entries in the "backlog". Set to 0 for "infinite" - */ -static void -navit_append_coord(struct navit *this_, char *file, struct pcoord *c, const char *type, const char *description, GHashTable *h, int limit) -{ - FILE *f; - int offset=0; - char *buffer; - int ch,prev,lines=0; - int numc,readc; - int fd; - const char *prostr; - - f=fopen(file, "r"); - if (!f) - goto new_file; - if (limit != 0) { - prev = '\n'; - while ((ch = fgetc(f)) != EOF) { - if ((ch == '\n') && (prev != '\n')) { - lines++; - } - prev = ch; - } - - if (prev != '\n') { // Last line did not end with a newline - lines++; - } - - fclose(f); - f = fopen(file, "r+"); - fd = fileno(f); - while (lines >= limit) { // We have to "scroll up" - rewind(f); - numc = 0; // Counts how many bytes we have in our line to scroll up - while ((ch = fgetc(f)) != EOF) { - numc++; - if (ch == '\n') { - break; - } - } - - buffer=g_malloc(numc); - offset = numc; // Offset holds where we currently are - - do { - fseek(f,offset,SEEK_SET); - readc = fread(buffer,1,numc,f); - - fseek(f,-(numc+readc),SEEK_CUR); - fwrite(buffer,1,readc,f); - - offset += readc; - } while (readc == numc); - - g_free(buffer); - fflush(f); - ftruncate(fd,(offset-numc)); -#ifdef HAVE_FSYNC - fsync(fd); -#endif - - lines--; - } - fclose(f); - } - -new_file: - f=fopen(file, "a"); - if (f) { - if (c) { - prostr = projection_to_name(c->pro,NULL); - fprintf(f,"%s%s%s0x%x %s0x%x type=%s label=\"%s\"\n", - prostr, *prostr ? ":" : "", - c->x >= 0 ? "":"-", c->x >= 0 ? c->x : -c->x, - c->y >= 0 ? "":"-", c->y >= 0 ? c->y : -c->y, - type, description); - } else - fprintf(f,"\n"); - } - fclose(f); -} - -/* - * navit_get_user_data_directory - * - * returns the directory used to store user data files (center.txt, - * destination.txt, bookmark.txt, ...) - * - * arg: gboolean create: create the directory if it does not exist - */ -static char* -navit_get_user_data_directory(gboolean create) { - char *dir; - dir = getenv("NAVIT_USER_DATADIR"); - if (create && !file_exists(dir)) { - dbg(0,"creating dir %s\n", dir); - if (file_mkdir(dir,0)) { - dbg(0,"failed creating dir %s\n", dir); - return NULL; - } - } - - return dir; -} - -/* - * navit_get_destination_file - * - * returns the name of the file used to store destinations with its - * full path - * - * arg: gboolean create: create the directory where the file is stored - * if it does not exist - */ -static char* -navit_get_destination_file(gboolean create) -{ - return g_strjoin(NULL, navit_get_user_data_directory(create), "/destination.txt", NULL); -} - -/* - * navit_get_bookmark_file - * - * returns the name of the file used to store bookmarks with its - * full path - * - * arg: gboolean create: create the directory where the file is stored - * if it does not exist - */ -static char* -navit_get_bookmark_file(gboolean create) -{ - return g_strjoin(NULL, navit_get_user_data_directory(create), "/bookmark.txt", NULL); -} - - -/* - * navit_get_bookmark_file - * - * returns the name of the file used to store the center file with its - * full path - * - * arg: gboolean create: create the directory where the file is stored - * if it does not exist - */ -static char* -navit_get_center_file(gboolean create) -{ - return g_strjoin(NULL, navit_get_user_data_directory(create), "/center.txt", NULL); -} - -static void -navit_set_center_from_file(struct navit *this_, char *file) -{ -#ifndef HAVE_API_ANDROID - FILE *f; - char *line = NULL; - - size_t line_size = 0; - enum projection pro; - struct coord *center; - - f = fopen(file, "r"); - if (! f) - return; - getline(&line, &line_size, f); - fclose(f); - if (line) { - center = transform_center(this_->trans); - pro = transform_get_projection(this_->trans); - coord_parse(g_strchomp(line), pro, center); - free(line); - } - return; -#endif -} - -static void -navit_write_center_to_file(struct navit *this_, char *file) -{ - FILE *f; - enum projection pro; - struct coord *center; - - 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); - } - return; -} - - -/** * Start the route computing to a given set of coordinates * * @param navit The navit instance @@ -1027,8 +831,8 @@ navit_set_destination(struct navit *this_, struct pcoord *c, const char *descrip this_->destination_valid=1; } else this_->destination_valid=0; - char *destination_file = navit_get_destination_file(TRUE); - navit_append_coord(this_, destination_file, c, "former_destination", description, NULL, this_->recentdest_count); + char *destination_file = bookmarks_get_destination_file(TRUE); + bookmarks_append_coord(this_->bookmarks, destination_file, c, "former_destination", description, NULL, this_->recentdest_count); g_free(destination_file); callback_list_call_attr_0(this_->attr_cbl, attr_destination); if (this_->route) { @@ -1057,42 +861,10 @@ navit_check_route(struct navit *this_) return 0; } -/** - * Record the given set of coordinates as a bookmark - * - * @param navit The navit instance - * @param c The coordinate to store - * @param description A label which allows the user to later identify this bookmark - * @returns nothing - */ -void -navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description) -{ - char *bookmark_file = navit_get_bookmark_file(TRUE); - navit_append_coord(this_,bookmark_file, c, "bookmark", description, this_->bookmarks_hash,0); - g_free(bookmark_file); - - callback_list_call_attr_0(this_->attr_cbl, attr_bookmark_map); -} - -struct navit *global_navit; - -static void -navit_add_bookmarks_from_file(struct navit *this_) -{ - char *bookmark_file = navit_get_bookmark_file(FALSE); - struct attr parent={attr_navit, .u.navit=this_}; - struct attr type={attr_type, {"textfile"}}, data={attr_data, {bookmark_file}}; - struct attr *attrs[]={&type, &data, NULL}; - - this_->bookmark=map_new(&parent, attrs); - g_free(bookmark_file); -} - static int navit_former_destinations_active(struct navit *this_) { - char *destination_file = navit_get_destination_file(FALSE); + char *destination_file = bookmarks_get_destination_file(FALSE); FILE *f; int active=0; char buffer[3]; @@ -1109,7 +881,7 @@ navit_former_destinations_active(struct navit *this_) static void navit_add_former_destinations_from_file(struct navit *this_) { - char *destination_file = navit_get_destination_file(FALSE); + char *destination_file = bookmarks_get_destination_file(FALSE); struct attr parent={attr_navit, .u.navit=this_}; struct attr type={attr_type, {"textfile"}}, data={attr_data, {destination_file}}; struct attr *attrs[]={&type, &data, NULL}; @@ -1403,7 +1175,7 @@ navit_init(struct navit *this_) map_set_attr(map, &(struct attr ){attr_active,.u.num=0}); } } - navit_add_bookmarks_from_file(this_); + bookmarks_add_bookmarks_from_file(this_->bookmarks); navit_add_former_destinations_from_file(this_); } if (this_->route) { @@ -1422,8 +1194,8 @@ navit_init(struct navit *this_) navigation_set_route(this_->navigation, this_->route); } dbg(2,"Setting Center\n"); - char *center_file = navit_get_center_file(FALSE); - navit_set_center_from_file(this_, center_file); + char *center_file = bookmarks_get_center_file(FALSE); + bookmarks_set_center_from_file(this_->bookmarks, center_file); g_free(center_file); #if 0 if (this_->menubar) { @@ -1890,7 +1662,7 @@ navit_get_attr(struct navit *this_, enum attr_type type, struct attr *attr, stru attr->u.str[len] = '\0'; break; case attr_bookmark_map: - attr->u.map=this_->bookmark; + attr->u.map=bookmarks_get_map(this_->bookmarks); break; case attr_callback_list: attr->u.callback_list=this_->attr_cbl; @@ -2472,6 +2244,11 @@ navit_set_layout_by_name(struct navit *n,char *name) return 0; } +struct bookmarks* +navit_get_bookmarks(struct navit *this_) { + return this_->bookmarks; +} + int navit_block(struct navit *this_, int block) { @@ -2496,9 +2273,12 @@ navit_destroy(struct navit *this_) /* TODO: destroy objects contained in this_ */ if (this_->vehicle) vehicle_destroy(this_->vehicle->vehicle); - char *center_file = navit_get_center_file(TRUE); - navit_write_center_to_file(this_, center_file); - g_free(center_file); + if (this_->bookmarks) { + char *center_file = bookmarks_get_center_file(TRUE); + bookmarks_write_center_to_file(this_->bookmarks, center_file); + g_free(center_file); + bookmarks_destroy(this_->bookmarks); + } callback_destroy(this_->nav_speech_cb); callback_destroy(this_->roadbook_callback); callback_destroy(this_->popup_callback); diff --git a/navit/navit/navit.h b/navit/navit/navit.h index 8745889..7e85dee 100644 --- a/navit/navit/navit.h +++ b/navit/navit/navit.h @@ -48,6 +48,7 @@ struct route; struct tracking; struct transformation; struct vehicleprofile; +struct bookmarks; void navit_add_mapset(struct navit *this_, struct mapset *ms); struct mapset *navit_get_mapset(struct navit *this_); struct tracking *navit_get_tracking(struct navit *this_); @@ -71,7 +72,6 @@ struct vehicleprofile *navit_get_vehicleprofile(struct navit *this_); GList *navit_get_vehicleprofiles(struct navit *this_); void navit_set_destination(struct navit *this_, struct pcoord *c, const char *description, int async); int navit_check_route(struct navit *this_); -void navit_add_bookmark(struct navit *this_, struct pcoord *c, const char *description); void navit_textfile_debug_log(struct navit *this_, const char *fmt, ...); int navit_speech_estimate(struct navit *this_, char *str); void navit_say(struct navit *this_, char *text); @@ -99,6 +99,7 @@ struct displaylist *navit_get_displaylist(struct navit *this_); int navit_block(struct navit *this_, int block); void navit_layout_switch(struct navit *n); int navit_set_layout_by_name(struct navit *n, char* name); +struct bookmarks* navit_get_bookmarks(struct navit *this_); void navit_destroy(struct navit *this_); /* end of prototypes */ #ifdef __cplusplus diff --git a/navit/navit/popup.c b/navit/navit/popup.c index eda64be..6c0c352 100644 --- a/navit/navit/popup.c +++ b/navit/navit/popup.c @@ -38,6 +38,7 @@ #include "callback.h" #include "route.h" #include "navit_nls.h" +#include "bookmarks.h" #if 0 static void @@ -126,7 +127,7 @@ popup_set_bookmark(struct navit *nav, struct pcoord *pc) coord_format(g.lat,g.lng,DEGREES_MINUTES_SECONDS,buffer_geo,sizeof(buffer_geo)); sprintf(buffer,"Map Point %s", buffer_geo); if (!gui_add_bookmark(navit_get_gui(nav), pc, buffer)) - navit_add_bookmark(nav, pc, buffer); + bookmarks_add_bookmark(navit_get_bookmarks(nav), pc, buffer); } -- 2.7.4