use NEC to handle resource conflict

This commit is contained in:
Yann Leboulanger 2010-09-09 16:40:58 +02:00
parent 5969a0a720
commit 016e2d4876
3 changed files with 31 additions and 17 deletions

View File

@ -1083,6 +1083,13 @@ ConnectionJingle, ConnectionIBBytestream):
self.gmail_last_tid = None
self.gmail_last_time = None
gajim.nec.register_incoming_event(PrivateStorageBookmarksReceivedEvent)
gajim.nec.register_incoming_event(BookmarksReceivedEvent)
gajim.nec.register_incoming_event(
PrivateStorageRosternotesReceivedEvent)
gajim.nec.register_incoming_event(RosternotesReceivedEvent)
gajim.nec.register_incoming_event(StreamConflictReceivedEvent)
gajim.ged.register_event_handler('http-auth-received', ged.CORE,
self._nec_http_auth_received)
gajim.ged.register_event_handler('version-request-received', ged.CORE,
@ -1095,15 +1102,10 @@ ConnectionJingle, ConnectionIBBytestream):
ged.CORE, self._nec_time_revised_request_received)
gajim.ged.register_event_handler('roster-set-received',
ged.CORE, self._nec_roster_set_received)
gajim.nec.register_incoming_event(PrivateStorageBookmarksReceivedEvent)
gajim.ged.register_event_handler('private-storage-bookmarks-received',
ged.CORE, self._nec_private_storate_bookmarks_received)
gajim.nec.register_incoming_event(BookmarksReceivedEvent)
gajim.nec.register_incoming_event(
PrivateStorageRosternotesReceivedEvent)
gajim.ged.register_event_handler('private-storage-rosternotes-received',
ged.CORE, self._nec_private_storate_rosternotes_received)
gajim.nec.register_incoming_event(RosternotesReceivedEvent)
gajim.ged.register_event_handler('roster-received', ged.CORE,
self._nec_roster_received)
gajim.ged.register_event_handler('error-received', ged.CORE,
@ -2261,10 +2263,10 @@ ConnectionJingle, ConnectionIBBytestream):
gajim.nec.push_incoming_event(SearchFormReceivedEvent(None,
conn=self, iq_obj=iq_obj))
def _StreamCB(self, con, obj):
if obj.getTag('conflict'):
# disconnected because of a resource conflict
self.dispatch('RESOURCE_CONFLICT', ())
def _StreamCB(self, con, iq_obj):
log.debug('StreamCB')
gajim.nec.push_incoming_event(StreamReceivedEvent(None,
conn=self, iq_obj=iq_obj))
def _register_handlers(self, con, con_type):
# try to find another way to register handlers in each class

View File

@ -573,3 +573,16 @@ class GmailNewMailReceivedEvent(nec.NetworkIncomingEvent):
class PingReceivedEvent(nec.NetworkIncomingEvent):
name = 'ping-received'
base_network_events = []
class StreamReceivedEvent(nec.NetworkIncomingEvent):
name = 'stream-received'
base_network_events = []
class StreamConflictReceivedEvent(nec.NetworkIncomingEvent):
name = 'stream-conflict-received'
base_network_events = ['stream-received']
def generate(self):
if self.base_event.iq_obj.getTag('conflict'):
self.conn = self.base_event.conn
return True

View File

@ -1701,17 +1701,16 @@ class Interface:
if ctrl:
ctrl.print_conversation(_('Error.'), 'status')
def handle_event_resource_conflict(self, account, data):
def handle_event_resource_conflict(self, obj):
# ('RESOURCE_CONFLICT', account, ())
# First we go offline, but we don't overwrite status message
self.roster.send_status(account, 'offline',
gajim.connections[account].status)
account = obj.conn.name
conn = obj.conn
self.roster.send_status(account, 'offline', conn.status)
def on_ok(new_resource):
gajim.config.set_per('accounts', account, 'resource', new_resource)
self.roster.send_status(account,
gajim.connections[account].old_show,
gajim.connections[account].status)
proposed_resource = gajim.connections[account].server_resource
self.roster.send_status(account, conn.old_show, conn.status)
proposed_resource = conn.server_resource
proposed_resource += gajim.config.get('gc_proposed_nick_char')
dlg = dialogs.ResourceConflictDialog(_('Resource Conflict'),
_('You are already connected to this account with the same '
@ -2114,7 +2113,6 @@ class Interface:
'PING_SENT': [self.handle_event_ping_sent],
'PING_REPLY': [self.handle_event_ping_reply],
'PING_ERROR': [self.handle_event_ping_error],
'RESOURCE_CONFLICT': [self.handle_event_resource_conflict],
'PEP_CONFIG': [self.handle_event_pep_config],
'UNIQUE_ROOM_ID_UNSUPPORTED': \
[self.handle_event_unique_room_id_unsupported],
@ -2147,6 +2145,7 @@ class Interface:
'roster-info': [self.handle_event_roster_info],
'roster-item-exchange-received': \
[self.handle_event_roster_item_exchange],
'stream-conflict-received': [self.handle_event_resource_conflict],
}
def register_core_handlers(self):