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;
47 pspp_options_var_order_get_type (void)
49 static GType etype = 0;
50 if (G_UNLIKELY(etype == 0)) {
51 static const GEnumValue values[] =
53 { PSPP_OPTIONS_VAR_ORDER_UNSORTED, "PSPP_OPTIONS_VAR_ORDER_UNSORTED", "unsorted" },
54 { PSPP_OPTIONS_VAR_ORDER_NAME, "PSPP_OPTIONS_VAR_ORDER_NAME", "name" },
55 { PSPP_OPTIONS_VAR_ORDER_LABEL, "PSPP_OPTIONS_VAR_ORDER_LABEL", "label" },
58 etype = g_enum_register_static (g_intern_static_string ("PsppOptionsVarOrder"), values);
64 Pops up the Options dialog box
67 options_dialog (PsppireDataWindow *de)
69 struct options_dialog fd;
73 gboolean disp_labels = true;
75 fd.xml = builder_new ("options.ui");
77 dialog = get_widget_assert (fd.xml, "options-dialog");
79 fd.show_labels = get_widget_assert (fd.xml, "radiobutton-labels");
80 fd.show_names = get_widget_assert (fd.xml, "radiobutton-names");
82 fd.sort_labels = get_widget_assert (fd.xml, "radiobutton-sort-by-label");
83 fd.sort_names = get_widget_assert (fd.xml, "radiobutton-sort-by-name");
84 fd.sort_none = get_widget_assert (fd.xml, "radiobutton-unsorted");
86 gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
89 fd.conf = psppire_conf_new ();
91 if (psppire_conf_get_boolean (fd.conf,
92 "VariableLists", "display-labels", &disp_labels))
94 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_labels),
97 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_names),
103 psppire_conf_get_enum (fd.conf, "VariableLists", "sort-order",
104 PSPP_TYPE_OPTIONS_VAR_ORDER, &what);
109 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_none), true);
111 case PSPP_OPTIONS_VAR_ORDER_NAME:
112 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_names), true);
114 case PSPP_OPTIONS_VAR_ORDER_LABEL:
115 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_labels), true);
119 const int result = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
121 if (result == GTK_RESPONSE_OK)
123 PsppOptionsVarOrder sort_order = -1;
124 gboolean sl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.show_labels));
126 psppire_conf_set_boolean (fd.conf,
127 "VariableLists", "display-labels", sl);
129 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_labels)))
131 sort_order = PSPP_OPTIONS_VAR_ORDER_LABEL;
133 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_names)))
135 sort_order = PSPP_OPTIONS_VAR_ORDER_NAME;
137 else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_none)))
139 sort_order = PSPP_OPTIONS_VAR_ORDER_UNSORTED;
142 psppire_conf_set_enum (fd.conf,
143 "VariableLists", "sort-order",
144 PSPP_TYPE_OPTIONS_VAR_ORDER,
148 g_object_unref (fd.xml);