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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 extern Panel
*InitWindowHandling(WMScreen
*scr
, WMWidget
*parent
);
30 extern Panel
*InitKeyboardSettings(WMScreen
*scr
, WMWidget
*parent
);
32 extern Panel
*InitMouseSettings(WMScreen
*scr
, WMWidget
*parent
);
34 extern Panel
*InitKeyboardShortcuts(WMScreen
*scr
, WMWidget
*parent
);
36 extern Panel
*InitWorkspace(WMScreen
*scr
, WMWidget
*parent
);
38 extern Panel
*InitFocus(WMScreen
*scr
, WMWidget
*parent
);
40 extern Panel
*InitPreferences(WMScreen
*scr
, WMWidget
*parent
);
42 extern Panel
*InitFont(WMScreen
*scr
, WMWidget
*parent
);
44 extern Panel
*InitConfigurations(WMScreen
*scr
, WMWidget
*parent
);
46 extern Panel
*InitPaths(WMScreen
*scr
, WMWidget
*parent
);
48 extern Panel
*InitMenu(WMScreen
*scr
, WMWidget
*parent
);
50 extern Panel
*InitExpert(WMScreen
*scr
, WMWidget
*parent
);
52 extern Panel
*InitMenuPreferences(WMScreen
*scr
, WMWidget
*parent
);
54 extern Panel
*InitIcons(WMScreen
*scr
, WMWidget
*parent
);
56 extern Panel
*InitThemes(WMScreen
*scr
, WMWidget
*parent
);
58 extern Panel
*InitAppearance(WMScreen
*scr
, WMWidget
*parent
);
63 #define ICON_TITLE_FONT "-adobe-helvetica-bold-r-*-*-10-*"
64 #define ICON_TITLE_VFONT "-adobe-helvetica-bold-r-*-*-10-[]-*"
67 #define MAX_SECTIONS 16
70 typedef struct _WPrefs
{
73 WMScrollView
*scrollV
;
75 WMButton
*sectionB
[MAX_SECTIONS
];
96 static _WPrefs WPrefs
;
98 /* system wide defaults dictionary. Read-only */
99 static WMPropList
*GlobalDB
= NULL
;
100 /* user defaults dictionary */
101 static WMPropList
*WindowMakerDB
= NULL
;
102 static char *WindowMakerDBPath
= NULL
;
105 static Bool TIFFOK
= False
;
108 #define INITIALIZED_PANEL (1<<0)
113 static void loadConfigurations(WMScreen
*scr
, WMWindow
*mainw
);
115 static void savePanelData(Panel
*panel
);
117 static void prepareForClose();
120 quit(WMWidget
*w
, void *data
)
129 save(WMWidget
*w
, void *data
)
135 char *msg
= "Reconfigure";
139 /* puts("gathering data");*/
140 for (i
=0; i
<WPrefs
.sectionCount
; i
++) {
141 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
142 if ((rec
->callbacks
.flags
& INITIALIZED_PANEL
))
143 savePanelData((Panel
*)rec
);
145 /* puts("compressing data");*/
146 /* compare the user dictionary with the global and remove redundant data */
147 keyList
= WMGetPLDictionaryKeys(GlobalDB
);
148 /* puts(WMGetPropListDescription(WindowMakerDB, False));*/
149 for (i
=0; i
<WMGetPropListItemCount(keyList
); i
++) {
150 key
= WMGetFromPLArray(keyList
, i
);
152 /* We don't have this value anyway, so no problem.
153 * Probably a new option */
154 p1
= WMGetFromPLDictionary(WindowMakerDB
, key
);
157 /* The global doesn't have it, so no problem either. */
158 p2
= WMGetFromPLDictionary(GlobalDB
, key
);
161 /* If both values are the same, don't save. */
162 if (WMIsPropListEqualTo(p1
, p2
))
163 WMRemoveFromPLDictionary(WindowMakerDB
, key
);
165 /* puts(WMGetPropListDescription(WindowMakerDB, False));*/
166 WMReleasePropList(keyList
);
167 /* puts("storing data");*/
169 WMWritePropListToFile(WindowMakerDB
, WindowMakerDBPath
, True
);
172 memset(&ev
, 0, sizeof(XEvent
));
174 ev
.xclient
.type
= ClientMessage
;
175 ev
.xclient
.message_type
= XInternAtom(WMScreenDisplay(WMWidgetScreen(w
)),
176 "_WINDOWMAKER_COMMAND", False
);
177 ev
.xclient
.window
= DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
)));
178 ev
.xclient
.format
= 8;
180 for (i
= 0; i
<= strlen(msg
); i
++) {
181 ev
.xclient
.data
.b
[i
] = msg
[i
];
183 XSendEvent(WMScreenDisplay(WMWidgetScreen(w
)),
184 DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
))),
185 False
, SubstructureRedirectMask
, &ev
);
186 XFlush(WMScreenDisplay(WMWidgetScreen(w
)));
192 undo(WMWidget
*w
, void *data
)
194 PanelRec
*rec
= (PanelRec
*)WPrefs
.currentPanel
;
199 if (rec
->callbacks
.undoChanges
200 && (rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
201 (*rec
->callbacks
.undoChanges
)(WPrefs
.currentPanel
);
207 undoAll(WMWidget
*w
, void *data
)
211 for (i
=0; i
<WPrefs
.sectionCount
; i
++) {
212 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
214 if (rec
->callbacks
.undoChanges
215 && (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
216 (*rec
->callbacks
.undoChanges
)((Panel
*)rec
);
227 for (i
=0; i
<WPrefs
.sectionCount
; i
++) {
228 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
230 if (rec
->callbacks
.prepareForClose
231 && (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
232 (*rec
->callbacks
.prepareForClose
)((Panel
*)rec
);
238 toggleBalloons(WMWidget
*w
, void *data
)
240 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
243 flag
= WMGetButtonSelected(WPrefs
.balloonBtn
);
245 WMSetBalloonEnabled(WMWidgetScreen(WPrefs
.win
), flag
);
247 WMSetUDBoolForKey(udb
, flag
, "BalloonHelp");
252 createMainWindow(WMScreen
*scr
)
254 WMScroller
*scroller
;
258 WPrefs
.win
= WMCreateWindow(scr
, "wprefs");
259 WMResizeWidget(WPrefs
.win
, 520, 390);
260 WMSetWindowTitle(WPrefs
.win
, _("Window Maker Preferences"));
261 WMSetWindowCloseAction(WPrefs
.win
, quit
, NULL
);
262 WMSetWindowMaxSize(WPrefs
.win
, 520, 390);
263 WMSetWindowMinSize(WPrefs
.win
, 520, 390);
264 WMSetWindowMiniwindowTitle(WPrefs
.win
, "Preferences");
265 WMSetWindowMiniwindowPixmap(WPrefs
.win
, WMGetApplicationIconPixmap(scr
));
267 WPrefs
.scrollV
= WMCreateScrollView(WPrefs
.win
);
268 WMResizeWidget(WPrefs
.scrollV
, 500, 87);
269 WMMoveWidget(WPrefs
.scrollV
, 10, 10);
270 WMSetScrollViewRelief(WPrefs
.scrollV
, WRSunken
);
271 WMSetScrollViewHasHorizontalScroller(WPrefs
.scrollV
, True
);
272 WMSetScrollViewHasVerticalScroller(WPrefs
.scrollV
, False
);
273 scroller
= WMGetScrollViewHorizontalScroller(WPrefs
.scrollV
);
274 WMSetScrollerArrowsPosition(scroller
, WSANone
);
276 WPrefs
.buttonF
= WMCreateFrame(WPrefs
.win
);
277 WMSetFrameRelief(WPrefs
.buttonF
, WRFlat
);
279 WMSetScrollViewContentView(WPrefs
.scrollV
, WMWidgetView(WPrefs
.buttonF
));
281 WPrefs
.undosBtn
= WMCreateCommandButton(WPrefs
.win
);
282 WMResizeWidget(WPrefs
.undosBtn
, 90, 28);
283 WMMoveWidget(WPrefs
.undosBtn
, 135, 350);
284 WMSetButtonText(WPrefs
.undosBtn
, _("Revert Page"));
285 WMSetButtonAction(WPrefs
.undosBtn
, undo
, NULL
);
287 WPrefs
.undoBtn
= WMCreateCommandButton(WPrefs
.win
);
288 WMResizeWidget(WPrefs
.undoBtn
, 90, 28);
289 WMMoveWidget(WPrefs
.undoBtn
, 235, 350);
290 WMSetButtonText(WPrefs
.undoBtn
, _("Revert All"));
291 WMSetButtonAction(WPrefs
.undoBtn
, undoAll
, NULL
);
293 WPrefs
.saveBtn
= WMCreateCommandButton(WPrefs
.win
);
294 WMResizeWidget(WPrefs
.saveBtn
, 80, 28);
295 WMMoveWidget(WPrefs
.saveBtn
, 335, 350);
296 WMSetButtonText(WPrefs
.saveBtn
, _("Save"));
297 WMSetButtonAction(WPrefs
.saveBtn
, save
, NULL
);
299 WPrefs
.closeBtn
= WMCreateCommandButton(WPrefs
.win
);
300 WMResizeWidget(WPrefs
.closeBtn
, 80, 28);
301 WMMoveWidget(WPrefs
.closeBtn
, 425, 350);
302 WMSetButtonText(WPrefs
.closeBtn
, _("Close"));
303 WMSetButtonAction(WPrefs
.closeBtn
, quit
, NULL
);
306 WPrefs
.balloonBtn
= WMCreateSwitchButton(WPrefs
.win
);
307 WMResizeWidget(WPrefs
.balloonBtn
, 200, 28);
308 WMMoveWidget(WPrefs
.balloonBtn
, 15, 350);
309 WMSetButtonText(WPrefs
.balloonBtn
, _("Balloon Help"));
310 WMSetButtonAction(WPrefs
.balloonBtn
, toggleBalloons
, NULL
);
312 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
313 Bool flag
= WMGetUDBoolForKey(udb
, "BalloonHelp");
315 WMSetButtonSelected(WPrefs
.balloonBtn
, flag
);
316 WMSetBalloonEnabled(scr
, flag
);
320 WPrefs
.banner
= WMCreateFrame(WPrefs
.win
);
321 WMResizeWidget(WPrefs
.banner
, FRAME_WIDTH
, FRAME_HEIGHT
);
322 WMMoveWidget(WPrefs
.banner
, FRAME_LEFT
, FRAME_TOP
);
323 WMSetFrameRelief(WPrefs
.banner
, WRFlat
);
325 font
= WMCreateFont(scr
, "-*-times-bold-r-*-*-24-*-*-*-*-*-*-*,"
326 "-*-fixed-medium-r-normal-*-24-*");
328 font
= WMBoldSystemFontOfSize(scr
, 24);
329 WPrefs
.nameL
= WMCreateLabel(WPrefs
.banner
);
330 WMSetLabelTextAlignment(WPrefs
.nameL
, WACenter
);
331 WMResizeWidget(WPrefs
.nameL
, FRAME_WIDTH
-20, 30);
332 WMMoveWidget(WPrefs
.nameL
, 10, 25);
333 WMSetLabelFont(WPrefs
.nameL
, font
);
334 WMSetLabelText(WPrefs
.nameL
, _("Window Maker Preferences Utility"));
337 WPrefs
.versionL
= WMCreateLabel(WPrefs
.banner
);
338 WMResizeWidget(WPrefs
.versionL
, FRAME_WIDTH
-20, 20);
339 WMMoveWidget(WPrefs
.versionL
, 10, 65);
340 WMSetLabelTextAlignment(WPrefs
.versionL
, WACenter
);
341 sprintf(buffer
, _("Version %s for Window Maker %s or newer"), WVERSION
,
343 WMSetLabelText(WPrefs
.versionL
, buffer
);
345 WPrefs
.statusL
= WMCreateLabel(WPrefs
.banner
);
346 WMResizeWidget(WPrefs
.statusL
, FRAME_WIDTH
-20, 60);
347 WMMoveWidget(WPrefs
.statusL
, 10, 100);
348 WMSetLabelTextAlignment(WPrefs
.statusL
, WACenter
);
349 WMSetLabelText(WPrefs
.statusL
, _("Starting..."));
351 WPrefs
.creditsL
= WMCreateLabel(WPrefs
.banner
);
352 WMResizeWidget(WPrefs
.creditsL
, FRAME_WIDTH
-20, 60);
353 WMMoveWidget(WPrefs
.creditsL
, 10, FRAME_HEIGHT
-60);
354 WMSetLabelTextAlignment(WPrefs
.creditsL
, WACenter
);
355 WMSetLabelText(WPrefs
.creditsL
, _("Programming/Design: Alfredo K. Kojima\n"
356 "Artwork: Marco van Hylckama Vlieg, Largo et al\n"
357 "More Programming: James Thompson et al"));
360 WMMapSubwidgets(WPrefs
.win
);
362 WMUnmapWidget(WPrefs
.undosBtn
);
363 WMUnmapWidget(WPrefs
.undoBtn
);
364 WMUnmapWidget(WPrefs
.saveBtn
);
369 showPanel(Panel
*panel
)
371 PanelRec
*rec
= (PanelRec
*)panel
;
373 if (!(rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
374 (*rec
->callbacks
.createWidgets
)(panel
);
375 rec
->callbacks
.flags
|= INITIALIZED_PANEL
;
378 WMSetWindowTitle(WPrefs
.win
, rec
->sectionName
);
380 if (rec
->callbacks
.showPanel
)
381 (*rec
->callbacks
.showPanel
)(panel
);
383 WMMapWidget(rec
->box
);
389 hidePanel(Panel
*panel
)
391 PanelRec
*rec
= (PanelRec
*)panel
;
393 WMUnmapWidget(rec
->box
);
395 if (rec
->callbacks
.hidePanel
)
396 (*rec
->callbacks
.hidePanel
)(panel
);
401 savePanelData(Panel
*panel
)
403 PanelRec
*rec
= (PanelRec
*)panel
;
405 if (rec
->callbacks
.updateDomain
) {
406 (*rec
->callbacks
.updateDomain
)(panel
);
412 changeSection(WMWidget
*self
, void *data
)
414 if (WPrefs
.currentPanel
== data
)
417 if (WPrefs
.currentPanel
== NULL
) {
418 WMDestroyWidget(WPrefs
.nameL
);
419 WMDestroyWidget(WPrefs
.creditsL
);
420 WMDestroyWidget(WPrefs
.versionL
);
421 WMDestroyWidget(WPrefs
.statusL
);
423 WMSetFrameRelief(WPrefs
.banner
, WRGroove
);
425 /* WMMapWidget(WPrefs.undosBtn);
426 WMMapWidget(WPrefs.undoBtn);
428 WMMapWidget(WPrefs
.saveBtn
);
433 if (WPrefs
.currentPanel
)
434 hidePanel(WPrefs
.currentPanel
);
435 WPrefs
.currentPanel
= data
;
441 LocateImage(char *name
)
444 char *tmp
= wmalloc(strlen(name
)+8);
447 sprintf(tmp
, "%s.tiff", name
);
448 path
= WMPathForResourceOfType(tmp
, "tiff");
450 sprintf(tmp
, "%s.xpm", name
);
451 path
= WMPathForResourceOfType(tmp
, "xpm");
455 wwarning(_("could not locate image file %s\n"), name
);
464 makeTitledIcon(WMScreen
*scr
, WMPixmap
*icon
, char *title1
, char *title2
)
466 return WMRetainPixmap(icon
);
470 static XFontStruct
*hfont
= NULL
;
471 static XFontStruct
*vfont
= NULL
;
474 Display
*dpy
= WMScreenDisplay(scr
);
475 WMColor
*black
= WMBlackColor(scr
);
477 WMSize size
= WMGetPixmapSize(icon
);
480 tmp
= WMCreatePixmap(scr
, 60, 60, WMScreenDepth(scr
), True
);
482 pix
= WMGetPixmapXID(tmp
);
483 mask
= WMGetPixmapMaskXID(tmp
);
486 gc
= XCreateGC(dpy
, mask
, 0, NULL
);
488 hfont
= XLoadQueryFont(dpy
, ICON_TITLE_FONT
);
489 vfont
= XLoadQueryFont(dpy
, ICON_TITLE_VFONT
);
493 return WMRetainPixmap(icon
);
496 XSetForeground(dpy
, gc
, 0);
497 XFillRectangle(dpy
, mask
, gc
, 0, 0, 60, 60);
499 fgc
= WMColorGC(black
);
501 XSetForeground(dpy
, gc
, 1);
503 XCopyArea(dpy
, WMGetPixmapXID(icon
), pix
, fgc
, 0, 0,
504 size
.width
, size
.height
, 12, 12);
506 if (WMGetPixmapMaskXID(icon
) != None
)
507 XCopyPlane(dpy
, WMGetPixmapMaskXID(icon
), mask
, gc
, 0, 0,
508 size
.width
, size
.height
, 12, 12, 1);
510 XFillRectangle(dpy
, mask
, gc
, 12, 12, 48, 48);
514 XSetFont(dpy
, fgc
, vfont
->fid
);
515 XSetFont(dpy
, gc
, vfont
->fid
);
517 XDrawString(dpy
, pix
, fgc
, 0, vfont
->ascent
,
518 title1
, strlen(title1
));
520 XDrawString(dpy
, mask
, gc
, 0, vfont
->ascent
,
521 title1
, strlen(title1
));
525 XSetFont(dpy
, fgc
, hfont
->fid
);
526 XSetFont(dpy
, gc
, hfont
->fid
);
528 XDrawString(dpy
, pix
, fgc
, (title1
? 12 : 0), hfont
->ascent
,
529 title2
, strlen(title2
));
531 XDrawString(dpy
, mask
, gc
, (title1
? 12 : 0), hfont
->ascent
,
532 title2
, strlen(title2
));
541 SetButtonAlphaImage(WMScreen
*scr
, WMButton
*bPtr
, char *file
,
542 char *title1
, char *title2
)
549 iconPath
= LocateImage(file
);
556 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
558 wwarning(_("could not load icon file %s"), iconPath
);
564 icon2
= makeTitledIcon(scr
, icon
, title1
, title2
);
566 WMReleasePixmap(icon
);
571 WMSetButtonImage(bPtr
, icon2
);
574 WMReleasePixmap(icon2
);
581 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
583 wwarning(_("could not load icon file %s"), iconPath
);
588 WMSetButtonAltImage(bPtr
, icon
);
591 WMReleasePixmap(icon
);
599 AddSection(Panel
*panel
, char *iconFile
)
603 assert(WPrefs
.sectionCount
< MAX_SECTIONS
);
606 bPtr
= WMCreateCustomButton(WPrefs
.buttonF
, WBBStateLightMask
607 |WBBStateChangeMask
);
608 WMResizeWidget(bPtr
, 64, 64);
609 WMMoveWidget(bPtr
, WPrefs
.sectionCount
*64, 0);
610 WMSetButtonImagePosition(bPtr
, WIPImageOnly
);
611 WMSetButtonAction(bPtr
, changeSection
, panel
);
612 WMHangData(bPtr
, panel
);
614 WMSetBalloonTextForView(((PanelRec
*)panel
)->description
,
620 t1
= wstrdup(((PanelRec
*)panel
)->sectionName
);
621 t2
= strchr(t1
, ' ');
626 SetButtonAlphaImage(WMWidgetScreen(bPtr
), bPtr
, iconFile
,
632 WPrefs
.sectionB
[WPrefs
.sectionCount
] = bPtr
;
634 if (WPrefs
.sectionCount
> 0) {
635 WMGroupButtons(WPrefs
.sectionB
[0], bPtr
);
638 WPrefs
.sectionCount
++;
640 WMResizeWidget(WPrefs
.buttonF
, WPrefs
.sectionCount
*64, 64);
645 Initialize(WMScreen
*scr
)
653 list
= RSupportedFileFormats();
654 for (i
=0; list
[i
]!=NULL
; i
++) {
655 if (strcmp(list
[i
], "TIFF")==0) {
662 path
= WMPathForResourceOfType("WPrefs.tiff", NULL
);
664 path
= WMPathForResourceOfType("WPrefs.xpm", NULL
);
668 tmp
= RLoadImage(WMScreenRContext(scr
), path
, 0);
670 wwarning(_("could not load image file %s:%s"), path
,
671 RMessageForError(RErrorCode
));
673 icon
= WMCreatePixmapFromRImage(scr
, tmp
, 0);
676 WMSetApplicationIconPixmap(scr
, icon
);
677 WMReleasePixmap(icon
);
683 memset(&WPrefs
, 0, sizeof(_WPrefs
));
684 createMainWindow(scr
);
686 WMRealizeWidget(WPrefs
.win
);
687 WMMapWidget(WPrefs
.win
);
688 XFlush(WMScreenDisplay(scr
));
689 WMSetLabelText(WPrefs
.statusL
, _("Loading Window Maker configuration files..."));
690 XFlush(WMScreenDisplay(scr
));
691 loadConfigurations(scr
, WPrefs
.win
);
693 WMSetLabelText(WPrefs
.statusL
, _("Initializing configuration panels..."));
695 InitFocus(scr
, WPrefs
.banner
);
696 InitWindowHandling(scr
, WPrefs
.banner
);
698 InitMenuPreferences(scr
, WPrefs
.banner
);
699 InitIcons(scr
, WPrefs
.banner
);
700 InitPreferences(scr
, WPrefs
.banner
);
702 InitPaths(scr
, WPrefs
.banner
);
703 InitWorkspace(scr
, WPrefs
.banner
);
704 InitConfigurations(scr
, WPrefs
.banner
);
706 InitMenu(scr
, WPrefs
.banner
);
708 #ifdef not_yet_fully_implemented
709 InitKeyboardSettings(scr
, WPrefs
.banner
);
711 InitKeyboardShortcuts(scr
, WPrefs
.banner
);
712 InitMouseSettings(scr
, WPrefs
.banner
);
714 InitAppearance(scr
, WPrefs
.banner
);
716 #ifdef finished_checking
717 InitFont(scr
, WPrefs
.banner
);
720 #ifdef not_yet_fully_implemented
721 InitThemes(scr
, WPrefs
.banner
);
723 InitExpert(scr
, WPrefs
.banner
);
725 WMRealizeWidget(WPrefs
.scrollV
);
727 WMSetLabelText(WPrefs
.statusL
,
728 _("WPrefs is free software and is distributed WITHOUT ANY\n"
729 "WARRANTY under the terms of the GNU General Public License."));
734 GetWindow(Panel
*panel
)
741 loadConfigurations(WMScreen
*scr
, WMWindow
*mainw
)
743 WMPropList
*db
, *gdb
;
750 path
= wdefaultspathfordomain("WindowMaker");
751 WindowMakerDBPath
= path
;
753 db
= WMReadPropListFromFile(path
);
755 if (!WMIsPLDictionary(db
)) {
756 WMReleasePropList(db
);
758 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), path
);
759 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
762 sprintf(mbuf
, _("Could not load Window Maker domain (%s) from defaults database."),
764 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
767 path
= getenv("WMAKER_BIN_NAME");
773 command
= wstrconcat(path
, " --version");
774 file
= popen(command
, "r");
777 if (!file
|| !fgets(buffer
, 1023, file
)) {
778 wsyserror(_("could not extract version information from Window Maker"));
779 wfatal(_("Make sure wmaker is in your search path."));
781 WMRunAlertPanel(scr
, mainw
, _("Error"),
782 _("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."),
783 _("OK"), NULL
, NULL
);
789 if (sscanf(buffer
, "Window Maker %i.%i.%i",&v1
,&v2
,&v3
)!=3
790 && sscanf(buffer
, "WindowMaker %i.%i.%i",&v1
,&v2
,&v3
)!=3) {
791 WMRunAlertPanel(scr
, mainw
, _("Error"),
792 _("Could not extract version from Window Maker. "
793 "Make sure it is correctly installed and the path "
794 "where it installed is in the PATH environment "
795 "variable."), _("OK"), NULL
, NULL
);
798 if (v1
== 0 && (v2
< 18 || v3
< 0)) {
799 sprintf(mbuf
, _("WPrefs only supports Window Maker 0.18.0 or newer.\n"
800 "The version installed is %i.%i.%i\n"), v1
, v2
, v3
);
801 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
805 if (v1
> 1 || (v1
== 1 && (v2
> 0))) {
806 sprintf(mbuf
, _("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."),
808 WMRunAlertPanel(scr
, mainw
, _("Warning"), mbuf
, _("OK"), NULL
, NULL
);
814 command
= wstrconcat(path
, " --global_defaults_path");
815 file
= popen(command
, "r");
818 if (!file
|| !fgets(buffer
, 1023, file
)) {
819 wsyserror(_("could not run \"%s --global_defaults_path\"."), path
);
823 ptr
= strchr(buffer
, '\n');
826 strcat(buffer
, "/WindowMaker");
832 gdb
= WMReadPropListFromFile(buffer
);
835 if (!WMIsPLDictionary(gdb
)) {
836 WMReleasePropList(gdb
);
838 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), buffer
);
839 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
842 sprintf(mbuf
, _("Could not load global Window Maker domain (%s)."),
844 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
848 db
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
851 gdb
= WMCreatePLDictionary(NULL
, NULL
, NULL
);
861 GetObjectForKey(char *defaultName
)
863 WMPropList
*object
= NULL
;
864 WMPropList
*key
= WMCreatePLString(defaultName
);
866 object
= WMGetFromPLDictionary(WindowMakerDB
, key
);
868 object
= WMGetFromPLDictionary(GlobalDB
, key
);
870 WMReleasePropList(key
);
877 SetObjectForKey(WMPropList
*object
, char *defaultName
)
879 WMPropList
*key
= WMCreatePLString(defaultName
);
881 WMPutInPLDictionary(WindowMakerDB
, key
, object
);
882 WMReleasePropList(key
);
887 RemoveObjectForKey(char *defaultName
)
889 WMPropList
*key
= WMCreatePLString(defaultName
);
891 WMRemoveFromPLDictionary(WindowMakerDB
, key
);
893 WMReleasePropList(key
);
898 GetStringForKey(char *defaultName
)
902 val
= GetObjectForKey(defaultName
);
907 if (!WMIsPLString(val
))
910 return WMGetFromPLString(val
);
916 GetArrayForKey(char *defaultName
)
920 val
= GetObjectForKey(defaultName
);
925 if (!WMIsPLArray(val
))
933 GetDictionaryForKey(char *defaultName
)
937 val
= GetObjectForKey(defaultName
);
942 if (!WMIsPLDictionary(val
))
950 GetIntegerForKey(char *defaultName
)
956 val
= GetObjectForKey(defaultName
);
961 if (!WMIsPLString(val
))
964 str
= WMGetFromPLString(val
);
968 if (sscanf(str
, "%i", &value
)!=1)
976 GetBoolForKey(char *defaultName
)
981 str
= GetStringForKey(defaultName
);
986 if (sscanf(str
, "%i", &value
)==1 && value
!=0)
989 if (strcasecmp(str
, "YES")==0)
992 if (strcasecmp(str
, "Y")==0)
1000 SetIntegerForKey(int value
, char *defaultName
)
1005 sprintf(buffer
, "%i", value
);
1006 object
= WMCreatePLString(buffer
);
1008 SetObjectForKey(object
, defaultName
);
1009 WMReleasePropList(object
);
1015 SetStringForKey(char *value
, char *defaultName
)
1019 object
= WMCreatePLString(value
);
1021 SetObjectForKey(object
, defaultName
);
1022 WMReleasePropList(object
);
1027 SetBoolForKey(Bool value
, char *defaultName
)
1029 static WMPropList
*yes
= NULL
, *no
= NULL
;
1032 yes
= WMCreatePLString("YES");
1033 no
= WMCreatePLString("NO");
1036 SetObjectForKey(value
? yes
: no
, defaultName
);
1041 SetSpeedForKey(int speed
, char *defaultName
)
1066 SetStringForKey(str
, defaultName
);
1071 GetSpeedForKey(char *defaultName
)
1076 str
= GetStringForKey(defaultName
);
1080 if (strcasecmp(str
, "ultraslow")==0)
1082 else if (strcasecmp(str
, "slow")==0)
1084 else if (strcasecmp(str
, "medium")==0)
1086 else if (strcasecmp(str
, "fast")==0)
1088 else if (strcasecmp(str
, "ultrafast")==0)
1091 wwarning(_("bad speed value for option %s\n. Using default Medium"),