Change to the linux kernel coding style
[wmaker-crm.git] / WINGs / configuration.c
1
2 #include "WINGsP.h"
3 #include "wconfig.h"
4
5 #include <X11/Xlocale.h>
6
7 _WINGsConfiguration WINGsConfiguration;
8
9 #define SYSTEM_FONT "Trebuchet MS,Luxi Sans"
10 #define BOLD_SYSTEM_FONT "Trebuchet MS,Luxi Sans:bold"
11 #define DEFAULT_FONT_SIZE 12
12
13 #define FLOPPY_PATH "/floppy"
14
15 static unsigned getButtonWithName(const char *name, unsigned defaultButton)
16 {
17 if (strncmp(name, "Button", 6) == 0 && strlen(name) == 7) {
18 switch (name[6]) {
19 case '1':
20 return Button1;
21 case '2':
22 return Button2;
23 case '3':
24 return Button3;
25 case '4':
26 return Button4;
27 case '5':
28 return Button5;
29 default:
30 break;
31 }
32 }
33
34 return defaultButton;
35 }
36
37 void W_ReadConfigurations(void)
38 {
39 WMUserDefaults *defaults;
40
41 memset(&WINGsConfiguration, 0, sizeof(_WINGsConfiguration));
42
43 defaults = WMGetStandardUserDefaults();
44
45 if (defaults) {
46 char *buttonName;
47 unsigned button;
48
49 WINGsConfiguration.systemFont = WMGetUDStringForKey(defaults, "SystemFont");
50
51 WINGsConfiguration.boldSystemFont = WMGetUDStringForKey(defaults, "BoldSystemFont");
52
53 WINGsConfiguration.antialiasedText = WMGetUDBoolForKey(defaults, "AntialiasedText");
54
55 WINGsConfiguration.doubleClickDelay = WMGetUDIntegerForKey(defaults, "DoubleClickTime");
56
57 WINGsConfiguration.floppyPath = WMGetUDStringForKey(defaults, "FloppyPath");
58
59 buttonName = WMGetUDStringForKey(defaults, "MouseWheelUp");
60 if (buttonName) {
61 button = getButtonWithName(buttonName, Button4);
62 wfree(buttonName);
63 } else {
64 button = Button4;
65 }
66 WINGsConfiguration.mouseWheelUp = button;
67
68 buttonName = WMGetUDStringForKey(defaults, "MouseWheelDown");
69 if (buttonName) {
70 button = getButtonWithName(buttonName, Button5);
71 wfree(buttonName);
72 } else {
73 button = Button5;
74 }
75 WINGsConfiguration.mouseWheelDown = button;
76
77 if (WINGsConfiguration.mouseWheelDown == WINGsConfiguration.mouseWheelUp) {
78 WINGsConfiguration.mouseWheelUp = Button4;
79 WINGsConfiguration.mouseWheelDown = Button5;
80 }
81
82 WINGsConfiguration.defaultFontSize = WMGetUDIntegerForKey(defaults, "DefaultFontSize");
83 }
84
85 if (!WINGsConfiguration.systemFont) {
86 WINGsConfiguration.systemFont = SYSTEM_FONT;
87 }
88 if (!WINGsConfiguration.boldSystemFont) {
89 WINGsConfiguration.boldSystemFont = BOLD_SYSTEM_FONT;
90 }
91 if (WINGsConfiguration.defaultFontSize == 0) {
92 WINGsConfiguration.defaultFontSize = DEFAULT_FONT_SIZE;
93 }
94 if (!WINGsConfiguration.floppyPath) {
95 WINGsConfiguration.floppyPath = FLOPPY_PATH;
96 }
97 if (WINGsConfiguration.doubleClickDelay == 0) {
98 WINGsConfiguration.doubleClickDelay = 250;
99 }
100 if (WINGsConfiguration.mouseWheelUp == 0) {
101 WINGsConfiguration.mouseWheelUp = Button4;
102 }
103 if (WINGsConfiguration.mouseWheelDown == 0) {
104 WINGsConfiguration.mouseWheelDown = Button5;
105 }
106
107 }