172 |
GtkTextBuffer *Buffer; |
GtkTextBuffer *Buffer; |
173 |
gboolean success; |
gboolean success; |
174 |
GError *error = NULL; |
GError *error = NULL; |
175 |
|
GtkWidget *confirm_invalid_utf8; |
176 |
|
gsize bytes_read, bytes_written; |
177 |
|
G_CONST_RETURN char **charset; |
178 |
|
|
179 |
START_FCN |
START_FCN |
180 |
|
|
203 |
/* make sure we have valid utf8 */ |
/* make sure we have valid utf8 */ |
204 |
if (!g_utf8_validate (buffer, -1, &end)) |
if (!g_utf8_validate (buffer, -1, &end)) |
205 |
{ |
{ |
|
gchar *primary; |
|
206 |
|
|
207 |
primary = g_strdup_printf (_("Document \"%s\" cannot be opened."), |
confirm_invalid_utf8 = gtk_message_dialog_new(GTK_WINDOW(MainWindow), |
208 |
str_get_last_part (Filename, PATH_SEP, TRUE)); |
GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, |
209 |
show_error (GTK_WINDOW (MainWindow), primary, |
GTK_MESSAGE_WARNING, |
210 |
"This file is not valid UTF-8 and will not be displayed."); |
GTK_BUTTONS_YES_NO, |
211 |
|
_("File \"%s\" does not qualify as valid UTF8. Attempt to convert to UTF8 and load anyway?"), |
212 |
|
Filename); |
213 |
|
|
214 |
|
if (gtk_dialog_run(GTK_DIALOG(confirm_invalid_utf8)) == GTK_RESPONSE_NO) |
215 |
|
{ |
216 |
|
g_free(buffer); |
217 |
|
gtk_widget_destroy(confirm_invalid_utf8); |
218 |
|
return; |
219 |
|
} |
220 |
|
else |
221 |
|
{ |
222 |
|
/* fix me, let the user choose the charset */ |
223 |
|
g_get_charset(charset); |
224 |
|
buffer = g_convert_with_fallback(buffer, strlen(buffer), |
225 |
|
"UTF-8", "ISO-8859-1", "[INVALID CHAR]", |
226 |
|
&bytes_read, &bytes_written, &error); |
227 |
|
if (buffer == NULL) |
228 |
|
{ |
229 |
|
g_print("conversion to utf8 failed at byte %d. reason why: %s\ncharset: %s\n", bytes_read, error->message, *charset); |
230 |
|
} |
231 |
|
} |
232 |
|
gtk_widget_destroy(confirm_invalid_utf8); |
233 |
|
|
234 |
g_free (primary); |
// primary = g_strdup_printf (_("Document \"%s\" cannot be opened."), |
235 |
g_free (buffer); |
// str_get_last_part (Filename, PATH_SEP, TRUE)); |
236 |
|
// show_error (GTK_WINDOW (MainWindow), primary, |
237 |
|
// "This file is not valid UTF-8 and will not be displayed."); |
238 |
|
|
239 |
} |
} |
240 |
else |
// else |
241 |
{ |
// { |
242 |
/* Insert file content in the widget */ |
/* Insert file content in the widget */ |
243 |
gtk_text_buffer_set_text (Buffer, buffer, -1); |
gtk_text_buffer_set_text (Buffer, buffer, -1); |
244 |
g_free (buffer); |
g_free (buffer); |
245 |
} |
// } |
246 |
} |
} |
247 |
} |
} |
248 |
gtk_text_buffer_get_start_iter(Buffer, &start); |
gtk_text_buffer_get_start_iter(Buffer, &start); |