1
/* finddefault.c -- find_default_device() implementation
2
Roger Dannenberg, June 2008
8
#include "pmmacosxcm.h"
9
#include "readbinaryplist.h"
11
/* Parse preference files, find default device, search devices --
12
This parses the preference file(s) once for input and once for
13
output, which is inefficient but much simpler to manage. Note
14
that using the readbinaryplist.c module, you cannot keep two
15
plist files (user and system) open at once (due to a simple
16
memory management scheme).
18
PmDeviceID find_default_device(char *path, int input, PmDeviceID id)
19
/* path -- the name of the preference we are searching for
20
input -- true iff this is an input device
21
id -- current default device id
22
returns matching device id if found, otherwise id
25
static char *pref_file = "com.apple.java.util.prefs.plist";
26
char *pref_str = NULL;
27
// read device preferences
28
value_ptr prefs = bplist_read_user_pref(pref_file);
30
value_ptr pref_val = value_dict_lookup_using_path(prefs, path);
32
pref_str = value_get_asciistring(pref_val);
36
bplist_free_data(); /* look elsewhere */
37
prefs = bplist_read_system_pref(pref_file);
39
value_ptr pref_val = value_dict_lookup_using_path(prefs, path);
41
pref_str = value_get_asciistring(pref_val);
45
if (pref_str) { /* search devices for match */
46
int i = pm_find_default_device(pref_str, input);
47
if (i != pmNoDevice) {