From eb95cc0d161a3d5408e182a56f70ba7b82b40370 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 18 Oct 2007 19:23:06 +0300 Subject: [PATCH] Split POI selection dialog from click select function. Move menu cb to cb.c --- src/cb.c | 9 ++++ src/poi-gui.c | 129 +++++++++++++++++++++++++------------------------- 2 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/cb.c b/src/cb.c index 95d68ae..7eb75c2 100644 --- a/src/cb.c +++ b/src/cb.c @@ -1164,6 +1164,15 @@ if ((way = find_nearest_waypoint(x2unit(_cmenu_position_x), y2unit(_cmenu_positi return TRUE; } +gboolean +menu_cb_category(GtkAction * action) +{ +if (category_list()) + map_force_redraw(); + +return TRUE; +} + gboolean cmenu_cb_way_add_poi(GtkAction * action) { diff --git a/src/poi-gui.c b/src/poi-gui.c index cb376cb..86328b6 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -31,7 +31,7 @@ static GtkWidget *dialog_qp; typedef struct _PoiCategoryEditInfo PoiCategoryEditInfo; -static struct _PoiCategoryEditInfo { +struct _PoiCategoryEditInfo { GtkWidget *cmb_category; guint cat_id; }; @@ -338,16 +338,6 @@ category_list() return TRUE; } -gboolean -menu_cb_category(GtkAction * action) -{ - - if (category_list()) - map_force_redraw(); - - return TRUE; -} - gboolean poi_delete_confirm(GtkWidget * widget, delete_poi * dpoi) { @@ -372,53 +362,34 @@ if (i == GTK_RESPONSE_OK) { return TRUE; } -gboolean -poi_select(guint unitx, guint unity, poi_info *poi) +gboolean +poi_search_dialog(GtkListStore *store, poi_info *poi) { -GtkWidget *dialog; -GtkWidget *list; -GtkWidget *sw; +GtkWidget *dialog, *list, *sw; +GtkWidget *hbox, *label, *search_entry; GtkTreeViewColumn *column; GtkCellRenderer *renderer; -GtkListStore *store; GtkTreeIter iter; gboolean selected = FALSE; -guint num_cats; - -if (poi_get_list(unitx, unity, &store, &num_cats)==FALSE) - return FALSE; - -switch (num_cats) { -case 0: - MACRO_BANNER_SHOW_INFO(_window, _("No POIs found.")); - g_object_unref(G_OBJECT(store)); - return FALSE; - break; -case 1: - gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); - gtk_tree_model_get(GTK_TREE_MODEL(store), - &iter, - POI_POIID, &(poi->poi_id), - POI_CATID, &(poi->cat_id), - POI_LAT, &(poi->lat), - POI_LON, &(poi->lon), - POI_LABEL, &(poi->label), - POI_DESC, &(poi->desc), -1); - g_object_unref(G_OBJECT(store)); - return TRUE; -break; -} -/* There are at least 2 matching POI's - let the user select one. */ dialog = gtk_dialog_new_with_buttons(_("Select POI"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, NULL); + GTK_WINDOW(_window), + GTK_DIALOG_MODAL, GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, + GTK_RESPONSE_REJECT, NULL); gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); +hbox = gtk_hbox_new(FALSE, 4), +gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), hbox, FALSE, FALSE, 0); + +label=gtk_label_new(_("Search:")); +gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); + +search_entry=gtk_entry_new(); +gtk_box_pack_start(GTK_BOX(hbox), search_entry, TRUE, TRUE, 0); + sw = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_ETCHED_IN); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); @@ -468,6 +439,40 @@ gtk_widget_destroy(dialog); return selected; } +gboolean +poi_select(guint unitx, guint unity, poi_info *poi) +{ +GtkListStore *store; +guint num_cats; +GtkTreeIter iter; + +if (poi_get_list(unitx, unity, &store, &num_cats)==FALSE) + return FALSE; + +switch (num_cats) { +case 0: + MACRO_BANNER_SHOW_INFO(_window, _("No POIs found.")); + g_object_unref(G_OBJECT(store)); + return FALSE; + break; +case 1: + gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); + gtk_tree_model_get(GTK_TREE_MODEL(store), + &iter, + POI_POIID, &(poi->poi_id), + POI_CATID, &(poi->cat_id), + POI_LAT, &(poi->lat), + POI_LON, &(poi->lon), + POI_LABEL, &(poi->label), + POI_DESC, &(poi->desc), -1); + g_object_unref(G_OBJECT(store)); + return TRUE; +break; +} + +return poi_search_dialog(store, poi); +} + static void poi_populate_cat_combo(GtkWidget * cmb_category, guint cat_id) { @@ -535,29 +540,23 @@ if (action == ACTION_EDIT_POI) { GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); - gtk_container_add(GTK_CONTAINER - (GTK_DIALOG(dialog)->action_area), + gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_delete = gtk_button_new_with_label(_("Delete"))); dpoi.dialog = dialog; dpoi.txt_label = g_strdup(poi.label); dpoi.id = poi.poi_id; - g_signal_connect(G_OBJECT(btn_delete), "clicked", - G_CALLBACK(poi_delete_confirm), &dpoi); + g_signal_connect(G_OBJECT(btn_delete), "clicked", G_CALLBACK(poi_delete_confirm), &dpoi); - gtk_dialog_add_button(GTK_DIALOG(dialog), - GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); + gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); } else { - if (SQLITE_ROW == sqlite3_step(poisql.nextlabel_poi)) - poi.label = g_strdup_printf("Point%06d", sqlite3_column_int(poisql.nextlabel_poi, 0)); - sqlite3_reset(poisql.nextlabel_poi); - unit2latlon(unitx, unity, poi.lat, poi.lon); poi.poi_id = 0; poi.cat_id = 0; poi.desc = g_strdup(""); + poi.label = g_strdup(""); dialog = gtk_dialog_new_with_buttons(_("Add POI"), GTK_WINDOW(_window), @@ -604,9 +603,11 @@ gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); gtk_table_attach(GTK_TABLE(table), hbox = gtk_hbox_new(FALSE, 4), 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_box_pack_start(GTK_BOX(hbox), cmb_category = gtk_combo_box_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(2, G_TYPE_INT, /* Category ID */ - G_TYPE_STRING))), /* Category Label */ - FALSE, FALSE, 4); + +/* Category ID, Label */ +cmb_category = gtk_combo_box_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING))); +gtk_box_pack_start(GTK_BOX(hbox), cmb_category, FALSE, FALSE, 4); + /* Set up the view for the combo box. */ { GtkCellRenderer *renderer; @@ -738,9 +739,9 @@ dialog_qp = gtk_dialog_new_with_buttons(_("Quick POI"), gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog_qp)->vbox), table = gtk_table_new(3, 3, FALSE), TRUE, TRUE, 0); -gtk_table_set_col_spacings(table, 6); -gtk_table_set_row_spacings(table, 6); -gtk_table_set_homogeneous(table, TRUE); +gtk_table_set_col_spacings(GTK_TABLE(table), 6); +gtk_table_set_row_spacings(GTK_TABLE(table), 6); +gtk_table_set_homogeneous(GTK_TABLE(table), TRUE); for (x=1;x<=3;x++) { for (y=1;y<=3;y++) { -- 2.39.5