This should allow old files in unexpected encodings to be more easily read.
Problem reported by Przemek Powalko <pp.alter.ego@gmail.com>.
* The SYSFILE INFO command now accepts an ENCODING subcommand to
specify the character encoding of string data in the system file.
+ * PSPPIRE graphical user interface improvements:
+
+ - File|Open now allows an encoding to be selected for opening
+ system files.
+
+ - File|Display Data File Information|External File... now allows an
+ encoding to be selected.
+
Changes from 0.8.1 to 0.8.2:
* Charts are now rendered with colours from the Tango palette instead
}
static gboolean
-load_file (PsppireWindow *de, const gchar *file_name, gpointer syn)
+load_file (PsppireWindow *de, const gchar *file_name, const char *encoding,
+ gpointer syn)
{
const char *mime_type = NULL;
gchar *syntax = NULL;
syntax_gen_string (&filename, ss_cstr (utf8_file_name));
g_free (utf8_file_name);
-
- syntax = g_strdup_printf ("GET FILE=%s.", ds_cstr (&filename));
+
+ if (encoding && encoding[0])
+ syntax = g_strdup_printf ("GET FILE=%s ENCODING='%s'.",
+ ds_cstr (&filename), encoding);
+ else
+ syntax = g_strdup_printf ("GET FILE=%s.", ds_cstr (&filename));
ds_destroy (&filename);
}
else
else if (name_has_sav_suffix (file_name))
mime_type = "application/x-spss-sav";
- add_most_recent (file_name, mime_type);
+ add_most_recent (file_name, mime_type, encoding);
}
return ok;
g_free (uri);
- open_data_window (window, file, NULL);
+ open_data_window (window, file, NULL, NULL);
g_free (file);
}
free (encoding);
- if ( psppire_window_load (PSPPIRE_WINDOW (se), file, NULL) )
+ if ( psppire_window_load (PSPPIRE_WINDOW (se), file, encoding, NULL) )
gtk_widget_show (se);
else
gtk_widget_destroy (se);
}
void
-open_data_window (PsppireWindow *victim, const char *file_name, gpointer hint)
+open_data_window (PsppireWindow *victim, const char *file_name,
+ const char *encoding, gpointer hint)
{
GtkWidget *window;
else
window = psppire_data_window_new (NULL);
- psppire_window_load (PSPPIRE_WINDOW (window), file_name, hint);
+ psppire_window_load (PSPPIRE_WINDOW (window), file_name, encoding, hint);
gtk_widget_show_all (window);
}
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2010, 2011, 2012, 2013 Free Software Foundation
+ Copyright (C) 2008, 2010, 2011, 2012, 2013, 2014 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
bool psppire_data_window_is_empty (PsppireDataWindow *);
void create_data_window (void);
-void open_data_window (PsppireWindow *victim, const char *file_name, gpointer hint);
+void open_data_window (PsppireWindow *victim, const char *file_name,
+ const char *encoding, gpointer hint);
G_END_DECLS
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2012, 2014 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static void
-load_and_show_syntax_window (GtkWidget *se, const gchar *filename)
+load_and_show_syntax_window (GtkWidget *se, const gchar *filename,
+ const gchar *encoding)
{
gboolean ok;
gtk_source_buffer_begin_not_undoable_action (PSPPIRE_SYNTAX_WINDOW (se)->buffer);
- ok = psppire_window_load (PSPPIRE_WINDOW (se), filename, NULL);
+ ok = psppire_window_load (PSPPIRE_WINDOW (se), filename, encoding, NULL);
gtk_source_buffer_end_not_undoable_action (PSPPIRE_SYNTAX_WINDOW (se)->buffer);
if (ok )
void
open_syntax_window (const char *file_name, const gchar *encoding)
{
- GtkWidget *se = psppire_syntax_window_new (encoding);
+ GtkWidget *se = psppire_syntax_window_new (NULL);
if ( file_name)
- load_and_show_syntax_window (se, file_name);
+ load_and_show_syntax_window (se, file_name, encoding);
}
Loads the buffer from the file called FILENAME
*/
gboolean
-syntax_load (PsppireWindow *window, const gchar *filename, gpointer not_used)
+syntax_load (PsppireWindow *window, const gchar *filename,
+ const gchar *encoding, gpointer not_used)
{
GError *err = NULL;
gchar *text_locale = NULL;
GtkTextIter iter;
PsppireSyntaxWindow *sw = PSPPIRE_SYNTAX_WINDOW (window);
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (sw->buffer);
- gchar *encoding;
- char *mime_type;
/* FIXME: What if it's a very big file ? */
if ( ! g_file_get_contents (filename, &text_locale, &len_locale, &err) )
return FALSE;
}
- /* Determine the file's encoding and update sw->encoding. (The ordering is
- important here because encoding_guess_whole_file() often returns its
- argument instead of a copy of it.) */
- encoding = g_strdup (encoding_guess_whole_file (sw->encoding, text_locale,
- len_locale));
- g_free (sw->encoding);
- sw->encoding = encoding;
+ if (!encoding || !encoding[0])
+ {
+ /* Determine the file's encoding and update sw->encoding. (The ordering
+ is important here because encoding_guess_whole_file() often returns
+ its argument instead of a copy of it.) */
+ char *guessed_encoding;
+
+ guessed_encoding = g_strdup (encoding_guess_whole_file (sw->encoding,
+ text_locale,
+ len_locale));
+ g_free (sw->encoding);
+ sw->encoding = guessed_encoding;
+ }
+ else
+ {
+ g_free (sw->encoding);
+ sw->encoding = g_strdup (encoding);
+ }
text_utf8 = recode_substring_pool ("UTF-8", encoding,
ss_buffer (text_locale, len_locale),
free (text_utf8);
- mime_type = xasprintf ("text/x-spss-syntax; charset=%s", sw->encoding);
- add_most_recent (filename, mime_type);
- free (mime_type);
+ add_most_recent (filename, "text/x-spss-syntax", sw->encoding);
return TRUE;
}
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2009, 2010, 2011, 2013 Free Software Foundation
+ Copyright (C) 2009, 2010, 2011, 2013, 2014 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
static void delete_recent (const char *file_name);
gboolean
-psppire_window_load (PsppireWindow *w, const gchar *file, gpointer hint)
+psppire_window_load (PsppireWindow *w, const gchar *file,
+ const gchar *encoding, gpointer hint)
{
gboolean ok;
PsppireWindowIface *i = PSPPIRE_WINDOW_MODEL_GET_IFACE (w);
g_return_val_if_fail (i->load, FALSE);
- ok = i->load (w, file, hint);
+ ok = i->load (w, file, encoding, hint);
if ( ok )
{
}
-static void
-on_selection_changed (GtkFileChooser *chooser, GtkWidget *encoding_selector)
-{
- const gchar *sysname;
-
- const gchar *name = gtk_file_chooser_get_filename (chooser);
-
- if ( NULL == name )
- return;
-
- sysname = convert_glib_filename_to_system_filename (name, NULL);
-
- if ( ! fn_exists (sysname))
- {
- gtk_widget_set_sensitive (encoding_selector, FALSE);
- return;
- }
-
- gtk_widget_set_sensitive (encoding_selector, ANY_NO == any_reader_may_open (sysname));
-}
-
GtkWidget *
psppire_window_file_chooser_dialog (PsppireWindow *toplevel)
{
free (dir_name);
}
-
- {
- GtkWidget *encoding_selector = psppire_encoding_selector_new ("Auto", true);
-
- gtk_widget_set_sensitive (encoding_selector, FALSE);
-
- g_signal_connect (dialog, "selection-changed", G_CALLBACK (on_selection_changed),
- encoding_selector);
-
- gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), encoding_selector);
- }
+ gtk_file_chooser_set_extra_widget (
+ GTK_FILE_CHOOSER (dialog),
+ psppire_encoding_selector_new ("Auto", true));
return dialog;
}
enum detect_result res = any_reader_may_open (sysname);
if (ANY_YES == res)
- open_data_window (de, name, NULL);
+ open_data_window (de, name, encoding, NULL);
else if (ANY_NO == res)
open_syntax_window (name, encoding);
with associated MIME_TYPE. If it's already in the list, it moves it to the
top. */
void
-add_most_recent (const char *file_name, const char *mime_type)
+add_most_recent (const char *file_name,
+ const char *mime_type, const char *encoding)
{
gchar *uri = g_filename_to_uri (file_name, NULL, NULL);
-
if ( uri )
{
GtkRecentData recent_data;
+ gchar *full_mime_type;
+
+ if (encoding && encoding[0])
+ full_mime_type = g_strdup_printf ("%s; charset=%s",
+ mime_type, encoding);
+ else
+ full_mime_type = g_strdup (mime_type);
recent_data.display_name = NULL;
recent_data.description = NULL;
- recent_data.mime_type = CONST_CAST (gchar *, mime_type);
+ recent_data.mime_type = full_mime_type;
recent_data.app_name = CONST_CAST (gchar *, g_get_application_name ());
recent_data.app_exec = g_strjoin (" ", g_get_prgname (), "%u", NULL);
recent_data.groups = NULL;
uri, &recent_data);
g_free (recent_data.app_exec);
+ g_free (full_mime_type);
}
g_free (uri);
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010, 2011, 2013 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2013, 2014 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
void (*save) (PsppireWindow *w);
void (*pick_filename) (PsppireWindow *);
- gboolean (*load) (PsppireWindow *w, const gchar *, gpointer hint);
+ gboolean (*load) (PsppireWindow *w, const gchar *filename,
+ const gchar *encoding, gpointer hint);
};
void psppire_window_save (PsppireWindow *w);
void psppire_window_save_as (PsppireWindow *w);
-gboolean psppire_window_load (PsppireWindow *w, const gchar *file, gpointer hint);
+gboolean psppire_window_load (PsppireWindow *w, const gchar *file,
+ const gchar *encoding, gpointer hint);
void psppire_window_open (PsppireWindow *de);
GtkWidget *psppire_window_file_chooser_dialog (PsppireWindow *toplevel);
-void add_most_recent (const char *file_name, const char *mime_type);
+void add_most_recent (const char *file_name, const char *mime_type,
+ const char *encoding);
G_END_DECLS
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011, 2012, 2013 Free Software Foundation
+ Copyright (C) 2004, 2005, 2006, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
/* Check to see if the file is a .sav or a .por file. If not
assume that it is a syntax file */
if (res == ANY_YES)
- open_data_window (NULL, filename, NULL);
+ open_data_window (NULL, filename, NULL, NULL);
else if (res == ANY_NO)
{
create_data_window ();
/* PSPPIRE - a graphical user interface for PSPP.
- Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation
+ Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
case GTK_RESPONSE_APPLY:
{
gchar *fn = g_path_get_basename (ia->file.file_name);
- open_data_window (PSPPIRE_WINDOW (dw), fn, generate_syntax (ia));
+ open_data_window (PSPPIRE_WINDOW (dw), fn, NULL, generate_syntax (ia));
g_free (fn);
}
break;