1 /* WPrefs.c- main window and other basic stuff
3 * WPrefs - Window Maker Preferences Program
5 * Copyright (c) 1998-2000 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 proplist_t GlobalDB
= NULL
;
100 /* user defaults dictionary */
101 static proplist_t WindowMakerDB
= NULL
;
104 static Bool TIFFOK
= False
;
107 #define INITIALIZED_PANEL (1<<0)
112 static void loadConfigurations(WMScreen
*scr
, WMWindow
*mainw
);
114 static void savePanelData(Panel
*panel
);
116 static void prepareForClose();
119 quit(WMWidget
*w
, void *data
)
128 save(WMWidget
*w
, void *data
)
134 char *msg
= "Reconfigure";
138 /* puts("gathering data");*/
139 for (i
=0; i
<WPrefs
.sectionCount
; i
++) {
140 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
141 if ((rec
->callbacks
.flags
& INITIALIZED_PANEL
))
142 savePanelData((Panel
*)rec
);
144 /* puts("compressing data");*/
145 /* compare the user dictionary with the global and remove redundant data */
146 keyList
= PLGetAllDictionaryKeys(GlobalDB
);
147 /* puts(PLGetDescription(WindowMakerDB));*/
148 for (i
=0; i
<PLGetNumberOfElements(keyList
); i
++) {
149 key
= PLGetArrayElement(keyList
, i
);
151 /* We don't have this value anyway, so no problem.
152 * Probably a new option */
153 p1
= PLGetDictionaryEntry(WindowMakerDB
, key
);
156 /* The global doesn't have it, so no problem either. */
157 p2
= PLGetDictionaryEntry(GlobalDB
, key
);
160 /* If both values are the same, don't save. */
161 if (PLIsEqual(p1
, p2
))
162 PLRemoveDictionaryEntry(WindowMakerDB
, key
);
164 /* puts(PLGetDescription(WindowMakerDB));*/
166 /* puts("storing data");*/
168 PLSave(WindowMakerDB
, YES
);
171 memset(&ev
, 0, sizeof(XEvent
));
173 ev
.xclient
.type
= ClientMessage
;
174 ev
.xclient
.message_type
= XInternAtom(WMScreenDisplay(WMWidgetScreen(w
)),
175 "_WINDOWMAKER_COMMAND", False
);
176 ev
.xclient
.window
= DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
)));
177 ev
.xclient
.format
= 8;
179 for (i
= 0; i
<= strlen(msg
); i
++) {
180 ev
.xclient
.data
.b
[i
] = msg
[i
];
182 XSendEvent(WMScreenDisplay(WMWidgetScreen(w
)),
183 DefaultRootWindow(WMScreenDisplay(WMWidgetScreen(w
))),
184 False
, SubstructureRedirectMask
, &ev
);
185 XFlush(WMScreenDisplay(WMWidgetScreen(w
)));
191 undo(WMWidget
*w
, void *data
)
193 PanelRec
*rec
= (PanelRec
*)WPrefs
.currentPanel
;
198 if (rec
->callbacks
.undoChanges
199 && (rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
200 (*rec
->callbacks
.undoChanges
)(WPrefs
.currentPanel
);
206 undoAll(WMWidget
*w
, void *data
)
210 for (i
=0; i
<WPrefs
.sectionCount
; i
++) {
211 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
213 if (rec
->callbacks
.undoChanges
214 && (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
215 (*rec
->callbacks
.undoChanges
)((Panel
*)rec
);
226 for (i
=0; i
<WPrefs
.sectionCount
; i
++) {
227 PanelRec
*rec
= WMGetHangedData(WPrefs
.sectionB
[i
]);
229 if (rec
->callbacks
.prepareForClose
230 && (rec
->callbacks
.flags
& INITIALIZED_PANEL
))
231 (*rec
->callbacks
.prepareForClose
)((Panel
*)rec
);
237 toggleBalloons(WMWidget
*w
, void *data
)
239 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
242 flag
= WMGetButtonSelected(WPrefs
.balloonBtn
);
244 WMSetBalloonEnabled(WMWidgetScreen(WPrefs
.win
), flag
);
246 WMSetUDBoolForKey(udb
, flag
, "BalloonHelp");
251 createMainWindow(WMScreen
*scr
)
253 WMScroller
*scroller
;
257 WPrefs
.win
= WMCreateWindow(scr
, "wprefs");
258 WMResizeWidget(WPrefs
.win
, 520, 390);
259 WMSetWindowTitle(WPrefs
.win
, _("Window Maker Preferences"));
260 WMSetWindowCloseAction(WPrefs
.win
, quit
, NULL
);
261 WMSetWindowMaxSize(WPrefs
.win
, 520, 390);
262 WMSetWindowMinSize(WPrefs
.win
, 520, 390);
263 WMSetWindowMiniwindowTitle(WPrefs
.win
, "Preferences");
264 WMSetWindowMiniwindowPixmap(WPrefs
.win
, WMGetApplicationIconPixmap(scr
));
266 WPrefs
.scrollV
= WMCreateScrollView(WPrefs
.win
);
267 WMResizeWidget(WPrefs
.scrollV
, 500, 87);
268 WMMoveWidget(WPrefs
.scrollV
, 10, 10);
269 WMSetScrollViewRelief(WPrefs
.scrollV
, WRSunken
);
270 WMSetScrollViewHasHorizontalScroller(WPrefs
.scrollV
, True
);
271 WMSetScrollViewHasVerticalScroller(WPrefs
.scrollV
, False
);
272 scroller
= WMGetScrollViewHorizontalScroller(WPrefs
.scrollV
);
273 WMSetScrollerArrowsPosition(scroller
, WSANone
);
275 WPrefs
.buttonF
= WMCreateFrame(WPrefs
.win
);
276 WMSetFrameRelief(WPrefs
.buttonF
, WRFlat
);
278 WMSetScrollViewContentView(WPrefs
.scrollV
, WMWidgetView(WPrefs
.buttonF
));
280 WPrefs
.undosBtn
= WMCreateCommandButton(WPrefs
.win
);
281 WMResizeWidget(WPrefs
.undosBtn
, 90, 28);
282 WMMoveWidget(WPrefs
.undosBtn
, 135, 350);
283 WMSetButtonText(WPrefs
.undosBtn
, _("Revert Page"));
284 WMSetButtonAction(WPrefs
.undosBtn
, undo
, NULL
);
286 WPrefs
.undoBtn
= WMCreateCommandButton(WPrefs
.win
);
287 WMResizeWidget(WPrefs
.undoBtn
, 90, 28);
288 WMMoveWidget(WPrefs
.undoBtn
, 235, 350);
289 WMSetButtonText(WPrefs
.undoBtn
, _("Revert All"));
290 WMSetButtonAction(WPrefs
.undoBtn
, undoAll
, NULL
);
292 WPrefs
.saveBtn
= WMCreateCommandButton(WPrefs
.win
);
293 WMResizeWidget(WPrefs
.saveBtn
, 80, 28);
294 WMMoveWidget(WPrefs
.saveBtn
, 335, 350);
295 WMSetButtonText(WPrefs
.saveBtn
, _("Save"));
296 WMSetButtonAction(WPrefs
.saveBtn
, save
, NULL
);
298 WPrefs
.closeBtn
= WMCreateCommandButton(WPrefs
.win
);
299 WMResizeWidget(WPrefs
.closeBtn
, 80, 28);
300 WMMoveWidget(WPrefs
.closeBtn
, 425, 350);
301 WMSetButtonText(WPrefs
.closeBtn
, _("Close"));
302 WMSetButtonAction(WPrefs
.closeBtn
, quit
, NULL
);
305 WPrefs
.balloonBtn
= WMCreateSwitchButton(WPrefs
.win
);
306 WMResizeWidget(WPrefs
.balloonBtn
, 200, 28);
307 WMMoveWidget(WPrefs
.balloonBtn
, 15, 350);
308 WMSetButtonText(WPrefs
.balloonBtn
, _("Balloon Help"));
309 WMSetButtonAction(WPrefs
.balloonBtn
, toggleBalloons
, NULL
);
311 WMUserDefaults
*udb
= WMGetStandardUserDefaults();
312 Bool flag
= WMGetUDBoolForKey(udb
, "BalloonHelp");
314 WMSetButtonSelected(WPrefs
.balloonBtn
, flag
);
315 WMSetBalloonEnabled(scr
, flag
);
319 WPrefs
.banner
= WMCreateFrame(WPrefs
.win
);
320 WMResizeWidget(WPrefs
.banner
, FRAME_WIDTH
, FRAME_HEIGHT
);
321 WMMoveWidget(WPrefs
.banner
, FRAME_LEFT
, FRAME_TOP
);
322 WMSetFrameRelief(WPrefs
.banner
, WRFlat
);
324 font
= WMCreateFont(scr
, "-*-times-bold-r-*-*-24-*-*-*-*-*-*-*,"
325 "-*-fixed-medium-r-normal-*-24-*");
327 font
= WMBoldSystemFontOfSize(scr
, 24);
328 WPrefs
.nameL
= WMCreateLabel(WPrefs
.banner
);
329 WMSetLabelTextAlignment(WPrefs
.nameL
, WACenter
);
330 WMResizeWidget(WPrefs
.nameL
, FRAME_WIDTH
-20, 30);
331 WMMoveWidget(WPrefs
.nameL
, 10, 25);
332 WMSetLabelFont(WPrefs
.nameL
, font
);
333 WMSetLabelText(WPrefs
.nameL
, _("Window Maker Preferences Utility"));
336 WPrefs
.versionL
= WMCreateLabel(WPrefs
.banner
);
337 WMResizeWidget(WPrefs
.versionL
, FRAME_WIDTH
-20, 20);
338 WMMoveWidget(WPrefs
.versionL
, 10, 65);
339 WMSetLabelTextAlignment(WPrefs
.versionL
, WACenter
);
340 sprintf(buffer
, _("Version %s for Window Maker %s or newer"), WVERSION
,
342 WMSetLabelText(WPrefs
.versionL
, buffer
);
344 WPrefs
.statusL
= WMCreateLabel(WPrefs
.banner
);
345 WMResizeWidget(WPrefs
.statusL
, FRAME_WIDTH
-20, 60);
346 WMMoveWidget(WPrefs
.statusL
, 10, 100);
347 WMSetLabelTextAlignment(WPrefs
.statusL
, WACenter
);
348 WMSetLabelText(WPrefs
.statusL
, _("Starting..."));
350 WPrefs
.creditsL
= WMCreateLabel(WPrefs
.banner
);
351 WMResizeWidget(WPrefs
.creditsL
, FRAME_WIDTH
-20, 60);
352 WMMoveWidget(WPrefs
.creditsL
, 10, FRAME_HEIGHT
-60);
353 WMSetLabelTextAlignment(WPrefs
.creditsL
, WACenter
);
354 WMSetLabelText(WPrefs
.creditsL
, _("Programming/Design: Alfredo K. Kojima\n"
355 "Artwork: Marco van Hylckama Vlieg, Largo et al\n"
356 "More Programming: James Thompson et al"));
359 WMMapSubwidgets(WPrefs
.win
);
361 WMUnmapWidget(WPrefs
.undosBtn
);
362 WMUnmapWidget(WPrefs
.undoBtn
);
363 WMUnmapWidget(WPrefs
.saveBtn
);
368 showPanel(Panel
*panel
)
370 PanelRec
*rec
= (PanelRec
*)panel
;
372 if (!(rec
->callbacks
.flags
& INITIALIZED_PANEL
)) {
373 (*rec
->callbacks
.createWidgets
)(panel
);
374 rec
->callbacks
.flags
|= INITIALIZED_PANEL
;
377 WMSetWindowTitle(WPrefs
.win
, rec
->sectionName
);
379 if (rec
->callbacks
.showPanel
)
380 (*rec
->callbacks
.showPanel
)(panel
);
382 WMMapWidget(rec
->box
);
388 hidePanel(Panel
*panel
)
390 PanelRec
*rec
= (PanelRec
*)panel
;
392 WMUnmapWidget(rec
->box
);
394 if (rec
->callbacks
.hidePanel
)
395 (*rec
->callbacks
.hidePanel
)(panel
);
400 savePanelData(Panel
*panel
)
402 PanelRec
*rec
= (PanelRec
*)panel
;
404 if (rec
->callbacks
.updateDomain
) {
405 (*rec
->callbacks
.updateDomain
)(panel
);
411 changeSection(WMWidget
*self
, void *data
)
413 if (WPrefs
.currentPanel
== data
)
416 if (WPrefs
.currentPanel
== NULL
) {
417 WMDestroyWidget(WPrefs
.nameL
);
418 WMDestroyWidget(WPrefs
.creditsL
);
419 WMDestroyWidget(WPrefs
.versionL
);
420 WMDestroyWidget(WPrefs
.statusL
);
422 WMSetFrameRelief(WPrefs
.banner
, WRGroove
);
424 /* WMMapWidget(WPrefs.undosBtn);
425 WMMapWidget(WPrefs.undoBtn);
427 WMMapWidget(WPrefs
.saveBtn
);
432 if (WPrefs
.currentPanel
)
433 hidePanel(WPrefs
.currentPanel
);
434 WPrefs
.currentPanel
= data
;
440 LocateImage(char *name
)
443 char *tmp
= wmalloc(strlen(name
)+8);
446 sprintf(tmp
, "%s.tiff", name
);
447 path
= WMPathForResourceOfType(tmp
, "tiff");
449 sprintf(tmp
, "%s.xpm", name
);
450 path
= WMPathForResourceOfType(tmp
, "xpm");
454 wwarning(_("could not locate image file %s\n"), name
);
463 makeTitledIcon(WMScreen
*scr
, WMPixmap
*icon
, char *title1
, char *title2
)
465 return WMRetainPixmap(icon
);
469 static XFontStruct
*hfont
= NULL
;
470 static XFontStruct
*vfont
= NULL
;
473 Display
*dpy
= WMScreenDisplay(scr
);
474 WMColor
*black
= WMBlackColor(scr
);
476 WMSize size
= WMGetPixmapSize(icon
);
479 tmp
= WMCreatePixmap(scr
, 60, 60, WMScreenDepth(scr
), True
);
481 pix
= WMGetPixmapXID(tmp
);
482 mask
= WMGetPixmapMaskXID(tmp
);
485 gc
= XCreateGC(dpy
, mask
, 0, NULL
);
487 hfont
= XLoadQueryFont(dpy
, ICON_TITLE_FONT
);
488 vfont
= XLoadQueryFont(dpy
, ICON_TITLE_VFONT
);
492 return WMRetainPixmap(icon
);
495 XSetForeground(dpy
, gc
, 0);
496 XFillRectangle(dpy
, mask
, gc
, 0, 0, 60, 60);
498 fgc
= WMColorGC(black
);
500 XSetForeground(dpy
, gc
, 1);
502 XCopyArea(dpy
, WMGetPixmapXID(icon
), pix
, fgc
, 0, 0,
503 size
.width
, size
.height
, 12, 12);
505 if (WMGetPixmapMaskXID(icon
) != None
)
506 XCopyPlane(dpy
, WMGetPixmapMaskXID(icon
), mask
, gc
, 0, 0,
507 size
.width
, size
.height
, 12, 12, 1);
509 XFillRectangle(dpy
, mask
, gc
, 12, 12, 48, 48);
513 XSetFont(dpy
, fgc
, vfont
->fid
);
514 XSetFont(dpy
, gc
, vfont
->fid
);
516 XDrawString(dpy
, pix
, fgc
, 0, vfont
->ascent
,
517 title1
, strlen(title1
));
519 XDrawString(dpy
, mask
, gc
, 0, vfont
->ascent
,
520 title1
, strlen(title1
));
524 XSetFont(dpy
, fgc
, hfont
->fid
);
525 XSetFont(dpy
, gc
, hfont
->fid
);
527 XDrawString(dpy
, pix
, fgc
, (title1
? 12 : 0), hfont
->ascent
,
528 title2
, strlen(title2
));
530 XDrawString(dpy
, mask
, gc
, (title1
? 12 : 0), hfont
->ascent
,
531 title2
, strlen(title2
));
540 SetButtonAlphaImage(WMScreen
*scr
, WMButton
*bPtr
, char *file
,
541 char *title1
, char *title2
)
548 iconPath
= LocateImage(file
);
555 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
557 wwarning(_("could not load icon file %s"), iconPath
);
563 icon2
= makeTitledIcon(scr
, icon
, title1
, title2
);
565 WMReleasePixmap(icon
);
570 WMSetButtonImage(bPtr
, icon2
);
573 WMReleasePixmap(icon2
);
580 icon
= WMCreateBlendedPixmapFromFile(scr
, iconPath
, &color
);
582 wwarning(_("could not load icon file %s"), iconPath
);
587 WMSetButtonAltImage(bPtr
, icon
);
590 WMReleasePixmap(icon
);
598 AddSection(Panel
*panel
, char *iconFile
)
602 assert(WPrefs
.sectionCount
< MAX_SECTIONS
);
605 bPtr
= WMCreateCustomButton(WPrefs
.buttonF
, WBBStateLightMask
606 |WBBStateChangeMask
);
607 WMResizeWidget(bPtr
, 64, 64);
608 WMMoveWidget(bPtr
, WPrefs
.sectionCount
*64, 0);
609 WMSetButtonImagePosition(bPtr
, WIPImageOnly
);
610 WMSetButtonAction(bPtr
, changeSection
, panel
);
611 WMHangData(bPtr
, panel
);
613 WMSetBalloonTextForView(((PanelRec
*)panel
)->description
,
619 t1
= wstrdup(((PanelRec
*)panel
)->sectionName
);
620 t2
= strchr(t1
, ' ');
625 SetButtonAlphaImage(WMWidgetScreen(bPtr
), bPtr
, iconFile
,
631 WPrefs
.sectionB
[WPrefs
.sectionCount
] = bPtr
;
633 if (WPrefs
.sectionCount
> 0) {
634 WMGroupButtons(WPrefs
.sectionB
[0], bPtr
);
637 WPrefs
.sectionCount
++;
639 WMResizeWidget(WPrefs
.buttonF
, WPrefs
.sectionCount
*64, 64);
644 Initialize(WMScreen
*scr
)
652 list
= RSupportedFileFormats();
653 for (i
=0; list
[i
]!=NULL
; i
++) {
654 if (strcmp(list
[i
], "TIFF")==0) {
661 path
= WMPathForResourceOfType("WPrefs.tiff", NULL
);
663 path
= WMPathForResourceOfType("WPrefs.xpm", NULL
);
667 tmp
= RLoadImage(WMScreenRContext(scr
), path
, 0);
669 wwarning(_("could not load image file %s:%s"), path
,
670 RMessageForError(RErrorCode
));
672 icon
= WMCreatePixmapFromRImage(scr
, tmp
, 0);
675 WMSetApplicationIconPixmap(scr
, icon
);
676 WMReleasePixmap(icon
);
682 memset(&WPrefs
, 0, sizeof(_WPrefs
));
683 createMainWindow(scr
);
685 WMRealizeWidget(WPrefs
.win
);
686 WMMapWidget(WPrefs
.win
);
687 XFlush(WMScreenDisplay(scr
));
688 WMSetLabelText(WPrefs
.statusL
, _("Loading Window Maker configuration files..."));
689 XFlush(WMScreenDisplay(scr
));
690 loadConfigurations(scr
, WPrefs
.win
);
692 WMSetLabelText(WPrefs
.statusL
, _("Initializing configuration panels..."));
694 InitFocus(scr
, WPrefs
.banner
);
695 InitWindowHandling(scr
, WPrefs
.banner
);
697 InitMenuPreferences(scr
, WPrefs
.banner
);
698 InitIcons(scr
, WPrefs
.banner
);
699 InitPreferences(scr
, WPrefs
.banner
);
701 InitPaths(scr
, WPrefs
.banner
);
702 InitWorkspace(scr
, WPrefs
.banner
);
703 InitConfigurations(scr
, WPrefs
.banner
);
705 InitMenu(scr
, WPrefs
.banner
);
707 #ifdef not_yet_fully_implemented
708 InitKeyboardSettings(scr
, WPrefs
.banner
);
710 InitKeyboardShortcuts(scr
, WPrefs
.banner
);
711 InitMouseSettings(scr
, WPrefs
.banner
);
713 InitAppearance(scr
, WPrefs
.banner
);
716 InitFont(scr
, WPrefs
.banner
);
718 #ifdef not_yet_fully_implemented
719 InitThemes(scr
, WPrefs
.banner
);
721 InitExpert(scr
, WPrefs
.banner
);
723 WMRealizeWidget(WPrefs
.scrollV
);
725 WMSetLabelText(WPrefs
.statusL
,
726 _("WPrefs is free software and is distributed WITHOUT ANY\n"
727 "WARRANTY under the terms of the GNU General Public License."));
732 GetWindow(Panel
*panel
)
739 loadConfigurations(WMScreen
*scr
, WMWindow
*mainw
)
748 path
= wdefaultspathfordomain("WindowMaker");
750 db
= PLGetProplistWithPath(path
);
752 if (!PLIsDictionary(db
)) {
755 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), path
);
756 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
759 sprintf(mbuf
, _("Could not load Window Maker domain (%s) from defaults database."),
761 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
765 path
= getenv("WMAKER_BIN_NAME");
771 command
= wstrconcat(path
, " --version");
772 file
= popen(command
, "r");
775 if (!file
|| !fgets(buffer
, 1023, file
)) {
776 wsyserror(_("could not extract version information from Window Maker"));
777 wfatal(_("Make sure wmaker is in your search path."));
779 WMRunAlertPanel(scr
, mainw
, _("Error"),
780 _("Could not extract version from Window Maker. Make sure it is correctly installed and is in your PATH environment variable."),
781 _("OK"), NULL
, NULL
);
787 if (sscanf(buffer
, "Window Maker %i.%i.%i",&v1
,&v2
,&v3
)!=3
788 && sscanf(buffer
, "WindowMaker %i.%i.%i",&v1
,&v2
,&v3
)!=3) {
789 WMRunAlertPanel(scr
, mainw
, _("Error"),
790 _("Could not extract version from Window Maker. "
791 "Make sure it is correctly installed and the path "
792 "where it installed is in the PATH environment "
793 "variable."), _("OK"), NULL
, NULL
);
796 if (v1
== 0 && (v2
< 18 || v3
< 0)) {
797 sprintf(mbuf
, _("WPrefs only supports Window Maker 0.18.0 or newer.\n"
798 "The version installed is %i.%i.%i\n"), v1
, v2
, v3
);
799 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
803 if (v1
> 1 || (v1
== 1 && (v2
> 0))) {
804 sprintf(mbuf
, _("Window Maker %i.%i.%i, which is installed in your system, is not fully supported by this version of WPrefs."),
806 WMRunAlertPanel(scr
, mainw
, _("Warning"), mbuf
, _("OK"), NULL
, NULL
);
812 command
= wstrconcat(path
, " --global_defaults_path");
813 file
= popen(command
, "r");
816 if (!file
|| !fgets(buffer
, 1023, file
)) {
817 wsyserror(_("could not run \"%s --global_defaults_path\"."), path
);
821 ptr
= strchr(buffer
, '\n');
824 strcat(buffer
, "/WindowMaker");
830 gdb
= PLGetProplistWithPath(buffer
);
832 if (!PLIsDictionary(gdb
)) {
835 sprintf(mbuf
, _("Window Maker domain (%s) is corrupted!"), buffer
);
836 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
839 sprintf(mbuf
, _("Could not load global Window Maker domain (%s)."),
841 WMRunAlertPanel(scr
, mainw
, _("Error"), mbuf
, _("OK"), NULL
, NULL
);
845 db
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
848 gdb
= PLMakeDictionaryFromEntries(NULL
, NULL
, NULL
);
858 GetObjectForKey(char *defaultName
)
860 proplist_t object
= NULL
;
861 proplist_t key
= PLMakeString(defaultName
);
863 object
= PLGetDictionaryEntry(WindowMakerDB
, key
);
865 object
= PLGetDictionaryEntry(GlobalDB
, key
);
874 SetObjectForKey(proplist_t object
, char *defaultName
)
876 proplist_t key
= PLMakeString(defaultName
);
878 PLInsertDictionaryEntry(WindowMakerDB
, key
, object
);
884 RemoveObjectForKey(char *defaultName
)
886 proplist_t key
= PLMakeString(defaultName
);
888 PLRemoveDictionaryEntry(WindowMakerDB
, key
);
895 GetStringForKey(char *defaultName
)
899 val
= GetObjectForKey(defaultName
);
904 if (!PLIsString(val
))
907 return PLGetString(val
);
913 GetArrayForKey(char *defaultName
)
917 val
= GetObjectForKey(defaultName
);
930 GetDictionaryForKey(char *defaultName
)
934 val
= GetObjectForKey(defaultName
);
939 if (!PLIsDictionary(val
))
947 GetIntegerForKey(char *defaultName
)
953 val
= GetObjectForKey(defaultName
);
958 if (!PLIsString(val
))
961 str
= PLGetString(val
);
965 if (sscanf(str
, "%i", &value
)!=1)
973 GetBoolForKey(char *defaultName
)
978 str
= GetStringForKey(defaultName
);
983 if (sscanf(str
, "%i", &value
)==1 && value
!=0)
986 if (strcasecmp(str
, "YES")==0)
989 if (strcasecmp(str
, "Y")==0)
997 SetIntegerForKey(int value
, char *defaultName
)
1002 sprintf(buffer
, "%i", value
);
1003 object
= PLMakeString(buffer
);
1005 SetObjectForKey(object
, defaultName
);
1012 SetStringForKey(char *value
, char *defaultName
)
1016 object
= PLMakeString(value
);
1018 SetObjectForKey(object
, defaultName
);
1024 SetBoolForKey(Bool value
, char *defaultName
)
1026 static proplist_t yes
= NULL
, no
= NULL
;
1029 yes
= PLMakeString("YES");
1030 no
= PLMakeString("NO");
1033 SetObjectForKey(value
? yes
: no
, defaultName
);
1038 SetSpeedForKey(int speed
, char *defaultName
)
1063 SetStringForKey(str
, defaultName
);
1068 GetSpeedForKey(char *defaultName
)
1073 str
= GetStringForKey(defaultName
);
1077 if (strcasecmp(str
, "ultraslow")==0)
1079 else if (strcasecmp(str
, "slow")==0)
1081 else if (strcasecmp(str
, "medium")==0)
1083 else if (strcasecmp(str
, "fast")==0)
1085 else if (strcasecmp(str
, "ultrafast")==0)
1088 wwarning(_("bad speed value for option %s\n. Using default Medium"),