From: martin-s Date: Mon, 5 Nov 2007 17:52:39 +0000 (+0000) Subject: Made some reasonable defaults for country in destination dialog X-Git-Tag: navit-0.5.0.5194svn~4617 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=facc7c1d74f3a8b796ec01ef0a1c42b5874a7682;p=profile%2Fivi%2Fnavit.git Made some reasonable defaults for country in destination dialog git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@532 ffa7fe5e-494d-0410-b361-a75ebd5db220 --- diff --git a/navit/src/country.c b/navit/src/country.c index 4adf632..7373f99 100644 --- a/navit/src/country.c +++ b/navit/src/country.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "debug.h" @@ -111,7 +112,7 @@ country_attr_get(void *priv_data, enum attr_type attr_type, struct attr *attr) return 0; case attr_label: attr->u.str=gettext(country->name); - this->attr_next=attr_id; + this->attr_next=attr_country_id; return 1; case attr_country_id: attr->u.num=country->id; @@ -203,6 +204,24 @@ country_search_get_item(struct country_search *this) } } +static struct attr country_default_attr; +static char iso2[3]; + +struct attr * +country_default(void) +{ + char *lang; + if (country_default_attr.u.str) + return &country_default_attr; + lang=getenv("LANG"); + if (!lang || strlen(lang) < 5) + return NULL; + strncpy(iso2, lang+3, 2); + country_default_attr.type=attr_country_iso2; + country_default_attr.u.str=iso2; + return &country_default_attr; +} + void country_search_destroy(struct country_search *this) { diff --git a/navit/src/country.h b/navit/src/country.h index edc9635..465c305 100644 --- a/navit/src/country.h +++ b/navit/src/country.h @@ -10,8 +10,10 @@ struct attr; struct country_search; struct item; struct country_search *country_search_new(struct attr *search, int partial); -struct item *country_search_get_item(struct country_search *this_); -void country_search_destroy(struct country_search *this_); +struct item *country_search_get_item(struct country_search *this); +struct attr *country_default(void); +void country_search_destroy(struct country_search *this); +/* end of prototypes */ #ifdef __cplusplus } diff --git a/navit/src/gui/gtk/destination.c b/navit/src/gui/gtk/destination.c index 6af8b34..d557d75 100644 --- a/navit/src/gui/gtk/destination.c +++ b/navit/src/gui/gtk/destination.c @@ -9,6 +9,8 @@ #include "navit.h" #include "item.h" #include "coord.h" +#include "track.h" +#include "country.h" #include "search.h" #define COL_COUNT 8 @@ -302,6 +304,10 @@ int destination_address(struct navit *nav) GtkWidget *button1,*button2,*button3; int i; struct search_param *search=&search_param; + struct attr search_attr, country_name, *country_attr; + struct tracking *tracking; + struct country_search *cs; + struct item *item; search->nav=nav; @@ -395,5 +401,14 @@ int destination_address(struct navit *nav) gtk_widget_show_all(window2); gtk_socket_steal(GTK_SOCKET(keyboard), spawn_xkbd("xkbd","-geometry 200x100")); + country_attr=country_default(); + tracking=navit_get_tracking(nav); + if (tracking && tracking_get_current_attr(tracking, attr_country_id, &search_attr)) + country_attr=&search_attr; + cs=country_search_new(country_attr, 0); + item=country_search_get_item(cs); + if (item && item_attr_get(item, attr_country_name, &country_name)) + gtk_entry_set_text(GTK_ENTRY(search->entry_country), country_name.u.str); + country_search_destroy(cs); return 0; } diff --git a/navit/src/search.c b/navit/src/search.c index 5bca95a..b4b9211 100644 --- a/navit/src/search.c +++ b/navit/src/search.c @@ -63,6 +63,11 @@ search_list_search(struct search_list *this_, struct attr *search_attr, int part struct search_list_level *le; switch(search_attr->type) { case attr_country_all: + case attr_country_id: + case attr_country_iso2: + case attr_country_iso3: + case attr_country_car: + case attr_country_name: level=0; break; case attr_town_name: @@ -79,7 +84,8 @@ search_list_search(struct search_list *this_, struct attr *search_attr, int part this_->level=level; le=&this_->levels[level]; le->attr=*search_attr; - le->attr.u.str=g_strdup(search_attr->u.str); + if (search_attr->type != attr_country_id) + le->attr.u.str=g_strdup(search_attr->u.str); search_list_search_free(this_, level); le->partial=partial; if (level > 0) { diff --git a/navit/src/track.c b/navit/src/track.c index 1183fba..a80adf2 100644 --- a/navit/src/track.c +++ b/navit/src/track.c @@ -82,13 +82,17 @@ tracking_get_street_data(struct tracking *tr) int tracking_get_current_attr(struct tracking *_this, enum attr_type type, struct attr *attr) { - struct item *item=&_this->curr_line->street->item; + struct item *item; int result=0; + if (! _this->curr_line || ! _this->curr_line->street) + return 0; + item=&_this->curr_line->street->item; + if (! item) + return 0; struct map_rect *mr=map_rect_new(item->map,NULL); item=map_rect_get_item_byid(mr, item->id_hi, item->id_lo); - if (item_attr_get(item, attr_street_name, attr)){ + if (item_attr_get(item, type, attr)) result=1; - } map_rect_destroy(mr); return result; }