2 /* implements Mac OS X specific functions */
3 #include "display-gtk.h"
4 #include <CoreFoundation/CoreFoundation.h>
6 static CFURLRef fileURL;
7 static CFPropertyListRef propertyList;
8 static CFMutableDictionaryRef dict = NULL;
10 /* macos defines CFSTR to create a CFString object from a constant,
11 * but no similar macros if a C string variable is supposed to be
12 * the argument. We add this here (hardcoding the default allocator
13 * and MacRoman encoding */
14 #define CFSTR_VAR(_var) CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, \
15 (_var), kCFStringEncodingMacRoman, \
18 void subsurface_open_conf(void)
20 CFStringRef errorString;
21 CFDataRef resourceData;
25 fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
26 CFSTR("subsurface.pref"),// file path name
27 kCFURLPOSIXPathStyle, // interpret as POSIX path
28 false ); // is it a directory?
30 status = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
31 fileURL, &resourceData,
32 NULL, NULL, &errorCode);
34 propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
35 resourceData, kCFPropertyListImmutable,
37 CFRelease(resourceData);
41 void subsurface_set_conf(char *name, pref_type_t type, const void *value)
44 dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
45 &kCFTypeDictionaryKeyCallBacks,
46 &kCFTypeDictionaryValueCallBacks);
49 CFDictionarySetValue(dict, CFSTR_VAR(name), value == NULL ? CFSTR("0") : CFSTR("1"));
52 CFDictionarySetValue(dict, CFSTR_VAR(name), CFSTR_VAR(value));
55 const void *subsurface_get_conf(char *name, pref_type_t type)
57 CFStringRef dict_entry;
59 /* if no settings exist, we return the value for FALSE */
65 dict_entry = CFDictionaryGetValue(propertyList, CFSTR_VAR(name));
66 if (dict_entry && ! CFStringCompare(CFSTR("1"), dict_entry, 0))
71 return CFStringGetCStringPtr(CFDictionaryGetValue(propertyList,
72 CFSTR_VAR(name)), kCFStringEncodingMacRoman);
74 /* we shouldn't get here, but having this line makes the compiler happy */
78 void subsurface_close_conf(void)
86 xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList);
87 status = CFURLWriteDataAndPropertiesToResource (fileURL, xmlData, NULL, &errorCode);
88 // some error handling - but really, what can we do?
90 CFRelease(propertyList);
93 const char *subsurface_USB_name()
95 return "/dev/tty.SLAB_USBtoUART";