From: Kaj-Michael Lang Date: Fri, 27 Jul 2007 10:31:18 +0000 (+0300) Subject: Use correct index to get poi count. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=af40a67f2d5cec6d58562f35be885510adf3fd49;p=mapper Use correct index to get poi count. Allow sorting in category table. --- diff --git a/src/poi-gui.c b/src/poi-gui.c index 62e3926..64d16ec 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -275,7 +275,8 @@ void category_toggled(GtkCellRendererToggle * cell, gchar * path, gpointer data) vprintf("%s(): return TRUE\n", __PRETTY_FUNCTION__); } -GtkListStore *generate_store() +static GtkListStore * +category_generate_store() { GtkTreeIter iter; GtkListStore *store; @@ -289,15 +290,11 @@ GtkListStore *generate_store() while (SQLITE_ROW == sqlite3_step(_stmt_selall_cat)) { gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, - CAT_ID, sqlite3_column_int(_stmt_selall_cat, - 0), CAT_ENABLED, - sqlite3_column_int(_stmt_selall_cat, 3), - CAT_LABEL, - sqlite3_column_text(_stmt_selall_cat, 1), - CAT_DESC, - sqlite3_column_text(_stmt_selall_cat, 2), - CAT_POI_CNT, - sqlite3_column_int(_stmt_selall_cat, 4), -1); + CAT_ID, sqlite3_column_int(_stmt_selall_cat, 0), + CAT_ENABLED, sqlite3_column_int(_stmt_selall_cat, 3), + CAT_LABEL, sqlite3_column_text(_stmt_selall_cat, 1), + CAT_DESC, sqlite3_column_text(_stmt_selall_cat, 2), + CAT_POI_CNT, sqlite3_column_int(_stmt_selall_cat, 6), -1); } sqlite3_reset(_stmt_selall_cat); @@ -305,13 +302,14 @@ GtkListStore *generate_store() return store; } -gboolean category_add(GtkWidget * widget, GtkWidget * tree_view) +gboolean +category_add(GtkWidget * widget, GtkWidget * tree_view) { GtkListStore *store; printf("%s()\n", __PRETTY_FUNCTION__); if (category_dialog(0)) { - store = generate_store(); + store = category_generate_store(); gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(store)); g_object_unref(G_OBJECT(store)); @@ -334,7 +332,7 @@ gboolean category_edit(GtkWidget * widget, GtkWidget * tree_view) memset(&val, 0, sizeof(val)); gtk_tree_model_get_value(store, &iter, 0, &val); if (category_dialog(g_value_get_uint(&val))) { - GtkListStore *new_store = generate_store(); + GtkListStore *new_store = category_generate_store(); gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(new_store)); g_object_unref(G_OBJECT(new_store)); @@ -372,7 +370,7 @@ gboolean category_list() gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), btn_add = gtk_button_new_with_label(_("Add"))); - store = generate_store(); + store = category_generate_store(); if (!store) return TRUE; @@ -394,40 +392,37 @@ gboolean category_list() gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE); renderer = gtk_cell_renderer_text_new(); - column = - gtk_tree_view_column_new_with_attributes(_("ID"), renderer, "text", - CAT_ID, NULL); + column = gtk_tree_view_column_new_with_attributes(_("ID"), renderer, "text", CAT_ID, NULL); 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); - column = - gtk_tree_view_column_new_with_attributes(_("Enabled"), renderer, + 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); g_object_unref(G_OBJECT(store)); renderer = gtk_cell_renderer_text_new(); - column = - gtk_tree_view_column_new_with_attributes(_("Label"), renderer, + column = gtk_tree_view_column_new_with_attributes(_("Label"), renderer, "text", CAT_LABEL, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); + gtk_tree_view_column_set_sort_column_id (column, CAT_LABEL); renderer = gtk_cell_renderer_text_new(); - column = - gtk_tree_view_column_new_with_attributes(_("Description"), renderer, + column = gtk_tree_view_column_new_with_attributes(_("Description"), renderer, "text", CAT_DESC, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); renderer = gtk_cell_renderer_text_new(); - column = - gtk_tree_view_column_new_with_attributes(_("# POIs"), renderer, + column = gtk_tree_view_column_new_with_attributes(_("# POIs"), renderer, "text", CAT_POI_CNT, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); + gtk_tree_view_column_set_sort_column_id (column, CAT_POI_CNT); gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); gtk_widget_show_all(dialog);