2 /* implements Mac OS X specific functions */
3 #include "display-gtk.h"
4 #include <CoreFoundation/CoreFoundation.h>
5 #include <mach-o/dyld.h>
7 static CFURLRef fileURL;
8 static CFPropertyListRef propertyList;
9 static CFMutableDictionaryRef dict = NULL;
11 /* macos defines CFSTR to create a CFString object from a constant,
12 * but no similar macros if a C string variable is supposed to be
13 * the argument. We add this here (hardcoding the default allocator
14 * and MacRoman encoding */
15 #define CFSTR_VAR(_var) CFStringCreateWithCStringNoCopy(kCFAllocatorDefault, \
16 (_var), kCFStringEncodingMacRoman, \
19 void subsurface_open_conf(void)
21 CFStringRef errorString;
22 CFDataRef resourceData;
26 fileURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,
27 CFSTR("subsurface.pref"),// file path name
28 kCFURLPOSIXPathStyle, // interpret as POSIX path
29 false ); // is it a directory?
31 status = CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault,
32 fileURL, &resourceData,
33 NULL, NULL, &errorCode);
35 propertyList = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
36 resourceData, kCFPropertyListImmutable,
38 CFRelease(resourceData);
42 void subsurface_set_conf(char *name, pref_type_t type, const void *value)
45 dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
46 &kCFTypeDictionaryKeyCallBacks,
47 &kCFTypeDictionaryValueCallBacks);
50 CFDictionarySetValue(dict, CFSTR_VAR(name), value == NULL ? CFSTR("0") : CFSTR("1"));
53 CFDictionarySetValue(dict, CFSTR_VAR(name), CFSTR_VAR(value));
56 const void *subsurface_get_conf(char *name, pref_type_t type)
58 CFStringRef dict_entry;
60 /* if no settings exist, we return the value for FALSE */
66 dict_entry = CFDictionaryGetValue(propertyList, CFSTR_VAR(name));
67 if (dict_entry && ! CFStringCompare(CFSTR("1"), dict_entry, 0))
72 return CFStringGetCStringPtr(CFDictionaryGetValue(propertyList,
73 CFSTR_VAR(name)), kCFStringEncodingMacRoman);
75 /* we shouldn't get here, but having this line makes the compiler happy */
79 void subsurface_close_conf(void)
87 xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, propertyList);
88 status = CFURLWriteDataAndPropertiesToResource (fileURL, xmlData, NULL, &errorCode);
89 // some error handling - but really, what can we do?
91 CFRelease(propertyList);
94 const char *subsurface_USB_name()
96 return "/dev/tty.SLAB_USBtoUART";
99 #define REL_ICON_PATH "Resources/Subsurface.icns"
100 const char *subsurface_icon_name()
102 static char path[1024];
104 uint32_t size = sizeof(path); /* need extra space to copy icon path */
105 if (_NSGetExecutablePath(path, &size) == 0) {
106 ptr1 = strcasestr(path,"MacOS/subsurface");
107 ptr2 = strcasestr(path,"Contents");
109 /* we are running as installed app from a bundle */
110 if (ptr1 - path < size - strlen(REL_ICON_PATH)) {
111 strcpy(ptr1,REL_ICON_PATH);
116 return "packaging/macosx/Subsurface.icns";