Change to the linux kernel coding style
[wmaker-crm.git] / WPrefs.app / WPrefs.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* WPrefs.c- main window and other basic stuff
6830b057 dan2004-10-12 21:28:27 +00002 *
9af1c6c4 dan1998-10-21 14:43:47 +00003 * WPrefs - Window Maker Preferences Program
6830b057 dan2004-10-12 21:28:27 +00004 *
4153e2fd dan2003-01-16 23:30:45 +00005 * Copyright (c) 1998-2003 Alfredo K. Kojima
6830b057 dan2004-10-12 21:28:27 +00006 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
6830b057 dan2004-10-12 21:28:27 +000019 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
9d2e6ef9 scottc1998-09-29 22:36:29 +000020 * USA.
21 */
22
9d2e6ef9 scottc1998-09-29 22:36:29 +000023#include "WPrefs.h"
24#include <assert.h>
25
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020026extern Panel *InitWindowHandling(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000027
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020028extern Panel *InitKeyboardSettings(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000029
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020030extern Panel *InitMouseSettings(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000031
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032extern Panel *InitKeyboardShortcuts(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000033
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034extern Panel *InitWorkspace(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000035
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020036extern Panel *InitFocus(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000037
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020038extern Panel *InitPreferences(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000039
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020040extern Panel *InitFont(WMScreen * scr, WMWidget * parent);
41extern Panel *InitFontSimple(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000042
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020043extern Panel *InitConfigurations(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000044
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020045extern Panel *InitPaths(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000046
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020047extern Panel *InitMenu(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000048
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020049extern Panel *InitExpert(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000050
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020051extern Panel *InitMenuPreferences(WMScreen * scr, WMWidget * parent);
0261c326 dan1999-01-06 15:22:33 +000052
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020053extern Panel *InitIcons(WMScreen * scr, WMWidget * parent);
0261c326 dan1999-01-06 15:22:33 +000054
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020055extern Panel *InitThemes(WMScreen * scr, WMWidget * parent);
9d2e6ef9 scottc1998-09-29 22:36:29 +000056
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020057extern Panel *InitAppearance(WMScreen * scr, WMWidget * parent);
f5177e67 kojima2000-03-28 02:48:32 +000058
d08691d5 dan2004-10-22 22:27:11 +000059#define ICON_TITLE_FONT "sans serif:pixelsize=9"
60#define ICON_TITLE_VFONT "sans serif:pixelsize=9:weight=100"
f5177e67 kojima2000-03-28 02:48:32 +000061
9d2e6ef9 scottc1998-09-29 22:36:29 +000062#define MAX_SECTIONS 16
63
6830b057 dan2004-10-12 21:28:27 +000064typedef struct _WPrefs {
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020065 WMWindow *win;
9d2e6ef9 scottc1998-09-29 22:36:29 +000066
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020067 WMScrollView *scrollV;
68 WMFrame *buttonF;
69 WMButton *sectionB[MAX_SECTIONS];
6830b057 dan2004-10-12 21:28:27 +000070
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020071 int sectionCount;
9d2e6ef9 scottc1998-09-29 22:36:29 +000072
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020073 WMButton *saveBtn;
74 WMButton *closeBtn;
75 WMButton *undoBtn;
76 WMButton *undosBtn;
d3609d34 kojima1999-04-25 21:43:50 +000077
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020078 WMButton *balloonBtn;
d3609d34 kojima1999-04-25 21:43:50 +000079
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020080 WMFrame *banner;
81 WMLabel *nameL;
82 WMLabel *versionL;
83 WMLabel *statusL;
6830b057 dan2004-10-12 21:28:27 +000084
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020085 Panel *currentPanel;
9d2e6ef9 scottc1998-09-29 22:36:29 +000086} _WPrefs;
87
9d2e6ef9 scottc1998-09-29 22:36:29 +000088static _WPrefs WPrefs;
89
90/* system wide defaults dictionary. Read-only */
33cc542e dan2001-10-04 03:07:34 +000091static WMPropList *GlobalDB = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +000092/* user defaults dictionary */
33cc542e dan2001-10-04 03:07:34 +000093static WMPropList *WindowMakerDB = NULL;
94static char *WindowMakerDBPath = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +000095
9d2e6ef9 scottc1998-09-29 22:36:29 +000096static Bool TIFFOK = False;
97
9d2e6ef9 scottc1998-09-29 22:36:29 +000098#define INITIALIZED_PANEL (1<<0)
99
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200100static void loadConfigurations(WMScreen * scr, WMWindow * mainw);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000101
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200102static void savePanelData(Panel * panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000103
ea55bc5e kojima1999-03-18 01:11:18 +0000104static void prepareForClose();
9d2e6ef9 scottc1998-09-29 22:36:29 +0000105
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200106void quit(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000107{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200108 prepareForClose();
ea55bc5e kojima1999-03-18 01:11:18 +0000109
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200110 exit(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000111}
112
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200113static void save(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000114{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200115 int i;
116 WMPropList *p1, *p2;
117 WMPropList *keyList;
118 WMPropList *key;
119 char *msg = "Reconfigure";
120 XEvent ev;
121
122 /* puts("gathering data"); */
123 for (i = 0; i < WPrefs.sectionCount; i++) {
124 PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
125 if ((rec->callbacks.flags & INITIALIZED_PANEL))
126 savePanelData((Panel *) rec);
127 }
128 /* puts("compressing data"); */
129 /* compare the user dictionary with the global and remove redundant data */
130 keyList = WMGetPLDictionaryKeys(GlobalDB);
131 /* puts(WMGetPropListDescription(WindowMakerDB, False)); */
132 for (i = 0; i < WMGetPropListItemCount(keyList); i++) {
133 key = WMGetFromPLArray(keyList, i);
134
135 /* We don't have this value anyway, so no problem.
136 * Probably a new option */
137 p1 = WMGetFromPLDictionary(WindowMakerDB, key);
138 if (!p1)
139 continue;
140 /* The global doesn't have it, so no problem either. */
141 p2 = WMGetFromPLDictionary(GlobalDB, key);
142 if (!p2)
143 continue;
144 /* If both values are the same, don't save. */
145 if (WMIsPropListEqualTo(p1, p2))
146 WMRemoveFromPLDictionary(WindowMakerDB, key);
147 }
148 /* puts(WMGetPropListDescription(WindowMakerDB, False)); */
149 WMReleasePropList(keyList);
150 /* puts("storing data"); */
151
152 WMWritePropListToFile(WindowMakerDB, WindowMakerDBPath, True);
153
154 memset(&ev, 0, sizeof(XEvent));
155
156 ev.xclient.type = ClientMessage;
157 ev.xclient.message_type = XInternAtom(WMScreenDisplay(WMWidgetScreen(w)), "_WINDOWMAKER_COMMAND", False);
158 ev.xclient.window = DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w)));
159 ev.xclient.format = 8;
160
161 for (i = 0; i <= strlen(msg); i++) {
162 ev.xclient.data.b[i] = msg[i];
163 }
164 XSendEvent(WMScreenDisplay(WMWidgetScreen(w)),
165 DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w))), False, SubstructureRedirectMask, &ev);
166 XFlush(WMScreenDisplay(WMWidgetScreen(w)));
9d2e6ef9 scottc1998-09-29 22:36:29 +0000167}
168
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200169static void undo(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000170{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200171 PanelRec *rec = (PanelRec *) WPrefs.currentPanel;
6830b057 dan2004-10-12 21:28:27 +0000172
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200173 if (!rec)
174 return;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000175
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200176 if (rec->callbacks.undoChanges && (rec->callbacks.flags & INITIALIZED_PANEL)) {
177 (*rec->callbacks.undoChanges) (WPrefs.currentPanel);
178 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000179}
180
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200181static void undoAll(WMWidget * w, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000182{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200183 int i;
6830b057 dan2004-10-12 21:28:27 +0000184
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200185 for (i = 0; i < WPrefs.sectionCount; i++) {
186 PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000187
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200188 if (rec->callbacks.undoChanges && (rec->callbacks.flags & INITIALIZED_PANEL))
189 (*rec->callbacks.undoChanges) ((Panel *) rec);
190 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000191}
192
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200193static void prepareForClose()
ea55bc5e kojima1999-03-18 01:11:18 +0000194{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200195 int i;
d3609d34 kojima1999-04-25 21:43:50 +0000196
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200197 for (i = 0; i < WPrefs.sectionCount; i++) {
198 PanelRec *rec = WMGetHangedData(WPrefs.sectionB[i]);
ea55bc5e kojima1999-03-18 01:11:18 +0000199
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200200 if (rec->callbacks.prepareForClose && (rec->callbacks.flags & INITIALIZED_PANEL))
201 (*rec->callbacks.prepareForClose) ((Panel *) rec);
202 }
ea55bc5e kojima1999-03-18 01:11:18 +0000203}
204
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200205void toggleBalloons(WMWidget * w, void *data)
d3609d34 kojima1999-04-25 21:43:50 +0000206{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200207 WMUserDefaults *udb = WMGetStandardUserDefaults();
208 Bool flag;
d3609d34 kojima1999-04-25 21:43:50 +0000209
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200210 flag = WMGetButtonSelected(WPrefs.balloonBtn);
d3609d34 kojima1999-04-25 21:43:50 +0000211
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200212 WMSetBalloonEnabled(WMWidgetScreen(WPrefs.win), flag);
d3609d34 kojima1999-04-25 21:43:50 +0000213
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200214 WMSetUDBoolForKey(udb, flag, "BalloonHelp");
d3609d34 kojima1999-04-25 21:43:50 +0000215}
216
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200217static void createMainWindow(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000218{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200219 WMScroller *scroller;
220 WMFont *font;
221 char buffer[128];
222
223 WPrefs.win = WMCreateWindow(scr, "wprefs");
224 WMResizeWidget(WPrefs.win, 520, 390);
225 WMSetWindowTitle(WPrefs.win, _("Window Maker Preferences"));
226 WMSetWindowCloseAction(WPrefs.win, quit, NULL);
227 WMSetWindowMaxSize(WPrefs.win, 520, 390);
228 WMSetWindowMinSize(WPrefs.win, 520, 390);
229 WMSetWindowMiniwindowTitle(WPrefs.win, "Preferences");
230
231 WPrefs.scrollV = WMCreateScrollView(WPrefs.win);
232 WMResizeWidget(WPrefs.scrollV, 500, 87);
233 WMMoveWidget(WPrefs.scrollV, 10, 10);
234 WMSetScrollViewRelief(WPrefs.scrollV, WRSunken);
235 WMSetScrollViewHasHorizontalScroller(WPrefs.scrollV, True);
236 WMSetScrollViewHasVerticalScroller(WPrefs.scrollV, False);
237 scroller = WMGetScrollViewHorizontalScroller(WPrefs.scrollV);
238 WMSetScrollerArrowsPosition(scroller, WSANone);
239
240 WPrefs.buttonF = WMCreateFrame(WPrefs.win);
241 WMSetFrameRelief(WPrefs.buttonF, WRFlat);
242
243 WMSetScrollViewContentView(WPrefs.scrollV, WMWidgetView(WPrefs.buttonF));
244
245 WPrefs.undosBtn = WMCreateCommandButton(WPrefs.win);
246 WMResizeWidget(WPrefs.undosBtn, 90, 28);
247 WMMoveWidget(WPrefs.undosBtn, 135, 350);
248 WMSetButtonText(WPrefs.undosBtn, _("Revert Page"));
249 WMSetButtonAction(WPrefs.undosBtn, undo, NULL);
250
251 WPrefs.undoBtn = WMCreateCommandButton(WPrefs.win);
252 WMResizeWidget(WPrefs.undoBtn, 90, 28);
253 WMMoveWidget(WPrefs.undoBtn, 235, 350);
254 WMSetButtonText(WPrefs.undoBtn, _("Revert All"));
255 WMSetButtonAction(WPrefs.undoBtn, undoAll, NULL);
256
257 WPrefs.saveBtn = WMCreateCommandButton(WPrefs.win);
258 WMResizeWidget(WPrefs.saveBtn, 80, 28);
259 WMMoveWidget(WPrefs.saveBtn, 335, 350);
260 WMSetButtonText(WPrefs.saveBtn, _("Save"));
261 WMSetButtonAction(WPrefs.saveBtn, save, NULL);
262
263 WPrefs.closeBtn = WMCreateCommandButton(WPrefs.win);
264 WMResizeWidget(WPrefs.closeBtn, 80, 28);
265 WMMoveWidget(WPrefs.closeBtn, 425, 350);
266 WMSetButtonText(WPrefs.closeBtn, _("Close"));
267 WMSetButtonAction(WPrefs.closeBtn, quit, NULL);
268
269 WPrefs.balloonBtn = WMCreateSwitchButton(WPrefs.win);
270 WMResizeWidget(WPrefs.balloonBtn, 200, 28);
271 WMMoveWidget(WPrefs.balloonBtn, 15, 350);
272 WMSetButtonText(WPrefs.balloonBtn, _("Balloon Help"));
273 WMSetButtonAction(WPrefs.balloonBtn, toggleBalloons, NULL);
274 {
275 WMUserDefaults *udb = WMGetStandardUserDefaults();
276 Bool flag = WMGetUDBoolForKey(udb, "BalloonHelp");
277
278 WMSetButtonSelected(WPrefs.balloonBtn, flag);
279 WMSetBalloonEnabled(scr, flag);
280 }
281
282 /* banner */
283 WPrefs.banner = WMCreateFrame(WPrefs.win);
284 WMResizeWidget(WPrefs.banner, FRAME_WIDTH, FRAME_HEIGHT);
285 WMMoveWidget(WPrefs.banner, FRAME_LEFT, FRAME_TOP);
286 WMSetFrameRelief(WPrefs.banner, WRFlat);
287
288 font = WMCreateFont(scr, "Lucida Sans,URW Gothic L,Times New Roman,serif"
289 ":bold:pixelsize=26:antialias=true");
290 WPrefs.nameL = WMCreateLabel(WPrefs.banner);
291 WMSetLabelTextAlignment(WPrefs.nameL, WACenter);
292 WMResizeWidget(WPrefs.nameL, FRAME_WIDTH - 20, 60);
293 WMMoveWidget(WPrefs.nameL, 10, 50);
294 WMSetLabelFont(WPrefs.nameL, font);
295 WMSetLabelText(WPrefs.nameL, _("Window Maker Preferences"));
296 WMReleaseFont(font);
297
298 WPrefs.versionL = WMCreateLabel(WPrefs.banner);
299 WMResizeWidget(WPrefs.versionL, FRAME_WIDTH - 20, 20);
300 WMMoveWidget(WPrefs.versionL, 10, 120);
301 WMSetLabelTextAlignment(WPrefs.versionL, WACenter);
302 sprintf(buffer, _("Version %s"), VERSION);
303 WMSetLabelText(WPrefs.versionL, buffer);
304
305 WPrefs.statusL = WMCreateLabel(WPrefs.banner);
306 WMResizeWidget(WPrefs.statusL, FRAME_WIDTH - 20, 60);
307 WMMoveWidget(WPrefs.statusL, 10, 150);
308 WMSetLabelTextAlignment(WPrefs.statusL, WACenter);
309 WMSetLabelText(WPrefs.statusL, _("Starting..."));
310
311 WMMapSubwidgets(WPrefs.win);
312
313 WMUnmapWidget(WPrefs.undosBtn);
314 WMUnmapWidget(WPrefs.undoBtn);
315 WMUnmapWidget(WPrefs.saveBtn);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000316}
317
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200318static void showPanel(Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000319{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200320 PanelRec *rec = (PanelRec *) panel;
6830b057 dan2004-10-12 21:28:27 +0000321
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200322 if (!(rec->callbacks.flags & INITIALIZED_PANEL)) {
323 (*rec->callbacks.createWidgets) (panel);
324 rec->callbacks.flags |= INITIALIZED_PANEL;
325 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000326
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200327 WMSetWindowTitle(WPrefs.win, rec->sectionName);
6830b057 dan2004-10-12 21:28:27 +0000328
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200329 if (rec->callbacks.showPanel)
330 (*rec->callbacks.showPanel) (panel);
6d5f1817 kojima2000-07-14 05:48:35 +0000331
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200332 WMMapWidget(rec->box);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000333}
334
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200335static void hidePanel(Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000336{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200337 PanelRec *rec = (PanelRec *) panel;
6830b057 dan2004-10-12 21:28:27 +0000338
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200339 WMUnmapWidget(rec->box);
6830b057 dan2004-10-12 21:28:27 +0000340
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200341 if (rec->callbacks.hidePanel)
342 (*rec->callbacks.hidePanel) (panel);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000343}
344
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200345static void savePanelData(Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000346{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200347 PanelRec *rec = (PanelRec *) panel;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000348
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200349 if (rec->callbacks.updateDomain) {
350 (*rec->callbacks.updateDomain) (panel);
351 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000352}
353
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200354static void changeSection(WMWidget * self, void *data)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000355{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200356 if (WPrefs.currentPanel == data)
357 return;
6830b057 dan2004-10-12 21:28:27 +0000358
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200359 if (WPrefs.currentPanel == NULL) {
360 WMDestroyWidget(WPrefs.nameL);
361 WMDestroyWidget(WPrefs.versionL);
362 WMDestroyWidget(WPrefs.statusL);
f91f2eb1 kojima2001-02-08 21:54:12 +0000363
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200364 WMSetFrameRelief(WPrefs.banner, WRGroove);
f91f2eb1 kojima2001-02-08 21:54:12 +0000365
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200366 /* WMMapWidget(WPrefs.undosBtn);
367 WMMapWidget(WPrefs.undoBtn);
368 */
369 WMMapWidget(WPrefs.saveBtn);
370 }
f91f2eb1 kojima2001-02-08 21:54:12 +0000371
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200372 showPanel(data);
f91f2eb1 kojima2001-02-08 21:54:12 +0000373
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200374 if (WPrefs.currentPanel)
375 hidePanel(WPrefs.currentPanel);
376 WPrefs.currentPanel = data;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000377}
378
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200379char *LocateImage(char *name)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000380{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200381 char *path;
382 char *tmp = wmalloc(strlen(name) + 8);
383
384 if (TIFFOK) {
385 sprintf(tmp, "%s.tiff", name);
386 path = WMPathForResourceOfType(tmp, "tiff");
387 } else {
388 sprintf(tmp, "%s.xpm", name);
389 path = WMPathForResourceOfType(tmp, "xpm");
390 }
391 wfree(tmp);
392 if (!path) {
393 wwarning(_("could not locate image file %s\n"), name);
394 }
395
396 return path;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000397}
398
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200399static WMPixmap *makeTitledIcon(WMScreen * scr, WMPixmap * icon, char *title1, char *title2)
f5177e67 kojima2000-03-28 02:48:32 +0000400{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200401 return WMRetainPixmap(icon);
6830b057 dan2004-10-12 21:28:27 +0000402
f5177e67 kojima2000-03-28 02:48:32 +0000403#if 0
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200404 static GC gc = NULL;
405 static XFontStruct *hfont = NULL;
406 static XFontStruct *vfont = NULL;
407 WMPixmap *tmp;
408 Pixmap pix, mask;
409 Display *dpy = WMScreenDisplay(scr);
410 WMColor *black = WMBlackColor(scr);
411 GC fgc;
412 WMSize size = WMGetPixmapSize(icon);
f5177e67 kojima2000-03-28 02:48:32 +0000413
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200414 tmp = WMCreatePixmap(scr, 60, 60, WMScreenDepth(scr), True);
f5177e67 kojima2000-03-28 02:48:32 +0000415
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200416 pix = WMGetPixmapXID(tmp);
417 mask = WMGetPixmapMaskXID(tmp);
f5177e67 kojima2000-03-28 02:48:32 +0000418
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200419 if (gc == NULL) {
420 gc = XCreateGC(dpy, mask, 0, NULL);
6830b057 dan2004-10-12 21:28:27 +0000421
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200422 hfont = XLoadQueryFont(dpy, ICON_TITLE_FONT);
423 vfont = XLoadQueryFont(dpy, ICON_TITLE_VFONT);
424 }
6830b057 dan2004-10-12 21:28:27 +0000425
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200426 if (hfont == NULL) {
427 return WMRetainPixmap(icon);
428 }
6830b057 dan2004-10-12 21:28:27 +0000429
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200430 XSetForeground(dpy, gc, 0);
431 XFillRectangle(dpy, mask, gc, 0, 0, 60, 60);
6830b057 dan2004-10-12 21:28:27 +0000432
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200433 fgc = WMColorGC(black);
6830b057 dan2004-10-12 21:28:27 +0000434
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200435 XSetForeground(dpy, gc, 1);
6830b057 dan2004-10-12 21:28:27 +0000436
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200437 XCopyArea(dpy, WMGetPixmapXID(icon), pix, fgc, 0, 0, size.width, size.height, 12, 12);
f5177e67 kojima2000-03-28 02:48:32 +0000438
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200439 if (WMGetPixmapMaskXID(icon) != None)
440 XCopyPlane(dpy, WMGetPixmapMaskXID(icon), mask, gc, 0, 0, size.width, size.height, 12, 12, 1);
441 else
442 XFillRectangle(dpy, mask, gc, 12, 12, 48, 48);
f5177e67 kojima2000-03-28 02:48:32 +0000443
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200444 if (title1) {
445 XSetFont(dpy, fgc, vfont->fid);
446 XSetFont(dpy, gc, vfont->fid);
6830b057 dan2004-10-12 21:28:27 +0000447
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200448 XDrawString(dpy, pix, fgc, 0, vfont->ascent, title1, strlen(title1));
6830b057 dan2004-10-12 21:28:27 +0000449
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200450 XDrawString(dpy, mask, gc, 0, vfont->ascent, title1, strlen(title1));
451 }
f5177e67 kojima2000-03-28 02:48:32 +0000452
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200453 if (title2) {
454 XSetFont(dpy, fgc, hfont->fid);
455 XSetFont(dpy, gc, hfont->fid);
6830b057 dan2004-10-12 21:28:27 +0000456
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200457 XDrawString(dpy, pix, fgc, (title1 ? 12 : 0), hfont->ascent, title2, strlen(title2));
6830b057 dan2004-10-12 21:28:27 +0000458
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200459 XDrawString(dpy, mask, gc, (title1 ? 12 : 0), hfont->ascent, title2, strlen(title2));
460 }
f5177e67 kojima2000-03-28 02:48:32 +0000461
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200462 return tmp;
f5177e67 kojima2000-03-28 02:48:32 +0000463#endif
464}
465
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200466void SetButtonAlphaImage(WMScreen * scr, WMButton * bPtr, char *file, char *title1, char *title2)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000467{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200468 WMPixmap *icon;
469 WMPixmap *icon2;
470 RColor color;
471 char *iconPath;
472
473 iconPath = LocateImage(file);
474
475 color.red = 0xae;
476 color.green = 0xaa;
477 color.blue = 0xae;
478 color.alpha = 0;
479 if (iconPath) {
480 icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color);
481 if (!icon)
482 wwarning(_("could not load icon file %s"), iconPath);
483 } else {
484 icon = NULL;
485 }
486
487 if (icon) {
488 icon2 = makeTitledIcon(scr, icon, title1, title2);
489 if (icon)
490 WMReleasePixmap(icon);
491 } else {
492 icon2 = NULL;
493 }
494
495 WMSetButtonImage(bPtr, icon2);
496
497 if (icon2)
498 WMReleasePixmap(icon2);
499
500 color.red = 0xff;
501 color.green = 0xff;
502 color.blue = 0xff;
503 color.alpha = 0;
504 if (iconPath) {
505 icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color);
506 if (!icon)
507 wwarning(_("could not load icon file %s"), iconPath);
508 } else {
509 icon = NULL;
510 }
511
512 WMSetButtonAltImage(bPtr, icon);
513
514 if (icon)
515 WMReleasePixmap(icon);
516
517 if (iconPath)
518 wfree(iconPath);
088c0ac2 dan1999-03-09 14:58:01 +0000519}
520
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200521void AddSection(Panel * panel, char *iconFile)
088c0ac2 dan1999-03-09 14:58:01 +0000522{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200523 WMButton *bPtr;
6830b057 dan2004-10-12 21:28:27 +0000524
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200525 assert(WPrefs.sectionCount < MAX_SECTIONS);
088c0ac2 dan1999-03-09 14:58:01 +0000526
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200527 bPtr = WMCreateCustomButton(WPrefs.buttonF, WBBStateLightMask | WBBStateChangeMask);
528 WMResizeWidget(bPtr, 64, 64);
529 WMMoveWidget(bPtr, WPrefs.sectionCount * 64, 0);
530 WMSetButtonImagePosition(bPtr, WIPImageOnly);
531 WMSetButtonAction(bPtr, changeSection, panel);
532 WMHangData(bPtr, panel);
088c0ac2 dan1999-03-09 14:58:01 +0000533
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200534 WMSetBalloonTextForView(((PanelRec *) panel)->description, WMWidgetView(bPtr));
d3f29988 kojima1999-04-25 01:49:46 +0000535
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200536 {
537 char *t1, *t2;
6830b057 dan2004-10-12 21:28:27 +0000538
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200539 t1 = wstrdup(((PanelRec *) panel)->sectionName);
540 t2 = strchr(t1, ' ');
541 if (t2) {
542 *t2 = 0;
543 t2++;
544 }
545 SetButtonAlphaImage(WMWidgetScreen(bPtr), bPtr, iconFile, t1, t2);
546 wfree(t1);
547 }
548 WMMapWidget(bPtr);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000549
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200550 WPrefs.sectionB[WPrefs.sectionCount] = bPtr;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000551
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200552 if (WPrefs.sectionCount > 0) {
553 WMGroupButtons(WPrefs.sectionB[0], bPtr);
554 }
d3f29988 kojima1999-04-25 01:49:46 +0000555
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200556 WPrefs.sectionCount++;
d3f29988 kojima1999-04-25 01:49:46 +0000557
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200558 WMResizeWidget(WPrefs.buttonF, WPrefs.sectionCount * 64, 64);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000559}
560
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200561void Initialize(WMScreen * scr)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000562{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200563 char **list;
564 int i;
565 char *path;
566
567 list = RSupportedFileFormats();
568 for (i = 0; list[i] != NULL; i++) {
569 if (strcmp(list[i], "TIFF") == 0) {
570 TIFFOK = True;
571 break;
572 }
573 }
574
575 if (TIFFOK)
576 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
577 else
578 path = WMPathForResourceOfType("WPrefs.xpm", NULL);
579 if (path) {
580 RImage *tmp;
581
582 tmp = RLoadImage(WMScreenRContext(scr), path, 0);
583 if (!tmp) {
584 wwarning(_("could not load image file %s:%s"), path, RMessageForError(RErrorCode));
585 } else {
586 WMSetApplicationIconImage(scr, tmp);
587 RReleaseImage(tmp);
588 }
589 wfree(path);
590 }
591
592 memset(&WPrefs, 0, sizeof(_WPrefs));
593 createMainWindow(scr);
594
595 WMRealizeWidget(WPrefs.win);
596
597 WMSetWindowMiniwindowImage(WPrefs.win, WMGetApplicationIconImage(scr));
598
599 WMMapWidget(WPrefs.win);
600 XFlush(WMScreenDisplay(scr));
601 WMSetLabelText(WPrefs.statusL, _("Loading Window Maker configuration files..."));
602 XFlush(WMScreenDisplay(scr));
603 loadConfigurations(scr, WPrefs.win);
604
605 WMSetLabelText(WPrefs.statusL, _("Initializing configuration panels..."));
606
607 InitFocus(scr, WPrefs.banner);
608 InitWindowHandling(scr, WPrefs.banner);
609
610 InitMenuPreferences(scr, WPrefs.banner);
611 InitIcons(scr, WPrefs.banner);
612 InitPreferences(scr, WPrefs.banner);
613
614 InitPaths(scr, WPrefs.banner);
615 InitWorkspace(scr, WPrefs.banner);
616 InitConfigurations(scr, WPrefs.banner);
617
618 InitMenu(scr, WPrefs.banner);
088c0ac2 dan1999-03-09 14:58:01 +0000619
9d2e6ef9 scottc1998-09-29 22:36:29 +0000620#ifdef not_yet_fully_implemented
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200621 InitKeyboardSettings(scr, WPrefs.banner);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000622#endif
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200623 InitKeyboardShortcuts(scr, WPrefs.banner);
624 InitMouseSettings(scr, WPrefs.banner);
c56756dc dan1999-03-14 22:35:50 +0000625
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200626 InitAppearance(scr, WPrefs.banner);
a2b404b5 dan2002-10-08 08:26:06 +0000627
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200628 InitFontSimple(scr, WPrefs.banner);
a2b404b5 dan2002-10-08 08:26:06 +0000629
a1e552d9 kojima1999-11-05 23:23:48 +0000630#ifdef not_yet_fully_implemented
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200631 InitThemes(scr, WPrefs.banner);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000632#endif
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200633 InitExpert(scr, WPrefs.banner);
088c0ac2 dan1999-03-09 14:58:01 +0000634
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200635 WMRealizeWidget(WPrefs.scrollV);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000636
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200637 WMSetLabelText(WPrefs.statusL, "");
9d2e6ef9 scottc1998-09-29 22:36:29 +0000638}
639
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200640WMWindow *GetWindow(Panel * panel)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000641{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200642 return WPrefs.win;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000643}
644
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200645static void loadConfigurations(WMScreen * scr, WMWindow * mainw)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000646{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200647 WMPropList *db, *gdb;
648 char *path;
649 FILE *file;
650 char buffer[1024];
651 char mbuf[1024];
652 int v1, v2, v3;
653
654 path = wdefaultspathfordomain("WindowMaker");
655 WindowMakerDBPath = path;
656
657 db = WMReadPropListFromFile(path);
658 if (db) {
659 if (!WMIsPLDictionary(db)) {
660 WMReleasePropList(db);
661 db = NULL;
662 sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), path);
663 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
664 }
665 } else {
666 sprintf(mbuf, _("Could not load Window Maker domain (%s) from defaults database."), path);
667 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
668 }
669
670 path = getenv("WMAKER_BIN_NAME");
671 if (!path)
672 path = "wmaker";
673 {
674 char *command;
675
676 command = wstrconcat(path, " --version");
677 file = popen(command, "r");
678 wfree(command);
679 }
680 if (!file || !fgets(buffer, 1023, file)) {
681 wsyserror(_("could not extract version information from Window Maker"));
682 wfatal(_("Make sure wmaker is in your search path."));
683
684 WMRunAlertPanel(scr, mainw, _("Error"),
685 _
686 ("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."),
687 _("OK"), NULL, NULL);
688 exit(1);
689 }
690 if (file)
691 pclose(file);
692
693 if (sscanf(buffer, "Window Maker %i.%i.%i", &v1, &v2, &v3) != 3
694 && sscanf(buffer, "WindowMaker %i.%i.%i", &v1, &v2, &v3) != 3) {
695 WMRunAlertPanel(scr, mainw, _("Error"),
696 _("Could not extract version from Window Maker. "
697 "Make sure it is correctly installed and the path "
698 "where it installed is in the PATH environment "
699 "variable."), _("OK"), NULL, NULL);
700 exit(1);
701 }
702 if (v1 == 0 && (v2 < 18 || v3 < 0)) {
703 sprintf(mbuf, _("WPrefs only supports Window Maker 0.18.0 or newer.\n"
704 "The version installed is %i.%i.%i\n"), v1, v2, v3);
705 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
706 exit(1);
707
708 }
709 if (v1 > 1 || (v1 == 1 && (v2 > 0))) {
710 sprintf(mbuf,
711 _
712 ("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."),
713 v1, v2, v3);
714 WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL);
715 }
716
717 {
718 char *command;
719
720 command = wstrconcat(path, " --global_defaults_path");
721 file = popen(command, "r");
722 wfree(command);
723 }
724 if (!file || !fgets(buffer, 1023, file)) {
725 wsyserror(_("could not run \"%s --global_defaults_path\"."), path);
726 exit(1);
727 } else {
728 char *ptr;
729 ptr = strchr(buffer, '\n');
730 if (ptr)
731 *ptr = 0;
732 strcat(buffer, "/WindowMaker");
733 }
734
735 if (file)
736 pclose(file);
737
738 gdb = WMReadPropListFromFile(buffer);
739
740 if (gdb) {
741 if (!WMIsPLDictionary(gdb)) {
742 WMReleasePropList(gdb);
743 gdb = NULL;
744 sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), buffer);
745 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
746 }
747 } else {
748 sprintf(mbuf, _("Could not load global Window Maker domain (%s)."), buffer);
749 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
750 }
751
752 if (!db) {
753 db = WMCreatePLDictionary(NULL, NULL);
754 }
755 if (!gdb) {
756 gdb = WMCreatePLDictionary(NULL, NULL);
757 }
758
759 GlobalDB = gdb;
760
761 WindowMakerDB = db;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000762}
763
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200764WMPropList *GetObjectForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000765{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200766 WMPropList *object = NULL;
767 WMPropList *key = WMCreatePLString(defaultName);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000768
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200769 object = WMGetFromPLDictionary(WindowMakerDB, key);
770 if (!object)
771 object = WMGetFromPLDictionary(GlobalDB, key);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000772
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200773 WMReleasePropList(key);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000774
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200775 return object;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000776}
777
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200778void SetObjectForKey(WMPropList * object, char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000779{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200780 WMPropList *key = WMCreatePLString(defaultName);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000781
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200782 WMPutInPLDictionary(WindowMakerDB, key, object);
783 WMReleasePropList(key);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000784}
785
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200786void RemoveObjectForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000787{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200788 WMPropList *key = WMCreatePLString(defaultName);
6830b057 dan2004-10-12 21:28:27 +0000789
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200790 WMRemoveFromPLDictionary(WindowMakerDB, key);
6830b057 dan2004-10-12 21:28:27 +0000791
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200792 WMReleasePropList(key);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000793}
794
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200795char *GetStringForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000796{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200797 WMPropList *val;
6830b057 dan2004-10-12 21:28:27 +0000798
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200799 val = GetObjectForKey(defaultName);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000800
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200801 if (!val)
802 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000803
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200804 if (!WMIsPLString(val))
805 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000806
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200807 return WMGetFromPLString(val);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000808}
809
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200810WMPropList *GetArrayForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000811{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200812 WMPropList *val;
6830b057 dan2004-10-12 21:28:27 +0000813
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200814 val = GetObjectForKey(defaultName);
6830b057 dan2004-10-12 21:28:27 +0000815
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200816 if (!val)
817 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000818
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200819 if (!WMIsPLArray(val))
820 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000821
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200822 return val;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000823}
824
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200825WMPropList *GetDictionaryForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000826{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200827 WMPropList *val;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000828
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200829 val = GetObjectForKey(defaultName);
6830b057 dan2004-10-12 21:28:27 +0000830
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200831 if (!val)
832 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000833
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200834 if (!WMIsPLDictionary(val))
835 return NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000836
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200837 return val;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000838}
839
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200840int GetIntegerForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000841{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200842 WMPropList *val;
843 char *str;
844 int value;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000845
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200846 val = GetObjectForKey(defaultName);
6830b057 dan2004-10-12 21:28:27 +0000847
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200848 if (!val)
849 return 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000850
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200851 if (!WMIsPLString(val))
852 return 0;
6830b057 dan2004-10-12 21:28:27 +0000853
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200854 str = WMGetFromPLString(val);
855 if (!str)
856 return 0;
6830b057 dan2004-10-12 21:28:27 +0000857
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200858 if (sscanf(str, "%i", &value) != 1)
859 return 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000860
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200861 return value;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000862}
863
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200864Bool GetBoolForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000865{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200866 int value;
867 char *str;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000868
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200869 str = GetStringForKey(defaultName);
6830b057 dan2004-10-12 21:28:27 +0000870
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200871 if (!str)
872 return False;
6830b057 dan2004-10-12 21:28:27 +0000873
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200874 if (sscanf(str, "%i", &value) == 1 && value != 0)
875 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000876
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200877 if (strcasecmp(str, "YES") == 0)
878 return True;
6830b057 dan2004-10-12 21:28:27 +0000879
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200880 if (strcasecmp(str, "Y") == 0)
881 return True;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000882
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200883 return False;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000884}
885
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200886void SetIntegerForKey(int value, char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000887{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200888 WMPropList *object;
889 char buffer[128];
9d2e6ef9 scottc1998-09-29 22:36:29 +0000890
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200891 sprintf(buffer, "%i", value);
892 object = WMCreatePLString(buffer);
6830b057 dan2004-10-12 21:28:27 +0000893
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200894 SetObjectForKey(object, defaultName);
895 WMReleasePropList(object);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000896}
897
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200898void SetStringForKey(char *value, char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000899{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200900 WMPropList *object;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000901
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200902 object = WMCreatePLString(value);
6830b057 dan2004-10-12 21:28:27 +0000903
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200904 SetObjectForKey(object, defaultName);
905 WMReleasePropList(object);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000906}
907
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200908void SetBoolForKey(Bool value, char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000909{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200910 static WMPropList *yes = NULL, *no = NULL;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000911
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200912 if (!yes) {
913 yes = WMCreatePLString("YES");
914 no = WMCreatePLString("NO");
915 }
9d2e6ef9 scottc1998-09-29 22:36:29 +0000916
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200917 SetObjectForKey(value ? yes : no, defaultName);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000918}
919
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200920void SetSpeedForKey(int speed, char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000921{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200922 char *str;
923
924 switch (speed) {
925 case 0:
926 str = "ultraslow";
927 break;
928 case 1:
929 str = "slow";
930 break;
931 case 2:
932 str = "medium";
933 break;
934 case 3:
935 str = "fast";
936 break;
937 case 4:
938 str = "ultrafast";
939 break;
940 default:
941 str = NULL;
942 }
943
944 if (str)
945 SetStringForKey(str, defaultName);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000946}
947
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +0200948int GetSpeedForKey(char *defaultName)
9d2e6ef9 scottc1998-09-29 22:36:29 +0000949{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +0200950 char *str;
951 int i;
952
953 str = GetStringForKey(defaultName);
954 if (!str)
955 return 2;
956
957 if (strcasecmp(str, "ultraslow") == 0)
958 i = 0;
959 else if (strcasecmp(str, "slow") == 0)
960 i = 1;
961 else if (strcasecmp(str, "medium") == 0)
962 i = 2;
963 else if (strcasecmp(str, "fast") == 0)
964 i = 3;
965 else if (strcasecmp(str, "ultrafast") == 0)
966 i = 4;
967 else {
968 wwarning(_("bad speed value for option %s\n. Using default Medium"), defaultName);
969 i = 2;
970 }
971 return i;
9d2e6ef9 scottc1998-09-29 22:36:29 +0000972}