Fixed bug related to account name in NewEventsExample name. Modified way to acquire message type.
This commit is contained in:
parent
6fecd84b16
commit
e8c3ba51b2
|
@ -51,10 +51,10 @@ class GoogleTranslationPlugin(GajimPlugin):
|
||||||
def init(self):
|
def init(self):
|
||||||
self.config_dialog = None
|
self.config_dialog = None
|
||||||
#self.gui_extension_points = {}
|
#self.gui_extension_points = {}
|
||||||
self.config_default_values = {'from_lang' : ('en', _('Language of text to be translated')),
|
self.config_default_values = {'from_lang' : (u'en', _(u'Language of text to be translated')),
|
||||||
'to_lang' : ('fr', _('Language to which translation will be made')),
|
'to_lang' : (u'fr', _(u'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' : (u'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'))}
|
_(u'User Agent data to be used with urllib2 when connecting to Google Translate service'))}
|
||||||
|
|
||||||
#self.events_handlers = {}
|
#self.events_handlers = {}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ class GoogleTranslationPlugin(GajimPlugin):
|
||||||
def translate_text(self, text, from_lang, to_lang):
|
def translate_text(self, text, from_lang, to_lang):
|
||||||
text = self.prepare_text_for_url(text)
|
text = self.prepare_text_for_url(text)
|
||||||
headers = { 'User-Agent' : self.config['user_agent'] }
|
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)
|
request = urllib2.Request(translation_url, headers=headers)
|
||||||
response = urllib2.urlopen(request)
|
response = urllib2.urlopen(request)
|
||||||
|
@ -105,7 +105,7 @@ class GoogleTranslateMessageReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
base_network_events = ['raw-message-received']
|
base_network_events = ['raw-message-received']
|
||||||
|
|
||||||
def generate(self):
|
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':
|
if msg_type == u'chat':
|
||||||
msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
|
msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
|
||||||
if msg_text:
|
if msg_text:
|
||||||
|
|
|
@ -113,7 +113,7 @@ class ModifyOnlyMessageReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
base_network_events = ['raw-message-received']
|
base_network_events = ['raw-message-received']
|
||||||
|
|
||||||
def generate(self):
|
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':
|
if msg_type == u'chat':
|
||||||
msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
|
msg_text = "".join(self.base_event.xmpp_msg.kids[0].data)
|
||||||
self.base_event.xmpp_msg.kids[0].setData(
|
self.base_event.xmpp_msg.kids[0].setData(
|
||||||
|
@ -130,14 +130,13 @@ class EnrichedChatMessageReceivedEvent(nec.NetworkIncomingEvent):
|
||||||
base_network_events = ['raw-message-received']
|
base_network_events = ['raw-message-received']
|
||||||
|
|
||||||
def generate(self):
|
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':
|
if msg_type == u'chat':
|
||||||
self.xmpp_msg = self.base_event.xmpp_msg
|
self.xmpp_msg = self.base_event.xmpp_msg
|
||||||
self.conn = self.base_event.conn
|
self.conn = self.base_event.conn
|
||||||
self.from_jid = helpers.get_full_jid_from_iq(self.xmpp_msg)
|
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.from_jid_without_resource = gajim.get_jid_without_resource(self.from_jid)
|
||||||
self.account = unicode(self.xmpp_msg.attrs['to'])
|
self.account = self.base_event.account
|
||||||
# FIXME: KeyError: u'vardo@jabber.org/Gajim'
|
|
||||||
self.from_nickname = gajim.get_contact_name_from_jid(
|
self.from_nickname = gajim.get_contact_name_from_jid(
|
||||||
self.account,
|
self.account,
|
||||||
self.from_jid_without_resource)
|
self.from_jid_without_resource)
|
||||||
|
|
|
@ -1782,7 +1782,8 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco,
|
||||||
|
|
||||||
gajim.nec.push_incoming_event(NetworkEvent('raw-message-received',
|
gajim.nec.push_incoming_event(NetworkEvent('raw-message-received',
|
||||||
conn = con,
|
conn = con,
|
||||||
xmpp_msg = msg))
|
xmpp_msg = msg,
|
||||||
|
account = self.name))
|
||||||
|
|
||||||
# check if the message is pubsub#event
|
# check if the message is pubsub#event
|
||||||
if msg.getTag('event') is not None:
|
if msg.getTag('event') is not None:
|
||||||
|
|
Loading…
Reference in New Issue