1 /* WPrefs.c- main window and other basic stuff
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2003 Alfredo K. Kojima
7 * 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.
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.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 extern Panel
*InitWindowHandling(WMScreen
* scr
, WMWidget
* parent
);
27 extern Panel
*InitKeyboardSettings(WMScreen
* scr
, WMWidget
* parent
);
29 extern Panel
*InitMouseSettings(WMScreen
* scr
, WMWidget
* parent
);
31 extern Panel
*InitKeyboardShortcuts(WMScreen
* scr
, WMWidget
* parent
);
33 extern Panel
*InitWorkspace(WMScreen
* scr
, WMWidget
* parent
);
35 extern Panel
*InitFocus(WMScreen
* scr
, WMWidget
* parent
);
37 extern Panel
*InitPreferences(WMScreen
* scr
, WMWidget
* parent
);
39 extern Panel
*InitFont(WMScreen
* scr
, WMWidget
* parent
);
40 extern Panel
*InitFontSimple(WMScreen
* scr
, WMWidget
* parent
);
42 extern Panel
*InitConfigurations(WMScreen
* scr
, WMWidget
* parent
);
44 extern Panel
*InitPaths(WMScreen
* scr
, WMWidget
* parent
);
46 extern Panel
*InitMenu(WMScreen
* scr
, WMWidget
* parent
);
48 extern Panel
*InitExpert(WMScreen
* scr
, WMWidget
* parent
);
50 extern Panel
*InitMenuPreferences(WMScreen
* scr
, WMWidget
* parent
);
52 extern Panel
*InitIcons(WMScreen
* scr
, WMWidget
* parent
);
54 extern Panel
*InitThemes(WMScreen
* scr
, WMWidget
* parent
);
56 extern Panel
*InitAppearance(WMScreen
* scr
, WMWidget
* parent
);
58 #define ICON_TITLE_FONT "sans serif:pixelsize=9"
59 #define ICON_TITLE_VFONT "sans serif:pixelsize=9:weight=100"
61 #define MAX_SECTIONS 16
63 typedef struct _WPrefs
{
66 WMScrollView
*scrollV
;
68 WMButton
*sectionB
[MAX_SECTIONS
];
87 static _WPrefs WPrefs
;
89 /* system wide defaults dictionary. Read-only */
90 static WMPropList
*GlobalDB
= NULL
;
91 /* user defaults dictionary */
92 static WMPropList
*WindowMakerDB
= NULL
;
93 static char *WindowMakerDBPath
= NULL
;
95 static Bool TIFFOK
= False
;
97 #define INITIALIZED_PANEL (1<<0)
99 static void loadConfigurations(WMScreen
* scr
, WMWindow
* mainw
);
101 static void savePanelData(Panel
* panel
);
103 static void prepareForClose();
105 void quit(WMWidget
* w
, void *data
)
112 static void save(WMWidget
* w
, void *data
)
120 /* puts("gathering data"); */
121 for (i
= 0; i
< WPrefs
.sectionCount
; i
++) {
122 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
123 if ((rec
->callbacks
.flags
& INITIALIZED_PANEL
))
124 savePanelData((Panel
*) rec
);
126 /* puts("compressing data"); */
127 /* compare the user dictionary with the global and remove redundant data */
128 keyList
= WMGetPLDictionaryKeys(GlobalDB
);
129 /* puts(WMGetPropListDescription(WindowMakerDB, False)); */
130 for (i
= 0; i
< WMGetPropListItemCount(keyList
); i
++) {
131 key
= WMGetFromPLArray(keyList
, i
);
133 /* We don't have this value anyway, so no problem.
134 * Probably a new option */
135 p1
= WMGetFromPLDictionary(WindowMakerDB
, key
);
138 /* The global doesn't have it, so no problem either. */
139 p2
= WMGetFromPLDictionary(GlobalDB
, key
);
142 /* If both values are the same, don't save. */
143 if (WMIsPropListEqualTo(p1
, p2
))
144 WMRemoveFromPLDictionary(WindowMakerDB
, key
);
146 /* puts(WMGetPropListDescription(WindowMakerDB, False)); */
147 WMReleasePropList(keyList
);
148 /* puts("storing data"); */
150 WMWritePropListToFile(WindowMakerDB
, WindowMakerDBPath
);
152 memset(&ev
, 0, sizeof(XEvent
));
154 ev
.xclient
.type
= ClientMessage
;
155 ev
.xclient
.message_type
= XInternAtom(WMScreenDisplay(WMWidgetScreen(w
)), "_WINDOWMAKER_COMMAND", False
);
156 ev
.xclient
.window
= DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
)));
157 ev
.xclient
.format
= 8;
158 strncpy(ev
.xclient
.data
.b
, "Reconfigure", sizeof(ev
.xclient
.data
.b
));
160 XSendEvent(WMScreenDisplay(WMWidgetScreen(w
)),
161 DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
))), False
, SubstructureRedirectMask
, &ev
);
162 XFlush(WMScreenDisplay(WMWidgetScreen(w
)));
165 static void undo(WMWidget
* w
, void *data
)
167 PanelRec
*rec
= (PanelRec
*) WPrefs
.currentPanel
;
172 if (rec
->callbacks
.undoChanges
&& (rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
173 (*rec
->callbacks
.undoChanges
) (WPrefs
.currentPanel
);
177 static void undoAll(WMWidget
* w
, void *data
)
181 for (i
= 0; i
< WPrefs
.sectionCount
; i
++) {
182 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
184 if (rec
->callbacks
.undoChanges
&& (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
185 (*rec
->callbacks
.undoChanges
) ((Panel
*) rec
);
189 static void prepareForClose()
193 for (i
= 0; i
< WPrefs
.sectionCount
; i
++) {
194 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
196 if (rec
->callbacks
.prepareForClose
&& (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
197 (*rec
->callbacks
.prepareForClose
) ((Panel
*) rec
);
201 void toggleBalloons(WMWidget
* w
, void *data
)
203 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
206 flag
= WMGetButtonSelected(WPrefs
.balloonBtn
);
208 WMSetBalloonEnabled(WMWidgetScreen(WPrefs
.win
), flag
);
210 WMSetUDBoolForKey(udb
, flag
, "BalloonHelp");
213 static void createMainWindow(WMScreen
* scr
)
215 WMScroller
*scroller
;
219 WPrefs
.win
= WMCreateWindow(scr
, "wprefs");
220 WMResizeWidget(WPrefs
.win
, 520, 390);
221 WMSetWindowTitle(WPrefs
.win
, _("Window Maker Preferences"));
222 WMSetWindowCloseAction(WPrefs
.win
, quit
, NULL
);
223 WMSetWindowMaxSize(WPrefs
.win
, 520, 390);
224 WMSetWindowMinSize(WPrefs
.win
, 520, 390);
225 WMSetWindowMiniwindowTitle(WPrefs
.win
, "Preferences");
227 WPrefs
.scrollV
= WMCreateScrollView(WPrefs
.win
);
228 WMResizeWidget(WPrefs
.scrollV
, 500, 87);
229 WMMoveWidget(WPrefs
.scrollV
, 10, 10);
230 WMSetScrollViewRelief(WPrefs
.scrollV
, WRSunken
);
231 WMSetScrollViewHasHorizontalScroller(WPrefs
.scrollV
, True
);
232 WMSetScrollViewHasVerticalScroller(WPrefs
.scrollV
, False
);
233 scroller
= WMGetScrollViewHorizontalScroller(WPrefs
.scrollV
);
234 WMSetScrollerArrowsPosition(scroller
, WSANone
);
236 WPrefs
.buttonF
= WMCreateFrame(WPrefs
.win
);
237 WMSetFrameRelief(WPrefs
.buttonF
, WRFlat
);
239 WMSetScrollViewContentView(WPrefs
.scrollV
, WMWidgetView(WPrefs
.buttonF
));
241 WPrefs
.undosBtn
= WMCreateCommandButton(WPrefs
.win
);
242 WMResizeWidget(WPrefs
.undosBtn
, 90, 28);
243 WMMoveWidget(WPrefs
.undosBtn
, 135, 350);
244 WMSetButtonText(WPrefs
.undosBtn
, _("Revert Page"));
245 WMSetButtonAction(WPrefs
.undosBtn
, undo
, NULL
);
247 WPrefs
.undoBtn
= WMCreateCommandButton(WPrefs
.win
);
248 WMResizeWidget(WPrefs
.undoBtn
, 90, 28);
249 WMMoveWidget(WPrefs
.undoBtn
, 235, 350);
250 WMSetButtonText(WPrefs
.undoBtn
, _("Revert All"));
251 WMSetButtonAction(WPrefs
.undoBtn
, undoAll
, NULL
);
253 WPrefs
.saveBtn
= WMCreateCommandButton(WPrefs
.win
);
254 WMResizeWidget(WPrefs
.saveBtn
, 80, 28);
255 WMMoveWidget(WPrefs
.saveBtn
, 335, 350);
256 WMSetButtonText(WPrefs
.saveBtn
, _("Save"));
257 WMSetButtonAction(WPrefs
.saveBtn
, save
, NULL
);
259 WPrefs
.closeBtn
= WMCreateCommandButton(WPrefs
.win
);
260 WMResizeWidget(WPrefs
.closeBtn
, 80, 28);
261 WMMoveWidget(WPrefs
.closeBtn
, 425, 350);
262 WMSetButtonText(WPrefs
.closeBtn
, _("Close"));
263 WMSetButtonAction(WPrefs
.closeBtn
, quit
, NULL
);
265 WPrefs
.balloonBtn
= WMCreateSwitchButton(WPrefs
.win
);
266 WMResizeWidget(WPrefs
.balloonBtn
, 200, 28);
267 WMMoveWidget(WPrefs
.balloonBtn
, 15, 350);
268 WMSetButtonText(WPrefs
.balloonBtn
, _("Balloon Help"));
269 WMSetButtonAction(WPrefs
.balloonBtn
, toggleBalloons
, NULL
);
271 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
272 Bool flag
= WMGetUDBoolForKey(udb
, "BalloonHelp");
274 WMSetButtonSelected(WPrefs
.balloonBtn
, flag
);
275 WMSetBalloonEnabled(scr
, flag
);
279 WPrefs
.banner
= WMCreateFrame(WPrefs
.win
);
280 WMResizeWidget(WPrefs
.banner
, FRAME_WIDTH
, FRAME_HEIGHT
);
281 WMMoveWidget(WPrefs
.banner
, FRAME_LEFT
, FRAME_TOP
);
282 WMSetFrameRelief(WPrefs
.banner
, WRFlat
);
284 font
= WMCreateFont(scr
, "Lucida Sans,URW Gothic L,Times New Roman,serif"
285 ":bold:pixelsize=26:antialias=true");
286 WPrefs
.nameL
= WMCreateLabel(WPrefs
.banner
);
287 WMSetLabelTextAlignment(WPrefs
.nameL
, WACenter
);
288 WMResizeWidget(WPrefs
.nameL
, FRAME_WIDTH
- 20, 60);
289 WMMoveWidget(WPrefs
.nameL
, 10, 50);
290 WMSetLabelFont(WPrefs
.nameL
, font
);
291 WMSetLabelText(WPrefs
.nameL
, _("Window Maker Preferences"));
294 WPrefs
.versionL
= WMCreateLabel(WPrefs
.banner
);
295 WMResizeWidget(WPrefs
.versionL
, FRAME_WIDTH
- 20, 20);
296 WMMoveWidget(WPrefs
.versionL
, 10, 120);
297 WMSetLabelTextAlignment(WPrefs
.versionL
, WACenter
);
298 sprintf(buffer
, _("Version %s"), VERSION
);
299 WMSetLabelText(WPrefs
.versionL
, buffer
);
301 WPrefs
.statusL
= WMCreateLabel(WPrefs
.banner
);
302 WMResizeWidget(WPrefs
.statusL
, FRAME_WIDTH
- 20, 60);
303 WMMoveWidget(WPrefs
.statusL
, 10, 150);
304 WMSetLabelTextAlignment(WPrefs
.statusL
, WACenter
);
305 WMSetLabelText(WPrefs
.statusL
, _("Starting..."));
307 WMMapSubwidgets(WPrefs
.win
);
309 WMUnmapWidget(WPrefs
.undosBtn
);
310 WMUnmapWidget(WPrefs
.undoBtn
);
311 WMUnmapWidget(WPrefs
.saveBtn
);
314 static void showPanel(Panel
* panel
)
316 PanelRec
*rec
= (PanelRec
*) panel
;
318 if (!(rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
319 (*rec
->callbacks
.createWidgets
) (panel
);
320 rec
->callbacks
.flags
|= INITIALIZED_PANEL
;
323 WMSetWindowTitle(WPrefs
.win
, rec
->sectionName
);
325 if (rec
->callbacks
.showPanel
)
326 (*rec
->callbacks
.showPanel
) (panel
);
328 WMMapWidget(rec
->box
);
331 static void hidePanel(Panel
* panel
)
333 PanelRec
*rec
= (PanelRec
*) panel
;
335 WMUnmapWidget(rec
->box
);
337 if (rec
->callbacks
.hidePanel
)
338 (*rec
->callbacks
.hidePanel
) (panel
);
341 static void savePanelData(Panel
* panel
)
343 PanelRec
*rec
= (PanelRec
*) panel
;
345 if (rec
->callbacks
.updateDomain
) {
346 (*rec
->callbacks
.updateDomain
) (panel
);
350 static void changeSection(WMWidget
* self
, void *data
)
352 if (WPrefs
.currentPanel
== data
)
355 if (WPrefs
.currentPanel
== NULL
) {
356 WMDestroyWidget(WPrefs
.nameL
);
357 WMDestroyWidget(WPrefs
.versionL
);
358 WMDestroyWidget(WPrefs
.statusL
);
360 WMSetFrameRelief(WPrefs
.banner
, WRGroove
);
362 /* WMMapWidget(WPrefs.undosBtn);
363 WMMapWidget(WPrefs.undoBtn);
365 WMMapWidget(WPrefs
.saveBtn
);
370 if (WPrefs
.currentPanel
)
371 hidePanel(WPrefs
.currentPanel
);
372 WPrefs
.currentPanel
= data
;
375 char *LocateImage(char *name
)
378 char *tmp
= wmalloc(strlen(name
) + 8);
381 sprintf(tmp
, "%s.tiff", name
);
382 path
= WMPathForResourceOfType(tmp
, "tiff");
384 sprintf(tmp
, "%s.xpm", name
);
385 path
= WMPathForResourceOfType(tmp
, "xpm");
389 wwarning(_("could not locate image file %s"), name
);
395 static WMPixmap
*makeTitledIcon(WMScreen
* scr
, WMPixmap
* icon
, char *title1
, char *title2
)
397 return WMRetainPixmap(icon
);
401 static XFontStruct
*hfont
= NULL
;
402 static XFontStruct
*vfont
= NULL
;
405 Display
*dpy
= WMScreenDisplay(scr
);
406 WMColor
*black
= WMBlackColor(scr
);
408 WMSize size
= WMGetPixmapSize(icon
);
410 tmp
= WMCreatePixmap(scr
, 60, 60, WMScreenDepth(scr
), True
);
412 pix
= WMGetPixmapXID(tmp
);
413 mask
= WMGetPixmapMaskXID(tmp
);
416 gc
= XCreateGC(dpy
, mask
, 0, NULL
);
418 hfont
= XLoadQueryFont(dpy
, ICON_TITLE_FONT
);
419 vfont
= XLoadQueryFont(dpy
, ICON_TITLE_VFONT
);
423 return WMRetainPixmap(icon
);
426 XSetForeground(dpy
, gc
, 0);
427 XFillRectangle(dpy
, mask
, gc
, 0, 0, 60, 60);
429 fgc
= WMColorGC(black
);
431 XSetForeground(dpy
, gc
, 1);
433 XCopyArea(dpy
, WMGetPixmapXID(icon
), pix
, fgc
, 0, 0, size
.width
, size
.height
, 12, 12);
435 if (WMGetPixmapMaskXID(icon
) != None
)
436 XCopyPlane(dpy
, WMGetPixmapMaskXID(icon
), mask
, gc
, 0, 0, size
.width
, size
.height
, 12, 12, 1);
438 XFillRectangle(dpy
, mask
, gc
, 12, 12, 48, 48);
441 XSetFont(dpy
, fgc
, vfont
->fid
);
442 XSetFont(dpy
, gc
, vfont
->fid
);
444 XDrawString(dpy
, pix
, fgc
, 0, vfont
->ascent
, title1
, strlen(title1
));
446 XDrawString(dpy
, mask
, gc
, 0, vfont
->ascent
, title1
, strlen(title1
));
450 XSetFont(dpy
, fgc
, hfont
->fid
);
451 XSetFont(dpy
, gc
, hfont
->fid
);
453 XDrawString(dpy
, pix
, fgc
, (title1
? 12 : 0), hfont
->ascent
, title2
, strlen(title2
));
455 XDrawString(dpy
, mask
, gc
, (title1
? 12 : 0), hfont
->ascent
, title2
, strlen(title2
));
462 void SetButtonAlphaImage(WMScreen
* scr
, WMButton
* bPtr
, char *file
, char *title1
, char *title2
)
469 iconPath
= LocateImage(file
);
476 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
478 wwarning(_("could not load icon file %s"), iconPath
);
484 icon2
= makeTitledIcon(scr
, icon
, title1
, title2
);
486 WMReleasePixmap(icon
);
491 WMSetButtonImage(bPtr
, icon2
);
494 WMReleasePixmap(icon2
);
501 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
503 wwarning(_("could not load icon file %s"), iconPath
);
508 WMSetButtonAltImage(bPtr
, icon
);
511 WMReleasePixmap(icon
);
517 void AddSection(Panel
* panel
, char *iconFile
)
521 assert(WPrefs
.sectionCount
< MAX_SECTIONS
);
523 bPtr
= WMCreateCustomButton(WPrefs
.buttonF
, WBBStateLightMask
| WBBStateChangeMask
);
524 WMResizeWidget(bPtr
, 64, 64);
525 WMMoveWidget(bPtr
, WPrefs
.sectionCount
* 64, 0);
526 WMSetButtonImagePosition(bPtr
, WIPImageOnly
);
527 WMSetButtonAction(bPtr
, changeSection
, panel
);
528 WMHangData(bPtr
, panel
);
530 WMSetBalloonTextForView(((PanelRec
*) panel
)->description
, WMWidgetView(bPtr
));
535 t1
= wstrdup(((PanelRec
*) panel
)->sectionName
);
536 t2
= strchr(t1
, ' ');
541 SetButtonAlphaImage(WMWidgetScreen(bPtr
), bPtr
, iconFile
, t1
, t2
);
546 WPrefs
.sectionB
[WPrefs
.sectionCount
] = bPtr
;
548 if (WPrefs
.sectionCount
> 0) {
549 WMGroupButtons(WPrefs
.sectionB
[0], bPtr
);
552 WPrefs
.sectionCount
++;
554 WMResizeWidget(WPrefs
.buttonF
, WPrefs
.sectionCount
* 64, 64);
557 void Initialize(WMScreen
* scr
)
563 list
= RSupportedFileFormats();
564 for (i
= 0; list
[i
] != NULL
; i
++) {
565 if (strcmp(list
[i
], "TIFF") == 0) {
572 path
= WMPathForResourceOfType("WPrefs.tiff", NULL
);
574 path
= WMPathForResourceOfType("WPrefs.xpm", NULL
);
578 tmp
= RLoadImage(WMScreenRContext(scr
), path
, 0);
580 wwarning(_("could not load image file %s:%s"), path
, RMessageForError(RErrorCode
));
582 WMSetApplicationIconImage(scr
, tmp
);
588 memset(&WPrefs
, 0, sizeof(_WPrefs
));
589 createMainWindow(scr
);
591 WMRealizeWidget(WPrefs
.win
);
593 WMSetWindowMiniwindowImage(WPrefs
.win
, WMGetApplicationIconImage(scr
));
595 WMMapWidget(WPrefs
.win
);
596 XFlush(WMScreenDisplay(scr
));
597 WMSetLabelText(WPrefs
.statusL
, _("Loading Window Maker configuration files..."));
598 XFlush(WMScreenDisplay(scr
));
599 loadConfigurations(scr
, WPrefs
.win
);
601 WMSetLabelText(WPrefs
.statusL
, _("Initializing configuration panels..."));
603 InitFocus(scr
, WPrefs
.banner
);
604 InitWindowHandling(scr
, WPrefs
.banner
);
606 InitMenuPreferences(scr
, WPrefs
.banner
);
607 InitIcons(scr
, WPrefs
.banner
);
608 InitPreferences(scr
, WPrefs
.banner
);
610 InitPaths(scr
, WPrefs
.banner
);
611 InitWorkspace(scr
, WPrefs
.banner
);
612 InitConfigurations(scr
, WPrefs
.banner
);
614 InitMenu(scr
, WPrefs
.banner
);
616 #ifdef not_yet_fully_implemented
617 InitKeyboardSettings(scr
, WPrefs
.banner
);
619 InitKeyboardShortcuts(scr
, WPrefs
.banner
);
620 InitMouseSettings(scr
, WPrefs
.banner
);
622 InitAppearance(scr
, WPrefs
.banner
);
624 InitFontSimple(scr
, WPrefs
.banner
);
626 #ifdef not_yet_fully_implemented
627 InitThemes(scr
, WPrefs
.banner
);
629 InitExpert(scr
, WPrefs
.banner
);
631 WMRealizeWidget(WPrefs
.scrollV
);
633 WMSetLabelText(WPrefs
.statusL
, "");
636 WMWindow
*GetWindow(Panel
* panel
)
641 static void loadConfigurations(WMScreen
* scr
, WMWindow
* mainw
)
643 WMPropList
*db
, *gdb
;
650 path
= wdefaultspathfordomain("WindowMaker");
651 WindowMakerDBPath
= path
;
653 db
= WMReadPropListFromFile(path
);
655 if (!WMIsPLDictionary(db
)) {
656 WMReleasePropList(db
);
658 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), path
);
659 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
662 sprintf(mbuf
, _("Could not load Window Maker domain (%s) from defaults database."), path
);
663 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
666 path
= getenv("WMAKER_BIN_NAME");
672 command
= wstrconcat(path
, " --version");
673 file
= popen(command
, "r");
676 if (!file
|| !fgets(buffer
, 1023, file
)) {
677 werror(_("could not extract version information from Window Maker"));
678 wfatal(_("Make sure wmaker is in your search path."));
680 WMRunAlertPanel(scr
, mainw
, _("Error"),
682 ("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."),
683 _("OK"), NULL
, NULL
);
689 if (sscanf(buffer
, "Window Maker %i.%i.%i", &v1
, &v2
, &v3
) != 3
690 && sscanf(buffer
, "WindowMaker %i.%i.%i", &v1
, &v2
, &v3
) != 3) {
691 WMRunAlertPanel(scr
, mainw
, _("Error"),
692 _("Could not extract version from Window Maker. "
693 "Make sure it is correctly installed and the path "
694 "where it installed is in the PATH environment "
695 "variable."), _("OK"), NULL
, NULL
);
698 if (v1
== 0 && (v2
< 18 || v3
< 0)) {
699 sprintf(mbuf
, _("WPrefs only supports Window Maker 0.18.0 or newer.\n"
700 "The version installed is %i.%i.%i\n"), v1
, v2
, v3
);
701 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
705 if (v1
> 1 || (v1
== 1 && (v2
> 0))) {
708 ("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."),
710 WMRunAlertPanel(scr
, mainw
, _("Warning"), mbuf
, _("OK"), NULL
, NULL
);
716 command
= wstrconcat(path
, " --global_defaults_path");
717 file
= popen(command
, "r");
720 if (!file
|| !fgets(buffer
, 1023, file
)) {
721 werror(_("could not run \"%s --global_defaults_path\"."), path
);
725 ptr
= strchr(buffer
, '\n');
728 strcat(buffer
, "/WindowMaker");
734 gdb
= WMReadPropListFromFile(buffer
);
737 if (!WMIsPLDictionary(gdb
)) {
738 WMReleasePropList(gdb
);
740 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), buffer
);
741 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
744 sprintf(mbuf
, _("Could not load global Window Maker domain (%s)."), buffer
);
745 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
749 db
= WMCreatePLDictionary(NULL
, NULL
);
752 gdb
= WMCreatePLDictionary(NULL
, NULL
);
760 WMPropList
*GetObjectForKey(char *defaultName
)
762 WMPropList
*object
= NULL
;
763 WMPropList
*key
= WMCreatePLString(defaultName
);
765 object
= WMGetFromPLDictionary(WindowMakerDB
, key
);
767 object
= WMGetFromPLDictionary(GlobalDB
, key
);
769 WMReleasePropList(key
);
774 void SetObjectForKey(WMPropList
* object
, char *defaultName
)
776 WMPropList
*key
= WMCreatePLString(defaultName
);
778 WMPutInPLDictionary(WindowMakerDB
, key
, object
);
779 WMReleasePropList(key
);
782 void RemoveObjectForKey(char *defaultName
)
784 WMPropList
*key
= WMCreatePLString(defaultName
);
786 WMRemoveFromPLDictionary(WindowMakerDB
, key
);
788 WMReleasePropList(key
);
791 char *GetStringForKey(char *defaultName
)
795 val
= GetObjectForKey(defaultName
);
800 if (!WMIsPLString(val
))
803 return WMGetFromPLString(val
);
806 WMPropList
*GetArrayForKey(char *defaultName
)
810 val
= GetObjectForKey(defaultName
);
815 if (!WMIsPLArray(val
))
821 WMPropList
*GetDictionaryForKey(char *defaultName
)
825 val
= GetObjectForKey(defaultName
);
830 if (!WMIsPLDictionary(val
))
836 int GetIntegerForKey(char *defaultName
)
842 val
= GetObjectForKey(defaultName
);
847 if (!WMIsPLString(val
))
850 str
= WMGetFromPLString(val
);
854 if (sscanf(str
, "%i", &value
) != 1)
860 Bool
GetBoolForKey(char *defaultName
)
865 str
= GetStringForKey(defaultName
);
870 if (sscanf(str
, "%i", &value
) == 1 && value
!= 0)
873 if (strcasecmp(str
, "YES") == 0)
876 if (strcasecmp(str
, "Y") == 0)
882 void SetIntegerForKey(int value
, char *defaultName
)
887 sprintf(buffer
, "%i", value
);
888 object
= WMCreatePLString(buffer
);
890 SetObjectForKey(object
, defaultName
);
891 WMReleasePropList(object
);
894 void SetStringForKey(char *value
, char *defaultName
)
898 object
= WMCreatePLString(value
);
900 SetObjectForKey(object
, defaultName
);
901 WMReleasePropList(object
);
904 void SetBoolForKey(Bool value
, char *defaultName
)
906 static WMPropList
*yes
= NULL
, *no
= NULL
;
909 yes
= WMCreatePLString("YES");
910 no
= WMCreatePLString("NO");
913 SetObjectForKey(value
? yes
: no
, defaultName
);
916 void SetSpeedForKey(int speed
, char *defaultName
)
941 SetStringForKey(str
, defaultName
);
944 int GetSpeedForKey(char *defaultName
)
949 str
= GetStringForKey(defaultName
);
953 if (strcasecmp(str
, "ultraslow") == 0)
955 else if (strcasecmp(str
, "slow") == 0)
957 else if (strcasecmp(str
, "medium") == 0)
959 else if (strcasecmp(str
, "fast") == 0)
961 else if (strcasecmp(str
, "ultrafast") == 0)
964 wwarning(_("bad speed value for option %s; using default Medium"), defaultName
);