Allow multiple event handlers for a single Interface event.
We can use that until the plugin branch is available.
This commit is contained in:
parent
addaaa9242
commit
3157cf0b1b
|
@ -1983,105 +1983,120 @@ class Interface:
|
||||||
_('PEP node %(node)s was not removed: %(message)s') % {
|
_('PEP node %(node)s was not removed: %(message)s') % {
|
||||||
'node': data[1], 'message': data[2]})
|
'node': data[1], 'message': data[2]})
|
||||||
|
|
||||||
|
def register_handler(self, event, handler):
|
||||||
|
if event not in self.handlers:
|
||||||
|
self.handlers[event] = []
|
||||||
|
|
||||||
|
if handler not in self.handlers[event]:
|
||||||
|
self.handlers[event].append(handler)
|
||||||
|
|
||||||
|
def unregister_handler(self, event, handler):
|
||||||
|
self.handlers[event].remove(handler)
|
||||||
|
|
||||||
def register_handlers(self):
|
def register_handlers(self):
|
||||||
self.handlers = {
|
self.handlers = {
|
||||||
'ROSTER': self.handle_event_roster,
|
'ROSTER': [self.handle_event_roster],
|
||||||
'WARNING': self.handle_event_warning,
|
'WARNING': [self.handle_event_warning],
|
||||||
'ERROR': self.handle_event_error,
|
'ERROR': [self.handle_event_error],
|
||||||
'INFORMATION': self.handle_event_information,
|
'INFORMATION': [self.handle_event_information],
|
||||||
'ERROR_ANSWER': self.handle_event_error_answer,
|
'ERROR_ANSWER': [self.handle_event_error_answer],
|
||||||
'STATUS': self.handle_event_status,
|
'STATUS': [self.handle_event_status],
|
||||||
'NOTIFY': self.handle_event_notify,
|
'NOTIFY': [self.handle_event_notify],
|
||||||
'MSGERROR': self.handle_event_msgerror,
|
'MSGERROR': [self.handle_event_msgerror],
|
||||||
'MSGSENT': self.handle_event_msgsent,
|
'MSGSENT': [self.handle_event_msgsent],
|
||||||
'MSGNOTSENT': self.handle_event_msgnotsent,
|
'MSGNOTSENT': [self.handle_event_msgnotsent],
|
||||||
'SUBSCRIBED': self.handle_event_subscribed,
|
'SUBSCRIBED': [self.handle_event_subscribed],
|
||||||
'UNSUBSCRIBED': self.handle_event_unsubscribed,
|
'UNSUBSCRIBED': [self.handle_event_unsubscribed],
|
||||||
'SUBSCRIBE': self.handle_event_subscribe,
|
'SUBSCRIBE': [self.handle_event_subscribe],
|
||||||
'AGENT_ERROR_INFO': self.handle_event_agent_info_error,
|
'AGENT_ERROR_INFO': [self.handle_event_agent_info_error],
|
||||||
'AGENT_ERROR_ITEMS': self.handle_event_agent_items_error,
|
'AGENT_ERROR_ITEMS': [self.handle_event_agent_items_error],
|
||||||
'AGENT_REMOVED': self.handle_event_agent_removed,
|
'AGENT_REMOVED': [self.handle_event_agent_removed],
|
||||||
'REGISTER_AGENT_INFO': self.handle_event_register_agent_info,
|
'REGISTER_AGENT_INFO': [self.handle_event_register_agent_info],
|
||||||
'AGENT_INFO_ITEMS': self.handle_event_agent_info_items,
|
'AGENT_INFO_ITEMS': [self.handle_event_agent_info_items],
|
||||||
'AGENT_INFO_INFO': self.handle_event_agent_info_info,
|
'AGENT_INFO_INFO': [self.handle_event_agent_info_info],
|
||||||
'QUIT': self.handle_event_quit,
|
'QUIT': [self.handle_event_quit],
|
||||||
'NEW_ACC_CONNECTED': self.handle_event_new_acc_connected,
|
'NEW_ACC_CONNECTED': [self.handle_event_new_acc_connected],
|
||||||
'NEW_ACC_NOT_CONNECTED': self.handle_event_new_acc_not_connected,
|
'NEW_ACC_NOT_CONNECTED': [self.handle_event_new_acc_not_connected],
|
||||||
'ACC_OK': self.handle_event_acc_ok,
|
'ACC_OK': [self.handle_event_acc_ok],
|
||||||
'ACC_NOT_OK': self.handle_event_acc_not_ok,
|
'ACC_NOT_OK': [self.handle_event_acc_not_ok],
|
||||||
'MYVCARD': self.handle_event_myvcard,
|
'MYVCARD': [self.handle_event_myvcard],
|
||||||
'VCARD': self.handle_event_vcard,
|
'VCARD': [self.handle_event_vcard],
|
||||||
'LAST_STATUS_TIME': self.handle_event_last_status_time,
|
'LAST_STATUS_TIME': [self.handle_event_last_status_time],
|
||||||
'OS_INFO': self.handle_event_os_info,
|
'OS_INFO': [self.handle_event_os_info],
|
||||||
'ENTITY_TIME': self.handle_event_entity_time,
|
'ENTITY_TIME': [self.handle_event_entity_time],
|
||||||
'GC_NOTIFY': self.handle_event_gc_notify,
|
'GC_NOTIFY': [self.handle_event_gc_notify],
|
||||||
'GC_MSG': self.handle_event_gc_msg,
|
'GC_MSG': [self.handle_event_gc_msg],
|
||||||
'GC_SUBJECT': self.handle_event_gc_subject,
|
'GC_SUBJECT': [self.handle_event_gc_subject],
|
||||||
'GC_CONFIG': self.handle_event_gc_config,
|
'GC_CONFIG': [self.handle_event_gc_config],
|
||||||
'GC_CONFIG_CHANGE': self.handle_event_gc_config_change,
|
'GC_CONFIG_CHANGE': [self.handle_event_gc_config_change],
|
||||||
'GC_INVITATION': self.handle_event_gc_invitation,
|
'GC_INVITATION': [self.handle_event_gc_invitation],
|
||||||
'GC_AFFILIATION': self.handle_event_gc_affiliation,
|
'GC_AFFILIATION': [self.handle_event_gc_affiliation],
|
||||||
'GC_PASSWORD_REQUIRED': self.handle_event_gc_password_required,
|
'GC_PASSWORD_REQUIRED': [self.handle_event_gc_password_required],
|
||||||
'BAD_PASSPHRASE': self.handle_event_bad_passphrase,
|
'BAD_PASSPHRASE': [self.handle_event_bad_passphrase],
|
||||||
'ROSTER_INFO': self.handle_event_roster_info,
|
'ROSTER_INFO': [self.handle_event_roster_info],
|
||||||
'BOOKMARKS': self.handle_event_bookmarks,
|
'BOOKMARKS': [self.handle_event_bookmarks],
|
||||||
'CON_TYPE': self.handle_event_con_type,
|
'CON_TYPE': [self.handle_event_con_type],
|
||||||
'CONNECTION_LOST': self.handle_event_connection_lost,
|
'CONNECTION_LOST': [self.handle_event_connection_lost],
|
||||||
'FILE_REQUEST': self.handle_event_file_request,
|
'FILE_REQUEST': [self.handle_event_file_request],
|
||||||
'GMAIL_NOTIFY': self.handle_event_gmail_notify,
|
'GMAIL_NOTIFY': [self.handle_event_gmail_notify],
|
||||||
'FILE_REQUEST_ERROR': self.handle_event_file_request_error,
|
'FILE_REQUEST_ERROR': [self.handle_event_file_request_error],
|
||||||
'FILE_SEND_ERROR': self.handle_event_file_send_error,
|
'FILE_SEND_ERROR': [self.handle_event_file_send_error],
|
||||||
'STANZA_ARRIVED': self.handle_event_stanza_arrived,
|
'STANZA_ARRIVED': [self.handle_event_stanza_arrived],
|
||||||
'STANZA_SENT': self.handle_event_stanza_sent,
|
'STANZA_SENT': [self.handle_event_stanza_sent],
|
||||||
'HTTP_AUTH': self.handle_event_http_auth,
|
'HTTP_AUTH': [self.handle_event_http_auth],
|
||||||
'VCARD_PUBLISHED': self.handle_event_vcard_published,
|
'VCARD_PUBLISHED': [self.handle_event_vcard_published],
|
||||||
'VCARD_NOT_PUBLISHED': self.handle_event_vcard_not_published,
|
'VCARD_NOT_PUBLISHED': [self.handle_event_vcard_not_published],
|
||||||
'ASK_NEW_NICK': self.handle_event_ask_new_nick,
|
'ASK_NEW_NICK': [self.handle_event_ask_new_nick],
|
||||||
'SIGNED_IN': self.handle_event_signed_in,
|
'SIGNED_IN': [self.handle_event_signed_in],
|
||||||
'METACONTACTS': self.handle_event_metacontacts,
|
'METACONTACTS': [self.handle_event_metacontacts],
|
||||||
'ATOM_ENTRY': self.handle_atom_entry,
|
'ATOM_ENTRY': [self.handle_atom_entry],
|
||||||
'FAILED_DECRYPT': self.handle_event_failed_decrypt,
|
'FAILED_DECRYPT': [self.handle_event_failed_decrypt],
|
||||||
'PRIVACY_LISTS_RECEIVED': self.handle_event_privacy_lists_received,
|
'PRIVACY_LISTS_RECEIVED': [self.handle_event_privacy_lists_received],
|
||||||
'PRIVACY_LIST_RECEIVED': self.handle_event_privacy_list_received,
|
'PRIVACY_LIST_RECEIVED': [self.handle_event_privacy_list_received],
|
||||||
'PRIVACY_LISTS_ACTIVE_DEFAULT': \
|
'PRIVACY_LISTS_ACTIVE_DEFAULT': \
|
||||||
self.handle_event_privacy_lists_active_default,
|
[self.handle_event_privacy_lists_active_default],
|
||||||
'PRIVACY_LIST_REMOVED': self.handle_event_privacy_list_removed,
|
'PRIVACY_LIST_REMOVED': [self.handle_event_privacy_list_removed],
|
||||||
'ZC_NAME_CONFLICT': self.handle_event_zc_name_conflict,
|
'ZC_NAME_CONFLICT': [self.handle_event_zc_name_conflict],
|
||||||
'PING_SENT': self.handle_event_ping_sent,
|
'PING_SENT': [self.handle_event_ping_sent],
|
||||||
'PING_REPLY': self.handle_event_ping_reply,
|
'PING_REPLY': [self.handle_event_ping_reply],
|
||||||
'PING_ERROR': self.handle_event_ping_error,
|
'PING_ERROR': [self.handle_event_ping_error],
|
||||||
'SEARCH_FORM': self.handle_event_search_form,
|
'SEARCH_FORM': [self.handle_event_search_form],
|
||||||
'SEARCH_RESULT': self.handle_event_search_result,
|
'SEARCH_RESULT': [self.handle_event_search_result],
|
||||||
'RESOURCE_CONFLICT': self.handle_event_resource_conflict,
|
'RESOURCE_CONFLICT': [self.handle_event_resource_conflict],
|
||||||
'ROSTERX': self.handle_event_roster_item_exchange,
|
'ROSTERX': [self.handle_event_roster_item_exchange],
|
||||||
'PEP_CONFIG': self.handle_event_pep_config,
|
'PEP_CONFIG': [self.handle_event_pep_config],
|
||||||
'UNIQUE_ROOM_ID_UNSUPPORTED': \
|
'UNIQUE_ROOM_ID_UNSUPPORTED': \
|
||||||
self.handle_event_unique_room_id_unsupported,
|
[self.handle_event_unique_room_id_unsupported],
|
||||||
'UNIQUE_ROOM_ID_SUPPORTED': self.handle_event_unique_room_id_supported,
|
'UNIQUE_ROOM_ID_SUPPORTED': [self.handle_event_unique_room_id_supported],
|
||||||
'GPG_PASSWORD_REQUIRED': self.handle_event_gpg_password_required,
|
'GPG_PASSWORD_REQUIRED': [self.handle_event_gpg_password_required],
|
||||||
'GPG_ALWAYS_TRUST': self.handle_event_gpg_always_trust,
|
'GPG_ALWAYS_TRUST': [self.handle_event_gpg_always_trust],
|
||||||
'PASSWORD_REQUIRED': self.handle_event_password_required,
|
'PASSWORD_REQUIRED': [self.handle_event_password_required],
|
||||||
'SSL_ERROR': self.handle_event_ssl_error,
|
'SSL_ERROR': [self.handle_event_ssl_error],
|
||||||
'FINGERPRINT_ERROR': self.handle_event_fingerprint_error,
|
'FINGERPRINT_ERROR': [self.handle_event_fingerprint_error],
|
||||||
'PLAIN_CONNECTION': self.handle_event_plain_connection,
|
'PLAIN_CONNECTION': [self.handle_event_plain_connection],
|
||||||
'INSECURE_SSL_CONNECTION': self.handle_event_insecure_ssl_connection,
|
'INSECURE_SSL_CONNECTION': [self.handle_event_insecure_ssl_connection],
|
||||||
'PUBSUB_NODE_REMOVED': self.handle_event_pubsub_node_removed,
|
'PUBSUB_NODE_REMOVED': [self.handle_event_pubsub_node_removed],
|
||||||
'PUBSUB_NODE_NOT_REMOVED': self.handle_event_pubsub_node_not_removed,
|
'PUBSUB_NODE_NOT_REMOVED': [self.handle_event_pubsub_node_not_removed],
|
||||||
'JINGLE_INCOMING': self.handle_event_jingle_incoming,
|
'JINGLE_INCOMING': [self.handle_event_jingle_incoming],
|
||||||
'JINGLE_CONNECTED': self.handle_event_jingle_connected,
|
'JINGLE_CONNECTED': [self.handle_event_jingle_connected],
|
||||||
'JINGLE_DISCONNECTED': self.handle_event_jingle_disconnected,
|
'JINGLE_DISCONNECTED': [self.handle_event_jingle_disconnected],
|
||||||
'JINGLE_ERROR': self.handle_event_jingle_error,
|
'JINGLE_ERROR': [self.handle_event_jingle_error],
|
||||||
}
|
}
|
||||||
|
|
||||||
def dispatch(self, event, account, data):
|
def dispatch(self, event, account, data):
|
||||||
'''
|
'''
|
||||||
Dispatches an network event to the event handlers of this class
|
Dispatches an network event to the event handlers of this class.
|
||||||
|
|
||||||
|
Return true if it could be dispatched to alteast one handler.
|
||||||
'''
|
'''
|
||||||
if event not in self.handlers:
|
if event not in self.handlers:
|
||||||
log.warning('Unknown event %s dispatched to GUI: %s' % (event, data))
|
log.warning('Unknown event %s dispatched to GUI: %s' % (event, data))
|
||||||
|
return False
|
||||||
else:
|
else:
|
||||||
log.debug('Event %s distpached to GUI: %s' % (event, data))
|
log.debug('Event %s distpached to GUI: %s' % (event, data))
|
||||||
self.handlers[event](account, data)
|
for handler in self.handlers[event]:
|
||||||
|
handler(account, data)
|
||||||
|
return len(self.handlers[event])
|
||||||
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
Loading…
Reference in New Issue