27 #include <glib/gi18n.h> 31 #include "assistant-xml-encoding.h" 32 #include "dialog-utils.h" 34 #include "gnc-component-manager.h" 53 GHashTable** ambiguous,
70 GtkWidget *default_encoding_combo;
71 GtkWidget *default_encoding_hbox;
72 GtkWidget *summary_label;
73 GtkWidget *impossible_label;
74 GtkWidget *string_box;
75 GtkWidget *string_box_container;
76 GtkWidget *encodings_dialog;
77 GtkWidget *custom_enc_entry;
78 GtkTreeView *available_encs_view;
79 GtkTreeView *selected_encs_view;
82 GQuark default_encoding;
90 GHashTable *ambiguous_ht;
93 GList *ambiguous_list;
120 gchar *byte_sequence;
146 void gxi_prepare_cb (GtkAssistant *assistant, GtkWidget *page,
GncXmlImportData *data);
150 void gxi_conversion_prepare (GtkAssistant *assistant, gpointer data );
151 void gxi_conversion_next (GtkAssistant *assistant, gpointer data);
160 static void gxi_update_progress_bar (
const gchar *message,
double percentage);
166 static void gxi_default_enc_combo_changed_cb (GtkComboBox *combo,
GncXmlImportData *data);
167 static void gxi_string_combo_changed_cb (GtkComboBox *combo,
GncXmlImportData *data);
168 void gxi_edit_encodings_clicked_cb (GtkButton *button,
GncXmlImportData *data);
169 void gxi_available_enc_activated_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column,
GncXmlImportData *data);
172 void gxi_add_custom_enc_clicked_cb (GtkButton *button,
GncXmlImportData *data);
173 void gxi_selected_enc_activated_cb (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *column,
GncXmlImportData *data);
177 static const gchar *encodings_doc_string = N_(
178 "\nThe file you are trying to load is from an older version of " 179 "GnuCash. The file format in the older versions was missing the " 180 "detailed specification of the character encoding being used. This " 181 "means the text in your data file could be read in multiple ambiguous " 182 "ways. This ambiguity cannot be resolved automatically, but the new " 183 "GnuCash 2.0.0 file format will include all necessary specifications so " 184 "that you do not have to go through this step again." 186 "GnuCash will try to guess the correct character encoding for your data " 187 "file. On the next page GnuCash will show the resulting texts when " 188 "using this guess. You have to check whether the words look as " 189 "expected. Either everything looks fine and you can simply press " 190 "\"Next\". Or the words contain unexpected characters, in which " 191 "case you should select different character encodings to see " 192 "different results. You may have to edit the list of character " 193 "encodings by clicking on the respective button." 195 "Press \"Next\" now to select the correct character encoding for " 196 "your data file.\n");
198 static const gchar *encodings_doc_page_title = N_(
"Ambiguous character encoding");
200 static const gchar *finish_convert_string = N_(
201 "The file has been loaded successfully. If you click \"Apply\" it will be saved " 202 "and reloaded into the main application. That way you will have a working " 203 "file as backup in the same directory.\n\n" 204 "You can also go back and verify your selections by clicking on \"Back\".");
207 static QofLogModule log_module = GNC_MOD_ASSISTANT;
210 static GtkWidget *progress_window = NULL;
211 static GtkProgressBar *progress_bar = NULL;
224 { N_(
"Unicode"), NULL, 2 },
225 {
"UTF-8",
"UTF-8", 0 },
226 { N_(
"European"), NULL, 2 },
227 { N_(
"ISO-8859-1 (West European)"),
"ISO-8859-1", 0 },
228 { N_(
"ISO-8859-2 (East European)"),
"ISO-8859-2", 1 },
229 { N_(
"ISO-8859-3 (South European)"),
"ISO-8859-3", 1 },
230 { N_(
"ISO-8859-4 (North European)"),
"ISO-8859-4", 1 },
231 { N_(
"ISO-8859-5 (Cyrillic)"),
"ISO-8859-5", 1 },
232 { N_(
"ISO-8859-6 (Arabic)"),
"ISO-8859-6", 1 },
233 { N_(
"ISO-8859-7 (Greek)"),
"ISO-8859-7", 1 },
234 { N_(
"ISO-8859-8 (Hebrew)"),
"ISO-8859-8", 1 },
235 { N_(
"ISO-8859-9 (Turkish)"),
"ISO-8859-9", 1 },
236 { N_(
"ISO-8859-10 (Nordic)"),
"ISO-8859-10", 1 },
237 { N_(
"ISO-8859-11 (Thai)"),
"ISO-8859-11", 1 },
238 { N_(
"ISO-8859-13 (Baltic)"),
"ISO-8859-13", 1 },
239 { N_(
"ISO-8859-14 (Celtic)"),
"ISO-8859-14", 1 },
240 { N_(
"ISO-8859-15 (West European, Euro sign)"),
"ISO-8859-15", 1 },
241 { N_(
"ISO-8859-16 (South-East European)"),
"ISO-8859-16", 1 },
242 { N_(
"Cyrillic"), NULL, 2 },
243 { N_(
"KOI8-R (Russian)"),
"KOI8-R", 0 },
244 { N_(
"KOI8-U (Ukrainian)"),
"KOI8-U", 1 },
246 static guint n_system_encodings = G_N_ELEMENTS (system_encodings);
249 void gxi_prepare_cb (GtkAssistant *assistant, GtkWidget *page,
252 switch (gtk_assistant_get_current_page(assistant))
256 gxi_conversion_prepare (assistant, data);
260 gxi_conversion_next (assistant, data);
274 GtkAssistant *assistant = GTK_ASSISTANT(data->assistant);
275 gint num = gtk_assistant_get_current_page (assistant);
276 GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
278 if (data->n_unassigned || data->n_impossible)
279 gtk_assistant_set_page_complete (assistant, page, FALSE);
281 gtk_assistant_set_page_complete (assistant, page, TRUE);
287 gnc_suspend_gui_refresh ();
288 data->canceled = TRUE;
289 gnc_resume_gui_refresh ();
296 gnc_xml_convert_single_file (
const gchar *filename)
305 data->canceled = FALSE;
308 gxi_check_file (data);
309 if (data->n_impossible == -1)
312 if (!g_hash_table_size (data->ambiguous_ht))
315 success = gxi_parse_file (data) &&
316 gxi_save_file (data);
318 gxi_data_destroy (data);
323 builder = gtk_builder_new();
324 gnc_builder_add_from_file (builder ,
"assistant-xml-encoding.glade",
"assistant_xml_encoding");
325 data->assistant = GTK_WIDGET(gtk_builder_get_object (builder,
"assistant_xml_encoding"));
328 gtk_assistant_set_page_complete (GTK_ASSISTANT (data->assistant),
329 GTK_WIDGET(gtk_builder_get_object(builder,
"start_page")),
331 gtk_assistant_set_page_complete (GTK_ASSISTANT (data->assistant),
332 GTK_WIDGET(gtk_builder_get_object(builder,
"conversion_page")),
334 gtk_assistant_set_page_complete (GTK_ASSISTANT (data->assistant),
335 GTK_WIDGET(gtk_builder_get_object(builder,
"end_page")),
339 gtk_assistant_set_page_title (GTK_ASSISTANT(data->assistant),
340 gtk_assistant_get_nth_page (GTK_ASSISTANT(data->assistant), 0),
341 gettext(encodings_doc_page_title));
343 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"start_page"));
344 gtk_label_set_text (GTK_LABEL(widget), gettext (encodings_doc_string));
347 data->default_encoding_hbox = GTK_WIDGET(gtk_builder_get_object (builder,
"default_enc_box"));
348 data->string_box_container = GTK_WIDGET(gtk_builder_get_object (builder,
"string_box_container"));
349 data->impossible_label = GTK_WIDGET(gtk_builder_get_object (builder,
"impossible_label"));
352 widget = GTK_WIDGET(gtk_builder_get_object(builder,
"end_page"));
353 gtk_label_set_text (GTK_LABEL(widget), gettext (finish_convert_string));
355 gtk_builder_connect_signals(builder, data);
357 gtk_widget_show_all (data->assistant);
359 gxi_update_default_enc_combo (data);
360 gxi_update_string_box (data);
362 g_object_unref(G_OBJECT(builder));
370 success = gxi_save_file (data);
374 gxi_data_destroy (data);
388 g_free (data->filename);
389 data->filename = NULL;
392 gxi_session_destroy (data);
393 gxi_ambiguous_info_destroy (data);
397 g_hash_table_destroy (data->choices);
398 data->choices = NULL;
401 if (data->string_box)
403 gtk_widget_destroy (data->string_box);
404 data->string_box = NULL;
409 gtk_widget_destroy (data->assistant);
410 data->assistant = NULL;
419 g_free(conv->utf8_string);
431 new_type->encoding = conv->encoding;
432 new_type->utf8_string = g_strdup (conv->utf8_string);
438 conv_enc_cmp (
const conv_type *conv,
const GQuark *enc)
440 return conv->encoding - *enc;
446 GList *found = g_list_find_custom (amb->conv_list, &enc,
447 (GCompareFunc) conv_enc_cmp);
451 return ((
conv_type*) found->data)->utf8_string;
463 const gchar *string_a = get_decoded_string (a, data->default_encoding);
464 const gchar *string_b = get_decoded_string (b, data->default_encoding);
471 return strcmp (string_a, string_b);
489 conv_type *conv_a = g_hash_table_lookup (data->choices, a->byte_sequence);
490 conv_type *conv_b = g_hash_table_lookup (data->choices, b->byte_sequence);
491 if (conv_a && !conv_b)
return 1;
492 if (conv_b && !conv_a)
return -1;
493 return strcmp (a->byte_sequence, b->byte_sequence);
499 ambiguous_list_insert (gchar *byte_sequence, GList *conv_list,
505 amb->byte_sequence = g_strdup (byte_sequence);
506 amb->conv_list = NULL;
507 for (iter = g_list_last (conv_list); iter; iter = iter->prev)
508 amb->conv_list = g_list_prepend (amb->conv_list, conv_copy (iter->data));
510 data->ambiguous_list = g_list_prepend (data->ambiguous_list, amb);
518 g_free (amb->byte_sequence);
519 g_list_foreach (amb->conv_list, (GFunc) conv_free, NULL);
520 g_list_free (amb->conv_list);
530 g_hash_table_destroy (data->unique);
533 if (data->ambiguous_ht)
535 g_hash_table_destroy (data->ambiguous_ht);
536 data->ambiguous_ht = NULL;
538 if (data->ambiguous_list)
540 g_list_foreach (data->ambiguous_list, (GFunc) ambiguous_free, NULL);
541 g_list_free (data->ambiguous_list);
542 data->ambiguous_list = NULL;
552 qof_session_destroy (data->session);
554 data->session = NULL;
561 data->ambiguous_list = g_list_sort_with_data (
562 data->ambiguous_list, (GCompareDataFunc) ambiguous_cmp, data);
567 subst_insert_amb (gchar *byte_sequence, GList *conv_list,
GncXmlImportData *data)
575 choice = g_hash_table_lookup (data->choices, byte_sequence);
579 g_hash_table_insert (data->subst, g_strdup (byte_sequence),
580 g_strdup (choice->utf8_string));
584 default_conv = g_list_find_custom (conv_list, &data->default_encoding,
585 (GCompareFunc) conv_enc_cmp);
589 default_utf8 = ((
conv_type*) default_conv->data)->utf8_string;
590 g_hash_table_insert (data->subst, g_strdup (byte_sequence),
591 g_strdup (default_utf8));
596 g_hash_table_destroy (data->subst);
603 subst_insert_unique (gchar *byte_sequence,
conv_type *conv,
608 g_hash_table_insert (data->subst, g_strdup (byte_sequence),
609 g_strdup (conv->utf8_string));
613 gxi_update_progress_bar (
const gchar *message,
double percentage)
615 if (!progress_window)
617 progress_window = gtk_window_new (GTK_WINDOW_POPUP);
618 progress_bar = GTK_PROGRESS_BAR (gtk_progress_bar_new ());
619 gtk_container_set_border_width (GTK_CONTAINER (progress_window), 12);
620 gtk_container_add (GTK_CONTAINER (progress_window),
621 GTK_WIDGET (progress_bar));
622 gtk_widget_show (GTK_WIDGET (progress_bar));
627 gtk_progress_bar_set_text (progress_bar, NULL);
628 gtk_progress_bar_set_fraction (progress_bar, 0.0);
629 gtk_widget_hide (progress_window);
633 gtk_progress_bar_set_text (progress_bar, message);
634 if (percentage <= 100)
635 gtk_progress_bar_set_fraction (progress_bar, percentage / 100);
637 gtk_progress_bar_pulse (progress_bar);
638 gtk_widget_show (progress_window);
645 GtkComboBoxText *combo;
649 if (data->default_encoding_combo)
650 gtk_widget_destroy (data->default_encoding_combo);
651 data->default_encoding_combo = gtk_combo_box_text_new();
652 combo = GTK_COMBO_BOX_TEXT (data->default_encoding_combo);
654 for (enc_iter = data->encodings; enc_iter; enc_iter = enc_iter->next)
656 gtk_combo_box_text_append_text (
657 combo, g_quark_to_string (GPOINTER_TO_UINT (enc_iter->data)));
659 gtk_combo_box_set_active (GTK_COMBO_BOX(combo),
660 g_list_index (data->encodings, GUINT_TO_POINTER (data->default_encoding)));
663 g_signal_connect (G_OBJECT (combo),
"changed",
664 G_CALLBACK (gxi_default_enc_combo_changed_cb), data);
665 gtk_container_add (GTK_CONTAINER (data->default_encoding_hbox), GTK_WIDGET (combo));
666 gtk_widget_show (GTK_WIDGET (combo));
672 gchar *
string = NULL;
673 gboolean show = FALSE;
675 if (data->n_unassigned)
677 if (data->n_impossible)
679 string = g_strdup_printf (
680 _(
"There are %d unassigned and %d undecodable words. " 681 "Please add encodings."),
682 data->n_unassigned, data->n_impossible);
687 string = g_strdup_printf (
688 _(
"There are %d unassigned words. " 689 "Please decide on them or add encodings."),
696 if (data->n_impossible)
698 string = g_strdup_printf (
699 _(
"There are %d undecodable words. " 700 "Please add encodings."),
712 gtk_label_set_text (GTK_LABEL (data->summary_label),
string);
714 gtk_widget_show (data->summary_label);
718 gtk_widget_hide (data->summary_label);
730 GList *word_iter, *conv_iter;
731 GtkCellRenderer *renderer;
733 GQuark chosen_encoding;
734 GtkTreeIter *chosen_iter, *default_iter;
738 if (data->string_box)
739 gtk_widget_destroy (data->string_box);
741 data->string_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
742 gtk_box_set_homogeneous (GTK_BOX (data->string_box), FALSE);
744 vbox = GTK_BOX (data->string_box);
746 data->n_unassigned = 0;
749 for (word_iter = data->ambiguous_list; word_iter; word_iter = word_iter->next)
752 store = gtk_list_store_new (WORD_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
753 combo = GTK_COMBO_BOX (gtk_combo_box_new_with_model (
754 GTK_TREE_MODEL (store)));
755 g_object_unref (store);
756 renderer = gtk_cell_renderer_text_new ();
757 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
758 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), renderer,
759 "text", WORD_COL_STRING, NULL);
763 utf8 = get_decoded_string (amb, data->default_encoding);
767 string = g_strdup_printf (
"%s (default)", utf8);
768 gtk_list_store_append (store, &iter);
769 gtk_list_store_set (store, &iter, WORD_COL_STRING,
string,
771 GUINT_TO_POINTER (data->default_encoding), -1);
773 default_iter = gtk_tree_iter_copy (&iter);
777 conv = (
conv_type*) g_hash_table_lookup (data->choices, amb->byte_sequence);
778 chosen_encoding = (conv) ? conv->encoding : 0;
782 for (conv_iter = amb->conv_list; conv_iter; conv_iter = conv_iter->next)
785 string = g_strdup_printf (
"%s (%s)", conv->utf8_string,
786 g_quark_to_string (conv->encoding));
787 gtk_list_store_append (store, &iter);
788 gtk_list_store_set (store, &iter, WORD_COL_STRING,
string,
790 GUINT_TO_POINTER (conv->encoding), -1);
793 if (chosen_encoding && conv->encoding == chosen_encoding)
795 chosen_iter = gtk_tree_iter_copy (&iter);
802 gtk_combo_box_set_active_iter (combo, chosen_iter);
803 gtk_tree_iter_free (chosen_iter);
810 gtk_combo_box_set_active_iter (combo, default_iter);
815 data->n_unassigned++;
820 g_object_set_data (G_OBJECT (combo),
"ambiguous", amb);
821 g_signal_connect (G_OBJECT (combo),
"changed",
822 G_CALLBACK (gxi_string_combo_changed_cb), data);
823 gtk_box_pack_start (vbox, GTK_WIDGET (combo), FALSE, FALSE, 0);
824 gtk_widget_show (GTK_WIDGET (combo));
829 gtk_container_add (GTK_CONTAINER (data->string_box_container), GTK_WIDGET (vbox));
830 gtk_widget_show (GTK_WIDGET (vbox));
833 if (!data->summary_label)
834 data->summary_label = data->impossible_label;
835 gxi_update_summary_label (data);
839 gxi_conversion_prepare (GtkAssistant *assistant, gpointer user_data )
843 gxi_update_string_box (data);
844 gxi_update_conversion_forward (data);
848 gxi_default_enc_combo_changed_cb (GtkComboBox *combo,
GncXmlImportData *data)
854 if (!gtk_combo_box_get_active_iter (combo, &iter))
857 gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
859 curr_enc = g_quark_from_string (enc_string);
862 if (data->default_encoding == curr_enc)
864 if (!g_list_find (data->encodings, GUINT_TO_POINTER (curr_enc)))
867 PERR(
"invalid encoding selection");
871 data->default_encoding = curr_enc;
872 gxi_sort_ambiguous_list (data);
873 gxi_update_string_box (data);
874 gxi_update_conversion_forward (data);
881 GList *found, *default_conv;
886 GQuark prev_enc, curr_enc;
888 amb = (
ambiguous_type*) g_object_get_data (G_OBJECT (combo),
"ambiguous");
889 prev_conv = (
conv_type*) g_hash_table_lookup (data->choices,
892 prev_enc = prev_conv->encoding;
894 default_conv = g_list_find_custom (amb->conv_list, &data->default_encoding,
895 (GCompareFunc) conv_enc_cmp);
897 is_active = gtk_combo_box_get_active_iter (combo, &iter);
900 gtk_tree_model_get (gtk_combo_box_get_model (combo), &iter,
901 WORD_COL_ENCODING, &ptr, -1);
902 curr_enc = GPOINTER_TO_UINT (ptr);
903 found = g_list_find_custom (amb->conv_list, &curr_enc,
904 (GCompareFunc) conv_enc_cmp);
912 PERR(
"invalid string selection");
921 if (curr_enc == prev_enc)
925 g_hash_table_replace (data->choices, g_strdup (amb->byte_sequence),
926 conv_copy (curr_conv));
928 found = g_list_find_custom (amb->conv_list, &prev_enc,
929 (GCompareFunc) conv_enc_cmp);
930 if (!found && !default_conv)
934 data->n_unassigned--;
935 gxi_update_summary_label (data);
936 gxi_update_conversion_forward (data);
942 g_hash_table_insert (data->choices, g_strdup (amb->byte_sequence),
943 conv_copy (curr_conv));
949 data->n_unassigned--;
950 gxi_update_summary_label (data);
951 gxi_update_conversion_forward (data);
960 g_hash_table_remove (data->choices, amb->byte_sequence);
966 data->n_unassigned++;
967 gxi_update_summary_label (data);
968 gxi_update_conversion_forward (data);
976 gxi_conversion_next (GtkAssistant *assistant, gpointer user_data)
979 gxi_parse_file (data);
985 if (!data->encodings)
988 const gchar *locale_enc;
989 gchar *enc_string, **enc_array, **enc_cursor;
994 is_utf8 = g_get_charset (&locale_enc);
995 enc_string = g_ascii_strup (locale_enc, -1);
996 enc_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string));
998 data->encodings = g_list_append (NULL, enc_ptr);
1003 enc_ptr = GUINT_TO_POINTER (g_quark_from_string (
"UTF-8"));
1004 data->encodings = g_list_append (data->encodings, enc_ptr);
1010 enc_array = g_strsplit (_(
"ISO-8859-1 KOI8-U"),
" ", 0);
1013 for (enc_cursor = enc_array; *enc_cursor; enc_cursor++)
1015 if (!**enc_cursor)
continue;
1016 enc_string = g_ascii_strup (*enc_cursor, -1);
1017 enc_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string));
1019 if (!g_list_find (data->encodings, enc_ptr))
1022 iconv = g_iconv_open (
"UTF-8", enc_string);
1023 if (iconv != (GIConv) - 1)
1025 data->encodings = g_list_append (data->encodings, enc_ptr);
1026 g_iconv_close (iconv);
1028 g_free (enc_string);
1030 g_strfreev (enc_array);
1033 if (!data->default_encoding)
1036 data->default_encoding = GPOINTER_TO_UINT (data->encodings->data);
1041 data->choices = g_hash_table_new_full (g_str_hash, g_str_equal,
1042 g_free, (GDestroyNotify) conv_free);
1045 gxi_ambiguous_info_destroy (data);
1049 data->filename, data->encodings, &data->unique, &data->ambiguous_ht, NULL);
1051 if (data->n_impossible != -1)
1054 g_hash_table_foreach (data->ambiguous_ht, (GHFunc)ambiguous_list_insert,
1056 gxi_sort_ambiguous_list (data);
1063 QofSession *session = NULL;
1067 gchar *message = NULL;
1068 gboolean success = FALSE;
1070 if (data->n_unassigned || data->n_impossible)
1071 goto cleanup_parse_file;
1074 data->subst = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
1075 g_hash_table_foreach (data->ambiguous_ht, (GHFunc) subst_insert_amb, data);
1076 g_hash_table_foreach (data->unique, (GHFunc) subst_insert_unique, data);
1079 goto cleanup_parse_file;
1082 gxi_session_destroy (data);
1083 session = qof_session_new (NULL);
1084 data->session = session;
1087 if (io_err != ERR_BACKEND_NO_ERR)
1089 message = _(
"The file could not be reopened.");
1090 goto cleanup_parse_file;
1094 gxi_update_progress_bar (_(
"Reading file…"), 0.0);
1095 qof_session_load (session, gxi_update_progress_bar);
1096 gxi_update_progress_bar (NULL, -1.0);
1100 if (io_err == ERR_BACKEND_NO_ERR)
1104 goto cleanup_parse_file;
1109 message = _(
"The file could not be reopened.");
1110 goto cleanup_parse_file;
1117 gxi_update_progress_bar (_(
"Parsing file…"), 0.0);
1119 gxi_update_progress_bar (NULL, -1.0);
1122 data->session = session;
1124 message = _(
"There was an error parsing the file.");
1130 g_hash_table_destroy (data->subst);
1135 gnc_error_dialog (GTK_WINDOW (data->assistant),
"%s", message);
1138 gxi_session_destroy (data);
1147 g_return_val_if_fail (data && data->session, FALSE);
1149 gxi_update_progress_bar (_(
"Writing file…"), 0.0);
1151 gxi_update_progress_bar (NULL, -1.0);
1155 if (io_err == ERR_BACKEND_NO_ERR)
1161 gxi_session_destroy (data);
1175 GtkBuilder *builder;
1177 GtkListStore *list_store;
1178 GtkTreeStore *tree_store;
1179 GtkTreeIter iter, parent, *parent_ptr;
1180 GList *encodings_bak, *enc_iter;
1181 const gchar *encoding;
1186 builder = gtk_builder_new();
1187 gnc_builder_add_from_file (builder,
"assistant-xml-encoding.glade",
"encodings_dialog");
1188 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"encodings_dialog"));
1189 data->encodings_dialog = dialog;
1192 gtk_widget_set_name (GTK_WIDGET(dialog),
"gnc-id-assistant-xml-encoding");
1194 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, data);
1196 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (data->assistant));
1198 data->available_encs_view = GTK_TREE_VIEW (gtk_builder_get_object (builder,
"available_encs_view"));
1200 data->custom_enc_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"custom_enc_entry"));
1203 data->selected_encs_view = GTK_TREE_VIEW (gtk_builder_get_object (builder,
"selected_encs_view"));
1204 list_store = gtk_list_store_new (ENC_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
1205 for (enc_iter = data->encodings; enc_iter; enc_iter = enc_iter->next)
1207 encoding = g_quark_to_string (GPOINTER_TO_UINT (enc_iter->data));
1208 gtk_list_store_append (list_store, &iter);
1209 gtk_list_store_set (list_store, &iter, ENC_COL_STRING, encoding,
1210 ENC_COL_QUARK, enc_iter->data, -1);
1212 gtk_tree_view_insert_column_with_attributes (
1213 data->selected_encs_view, -1, NULL,
1214 gtk_cell_renderer_text_new (),
"text", ENC_COL_STRING, NULL);
1215 gtk_tree_view_set_model (data->selected_encs_view,
1216 GTK_TREE_MODEL (list_store));
1217 g_object_unref (list_store);
1220 data->available_encs_view = GTK_TREE_VIEW (gtk_builder_get_object (builder,
"available_encs_view"));
1221 tree_store = gtk_tree_store_new (ENC_NUM_COLS, G_TYPE_STRING, G_TYPE_POINTER);
1222 for (i = 0, system_enc = system_encodings;
1223 i < n_system_encodings;
1234 for (j = 0; j < system_enc->parent; j++)
1235 if (gtk_tree_model_iter_parent (GTK_TREE_MODEL (tree_store),
1247 if (system_enc->encoding)
1248 enc_ptr = GUINT_TO_POINTER (g_quark_from_string (system_enc->encoding));
1252 gtk_tree_store_append (tree_store, &iter, parent_ptr);
1253 gtk_tree_store_set (tree_store, &iter, ENC_COL_STRING,
1254 gettext (system_enc->text), ENC_COL_QUARK, enc_ptr, -1);
1256 gtk_tree_view_insert_column_with_attributes (
1257 data->available_encs_view, -1, NULL,
1258 gtk_cell_renderer_text_new (),
"text", ENC_COL_STRING, NULL);
1259 gtk_tree_view_set_model (data->available_encs_view,
1260 GTK_TREE_MODEL (tree_store));
1261 g_object_unref (tree_store);
1264 encodings_bak = g_list_copy (data->encodings);
1265 if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK)
1267 g_list_free (encodings_bak);
1268 if (data->encodings && !g_list_find (data->encodings,
1269 GUINT_TO_POINTER (data->default_encoding)))
1272 data->default_encoding = GPOINTER_TO_UINT (data->encodings->data);
1276 gxi_check_file (data);
1277 gxi_update_default_enc_combo (data);
1278 gxi_update_string_box (data);
1279 gxi_update_conversion_forward (data);
1283 g_list_free (data->encodings);
1284 data->encodings = encodings_bak;
1286 g_object_unref(G_OBJECT(builder));
1288 gtk_widget_destroy (dialog);
1289 data->encodings_dialog = NULL;
1296 const gchar *message;
1298 GtkListStore *store;
1301 enc_string = g_ascii_strup (
1302 g_quark_to_string (GPOINTER_TO_UINT (encoding_ptr)), -1);
1303 encoding_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string));
1305 if (g_list_find (data->encodings, encoding_ptr))
1307 message = _(
"This encoding has been added to the list already.");
1308 gnc_error_dialog (GTK_WINDOW (data->encodings_dialog),
"%s", message);
1313 iconv = g_iconv_open (
"UTF-8", enc_string);
1314 if (iconv == (GIConv) - 1)
1316 g_iconv_close (iconv);
1317 g_free (enc_string);
1318 message = _(
"This is an invalid encoding.");
1319 gnc_error_dialog (GTK_WINDOW (data->encodings_dialog),
"%s", message);
1322 g_iconv_close (iconv);
1325 data->encodings = g_list_append (data->encodings, encoding_ptr);
1326 store = GTK_LIST_STORE (gtk_tree_view_get_model (data->selected_encs_view));
1327 gtk_list_store_append (store, &iter);
1328 gtk_list_store_set (store, &iter, ENC_COL_STRING, enc_string,
1329 ENC_COL_QUARK, encoding_ptr, -1);
1331 g_free (enc_string);
1333 if (!data->encodings->next)
1334 gtk_dialog_set_response_sensitive (GTK_DIALOG (data->encodings_dialog),
1335 GTK_RESPONSE_OK, TRUE);
1341 GtkTreeSelection *selection;
1342 GtkTreeModel *model;
1346 selection = gtk_tree_view_get_selection (data->available_encs_view);
1347 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1349 gtk_tree_model_get (model, &iter, ENC_COL_QUARK, &enc_ptr, -1);
1352 gxi_add_encoding (data, enc_ptr);
1361 gtk_tree_model_get (model, iter, ENC_COL_QUARK, &enc_ptr, -1);
1362 data->encodings = g_list_remove (data->encodings, enc_ptr);
1363 gtk_list_store_remove (GTK_LIST_STORE (model), iter);
1364 if (!data->encodings)
1365 gtk_dialog_set_response_sensitive (GTK_DIALOG (data->encodings_dialog),
1366 GTK_RESPONSE_OK, FALSE);
1372 GtkTreeSelection *selection;
1373 GtkTreeModel *model;
1376 selection = gtk_tree_view_get_selection (data->selected_encs_view);
1377 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
1379 gxi_remove_encoding (data, model, &iter);
1383 gxi_available_enc_activated_cb (GtkTreeView *view, GtkTreePath *path,
1384 GtkTreeViewColumn *column,
1387 GtkTreeModel *model;
1391 model = gtk_tree_view_get_model (data->available_encs_view);
1392 if (!gtk_tree_model_get_iter (model, &iter, path))
1394 gtk_tree_model_get (model, &iter, ENC_COL_QUARK, &enc_ptr, -1);
1397 gxi_add_encoding (data, enc_ptr);
1403 const gchar *enc_string;
1405 enc_string = gtk_entry_get_text (entry);
1408 gxi_add_encoding (data, GUINT_TO_POINTER (g_quark_from_string (enc_string)));
1414 GtkWidget *entry = data->custom_enc_entry;
1415 gxi_custom_enc_activate_cb (GTK_ENTRY (entry), data);
1419 gxi_selected_enc_activated_cb (GtkTreeView *view, GtkTreePath *path,
1422 GtkTreeModel *model;
1425 model = gtk_tree_view_get_model (data->selected_encs_view);
1426 if (!gtk_tree_model_get_iter (model, &iter, path))
1428 gxi_remove_encoding (data, model, &iter);
void qof_session_save(QofSession *session, QofPercentageFunc percentage_func)
The qof_session_save() method will commit all changes that have been made to the session.
QofBackendError
The errors that can be reported to the GUI & other front-end users.
void qof_session_begin(QofSession *session, const char *uri, SessionOpenMode mode)
Begins a new session.
void xaccLogDisable(void)
document me
gchar * gnc_uri_get_path(const gchar *uri)
Extracts the path part from a uri.
#define PERR(format, args...)
Log a serious error.
Create a new store at the URI even if a store already exists there.
file does not specify encoding
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
gboolean gnc_xml2_parse_with_subst(GncXmlBackend *xml_be, QofBook *book, GHashTable *subst)
Parse a file in push mode, but replace byte sequences in the file given a hash table of substitutions...
QofBackendError qof_session_pop_error(QofSession *session)
The qof_session_pop_error() routine can be used to obtain the reason for any failure.
QofBackendError qof_session_get_error(QofSession *session)
The qof_session_get_error() routine can be used to obtain the reason for any failure.
API for the transaction logger.
gint gnc_xml2_find_ambiguous(const gchar *filename, GList *encodings, GHashTable **unique, GHashTable **ambiguous, GList **impossible)
Read a file as plain byte stream to find words that are not completely ASCII.
Utility functions for convert uri in separate components and back.
load and save data to files
QofBackend * qof_book_get_backend(const QofBook *book)
Retrieve the backend used by this book.
void xaccLogEnable(void)
document me