summaryrefslogtreecommitdiff
path: root/examples/python/callhandler.py
blob: f4053b22b861a89f6cefb450c875de64d1f18478 (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
# callhandler.py
# Copyright (C) 2008-2010 Collabora Ltd.
#
# 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.1 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 library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import gi
gi.require_version('TelepathyGLib', '0.12')
from gi.repository import GObject, Gio, TelepathyGLib

from constants import *

from callchannel import CallChannel

class CallHandler(GObject.Object):
    __gsignals__ = {
        'new-channel' : (GObject.SIGNAL_RUN_LAST, None, (object,))
        }

    def __init__(self, bus_name = 'CallDemo'):
        GObject.Object.__init__(self)
        TelepathyGLib.debug_set_flags("all")
        am = TelepathyGLib.AccountManager.dup()
        self.handler = handler = TelepathyGLib.SimpleHandler.new_with_am(
            am, True, False, bus_name, True, self.handle_channels_cb)

        handler.add_handler_filter({
            TelepathyGLib.PROP_CHANNEL_CHANNEL_TYPE: TelepathyGLib.IFACE_CHANNEL_TYPE_CALL,

            TelepathyGLib.PROP_CHANNEL_TARGET_HANDLE_TYPE: int(TelepathyGLib.HandleType.CONTACT)
        })
        self.bus_name = handler.get_bus_name()

        handler.register()

    def handle_channels_cb (self, handler, account, conn, channels,
                            requests_satisfied, user_action_time, context):
        assert len(channels) == 1
        cchannel = CallChannel(conn, channels[0])
        self.emit("new-channel", channels[0])
        context.accept()
        channels[0].accept_async(None)

if __name__ == '__main__':
    GObject.threads_init()
    loop = GObject.MainLoop()
    CallHandler()
    loop.run()