/* 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
#include "libpspp/str.h"
#include "ui/gui/aggregate-dialog.h"
#include "ui/gui/autorecode-dialog.h"
-#include "ui/gui/binomial-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/crosstabs-dialog.h"
#include "ui/gui/entry-dialog.h"
#include "ui/gui/executor.h"
-#include "ui/gui/frequencies-dialog.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"
static void psppire_data_window_iface_init (PsppireWindowIface *iface);
static void psppire_data_window_dispose (GObject *object);
+static void psppire_data_window_finalize (GObject *object);
static void psppire_data_window_set_property (GObject *object,
guint prop_id,
const GValue *value,
parent_class = g_type_class_peek_parent (class);
object_class->dispose = psppire_data_window_dispose;
+ object_class->finalize = psppire_data_window_finalize;
object_class->set_property = psppire_data_window_set_property;
object_class->get_property = psppire_data_window_get_property;
}
#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 */
}
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);
+ if (syn == NULL)
+ {
+ gchar *utf8_file_name;
+ struct string filename;
+
+ utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
- utf8_file_name = g_filename_to_utf8 (file_name, -1, NULL, NULL, NULL);
+ if (NULL == utf8_file_name)
+ return FALSE;
- syntax_gen_string (&filename, ss_cstr (utf8_file_name));
-
- 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)
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);
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);
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);
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));
}
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),
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");
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),
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);
g_free (uri);
- open_data_window (window, file);
+ open_data_window (window, file, NULL, NULL);
g_free (file);
}
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);
}
static void
-on_switch_page (PsppireDataEditor *de, GtkNotebookPage *p,
+on_switch_page (PsppireDataEditor *de, gpointer p,
gint pagenum, PsppireDataWindow *dw)
{
GtkWidget *page_menu_item;
GCallback handler)
{
GtkAction *action = get_action_assert (dw->builder, action_name);
-
+
g_signal_connect_swapped (action, "activate", handler, dw);
return action;
}
+/* Only a data file with at least one variable can be saved. */
+static void
+enable_save (PsppireDataWindow *dw)
+{
+ gboolean enable = psppire_dict_get_var_cnt (dw->dict) > 0;
+
+ gtk_action_set_sensitive (get_action_assert (dw->builder, "file_save"),
+ enable);
+ gtk_action_set_sensitive (get_action_assert (dw->builder, "file_save_as"),
+ enable);
+}
+
/* Initializes as much of a PsppireDataWindow as we can and must before the
dataset has been set.
G_CALLBACK (on_split_change),
de);
+ g_signal_connect_swapped (de->dict, "backend-changed",
+ G_CALLBACK (enable_save), de);
+ g_signal_connect_swapped (de->dict, "variable-inserted",
+ G_CALLBACK (enable_save), de);
+ g_signal_connect_swapped (de->dict, "variable-deleted",
+ G_CALLBACK (enable_save), de);
+ enable_save (de);
connect_action (de, "file_new_data", G_CALLBACK (create_data_window));
-
- connect_action (de, "file_import-text", G_CALLBACK (text_data_import_assistant));
-
+ 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, "analyze_frequencies", G_CALLBACK (frequencies_dialog));
- connect_action (de, "crosstabs", G_CALLBACK (crosstabs_dialog));
- connect_action (de, "univariate", G_CALLBACK (univariate_dialog));
- connect_action (de, "chi-square", G_CALLBACK (chisquare_dialog));
- connect_action (de, "binomial", G_CALLBACK (binomial_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 =
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;
}
G_OBJECT_CLASS (parent_class)->dispose (object);
}
+static void
+psppire_data_window_finalize (GObject *object)
+{
+ PsppireDataWindow *dw = PSPPIRE_DATA_WINDOW (object);
+
+ if (dw->dataset)
+ {
+ struct dataset *dataset = dw->dataset;
+ struct session *session = dataset_session (dataset);
+
+ dw->dataset = NULL;
+
+ dataset_set_callbacks (dataset, NULL, NULL);
+ session_set_active_dataset (session, NULL);
+ dataset_destroy (dataset);
+ }
+
+ if (G_OBJECT_CLASS (parent_class)->finalize)
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
static void
psppire_data_window_set_property (GObject *object,
guint prop_id,
GtkWidget *dw;
if (the_session == NULL)
- the_session = session_create ();
+ the_session = session_create (NULL);
if (ds == NULL)
{
- static int n_datasets;
- char *dataset_name;
-
- dataset_name = xasprintf ("DataSet%d", ++n_datasets);
+ char *dataset_name = session_generate_dataset_name (the_session);
ds = dataset_create (the_session, dataset_name);
free (dataset_name);
}
}
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;
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);
}