Made some reasonable defaults for country in destination dialog
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 5 Nov 2007 17:52:39 +0000 (17:52 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Mon, 5 Nov 2007 17:52:39 +0000 (17:52 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@532 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/src/country.c
navit/src/country.h
navit/src/gui/gtk/destination.c
navit/src/search.c
navit/src/track.c

index 4adf632..7373f99 100644 (file)
@@ -1,5 +1,6 @@
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <glib.h>
 #include <libintl.h>
 #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)
 {
index edc9635..465c305 100644 (file)
@@ -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
 }
index 6af8b34..d557d75 100644 (file)
@@ -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;
 }
index 5bca95a..b4b9211 100644 (file)
@@ -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) {
index 1183fba..a80adf2 100644 (file)
@@ -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;
 }