wmaker: remove useless null pointer check (Coverity #109612)
[wmaker-crm.git] / WPrefs.app / Expert.c
blob72680023bbbba0be61781ceee75c0d80646256db
1 /* Expert.c- expert user options
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 2014 Window Maker Team
6 * Copyright (c) 1998-2003 Alfredo K. Kojima
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "WPrefs.h"
25 /* This structure containts the list of all the check-buttons to display in the
26 * expert tab of the window with the corresponding information for effect
28 static const struct {
29 const char *label; /* Text displayed to user */
31 int def_state; /* True/False: the default value, if not defined in current config */
33 enum {
34 OPTION_WMAKER,
35 OPTION_WMAKER_ARRAY,
36 OPTION_USERDEF
37 } class;
39 const char *op_name; /* The identifier for the option in the config file */
41 } expert_options[] = {
43 { N_("Disable miniwindows (icons for minimized windows). For use with KDE/GNOME."),
44 /* default: */ False, OPTION_WMAKER, "DisableMiniwindows" },
46 { N_("Disable workspace pager."),
47 /* default: */ False, OPTION_WMAKER, "DisableWorkspacePager" },
49 { N_("Do not set non-WindowMaker specific parameters (do not use xset)."),
50 /* default: */ False, OPTION_USERDEF, "NoXSetStuff" },
52 { N_("Automatically save session when exiting Window Maker."),
53 /* default: */ False, OPTION_WMAKER, "SaveSessionOnExit" },
55 { N_("Use SaveUnder in window frames, icons, menus and other objects."),
56 /* default: */ False, OPTION_WMAKER, "UseSaveUnders" },
58 { N_("Disable confirmation panel for the Kill command."),
59 /* default: */ False, OPTION_WMAKER, "DontConfirmKill" },
61 { N_("Disable selection animation for selected icons."),
62 /* default: */ False, OPTION_WMAKER, "DisableBlinking" },
64 { N_("Smooth font edges (needs restart)."),
65 /* default: */ True, OPTION_WMAKER, "AntialiasedText" },
67 { N_("Cycle windows only on the active head."),
68 /* default: */ False, OPTION_WMAKER, "CycleActiveHeadOnly" },
70 { N_("Ignore minimized windows when cycling."),
71 /* default: */ False, OPTION_WMAKER, "CycleIgnoreMinimized" },
73 { N_("Show switch panel when cycling windows."),
74 /* default: */ True, OPTION_WMAKER_ARRAY, "SwitchPanelImages" },
76 { N_("Show workspace title on Clip."),
77 /* default: */ True, OPTION_WMAKER, "ShowClipTitle" },
79 { N_("Highlight the icon of the application when it has the focus."),
80 /* default: */ True, OPTION_WMAKER, "HighlightActiveApp" },
82 #ifdef XKB_MODELOCK
83 { N_("Enable keyboard language switch button in window titlebars."),
84 /* default: */ False, OPTION_WMAKER, "KbdModeLock" },
85 #endif /* XKB_MODELOCK */
87 { N_("Maximize a window to side or corner by dragging."),
88 /* default: */ False, OPTION_WMAKER, "WindowSnapping" },
90 { N_("Open dialogs in the same workspace as their owners."),
91 /* default: */ False, OPTION_WMAKER, "OpenTransientOnOwnerWorkspace" }
96 typedef struct _Panel {
97 WMBox *box;
98 char *sectionName;
100 char *description;
102 CallbackRec callbacks;
104 WMWidget *parent;
106 WMButton *swi[wlengthof_nocheck(expert_options)];
108 } _Panel;
110 #define ICON_FILE "expert"
113 static void createPanel(Panel *p)
115 _Panel *panel = (_Panel *) p;
116 WMScrollView *sv;
117 WMFrame *f;
118 WMUserDefaults *udb;
119 int i, state;
121 panel->box = WMCreateBox(panel->parent);
122 WMSetViewExpandsToParent(WMWidgetView(panel->box), 2, 2, 2, 2);
124 sv = WMCreateScrollView(panel->box);
125 WMResizeWidget(sv, 500, 215);
126 WMMoveWidget(sv, 12, 10);
127 WMSetScrollViewRelief(sv, WRSunken);
128 WMSetScrollViewHasVerticalScroller(sv, True);
129 WMSetScrollViewHasHorizontalScroller(sv, False);
131 f = WMCreateFrame(panel->box);
132 WMResizeWidget(f, 495, wlengthof(expert_options) * 25 + 8);
133 WMSetFrameRelief(f, WRFlat);
135 udb = WMGetStandardUserDefaults();
136 for (i = 0; i < wlengthof(expert_options); i++) {
137 panel->swi[i] = WMCreateSwitchButton(f);
138 WMResizeWidget(panel->swi[i], FRAME_WIDTH - 40, 25);
139 WMMoveWidget(panel->swi[i], 5, 5 + i * 25);
141 WMSetButtonText(panel->swi[i], _(expert_options[i].label));
143 switch (expert_options[i].class) {
144 case OPTION_WMAKER:
145 if (GetStringForKey(expert_options[i].op_name))
146 state = GetBoolForKey(expert_options[i].op_name);
147 else
148 state = expert_options[i].def_state;
149 break;
151 case OPTION_WMAKER_ARRAY: {
152 char *str = GetStringForKey(expert_options[i].op_name);
153 state = expert_options[i].def_state;
154 if (str && strcasecmp(str, "None") == 0)
155 state = False;
157 break;
159 case OPTION_USERDEF:
160 state = WMGetUDBoolForKey(udb, expert_options[i].op_name);
161 break;
163 default:
164 #ifdef DEBUG
165 wwarning("export_options[%d].class = %d, this should not happen\n",
166 i, expert_options[i].class);
167 #endif
168 state = expert_options[i].def_state;
169 break;
171 WMSetButtonSelected(panel->swi[i], state);
174 WMMapSubwidgets(panel->box);
175 WMSetScrollViewContentView(sv, WMWidgetView(f));
176 WMRealizeWidget(panel->box);
179 static void storeDefaults(_Panel *panel)
181 WMUserDefaults *udb = WMGetStandardUserDefaults();
182 int i;
184 for (i = 0; i < wlengthof(expert_options); i++) {
185 switch (expert_options[i].class) {
186 case OPTION_WMAKER:
187 SetBoolForKey(WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
188 break;
190 case OPTION_WMAKER_ARRAY:
191 if (WMGetButtonSelected(panel->swi[i])) {
192 /* check if the array was not manually modified */
193 char *str = GetStringForKey(expert_options[i].op_name);
194 if (str && strcasecmp(str, "None") == 0)
195 RemoveObjectForKey(expert_options[i].op_name);
197 else
198 SetStringForKey("None", expert_options[i].op_name);
199 break;
201 case OPTION_USERDEF:
202 WMSetUDBoolForKey(udb, WMGetButtonSelected(panel->swi[i]), expert_options[i].op_name);
203 break;
208 Panel *InitExpert(WMWidget *parent)
210 _Panel *panel;
212 panel = wmalloc(sizeof(_Panel));
214 panel->sectionName = _("Expert User Preferences");
216 panel->description = _("Options for people who know what they're doing...\n"
217 "Also has some other misc. options.");
219 panel->parent = parent;
221 panel->callbacks.createWidgets = createPanel;
222 panel->callbacks.updateDomain = storeDefaults;
224 AddSection(panel, ICON_FILE);
226 return panel;