changeset ce68139c3179 in /home/hg/repos/gajim
details:http://hg.gajim.org/gajim?cmd=changeset;node=ce68139c3179
description: spread presence handler into classes that really need it
diffstat:
src/common/connection_handlers.py | 127 ++++++++++++++
src/common/connection_handlers_events.py | 10 +-
src/dialogs.py | 13 +
src/gui_interface.py | 277 +++++-------------------------
src/roster_window.py | 43 ++++-
5 files changed, 242 insertions(+), 228 deletions(-)
diffs (truncated from 596 to 300 lines):
diff -r 34fffe2e37df -r ce68139c3179 src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Wed Sep 22 18:20:01 2010 +0200
+++ b/src/common/connection_handlers.py Thu Sep 23 20:46:47 2010 +0200
@@ -1115,6 +1115,8 @@
self._nec_gmail_new_mail_received)
gajim.ged.register_event_handler('ping-received', ged.CORE,
self._nec_ping_received)
+ gajim.ged.register_event_handler('presence-received', ged.CORE,
+ self._nec_presence_received)
def build_http_auth_answer(self, iq_obj, answer):
if not self.connection or self.connected < 2:
@@ -1743,6 +1745,131 @@
gajim.nec.push_incoming_event(NetworkEvent('raw-pres-received',
conn=self, iq_obj=prs))
+ def _nec_presence_received(self, obj):
+ account = obj.conn.name
+ jid = obj.jid
+ resource = obj.resource or ''
+
+ statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
+ 'invisible']
+ obj.old_show = 0
+ obj.new_show = statuss.index(obj.show)
+
+ obj.contact_list = []
+
+ highest = gajim.contacts.get_contact_with_highest_priority(account,
jid)
+ obj.was_highest = (highest and highest.resource == resource)
+
+ # Update contact
+ obj.contact_list = gajim.contacts.get_contacts(account, jid)
+ obj.contact = None
+ resources = []
+ for c in obj.contact_list:
+ resources.append(c.resource)
+ if c.resource == resource:
+ obj.contact = c
+ break
+
+ if obj.contact:
+ obj.old_show = statuss.index(obj.contact.show)
+ # nick changed
+ if obj.contact_nickname is not None and \
+ obj.contact.contact_name != obj.contact_nickname:
+ obj.contact.contact_name = obj.contact_nickname
+ obj.need_redraw = True
+# gajim.interface.roster.draw_contact(jid, account)
+
+ if obj.old_show == obj.new_show and obj.contact.status == \
+ obj.status and obj.contact.priority == obj.prio: # no change
+ return
+ else:
+ obj.contact = gajim.contacts.get_first_contact_from_jid(account,
+ jid)
+ if not obj.contact:
+ # Presence of another resource of our jid
+ # Create self contact and add to roster
+ if resource == obj.conn.server_resource:
+ return
+ # Ignore offline presence of unknown self resource
+ if obj.new_show < 2:
+ return
+ obj.contact = gajim.contacts.create_self_contact(jid=jid,
+ account=account, show=obj.show, status=obj.status,
+ priority=obj.prio, keyID=obj.keyID,
+ resource=obj.resource)
+ gajim.contacts.add_contact(account, obj.contact)
+ obj.contact_list.append(obj.contact)
+ else:
+ obj.old_show = statuss.index(obj.contact.show)
+ if (resources != [''] and (len(obj.contact_list) != 1 or \
+ obj.contact_list[0].show != 'offline')) and \
+ not gajim.jid_is_transport(jid):
+ # Another resource of an existing contact connected
+ obj.old_show = 0
+ obj.contact = gajim.contacts.copy_contact(obj.contact)
+ obj.contact_list.append(obj.contact)
+ obj.contact.resource = resource
+
+ obj.need_add_in_roster = True
+# gajim.interface.roster.add_contact(jid, account)
+
+ if not gajim.jid_is_transport(jid) and len(obj.contact_list) == 1:
+ # It's not an agent
+ if obj.old_show == 0 and obj.new_show > 1:
+ if not jid in gajim.newly_added[account]:
+ gajim.newly_added[account].append(jid)
+ if jid in gajim.to_be_removed[account]:
+ gajim.to_be_removed[account].remove(jid)
+ elif obj.old_show > 1 and obj.new_show == 0 and \
+ obj.conn.connected > 1:
+ if not jid in gajim.to_be_removed[account]:
+ gajim.to_be_removed[account].append(jid)
+ if jid in gajim.newly_added[account]:
+ gajim.newly_added[account].remove(jid)
+ obj.need_redraw = True
+# self.roster.draw_contact(jid, account)
+
+ obj.contact.show = obj.show
+ obj.contact.status = obj.status
+ obj.contact.priority = obj.prio
+ obj.contact.keyID = obj.keyID
+ if obj.timestamp:
+ obj.contact.last_status_time = obj.timestamp
+ elif not gajim.block_signed_in_notifications[account]:
+ # We're connected since more that 30 seconds
+ obj.contact.last_status_time = localtime()
+ obj.contact.contact_nickname = obj.contact_nickname
+
+ if gajim.jid_is_transport(jid):
+ return
+
+ # It isn't an agent
+ # reset chatstate if needed:
+ # (when contact signs out or has errors)
+ if obj.show in ('offline', 'error'):
+ obj.contact.our_chatstate = obj.contact.chatstate = \
+ obj.contact.composing_xep = None
+
+ # TODO: This causes problems when another
+ # resource signs off!
+ self.stop_all_active_file_transfers(obj.contact)
+
+ # disable encryption, since if any messages are
+ # lost they'll be not decryptable (note that
+ # this contradicts XEP-0201 - trying to get that
+ # in the XEP, though)
+
+ # there won't be any sessions here if the contact terminated
+ # their sessions before going offline (which we do)
+ for sess in self.get_sessions(jid):
+ if obj.fjid != str(sess.jid):
+ continue
+ if sess.control:
+ sess.control.no_autonegotiation = False
+ if sess.enable_encryption:
+ sess.terminate_e2e()
+ self.delete_session(jid, sess.thread_id)
+
def _StanzaArrivedCB(self, con, obj):
self.last_io = gajim.idlequeue.current_time()
diff -r 34fffe2e37df -r ce68139c3179 src/common/connection_handlers_events.py
--- a/src/common/connection_handlers_events.py Wed Sep 22 18:20:01 2010 +0200
+++ b/src/common/connection_handlers_events.py Thu Sep 23 20:46:47 2010 +0200
@@ -604,6 +604,10 @@
def generate(self):
self.conn = self.base_event.conn
self.iq_obj = self.base_event.iq_obj
+
+ self.need_add_in_roster = False
+ self.need_redraw = False
+
self.ptype = self.iq_obj.getType()
if self.ptype == 'available':
self.ptype = None
@@ -627,6 +631,10 @@
_('Nickname not allowed: %s') % resource, None, False,
None,
[]))
return
+ jid_list = gajim.contacts.get_jid_list(self.conn.name)
+# if self.jid not in jid_list and self.jid !=
gajim.get_jid_from_account(
+# self.conn.name):
+# return
self.timestamp = None
self.get_id()
self.is_gc = False # is it a GC presence ?
@@ -957,5 +965,5 @@
self.conn.server_resource:
# We got our own presence
self.conn.dispatch('STATUS', self.show)
- else:
+ elif self.jid in jid_list:
return True
diff -r 34fffe2e37df -r ce68139c3179 src/dialogs.py
--- a/src/dialogs.py Wed Sep 22 18:20:01 2010 +0200
+++ b/src/dialogs.py Thu Sep 23 20:46:47 2010 +0200
@@ -995,12 +995,17 @@
message_buffer.set_text(helpers.get_subscription_request_msg(
self.account))
+ gajim.ged.register_event_handler('presence-received', ged.GUI1,
+ self._nec_presence_received)
+
def on_add_new_contact_window_destroy(self, widget):
if self.account:
location = gajim.interface.instances[self.account]
else:
location = gajim.interface.instances
del location['add_contact']
+ gajim.ged.remove_event_handler('presence-received', ged.GUI1,
+ self._nec_presence_received)
def on_register_button_clicked(self, widget):
jid = self.protocol_jid_combobox.get_active_text().decode('utf-8')
@@ -1154,6 +1159,14 @@
self.connected_label.show()
self.add_button.set_sensitive(False)
+ def _nec_presence_received(self, obj):
+ if gajim.jid_is_transport(obj.jid):
+ if obj.old_show == 0 and obj.new_show > 1:
+ self.transport_signed_in(obj.jid)
+ elif obj.old_show > 1 and obj.new_show == 0:
+ self.transport_signed_out(obj.jid)
+
+
class AboutDialog:
"""
Class for about dialog
diff -r 34fffe2e37df -r ce68139c3179 src/gui_interface.py
--- a/src/gui_interface.py Wed Sep 22 18:20:01 2010 +0200
+++ b/src/gui_interface.py Thu Sep 23 20:46:47 2010 +0200
@@ -290,249 +290,76 @@
#
# Contact changed show
- # FIXME: Drop and rewrite...
-
- statuss = ['offline', 'error', 'online', 'chat', 'away', 'xa', 'dnd',
- 'invisible']
-
account = obj.conn.name
jid = obj.jid
show = obj.show
status = obj.status
resource = obj.resource or ''
- priority = obj.prio
- keyID = obj.keyID
- timestamp = obj.timestamp
- contact_nickname = obj.contact_nickname
-
- obj.old_show = 0
- obj.new_show = statuss.index(show)
-
- lcontact = []
-
- highest = gajim.contacts.get_contact_with_highest_priority(account,
jid)
- was_highest = (highest and highest.resource == resource)
-
- # Update contact
+
jid_list = gajim.contacts.get_jid_list(account)
- if jid in jid_list or jid == gajim.get_jid_from_account(account):
- lcontact = gajim.contacts.get_contacts(account, jid)
- contact1 = None
- resources = []
- for c in lcontact:
- resources.append(c.resource)
- if c.resource == resource:
- contact1 = c
- break
-
- if contact1:
- if contact1.show in statuss:
- obj.old_show = statuss.index(contact1.show)
- # nick changed
- if contact_nickname is not None and \
- contact1.contact_name != contact_nickname:
- contact1.contact_name = contact_nickname
- self.roster.draw_contact(jid, account)
-
- if obj.old_show == obj.new_show and contact1.status == status \
- and contact1.priority == priority: # no change
- return
- else:
- contact1 = gajim.contacts.get_first_contact_from_jid(account,
- jid)
- if not contact1:
- # Presence of another resource of our
- # jid
- # Create self contact and add to roster
- if resource == obj.conn.server_resource:
- return
- # Ignore offline presence of unknown self resource
- if obj.new_show < 2:
- return
- contact1 = gajim.contacts.create_self_contact(jid=jid,
- account=account, show=show, status=status,
- priority=priority, keyID=keyID, resource=resource)
- obj.old_show = 0
- gajim.contacts.add_contact(account, contact1)
- lcontact.append(contact1)
- elif contact1.show in statuss:
- obj.old_show = statuss.index(contact1.show)
- if (resources != [''] and (len(lcontact) != 1 or \
- lcontact[0].show != 'offline')) and \
- not gajim.jid_is_transport(jid):
- # Another resource of an existing contact connected
- obj.old_show = 0
- contact1 = gajim.contacts.copy_contact(contact1)
- lcontact.append(contact1)
- contact1.resource = resource
-
- self.roster.add_contact(contact1.jid, account)
-
- if not gajim.jid_is_transport(contact1.jid) and len(lcontact) == 1:
- # It's not an agent
_______________________________________________
Commits mailing list
[email protected]
http://lists.gajim.org/cgi-bin/listinfo/commits