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

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Biliński <mateusz.bilinski@gmail.com>2008-08-18 20:35:14 +0400
committerMateusz Biliński <mateusz.bilinski@gmail.com>2008-08-18 20:35:14 +0400
commitc0a26be684cdbf613939052ef91b37afba5e20f3 (patch)
tree202b8257c4c6627992a79afcc5a107ac8a669899 /plugins
parentff8eaddf5120bb6b232fae234d58623c0dd6ba68 (diff)
Three core (raw) events (iq, message, presence) go also through Network Events Controller (layer between network library and Global Events Dispatcher, newly added) and from there they are dispatched through Global Events Dispatcher.
Ability to register new incoming network events (based on exisiting one) added. Modify-only network events are possible (eg. add some text each message, but don't create any new global event). Events creation can be chained. Examples of new network events classes are in New Events Example plugin. Events from src/gajim.py now all go through Global Events Dispatcher and only through it (easy to modify, in chain, data passed with them).
Diffstat (limited to 'plugins')
-rw-r--r--plugins/events_dump/plugin.py91
-rw-r--r--plugins/new_events_example/__init__.py1
-rw-r--r--plugins/new_events_example/plugin.py145
-rw-r--r--plugins/snarl_notifications/plugin.py18
4 files changed, 209 insertions, 46 deletions
diff --git a/plugins/events_dump/plugin.py b/plugins/events_dump/plugin.py
index 055af8772..b5d37cd06 100644
--- a/plugins/events_dump/plugin.py
+++ b/plugins/events_dump/plugin.py
@@ -45,43 +45,60 @@ class EventsDumpPlugin(GajimPlugin):
self.config_dialog = None
#self.gui_extension_points = {}
#self.config_default_values = {}
+ events_from_old_dbus_support = [
+ 'Roster', 'AccountPresence', 'ContactPresence',
+ 'ContactAbsence', 'ContactStatus', 'NewMessage',
+ 'Subscribe', 'Subscribed', 'Unsubscribed',
+ 'NewAccount', 'VcardInfo', 'LastStatusTime',
+ 'OsInfo', 'GCPresence', 'GCMessage', 'RosterInfo',
+ 'NewGmail']
- self.events_names = ['Roster', 'AccountPresence', 'ContactPresence',
- 'ContactAbsence', 'ContactStatus', 'NewMessage',
- 'Subscribe', 'Subscribed', 'Unsubscribed',
- 'NewAccount', 'VcardInfo', 'LastStatusTime',
- 'OsInfo', 'GCPresence', 'GCMessage', 'RosterInfo',
- 'NewGmail','ROSTER', 'WARNING', 'ERROR',
- 'INFORMATION', 'ERROR_ANSWER', 'STATUS',
- 'NOTIFY', 'MSGERROR', 'MSGSENT', 'MSGNOTSENT',
- 'SUBSCRIBED', 'UNSUBSCRIBED', 'SUBSCRIBE',
- 'AGENT_ERROR_INFO', 'AGENT_ERROR_ITEMS',
- 'AGENT_REMOVED', 'REGISTER_AGENT_INFO',
- 'AGENT_INFO_ITEMS', 'AGENT_INFO_INFO',
- 'QUIT', 'NEW_ACC_CONNECTED',
- 'NEW_ACC_NOT_CONNECTED', 'ACC_OK', 'ACC_NOT_OK',
- 'MYVCARD', 'VCARD', 'LAST_STATUS_TIME', 'OS_INFO',
- 'GC_NOTIFY', 'GC_MSG', 'GC_SUBJECT', 'GC_CONFIG',
- 'GC_CONFIG_CHANGE', 'GC_INVITATION',
- 'GC_AFFILIATION', 'GC_PASSWORD_REQUIRED',
- 'BAD_PASSPHRASE', 'ROSTER_INFO', 'BOOKMARKS',
- 'CON_TYPE', 'CONNECTION_LOST', 'FILE_REQUEST',
- 'GMAIL_NOTIFY', 'FILE_REQUEST_ERROR',
- 'FILE_SEND_ERROR', 'STANZA_ARRIVED', 'STANZA_SENT',
- 'HTTP_AUTH', 'VCARD_PUBLISHED',
- 'VCARD_NOT_PUBLISHED', 'ASK_NEW_NICK', 'SIGNED_IN',
- 'METACONTACTS', 'ATOM_ENTRY', 'FAILED_DECRYPT',
- 'PRIVACY_LISTS_RECEIVED', 'PRIVACY_LIST_RECEIVED',
- 'PRIVACY_LISTS_ACTIVE_DEFAULT',
- 'PRIVACY_LIST_REMOVED', 'ZC_NAME_CONFLICT',
- 'PING_SENT', 'PING_REPLY', 'PING_ERROR',
- 'SEARCH_FORM', 'SEARCH_RESULT',
- 'RESOURCE_CONFLICT', 'PEP_CONFIG',
- 'UNIQUE_ROOM_ID_UNSUPPORTED',
- 'UNIQUE_ROOM_ID_SUPPORTED', 'SESSION_NEG',
- 'GPG_PASSWORD_REQUIRED', 'SSL_ERROR',
- 'FINGERPRINT_ERROR', 'PLAIN_CONNECTION',
- 'PUBSUB_NODE_REMOVED', 'PUBSUB_NODE_NOT_REMOVED']
+ events_from_src_gajim = [
+ 'ROSTER', 'WARNING', 'ERROR',
+ 'INFORMATION', 'ERROR_ANSWER', 'STATUS',
+ 'NOTIFY', 'MSGERROR', 'MSGSENT', 'MSGNOTSENT',
+ 'SUBSCRIBED', 'UNSUBSCRIBED', 'SUBSCRIBE',
+ 'AGENT_ERROR_INFO', 'AGENT_ERROR_ITEMS',
+ 'AGENT_REMOVED', 'REGISTER_AGENT_INFO',
+ 'AGENT_INFO_ITEMS', 'AGENT_INFO_INFO',
+ 'QUIT', 'NEW_ACC_CONNECTED',
+ 'NEW_ACC_NOT_CONNECTED', 'ACC_OK', 'ACC_NOT_OK',
+ 'MYVCARD', 'VCARD', 'LAST_STATUS_TIME', 'OS_INFO',
+ 'GC_NOTIFY', 'GC_MSG', 'GC_SUBJECT', 'GC_CONFIG',
+ 'GC_CONFIG_CHANGE', 'GC_INVITATION',
+ 'GC_AFFILIATION', 'GC_PASSWORD_REQUIRED',
+ 'BAD_PASSPHRASE', 'ROSTER_INFO', 'BOOKMARKS',
+ 'CON_TYPE', 'CONNECTION_LOST', 'FILE_REQUEST',
+ 'GMAIL_NOTIFY', 'FILE_REQUEST_ERROR',
+ 'FILE_SEND_ERROR', 'STANZA_ARRIVED', 'STANZA_SENT',
+ 'HTTP_AUTH', 'VCARD_PUBLISHED',
+ 'VCARD_NOT_PUBLISHED', 'ASK_NEW_NICK', 'SIGNED_IN',
+ 'METACONTACTS', 'ATOM_ENTRY', 'FAILED_DECRYPT',
+ 'PRIVACY_LISTS_RECEIVED', 'PRIVACY_LIST_RECEIVED',
+ 'PRIVACY_LISTS_ACTIVE_DEFAULT',
+ 'PRIVACY_LIST_REMOVED', 'ZC_NAME_CONFLICT',
+ 'PING_SENT', 'PING_REPLY', 'PING_ERROR',
+ 'SEARCH_FORM', 'SEARCH_RESULT',
+ 'RESOURCE_CONFLICT', 'PEP_CONFIG',
+ 'UNIQUE_ROOM_ID_UNSUPPORTED',
+ 'UNIQUE_ROOM_ID_SUPPORTED', 'SESSION_NEG',
+ 'GPG_PASSWORD_REQUIRED', 'SSL_ERROR',
+ 'FINGERPRINT_ERROR', 'PLAIN_CONNECTION',
+ 'PUBSUB_NODE_REMOVED', 'PUBSUB_NODE_NOT_REMOVED']
+
+ network_events_from_core = ['raw-message-received',
+ 'raw-iq-received',
+ 'raw-pres-received']
+
+ network_events_generated_in_nec = [
+ 'customized-message-received',
+ 'more-customized-message-received',
+ 'modify-only-message-received',
+ 'enriched-chat-message-received']
+
+ self.events_names = []
+ self.events_names += network_events_from_core
+ self.events_names += network_events_generated_in_nec
self.events_handlers = {}
self._set_handling_methods()
@@ -105,6 +122,6 @@ class EventsDumpPlugin(GajimPlugin):
def _generate_handling_method(self, event_name):
def handler(self, *args):
- print "Event '%s' occured. Arguments: %s\n\n===\n"%(event_name, pformat(*args))
+ print "Event '%s' occured. Arguments: %s\n\n===\n"%(event_name, pformat(args))
return handler \ No newline at end of file
diff --git a/plugins/new_events_example/__init__.py b/plugins/new_events_example/__init__.py
new file mode 100644
index 000000000..a0eca896c
--- /dev/null
+++ b/plugins/new_events_example/__init__.py
@@ -0,0 +1 @@
+from plugin import NewEventsExamplePlugin \ No newline at end of file
diff --git a/plugins/new_events_example/plugin.py b/plugins/new_events_example/plugin.py
new file mode 100644
index 000000000..451f300c2
--- /dev/null
+++ b/plugins/new_events_example/plugin.py
@@ -0,0 +1,145 @@
+# -*- coding: utf-8 -*-
+##
+## 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/>.
+##
+'''
+New Events Example plugin.
+
+Demonstrates how to use Network Events Controller to generate new events
+based on existing one.
+
+:author: Mateusz Biliński <mateusz@bilinski.it>
+:since: 15th August 2008
+:copyright: Copyright (2008) Mateusz Biliński <mateusz@bilinski.it>
+:license: GPL
+'''
+
+import new
+from pprint import pformat
+
+from common import helpers
+from common import gajim
+
+from plugins import GajimPlugin
+from plugins.helpers import log_calls, log
+from common import ged
+from common import nec
+
+class NewEventsExamplePlugin(GajimPlugin):
+ name = u'New Events Example'
+ short_name = u'new_events_example'
+ version = u'0.1'
+ description = u'''Shows how to generate new network events based on existing one using Network Events Controller.'''
+ authors = [u'Mateusz Biliński <mateusz@bilinski.it>']
+ homepage = u'http://blog.bilinski.it'
+
+ @log_calls('NewEventsExamplePlugin')
+ def init(self):
+ self.config_dialog = None
+ #self.gui_extension_points = {}
+ #self.config_default_values = {}
+
+ self.events_handlers = {'raw-message-received' :
+ (ged.POSTCORE,
+ self.raw_message_received),
+ 'customized-message-received' :
+ (ged.POSTCORE,
+ self.customized_message_received),
+ 'enriched-chat-message-received' :
+ (ged.POSTCORE,
+ self.enriched_chat_message_received)}
+
+ self.events = [CustomizedMessageReceivedEvent,
+ MoreCustomizedMessageReceivedEvent,
+ ModifyOnlyMessageReceivedEvent,
+ EnrichedChatMessageReceivedEvent]
+
+ def enriched_chat_message_received(self, event_object):
+ pass
+ #print "Event '%s' occured. Event object: %s\n\n===\n"%(event_object.name,
+ #event_object)
+
+ def raw_message_received(self, event_object):
+ pass
+ #print "Event '%s' occured. Event object: %s\n\n===\n"%(event_object.name,
+ #event_object)
+
+ def customized_message_received(self, event_object):
+ pass
+ #print "Event '%s' occured. Event object: %s\n\n===\n"%(event_object.name,
+ #event_object)
+
+ def activate(self):
+ pass
+
+ def deactivate(self):
+ pass
+
+class CustomizedMessageReceivedEvent(nec.NetworkIncomingEvent):
+ name = 'customized-message-received'
+ base_network_events = ['raw-message-received']
+
+ def generate(self):
+ return True
+
+class MoreCustomizedMessageReceivedEvent(nec.NetworkIncomingEvent):
+ '''
+ Shows chain of custom created events.
+
+ This one is based on custom 'customized-messsage-received'.
+ '''
+ name = 'more-customized-message-received'
+ base_network_events = ['customized-message-received']
+
+ def generate(self):
+ return True
+
+class ModifyOnlyMessageReceivedEvent(nec.NetworkIncomingEvent):
+ name = 'modify-only-message-received'
+ base_network_events = ['raw-message-received']
+
+ def generate(self):
+ msg_type = self.base_event.xmpp_msg.attrs['type']
+ if msg_type == u'chat':
+ msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
+ self.base_event.xmpp_msg.kids[0].setData(
+ u'%s [MODIFIED BY CUSTOM NETWORK EVENT]'%(msg_text))
+
+ return False
+
+class EnrichedChatMessageReceivedEvent(nec.NetworkIncomingEvent):
+ '''
+ Generates more friendly (in use by handlers) network event for
+ received chat message.
+ '''
+ name = 'enriched-chat-message-received'
+ base_network_events = ['raw-message-received']
+
+ def generate(self):
+ msg_type = self.base_event.xmpp_msg.attrs['type']
+ if msg_type == u'chat':
+ self.xmpp_msg = self.base_event.xmpp_msg
+ self.conn = self.base_event.conn
+ self.from_jid = helpers.get_full_jid_from_iq(self.xmpp_msg)
+ self.from_jid_without_resource = gajim.get_jid_without_resource(self.from_jid)
+ self.account = unicode(self.xmpp_msg.attrs['to'])
+ self.from_nickname = gajim.get_contact_name_from_jid(
+ self.account,
+ self.from_jid_without_resource)
+ self.msg_text = "".join(self.xmpp_msg.kids[0].data)
+
+ return True
+
+ return False
diff --git a/plugins/snarl_notifications/plugin.py b/plugins/snarl_notifications/plugin.py
index e6ef5ae18..9835cca28 100644
--- a/plugins/snarl_notifications/plugin.py
+++ b/plugins/snarl_notifications/plugin.py
@@ -30,7 +30,7 @@ Fancy events notifications under Windows using Snarl infrastructure.
import new
from pprint import pformat
-import PySnarl
+#import PySnarl
from common import gajim
from plugins import GajimPlugin
@@ -62,7 +62,7 @@ PySnarl bindings are used (http://code.google.com/p/pysnarl/).'''
def newMessage(self, args):
event_name = "NewMessage"
- data = args[0]
+ data = args
account = data[0]
jid = data[1][0]
jid_without_resource = gajim.get_jid_without_resource(jid)
@@ -74,15 +74,15 @@ PySnarl bindings are used (http://code.google.com/p/pysnarl/).'''
elif msg_type == 'pm':
nickname = gajim.get_resource_from_jid(jid)
- print "Event '%s' occured. Arguments: %s\n\n===\n"%(event_name, pformat(*args))
+ print "Event '%s' occured. Arguments: %s\n\n===\n"%(event_name, pformat(args))
print "Event '%s' occured. Arguments: \naccount = %s\njid = %s\nmsg = %s\nnickname = %s"%(
event_name, account, jid, msg, nickname)
- if PySnarl.snGetVersion() != False:
- (major, minor) = PySnarl.snGetVersion()
- print "Found Snarl version",str(major)+"."+str(minor),"running."
- PySnarl.snShowMessage(nickname, msg[:20]+'...')
- else:
- print "Sorry Snarl does not appear to be running"
+ #if PySnarl.snGetVersion() != False:
+ #(major, minor) = PySnarl.snGetVersion()
+ #print "Found Snarl version",str(major)+"."+str(minor),"running."
+ #PySnarl.snShowMessage(nickname, msg[:20]+'...')
+ #else:
+ #print "Sorry Snarl does not appear to be running"
\ No newline at end of file