For libwraster:
[wmaker-crm.git] / WPrefs.app / WPrefs.c
bloba2ceb4e8385b66d9b79898ee7264c17d4faeec34
1 /* WPrefs.c- main window and other basic stuff
2 *
3 * WPrefs - Window Maker Preferences Program
4 *
5 * Copyright (c) 1998-2000 Alfredo K. Kojima
6 *
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,
20 * USA.
24 #include "WPrefs.h"
25 #include <assert.h>
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 {
71 WMWindow *win;
73 WMScrollView *scrollV;
74 WMFrame *buttonF;
75 WMButton *sectionB[MAX_SECTIONS];
77 int sectionCount;
79 WMButton *saveBtn;
80 WMButton *closeBtn;
81 WMButton *undoBtn;
82 WMButton *undosBtn;
84 WMButton *balloonBtn;
86 WMFrame *banner;
87 WMLabel *nameL;
88 WMLabel *versionL;
89 WMLabel *creditsL;
90 WMLabel *statusL;
92 Panel *currentPanel;
93 } _WPrefs;
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();
118 void
119 quit(WMWidget *w, void *data)
121 prepareForClose();
123 exit(0);
127 static void
128 save(WMWidget *w, void *data)
130 int i;
131 proplist_t p1, p2;
132 proplist_t keyList;
133 proplist_t key;
134 char *msg = "Reconfigure";
135 XEvent ev;
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);
154 if (!p1)
155 continue;
156 /* The global doesn't have it, so no problem either. */
157 p2 = PLGetDictionaryEntry(GlobalDB, key);
158 if (!p2)
159 continue;
160 /* If both values are the same, don't save. */
161 if (PLIsEqual(p1, p2))
162 PLRemoveDictionaryEntry(WindowMakerDB, key);
164 /* puts(PLGetDescription(WindowMakerDB));*/
165 PLRelease(keyList);
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)));
190 static void
191 undo(WMWidget *w, void *data)
193 PanelRec *rec = (PanelRec*)WPrefs.currentPanel;
195 if (!rec)
196 return;
198 if (rec->callbacks.undoChanges
199 && (rec->callbacks.flags & INITIALIZED_PANEL)) {
200 (*rec->callbacks.undoChanges)(WPrefs.currentPanel);
205 static void
206 undoAll(WMWidget *w, void *data)
208 int i;
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);
221 static void
222 prepareForClose()
224 int i;
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);
236 void
237 toggleBalloons(WMWidget *w, void *data)
239 WMUserDefaults *udb = WMGetStandardUserDefaults();
240 Bool flag;
242 flag = WMGetButtonSelected(WPrefs.balloonBtn);
244 WMSetBalloonEnabled(WMWidgetScreen(WPrefs.win), flag);
246 WMSetUDBoolForKey(udb, flag, "BalloonHelp");
250 static void
251 createMainWindow(WMScreen *scr)
253 WMScroller *scroller;
254 WMFont *font;
255 char buffer[128];
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);
318 /* banner */
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-*");
326 if (!font)
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"));
334 WMReleaseFont(font);
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,
341 WMVERSION);
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);
367 static void
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);
387 static void
388 hidePanel(Panel *panel)
390 PanelRec *rec = (PanelRec*)panel;
392 WMUnmapWidget(rec->box);
394 if (rec->callbacks.hidePanel)
395 (*rec->callbacks.hidePanel)(panel);
399 static void
400 savePanelData(Panel *panel)
402 PanelRec *rec = (PanelRec*)panel;
404 if (rec->callbacks.updateDomain) {
405 (*rec->callbacks.updateDomain)(panel);
410 static void
411 changeSection(WMWidget *self, void *data)
413 if (WPrefs.currentPanel == data)
414 return;
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);
430 showPanel(data);
432 if (WPrefs.currentPanel)
433 hidePanel(WPrefs.currentPanel);
434 WPrefs.currentPanel = data;
439 char*
440 LocateImage(char *name)
442 char *path;
443 char *tmp = wmalloc(strlen(name)+8);
445 if (TIFFOK) {
446 sprintf(tmp, "%s.tiff", name);
447 path = WMPathForResourceOfType(tmp, "tiff");
448 } else {
449 sprintf(tmp, "%s.xpm", name);
450 path = WMPathForResourceOfType(tmp, "xpm");
452 wfree(tmp);
453 if (!path) {
454 wwarning(_("could not locate image file %s\n"), name);
457 return path;
462 static WMPixmap*
463 makeTitledIcon(WMScreen *scr, WMPixmap *icon, char *title1, char *title2)
465 return WMRetainPixmap(icon);
467 #if 0
468 static GC gc = NULL;
469 static XFontStruct *hfont = NULL;
470 static XFontStruct *vfont = NULL;
471 WMPixmap *tmp;
472 Pixmap pix, mask;
473 Display *dpy = WMScreenDisplay(scr);
474 WMColor *black = WMBlackColor(scr);
475 GC fgc;
476 WMSize size = WMGetPixmapSize(icon);
479 tmp = WMCreatePixmap(scr, 60, 60, WMScreenDepth(scr), True);
481 pix = WMGetPixmapXID(tmp);
482 mask = WMGetPixmapMaskXID(tmp);
484 if (gc == NULL) {
485 gc = XCreateGC(dpy, mask, 0, NULL);
487 hfont = XLoadQueryFont(dpy, ICON_TITLE_FONT);
488 vfont = XLoadQueryFont(dpy, ICON_TITLE_VFONT);
491 if (hfont == NULL) {
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);
508 else
509 XFillRectangle(dpy, mask, gc, 12, 12, 48, 48);
512 if (title1) {
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));
523 if (title2) {
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));
534 return tmp;
535 #endif
539 void
540 SetButtonAlphaImage(WMScreen *scr, WMButton *bPtr, char *file,
541 char *title1, char *title2)
543 WMPixmap *icon;
544 WMPixmap *icon2;
545 RColor color;
546 char *iconPath;
548 iconPath = LocateImage(file);
550 color.red = 0xae;
551 color.green = 0xaa;
552 color.blue = 0xae;
553 color.alpha = 0;
554 if (iconPath) {
555 icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color);
556 if (!icon)
557 wwarning(_("could not load icon file %s"), iconPath);
558 } else {
559 icon = NULL;
562 if (icon) {
563 icon2 = makeTitledIcon(scr, icon, title1, title2);
564 if (icon)
565 WMReleasePixmap(icon);
566 } else {
567 icon2 = NULL;
570 WMSetButtonImage(bPtr, icon2);
572 if (icon2)
573 WMReleasePixmap(icon2);
575 color.red = 0xff;
576 color.green = 0xff;
577 color.blue = 0xff;
578 color.alpha = 0;
579 if (iconPath) {
580 icon = WMCreateBlendedPixmapFromFile(scr, iconPath, &color);
581 if (!icon)
582 wwarning(_("could not load icon file %s"), iconPath);
583 } else {
584 icon = NULL;
587 WMSetButtonAltImage(bPtr, icon);
589 if (icon)
590 WMReleasePixmap(icon);
592 if (iconPath)
593 wfree(iconPath);
597 void
598 AddSection(Panel *panel, char *iconFile)
600 WMButton *bPtr;
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,
614 WMWidgetView(bPtr));
617 char *t1, *t2;
619 t1 = wstrdup(((PanelRec*)panel)->sectionName);
620 t2 = strchr(t1, ' ');
621 if (t2) {
622 *t2 = 0;
623 t2++;
625 SetButtonAlphaImage(WMWidgetScreen(bPtr), bPtr, iconFile,
626 t1, t2);
627 wfree(t1);
629 WMMapWidget(bPtr);
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);
643 void
644 Initialize(WMScreen *scr)
646 char **list;
647 int i;
648 char *path;
649 WMPixmap *icon;
652 list = RSupportedFileFormats();
653 for (i=0; list[i]!=NULL; i++) {
654 if (strcmp(list[i], "TIFF")==0) {
655 TIFFOK = True;
656 break;
660 if (TIFFOK)
661 path = WMPathForResourceOfType("WPrefs.tiff", NULL);
662 else
663 path = WMPathForResourceOfType("WPrefs.xpm", NULL);
664 if (path) {
665 RImage *tmp;
667 tmp = RLoadImage(WMScreenRContext(scr), path, 0);
668 if (!tmp) {
669 wwarning(_("could not load image file %s:%s"), path,
670 RMessageForError(RErrorCode));
671 } else {
672 icon = WMCreatePixmapFromRImage(scr, tmp, 0);
673 RReleaseImage(tmp);
674 if (icon) {
675 WMSetApplicationIconPixmap(scr, icon);
676 WMReleasePixmap(icon);
679 wfree(path);
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);
709 #endif
710 InitKeyboardShortcuts(scr, WPrefs.banner);
711 InitMouseSettings(scr, WPrefs.banner);
713 InitAppearance(scr, WPrefs.banner);
715 #ifdef akk
716 InitFont(scr, WPrefs.banner);
717 #endif
718 #ifdef not_yet_fully_implemented
719 InitThemes(scr, WPrefs.banner);
720 #endif
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."));
731 WMWindow*
732 GetWindow(Panel *panel)
734 return WPrefs.win;
738 static void
739 loadConfigurations(WMScreen *scr, WMWindow *mainw)
741 proplist_t db, gdb;
742 char *path;
743 FILE *file;
744 char buffer[1024];
745 char mbuf[1024];
746 int v1, v2, v3;
748 path = wdefaultspathfordomain("WindowMaker");
750 db = PLGetProplistWithPath(path);
751 if (db) {
752 if (!PLIsDictionary(db)) {
753 PLRelease(db);
754 db = NULL;
755 sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), path);
756 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
758 } else {
759 sprintf(mbuf, _("Could not load Window Maker domain (%s) from defaults database."),
760 path);
761 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
763 wfree(path);
765 path = getenv("WMAKER_BIN_NAME");
766 if (!path)
767 path = "wmaker";
769 char *command;
771 command = wstrconcat(path, " --version");
772 file = popen(command, "r");
773 wfree(command);
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);
782 exit(1);
784 if (file)
785 pclose(file);
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);
794 exit(1);
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);
800 exit(1);
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."),
805 v1, v2, v3);
806 WMRunAlertPanel(scr, mainw, _("Warning"), mbuf, _("OK"), NULL, NULL);
810 char *command;
812 command = wstrconcat(path, " --global_defaults_path");
813 file = popen(command, "r");
814 wfree(command);
816 if (!file || !fgets(buffer, 1023, file)) {
817 wsyserror(_("could not run \"%s --global_defaults_path\"."), path);
818 exit(1);
819 } else {
820 char *ptr;
821 ptr = strchr(buffer, '\n');
822 if (ptr)
823 *ptr = 0;
824 strcat(buffer, "/WindowMaker");
827 if (file)
828 pclose(file);
830 gdb = PLGetProplistWithPath(buffer);
831 if (gdb) {
832 if (!PLIsDictionary(gdb)) {
833 PLRelease(gdb);
834 gdb = NULL;
835 sprintf(mbuf, _("Window Maker domain (%s) is corrupted!"), buffer);
836 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
838 } else {
839 sprintf(mbuf, _("Could not load global Window Maker domain (%s)."),
840 buffer);
841 WMRunAlertPanel(scr, mainw, _("Error"), mbuf, _("OK"), NULL, NULL);
844 if (!db) {
845 db = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
847 if (!gdb) {
848 gdb = PLMakeDictionaryFromEntries(NULL, NULL, NULL);
851 GlobalDB = gdb;
853 WindowMakerDB = db;
857 proplist_t
858 GetObjectForKey(char *defaultName)
860 proplist_t object = NULL;
861 proplist_t key = PLMakeString(defaultName);
863 object = PLGetDictionaryEntry(WindowMakerDB, key);
864 if (!object)
865 object = PLGetDictionaryEntry(GlobalDB, key);
867 PLRelease(key);
869 return object;
873 void
874 SetObjectForKey(proplist_t object, char *defaultName)
876 proplist_t key = PLMakeString(defaultName);
878 PLInsertDictionaryEntry(WindowMakerDB, key, object);
879 PLRelease(key);
883 void
884 RemoveObjectForKey(char *defaultName)
886 proplist_t key = PLMakeString(defaultName);
888 PLRemoveDictionaryEntry(WindowMakerDB, key);
890 PLRelease(key);
894 char*
895 GetStringForKey(char *defaultName)
897 proplist_t val;
899 val = GetObjectForKey(defaultName);
901 if (!val)
902 return NULL;
904 if (!PLIsString(val))
905 return NULL;
907 return PLGetString(val);
912 proplist_t
913 GetArrayForKey(char *defaultName)
915 proplist_t val;
917 val = GetObjectForKey(defaultName);
919 if (!val)
920 return NULL;
922 if (!PLIsArray(val))
923 return NULL;
925 return val;
929 proplist_t
930 GetDictionaryForKey(char *defaultName)
932 proplist_t val;
934 val = GetObjectForKey(defaultName);
936 if (!val)
937 return NULL;
939 if (!PLIsDictionary(val))
940 return NULL;
942 return val;
947 GetIntegerForKey(char *defaultName)
949 proplist_t val;
950 char *str;
951 int value;
953 val = GetObjectForKey(defaultName);
955 if (!val)
956 return 0;
958 if (!PLIsString(val))
959 return 0;
961 str = PLGetString(val);
962 if (!str)
963 return 0;
965 if (sscanf(str, "%i", &value)!=1)
966 return 0;
968 return value;
972 Bool
973 GetBoolForKey(char *defaultName)
975 int value;
976 char *str;
978 str = GetStringForKey(defaultName);
980 if (!str)
981 return False;
983 if (sscanf(str, "%i", &value)==1 && value!=0)
984 return True;
986 if (strcasecmp(str, "YES")==0)
987 return True;
989 if (strcasecmp(str, "Y")==0)
990 return True;
992 return False;
996 void
997 SetIntegerForKey(int value, char *defaultName)
999 proplist_t object;
1000 char buffer[128];
1002 sprintf(buffer, "%i", value);
1003 object = PLMakeString(buffer);
1005 SetObjectForKey(object, defaultName);
1006 PLRelease(object);
1011 void
1012 SetStringForKey(char *value, char *defaultName)
1014 proplist_t object;
1016 object = PLMakeString(value);
1018 SetObjectForKey(object, defaultName);
1019 PLRelease(object);
1023 void
1024 SetBoolForKey(Bool value, char *defaultName)
1026 static proplist_t yes = NULL, no = NULL;
1028 if (!yes) {
1029 yes = PLMakeString("YES");
1030 no = PLMakeString("NO");
1033 SetObjectForKey(value ? yes : no, defaultName);
1037 void
1038 SetSpeedForKey(int speed, char *defaultName)
1040 char *str;
1042 switch (speed) {
1043 case 0:
1044 str = "ultraslow";
1045 break;
1046 case 1:
1047 str = "slow";
1048 break;
1049 case 2:
1050 str = "medium";
1051 break;
1052 case 3:
1053 str = "fast";
1054 break;
1055 case 4:
1056 str = "ultrafast";
1057 break;
1058 default:
1059 str = NULL;
1062 if (str)
1063 SetStringForKey(str, defaultName);
1068 GetSpeedForKey(char *defaultName)
1070 char *str;
1071 int i;
1073 str = GetStringForKey(defaultName);
1074 if (!str)
1075 return 2;
1077 if (strcasecmp(str, "ultraslow")==0)
1078 i = 0;
1079 else if (strcasecmp(str, "slow")==0)
1080 i = 1;
1081 else if (strcasecmp(str, "medium")==0)
1082 i = 2;
1083 else if (strcasecmp(str, "fast")==0)
1084 i = 3;
1085 else if (strcasecmp(str, "ultrafast")==0)
1086 i = 4;
1087 else {
1088 wwarning(_("bad speed value for option %s\n. Using default Medium"),
1089 defaultName);
1090 i = 2;
1092 return i;