threads don't send event to gui if connection succeed, thay are in a queue
This commit is contained in:
		
							parent
							
								
									4df50b17ee
								
							
						
					
					
						commit
						5a9bb51f97
					
				
					 1 changed files with 16 additions and 12 deletions
				
			
		| 
						 | 
					@ -142,6 +142,7 @@ class Connection:
 | 
				
			||||||
		self.last_incoming = time.time()
 | 
							self.last_incoming = time.time()
 | 
				
			||||||
		self.keep_alive_sent = False
 | 
							self.keep_alive_sent = False
 | 
				
			||||||
		self.to_be_sent = []
 | 
							self.to_be_sent = []
 | 
				
			||||||
 | 
							self.for_gui = []
 | 
				
			||||||
		self.last_sent = []
 | 
							self.last_sent = []
 | 
				
			||||||
		self.files_props = {}
 | 
							self.files_props = {}
 | 
				
			||||||
		self.password = gajim.config.get_per('accounts', name, 'password')
 | 
							self.password = gajim.config.get_per('accounts', name, 'password')
 | 
				
			||||||
| 
						 | 
					@ -372,8 +373,8 @@ class Connection:
 | 
				
			||||||
					prs.getReason(), prs.getActor(), prs.getStatusCode(),
 | 
										prs.getReason(), prs.getActor(), prs.getStatusCode(),
 | 
				
			||||||
					prs.getNewNick()))
 | 
										prs.getNewNick()))
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				self.dispatch('ERROR_ANSWER', ('', prs.getFrom().getStripped(), errmsg,
 | 
									self.dispatch('ERROR_ANSWER', ('', prs.getFrom().getStripped(),
 | 
				
			||||||
																					errcode))
 | 
										errmsg, errcode))
 | 
				
			||||||
		if not ptype or ptype == 'unavailable':
 | 
							if not ptype or ptype == 'unavailable':
 | 
				
			||||||
			jid = prs.getFrom()
 | 
								jid = prs.getFrom()
 | 
				
			||||||
			gajim.logger.write('status', status, str(jid).encode('utf8'), show)
 | 
								gajim.logger.write('status', status, str(jid).encode('utf8'), show)
 | 
				
			||||||
| 
						 | 
					@ -1203,7 +1204,7 @@ class Connection:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		gajim.log.debug(_('Connected to server with %s'), con_type)
 | 
							gajim.log.debug(_('Connected to server with %s'), con_type)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		self.dispatch('CON_TYPE', con_type) # notify the gui about con_type
 | 
							self.for_gui.append(['CON_TYPE', con_type]) # notify the gui about con_type
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		con.RegisterHandler('message', self._messageCB)
 | 
							con.RegisterHandler('message', self._messageCB)
 | 
				
			||||||
		con.RegisterHandler('presence', self._presenceCB)
 | 
							con.RegisterHandler('presence', self._presenceCB)
 | 
				
			||||||
| 
						 | 
					@ -1267,8 +1268,7 @@ class Connection:
 | 
				
			||||||
			gajim.log.debug("Couldn't authenticate to %s" % self.name)
 | 
								gajim.log.debug("Couldn't authenticate to %s" % self.name)
 | 
				
			||||||
			self.connected = 0
 | 
								self.connected = 0
 | 
				
			||||||
			self.dispatch('STATUS', 'offline')
 | 
								self.dispatch('STATUS', 'offline')
 | 
				
			||||||
			self.dispatch('ERROR', (_('Authentication failed with "%s"') % \
 | 
								self.dispatch('ERROR', (_('Authentication failed with "%s"') % self.name,
 | 
				
			||||||
				self.name,
 | 
					 | 
				
			||||||
				_('Please check your login and password for correctness.')))
 | 
									_('Please check your login and password for correctness.')))
 | 
				
			||||||
			return None
 | 
								return None
 | 
				
			||||||
	# END connect
 | 
						# END connect
 | 
				
			||||||
| 
						 | 
					@ -1335,7 +1335,7 @@ class Connection:
 | 
				
			||||||
		if signed:
 | 
							if signed:
 | 
				
			||||||
			p.setTag(common.xmpp.NS_SIGNED + ' x').setData(signed)
 | 
								p.setTag(common.xmpp.NS_SIGNED + ' x').setData(signed)
 | 
				
			||||||
		self.connection.send(p)
 | 
							self.connection.send(p)
 | 
				
			||||||
		self.dispatch('STATUS', 'invisible')
 | 
							self.for_gui.append(['STATUS', 'invisible'])
 | 
				
			||||||
		if initial:
 | 
							if initial:
 | 
				
			||||||
			#ask our VCard
 | 
								#ask our VCard
 | 
				
			||||||
			self.request_vcard(None)
 | 
								self.request_vcard(None)
 | 
				
			||||||
| 
						 | 
					@ -1364,14 +1364,14 @@ class Connection:
 | 
				
			||||||
		if keyID and USE_GPG:
 | 
							if keyID and USE_GPG:
 | 
				
			||||||
			if self.connected < 2 and self.gpg.passphrase is None:
 | 
								if self.connected < 2 and self.gpg.passphrase is None:
 | 
				
			||||||
				# We didn't set a passphrase
 | 
									# We didn't set a passphrase
 | 
				
			||||||
				self.dispatch('ERROR', (_('OpenPGP Key was not given'),
 | 
									self.for_gui.append(['ERROR', (_('OpenPGP Key was not given'),
 | 
				
			||||||
					_('You will be connected to %s without OpenPGP.') % self.name))
 | 
										_('You will be connected to %s without OpenPGP.') % self.name)])
 | 
				
			||||||
			else:
 | 
								else:
 | 
				
			||||||
				signed = self.gpg.sign(msg, keyID)
 | 
									signed = self.gpg.sign(msg, keyID)
 | 
				
			||||||
				if signed == 'BAD_PASSPHRASE':
 | 
									if signed == 'BAD_PASSPHRASE':
 | 
				
			||||||
					signed = ''
 | 
										signed = ''
 | 
				
			||||||
					if self.connected < 2:
 | 
										if self.connected < 2:
 | 
				
			||||||
						self.dispatch('BAD_PASSPHRASE', ())
 | 
											self.for_gui.append(['BAD_PASSPHRASE', ()])
 | 
				
			||||||
		self.status = msg
 | 
							self.status = msg
 | 
				
			||||||
		if show != 'offline' and not self.connected:
 | 
							if show != 'offline' and not self.connected:
 | 
				
			||||||
			self.connection = self.connect()
 | 
								self.connection = self.connect()
 | 
				
			||||||
| 
						 | 
					@ -1391,7 +1391,7 @@ class Connection:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if self.connection:
 | 
									if self.connection:
 | 
				
			||||||
					self.connection.send(p)
 | 
										self.connection.send(p)
 | 
				
			||||||
				self.dispatch('STATUS', show)
 | 
									self.for_gui.append(['STATUS', show])
 | 
				
			||||||
				#ask our VCard
 | 
									#ask our VCard
 | 
				
			||||||
				self.request_vcard(None)
 | 
									self.request_vcard(None)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1412,7 +1412,7 @@ class Connection:
 | 
				
			||||||
					self.connection.disconnect()
 | 
										self.connection.disconnect()
 | 
				
			||||||
				except:
 | 
									except:
 | 
				
			||||||
					pass
 | 
										pass
 | 
				
			||||||
			self.dispatch('STATUS', 'offline')
 | 
								self.for_gui.append(['STATUS', 'offline'])
 | 
				
			||||||
			self.connection = None
 | 
								self.connection = None
 | 
				
			||||||
		elif show != 'offline' and self.connected:
 | 
							elif show != 'offline' and self.connected:
 | 
				
			||||||
			was_invisible = self.connected == STATUS_LIST.index('invisible')
 | 
								was_invisible = self.connected == STATUS_LIST.index('invisible')
 | 
				
			||||||
| 
						 | 
					@ -1433,7 +1433,7 @@ class Connection:
 | 
				
			||||||
				p.setTag(common.xmpp.NS_SIGNED + ' x').setData(signed)
 | 
									p.setTag(common.xmpp.NS_SIGNED + ' x').setData(signed)
 | 
				
			||||||
			if self.connection:
 | 
								if self.connection:
 | 
				
			||||||
				self.connection.send(p)
 | 
									self.connection.send(p)
 | 
				
			||||||
			self.dispatch('STATUS', show)
 | 
								self.for_gui.append(['STATUS', show])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	def send_motd(self, jid, subject = '', msg = ''):
 | 
						def send_motd(self, jid, subject = '', msg = ''):
 | 
				
			||||||
		if not self.connection:
 | 
							if not self.connection:
 | 
				
			||||||
| 
						 | 
					@ -1861,6 +1861,10 @@ class Connection:
 | 
				
			||||||
				
 | 
									
 | 
				
			||||||
				self.connection.send(tosend)
 | 
									self.connection.send(tosend)
 | 
				
			||||||
				self.last_sent.append(time.time())
 | 
									self.last_sent.append(time.time())
 | 
				
			||||||
 | 
								while time.time() < t_limit and len(self.for_gui):
 | 
				
			||||||
 | 
									print len(self.for_gui)
 | 
				
			||||||
 | 
									tosend = self.for_gui.pop(0)
 | 
				
			||||||
 | 
									self.dispatch(tosend[0], tosend[1])
 | 
				
			||||||
			try:
 | 
								try:
 | 
				
			||||||
				if gajim.config.get_per('accounts', self.name,
 | 
									if gajim.config.get_per('accounts', self.name,
 | 
				
			||||||
				'keep_alives_enabled'): # do we want keepalives?
 | 
									'keep_alives_enabled'): # do we want keepalives?
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue