1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2017 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 "options-dialog.h"
21 #include "ui/gui/helper.h"
22 #include "ui/gui/psppire-conf.h"
23 #include "ui/gui/builder-wrapper.h"
24 #include "ui/gui/psppire-data-window.h"
25 #include "ui/gui/psppire-dialog.h"
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
37 GtkWidget *show_labels;
38 GtkWidget *show_names;
41 GtkWidget *sort_names;
42 GtkWidget *sort_labels;
51 pspp_options_var_order_get_type (void)
53 static GType etype = 0;
54 if (G_UNLIKELY(etype == 0)) {
55 static const GEnumValue values[] =
57 { PSPP_OPTIONS_VAR_ORDER_UNSORTED, "PSPP_OPTIONS_VAR_ORDER_UNSORTED", "unsorted" },
58 { PSPP_OPTIONS_VAR_ORDER_NAME, "PSPP_OPTIONS_VAR_ORDER_NAME", "name" },
59 { PSPP_OPTIONS_VAR_ORDER_LABEL, "PSPP_OPTIONS_VAR_ORDER_LABEL", "label" },
62 etype = g_enum_register_static (g_intern_static_string ("PsppOptionsVarOrder"), values);
68 Pops up the Options dialog box
71 options_dialog (PsppireDataWindow *de)
73 struct options_dialog fd;
77 gboolean disp_labels = true;
79 fd.xml = builder_new ("options.ui");
81 dialog = get_widget_assert (fd.xml, "options-dialog");
83 fd.show_labels = get_widget_assert (fd.xml, "radiobutton-labels");
84 fd.show_names = get_widget_assert (fd.xml, "radiobutton-names");
86 fd.sort_labels = get_widget_assert (fd.xml, "radiobutton-sort-by-label");
87 fd.sort_names = get_widget_assert (fd.xml, "radiobutton-sort-by-name");
88 fd.sort_none = get_widget_assert (fd.xml, "radiobutton-unsorted");
90 fd.maximize = get_widget_assert (fd.xml, "checkbutton-maximize");
91 fd.alert = get_widget_assert (fd.xml, "checkbutton-alert");
92 fd.raise = get_widget_assert (fd.xml, "checkbutton-raise");
94 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
96 fd.conf = psppire_conf_new ();
98 if (psppire_conf_get_boolean (fd.conf,
99 "VariableLists", "display-labels", &disp_labels))
101 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_labels),
104 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_names),
110 psppire_conf_get_enum (fd.conf, "VariableLists", "sort-order",
111 PSPP_TYPE_OPTIONS_VAR_ORDER, &what);
116 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_none), true);
118 case PSPP_OPTIONS_VAR_ORDER_NAME:
119 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_names), true);
121 case PSPP_OPTIONS_VAR_ORDER_LABEL:
122 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_labels), true);
128 if (psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "maximize",
130 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.maximize), status);
134 gboolean status = true;
135 psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "alert", &status);
136 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.alert), status);
141 if (psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "raise",
143 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.raise), status);
146 const int result = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
148 if (result == GTK_RESPONSE_OK)
150 PsppOptionsVarOrder sort_order = -1;
151 gboolean sl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.show_labels));
153 psppire_conf_set_boolean (fd.conf,
154 "VariableLists", "display-labels", sl);
156 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_labels)))
158 sort_order = PSPP_OPTIONS_VAR_ORDER_LABEL;
160 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_names)))
162 sort_order = PSPP_OPTIONS_VAR_ORDER_NAME;
164 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_none)))
166 sort_order = PSPP_OPTIONS_VAR_ORDER_UNSORTED;
169 psppire_conf_set_enum (fd.conf,
170 "VariableLists", "sort-order",
171 PSPP_TYPE_OPTIONS_VAR_ORDER,
174 psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "maximize",
175 gtk_toggle_button_get_active
176 (GTK_TOGGLE_BUTTON (fd.maximize)));
178 psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "raise",
179 gtk_toggle_button_get_active
180 (GTK_TOGGLE_BUTTON (fd.raise)));
182 psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "alert",
183 gtk_toggle_button_get_active
184 (GTK_TOGGLE_BUTTON (fd.alert)));
187 g_object_unref (fd.xml);