Coding style.

This commit is contained in:
js 2008-05-18 19:44:43 +00:00
parent b8909e86ce
commit 2be8792fd3
2 changed files with 85 additions and 64 deletions

View file

@ -287,11 +287,13 @@ class OtrlMessageAppOps:
if not no_print: if not no_print:
ctrl = self.get_control(fjid, account) ctrl = self.get_control(fjid, account)
if ctrl: if ctrl:
ctrl.print_conversation_line(u" [OTR] %s"%msg, 'status', '', None) ctrl.print_conversation_line(u'[OTR] %s' % \
id = gajim.logger.write('chat_msg_recv', fjid, message='[OTR: %s]' % msg, tim=tim) msg, 'status', '', None)
# gajim.logger.write() only marks a message as unread (and so only id = gajim.logger.write('chat_msg_recv', fjid,
# returns an id) when fjid is a real contact (NOT if it's a GC private message='[OTR: %s]' % msg, tim=tim)
# chat) # gajim.logger.write() only marks a message as unread
# (and so only returns an id) when fjid is a real contact
# (NOT if it's a GC private chat)
if id: if id:
gajim.logger.set_read_messages([id]) gajim.logger.set_read_messages([id])
@ -310,24 +312,29 @@ class OtrlMessageAppOps:
return ctrls[0] return ctrls[0]
def policy(self, opdata=None, context=None): def policy(self, opdata=None, context=None):
policy = gajim.config.get_per("contacts", context.username, policy = gajim.config.get_per('contacts', context.username,
"otr_flags") "otr_flags")
if policy <= 0: if policy <= 0:
policy = gajim.config.get_per("contacts", policy = gajim.config.get_per('contacts',
gajim.get_jid_without_resource(context.username), gajim.get_jid_without_resource(
"otr_flags") context.username), 'otr_flags')
if policy <= 0: if policy <= 0:
policy = gajim.config.get_per("accounts", opdata['account'], "otr_flags") policy = gajim.config.get_per('accounts',
opdata['account'], 'otr_flags')
return policy return policy
def create_privkey(self, opdata="", accountname="", protocol=""): def create_privkey(self, opdata='', accountname='', protocol=''):
dialog = gtk.Dialog(title=_("Generating..."), parent=gajim.interface.roster.window, dialog = gtk.Dialog(
flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)) title = _('Generating...'),
permlabel = gtk.Label("Generating a private key for %s..."%accountname) parent = gajim.interface.roster.window,
permlabel.set_padding(20,20) flags = gtk.DIALOG_MODAL,
buttons = (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))
permlabel = gtk.Label(_('Generating a private key for %s...') \
% accountname)
permlabel.set_padding(20, 20)
dialog.set_response_sensitive(gtk.RESPONSE_CLOSE, False) dialog.set_response_sensitive(gtk.RESPONSE_CLOSE, False)
dialog.connect("destroy", otr_dialog_destroy) dialog.connect('destroy', otr_dialog_destroy)
dialog.connect("response", otr_dialog_destroy) dialog.connect('response', otr_dialog_destroy)
dialog.vbox.pack_start(permlabel) dialog.vbox.pack_start(permlabel)
dialog.get_root_window().raise_() dialog.get_root_window().raise_()
dialog.show_all() dialog.show_all()
@ -337,55 +344,66 @@ class OtrlMessageAppOps:
c.map() c.map()
while gtk.events_pending(): while gtk.events_pending():
gtk.main_iteration(block=False) gtk.main_iteration(block = False)
otr.otrl_privkey_generate(gajim.connections[opdata['account']].otr_userstates, otr.otrl_privkey_generate(
os.path.join(gajimpaths.root, "%s.key"%opdata['account']).encode(), gajim.connections[opdata['account']].otr_userstates,
os.path.join(gajimpaths.root,
'%s.key' % opdata['account']).encode(),
accountname, gajim.OTR_PROTO) accountname, gajim.OTR_PROTO)
permlabel.set_text("Generating a private key for %s...\ndone."%accountname) permlabel.set_text(_('Generating a private key for %s...\n' \
'done.') % accountname)
dialog.set_response_sensitive(gtk.RESPONSE_CLOSE, True) dialog.set_response_sensitive(gtk.RESPONSE_CLOSE, True)
def is_logged_in(self, opdata={}, accountname="", protocol="", recipient=""): def is_logged_in(self, opdata={}, accountname='', protocol='',
contact = gajim.contacts.get_contact_from_full_jid(opdata['account'], recipient) recipient=""):
contact = gajim.contacts.get_contact_from_full_jid(
opdata['account'], recipient)
if contact: if contact:
return contact.show \ return contact.show \
in ['dnd', 'xa', 'chat', 'online', 'away', in ['dnd', 'xa', 'chat', 'online', 'away',
'invisible'] 'invisible']
return 0 return 0
def inject_message(self, opdata=None, accountname="", protocol="", recipient="", def inject_message(self, opdata=None, accountname='', protocol='',
message=""): recipient='', message=''):
msg_type = otr.otrl_proto_message_type(message) msg_type = otr.otrl_proto_message_type(message)
if 'kwargs' not in opdata or 'urgent' in opdata: if 'kwargs' not in opdata or 'urgent' in opdata:
# don't use send_message here to have the message sent immediatly. # don't use send_message here to have the message
# this results in being able to disconnect from OTR sessions before # sent immediatly. This results in being able to
# quitting # disconnect from OTR sessions before quitting
stanza = XmppMessage(to=recipient, body=message, typ="chat") stanza = XmppMessage(to = recipient,
gajim.connections[opdata['account']].connection.send(stanza, now=True) body = message, typ='chat')
gajim.connections[opdata['account']].connection. \
send(stanza, now = True)
return return
if msg_type == otr.OTRL_MSGTYPE_QUERY: if msg_type == otr.OTRL_MSGTYPE_QUERY:
# split away XHTML-contaminated explanatory message # split away XHTML-contaminated explanatory message
message = unicode(message.splitlines()[0]) message = unicode(message.splitlines()[0])
message += _(u"\nThis user has requested an Off-the-Record private " \ message += _(u'\nThis user has requested an ' \
"conversation. However, you do not have a plugin to " \ 'Off-the-Record private conversation. ' \
"support that.\nSee http://otr.cypherpunks.ca/ for more "\ 'However, you do not have a plugin to ' \
"information.") 'support that.\n' \
'See http://otr.cypherpunks.ca/ for more ' \
'information.')
gajim.connections[opdata['account']].connection.send( gajim.connections[opdata['account']].connection.send(
common.xmpp.Message(to = recipient, common.xmpp.Message(to = recipient,
body = message, typ = 'chat')) body = message, typ = 'chat'))
return return
gajim.connections[opdata['account']].send_message(recipient, message, gajim.connections[opdata['account']].send_message(recipient,
**opdata['kwargs']) message, **opdata['kwargs'])
def notify(sef, opdata=None, username="", **kwargs): def notify(sef, opdata=None, username='', **kwargs):
self.gajim_log("Notify: "+str(kwargs), opdata['account'], username) self.gajim_log('Notify: ' + str(kwargs), opdata['account'],
username)
def display_otr_message(self, opdata=None, username="", msg="", **kwargs): def display_otr_message(self, opdata=None, username="", msg="", **kwargs):
self.gajim_log("OTR Message: "+msg, opdata['account'], username) self.gajim_log('OTR Message: ' + msg, opdata['account'],
username)
return 0 return 0
def update_context_list(self, **kwargs): def update_context_list(self, **kwargs):
@ -393,31 +411,33 @@ class OtrlMessageAppOps:
pass pass
def protocol_name(self, opdata=None, protocol=""): def protocol_name(self, opdata=None, protocol=""):
return "XMPP" return 'XMPP'
def new_fingerprint(self, opdata=None, username="", fingerprint="", **kwargs): def new_fingerprint(self, opdata=None, username='', fingerprint='',
self.gajim_log("New fingerprint for %s: %s"%(username, **kwargs):
otr.otrl_privkey_hash_to_human(fingerprint)), opdata['account'], username) self.gajim_log('New fingerprint for %s: %s' % (username,
otr.otrl_privkey_hash_to_human(fingerprint)),
opdata['account'], username)
def write_fingerprints(self, opdata=""): def write_fingerprints(self, opdata=''):
otr.otrl_privkey_write_fingerprints(gajim.connections[opdata['account']].otr_userstates, otr.otrl_privkey_write_fingerprints(
os.path.join(gajimpaths.root, "%s.fpr"%opdata['account']).encode()) gajim.connections[opdata['account']].otr_userstates,
os.path.join(gajimpaths.root, '%s.fpr' % \
opdata['account']).encode())
def gone_secure(self, opdata="", context=None): def gone_secure(self, opdata='', context=None):
trust = context.active_fingerprint.trust trust = context.active_fingerprint.trust \
if trust: and 'verified' or 'unverified'
trust = "verified" self.gajim_log('%s secured OTR connection started' % trust,
else: opdata['account'], context.username, no_print = True)
trust = "unverified"
self.gajim_log("%s secured OTR connection started"%trust,
opdata['account'], context.username, no_print=True)
ctrl = self.get_control(context.username, opdata['account']) ctrl = self.get_control(context.username, opdata['account'])
if ctrl: if ctrl:
ctrl.update_otr(True) ctrl.update_otr(True)
def gone_insecure(self, opdata="", context=None): def gone_insecure(self, opdata='', context=None):
self.gajim_log("Private conversation with %s lost.", opdata['account'], context.username) self.gajim_log('Private conversation with %s lost.',
opdata['account'], context.username)
ctrl = self.get_control(context.username, opdata['account']) ctrl = self.get_control(context.username, opdata['account'])
if ctrl: if ctrl:
@ -428,17 +448,18 @@ class OtrlMessageAppOps:
if ctrl: if ctrl:
ctrl.update_otr(True) ctrl.update_otr(True)
self.gajim_log("OTR connection was refreshed", opdata['account'], self.gajim_log('OTR connection was refreshed',
context.username) opdata['account'], context.username)
def log_message(self, opdata=None, message=""): def log_message(self, opdata=None, message=''):
gajim.log.debug(message) gajim.log.debug(message)
def max_message_size(self, **kwargs): def max_message_size(self, **kwargs):
return 0 return 0
def account_name(self, opdata=None, account="",protocol=""): def account_name(self, opdata=None, account='',protocol=''):
return gajim.get_name_from_jid(opdata['account'], unicode(account)) return gajim.get_name_from_jid(opdata['account'],
unicode(account))
gajim.otr_ui_ops = OtrlMessageAppOps() gajim.otr_ui_ops = OtrlMessageAppOps()

View file

@ -103,9 +103,9 @@ class ChatControlSession(stanza_session.EncryptedStanzaSession):
if gajim.otr_module.otrl_tlv_find( if gajim.otr_module.otrl_tlv_find(
otr_msg_tuple[2], otr_msg_tuple[2],
gajim.otr_module.OTRL_TLV_DISCONNECTED) != None: gajim.otr_module.OTRL_TLV_DISCONNECTED) != None:
gajim.otr_ui_ops.gajim_log(_("%s " + \ gajim.otr_ui_ops.gajim_log(_("%s " \
"has ended his/her private " + \ "has ended his/her private " \
"conversation with you; " + \ "conversation with you; " \
"should do the same.") % \ "should do the same.") % \
full_jid_with_resource, full_jid_with_resource,
self.conn.name, self.conn.name,