- Replaced all free() with wfree() where appropriate
[wmaker-crm.git] / WINGs / configuration.c
blob37b7105c834543b8c1b4c7bbad7bad6840b4e1b6
3 #include "WINGsP.h"
5 #include <X11/Xlocale.h>
7 #include <proplist.h>
10 _WINGsConfiguration WINGsConfiguration;
14 #define SYSTEM_FONT "-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-medium-r-*-*-%d-*-*-*-*-*-*-*"
16 #define BOLD_SYSTEM_FONT "-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-*-*,-*-*-bold-r-*-*-%d-*-*-*-*-*-*-*"
18 #define FLOPPY_PATH "/floppy"
21 static unsigned
22 getButtonWithName(const char *name, unsigned defaultButton)
24 if (strncmp(name, "Button", 6)==0 && strlen(name)==7) {
25 switch (name[6]) {
26 case '1':
27 return Button1;
28 case '2':
29 return Button2;
30 case '3':
31 return Button3;
32 case '4':
33 return Button4;
34 case '5':
35 return Button5;
36 default:
37 break;
41 return defaultButton;
45 void
46 W_ReadConfigurations(void)
48 WMUserDefaults *defaults;
50 memset(&WINGsConfiguration, 0, sizeof(_WINGsConfiguration));
52 defaults = WMGetStandardUserDefaults();
54 if (defaults) {
55 char *buttonName;
56 unsigned button;
57 char *str;
59 WINGsConfiguration.systemFont =
60 WMGetUDStringForKey(defaults, "SystemFont");
62 WINGsConfiguration.boldSystemFont =
63 WMGetUDStringForKey(defaults, "BoldSystemFont");
65 WINGsConfiguration.useMultiByte = False;
66 str = WMGetUDStringForKey(defaults, "MultiByteText");
67 if (str) {
68 if (strcasecmp(str, "YES") == 0) {
69 WINGsConfiguration.useMultiByte = True;
70 } else if (strcasecmp(str, "AUTO") == 0) {
71 char *locale;
73 /* if it's a multibyte language (japanese, chinese or korean)
74 * then set it to True */
75 locale = setlocale(LC_CTYPE, NULL);
76 if (locale != NULL
77 && (strncmp(locale, "ja", 2) == 0
78 || strncmp(locale, "zh", 2) == 0
79 || strncmp(locale, "ko", 2) == 0)) {
81 WINGsConfiguration.useMultiByte = True;
86 WINGsConfiguration.doubleClickDelay =
87 WMGetUDIntegerForKey(defaults, "DoubleClickTime");
89 WINGsConfiguration.floppyPath =
90 WMGetUDStringForKey(defaults, "FloppyPath");
92 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
93 if (buttonName) {
94 button = getButtonWithName(buttonName, Button4);
95 wfree(buttonName);
96 } else {
97 button = Button4;
99 WINGsConfiguration.mouseWheelUp = button;
101 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
102 if (buttonName) {
103 button = getButtonWithName(buttonName, Button5);
104 wfree(buttonName);
105 } else {
106 button = Button5;
108 WINGsConfiguration.mouseWheelDown = button;
110 if (WINGsConfiguration.mouseWheelDown==WINGsConfiguration.mouseWheelUp) {
111 WINGsConfiguration.mouseWheelUp = Button4;
112 WINGsConfiguration.mouseWheelDown = Button5;
115 WINGsConfiguration.defaultFontSize =
116 WMGetUDIntegerForKey(defaults, "DefaultFontSize");
120 if (!WINGsConfiguration.systemFont) {
121 WINGsConfiguration.systemFont = SYSTEM_FONT;
123 if (!WINGsConfiguration.boldSystemFont) {
124 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
126 if (!WINGsConfiguration.floppyPath) {
127 WINGsConfiguration.floppyPath = FLOPPY_PATH;
129 if (WINGsConfiguration.doubleClickDelay == 0) {
130 WINGsConfiguration.doubleClickDelay = 250;
132 if (WINGsConfiguration.mouseWheelUp == 0) {
133 WINGsConfiguration.mouseWheelUp = Button4;
135 if (WINGsConfiguration.mouseWheelDown == 0) {
136 WINGsConfiguration.mouseWheelDown = Button5;
138 if (WINGsConfiguration.defaultFontSize == 0) {
139 WINGsConfiguration.defaultFontSize = 12;