Blame examples/gconf-proxy-service2.py

Packit 130fc8
#!/usr/bin/env python
Packit 130fc8
Packit 130fc8
# Example of implementing an entire subtree of objects using
Packit 130fc8
# a FallbackObject.
Packit 130fc8
#
Packit 130fc8
# This is not a particularly realistic example of real-world code any more,
Packit 130fc8
# because GConf now uses D-Bus internally itself, and is deprecated;
Packit 130fc8
# but it's a valid example of a FallbackObject.
Packit 130fc8
Packit 130fc8
# Copyright (C) 2004-2006 Red Hat Inc. <http://www.redhat.com/>
Packit 130fc8
# Copyright (C) 2005-2007 Collabora Ltd. <http://www.collabora.co.uk/>
Packit 130fc8
#
Packit 130fc8
# Permission is hereby granted, free of charge, to any person
Packit 130fc8
# obtaining a copy of this software and associated documentation
Packit 130fc8
# files (the "Software"), to deal in the Software without
Packit 130fc8
# restriction, including without limitation the rights to use, copy,
Packit 130fc8
# modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 130fc8
# of the Software, and to permit persons to whom the Software is
Packit 130fc8
# furnished to do so, subject to the following conditions:
Packit 130fc8
#
Packit 130fc8
# The above copyright notice and this permission notice shall be
Packit 130fc8
# included in all copies or substantial portions of the Software.
Packit 130fc8
#
Packit 130fc8
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 130fc8
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 130fc8
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 130fc8
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 130fc8
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
Packit 130fc8
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Packit 130fc8
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
Packit 130fc8
# DEALINGS IN THE SOFTWARE.
Packit 130fc8
Packit 130fc8
import dbus
Packit 130fc8
import dbus.mainloop.glib
Packit 130fc8
import dbus.service
Packit 130fc8
Packit 130fc8
from gi.repository import GLib
Packit 130fc8
import gconf
Packit 130fc8
Packit 130fc8
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
Packit 130fc8
Packit 130fc8
# there is a real service called "org.gnome.GConf"; don't collide with it.
Packit 130fc8
name = dbus.service.BusName("com.example.GConfProxy", dbus.SessionBus())
Packit 130fc8
Packit 130fc8
class GConfObject(dbus.service.FallbackObject):
Packit 130fc8
    def __init__(self):
Packit 130fc8
        dbus.service.FallbackObject.__init__(self, dbus.SessionBus(), '/org/gnome/GConf')
Packit 130fc8
        self.client = gconf.client_get_default()
Packit 130fc8
Packit 130fc8
    @dbus.service.method("org.gnome.GConf", in_signature='', out_signature='s', rel_path_keyword='object_path')
Packit 130fc8
    def getString(self, object_path):
Packit 130fc8
        return self.client.get_string(object_path)
Packit 130fc8
Packit 130fc8
    @dbus.service.method("org.gnome.GConf", in_signature='s', out_signature='', rel_path_keyword='object_path')
Packit 130fc8
    def setString(self, value, object_path):
Packit 130fc8
        self.client.set_string(object_path, value)
Packit 130fc8
Packit 130fc8
    @dbus.service.method("org.gnome.GConf", in_signature='', out_signature='i', rel_path_keyword='object_path')
Packit 130fc8
    def getInt(self, object_path):
Packit 130fc8
        return self.client.get_int(object_path)
Packit 130fc8
Packit 130fc8
    @dbus.service.method("org.gnome.GConf", in_signature='i', out_signature='', rel_path_keyword='object_path')
Packit 130fc8
    def setInt(self, value, object_path):
Packit 130fc8
        self.client.set_int(object_path, value)
Packit 130fc8
Packit 130fc8
gconf_service = GConfObject()
Packit 130fc8
Packit 130fc8
print ("GConf Proxy service started.")
Packit 130fc8
print ("Run 'gconf-proxy-client.py' to fetch a GConf key through the proxy...")
Packit 130fc8
Packit 130fc8
mainloop = GLib.MainLoop()
Packit 130fc8
mainloop.run()