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.
26 #define ICON_TITLE_FONT "sans serif:pixelsize=9"
27 #define ICON_TITLE_VFONT "sans serif:pixelsize=9:weight=100"
29 #define MAX_SECTIONS 16
31 typedef struct _WPrefs
{
34 WMScrollView
*scrollV
;
36 WMButton
*sectionB
[MAX_SECTIONS
];
55 static _WPrefs WPrefs
;
57 /* system wide defaults dictionary. Read-only */
58 static WMPropList
*GlobalDB
= NULL
;
59 /* user defaults dictionary */
60 static WMPropList
*WindowMakerDB
= NULL
;
61 static char *WindowMakerDBPath
= NULL
;
63 static Bool TIFFOK
= False
;
65 #define INITIALIZED_PANEL (1<<0)
67 static void loadConfigurations(WMScreen
* scr
, WMWindow
* mainw
);
69 static void savePanelData(Panel
* panel
);
71 static void prepareForClose(void);
73 static void quit(WMWidget
*w
, void *data
)
80 static void save(WMWidget
* w
, void *data
)
88 /* puts("gathering data"); */
89 for (i
= 0; i
< WPrefs
.sectionCount
; i
++) {
90 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
91 if ((rec
->callbacks
.flags
& INITIALIZED_PANEL
))
92 savePanelData((Panel
*) rec
);
94 /* puts("compressing data"); */
95 /* compare the user dictionary with the global and remove redundant data */
96 keyList
= WMGetPLDictionaryKeys(GlobalDB
);
97 /* puts(WMGetPropListDescription(WindowMakerDB, False)); */
98 for (i
= 0; i
< WMGetPropListItemCount(keyList
); i
++) {
99 key
= WMGetFromPLArray(keyList
, i
);
101 /* We don't have this value anyway, so no problem.
102 * Probably a new option */
103 p1
= WMGetFromPLDictionary(WindowMakerDB
, key
);
106 /* The global doesn't have it, so no problem either. */
107 p2
= WMGetFromPLDictionary(GlobalDB
, key
);
110 /* If both values are the same, don't save. */
111 if (WMIsPropListEqualTo(p1
, p2
))
112 WMRemoveFromPLDictionary(WindowMakerDB
, key
);
114 /* puts(WMGetPropListDescription(WindowMakerDB, False)); */
115 WMReleasePropList(keyList
);
116 /* puts("storing data"); */
118 WMWritePropListToFile(WindowMakerDB
, WindowMakerDBPath
);
120 memset(&ev
, 0, sizeof(XEvent
));
122 ev
.xclient
.type
= ClientMessage
;
123 ev
.xclient
.message_type
= XInternAtom(WMScreenDisplay(WMWidgetScreen(w
)), "_WINDOWMAKER_COMMAND", False
);
124 ev
.xclient
.window
= DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
)));
125 ev
.xclient
.format
= 8;
126 strncpy(ev
.xclient
.data
.b
, "Reconfigure", sizeof(ev
.xclient
.data
.b
));
128 XSendEvent(WMScreenDisplay(WMWidgetScreen(w
)),
129 DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
))), False
, SubstructureRedirectMask
, &ev
);
130 XFlush(WMScreenDisplay(WMWidgetScreen(w
)));
133 static void undo(WMWidget
* w
, void *data
)
135 PanelRec
*rec
= (PanelRec
*) WPrefs
.currentPanel
;
140 if (rec
->callbacks
.undoChanges
&& (rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
141 (*rec
->callbacks
.undoChanges
) (WPrefs
.currentPanel
);
145 static void undoAll(WMWidget
* w
, void *data
)
149 for (i
= 0; i
< WPrefs
.sectionCount
; i
++) {
150 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
152 if (rec
->callbacks
.undoChanges
&& (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
153 (*rec
->callbacks
.undoChanges
) ((Panel
*) rec
);
157 static void prepareForClose(void)
161 for (i
= 0; i
< WPrefs
.sectionCount
; i
++) {
162 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
164 if (rec
->callbacks
.prepareForClose
&& (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
165 (*rec
->callbacks
.prepareForClose
) ((Panel
*) rec
);
169 static void toggleBalloons(WMWidget
*w
, void *data
)
171 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
174 flag
= WMGetButtonSelected(WPrefs
.balloonBtn
);
176 WMSetBalloonEnabled(WMWidgetScreen(WPrefs
.win
), flag
);
178 WMSetUDBoolForKey(udb
, flag
, "BalloonHelp");
181 static void createMainWindow(WMScreen
* scr
)
183 WMScroller
*scroller
;
187 WPrefs
.win
= WMCreateWindow(scr
, "wprefs");
188 WMResizeWidget(WPrefs
.win
, 520, 390);
189 WMSetWindowTitle(WPrefs
.win
, _("Window Maker Preferences"));
190 WMSetWindowCloseAction(WPrefs
.win
, quit
, NULL
);
191 WMSetWindowMaxSize(WPrefs
.win
, 520, 390);
192 WMSetWindowMinSize(WPrefs
.win
, 520, 390);
193 WMSetWindowMiniwindowTitle(WPrefs
.win
, "Preferences");
195 WPrefs
.scrollV
= WMCreateScrollView(WPrefs
.win
);
196 WMResizeWidget(WPrefs
.scrollV
, 500, 87);
197 WMMoveWidget(WPrefs
.scrollV
, 10, 10);
198 WMSetScrollViewRelief(WPrefs
.scrollV
, WRSunken
);
199 WMSetScrollViewHasHorizontalScroller(WPrefs
.scrollV
, True
);
200 WMSetScrollViewHasVerticalScroller(WPrefs
.scrollV
, False
);
201 scroller
= WMGetScrollViewHorizontalScroller(WPrefs
.scrollV
);
202 WMSetScrollerArrowsPosition(scroller
, WSANone
);
204 WPrefs
.buttonF
= WMCreateFrame(WPrefs
.win
);
205 WMSetFrameRelief(WPrefs
.buttonF
, WRFlat
);
207 WMSetScrollViewContentView(WPrefs
.scrollV
, WMWidgetView(WPrefs
.buttonF
));
209 WPrefs
.undosBtn
= WMCreateCommandButton(WPrefs
.win
);
210 WMResizeWidget(WPrefs
.undosBtn
, 90, 28);
211 WMMoveWidget(WPrefs
.undosBtn
, 135, 350);
212 WMSetButtonText(WPrefs
.undosBtn
, _("Revert Page"));
213 WMSetButtonAction(WPrefs
.undosBtn
, undo
, NULL
);
215 WPrefs
.undoBtn
= WMCreateCommandButton(WPrefs
.win
);
216 WMResizeWidget(WPrefs
.undoBtn
, 90, 28);
217 WMMoveWidget(WPrefs
.undoBtn
, 235, 350);
218 WMSetButtonText(WPrefs
.undoBtn
, _("Revert All"));
219 WMSetButtonAction(WPrefs
.undoBtn
, undoAll
, NULL
);
221 WPrefs
.saveBtn
= WMCreateCommandButton(WPrefs
.win
);
222 WMResizeWidget(WPrefs
.saveBtn
, 80, 28);
223 WMMoveWidget(WPrefs
.saveBtn
, 335, 350);
224 WMSetButtonText(WPrefs
.saveBtn
, _("Save"));
225 WMSetButtonAction(WPrefs
.saveBtn
, save
, NULL
);
227 WPrefs
.closeBtn
= WMCreateCommandButton(WPrefs
.win
);
228 WMResizeWidget(WPrefs
.closeBtn
, 80, 28);
229 WMMoveWidget(WPrefs
.closeBtn
, 425, 350);
230 WMSetButtonText(WPrefs
.closeBtn
, _("Close"));
231 WMSetButtonAction(WPrefs
.closeBtn
, quit
, NULL
);
233 WPrefs
.balloonBtn
= WMCreateSwitchButton(WPrefs
.win
);
234 WMResizeWidget(WPrefs
.balloonBtn
, 200, 28);
235 WMMoveWidget(WPrefs
.balloonBtn
, 15, 350);
236 WMSetButtonText(WPrefs
.balloonBtn
, _("Balloon Help"));
237 WMSetButtonAction(WPrefs
.balloonBtn
, toggleBalloons
, NULL
);
239 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
240 Bool flag
= WMGetUDBoolForKey(udb
, "BalloonHelp");
242 WMSetButtonSelected(WPrefs
.balloonBtn
, flag
);
243 WMSetBalloonEnabled(scr
, flag
);
247 WPrefs
.banner
= WMCreateFrame(WPrefs
.win
);
248 WMResizeWidget(WPrefs
.banner
, FRAME_WIDTH
, FRAME_HEIGHT
);
249 WMMoveWidget(WPrefs
.banner
, FRAME_LEFT
, FRAME_TOP
);
250 WMSetFrameRelief(WPrefs
.banner
, WRFlat
);
252 font
= WMCreateFont(scr
, "Lucida Sans,URW Gothic L,Times New Roman,serif"
253 ":bold:pixelsize=26:antialias=true");
254 WPrefs
.nameL
= WMCreateLabel(WPrefs
.banner
);
255 WMSetLabelTextAlignment(WPrefs
.nameL
, WACenter
);
256 WMResizeWidget(WPrefs
.nameL
, FRAME_WIDTH
- 20, 60);
257 WMMoveWidget(WPrefs
.nameL
, 10, 50);
258 WMSetLabelFont(WPrefs
.nameL
, font
);
259 WMSetLabelText(WPrefs
.nameL
, _("Window Maker Preferences"));
262 WPrefs
.versionL
= WMCreateLabel(WPrefs
.banner
);
263 WMResizeWidget(WPrefs
.versionL
, FRAME_WIDTH
- 20, 20);
264 WMMoveWidget(WPrefs
.versionL
, 10, 120);
265 WMSetLabelTextAlignment(WPrefs
.versionL
, WACenter
);
266 sprintf(buffer
, _("Version %s"), VERSION
);
267 WMSetLabelText(WPrefs
.versionL
, buffer
);
269 WPrefs
.statusL
= WMCreateLabel(WPrefs
.banner
);
270 WMResizeWidget(WPrefs
.statusL
, FRAME_WIDTH
- 20, 60);
271 WMMoveWidget(WPrefs
.statusL
, 10, 150);
272 WMSetLabelTextAlignment(WPrefs
.statusL
, WACenter
);
273 WMSetLabelText(WPrefs
.statusL
, _("Starting..."));
275 WMMapSubwidgets(WPrefs
.win
);
277 WMUnmapWidget(WPrefs
.undosBtn
);
278 WMUnmapWidget(WPrefs
.undoBtn
);
279 WMUnmapWidget(WPrefs
.saveBtn
);
282 static void showPanel(Panel
* panel
)
284 PanelRec
*rec
= (PanelRec
*) panel
;
286 if (!(rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
287 (*rec
->callbacks
.createWidgets
) (panel
);
288 rec
->callbacks
.flags
|= INITIALIZED_PANEL
;
291 WMSetWindowTitle(WPrefs
.win
, rec
->sectionName
);
293 if (rec
->callbacks
.showPanel
)
294 (*rec
->callbacks
.showPanel
) (panel
);
296 WMMapWidget(rec
->box
);
299 static void hidePanel(Panel
* panel
)
301 PanelRec
*rec
= (PanelRec
*) panel
;
303 WMUnmapWidget(rec
->box
);
305 if (rec
->callbacks
.hidePanel
)
306 (*rec
->callbacks
.hidePanel
) (panel
);
309 static void savePanelData(Panel
* panel
)
311 PanelRec
*rec
= (PanelRec
*) panel
;
313 if (rec
->callbacks
.updateDomain
) {
314 (*rec
->callbacks
.updateDomain
) (panel
);
318 static void changeSection(WMWidget
* self
, void *data
)
320 if (WPrefs
.currentPanel
== data
)
323 if (WPrefs
.currentPanel
== NULL
) {
324 WMDestroyWidget(WPrefs
.nameL
);
325 WMDestroyWidget(WPrefs
.versionL
);
326 WMDestroyWidget(WPrefs
.statusL
);
328 WMSetFrameRelief(WPrefs
.banner
, WRGroove
);
330 /* WMMapWidget(WPrefs.undosBtn);
331 WMMapWidget(WPrefs.undoBtn);
333 WMMapWidget(WPrefs
.saveBtn
);
338 if (WPrefs
.currentPanel
)
339 hidePanel(WPrefs
.currentPanel
);
340 WPrefs
.currentPanel
= data
;
343 char *LocateImage(const char *name
)
346 char *tmp
= wmalloc(strlen(name
) + 8);
349 sprintf(tmp
, "%s.tiff", name
);
350 path
= WMPathForResourceOfType(tmp
, "tiff");
352 sprintf(tmp
, "%s.xpm", name
);
353 path
= WMPathForResourceOfType(tmp
, "xpm");
357 wwarning(_("could not locate image file %s"), name
);
363 void CreateImages(WMScreen
*scr
, RContext
*rc
, RImage
*xis
, const char *file
,
364 WMPixmap
**icon_normal
, WMPixmap
**icon_greyed
)
368 RColor gray
= { 0xae, 0xaa, 0xae, 0 };
370 path
= LocateImage(file
);
379 *icon_normal
= WMCreatePixmapFromFile(scr
, path
);
382 wwarning(_("could not load icon %s"), path
);
389 if (!icon_greyed
) // Greyed-out version not requested, we are done
395 icon
= RLoadImage(rc
, path
, 0);
398 wwarning(_("could not load icon %s"), path
);
403 RCombineImageWithColor(icon
, &gray
);
406 RCombineImagesWithOpaqueness(icon
, xis
, 180);
408 *icon_greyed
= WMCreatePixmapFromRImage(scr
, icon
, 127);
411 wwarning(_("could not process icon %s: %s"), path
, RMessageForError(RErrorCode
));
418 static WMPixmap
*makeTitledIcon(WMScreen
* scr
, WMPixmap
* icon
, const char *title1
, const char *title2
)
420 return WMRetainPixmap(icon
);
424 static XFontStruct
*hfont
= NULL
;
425 static XFontStruct
*vfont
= NULL
;
428 Display
*dpy
= WMScreenDisplay(scr
);
429 WMColor
*black
= WMBlackColor(scr
);
431 WMSize size
= WMGetPixmapSize(icon
);
433 tmp
= WMCreatePixmap(scr
, 60, 60, WMScreenDepth(scr
), True
);
435 pix
= WMGetPixmapXID(tmp
);
436 mask
= WMGetPixmapMaskXID(tmp
);
439 gc
= XCreateGC(dpy
, mask
, 0, NULL
);
441 hfont
= XLoadQueryFont(dpy
, ICON_TITLE_FONT
);
442 vfont
= XLoadQueryFont(dpy
, ICON_TITLE_VFONT
);
446 return WMRetainPixmap(icon
);
449 XSetForeground(dpy
, gc
, 0);
450 XFillRectangle(dpy
, mask
, gc
, 0, 0, 60, 60);
452 fgc
= WMColorGC(black
);
454 XSetForeground(dpy
, gc
, 1);
456 XCopyArea(dpy
, WMGetPixmapXID(icon
), pix
, fgc
, 0, 0, size
.width
, size
.height
, 12, 12);
458 if (WMGetPixmapMaskXID(icon
) != None
)
459 XCopyPlane(dpy
, WMGetPixmapMaskXID(icon
), mask
, gc
, 0, 0, size
.width
, size
.height
, 12, 12, 1);
461 XFillRectangle(dpy
, mask
, gc
, 12, 12, 48, 48);
464 XSetFont(dpy
, fgc
, vfont
->fid
);
465 XSetFont(dpy
, gc
, vfont
->fid
);
467 XDrawString(dpy
, pix
, fgc
, 0, vfont
->ascent
, title1
, strlen(title1
));
469 XDrawString(dpy
, mask
, gc
, 0, vfont
->ascent
, title1
, strlen(title1
));
473 XSetFont(dpy
, fgc
, hfont
->fid
);
474 XSetFont(dpy
, gc
, hfont
->fid
);
476 XDrawString(dpy
, pix
, fgc
, (title1
? 12 : 0), hfont
->ascent
, title2
, strlen(title2
));
478 XDrawString(dpy
, mask
, gc
, (title1
? 12 : 0), hfont
->ascent
, title2
, strlen(title2
));
485 void SetButtonAlphaImage(WMScreen
* scr
, WMButton
* bPtr
, const char *file
, const char *title1
, const char *title2
)
492 iconPath
= LocateImage(file
);
499 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
501 wwarning(_("could not load icon file %s"), iconPath
);
507 icon2
= makeTitledIcon(scr
, icon
, title1
, title2
);
509 WMReleasePixmap(icon
);
514 WMSetButtonImage(bPtr
, icon2
);
517 WMReleasePixmap(icon2
);
524 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
526 wwarning(_("could not load icon file %s"), iconPath
);
531 WMSetButtonAltImage(bPtr
, icon
);
534 WMReleasePixmap(icon
);
540 void AddSection(Panel
* panel
, const char *iconFile
)
544 assert(WPrefs
.sectionCount
< MAX_SECTIONS
);
546 bPtr
= WMCreateCustomButton(WPrefs
.buttonF
, WBBStateLightMask
| WBBStateChangeMask
);
547 WMResizeWidget(bPtr
, 64, 64);
548 WMMoveWidget(bPtr
, WPrefs
.sectionCount
* 64, 0);
549 WMSetButtonImagePosition(bPtr
, WIPImageOnly
);
550 WMSetButtonAction(bPtr
, changeSection
, panel
);
551 WMHangData(bPtr
, panel
);
553 WMSetBalloonTextForView(((PanelRec
*) panel
)->description
, WMWidgetView(bPtr
));
558 t1
= wstrdup(((PanelRec
*) panel
)->sectionName
);
559 t2
= strchr(t1
, ' ');
564 SetButtonAlphaImage(WMWidgetScreen(bPtr
), bPtr
, iconFile
, t1
, t2
);
569 WPrefs
.sectionB
[WPrefs
.sectionCount
] = bPtr
;
571 if (WPrefs
.sectionCount
> 0) {
572 WMGroupButtons(WPrefs
.sectionB
[0], bPtr
);
575 WPrefs
.sectionCount
++;
577 WMResizeWidget(WPrefs
.buttonF
, WPrefs
.sectionCount
* 64, 64);
580 void Initialize(WMScreen
* scr
)
586 list
= RSupportedFileFormats();
587 for (i
= 0; list
[i
] != NULL
; i
++) {
588 if (strcmp(list
[i
], "TIFF") == 0) {
595 path
= WMPathForResourceOfType("WPrefs.tiff", NULL
);
597 path
= WMPathForResourceOfType("WPrefs.xpm", NULL
);
601 tmp
= RLoadImage(WMScreenRContext(scr
), path
, 0);
603 wwarning(_("could not load image file %s:%s"), path
, RMessageForError(RErrorCode
));
605 WMSetApplicationIconImage(scr
, tmp
);
611 memset(&WPrefs
, 0, sizeof(_WPrefs
));
612 createMainWindow(scr
);
614 WMRealizeWidget(WPrefs
.win
);
616 WMSetWindowMiniwindowImage(WPrefs
.win
, WMGetApplicationIconImage(scr
));
618 WMMapWidget(WPrefs
.win
);
619 XFlush(WMScreenDisplay(scr
));
620 WMSetLabelText(WPrefs
.statusL
, _("Loading Window Maker configuration files..."));
621 XFlush(WMScreenDisplay(scr
));
622 loadConfigurations(scr
, WPrefs
.win
);
624 WMSetLabelText(WPrefs
.statusL
, _("Initializing configuration panels..."));
626 InitFocus(scr
, WPrefs
.banner
);
627 InitWindowHandling(scr
, WPrefs
.banner
);
629 InitMenuPreferences(scr
, WPrefs
.banner
);
630 InitIcons(scr
, WPrefs
.banner
);
631 InitPreferences(scr
, WPrefs
.banner
);
633 InitPaths(scr
, WPrefs
.banner
);
634 InitDocks(scr
, WPrefs
.banner
);
635 InitWorkspace(scr
, WPrefs
.banner
);
636 InitConfigurations(scr
, WPrefs
.banner
);
638 InitMenu(scr
, WPrefs
.banner
);
640 #ifdef not_yet_fully_implemented
641 InitKeyboardSettings(scr
, WPrefs
.banner
);
643 InitKeyboardShortcuts(scr
, WPrefs
.banner
);
644 InitMouseSettings(scr
, WPrefs
.banner
);
646 InitAppearance(scr
, WPrefs
.banner
);
648 InitFontSimple(scr
, WPrefs
.banner
);
650 #ifdef not_yet_fully_implemented
651 InitThemes(scr
, WPrefs
.banner
);
653 InitExpert(scr
, WPrefs
.banner
);
655 WMRealizeWidget(WPrefs
.scrollV
);
657 WMSetLabelText(WPrefs
.statusL
, "");
660 WMWindow
*GetWindow(Panel
* panel
)
665 static void loadConfigurations(WMScreen
* scr
, WMWindow
* mainw
)
667 WMPropList
*db
, *gdb
;
674 path
= wdefaultspathfordomain("WindowMaker");
675 WindowMakerDBPath
= path
;
677 db
= WMReadPropListFromFile(path
);
679 if (!WMIsPLDictionary(db
)) {
680 WMReleasePropList(db
);
682 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), path
);
683 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
686 sprintf(mbuf
, _("Could not load Window Maker domain (%s) from defaults database."), path
);
687 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
690 path
= getenv("WMAKER_BIN_NAME");
696 command
= wstrconcat(path
, " --version");
697 file
= popen(command
, "r");
700 if (!file
|| !fgets(buffer
, 1023, file
)) {
701 werror(_("could not extract version information from Window Maker"));
702 wfatal(_("Make sure wmaker is in your search path."));
704 WMRunAlertPanel(scr
, mainw
, _("Error"),
706 ("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."),
707 _("OK"), NULL
, NULL
);
713 if (sscanf(buffer
, "Window Maker %i.%i.%i", &v1
, &v2
, &v3
) != 3
714 && sscanf(buffer
, "WindowMaker %i.%i.%i", &v1
, &v2
, &v3
) != 3) {
715 WMRunAlertPanel(scr
, mainw
, _("Error"),
716 _("Could not extract version from Window Maker. "
717 "Make sure it is correctly installed and the path "
718 "where it installed is in the PATH environment "
719 "variable."), _("OK"), NULL
, NULL
);
722 if (v1
== 0 && (v2
< 18 || v3
< 0)) {
723 sprintf(mbuf
, _("WPrefs only supports Window Maker 0.18.0 or newer.\n"
724 "The version installed is %i.%i.%i\n"), v1
, v2
, v3
);
725 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
729 if (v1
> 1 || (v1
== 1 && (v2
> 0))) {
732 ("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."),
734 WMRunAlertPanel(scr
, mainw
, _("Warning"), mbuf
, _("OK"), NULL
, NULL
);
740 command
= wstrconcat(path
, " --global_defaults_path");
741 file
= popen(command
, "r");
744 if (!file
|| !fgets(buffer
, 1023, file
)) {
745 werror(_("could not run \"%s --global_defaults_path\"."), path
);
749 ptr
= strchr(buffer
, '\n');
752 strcat(buffer
, "/WindowMaker");
758 gdb
= WMReadPropListFromFile(buffer
);
761 if (!WMIsPLDictionary(gdb
)) {
762 WMReleasePropList(gdb
);
764 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), buffer
);
765 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
768 sprintf(mbuf
, _("Could not load global Window Maker domain (%s)."), buffer
);
769 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
773 db
= WMCreatePLDictionary(NULL
, NULL
);
776 gdb
= WMCreatePLDictionary(NULL
, NULL
);
784 WMPropList
*GetObjectForKey(const char *defaultName
)
786 WMPropList
*object
= NULL
;
787 WMPropList
*key
= WMCreatePLString(defaultName
);
789 object
= WMGetFromPLDictionary(WindowMakerDB
, key
);
791 object
= WMGetFromPLDictionary(GlobalDB
, key
);
793 WMReleasePropList(key
);
798 void SetObjectForKey(WMPropList
* object
, const char *defaultName
)
800 WMPropList
*key
= WMCreatePLString(defaultName
);
802 WMPutInPLDictionary(WindowMakerDB
, key
, object
);
803 WMReleasePropList(key
);
806 void RemoveObjectForKey(const char *defaultName
)
808 WMPropList
*key
= WMCreatePLString(defaultName
);
810 WMRemoveFromPLDictionary(WindowMakerDB
, key
);
812 WMReleasePropList(key
);
815 char *GetStringForKey(const char *defaultName
)
819 val
= GetObjectForKey(defaultName
);
824 if (!WMIsPLString(val
))
827 return WMGetFromPLString(val
);
830 WMPropList
*GetArrayForKey(const char *defaultName
)
834 val
= GetObjectForKey(defaultName
);
839 if (!WMIsPLArray(val
))
845 WMPropList
*GetDictionaryForKey(const char *defaultName
)
849 val
= GetObjectForKey(defaultName
);
854 if (!WMIsPLDictionary(val
))
860 int GetIntegerForKey(const char *defaultName
)
866 val
= GetObjectForKey(defaultName
);
871 if (!WMIsPLString(val
))
874 str
= WMGetFromPLString(val
);
878 if (sscanf(str
, "%i", &value
) != 1)
884 Bool
GetBoolForKey(const char *defaultName
)
889 str
= GetStringForKey(defaultName
);
894 if (sscanf(str
, "%i", &value
) == 1 && value
!= 0)
897 if (strcasecmp(str
, "YES") == 0)
900 if (strcasecmp(str
, "Y") == 0)
906 void SetIntegerForKey(int value
, const char *defaultName
)
911 sprintf(buffer
, "%i", value
);
912 object
= WMCreatePLString(buffer
);
914 SetObjectForKey(object
, defaultName
);
915 WMReleasePropList(object
);
918 void SetStringForKey(const char *value
, const const char *defaultName
)
922 object
= WMCreatePLString(value
);
924 SetObjectForKey(object
, defaultName
);
925 WMReleasePropList(object
);
928 void SetBoolForKey(Bool value
, const char *defaultName
)
930 static WMPropList
*yes
= NULL
, *no
= NULL
;
933 yes
= WMCreatePLString("YES");
934 no
= WMCreatePLString("NO");
937 SetObjectForKey(value
? yes
: no
, defaultName
);
940 void SetSpeedForKey(int speed
, const char *defaultName
)
965 SetStringForKey(str
, defaultName
);
968 int GetSpeedForKey(const char *defaultName
)
973 str
= GetStringForKey(defaultName
);
977 if (strcasecmp(str
, "ultraslow") == 0)
979 else if (strcasecmp(str
, "slow") == 0)
981 else if (strcasecmp(str
, "medium") == 0)
983 else if (strcasecmp(str
, "fast") == 0)
985 else if (strcasecmp(str
, "ultrafast") == 0)
988 wwarning(_("bad speed value for option %s; using default Medium"), defaultName
);