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"
34 #define _(msgid) gettext (msgid)
35 #define N_(msgid) msgid
41 GtkWidget *model_combo;
43 GtkWidget *split_point_hbox;
44 GtkWidget *split_spinbutton;
48 static char * generate_syntax (const struct reliability *rd);
52 on_vars_changed (struct reliability *rd)
55 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
57 gint n_vars = gtk_tree_model_iter_n_children (tm, NULL);
60 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton));
62 gint new_value = current_value;
64 gtk_spin_button_set_range (GTK_SPIN_BUTTON (rd->split_spinbutton),
67 if ( current_value > n_vars - 1)
68 new_value = n_vars - 1;
70 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rd->split_spinbutton),
75 on_method_change (struct reliability *rd)
77 gtk_widget_set_sensitive (rd->split_point_hbox,
78 ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo))));
83 refresh (PsppireDialog *dialog, struct reliability *rd)
85 GtkTreeModel *liststore =
86 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
87 gtk_list_store_clear (GTK_LIST_STORE (liststore));
89 gtk_combo_box_set_active (GTK_COMBO_BOX (rd->model_combo), 0);
91 gtk_spin_button_set_value (GTK_SPIN_BUTTON (rd->split_spinbutton), 0);
93 gtk_spin_button_set_range (GTK_SPIN_BUTTON (rd->split_spinbutton),
99 dialog_state_valid (gpointer data)
101 struct reliability *rd = data;
103 GtkTreeModel *liststore =
104 gtk_tree_view_get_model (GTK_TREE_VIEW (rd->variables));
106 return (2 <= gtk_tree_model_iter_n_children (liststore, NULL));
110 /* Pops up the Reliability dialog box */
112 reliability_dialog (GObject *o, gpointer data)
114 struct reliability rd;
117 GtkBuilder *xml = builder_new ("reliability.ui");
118 PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data);
121 GtkWidget *dialog = get_widget_assert (xml, "reliability-dialog");
122 GtkWidget *source = get_widget_assert (xml, "dict-view");
124 GtkWidget *selector = get_widget_assert (xml, "psppire-selector1");
126 rd.split_point_hbox = get_widget_assert (xml, "split-point-hbox");
128 rd.variables = get_widget_assert (xml, "treeview2");
130 rd.model_combo = get_widget_assert (xml, "combobox1");
131 rd.split_spinbutton = get_widget_assert (xml, "spinbutton1");
133 g_signal_connect_swapped (rd.model_combo, "changed",
134 G_CALLBACK (on_method_change), &rd);
136 g_object_get (de->data_editor, "var-store", &vs, NULL);
138 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
140 g_object_set (source, "dictionary", vs->dict, NULL);
144 set_dest_model (GTK_TREE_VIEW (rd.variables), vs->dict);
146 psppire_selector_set_subjects (PSPPIRE_SELECTOR (selector),
149 insert_source_row_into_tree_view,
155 gtk_tree_view_get_model (GTK_TREE_VIEW (rd.variables));
158 g_signal_connect_swapped (tm, "row-inserted",
159 G_CALLBACK (on_vars_changed), &rd);
161 g_signal_connect_swapped (tm, "row-deleted",
162 G_CALLBACK (on_vars_changed), &rd);
165 g_signal_connect (dialog, "refresh", G_CALLBACK (refresh), &rd);
167 psppire_dialog_set_valid_predicate (PSPPIRE_DIALOG (dialog),
168 dialog_state_valid, &rd);
170 response = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
175 case GTK_RESPONSE_OK:
177 gchar *syntax = generate_syntax (&rd);
179 struct getl_interface *sss = create_syntax_string_source (syntax);
180 execute_syntax (sss);
185 case PSPPIRE_RESPONSE_PASTE:
187 gchar *syntax = generate_syntax (&rd);
188 paste_syntax_in_new_window (syntax);
197 g_object_unref (xml);
204 generate_syntax (const struct reliability *rd)
207 GString *string = g_string_new ("RELIABILITY");
209 g_string_append (string, "\n\t/VARIABLES=");
210 append_variable_names (string, rd->dict, GTK_TREE_VIEW (rd->variables), 0);
213 g_string_append (string, "\n\t/MODEL=");
215 if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
216 g_string_append (string, "ALPHA");
218 g_string_append_printf (string, "SPLIT (%d)",
219 gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton))
222 g_string_append (string, ".\n");
226 g_string_free (string, FALSE);