From d645d1f2362a623b037cbfa09405e09b0f530c71 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Wed, 17 Jan 2001 06:56:04 +0000 Subject: Load frames. 2001-01-16 Miguel de Icaza * e-table-config.c (configure_sort_dialog): Load frames. * Kill e-table-config-field.c * e-table-specification.c (e_table_specification_save_to_file): Specify version to xmlNewDoc. * e-table-state.c (e_table_state_save_to_string): Specify version to xmlNewDoc. * e-table-config.c (config_destroy): Destroy the copies. Unref the originals. (e_table_config_construct): Duplicate values of configuration here. (configure_sort_dialog): New function that populates the sort gtk combo boxes. * e-table.c (et_col_spec_to_col): Fixup use of title here. Do the actual translation here. * e-table-column-specification.c: Remove title_, it is now called title. Translation needs to take place elsewhere, not here * e-table-specification.c (e_table_specification_duplicate): Add preconditions here. (e_table_specification_save_to_node): ditto. (e_table_specification_save_to_string): ditto. (e_table_specification_save_to_file): ditto. * e-table-state.c (e_table_state_duplicate): Implement. * e-table-config.glade (dialog_sort): Change drop down menus to use GtkComboText widgets. * e-table-config.c (configure_dialog): New function, used to set up dialogs. svn path=/trunk/; revision=7563 --- widgets/table/e-table-column-specification.c | 20 +- widgets/table/e-table-column-specification.h | 2 +- widgets/table/e-table-config.c | 211 ++++++++--------- widgets/table/e-table-config.glade | 340 +++++++++++---------------- widgets/table/e-table-config.glade.h | 5 +- widgets/table/e-table-config.h | 12 +- widgets/table/e-table-specification.c | 26 +- widgets/table/e-table-state.c | 65 +++-- widgets/table/e-table-state.h | 2 +- widgets/table/e-table.c | 31 ++- 10 files changed, 344 insertions(+), 370 deletions(-) diff --git a/widgets/table/e-table-column-specification.c b/widgets/table/e-table-column-specification.c index ddd0f0bfef..68c19188b1 100644 --- a/widgets/table/e-table-column-specification.c +++ b/widgets/table/e-table-column-specification.c @@ -23,7 +23,7 @@ static GtkObjectClass *etcs_parent_class; static void free_strings (ETableColumnSpecification *etcs) { - g_free(etcs->title_); + g_free(etcs->title); g_free(etcs->pixbuf); g_free(etcs->cell); g_free(etcs->compare); @@ -51,7 +51,7 @@ static void etcs_init (ETableColumnSpecification *specification) { specification->model_col = 0; - specification->title_ = g_strdup(""); + specification->title = g_strdup(""); specification->pixbuf = NULL; specification->expansion = 0; @@ -73,13 +73,13 @@ e_table_column_specification_new (void) } void -e_table_column_specification_load_from_node (ETableColumnSpecification *etcs, - const xmlNode *node) +e_table_column_specification_load_from_node (ETableColumnSpecification *etcs, + const xmlNode *node) { free_strings(etcs); etcs->model_col = e_xml_get_integer_prop_by_name(node, "model_col"); - etcs->title_ = e_xml_get_translated_string_prop_by_name(node, "_title"); + etcs->title = e_xml_get_string_prop_by_name(node, "_title"); etcs->pixbuf = e_xml_get_string_prop_by_name(node, "pixbuf"); etcs->expansion = e_xml_get_double_prop_by_name(node, "expansion"); @@ -89,13 +89,13 @@ e_table_column_specification_load_from_node (ETableColumnSpecification *etcs, etcs->cell = e_xml_get_string_prop_by_name(node, "cell"); etcs->compare = e_xml_get_string_prop_by_name(node, "compare"); - if (etcs->title_ == NULL) - etcs->title_ = g_strdup(""); + if (etcs->title == NULL) + etcs->title = g_strdup(""); } xmlNode * -e_table_column_specification_save_to_node (ETableColumnSpecification *specification, - xmlNode *parent) +e_table_column_specification_save_to_node (ETableColumnSpecification *specification, + xmlNode *parent) { xmlNode *node; if (parent) @@ -104,7 +104,7 @@ e_table_column_specification_save_to_node (ETableColumnSpecification *speci node = xmlNewNode(NULL, "ETableColumn"); e_xml_set_integer_prop_by_name(node, "model_col", specification->model_col); - e_xml_set_string_prop_by_name(node, "_title", specification->title_); + e_xml_set_string_prop_by_name(node, "_title", specification->title); e_xml_set_string_prop_by_name(node, "pixbuf", specification->pixbuf); e_xml_set_double_prop_by_name(node, "expansion", specification->expansion); diff --git a/widgets/table/e-table-column-specification.h b/widgets/table/e-table-column-specification.h index 4004e3eb8b..c19ea5b3d0 100644 --- a/widgets/table/e-table-column-specification.h +++ b/widgets/table/e-table-column-specification.h @@ -14,7 +14,7 @@ typedef struct { GtkObject base; int model_col; - char *title_; + char *title; char *pixbuf; double expansion; diff --git a/widgets/table/e-table-config.c b/widgets/table/e-table-config.c index bcefb1b53c..af31e1e788 100644 --- a/widgets/table/e-table-config.c +++ b/widgets/table/e-table-config.c @@ -27,20 +27,12 @@ config_destroy (GtkObject *object) { ETableConfig *config = E_TABLE_CONFIG (object); - if (config->state) { - if (config->sorting_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT (config->state->sort_info), - config->sorting_changed_id); - if (config->grouping_changed_id) - gtk_signal_disconnect ( - GTK_OBJECT(config->state->sort_info), - config->grouping_changed_id); - gtk_object_unref (GTK_OBJECT (config->state)); - } + gtk_object_destroy (GTK_OBJECT (config->state)); + gtk_object_destroy (GTK_OBJECT (config->spec)); + gtk_object_unref (GTK_OBJECT (config->state)); gtk_object_unref (GTK_OBJECT (config->spec)); - + GTK_OBJECT_CLASS (config_parent_class)->destroy (object); } @@ -55,79 +47,38 @@ config_class_init (GtkObjectClass *klass) static void config_clear_sort (GtkWidget *widget, ETableConfig *config) { - config->sort_dialog = NULL; gtk_object_unref (GTK_OBJECT(config)); } static void config_clear_group (GtkWidget *widget, ETableConfig *config) { - config->group_dialog = NULL; gtk_object_unref (GTK_OBJECT (config)); } static void config_sort_config_show (GtkWidget *widget, ETableConfig *config) { - if (config->sort_dialog) - gdk_window_raise (GTK_WIDGET (config->sort_dialog)->window); - else { - GtkWidget *etcf; - config->sort_dialog = gnome_dialog_new ( - _("Sort"), - GNOME_STOCK_BUTTON_OK, - NULL); - etcf = GTK_WIDGET (e_table_config_field_new - (config->spec, - config->state->sort_info, - FALSE)); - gtk_box_pack_start ( - GTK_BOX (GNOME_DIALOG (config->sort_dialog)->vbox), - etcf, FALSE, FALSE, 0); - gnome_dialog_set_parent ( - GNOME_DIALOG (config->sort_dialog), - GTK_WINDOW(config->dialog_toplevel)); - - gtk_signal_connect ( - GTK_OBJECT (config->sort_dialog), "destroy", - GTK_SIGNAL_FUNC (config_clear_sort), config); - gtk_object_ref (GTK_OBJECT (config)); - - gtk_signal_connect ( - GTK_OBJECT (config->sort_dialog), "clicked", - GTK_SIGNAL_FUNC(gnome_dialog_close), config); - - gtk_widget_show (GTK_WIDGET (etcf)); - gtk_widget_show (GTK_WIDGET (config->sort_dialog)); + GnomeDialog *dialog = GNOME_DIALOG (config->dialog_sort); + int button, count, i; + + /* + * Make the dialog reflect the current state + */ + count = e_table_sort_info_sorting_get_count (config->state->sort_info); + + for (i = 0; i < 4; i++){ + gboolean sensitive = (i <= count); + + gtk_widget_set_sensitive (config->frames [i], sensitive); } + + button = gnome_dialog_run (dialog); } static void config_group_config_show (GtkWidget *widget, ETableConfig *config) { - if (config->group_dialog) - gdk_window_raise(GTK_WIDGET(config->group_dialog)->window); - else { - GtkWidget *etcf; - config->group_dialog = gnome_dialog_new(_("Group"), - GNOME_STOCK_BUTTON_OK, - NULL); - etcf = GTK_WIDGET(e_table_config_field_new(config->spec, - config->state->sort_info, - TRUE)); - gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(config->group_dialog)->vbox), etcf, FALSE, FALSE, 0); - gnome_dialog_set_parent(GNOME_DIALOG(config->group_dialog), - GTK_WINDOW(config->dialog_toplevel)); - - gtk_signal_connect(GTK_OBJECT(config->group_dialog), "destroy", - GTK_SIGNAL_FUNC(config_clear_group), config); - gtk_signal_connect(GTK_OBJECT(config->group_dialog), "clicked", - GTK_SIGNAL_FUNC(gnome_dialog_close), config); - gtk_object_ref(GTK_OBJECT(config)); - - gtk_widget_show(GTK_WIDGET(etcf)); - gtk_widget_show(GTK_WIDGET(config->group_dialog)); - } } static void @@ -148,7 +99,7 @@ config_sort_info_update (ETableConfig *config) if (col.column != (*column)->model_col) continue; - g_string_append (res, (*column)->title_); + g_string_append (res, _((*column)->title)); g_string_append_c (res, ' '); g_string_append ( res, @@ -185,7 +136,7 @@ config_group_info_update (ETableConfig *config) if (col.column != (*column)->model_col) continue; - g_string_append (res, (*column)->title_); + g_string_append (res, _((*column)->title)); g_string_append_c (res, ' '); g_string_append ( res, @@ -217,7 +168,7 @@ config_fields_info_update (ETableConfig *config) if (config->state->columns [i] != (*column)->model_col) continue; - g_string_append (res, (*column)->title_); + g_string_append (res, _((*column)->title)); if (column [1]) g_string_append (res, ", "); items++; @@ -243,11 +194,69 @@ dialog_destroyed (GtkObject *dialog, ETableConfig *config) gtk_object_destroy (GTK_OBJECT (config)); } +static void +connect_button (ETableConfig *config, GladeXML *gui, const char *widget_name, void *cback) +{ + GtkWidget *button = glade_xml_get_widget (gui, widget_name); + + gtk_signal_connect( + GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (cback), config); +} + +/* + * Invoked by the Glade auto-connect code + */ +GtkWidget *e_table_proxy_gtk_combo_text_new (void); +GtkWidget * +e_table_proxy_gtk_combo_text_new (void) +{ + return gtk_combo_text_new (TRUE); +} + +static GtkWidget * +configure_dialog (GladeXML *gui, const char *widget_name, ETableConfig *config) +{ + GtkWidget *w; + + w = glade_xml_get_widget (gui, widget_name); + + return w; +} + +static void +configure_sort_dialog (ETableConfig *config, GladeXML *gui) +{ + ETableColumnSpecification **column; + int i; + + for (i = 0; i < 4; i++){ + char buffer [30]; + + snprintf (buffer, sizeof (buffer), "sort-combo-%d", i + 1); + config->sort_combos [i] = GTK_COMBO_TEXT ( + glade_xml_get_widget (gui, buffer)); + gtk_combo_text_add_item (config->sort_combos [i], "", ""); + + snprintf (buffer, sizeof (buffer), "frame-sort-%d", i + 1); + config->frames [i] = + glade_xml_get_widget (gui, buffer); + } + + for (column = config->spec->columns; *column; column++){ + char *label = (*column)->title; + + for (i = 0; i < 4; i++){ + gtk_combo_text_add_item ( + config->sort_combos [i], + _(label), label); + } + } +} + static void setup_gui (ETableConfig *config) { - GtkWidget *sort_button; - GtkWidget *group_button; GladeXML *gui = glade_xml_new ( ETABLE_GLADEDIR "/e-table-config.glade", NULL); @@ -263,12 +272,9 @@ setup_gui (ETableConfig *config) GTK_OBJECT (config->dialog_toplevel), "apply", GTK_SIGNAL_FUNC (apply_changes), config); - config->dialog_show_fields = glade_xml_get_widget ( - gui, "dialog-show-fields"); - config->dialog_group_by = glade_xml_get_widget ( - gui, "dialog-group-by"); - config->dialog_sort = glade_xml_get_widget ( - gui, "dialog-sort"); + config->dialog_show_fields = configure_dialog (gui, "dialog-show-fields", config); + config->dialog_group_by = configure_dialog (gui, "dialog-group-by", config); + config->dialog_sort = configure_dialog (gui, "dialog-sort", config); config->sort_label = glade_xml_get_widget ( gui, "label-sort"); @@ -277,16 +283,11 @@ setup_gui (ETableConfig *config) config->fields_label = glade_xml_get_widget ( gui, "label-fields"); - sort_button = glade_xml_get_widget (gui, "button-sort"); - gtk_signal_connect( - GTK_OBJECT(sort_button), "clicked", - GTK_SIGNAL_FUNC (config_sort_config_show), config); - - group_button = glade_xml_get_widget (gui, "button-group"); - gtk_signal_connect( - GTK_OBJECT(group_button), "clicked", - GTK_SIGNAL_FUNC (config_group_config_show), config); + connect_button (config, gui, "button-sort", config_sort_config_show); + connect_button (config, gui, "button-group", config_group_config_show); + configure_sort_dialog (config, gui); + gtk_signal_connect ( GTK_OBJECT (config->dialog_toplevel), "destroy", GTK_SIGNAL_FUNC (dialog_destroyed), config); @@ -298,10 +299,6 @@ static void config_init (ETableConfig *config) { glade_gnome_init (); - setup_gui (config); - - config->sorting_changed_id = 0; - config->grouping_changed_id = 0; } ETableConfig * @@ -310,27 +307,21 @@ e_table_config_construct (ETableConfig *config, ETableSpecification *spec, ETableState *state) { - config->spec = spec; - config->state = state; + g_return_val_if_fail (config != NULL, NULL); + g_return_val_if_fail (header != NULL, NULL); + g_return_val_if_fail (spec != NULL, NULL); + g_return_val_if_fail (state != NULL, NULL); + + config->source_spec = spec; + config->source_state = state; - if (config->spec) - gtk_object_ref (GTK_OBJECT(config->spec)); - if (config->state) - gtk_object_ref (GTK_OBJECT(config->state)); + gtk_object_ref (GTK_OBJECT (config->source_spec)); + gtk_object_ref (GTK_OBJECT (config->source_state)); - /* - * FIXME: - * - * Are we going to allow async changes to the ETable? If so, - * we are in for some more work than required - * - */ - config->sorting_changed_id = gtk_signal_connect ( - GTK_OBJECT(config->state->sort_info), "sort_info_changed", - GTK_SIGNAL_FUNC(config_sort_info_update), config); - config->grouping_changed_id = gtk_signal_connect ( - GTK_OBJECT(config->state->sort_info), "group_info_changed", - GTK_SIGNAL_FUNC (config_group_info_update), config); + config->spec = e_table_specification_duplicate (spec); + config->state = e_table_state_duplicate (state); + + setup_gui (config); config_sort_info_update (config); config_group_info_update (config); diff --git a/widgets/table/e-table-config.glade b/widgets/table/e-table-config.glade index b210a4d2da..a6920ee81c 100644 --- a/widgets/table/e-table-config.glade +++ b/widgets/table/e-table-config.glade @@ -10,9 +10,17 @@ C True True + False False False False + True + interface.c + interface.h + callbacks.c + callbacks.h + support.c + support.h True e-table-config.glade.h @@ -43,40 +51,6 @@ True - - GtkHButtonBox - GnomeDialog:action_area - dialog-action_area3 - GTK_BUTTONBOX_END - 8 - 85 - 27 - 7 - 0 - - 0 - False - True - GTK_PACK_END - - - - GtkButton - button20 - True - True - GNOME_STOCK_BUTTON_OK - - - - GtkButton - button22 - True - True - GNOME_STOCK_BUTTON_CANCEL - - - GtkVBox vbox2 @@ -214,7 +188,6 @@ table-1 True - GTK_RELIEF_NORMAL @@ -263,7 +236,6 @@ table-2 True - GTK_RELIEF_NORMAL @@ -284,7 +256,6 @@ button-up True - GTK_RELIEF_NORMAL 0 False @@ -297,7 +268,6 @@ button-down True - GTK_RELIEF_NORMAL 0 False @@ -332,7 +302,6 @@ button-add True - GTK_RELIEF_NORMAL 0 False @@ -345,7 +314,6 @@ button-remove True - GTK_RELIEF_NORMAL 0 False @@ -359,39 +327,11 @@ - - - - - GnomeDialog - dialog-group-by - False - Group - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - True - False - False - False - - - GtkVBox - GnomeDialog:vbox - dialog-vbox4 - False - 8 - - 4 - True - True - GtkHButtonBox GnomeDialog:action_area - dialog-action_area4 + dialog-action_area3 GTK_BUTTONBOX_END 8 85 @@ -407,15 +347,7 @@ GtkButton - button39 - True - True - - - - - GtkButton - button41 + button20 True True GNOME_STOCK_BUTTON_OK @@ -423,12 +355,40 @@ GtkButton - button42 + button22 True True GNOME_STOCK_BUTTON_CANCEL + + + + + GnomeDialog + dialog-group-by + False + Group + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + True + False + False + False + + + GtkVBox + GnomeDialog:vbox + dialog-vbox4 + False + 8 + + 4 + True + True + GtkVBox @@ -1153,39 +1113,11 @@ - - - - - GnomeDialog - dialog-sort - False - Sort - GTK_WINDOW_TOPLEVEL - GTK_WIN_POS_NONE - False - False - True - False - False - False - - - GtkVBox - GnomeDialog:vbox - vbox15 - False - 8 - - 4 - True - True - GtkHButtonBox GnomeDialog:action_area - hbuttonbox1 + dialog-action_area4 GTK_BUTTONBOX_END 8 85 @@ -1201,7 +1133,7 @@ GtkButton - button43 + button39 True True @@ -1209,7 +1141,7 @@ GtkButton - button44 + button41 True True GNOME_STOCK_BUTTON_OK @@ -1217,12 +1149,40 @@ GtkButton - button45 + button42 True True GNOME_STOCK_BUTTON_CANCEL + + + + + GnomeDialog + dialog-sort + False + Sort + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + True + False + False + True + + + GtkVBox + GnomeDialog:vbox + vbox15 + False + 8 + + 4 + True + True + GtkTable @@ -1269,7 +1229,7 @@ GtkAlignment alignment1 0.5 - 7.45058e-09 + 0.5 1 0 @@ -1279,25 +1239,12 @@ - GtkCombo - combo-sort-4 - False - True - False - True - False - - - - GtkEntry - GtkCombo:entry - entry-sort-4 - True - True - True - 0 - - + Custom + sort-combo-4 + e_table_proxy_gtk_combo_text_new + 0 + 0 + Tue, 16 Jan 2001 08:33:52 GMT @@ -1376,7 +1323,7 @@ GtkAlignment alignment2 0.5 - 7.45058e-09 + 0.5 1 0 @@ -1386,25 +1333,12 @@ - GtkCombo - combo-sort-3 - False - True - False - True - False - - - - GtkEntry - GtkCombo:entry - entry-sort-3 - True - True - True - 0 - - + Custom + sort-combo-3 + e_table_proxy_gtk_combo_text_new + 0 + 0 + Tue, 16 Jan 2001 05:22:22 GMT @@ -1483,7 +1417,7 @@ GtkAlignment alignment3 0.5 - 0 + 0.5 1 0 @@ -1493,25 +1427,12 @@ - GtkCombo - combo-sort-2 - False - True - False - True - False - - - - GtkEntry - GtkCombo:entry - entry-sort-2 - True - True - True - 0 - - + Custom + sort-combo-2 + e_table_proxy_gtk_combo_text_new + 0 + 0 + Tue, 16 Jan 2001 05:22:15 GMT @@ -1590,7 +1511,7 @@ GtkAlignment alignment4 0.5 - 0 + 0.5 1 0 @@ -1600,25 +1521,12 @@ - GtkCombo - combo-sort-1 - False - True - False - True - False - - - - GtkEntry - GtkCombo:entry - entry-sort-1 - True - True - True - 0 - File By - + Custom + sort-combo-1 + e_table_proxy_gtk_combo_text_new + 0 + 0 + Tue, 16 Jan 2001 05:22:00 GMT @@ -1666,17 +1574,54 @@ + + + GtkHButtonBox + GnomeDialog:action_area + hbuttonbox1 + GTK_BUTTONBOX_END + 8 + 85 + 27 + 7 + 0 + + 0 + False + True + GTK_PACK_END + + + + GtkButton + button43 + True + True + + + + + GtkButton + button44 + True + True + GNOME_STOCK_BUTTON_OK + + + + GtkButton + button45 + True + True + GNOME_STOCK_BUTTON_CANCEL + + GnomePropertyBox e-table-config - GTK_WIN_POS_NONE - False - False - False - False GtkNotebook @@ -1802,7 +1747,6 @@ Tue, 03 Oct 2000 22:11:12 GMT - GTK_RELIEF_NORMAL 0 1 @@ -1830,7 +1774,6 @@ Tue, 03 Oct 2000 22:10:58 GMT - GTK_RELIEF_NORMAL 0 1 @@ -1858,7 +1801,6 @@ Tue, 03 Oct 2000 22:10:50 GMT - GTK_RELIEF_NORMAL 0 1 diff --git a/widgets/table/e-table-config.glade.h b/widgets/table/e-table-config.glade.h index bed862eaac..1bc023a51b 100644 --- a/widgets/table/e-table-config.glade.h +++ b/widgets/table/e-table-config.glade.h @@ -14,7 +14,6 @@ gchar *s = N_("Move _Down"); gchar *s = N_("_Add ->"); gchar *s = N_("<- _Remove"); gchar *s = N_("Group"); -gchar *s = N_("_Clear All"); gchar *s = N_("Group Items By"); gchar *s = N_("Show field in View"); gchar *s = N_("Ascending"); @@ -31,8 +30,8 @@ gchar *s = N_("Then By"); gchar *s = N_("Show field in View"); gchar *s = N_("Ascending"); gchar *s = N_("Descending"); -gchar *s = N_("Sort"); gchar *s = N_("_Clear All"); +gchar *s = N_("Sort"); gchar *s = N_("Then By"); gchar *s = N_("Ascending"); gchar *s = N_("Descending"); @@ -43,9 +42,9 @@ gchar *s = N_("Then By"); gchar *s = N_("Ascending"); gchar *s = N_("Descending"); gchar *s = N_("Sort Items By"); -gchar *s = N_("File By"); gchar *s = N_("Ascending"); gchar *s = N_("Descending"); +gchar *s = N_("_Clear All"); gchar *s = N_("Description"); gchar *s = N_("_Fields..."); gchar *s = N_("_Sort..."); diff --git a/widgets/table/e-table-config.h b/widgets/table/e-table-config.h index 4b444636d7..fcf6eff9cc 100644 --- a/widgets/table/e-table-config.h +++ b/widgets/table/e-table-config.h @@ -5,6 +5,7 @@ #include #include #include +#include #define E_TABLE_CONFIG_TYPE (e_table_config_get_type ()) #define E_TABLE_CONFIG(o) (GTK_CHECK_CAST ((o), E_TABLE_CONFIG_TYPE, ETableConfig)) @@ -26,18 +27,15 @@ typedef struct { /* * The state we manipulate */ - ETableSpecification *spec; - ETableState *state; + ETableSpecification *source_spec, *spec; + ETableState *source_state, *state; GtkWidget *sort_label; GtkWidget *group_label; GtkWidget *fields_label; - GtkWidget *sort_dialog; - GtkWidget *group_dialog; - - int sorting_changed_id; - int grouping_changed_id; + GtkComboText *sort_combos [4]; + GtkWidget *frames [4]; } ETableConfig; typedef struct { diff --git a/widgets/table/e-table-specification.c b/widgets/table/e-table-specification.c index fa80d6a40c..b9a3c4ee98 100644 --- a/widgets/table/e-table-specification.c +++ b/widgets/table/e-table-specification.c @@ -228,6 +228,10 @@ e_table_specification_save_to_file (ETableSpecification *specification, { xmlDoc *doc; + g_return_val_if_fail (specification != NULL, -1); + g_return_val_if_fail (filename != NULL, -1); + g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), -1); + doc = xmlNewDoc ("1.0"); xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); return xmlSaveFile (filename, doc); @@ -251,6 +255,9 @@ e_table_specification_save_to_string (ETableSpecification *specification) int length; xmlDoc *doc; + g_return_val_if_fail (specification != NULL, NULL); + g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); + doc = xmlNewDoc ("1.0"); xmlDocSetRootElement (doc, e_table_specification_save_to_node (specification, doc)); xmlDocDumpMemory (doc, &string, &length); @@ -275,9 +282,14 @@ xmlNode * e_table_specification_save_to_node (ETableSpecification *specification, xmlDoc *doc) { - xmlNode *node = xmlDocGetRootElement (doc); + xmlNode *node; char *s; - + + g_return_val_if_fail (doc != NULL, NULL); + g_return_val_if_fail (specification != NULL, NULL); + g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (specification), NULL); + + node = xmlNewNode (NULL, "ETableSpecification"); e_xml_set_bool_prop_by_name (node, "no-headers", specification->no_headers); e_xml_set_bool_prop_by_name (node, "click-to-add", specification->click_to_add); e_xml_set_bool_prop_by_name (node, "draw-grid", specification->draw_grid); @@ -328,11 +340,17 @@ e_table_specification_save_to_node (ETableSpecification *specification, ETableSpecification * e_table_specification_duplicate (ETableSpecification *spec) { - ETableSpecification *new_spec = e_table_specification_new (); - char *spec_str = e_table_specification_save_to_string (spec); + ETableSpecification *new_spec; + char *spec_str; + g_return_val_if_fail (spec != NULL, NULL); + g_return_val_if_fail (E_IS_TABLE_SPECIFICATION (spec), NULL); + + new_spec = e_table_specification_new (); + spec_str = e_table_specification_save_to_string (spec); printf ("This is the spec: \n%s\n", spec_str); e_table_specification_load_from_string (new_spec, spec_str); + g_free (spec_str); return new_spec; } diff --git a/widgets/table/e-table-state.c b/widgets/table/e-table-state.c index c9049b7a18..c978487368 100644 --- a/widgets/table/e-table-state.c +++ b/widgets/table/e-table-state.c @@ -2,8 +2,9 @@ /* * E-table-state.c: Savable state of a table. * - * Author: + * Authors: * Chris Lahey + * Miguel de Icaza (miguel@ximian.com) * * (C) 2000 Ximian, Inc. */ @@ -87,37 +88,44 @@ e_table_state_load_from_string (ETableState *state, } } -typedef struct -{ +typedef struct { int column; double expansion; } int_and_double; void -e_table_state_load_from_node (ETableState *state, - const xmlNode *node) +e_table_state_load_from_node (ETableState *state, + const xmlNode *node) { xmlNode *children; GList *list = NULL, *iterator; gdouble state_version; int i; - state_version = e_xml_get_double_prop_by_name_with_default(node, "state-version", STATE_VERSION); + state_version = e_xml_get_double_prop_by_name_with_default ( + node, "state-version", STATE_VERSION); if (state->sort_info) - gtk_object_unref(GTK_OBJECT(state->sort_info)); + gtk_object_unref (GTK_OBJECT(state->sort_info)); + state->sort_info = NULL; - for (children = node->xmlChildrenNode; children; children = children->next) { - if (!strcmp(children->name, "column")) { + children = node->xmlChildrenNode; + for (; children; children = children->next) { + if (!strcmp (children->name, "column")) { int_and_double *column_info = g_new(int_and_double, 1); - column_info->column = e_xml_get_integer_prop_by_name(children, "source"); - column_info->expansion = e_xml_get_double_prop_by_name_with_default(children, "expansion", -2); + column_info->column = e_xml_get_integer_prop_by_name( + children, "source"); + column_info->expansion = + e_xml_get_double_prop_by_name_with_default( + children, "expansion", -2); - list = g_list_append(list, column_info); - } else if (state->sort_info == NULL && !strcmp(children->name, "grouping")) { + list = g_list_append (list, column_info); + } else if (state->sort_info == NULL && + !strcmp (children->name, "grouping")) { state->sort_info = e_table_sort_info_new(); - e_table_sort_info_load_from_node(state->sort_info, children, state_version); + e_table_sort_info_load_from_node( + state->sort_info, children, state_version); } } g_free(state->columns); @@ -125,11 +133,14 @@ e_table_state_load_from_node (ETableState *state, state->col_count = g_list_length(list); state->columns = g_new(int, state->col_count); state->expansions = g_new(double, state->col_count); - for (iterator = list, i = 0; iterator; iterator = g_list_next(iterator), i++) { + + for (iterator = list, i = 0; iterator; i++) { int_and_double *column_info = iterator->data; - state->columns[i] = column_info->column; - state->expansions[i] = column_info->expansion; - g_free(column_info); + + state->columns [i] = column_info->column; + state->expansions [i] = column_info->expansion; + g_free (column_info); + iterator = g_list_next (iterator); } g_list_free(list); } @@ -196,7 +207,7 @@ e_table_state_save_to_node (ETableState *state, /** * e_table_state_duplicate: - * @state: state to duplicate + * @state: The ETableState to duplicate * * This creates a copy of the %ETableState @state * @@ -205,11 +216,17 @@ e_table_state_save_to_node (ETableState *state, ETableState * e_table_state_duplicate (ETableState *state) { - ETableState *new_state = e_table_state_new (); - char *state_str = e_table_state_save_to_string (state); - - printf ("This is the state: \n%s\n", state_str); - e_table_state_load_from_string (new_state, state_str); + ETableState *new_state; + char *copy; + g_return_val_if_fail (state != NULL, NULL); + g_return_val_if_fail (E_IS_TABLE_STATE (state), NULL); + + new_state = e_table_state_new (); + copy = e_table_state_save_to_string (state); + e_table_state_load_from_string (new_state, copy); + g_free (copy); + return new_state; } + diff --git a/widgets/table/e-table-state.h b/widgets/table/e-table-state.h index 32956bd5f8..906bbedb3f 100644 --- a/widgets/table/e-table-state.h +++ b/widgets/table/e-table-state.h @@ -40,6 +40,6 @@ void e_table_state_save_to_file (ETableState *state, char *e_table_state_save_to_string (ETableState *state); xmlNode *e_table_state_save_to_node (ETableState *state, xmlNode *parent); -ETableState *e_table_state_duplicate (ETableState *spec); +ETableState *e_table_state_duplicate (ETableState *state); #endif /* _E_TABLE_STATE_H_ */ diff --git a/widgets/table/e-table.c b/widgets/table/e-table.c index 3a471ee7c8..5e597bdd0c 100644 --- a/widgets/table/e-table.c +++ b/widgets/table/e-table.c @@ -647,7 +647,9 @@ e_table_fill_table (ETable *e_table, ETableModel *model) } static ETableCol * -et_col_spec_to_col (ETable *e_table, ETableColumnSpecification *col_spec, ETableExtras *ete) +et_col_spec_to_col (ETable *e_table, + ETableColumnSpecification *col_spec, + ETableExtras *ete) { ETableCol *col = NULL; ECell *cell; @@ -660,24 +662,30 @@ et_col_spec_to_col (ETable *e_table, ETableColumnSpecification *col_spec, ETable if (col_spec->pixbuf && *col_spec->pixbuf) { GdkPixbuf *pixbuf; - pixbuf = e_table_extras_get_pixbuf(ete, col_spec->pixbuf); + pixbuf = e_table_extras_get_pixbuf( + ete, col_spec->pixbuf); if (pixbuf) { - col = e_table_col_new_with_pixbuf (col_spec->model_col, col_spec->title_, pixbuf, - col_spec->expansion, col_spec->minimum_width, - cell, compare, col_spec->resizable); + col = e_table_col_new_with_pixbuf ( + col_spec->model_col, _(col_spec->title), + pixbuf, col_spec->expansion, + col_spec->minimum_width, + cell, compare, col_spec->resizable); } } - if (col == NULL && col_spec->title_ && *col_spec->title_) { - col = e_table_col_new (col_spec->model_col, col_spec->title_, - col_spec->expansion, col_spec->minimum_width, - cell, compare, col_spec->resizable); + if (col == NULL && col_spec->title && *col_spec->title) { + col = e_table_col_new ( + col_spec->model_col, _(col_spec->title), + col_spec->expansion, col_spec->minimum_width, + cell, compare, col_spec->resizable); } } return col; } static ETableHeader * -et_spec_to_full_header (ETable *e_table, ETableSpecification *spec, ETableExtras *ete) +et_spec_to_full_header (ETable *e_table, + ETableSpecification *spec, + ETableExtras *ete) { ETableHeader *nh; int column; @@ -689,7 +697,8 @@ et_spec_to_full_header (ETable *e_table, ETableSpecification *spec, ETableExtras nh = e_table_header_new (); for (column = 0; spec->columns[column]; column++) { - ETableCol *col = et_col_spec_to_col(e_table, spec->columns[column], ete); + ETableCol *col = et_col_spec_to_col ( + e_table, spec->columns[column], ete); if (col) e_table_header_add_column (nh, col, -1); -- cgit v1.2.3