def _set_pref(key, setter_name, value): gconf_lock.acquire() try: client = gconf.client_get_default() fullkey = gconf_key(key) setter = getattr(client, setter_name) setter(fullkey, value) finally: gconf_lock.release()
def _get_pref(key, getter_name): gconf_lock.acquire() try: client = gconf.client_get_default() fullkey = gconf_key(key) value = client.get(fullkey) if value is not None: getter = getattr(value, getter_name) return getter() else: return None finally: gconf_lock.release()
def _disassociate_protocol(name, command): url_handlers_key = "/desktop/gnome/url-handlers/" + name + "/" if _is_associated(name, command): gconf_lock.acquire() try: gconf_client = gconf.client_get_default() if gconf_client.set_bool(url_handlers_key + "enabled", False): success = True else: success = False finally: gconf_lock.release() else: success = True return success
def _associate_protocol(name, command, overwrite_existing=False): url_handlers_key = "/desktop/gnome/url-handlers/" + name + "/" if not _is_associated(name) or overwrite_existing: gconf_lock.acquire() try: gconf_client = gconf.client_get_default() if gconf_client.set_string(url_handlers_key + "command", command): gconf_client.set_bool(url_handlers_key + "needs_terminal", False) gconf_client.set_bool(url_handlers_key + "enabled", True) success = True else: success = False finally: gconf_lock.release() else: success = True return success
def _is_associated(protocol, command=None): """ Checks whether a protocol currently is associated with the given command, or, if none is given, whether the protocol is associated with anything at all. """ url_handlers_key = "/desktop/gnome/url-handlers/" + protocol + "/" gconf_lock.acquire() try: gconf_client = gconf.client_get_default() key = gconf_client.get(url_handlers_key + "command") if key is None: associated = False else: enabled = gconf_client.get(url_handlers_key + "enabled") if command: associated = key.get_string() == command and enabled.get_bool() else: associated = key.get_string() != "" and enabled.get_bool() finally: gconf_lock.release() return associated