Converted reliability dialog to a PsppireDialogAction object
[pspp-builds.git] / src / ui / gui / psppire-dialog-action-reliability.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2012  Free Software Foundation
3
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.
8
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.
13
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/>. */
16
17
18 #include <config.h>
19
20 #include "psppire-dialog-action-reliability.h"
21
22 #include "psppire-var-view.h"
23
24 #include "psppire-dialog.h"
25 #include "builder-wrapper.h"
26
27 static void psppire_dialog_action_reliability_init            (PsppireDialogActionReliability      *act);
28 static void psppire_dialog_action_reliability_class_init      (PsppireDialogActionReliabilityClass *class);
29
30 G_DEFINE_TYPE (PsppireDialogActionReliability, psppire_dialog_action_reliability, PSPPIRE_TYPE_DIALOG_ACTION);
31
32 static char *
33 generate_syntax (PsppireDialogAction *act)
34 {
35   PsppireDialogActionReliability *rd = PSPPIRE_DIALOG_ACTION_RELIABILITY (act);
36   gchar *text;
37   GString *string = g_string_new ("RELIABILITY");
38
39   g_string_append (string, "\n\t/VARIABLES=");
40   psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->variables), 0, string);
41
42
43   g_string_append (string, "\n\t/MODEL=");
44
45   if ( 0 == gtk_combo_box_get_active (GTK_COMBO_BOX (rd->model_combo)))
46     g_string_append (string, "ALPHA");
47   else
48     g_string_append_printf (string, "SPLIT (%d)",
49                             gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (rd->split_spinbutton))
50                             );
51
52   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (rd->scale_if_item_deleted_checkbutton)))
53     g_string_append (string, "\n\t/SUMMARY = TOTAL");
54
55   g_string_append (string, ".\n");
56
57   text = string->str;
58
59   g_string_free (string, FALSE);
60
61   return text;
62 }
63
64
65 static gboolean
66 dialog_state_valid (gpointer user_data)
67 {
68   PsppireDialogActionReliability *pda = user_data;
69   GtkTreeModel *liststore =
70     gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables));
71
72   return (2 <= gtk_tree_model_iter_n_children (liststore, NULL));
73 }
74
75 static void
76 on_method_change (PsppireDialogActionReliability *pda)
77 {
78   gtk_widget_set_sensitive (pda->split_point_hbox,
79                             ( 1 == gtk_combo_box_get_active (GTK_COMBO_BOX (pda->model_combo))));
80 }
81
82
83 static void
84 refresh (PsppireDialogActionReliability *pda)
85 {
86   GtkTreeModel *liststore =
87     gtk_tree_view_get_model (GTK_TREE_VIEW (pda->variables));
88   gtk_list_store_clear (GTK_LIST_STORE (liststore));
89
90   gtk_combo_box_set_active (GTK_COMBO_BOX (pda->model_combo), 0);
91
92   gtk_spin_button_set_value (GTK_SPIN_BUTTON (pda->split_spinbutton), 0);
93
94   gtk_spin_button_set_range (GTK_SPIN_BUTTON (pda->split_spinbutton),
95                              0, 0);
96
97   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (pda->scale_if_item_deleted_checkbutton),
98                                 FALSE);
99 }
100
101 static void
102 psppire_dialog_action_reliability_activate (GtkAction *a)
103 {
104   PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a);
105   PsppireDialogActionReliability *act = PSPPIRE_DIALOG_ACTION_RELIABILITY (a);
106
107   GtkBuilder *xml = builder_new ("reliability.ui");
108   pda->dialog = get_widget_assert   (xml, "reliability-dialog");
109   pda->source = get_widget_assert   (xml, "dict-view");
110
111   act->variables = get_widget_assert   (xml, "treeview2");
112
113   act->split_point_hbox = get_widget_assert (xml, "split-point-hbox");
114
115   act->variables = get_widget_assert   (xml, "treeview2");
116
117   act->model_combo = get_widget_assert   (xml, "combobox1");
118   act->split_spinbutton = get_widget_assert (xml, "spinbutton1");
119
120   act->scale_if_item_deleted_checkbutton = get_widget_assert (xml, "totals-checkbutton");
121
122   g_signal_connect_swapped (act->model_combo, "changed",
123                             G_CALLBACK (on_method_change), pda);
124
125   psppire_dialog_action_set_refresh (pda, refresh);
126   psppire_dialog_action_set_valid_predicate (pda, dialog_state_valid);
127
128   if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_reliability_parent_class)->activate)
129     PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_reliability_parent_class)->activate (pda);
130 }
131
132 static void
133 psppire_dialog_action_reliability_class_init (PsppireDialogActionReliabilityClass *class)
134 {
135   GtkActionClass *action_class = GTK_ACTION_CLASS (class);
136   PsppireDialogActionClass *pdac = PSPPIRE_DIALOG_ACTION_CLASS (class);
137
138   action_class->activate = psppire_dialog_action_reliability_activate;
139
140   pdac->generate_syntax = generate_syntax;
141 }
142
143
144 static void
145 psppire_dialog_action_reliability_init (PsppireDialogActionReliability *act)
146 {
147 }
148