Fixed bug related to account name in NewEventsExample name. Modified way to acquire message type.

This commit is contained in:
Mateusz Biliński 2009-06-21 23:12:30 +02:00
parent 6fecd84b16
commit e8c3ba51b2
3 changed files with 11 additions and 11 deletions

View File

@ -51,10 +51,10 @@ class GoogleTranslationPlugin(GajimPlugin):
def init(self):
self.config_dialog = None
#self.gui_extension_points = {}
self.config_default_values = {'from_lang' : ('en', _('Language of text to be translated')),
'to_lang' : ('fr', _('Language to which translation will be made')),
'user_agent' : ('Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080213 Firefox/2.0.0.11',
_('User Agent data to be used with urllib2 when connecting to Google Translate service'))}
self.config_default_values = {'from_lang' : (u'en', _(u'Language of text to be translated')),
'to_lang' : (u'fr', _(u'Language to which translation will be made')),
'user_agent' : (u'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080213 Firefox/2.0.0.11',
_(u'User Agent data to be used with urllib2 when connecting to Google Translate service'))}
#self.events_handlers = {}
@ -67,7 +67,7 @@ class GoogleTranslationPlugin(GajimPlugin):
def translate_text(self, text, from_lang, to_lang):
text = self.prepare_text_for_url(text)
headers = { 'User-Agent' : self.config['user_agent'] }
translation_url = 'http://www.google.com/uds/Gtranslate?callback=google.language.callbacks.id100&context=22&q=%(text)s&langpair=%(from_lang)s%%7C%(to_lang)s&key=notsupplied&v=1.0'%locals()
translation_url = u'http://www.google.com/uds/Gtranslate?callback=google.language.callbacks.id100&context=22&q=%(text)s&langpair=%(from_lang)s%%7C%(to_lang)s&key=notsupplied&v=1.0'%locals()
request = urllib2.Request(translation_url, headers=headers)
response = urllib2.urlopen(request)
@ -105,7 +105,7 @@ class GoogleTranslateMessageReceivedEvent(nec.NetworkIncomingEvent):
base_network_events = ['raw-message-received']
def generate(self):
msg_type = self.base_event.xmpp_msg.attrs['type']
msg_type = self.base_event.xmpp_msg.attrs.get('type', None)
if msg_type == u'chat':
msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
if msg_text:

View File

@ -113,7 +113,7 @@ class ModifyOnlyMessageReceivedEvent(nec.NetworkIncomingEvent):
base_network_events = ['raw-message-received']
def generate(self):
msg_type = self.base_event.xmpp_msg.attrs['type']
msg_type = self.base_event.xmpp_msg.attrs.get('type', None)
if msg_type == u'chat':
msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
self.base_event.xmpp_msg.kids[0].setData(
@ -130,14 +130,13 @@ class EnrichedChatMessageReceivedEvent(nec.NetworkIncomingEvent):
base_network_events = ['raw-message-received']
def generate(self):
msg_type = self.base_event.xmpp_msg.attrs['type']
msg_type = self.base_event.xmpp_msg.attrs.get('type', None)
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'])
# FIXME: KeyError: u'vardo@jabber.org/Gajim'
self.account = self.base_event.account
self.from_nickname = gajim.get_contact_name_from_jid(
self.account,
self.from_jid_without_resource)

View File

@ -1782,7 +1782,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
gajim.nec.push_incoming_event(NetworkEvent('raw-message-received',
conn = con,
xmpp_msg = msg))
xmpp_msg = msg,
account = self.name))
# check if the message is pubsub#event
if msg.getTag('event') is not None: