1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2009 Free Software Foundation
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include "dialog-common.h"
20 #include <language/syntax-string-source.h>
21 #include "reliability-dialog.h"
22 #include "psppire-selector.h"
23 #include "psppire-dictview.h"
24 #include "psppire-dialog.h"
26 #include "psppire-data-window.h"
33 #define _(msgid) gettext (msgid)
34 #define N_(msgid) msgid
40 GtkWidget *model_combo;
42 GtkWidget *split_point_hbox;
43 GtkWidget *split_spinbutton;
47 static char * generate_syntax (const struct reliability *rd);
51 on_vars_changed (struct reliability *rd)
54 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
56 gint n_vars = gtk_tree_model_iter_n_children (tm, NULL);
59 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton));
61 gint new_value = current_value;
63 gtk_spin_button_set_range (GTK_SPIN_BUTTON (rd->split_spinbutton),
66 if ( current_value > n_vars - 1)
67 new_value = n_vars - 1;
69 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rd->split_spinbutton),
74 on_method_change (struct reliability *rd)
76 gtk_widget_set_sensitive (rd->split_point_hbox,
77 ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo))));
82 refresh (PsppireDialog *dialog, struct reliability *rd)
84 GtkTreeModel *liststore =
85 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
86 gtk_list_store_clear (GTK_LIST_STORE (liststore));
88 gtk_combo_box_set_active (GTK_COMBO_BOX (rd->model_combo), 0);
90 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rd->split_spinbutton), 0);
92 gtk_spin_button_set_range (GTK_SPIN_BUTTON (rd->split_spinbutton),
98 dialog_state_valid (gpointer data)
100 struct reliability *rd = data;
102 GtkTreeModel *liststore =
103 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
105 return (2 <= gtk_tree_model_iter_n_children (liststore, NULL));
109 /* Pops up the Reliability dialog box */
111 reliability_dialog (GObject *o, gpointer data)
113 struct reliability rd;
116 GtkBuilder *xml = builder_new ("reliability.ui");
117 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
120 GtkWidget *dialog = get_widget_assert (xml, "reliability-dialog");
121 GtkWidget *source = get_widget_assert (xml, "dict-view");
123 GtkWidget *selector = get_widget_assert (xml, "psppire-selector1");
125 rd.split_point_hbox = get_widget_assert (xml, "split-point-hbox");
127 rd.variables = get_widget_assert (xml, "treeview2");
129 rd.model_combo = get_widget_assert (xml, "combobox1");
130 rd.split_spinbutton = get_widget_assert (xml, "spinbutton1");
132 g_signal_connect_swapped (rd.model_combo, "changed",
133 G_CALLBACK (on_method_change), &rd);
135 g_object_get (de->data_editor, "var-store", &vs, NULL);
137 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
139 g_object_set (source, "dictionary", vs->dict, NULL);
143 set_dest_model (GTK_TREE_VIEW (rd.variables), vs->dict);
145 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
148 insert_source_row_into_tree_view,
154 gtk_tree_view_get_model (GTK_TREE_VIEW (rd.variables));
157 g_signal_connect_swapped (tm, "row-inserted",
158 G_CALLBACK (on_vars_changed), &rd);
160 g_signal_connect_swapped (tm, "row-deleted",
161 G_CALLBACK (on_vars_changed), &rd);
164 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &rd);
166 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
167 dialog_state_valid, &rd);
169 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
174 case GTK_RESPONSE_OK:
176 gchar *syntax = generate_syntax (&rd);
178 struct getl_interface *sss = create_syntax_string_source (syntax);
179 execute_syntax (sss);
184 case PSPPIRE_RESPONSE_PASTE:
186 gchar *syntax = generate_syntax (&rd);
187 paste_syntax_in_new_window (syntax);
196 g_object_unref (xml);
203 generate_syntax (const struct reliability *rd)
206 GString *string = g_string_new ("RELIABILITY");
208 g_string_append (string, "\n\t/VARIABLES=");
209 append_variable_names (string, rd->dict, GTK_TREE_VIEW (rd->variables), 0);
212 g_string_append (string, "\n\t/MODEL=");
214 if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
215 g_string_append (string, "ALPHA");
217 g_string_append_printf (string, "SPLIT (%d)",
218 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton))
221 g_string_append (string, ".\n");
225 g_string_free (string, FALSE);