From: John Darrington Date: Sun, 22 Mar 2009 08:37:42 +0000 (+0900) Subject: Allow non-ascii characters to be entered into the variable and data sheets. X-Git-Tag: v0.7.3~209 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f70b0dd47b62dbefe87fb08ba8a8984aa5a50c4;p=pspp-builds.git Allow non-ascii characters to be entered into the variable and data sheets. Convert strings from utf8 to the pspp (data) localeĀ“s encoding before passing to the model. --- diff --git a/src/ui/gui/helper.c b/src/ui/gui/helper.c index 49dbfda4..83319c45 100644 --- a/src/ui/gui/helper.c +++ b/src/ui/gui/helper.c @@ -160,6 +160,13 @@ pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err) return recode_string (CONV_PSPP_TO_UTF8, text, len); } +gchar * +utf8_to_pspp_locale (const gchar *text, gssize len, GError **err) +{ + return recode_string (CONV_UTF8_TO_PSPP, text, len); +} + + #define _(msgid) gettext (msgid) #define N_(msgid) msgid diff --git a/src/ui/gui/helper.h b/src/ui/gui/helper.h index 17e777ac..ca15a35c 100644 --- a/src/ui/gui/helper.h +++ b/src/ui/gui/helper.h @@ -44,7 +44,8 @@ GtkAction * get_action_assert (GtkBuilder *builder, const gchar *name); GtkWidget * get_widget_assert (GtkBuilder *builder, const gchar *name); /* Converts a string in the pspp locale to utf-8 */ -char * pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err); +gchar * pspp_locale_to_utf8 (const gchar *text, gssize len, GError **err); +gchar * utf8_to_pspp_locale (const gchar *text, gssize len, GError **err); void connect_help (GtkBuilder *); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index f36fe38a..45104f5c 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -659,6 +659,7 @@ gboolean psppire_data_store_set_string (PsppireDataStore *store, const gchar *text, glong row, glong col) { + gchar *s; glong n_cases; const struct variable *pv = psppire_dict_get_variable (store->dict, col); if ( NULL == pv) @@ -672,9 +673,12 @@ psppire_data_store_set_string (PsppireDataStore *store, if (row == n_cases) psppire_data_store_insert_new_case (store, row); + s = utf8_to_pspp_locale (text, -1, NULL); + psppire_data_store_data_in (store, row, - var_get_case_index (pv), ss_cstr (text), + var_get_case_index (pv), ss_cstr (s), var_get_write_format (pv)); + free (s); psppire_sheet_model_range_changed (PSPPIRE_SHEET_MODEL (store), row, col, row, col); diff --git a/src/ui/gui/psppire-var-store.c b/src/ui/gui/psppire-var-store.c index 8e78e2ec..1d6f465d 100644 --- a/src/ui/gui/psppire-var-store.c +++ b/src/ui/gui/psppire-var-store.c @@ -467,8 +467,16 @@ psppire_var_store_set_string (PsppireSheetModel *model, switch (col) { case PSPPIRE_VAR_STORE_COL_NAME: - return psppire_dict_rename_var (var_store->dict, pv, text); - break; + { + int i; + /* Until non-ascii in variable names is better managed, + simply refuse to allow them to be entered. */ + for (i = 0 ; i < strlen (text) ; ++i ) + if (!g_ascii_isprint (text[i])) + return FALSE; + return psppire_dict_rename_var (var_store->dict, pv, text); + break; + } case PSPPIRE_VAR_STORE_COL_COLUMNS: if ( ! text) return FALSE; var_set_display_width (pv, atoi (text)); @@ -522,8 +530,12 @@ psppire_var_store_set_string (PsppireSheetModel *model, } break; case PSPPIRE_VAR_STORE_COL_LABEL: - var_set_label (pv, text); - return TRUE; + { + gchar *s = utf8_to_pspp_locale (text, -1, NULL); + var_set_label (pv, s); + free (s); + return TRUE; + } break; case PSPPIRE_VAR_STORE_COL_TYPE: case PSPPIRE_VAR_STORE_COL_VALUES: