1 /* PSPPIRE - a graphical user interface for PSPP.
2 Copyright (C) 2017, 2021 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;
53 pspp_options_var_order_get_type (void)
55 static GType etype = 0;
56 if (G_UNLIKELY(etype == 0)) {
57 static const GEnumValue values[] =
59 { PSPP_OPTIONS_VAR_ORDER_UNSORTED, "PSPP_OPTIONS_VAR_ORDER_UNSORTED", "unsorted" },
60 { PSPP_OPTIONS_VAR_ORDER_NAME, "PSPP_OPTIONS_VAR_ORDER_NAME", "name" },
61 { PSPP_OPTIONS_VAR_ORDER_LABEL, "PSPP_OPTIONS_VAR_ORDER_LABEL", "label" },
64 etype = g_enum_register_static (g_intern_static_string ("PsppOptionsVarOrder"), values);
70 Pops up the Options dialog box
73 options_dialog (PsppireDataWindow *de)
75 struct options_dialog fd;
79 gboolean disp_labels = true;
80 gboolean show_tips = true;
82 fd.xml = builder_new ("options.ui");
84 dialog = get_widget_assert (fd.xml, "options-dialog");
86 fd.show_tips = get_widget_assert (fd.xml, "checkbutton-show-tips");
88 fd.show_labels = get_widget_assert (fd.xml, "radiobutton-labels");
89 fd.show_names = get_widget_assert (fd.xml, "radiobutton-names");
91 fd.sort_labels = get_widget_assert (fd.xml, "radiobutton-sort-by-label");
92 fd.sort_names = get_widget_assert (fd.xml, "radiobutton-sort-by-name");
93 fd.sort_none = get_widget_assert (fd.xml, "radiobutton-unsorted");
95 fd.maximize = get_widget_assert (fd.xml, "checkbutton-maximize");
96 fd.alert = get_widget_assert (fd.xml, "checkbutton-alert");
97 fd.raise = get_widget_assert (fd.xml, "checkbutton-raise");
99 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
101 fd.conf = psppire_conf_new ();
103 if (psppire_conf_get_boolean (fd.conf,
104 "VariableLists", "display-labels", &disp_labels))
106 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_labels),
109 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_names),
113 if (psppire_conf_get_boolean (fd.conf,
114 "startup", "show-user-tips", &show_tips))
116 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_tips),
122 psppire_conf_get_enum (fd.conf, "VariableLists", "sort-order",
123 PSPP_TYPE_OPTIONS_VAR_ORDER, &what);
128 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_none), true);
130 case PSPP_OPTIONS_VAR_ORDER_NAME:
131 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_names), true);
133 case PSPP_OPTIONS_VAR_ORDER_LABEL:
134 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_labels), true);
140 if (psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "maximize",
142 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.maximize), status);
146 gboolean status = true;
147 psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "alert", &status);
148 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.alert), status);
153 if (psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "raise",
155 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.raise), status);
158 const int result = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
160 if (result == GTK_RESPONSE_OK)
162 PsppOptionsVarOrder sort_order = -1;
163 gboolean sl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.show_labels));
165 psppire_conf_set_boolean (fd.conf,
166 "VariableLists", "display-labels", sl);
168 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_labels)))
170 sort_order = PSPP_OPTIONS_VAR_ORDER_LABEL;
172 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_names)))
174 sort_order = PSPP_OPTIONS_VAR_ORDER_NAME;
176 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_none)))
178 sort_order = PSPP_OPTIONS_VAR_ORDER_UNSORTED;
181 psppire_conf_set_enum (fd.conf,
182 "VariableLists", "sort-order",
183 PSPP_TYPE_OPTIONS_VAR_ORDER,
186 psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "maximize",
187 gtk_toggle_button_get_active
188 (GTK_TOGGLE_BUTTON (fd.maximize)));
190 psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "raise",
191 gtk_toggle_button_get_active
192 (GTK_TOGGLE_BUTTON (fd.raise)));
194 psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "alert",
195 gtk_toggle_button_get_active
196 (GTK_TOGGLE_BUTTON (fd.alert)));
198 psppire_conf_set_boolean (fd.conf, "startup", "show-user-tips",
199 gtk_toggle_button_get_active
200 (GTK_TOGGLE_BUTTON (fd.show_tips)));
203 g_object_unref (fd.xml);