Example #1
0
static void
navit_debug(struct navit *this_)
{
#if 0
#include "attr.h"
#include "item.h"
#include "search.h"
	struct attr attr;
	struct search_list *sl;
	struct search_list_result *res;

	debug_level_set("data_mg:town_search_get_item",1);
	debug_level_set("data_mg:town_search_compare",1);
	debug_level_set("data_mg:tree_search_next",1);
	sl=search_list_new(this_->mapsets->data);
	attr.type=attr_country_all;
	attr.u.str="Deu";
	search_list_search(sl, &attr, 1);
	while (res=search_list_get_result(sl)) {
		printf("country result\n");
	}
	attr.type=attr_town_name;
	attr.u.str="U";
	search_list_search(sl, &attr, 1);
	while (res=search_list_get_result(sl)) {
		printf("town result\n");
	}
	search_list_destroy(sl);
#endif
}
Example #2
0
static void changed(GtkWidget *widget, struct search_param *search)
{
	struct search_list_result *res;
	GtkTreeIter iter;

	search->attr.u.str=(char *)gtk_entry_get_text(GTK_ENTRY(widget));
	printf("changed %s\n", search->attr.u.str);
	if (widget == search->entry_country) {
		dbg(0,"country\n");
		search->attr.type=attr_country_all;
		set_columns(search, 0);
	}
	if (widget == search->entry_city) {
		dbg(0,"town\n");
		search->attr.type=attr_town_name;
		if (strlen(search->attr.u.str) < 3) 
			return;
		set_columns(search, 1);
	}
	if (widget == search->entry_street) {
		dbg(0,"street\n");
		search->attr.type=attr_street_name;
		set_columns(search, 2);
	}


	search_list_search(search->sl, &search->attr, 1);	
	gtk_list_store_clear(search->liststore);
	while((res=search_list_get_result(search->sl))) {
		gtk_list_store_append(search->liststore,&iter);
		gtk_list_store_set(search->liststore,&iter,COL_COUNT,res->c,-1);
		if (widget == search->entry_country) {
			if (res->country) {
				gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->country->iso3,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->country->iso2,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->country->name,-1);
			}
		} else {
			if (res->country)
				gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
			else
				gtk_list_store_set(search->liststore,&iter,0,"",-1);
			if (res->town) {
				gtk_list_store_set(search->liststore,&iter,1,res->town->postal,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->town->name,-1);
				gtk_list_store_set(search->liststore,&iter,3,"",-1);
			} else {
				gtk_list_store_set(search->liststore,&iter,1,"",-1);
				gtk_list_store_set(search->liststore,&iter,2,"",-1);
				gtk_list_store_set(search->liststore,&iter,3,"",-1);
			}
			if (res->street)
				gtk_list_store_set(search->liststore,&iter,4,res->street->name,-1);
			else
				gtk_list_store_set(search->liststore,&iter,4,"",-1);
			
		}
	}
}
void search(char * town_name,char* street_name, struct coord* result)
{

	struct attr country;
	country.type = attr_country_all;
	country.u.str = "United States";
	search_list * list = search_list_new(navit_get_mapset(getNavit()));
	search_list_search(list, &country, 0);
	search_list_result * res;
	while((res=search_list_get_result(list)));
	struct attr town;
	town.type = attr_town_name;
	town.u.str = town_name;
	printf("Searching Towns for ... %s\n",town_name);
	search_list_search(list, &town,0);
	while((res=search_list_get_result(list)))
	{
		printf("\t");
		printf(res->town->common.town_name);
		printf("\n");
	}
	struct attr str;
	str.type = attr_street_name;
	str.u.str = street_name;
	printf("Searching Streets for ... %s\n",street_name);
	search_list_search(list, &str,1);
	while((res=search_list_get_result(list)))
	{
		printf(res->street->name);
		struct coord_geo geoPoint;
		struct coord cor;
		cor.x = res->street->common.c->x;
		cor.y = res->street->common.c->y;
		transform_to_geo(projection_mg,&cor,&geoPoint);
		printf(" X Coord: %f",geoPoint.lat);
		printf(" Y Coord: %f\n",geoPoint.lng);
		result->x = cor.x;
		result->y = cor.y;
	}
}
Example #4
0
static void notify_apply(struct datawindow_priv *datawindow, int index, int param2)
{
    TCHAR txtBuffer[1024];
    char search_string[1024];
    struct attr search_attr;
    struct search_list_result *res;
    

    if ( index >= 0 )
    {
        ListView_GetItemText(datawindow->hwndList, index, 1, txtBuffer, 1024);

        TCHAR_TO_UTF8(txtBuffer, search_string);

        search_attr.type = datawindow->currentSearchState;
        search_attr.u.str = search_string;

        search_list_search(datawindow->sl, &search_attr, 0);
        res=search_list_get_result(datawindow->sl);
    }

    switch (datawindow->currentSearchState)
    {
    case attr_country_name:
    {
        datawindow->currentSearchState = attr_town_name;
    }
    break;
    case attr_town_name:
    {
        datawindow->currentSearchState = attr_street_name;
    }
    break;
    case attr_street_name:
    {
        navit_set_destination(datawindow->nav, res->c, "Mein Test", 1);
        DestroyWindow(datawindow->hwnd);
    }
    break;
    default:
        break;

    }

    setlayout(datawindow);

}
Example #5
0
static void changed(GtkWidget *widget, struct search_param *search)
{
	struct search_list_result *res;
	GtkTreeIter iter;
	GtkTreeSelection *sel;
	gchar buf[512];
	search->attr.u.str=(char *)gtk_entry_get_text(GTK_ENTRY(widget));
	
	printf("changed %s\n", search->attr.u.str);
	if (search->dontsearch)
		return;
	if (widget == search->entry_country) {
		dbg(0,"country\n");
		search->attr.type=attr_country_all;
		search->mode = 0;
		set_columns(search);
	}
	if (widget == search->entry_district) {
		dbg(0,"district\n");
		search->attr.type=attr_district_name;
		search->mode = 1;
		set_columns(search);
	}
	if (widget == search->entry_city) {
		dbg(0,"town\n");
		search->attr.type=attr_town_name;
		if (strlen(search->attr.u.str) < 2) 
			return;
		search->mode = 2;
		set_columns(search);
	}
	if (widget == search->entry_street) {
		dbg(0,"street\n");
		search->attr.type=attr_street_name;
		search->mode = 3;
		set_columns(search);
	}

	search_list_search(search->sl, &search->attr, 1);
	gtk_list_store_clear(search->liststore);
	while((res=search_list_get_result(search->sl))) {
		gtk_list_store_append(search->liststore,&iter);
		gtk_list_store_set(search->liststore,&iter,COORD_COL,res->c,-1);
		if (widget == search->entry_country) {
			if (res->country) {
				sprintf(buf, "%d", res->country->id);
				gtk_list_store_set(search->liststore,&iter,0,buf,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->country->car,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->country->iso3,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->country->iso2,-1);
				gtk_list_store_set(search->liststore,&iter,4,res->country->name,-1);
				gtk_list_store_set(search->liststore,&iter,RES_COL,res->country,-1);
			}
		} else if (widget == search->entry_district) {
			if (res->district) {
				sprintf(buf, "%d", res->district->id);
				gtk_list_store_set(search->liststore,&iter,0,buf,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->district->country,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->district->name,-1);
				gtk_list_store_set(search->liststore,&iter,RES_COL,res->district,-1);
			}
		} else if (widget == search->entry_city) {
//			if (res->country)
//				gtk_list_store_set(search->liststore,&iter,1,res->country->car,-1);
//			else
//				gtk_list_store_set(search->liststore,&iter,1,"",-1);
			if (res->town) {
				sprintf(buf, "%d", res->town->id);
				gtk_list_store_set(search->liststore,&iter,0,buf,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->town->country,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->town->district,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->town->postal,-1);
				gtk_list_store_set(search->liststore,&iter,4,res->town->name,-1);
				gtk_list_store_set(search->liststore,&iter,5,"",-1);
				gtk_list_store_set(search->liststore,&iter,RES_COL,res->town,-1);
			} else {
				gtk_list_store_set(search->liststore,&iter,0,"0",-1);
				gtk_list_store_set(search->liststore,&iter,1,"",-1);
				gtk_list_store_set(search->liststore,&iter,2,"",-1);
				gtk_list_store_set(search->liststore,&iter,3,"",-1);
				gtk_list_store_set(search->liststore,&iter,4,"",-1);
				gtk_list_store_set(search->liststore,&iter,5,"",-1);
			}
//			if (res->street)
//				gtk_list_store_set(search->liststore,&iter,4,res->street->name,-1);
//			else
//				gtk_list_store_set(search->liststore,&iter,4,"",-1);
			
		} else if (widget == search->entry_street) {
			if (res->street) {
				sprintf(buf, "%d", res->street->id);
				gtk_list_store_set(search->liststore,&iter,0,buf,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->street->country,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->street->district,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->street->postal,-1);
				gtk_list_store_set(search->liststore,&iter,4,res->street->city,-1);
				gtk_list_store_set(search->liststore,&iter,5,res->street->name,-1);
				gtk_list_store_set(search->liststore,&iter,6,"",-1);
				gtk_list_store_set(search->liststore,&iter,RES_COL,res->town,-1);
			}
		}
	}
}
Example #6
0
static void changed(GtkWidget *widget, struct search_param *search)
{
	struct search_list_result *res;
	GtkTreeIter iter;

	search->attr.u.str=(char *)gtk_entry_get_text(GTK_ENTRY(widget));
	printf("changed %s partial %d\n", search->attr.u.str, search->partial);
	if (widget == search->entry_country) {
		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 3, GTK_SORT_ASCENDING);
		dbg(0,"country\n");
		search->attr.type=attr_country_all;
		set_columns(search, 0);
	}
	if (widget == search->entry_postal) {
		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 1, GTK_SORT_ASCENDING);
		dbg(0,"postal\n");
		search->attr.type=attr_town_postal;
		if (strlen(search->attr.u.str) < 2)
			return;
		set_columns(search, 1);
	}
	if (widget == search->entry_city) {
		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 2, GTK_SORT_ASCENDING);
		dbg(0,"town\n");
		search->attr.type=attr_town_name;
		if (strlen(search->attr.u.str) < 3)
			return;
		set_columns(search, 1);
	}
	if (widget == search->entry_street) {
		dbg(0,"street\n");
		search->attr.type=attr_street_name;
		set_columns(search, 2);
	}


	search_list_search(search->sl, &search->attr, search->partial);
	gtk_list_store_clear(search->liststore);
	while((res=search_list_get_result(search->sl))) {
		gtk_list_store_append(search->liststore,&iter);
		gtk_list_store_set(search->liststore,&iter,COL_COUNT,res->c,-1);
		if (widget == search->entry_country) {
			if (res->country) {
				gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->country->iso3,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->country->iso2,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->country->name,-1);
			}
		} else {
			if (res->country)
				gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
			else
				gtk_list_store_set(search->liststore,&iter,0,"",-1);
			if (res->town) {
				gtk_list_store_set(search->liststore,&iter,1,res->town->common.postal,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->town->name,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->town->district,-1);
			} else {
				gtk_list_store_set(search->liststore,&iter,1,"",-1);
				gtk_list_store_set(search->liststore,&iter,2,"",-1);
				gtk_list_store_set(search->liststore,&iter,3,"",-1);
			}
			if (res->street)
				gtk_list_store_set(search->liststore,&iter,4,res->street->name,-1);
			else
				gtk_list_store_set(search->liststore,&iter,4,"",-1);

		}
	}
	if (! search->partial)
		next_focus(search, widget);
	search->partial=1;
}
Example #7
0
static void notify_textchange(struct datawindow_priv *datawindow, int param1, int param2)
{

    struct attr search_attr;
    struct search_list_result *res;
    char search_string[1024];
    TCHAR converted_iso2[32];
    

    int lineLength = Edit_LineLength(datawindow->hwndEdit, 0);
    TCHAR line[lineLength + 1];
    (void)Edit_GetLine(datawindow->hwndEdit, 0, line, lineLength  + 1);
    line[lineLength] = 0;


    (void)ListView_DeleteAllItems( datawindow->hwndList);

    TCHAR_TO_UTF8(line, search_string);

    search_attr.type = datawindow->currentSearchState;
    search_attr.u.str = search_string;

    if (lineLength<1)
        return;

    search_list_search(datawindow->sl, &search_attr, 1);


    TCHAR *tcharBuffer = NULL;
    int listIndex = 0;
    LVITEM lvI;

    lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
    lvI.state = 0;
    lvI.stateMask = 0;

    while ((res=search_list_get_result(datawindow->sl)) && listIndex < 50)
    {

        switch (search_attr.type)
        {
        case attr_country_name:
            tcharBuffer = newSysString(res->country->name);
            break;
        case attr_town_name:
            tcharBuffer = newSysString(res->town->common.town_name);
            break;
        case attr_street_name:
            if (res->street->name)
            {
                tcharBuffer = newSysString(res->street->name);
            }
            else
            {
                continue;
            }
            break;
        default:
            dbg(0, "Unhandled search type");
        }

        lvI.iItem = listIndex;
        lvI.iImage = listIndex;
        lvI.iSubItem = 0;
        lvI.lParam = (LPARAM) res->country->iso2;
        UTF8_TO_TCHAR(res->country->iso2, converted_iso2);
        lvI.pszText = converted_iso2;//LPSTR_TEXTCALLBACK; // sends an LVN_GETDISP message.
        (void)ListView_InsertItem(datawindow->hwndList, &lvI);
        ListView_SetItemText(datawindow->hwndList, listIndex, 1, tcharBuffer);
        g_free(tcharBuffer);
        dbg(0,"%s\n", res->country->name);
        listIndex++;
    }
}
Example #8
0
static void changed(GtkWidget *widget, struct search_param *search)
{
	struct search_list_result *res;
	GtkTreeIter iter;

	search->attr.u.str=(char *)gtk_entry_get_text(GTK_ENTRY(widget));
	printf("changed %s partial %d\n", search->attr.u.str, search->partial);
	if (widget == search->entry_country) {
		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 3, GTK_SORT_ASCENDING);
		dbg(0,"country\n");
		search->attr.type=attr_country_all;
		set_columns(search, 0);
	}
	if (widget == search->entry_postal) {
		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 1, GTK_SORT_ASCENDING);
		dbg(0,"postal\n");
		search->attr.type=attr_town_postal;
		if (strlen(search->attr.u.str) < 2)
			return;
		set_columns(search, 1);
	}
	if (widget == search->entry_city) {
		gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (search->liststore2), 2, GTK_SORT_ASCENDING);
		dbg(0,"town\n");
		search->attr.type=attr_town_name;
		if (strlen(search->attr.u.str) < 3)
			return;
		set_columns(search, 1);
	}
	if (widget == search->entry_street) {
		dbg(0,"street\n");
		search->attr.type=attr_street_name;
		// Searching for a street by just its first letter generates too many hits to be useful, 
		// plus it causes the GUI to become unresponsive because the search is single-threaded.
		// So we only start searching once we have two letters.
		if (strlen(search->attr.u.str) < 2)
			return;
		set_columns(search, 2);
	}

	search_list_search(search->sl, &search->attr, search->partial);
	gtk_list_store_clear(search->liststore);
	while((res=search_list_get_result(search->sl))) {
		gtk_list_store_append(search->liststore,&iter);
		gtk_list_store_set(search->liststore,&iter,COL_COUNT,res->c,-1);
		if (widget == search->entry_country) {
			if (res->country) {
				gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
				gtk_list_store_set(search->liststore,&iter,1,res->country->iso3,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->country->iso2,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->country->name,-1);
			}
		} else {
			if (res->country)
				gtk_list_store_set(search->liststore,&iter,0,res->country->car,-1);
			else
				gtk_list_store_set(search->liststore,&iter,0,"",-1);
			if (res->town) {
				gtk_list_store_set(search->liststore,&iter,1,res->town->common.postal,-1);
				gtk_list_store_set(search->liststore,&iter,2,res->town->common.town_name,-1);
				gtk_list_store_set(search->liststore,&iter,3,res->town->common.district_name,-1);
			} else {
				gtk_list_store_set(search->liststore,&iter,1,"",-1);
				gtk_list_store_set(search->liststore,&iter,2,"",-1);
				gtk_list_store_set(search->liststore,&iter,3,"",-1);
			}
			if (res->street)
				gtk_list_store_set(search->liststore,&iter,4,res->street->name,-1);
			else
				gtk_list_store_set(search->liststore,&iter,4,"",-1);

		}
	}
	
	if(! search->partial)
	{
	    if( widget == search->entry_country )
	    {
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
	    }
	    if( widget == search->entry_city )
	    {
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), TRUE);
	    }
	    if( widget == search->entry_street )
	    {
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), TRUE);
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), TRUE);
	    }
	} else {
	    if( widget == search->entry_country )
	    {
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_city), FALSE);
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
	    }
	    if( widget == search->entry_city )
	    {
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_street), FALSE);
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
	    }
	    if( widget == search->entry_street )
	    {
		gtk_widget_set_sensitive(GTK_WIDGET(search->entry_number), FALSE);
	    }
	}
	if (! search->partial)
		next_focus(search, widget);
	search->partial=1;
}