summaryrefslogtreecommitdiffstats
path: root/ibus/factory.py
blob: 82751bacf0233077f27d72d0270ed7c50339c4d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# vim:set et sts=4 sw=4:
#
# ibus - The Input Bus
#
# Copyright (c) 2007-2008 Huang Peng <shawn.p.huang@gmail.com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA  02111-1307  USA

__all__ = (
        "EngineFactoryBase",
        "FactoryInfo"
    )
import dbus
import object
import interface
from serializable import *
from exception import *

class EngineFactoryBase(object.Object):
    def __init__(self, bus):
        super(EngineFactoryBase, self).__init__()
        self.__proxy = EngineFactoryProxy (self, bus.get_dbusconn(), "/org/freedesktop/IBus/Factory")
        self.__bus = bus

    def initialize(self):
        pass

    def uninitialize(self):
        pass

    def create_engine(self, engine_name):
        raise IBusException("Can not create engine %s" % engine_name)

    def do_destroy(self):
        self.__proxy = None
        self.__bus = None
        super(EngineFactoryBase, self).do_destroy()


class EngineFactoryProxy(interface.IEngineFactory):
    def __init__(self, factory, conn, object_path):
        super(EngineFactoryProxy, self).__init__(conn, object_path)
        self.__factory = factory

    def GetInfo(self):
        return self.__factory.get_info()

    def Initialize(self):
        return self.__factory.initialize()

    def Uninitialize(self):
        return self.__factory.uninitialize()

    def CreateEngine(self, engine_name):
        engine = self.__factory.create_engine(engine_name)
        return engine.get_dbus_object()

    def Destroy(self):
        self.__factory.destroy()
        self.__factory = None
        self.remove_from_connection ()

class FactoryInfo(Serializable):
    __NAME__ = "IBusFactoryInfo"
    def __init__ (self, path=None, name=None, lang=None, icon=None, authors=None, credits=None):
        super(FactoryInfo, self).__init__()
        self.__path = path
        self.__name = name
        self.__lang = lang
        self.__icon = icon
        self.__authors = authors
        self.__credits = credits

    def get_path(self):
        return self.__path

    def get_name(self):
        return self.__name

    def get_lang(self):
        return self.__lang

    def get_icon(self):
        return self.__icon
    def get_authors(self):
        return self.__authors

    def get_credits(self):
        return self.__credits

    path = property(get_path)
    name = property(get_name)
    lang = property(get_lang)
    icon = property(get_icon)
    authors = property(get_authors)
    credits = property(get_credits)

    def serialize(self, struct):
        super(FactoryInfo, self).serialize(struct)
        struct.append (dbus.ObjectPath(self.__path))
        struct.append (dbus.String(self.__name))
        struct.append (dbus.String(self.__lang))
        struct.append (dbus.String(self.__icon))
        struct.append (dbus.String(self.__authors))
        struct.append (dbus.String(self.__credits))

    def deserialize(self, struct):
        super(FactoryInfo, self).deserialize(struct)
        if len(struct) < 5:
            raise IBusException ("Can not deserialize IBusFactoryInfo")

        self.__path = struct.pop(0)
        self.__name = struct.pop(0)
        self.__lang = struct.pop(0)
        self.__icon = struct.pop(0)
        self.__authors = struct.pop(0)
        self.__credits = struct.pop(0)

serializable_register(FactoryInfo)