Welcome to mirror list, hosted at ThFree Co, Russian Federation.

plugin.py « gnome_session_manager - dev.gajim.org/gajim/gajim-plugins.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ea0f3cb3852c57adadfbea457902daee5bb09ed7 (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
# -*- coding: utf-8 -*-

## Copyright (C) 2010 Philippe Normand <phil@base-art.net>
##
## This file is part of Gajim.
##
## Gajim is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation; version 3 only.
##
## Gajim 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 General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Gajim.  If not, see <http://www.gnu.org/licenses/>.
##

import dbus
from common import gajim
from common import ged
from common import dbus_support
import gui_interface
from plugins import GajimPlugin
from plugins.helpers import log_calls, log

GNOME_STATUS = [u'online', u'invisible', u'dnd', u'idle']
PRESENCE_INTERFACE = "org.gnome.SessionManager.Presence"

class GnomeSessionManagerPlugin(GajimPlugin):

    @log_calls('GnomeSessionManagerPlugin')
    def init(self):
        self.description = _('Set and react on GNOME Session presence settings')
        self.config_dialog = None
        self.events_handlers = {}

    @log_calls('GnomeSessionManagerPlugin')
    def activate(self):
        if not dbus_support.supported:
            return

        self.bus = dbus_support.session_bus.SessionBus()
        try:
            self.session_presence = self.bus.get_object("org.gnome.SessionManager",
                                                        "/org/gnome/SessionManager/Presence")
        except:
            gajim.log.debug("GNOME SessionManager D-Bus service not found")
            return

        self.active = True
        gajim.ged.register_event_handler('our-show', ged.POSTGUI,
                                         self.on_our_status)
        self.bus.add_signal_receiver(self.gnome_presence_changed,
                                     "StatusChanged", PRESENCE_INTERFACE)

    @log_calls('GnomeSessionManagerPlugin')
    def deactivate(self):
        if not dbus_support.supported or not self.active:
            return

        self.active = False
        self.bus.remove_signal_receiver(self.gnome_presence_changed, "StatusChanged",
                                        dbus_interface=PRESENCE_INTERFACE)
        gajim.ged.remove_event_handler('our-show', ged.POSTGUI, self.on_our_status)


    def gnome_presence_changed(self, status, *args, **kw):
        if not gajim.interface.remote_ctrl:
            try:
                import remote_control
                gajim.interface.remote_ctrl = remote_control.Remote()
            except:
                return
        remote_gajim = gajim.interface.remote_ctrl.signal_object
        gajim_status = GNOME_STATUS[status]
        accounts = remote_gajim.list_accounts()
        for account in accounts:
            message = remote_gajim.get_status_message(account)
            remote_gajim.change_status(gajim_status, message, account)

    def on_our_status(self, network_event):
        try:
            gnome_status = GNOME_STATUS.index(network_event.show)
        except ValueError:
            print "GNOME SessionManager doesn't support %r status" % network_event.show
        else:
            self.session_presence.SetStatus(dbus.UInt32(gnome_status),
                                            dbus_interface=PRESENCE_INTERFACE)