From: Kaj-Michael Lang Date: Wed, 24 Oct 2007 15:14:45 +0000 (+0300) Subject: More POI search UI work. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d4ed3638e3fc3d9c8e82c1dc342dffe07ebf79b;p=mapper More POI search UI work. --- diff --git a/src/cb.c b/src/cb.c index 4cc0675..e5d83fd 100644 --- a/src/cb.c +++ b/src/cb.c @@ -980,8 +980,17 @@ poi_dialog(ACTION_ADD_POI, x2unit(_cmenu_position_x), y2unit(_cmenu_position_y)) return TRUE; } +gboolean +cb_poi_search(GtkAction *action) +{ +poi_info poi; + +poi_search_dialog(NULL, &poi); +return TRUE; +} + gboolean -cb_add_poi(GtkAction *action) +cb_poi_add(GtkAction *action) { guint unitx, unity; const gchar *name = gtk_action_get_name(action); diff --git a/src/cb.h b/src/cb.h index 4b070a6..53c2105 100644 --- a/src/cb.h +++ b/src/cb.h @@ -86,7 +86,8 @@ gboolean cmenu_cb_loc_set_gps(GtkAction * action); gboolean cmenu_cb_loc_set_home(GtkAction * action); gboolean cmenu_cb_loc_set_destination(GtkAction *action); -gboolean cb_add_poi(GtkAction * action); +gboolean cb_poi_add(GtkAction * action); +gboolean cb_poi_search(GtkAction *action); /* Callbacks for the "Waypoint" context menu. */ gboolean cmenu_cb_way_show_latlon(GtkAction * action); diff --git a/src/poi-gui.c b/src/poi-gui.c index 60716f2..6a20be5 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -84,6 +84,51 @@ if (i == GTK_RESPONSE_OK) { return TRUE; } +GtkWidget * +category_combo_new(void) +{ +GtkWidget *cmb; +GtkCellRenderer *renderer; + +/* Category ID, Label */ +cmb=gtk_combo_box_new_with_model(GTK_TREE_MODEL(gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING))); + +/* Set up the view for the combo box. */ +renderer = gtk_cell_renderer_text_new(); +gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cmb), renderer, TRUE); +gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cmb), renderer, "text", 1, NULL); + +return cmb; +} + +static void +poi_category_combo_populate(GtkWidget *cmb_category, guint cat_id) +{ +GtkTreeIter active; +GtkListStore *store; +gboolean has_active = FALSE; + +store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category))); +gtk_list_store_clear(store); + +while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) { + GtkTreeIter iter; + guint cid = sqlite3_column_int(poisql.selall_cat, 0); + gtk_list_store_append(store, &iter); + gtk_list_store_set(store, &iter, 0, cid, 1, sqlite3_column_text(poisql.selall_cat, 1), -1); + if (cid == cat_id) { + active = iter; + has_active = TRUE; + } +} +sqlite3_reset(poisql.selall_cat); + +if (!has_active) + gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active); + +gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &active); +} + gboolean category_dialog(guint cat_id) { @@ -111,8 +156,7 @@ if (cat_id > 0) { 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; @@ -137,25 +181,18 @@ if (cat_id > 0) { GTK_RESPONSE_REJECT, NULL); } -gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), - table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0); +gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0); -gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Label")), - 0, 1, 0, 1, GTK_FILL, 0, 2, 4); +gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Label")), 0, 1, 0, 1, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); -gtk_table_attach(GTK_TABLE(table), - txt_label = gtk_entry_new(), - 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4); - gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")), - 0, 1, 1, 2, GTK_FILL, 0, 2, 4); +gtk_table_attach(GTK_TABLE(table), txt_label = gtk_entry_new(), 1, 2, 0, 1, GTK_EXPAND | GTK_FILL, 0, 2, 4); +gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")), 0, 1, 1, 2, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); - txt_scroll = gtk_scrolled_window_new(NULL, NULL); +txt_scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll), GTK_SHADOW_IN); - gtk_table_attach(GTK_TABLE(table), - txt_scroll, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4); +gtk_table_attach(GTK_TABLE(table), txt_scroll, 1, 2, 1, 2, GTK_EXPAND | GTK_FILL, 0, 2, 4); -gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); +gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(txt_scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); txt_desc = gtk_text_view_new(); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD); @@ -165,9 +202,7 @@ gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60); desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc)); -gtk_table_attach(GTK_TABLE(table), - chk_enabled = gtk_check_button_new_with_label(_("Enabled")), 0, 2, 2, - 3, GTK_EXPAND | GTK_FILL, 0, 2, 4); +gtk_table_attach(GTK_TABLE(table), chk_enabled = gtk_check_button_new_with_label(_("Enabled")), 0, 2, 2, 3, GTK_EXPAND | GTK_FILL, 0, 2, 4); /* label */ gtk_entry_set_text(GTK_ENTRY(txt_label), c->label); @@ -211,7 +246,7 @@ return results; } static void -category_toggled(GtkCellRendererToggle * cell, gchar * path, gpointer data) +category_toggled_cb(GtkCellRendererToggle * cell, gchar * path, gpointer data) { GtkTreeIter iter; gboolean cat_enabled; @@ -235,7 +270,7 @@ if (poi_category_toggle(cat_id, cat_enabled)==FALSE) { } static gboolean -category_add(GtkWidget * widget, GtkWidget * tree_view) +category_add_cb(GtkWidget *widget, GtkWidget *tree_view) { GtkListStore *store; @@ -248,7 +283,7 @@ return TRUE; } static gboolean -category_edit(GtkWidget * widget, GtkWidget * tree_view) +category_edit_cb(GtkWidget *widget, GtkWidget *tree_view) { GtkTreeIter iter; GtkTreeModel *store; @@ -320,7 +355,7 @@ gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); gtk_tree_view_column_set_max_width(column, 1); renderer = gtk_cell_renderer_toggle_new(); -g_signal_connect(renderer, "toggled", G_CALLBACK(category_toggled), store); +g_signal_connect(renderer, "toggled", G_CALLBACK(category_toggled_cb), store); column = gtk_tree_view_column_new_with_attributes(_("Enabled"), renderer, "active", CAT_ENABLED, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); gtk_tree_view_column_set_sort_column_id (column, CAT_ENABLED); @@ -343,8 +378,8 @@ gtk_tree_view_column_set_sort_column_id (column, CAT_POI_CNT); gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); -g_signal_connect(G_OBJECT(btn_edit), "clicked", G_CALLBACK(category_edit), tree_view); -g_signal_connect(G_OBJECT(btn_add), "clicked", G_CALLBACK(category_add), tree_view); +g_signal_connect(G_OBJECT(btn_edit), "clicked", G_CALLBACK(category_edit_cb), tree_view); +g_signal_connect(G_OBJECT(btn_add), "clicked", G_CALLBACK(category_add_cb), tree_view); gtk_widget_show_all(dialog); while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { @@ -379,11 +414,29 @@ if (i == GTK_RESPONSE_OK) { return TRUE; } +static gboolean +poi_search_do_cb(GtkWidget *widget, gpointer data) +{ +return TRUE; +} + +static gboolean +poi_goto_cb(GtkWidget *widget, gpointer data) +{ +return TRUE; +} + +static gboolean +poi_route_to_cb(GtkWidget *widget, gpointer data) +{ +return TRUE; +} + gboolean poi_search_dialog(GtkListStore *store, poi_info *poi) { -GtkWidget *dialog, *list, *sw; -GtkWidget *hbox, *label, *search_entry; +GtkWidget *dialog, *list, *sw, *cmb_category; +GtkWidget *hbox, *label, *search_entry, *btn_search, *btn_goto, *btn_route_to; GtkTreeViewColumn *column; GtkCellRenderer *renderer; GtkTreeIter iter; @@ -396,6 +449,12 @@ dialog = gtk_dialog_new_with_buttons(_("Select POI"), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); +gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), + btn_goto = gtk_button_new_with_label(_("Go"))); + +gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), + btn_route_to = gtk_button_new_with_label(_("Route to"))); + gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); hbox = gtk_hbox_new(FALSE, 4), @@ -404,9 +463,16 @@ 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); +cmb_category = category_combo_new(); +gtk_box_pack_start(GTK_BOX(hbox), cmb_category, FALSE, FALSE, 0); +poi_category_combo_populate(cmb_category, 0); + search_entry=gtk_entry_new(); gtk_box_pack_start(GTK_BOX(hbox), search_entry, TRUE, TRUE, 0); +btn_search=gtk_button_new_with_label(_("Search")); +gtk_box_pack_start(GTK_BOX(hbox), btn_search, FALSE, FALSE, 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); @@ -435,6 +501,10 @@ column = gtk_tree_view_column_new_with_attributes(_("Category"), renderer, "text gtk_tree_view_column_set_sort_column_id (column, POI_CATLAB); gtk_tree_view_append_column(GTK_TREE_VIEW(list), column); +g_signal_connect(G_OBJECT(btn_search), "clicked", G_CALLBACK(poi_search_do_cb), NULL); +g_signal_connect(G_OBJECT(btn_goto), "clicked", G_CALLBACK(poi_goto_cb), NULL); +g_signal_connect(G_OBJECT(btn_route_to), "clicked", G_CALLBACK(poi_route_to_cb), NULL); + gtk_widget_show_all(dialog); while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { @@ -490,39 +560,11 @@ break; return poi_search_dialog(store, poi); } -static void -poi_populate_cat_combo(GtkWidget * cmb_category, guint cat_id) -{ -GtkTreeIter active; -GtkListStore *store; -gboolean has_active = FALSE; - -store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(cmb_category))); -gtk_list_store_clear(store); - -while (SQLITE_ROW == sqlite3_step(poisql.selall_cat)) { - GtkTreeIter iter; - guint cid = sqlite3_column_int(poisql.selall_cat, 0); - gtk_list_store_append(store, &iter); - gtk_list_store_set(store, &iter, 0, cid, 1, sqlite3_column_text(poisql.selall_cat, 1), -1); - if (cid == cat_id) { - active = iter; - has_active = TRUE; - } -} -sqlite3_reset(poisql.selall_cat); - -if (!has_active) - gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &active); - -gtk_combo_box_set_active_iter(GTK_COMBO_BOX(cmb_category), &active); -} - gboolean poi_edit_cat(GtkWidget * widget, PoiCategoryEditInfo * data) { if (category_list()) - poi_populate_cat_combo(data->cmb_category, data->cat_id); + poi_category_combo_populate(data->cmb_category, data->cat_id); return TRUE; } @@ -621,25 +663,12 @@ gtk_table_attach(GTK_TABLE(table), hbox = gtk_hbox_new(FALSE, 4), 1, 2, 3, 4, GTK_EXPAND | GTK_FILL, 0, 2, 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))); +cmb_category = category_combo_new(); gtk_box_pack_start(GTK_BOX(hbox), cmb_category, FALSE, FALSE, 4); -/* Set up the view for the combo box. */ -{ - GtkCellRenderer *renderer; - renderer = gtk_cell_renderer_text_new(); - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(cmb_category), renderer, TRUE); - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(cmb_category), renderer, "text", 1, NULL); -} - -gtk_box_pack_start(GTK_BOX(hbox), - btn_catedit = gtk_button_new_with_label(_("Edit Categories...")), - FALSE, FALSE, 4); +gtk_box_pack_start(GTK_BOX(hbox), btn_catedit = gtk_button_new_with_label(_("Edit Categories...")), FALSE, FALSE, 4); -gtk_table_attach(GTK_TABLE(table), - label = gtk_label_new(_("Description")), - 0, 1, 5, 6, GTK_FILL, 0, 2, 4); +gtk_table_attach(GTK_TABLE(table), label = gtk_label_new(_("Description")), 0, 1, 5, 6, GTK_FILL, 0, 2, 4); gtk_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); txt_scroll = gtk_scrolled_window_new(NULL, NULL); @@ -660,7 +689,7 @@ desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc)); gtk_entry_set_text(GTK_ENTRY(txt_label), poi.label); /* category */ -poi_populate_cat_combo(cmb_category, poi.cat_id); +poi_category_combo_populate(cmb_category, poi.cat_id); /* poi_desc */ gtk_text_buffer_set_text(desc_txt, poi.desc, -1); diff --git a/src/poi-gui.h b/src/poi-gui.h index 3694ed7..a4cb365 100644 --- a/src/poi-gui.h +++ b/src/poi-gui.h @@ -8,5 +8,6 @@ gboolean poi_select(guint unitx, guint unity, poi_info *poi); gboolean category_dialog(guint cat_id); gboolean category_list(); gboolean poi_dialog(POIAction action, guint unitx, guint unity); +gboolean poi_search_dialog(GtkListStore *store, poi_info *poi); #endif diff --git a/src/ui-common.c b/src/ui-common.c index 133862a..fa7fcd4 100644 --- a/src/ui-common.c +++ b/src/ui-common.c @@ -213,9 +213,9 @@ static GtkActionEntry ui_entries[] = { {"poi", NULL, N_("_Poi"), NULL, NULL, NULL }, {"poi_categories", GTK_STOCK_INDEX, N_("_Categories.."), NULL, NULL, G_CALLBACK(menu_cb_category) }, {"poi_settings", GTK_STOCK_PREFERENCES, N_("_Settings..."), NULL, NULL, NULL }, - {"poi_add", GTK_STOCK_ADD, N_("_Add"), "A", NULL, G_CALLBACK(cb_add_poi) }, - {"poi_quick_add", GTK_STOCK_ABOUT, N_("_Quick Add"), "E", NULL, G_CALLBACK(cb_add_poi) }, - {"poi_search", GTK_STOCK_FIND, N_("_Search..."), NULL, NULL, NULL }, + {"poi_add", GTK_STOCK_ADD, N_("_Add"), "A", NULL, G_CALLBACK(cb_poi_add) }, + {"poi_quick_add", GTK_STOCK_ABOUT, N_("_Quick Add"), "E", NULL, G_CALLBACK(cb_poi_add) }, + {"poi_search", GTK_STOCK_FIND, N_("_Search..."), NULL, NULL, G_CALLBACK(cb_poi_search) }, {"map", NULL, N_("_Map"), NULL, NULL, NULL }, {"map_maps", NULL, N_("_Maps"), NULL, NULL, NULL },