X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fui%2Fgui%2Fpsppire-data-window.c;h=28ec605205106c9f8e4ee7e3924a66279572ef4f;hb=3e98eec9f2c774a7c695944c15de651ecd120430;hp=f36283289f324e7779b46f9175eee82b93013771;hpb=adf4bc614f52fd20d34190dc710af5db9a897c40;p=pspp diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index f36283289f..28ec605205 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -1,5 +1,5 @@ /* PSPPIRE - a graphical user interface for PSPP. - Copyright (C) 2008, 2009, 2010, 2011, 2012 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 @@ -27,33 +27,22 @@ #include "ui/gui/aggregate-dialog.h" #include "ui/gui/autorecode-dialog.h" #include "ui/gui/builder-wrapper.h" -#include "ui/gui/chi-square-dialog.h" #include "ui/gui/comments-dialog.h" -#include "ui/gui/compute-dialog.h" -#include "ui/gui/count-dialog.h" #include "ui/gui/entry-dialog.h" #include "ui/gui/executor.h" #include "ui/gui/help-menu.h" #include "ui/gui/helper.h" #include "ui/gui/helper.h" -#include "ui/gui/k-related-dialog.h" -#include "ui/gui/npar-two-sample-related.h" -#include "ui/gui/oneway-anova-dialog.h" #include "ui/gui/psppire-data-window.h" #include "ui/gui/psppire-dialog-action.h" +#include "ui/gui/psppire-encoding-selector.h" #include "ui/gui/psppire-syntax-window.h" #include "ui/gui/psppire-window.h" #include "ui/gui/psppire.h" -#include "ui/gui/runs-dialog.h" -#include "ui/gui/ks-one-sample-dialog.h" #include "ui/gui/recode-dialog.h" #include "ui/gui/select-cases-dialog.h" #include "ui/gui/split-file-dialog.h" -#include "ui/gui/t-test-one-sample.h" -#include "ui/gui/t-test-paired-samples.h" #include "ui/gui/text-data-import-dialog.h" -#include "ui/gui/transpose-dialog.h" -#include "ui/gui/univariate-dialog.h" #include "ui/gui/weight-cases-dialog.h" #include "ui/syntax-gen.h" @@ -314,18 +303,25 @@ dump_rm (GtkRecentManager *rm) } #endif +static gboolean +has_suffix (const gchar *name, const gchar *suffix) +{ + size_t name_len = strlen (name); + size_t suffix_len = strlen (suffix); + return (name_len > suffix_len + && !c_strcasecmp (&name[name_len - suffix_len], suffix)); +} + static gboolean name_has_por_suffix (const gchar *name) { - size_t length = strlen (name); - return length > 4 && !c_strcasecmp (&name[length - 4], ".por"); + return has_suffix (name, ".por"); } static gboolean name_has_sav_suffix (const gchar *name) { - size_t length = strlen (name); - return length > 4 && !c_strcasecmp (&name[length - 4], ".sav"); + return has_suffix (name, ".sav") || has_suffix (name, ".zsav"); } /* Returns true if NAME has a suffix which might denote a PSPP file */ @@ -336,38 +332,68 @@ name_has_suffix (const gchar *name) } static gboolean -load_file (PsppireWindow *de, const gchar *file_name) +load_file (PsppireWindow *de, const gchar *file_name, const char *encoding, + gpointer syn) { - struct string filename; - gchar *utf8_file_name; - const char *mime_type; - gchar *syntax; + const char *mime_type = NULL; + gchar *syntax = NULL; bool ok; - ds_init_empty (&filename); - - utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL); + if (syn == NULL) + { + gchar *utf8_file_name; + struct string filename; + + utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL); - syntax_gen_string (&filename, ss_cstr (utf8_file_name)); + if (NULL == utf8_file_name) + return FALSE; - g_free (utf8_file_name); + ds_init_empty (&filename); + syntax_gen_string (&filename, ss_cstr (utf8_file_name)); + + g_free (utf8_file_name); - syntax = g_strdup_printf ("GET FILE=%s.", ds_cstr (&filename)); - ds_destroy (&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 + { + syntax = syn; + } ok = execute_syntax (PSPPIRE_DATA_WINDOW (de), lex_reader_for_string (syntax)); g_free (syntax); - mime_type = (name_has_por_suffix (file_name) - ? "application/x-spss-por" - : "application/x-spss-sav"); - - add_most_recent (file_name, mime_type); + if (ok && syn == NULL) + { + if (name_has_por_suffix (file_name)) + mime_type = "application/x-spss-por"; + else if (name_has_sav_suffix (file_name)) + mime_type = "application/x-spss-sav"; + + add_most_recent (file_name, mime_type, encoding); + } return ok; } +static const char * +psppire_data_window_format_to_string (enum PsppireDataWindowFormat format) +{ + if (format == PSPPIRE_DATA_WINDOW_SAV) + return ".sav"; + else if (format == PSPPIRE_DATA_WINDOW_ZSAV) + return ".zsav"; + else + return ".por"; +} + /* Save DE to file */ static void save_file (PsppireWindow *w) @@ -384,12 +410,7 @@ save_file (PsppireWindow *w) fnx = g_string_new (file_name); if ( ! name_has_suffix (fnx->str)) - { - if ( de->save_as_portable) - g_string_append (fnx, ".por"); - else - g_string_append (fnx, ".sav"); - } + g_string_append (fnx, psppire_data_window_format_to_string (de->format)); ds_init_empty (&filename); @@ -400,9 +421,13 @@ save_file (PsppireWindow *w) syntax_gen_string (&filename, ss_cstr (utf8_file_name)); g_free (utf8_file_name); - syntax = g_strdup_printf ("%s OUTFILE=%s.", - de->save_as_portable ? "EXPORT" : "SAVE", - ds_cstr (&filename)); + if (de->format == PSPPIRE_DATA_WINDOW_SAV) + syntax = g_strdup_printf ("SAVE OUTFILE=%s.", ds_cstr (&filename)); + else if (de->format == PSPPIRE_DATA_WINDOW_ZSAV) + syntax = g_strdup_printf ("SAVE /ZCOMPRESSED /OUTFILE=%s.", + ds_cstr (&filename)); + else + syntax = g_strdup_printf ("EXPORT OUTFILE=%s.", ds_cstr (&filename)); ds_destroy (&filename); @@ -426,10 +451,12 @@ sysfile_info (PsppireDataWindow *de) struct string filename; gchar *file_name = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); - gchar *utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL); + const gchar *encoding = psppire_encoding_selector_get_encoding ( + gtk_file_chooser_get_extra_widget (GTK_FILE_CHOOSER (dialog))); + gchar *syntax; ds_init_empty (&filename); @@ -438,7 +465,11 @@ sysfile_info (PsppireDataWindow *de) g_free (utf8_file_name); - syntax = g_strdup_printf ("SYSFILE INFO %s.", ds_cstr (&filename)); + if (encoding) + syntax = g_strdup_printf ("SYSFILE INFO %s ENCODING='%s'.", + ds_cstr (&filename), encoding); + else + syntax = g_strdup_printf ("SYSFILE INFO %s.", ds_cstr (&filename)); g_free (execute_syntax_string (de, syntax)); } @@ -450,9 +481,11 @@ sysfile_info (PsppireDataWindow *de) static void data_pick_filename (PsppireWindow *window) { + GtkListStore *list_store; + GtkWidget *combo_box; + PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (window); - GtkFileFilter *filter = gtk_file_filter_new (); - GtkWidget *button_sys; + GtkFileFilter *filter; GtkWidget *dialog = gtk_file_chooser_dialog_new (_("Save"), GTK_WINDOW (de), @@ -463,10 +496,16 @@ data_pick_filename (PsppireWindow *window) g_object_set (dialog, "local-only", FALSE, NULL); + filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("System Files (*.sav)")); gtk_file_filter_add_mime_type (filter, "application/x-spss-sav"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + filter = gtk_file_filter_new (); + gtk_file_filter_set_name (filter, _("Compressed System Files (*.zsav)")); + gtk_file_filter_add_pattern (filter, "*.zsav"); + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, _("Portable Files (*.por) ")); gtk_file_filter_add_mime_type (filter, "application/x-spss-por"); @@ -476,24 +515,49 @@ data_pick_filename (PsppireWindow *window) gtk_file_filter_set_name (filter, _("All Files")); gtk_file_filter_add_pattern (filter, "*"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); { - GtkWidget *button_por; - GtkWidget *vbox = gtk_vbox_new (TRUE, 5); - button_sys = - gtk_radio_button_new_with_label (NULL, _("System File")); - - button_por = - gtk_radio_button_new_with_label - (gtk_radio_button_get_group (GTK_RADIO_BUTTON(button_sys)), - _("Portable File")); - - psppire_box_pack_start_defaults (GTK_BOX (vbox), button_sys); - psppire_box_pack_start_defaults (GTK_BOX (vbox), button_por); - - gtk_widget_show_all (vbox); - - gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(dialog), vbox); + GtkCellRenderer *cell; + GtkWidget *label; + GtkTreeIter iter; + GtkWidget *hbox; + + list_store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING); + combo_box = gtk_combo_box_new_with_model (GTK_TREE_MODEL (list_store)); + + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + 0, PSPPIRE_DATA_WINDOW_SAV, + 1, _("System File"), + -1); + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); + + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + 0, PSPPIRE_DATA_WINDOW_ZSAV, + 1, _("Compressed System File"), + -1); + + gtk_list_store_append (list_store, &iter); + gtk_list_store_set (list_store, &iter, + 0, PSPPIRE_DATA_WINDOW_POR, + 1, _("Portable File"), + -1); + + label = gtk_label_new (_("Format:")); + + cell = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo_box), cell, + "text", 1); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), combo_box, FALSE, FALSE, 0); + gtk_widget_show_all (hbox); + + gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), hbox); } gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), @@ -509,16 +573,18 @@ data_pick_filename (PsppireWindow *window) gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)) ); - de->save_as_portable = - ! gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button_sys)); + GtkTreeIter iter; + int format; + + gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter); + gtk_tree_model_get (GTK_TREE_MODEL (list_store), &iter, + 0, &format, + -1); + de->format = format; if ( ! name_has_suffix (filename->str)) - { - if ( de->save_as_portable) - g_string_append (filename, ".por"); - else - g_string_append (filename, ".sav"); - } + g_string_append (filename, + psppire_data_window_format_to_string (format)); psppire_window_set_filename (PSPPIRE_WINDOW (de), filename->str); @@ -701,7 +767,7 @@ on_recent_data_select (GtkMenuShell *menushell, g_free (uri); - open_data_window (window, file); + open_data_window (window, file, NULL, NULL); g_free (file); } @@ -764,7 +830,7 @@ on_recent_files_select (GtkMenuShell *menushell, gpointer user_data) free (encoding); - if ( psppire_window_load (PSPPIRE_WINDOW (se), file) ) + if ( psppire_window_load (PSPPIRE_WINDOW (se), file, encoding, NULL) ) gtk_widget_show (se); else gtk_widget_destroy (se); @@ -939,43 +1005,24 @@ psppire_data_window_finish_init (PsppireDataWindow *de, enable_save (de); connect_action (de, "file_new_data", G_CALLBACK (create_data_window)); - connect_action (de, "file_import", G_CALLBACK (text_data_import_assistant)); - connect_action (de, "file_save", G_CALLBACK (psppire_window_save)); - connect_action (de, "file_open", G_CALLBACK (psppire_window_open)); - connect_action (de, "file_save_as", G_CALLBACK (psppire_window_save_as)); - connect_action (de, "rename_dataset", G_CALLBACK (on_rename_dataset)); - connect_action (de, "file_information_working-file", G_CALLBACK (display_dict)); - connect_action (de, "file_information_external-file", G_CALLBACK (sysfile_info)); g_signal_connect_swapped (get_action_assert (de->builder, "view_value-labels"), "toggled", G_CALLBACK (toggle_value_labels), de); - connect_action (de, "data_transpose", G_CALLBACK (transpose_dialog)); connect_action (de, "data_select-cases", G_CALLBACK (select_cases_dialog)); connect_action (de, "data_aggregate", G_CALLBACK (aggregate_dialog)); - connect_action (de, "transform_compute", G_CALLBACK (compute_dialog)); connect_action (de, "transform_autorecode", G_CALLBACK (autorecode_dialog)); connect_action (de, "data_split-file", G_CALLBACK (split_file_dialog)); connect_action (de, "data_weight-cases", G_CALLBACK (weight_cases_dialog)); - connect_action (de, "oneway-anova", G_CALLBACK (oneway_anova_dialog)); - connect_action (de, "paired-t-test", G_CALLBACK (t_test_paired_samples_dialog)); - connect_action (de, "one-sample-t-test", G_CALLBACK (t_test_one_sample_dialog)); connect_action (de, "utilities_comments", G_CALLBACK (comments_dialog)); - connect_action (de, "transform_count", G_CALLBACK (count_dialog)); connect_action (de, "transform_recode-same", G_CALLBACK (recode_same_dialog)); connect_action (de, "transform_recode-different", G_CALLBACK (recode_different_dialog)); - connect_action (de, "univariate", G_CALLBACK (univariate_dialog)); - connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog)); - connect_action (de, "runs", G_CALLBACK (runs_dialog)); - connect_action (de, "ks-one-sample", G_CALLBACK (ks_one_sample_dialog)); - connect_action (de, "k-related-samples", G_CALLBACK (k_related_dialog)); - connect_action (de, "two-related-samples", G_CALLBACK (two_related_dialog)); { GtkWidget *recent_data = @@ -1083,6 +1130,15 @@ psppire_data_window_dispose (GObject *object) if (dw->dict) { + g_signal_handlers_disconnect_by_func (dw->dict, + G_CALLBACK (enable_save), dw); + g_signal_handlers_disconnect_by_func (dw->dict, + G_CALLBACK (on_weight_change), dw); + g_signal_handlers_disconnect_by_func (dw->dict, + G_CALLBACK (on_filter_change), dw); + g_signal_handlers_disconnect_by_func (dw->dict, + G_CALLBACK (on_split_change), dw); + g_object_unref (dw->dict); dw->dict = NULL; } @@ -1227,7 +1283,7 @@ psppire_data_window_new (struct dataset *ds) GtkWidget *dw; if (the_session == NULL) - the_session = session_create (); + the_session = session_create (NULL); if (ds == NULL) { @@ -1317,7 +1373,8 @@ create_data_window (void) } void -open_data_window (PsppireWindow *victim, const char *file_name) +open_data_window (PsppireWindow *victim, const char *file_name, + const char *encoding, gpointer hint) { GtkWidget *window; @@ -1330,7 +1387,7 @@ open_data_window (PsppireWindow *victim, const char *file_name) else window = psppire_data_window_new (NULL); - psppire_window_load (PSPPIRE_WINDOW (window), file_name); + psppire_window_load (PSPPIRE_WINDOW (window), file_name, encoding, hint); gtk_widget_show_all (window); }