poezio/src/handler.py

145 lines
4.8 KiB
Python
Raw Normal View History

2010-01-10 20:14:17 +00:00
# -*- coding: utf-8 -*-
# Copyright 2009, 2010 Erwan Briand
# Copyright 2010, Florent Le Coz <louizatakk@fedoraproject.org>
# This program 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 of the License.
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
from singleton import Singleton
class Handler(Singleton):
"""
This class is the global handler for the software's signals.
"""
2010-01-10 20:14:17 +00:00
__is_first_instance = True
def __init__(self):
if Handler.__is_first_instance:
Handler.__is_first_instance = False
self.__signals__ = {
'on-connected': list(),
# At the end of a successful connection process.
# emitted when presence confirmation is received
2010-01-10 20:14:17 +00:00
'join-room': list(),
# Join a room.
# Args: room, nick
'room-presence': list(),
# A presence is received
2010-01-10 20:14:17 +00:00
# Args: the stanza object
'room-message': list(),
2010-01-10 20:14:17 +00:00
# A message is received
# Args: the stanza object
# 'xmpp-presence-handler': list(),
# # A presence is received
# # Args: the stanza object
2010-01-10 20:14:17 +00:00
# 'xmpp-iq-handler': list(),
# # An iq is received
# # Args: the stanza object
2010-01-10 20:14:17 +00:00
# 'xmpp-message-handler': list(),
# # A message is received
# # Args: the stanza object
2010-01-10 20:14:17 +00:00
# # - GUI event
2010-01-10 20:14:17 +00:00
# 'on-quit': list(),
# # When the user wants to quit.
2010-01-10 20:14:17 +00:00
# # - Roster and presence
2010-01-10 20:14:17 +00:00
# 'on-disconnected': list(),
# # When the user is disconnected from the server.
2010-01-10 20:14:17 +00:00
# 'on-message-received': list(),
# # When a message is received.
# # Args: jid, msg, subject, typ
2010-01-10 20:14:17 +00:00
# 'send-message': list(),
# # Send a message to someone.
# # Args: jid, msg, subj, typ
2010-01-10 20:14:17 +00:00
# # - vCard (XEP-0054)
2010-01-10 20:14:17 +00:00
# 'vcard-request': list(),
# # Request a vcard.
# # Args: jid
2010-01-10 20:14:17 +00:00
# 'on-vcard-received': list(),
# # When a vcard is received.
# # Args: jid, vcard
2010-01-10 20:14:17 +00:00
# # - Multi-User Chat (XEP-0045)
2010-01-10 20:14:17 +00:00
# 'gui-join-room': list(),
# # Join a room inside the GUI (call `join-room`).
# # Args: room, nickname
2010-01-10 20:14:17 +00:00
# 'quit-room': list(),
# # Quit a room.
# # Args: room, nick
2010-01-10 20:14:17 +00:00
# 'on-muc-message-received': list(),
# # When a message is received.
# # Args: jid, msg, subject, typ, stanza
2010-01-10 20:14:17 +00:00
# 'on-muc-presence-changed': list(),
# # When someone in the roster changes his presence.
# # Args: jid, priority, show, status, stanza
2010-01-10 20:14:17 +00:00
# 'on-muc-error': list(),
# # When the MUC composant sends an error
# # Args: room, code, msg
2010-01-10 20:14:17 +00:00
# 'eject-user': list(),
# # When the user try to eject another one.
# # Args: room, action, nick, reason
2010-01-10 20:14:17 +00:00
# 'change-user-role': list(),
# # When the user try to change the role of someone.
# # Args: room, nick, role
2010-01-10 20:14:17 +00:00
# 'change-user-affiliation': list(),
# # When the user try to change the affiliation of someone.
# # Args: room, jid, aff
2010-01-10 20:14:17 +00:00
# 'change-subject': list(),
# # When the user try to change the topic.
# # Args: room, subject
# 'change-nick': list()
# # When the user try to change his nick.
# # Args: room, nick
2010-01-10 20:14:17 +00:00
}
def connect(self, signal, func):
"""Connect a function to a signal."""
if func not in self.__signals__[signal]:
self.__signals__[signal].append(func)
else:
print "signal %s doesn't exist." % signal
2010-01-10 20:14:17 +00:00
def emit(self, signal, **kwargs):
"""Emit a signal."""
if self.__signals__.has_key(signal):
for func in self.__signals__[signal]:
func(**kwargs)
else:
print "signal %s doesn't exist." % signal