static void gxi_data_destroy (GncXmlImportData *data) { if (!data) return; if (data->filename) { g_free (data->filename); data->filename = NULL; } gxi_session_destroy (data); gxi_ambiguous_info_destroy (data); if (data->choices) { g_hash_table_destroy (data->choices); data->choices = NULL; } if (data->string_box) { gtk_widget_destroy (data->string_box); data->string_box = NULL; } if (data->assistant) { gtk_widget_destroy (data->assistant); data->assistant = NULL; } }
static void gxi_check_file (GncXmlImportData *data) { if (!data->encodings) { gboolean is_utf8; const gchar *locale_enc; gchar *enc_string, **enc_array, **enc_cursor; gpointer enc_ptr; GIConv iconv; /* first locale encoding */ is_utf8 = g_get_charset (&locale_enc); enc_string = g_ascii_strup (locale_enc, -1); enc_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string)); g_free (enc_string); data->encodings = g_list_append (NULL, enc_ptr); /* add utf-8 */ if (!is_utf8) { enc_ptr = GUINT_TO_POINTER (g_quark_from_string ("UTF-8")); data->encodings = g_list_append (data->encodings, enc_ptr); } /* Translators: Please insert encodings here that are typically used in your * locale, separated by spaces. No need for ASCII or UTF-8, check `locale -m` * for assistance with spelling. */ enc_array = g_strsplit (_("ISO-8859-1 KOI8-U"), " ", 0); /* loop through typical encodings */ for (enc_cursor = enc_array; *enc_cursor; enc_cursor++) { if (!**enc_cursor) continue; enc_string = g_ascii_strup (*enc_cursor, -1); enc_ptr = GUINT_TO_POINTER (g_quark_from_string (enc_string)); if (!g_list_find (data->encodings, enc_ptr)) { /* test whether we like this encoding */ iconv = g_iconv_open ("UTF-8", enc_string); if (iconv != (GIConv) - 1) /* we like it */ data->encodings = g_list_append (data->encodings, enc_ptr); g_iconv_close (iconv); } g_free (enc_string); } g_strfreev (enc_array); } if (!data->default_encoding) { /* choose top one */ data->default_encoding = GPOINTER_TO_UINT (data->encodings->data); } if (!data->choices) { data->choices = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) conv_free); } gxi_ambiguous_info_destroy (data); /* analyze file */ data->n_impossible = gnc_xml2_find_ambiguous ( data->filename, data->encodings, &data->unique, &data->ambiguous_ht, NULL); if (data->n_impossible != -1) { /* sort ambiguous words */ g_hash_table_foreach (data->ambiguous_ht, (GHFunc)ambiguous_list_insert, data); gxi_sort_ambiguous_list (data); } }