#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#include <glib.h>
#include <libintl.h>
#include "debug.h"
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;
}
}
+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)
{
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
}
#include "navit.h"
#include "item.h"
#include "coord.h"
+#include "track.h"
+#include "country.h"
#include "search.h"
#define COL_COUNT 8
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;
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;
}
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:
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) {
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;
}