From 9709d545eb1c22dac0cbc5e7cc76bc340fc6cd84 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Wed, 24 Oct 2007 17:19:29 +0300 Subject: [PATCH] Formating only --- src/poi-gui.c | 429 +++++++++++++++++++++++++------------------------- 1 file changed, 211 insertions(+), 218 deletions(-) diff --git a/src/poi-gui.c b/src/poi-gui.c index 9aa0a63..60716f2 100644 --- a/src/poi-gui.c +++ b/src/poi-gui.c @@ -63,303 +63,296 @@ static gdouble qp_lat, qp_lon; static gboolean category_delete(GtkWidget *widget, delete_poi *dpoi) { - GtkWidget *dialog; - guint i; - gchar *buffer; - - buffer = g_strdup_printf("%s\n\t%s\n%s", _("Delete category?"), - dpoi->txt_label, _("WARNING: All POIs in that category will also be deleted!")); - dialog = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer); - g_free(buffer); - i = gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(GTK_WIDGET(dialog)); - - if (i == GTK_RESPONSE_OK) { - if (poi_category_delete(dpoi)==FALSE) - popup_error(_window, _("Problem deleting category or POI")); - gtk_widget_hide_all(dpoi->dialog); - map_force_redraw(); - } +GtkWidget *dialog; +guint i; +gchar *buffer; - return TRUE; +buffer = g_strdup_printf("%s\n\t%s\n%s", _("Delete category?"), + dpoi->txt_label, _("WARNING: All POIs in that category will also be deleted!")); +dialog = hildon_note_new_confirmation(GTK_WINDOW(_window), buffer); +g_free(buffer); +i = gtk_dialog_run(GTK_DIALOG(dialog)); +gtk_widget_destroy(GTK_WIDGET(dialog)); + +if (i == GTK_RESPONSE_OK) { + if (poi_category_delete(dpoi)==FALSE) + popup_error(_window, _("Problem deleting category or POI")); + gtk_widget_hide_all(dpoi->dialog); + map_force_redraw(); +} + +return TRUE; } gboolean category_dialog(guint cat_id) { - GtkWidget *dialog; - GtkWidget *table; - GtkWidget *label; - GtkWidget *txt_label; - GtkWidget *txt_desc; - GtkWidget *btn_delete = NULL; - GtkWidget *txt_scroll; - GtkWidget *chk_enabled; - GtkTextBuffer *desc_txt; - GtkTextIter begin, end; - gboolean results = TRUE; - delete_poi dpoi = { NULL, NULL, 0 }; - poi_category *c; - - - if (cat_id > 0) { - if (poi_category_get(cat_id, &c)==FALSE) - return FALSE; - - dialog = gtk_dialog_new_with_buttons(_("Edit Category"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, - GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, NULL); - - 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(c->label); - dpoi.id = c->id; - - g_signal_connect(G_OBJECT(btn_delete), "clicked", G_CALLBACK(category_delete), &dpoi); - - gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); - } else { - c=poi_category_new(); - c->enabled = 1; - c->label = g_strdup(""); - c->id = 0; - c->desc = g_strdup(""); - - dialog = gtk_dialog_new_with_buttons(_("Add Category"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, - GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, NULL); - } +GtkWidget *dialog; +GtkWidget *table; +GtkWidget *label; +GtkWidget *txt_label; +GtkWidget *txt_desc; +GtkWidget *btn_delete = NULL; +GtkWidget *txt_scroll; +GtkWidget *chk_enabled; +GtkTextBuffer *desc_txt; +GtkTextIter begin, end; +gboolean results = TRUE; +delete_poi dpoi = { NULL, NULL, 0 }; +poi_category *c; - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), - table = gtk_table_new(6, 4, FALSE), TRUE, TRUE, 0); +if (cat_id > 0) { + if (poi_category_get(cat_id, &c)==FALSE) + return FALSE; - 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); + dialog = gtk_dialog_new_with_buttons(_("Edit Category"), + GTK_WINDOW(_window), + GTK_DIALOG_MODAL, + GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, NULL); - 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); + 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(c->label); + dpoi.id = c->id; + + g_signal_connect(G_OBJECT(btn_delete), "clicked", G_CALLBACK(category_delete), &dpoi); + gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT); +} else { + c=poi_category_new(); + c->enabled = 1; + c->label = g_strdup(""); + c->id = 0; + c->desc = g_strdup(""); + + dialog = gtk_dialog_new_with_buttons(_("Add Category"), + GTK_WINDOW(_window), + GTK_DIALOG_MODAL, + GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, + 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_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_misc_set_alignment(GTK_MISC(label), 1.f, 0.5f); txt_scroll = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(txt_scroll), GTK_SHADOW_IN); +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_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); +txt_desc = gtk_text_view_new(); +gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(txt_desc), GTK_WRAP_WORD); - gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc); - gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60); +gtk_container_add(GTK_CONTAINER(txt_scroll), txt_desc); +gtk_widget_set_size_request(GTK_WIDGET(txt_scroll), 400, 60); - desc_txt = gtk_text_view_get_buffer(GTK_TEXT_VIEW(txt_desc)); +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); +/* label */ +gtk_entry_set_text(GTK_ENTRY(txt_label), c->label); - /* desc */ - gtk_text_buffer_set_text(desc_txt, c->desc, -1); +/* desc */ +gtk_text_buffer_set_text(desc_txt, c->desc, -1); - /* enabled */ - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled), (c->enabled == 1 ? TRUE : FALSE)); +/* enabled */ +gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chk_enabled), (c->enabled == 1 ? TRUE : FALSE)); - poi_category_free(c); +poi_category_free(c); - gtk_widget_show_all(dialog); +gtk_widget_show_all(dialog); - while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label)))) { - c=poi_category_new(); - c->label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label))); - } else { - popup_error(dialog,_("Please specify a name for the category.")); - continue; - } +while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { + if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_label)))) { + c=poi_category_new(); + c->label = g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_label))); + } else { + popup_error(dialog,_("Please specify a name for the category.")); + continue; + } - gtk_text_buffer_get_iter_at_offset(desc_txt, &begin, 0); - gtk_text_buffer_get_end_iter(desc_txt, &end); - c->desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE); - c->enabled = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0); + gtk_text_buffer_get_iter_at_offset(desc_txt, &begin, 0); + gtk_text_buffer_get_end_iter(desc_txt, &end); + c->desc = gtk_text_buffer_get_text(desc_txt, &begin, &end, TRUE); + c->enabled = (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(chk_enabled)) ? 1 : 0); - results=poi_category_update(cat_id, c); + results=poi_category_update(cat_id, c); - if (results==FALSE) - popup_error(_window, _("Problem updating category")); - poi_category_free(c); - } + if (results==FALSE) + popup_error(_window, _("Problem updating category")); + poi_category_free(c); +} - g_free(dpoi.txt_label); - g_object_unref(desc_txt); - gtk_widget_hide_all(dialog); +g_free(dpoi.txt_label); +g_object_unref(desc_txt); +gtk_widget_hide_all(dialog); - return results; +return results; } static void category_toggled(GtkCellRendererToggle * cell, gchar * path, gpointer data) { - GtkTreeIter iter; - gboolean cat_enabled; - guint cat_id; +GtkTreeIter iter; +gboolean cat_enabled; +guint cat_id; - GtkTreeModel *model = GTK_TREE_MODEL(data); - if (!gtk_tree_model_get_iter_from_string(model, &iter, path)) - return; +GtkTreeModel *model = GTK_TREE_MODEL(data); +if (!gtk_tree_model_get_iter_from_string(model, &iter, path)) + return; - gtk_tree_model_get(model, &iter, CAT_ENABLED, &cat_enabled, -1); - gtk_tree_model_get(model, &iter, CAT_ID, &cat_id, -1); +gtk_tree_model_get(model, &iter, CAT_ENABLED, &cat_enabled, -1); +gtk_tree_model_get(model, &iter, CAT_ID, &cat_id, -1); - cat_enabled ^= 1; +cat_enabled ^= 1; - if (poi_category_toggle(cat_id, cat_enabled)==FALSE) { - popup_error(_window, _("Problem updating Category")); - } else { - gtk_list_store_set(GTK_LIST_STORE(model), &iter, CAT_ENABLED, cat_enabled, -1); - } +if (poi_category_toggle(cat_id, cat_enabled)==FALSE) { + popup_error(_window, _("Problem updating Category")); +} else { + gtk_list_store_set(GTK_LIST_STORE(model), &iter, CAT_ENABLED, cat_enabled, -1); +} } static gboolean category_add(GtkWidget * widget, GtkWidget * tree_view) { - GtkListStore *store; +GtkListStore *store; - if (category_dialog(0)) { - store = poi_category_generate_store(); - gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), - GTK_TREE_MODEL(store)); - g_object_unref(G_OBJECT(store)); - } - return TRUE; +if (category_dialog(0)) { + store = poi_category_generate_store(); + gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(store)); + g_object_unref(G_OBJECT(store)); +} +return TRUE; } static gboolean category_edit(GtkWidget * widget, GtkWidget * tree_view) { - GtkTreeIter iter; - GtkTreeModel *store; - GtkTreeSelection *selection; - - store = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); - selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); - if (gtk_tree_selection_get_selected(selection, &store, &iter)) { - GValue val; - 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 = poi_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)); - } +GtkTreeIter iter; +GtkTreeModel *store; +GtkTreeSelection *selection; + +store = gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)); +selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); +if (gtk_tree_selection_get_selected(selection, &store, &iter)) { + GValue val; + 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 = poi_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)); } - return TRUE; +} +return TRUE; } gboolean category_list() { - GtkWidget *dialog; - GtkWidget *tree_view; - GtkWidget *sw; - GtkWidget *btn_edit; - GtkWidget *btn_add; - GtkTreeViewColumn *column; - GtkCellRenderer *renderer; - GtkListStore *store; +GtkWidget *dialog; +GtkWidget *tree_view; +GtkWidget *sw; +GtkWidget *btn_edit; +GtkWidget *btn_add; +GtkTreeViewColumn *column; +GtkCellRenderer *renderer; +GtkListStore *store; - dialog = gtk_dialog_new_with_buttons(_("POI Categories"), - GTK_WINDOW(_window), - GTK_DIALOG_MODAL, GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, NULL); +dialog = gtk_dialog_new_with_buttons(_("POI Categories"), + GTK_WINDOW(_window), + GTK_DIALOG_MODAL, GTK_STOCK_OK, + GTK_RESPONSE_ACCEPT, NULL); #ifdef WITH_OSSO_HELP /* Enable the help button. */ ossohelp_dialog_help_enable(GTK_DIALOG(dialog), HELP_ID_POICAT, _osso); #endif - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), - btn_edit = gtk_button_new_with_label(_("Edit"))); +gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), + btn_edit = gtk_button_new_with_label(_("Edit"))); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), - btn_add = gtk_button_new_with_label(_("Add"))); +gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), + btn_add = gtk_button_new_with_label(_("Add"))); - store = poi_category_generate_store(); +store = poi_category_generate_store(); - if (!store) - return TRUE; +if (!store) + return TRUE; - sw = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0); +sw = gtk_scrolled_window_new(NULL, NULL); +gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); +gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), sw, TRUE, TRUE, 0); - tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); - /* Maemo-related? */ - g_object_set(tree_view, "allow-checkbox-mode", FALSE, NULL); - gtk_container_add(GTK_CONTAINER(sw), tree_view); +tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); +/* Maemo-related? */ +g_object_set(tree_view, "allow-checkbox-mode", FALSE, NULL); +gtk_container_add(GTK_CONTAINER(sw), tree_view); - gtk_tree_selection_set_mode(gtk_tree_view_get_selection (GTK_TREE_VIEW(tree_view)), GTK_SELECTION_SINGLE); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE); +gtk_tree_selection_set_mode(gtk_tree_view_get_selection (GTK_TREE_VIEW(tree_view)), GTK_SELECTION_SINGLE); +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); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); - gtk_tree_view_column_set_max_width(column, 1); +renderer = gtk_cell_renderer_text_new(); +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, "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); +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, "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)); +g_object_unref(G_OBJECT(store)); - renderer = gtk_cell_renderer_text_new(); - 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(_("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, "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(_("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, "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); +renderer = gtk_cell_renderer_text_new(); +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_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), tree_view); +g_signal_connect(G_OBJECT(btn_add), "clicked", G_CALLBACK(category_add), tree_view); - gtk_widget_show_all(dialog); - while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - break; - } - gtk_widget_destroy(dialog); +gtk_widget_show_all(dialog); +while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { + break; +} +gtk_widget_destroy(dialog); - return TRUE; +return TRUE; } gboolean -- 2.39.5