Options dialog: add checkbox for startup tips
[pspp] / src / ui / gui / options-dialog.c
1 /* PSPPIRE - a graphical user interface for PSPP.
2    Copyright (C) 2017, 2021 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 #include <config.h>
18
19 #include "options-dialog.h"
20
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"
26
27 #include <gtk/gtk.h>
28
29 #include <gettext.h>
30 #define _(msgid) gettext (msgid)
31 #define N_(msgid) msgid
32
33
34 struct options_dialog
35 {
36   GtkBuilder *xml;
37   GtkWidget *show_labels;
38   GtkWidget *show_names;
39   PsppireConf *conf;
40
41   GtkWidget *sort_names;
42   GtkWidget *sort_labels;
43   GtkWidget *sort_none;
44
45   GtkWidget *maximize;
46   GtkWidget *alert;
47   GtkWidget *raise;
48
49   GtkWidget *show_tips;
50 };
51
52 GType
53 pspp_options_var_order_get_type (void)
54 {
55   static GType etype = 0;
56   if (G_UNLIKELY(etype == 0)) {
57     static const GEnumValue values[] =
58       {
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" },
62         { 0, NULL, NULL }
63       };
64     etype = g_enum_register_static (g_intern_static_string ("PsppOptionsVarOrder"), values);
65   }
66   return etype;
67 }
68
69 /*
70    Pops up the Options dialog box
71  */
72 void
73 options_dialog (PsppireDataWindow *de)
74 {
75   struct options_dialog fd;
76
77   GtkWidget *dialog ;
78
79   gboolean disp_labels = true;
80   gboolean show_tips = true;
81
82   fd.xml = builder_new ("options.ui");
83
84   dialog = get_widget_assert (fd.xml, "options-dialog");
85
86   fd.show_tips = get_widget_assert (fd.xml, "checkbutton-show-tips");
87
88   fd.show_labels = get_widget_assert (fd.xml, "radiobutton-labels");
89   fd.show_names  = get_widget_assert (fd.xml, "radiobutton-names");
90
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");
94
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");
98
99   gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (de));
100
101   fd.conf = psppire_conf_new ();
102
103   if (psppire_conf_get_boolean (fd.conf,
104                                 "VariableLists", "display-labels", &disp_labels))
105     {
106       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_labels),
107                                     disp_labels);
108
109       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_names),
110                                     !disp_labels);
111     }
112
113   if (psppire_conf_get_boolean (fd.conf,
114                                 "startup", "show-user-tips", &show_tips))
115     {
116       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.show_tips),
117                                     show_tips);
118     }
119
120
121   int what = -1;
122   psppire_conf_get_enum (fd.conf, "VariableLists", "sort-order",
123                          PSPP_TYPE_OPTIONS_VAR_ORDER, &what);
124
125   switch (what)
126     {
127     default:
128       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_none), true);
129       break;
130     case PSPP_OPTIONS_VAR_ORDER_NAME:
131       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_names), true);
132       break;
133     case PSPP_OPTIONS_VAR_ORDER_LABEL:
134       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.sort_labels), true);
135       break;
136     }
137
138   {
139     gboolean status;
140     if (psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "maximize",
141                                   &status))
142       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.maximize), status);
143   }
144
145   {
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);
149   }
150
151   {
152     gboolean status;
153     if (psppire_conf_get_boolean (fd.conf, "OutputWindowAction", "raise",
154                                   &status))
155       gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (fd.raise), status);
156   }
157
158   const int result = psppire_dialog_run (PSPPIRE_DIALOG (dialog));
159
160   if (result == GTK_RESPONSE_OK)
161     {
162       PsppOptionsVarOrder sort_order = -1;
163       gboolean sl = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.show_labels));
164
165       psppire_conf_set_boolean (fd.conf,
166                                 "VariableLists", "display-labels", sl);
167
168       if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_labels)))
169         {
170           sort_order = PSPP_OPTIONS_VAR_ORDER_LABEL;
171         }
172       else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_names)))
173         {
174           sort_order = PSPP_OPTIONS_VAR_ORDER_NAME;
175         }
176       else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (fd.sort_none)))
177         {
178           sort_order = PSPP_OPTIONS_VAR_ORDER_UNSORTED;
179         }
180
181       psppire_conf_set_enum (fd.conf,
182                              "VariableLists", "sort-order",
183                              PSPP_TYPE_OPTIONS_VAR_ORDER,
184                              sort_order);
185
186       psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "maximize",
187                                 gtk_toggle_button_get_active
188                                 (GTK_TOGGLE_BUTTON (fd.maximize)));
189
190       psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "raise",
191                                 gtk_toggle_button_get_active
192                                 (GTK_TOGGLE_BUTTON (fd.raise)));
193
194       psppire_conf_set_boolean (fd.conf, "OutputWindowAction", "alert",
195                                 gtk_toggle_button_get_active
196                                 (GTK_TOGGLE_BUTTON (fd.alert)));
197
198       psppire_conf_set_boolean (fd.conf, "startup", "show-user-tips",
199                                 gtk_toggle_button_get_active
200                                 (GTK_TOGGLE_BUTTON (fd.show_tips)));
201     }
202
203   g_object_unref (fd.xml);
204 }