def connect(self, show='online', msg=''): self.get_config_values_or_default() if not self.connection: self.connection = client_zeroconf.ClientZeroconf(self) if not zeroconf.test_zeroconf(): app.nec.push_incoming_event(OurShowEvent(None, conn=self, show='offline')) self.status = 'offline' app.nec.push_incoming_event(ConnectionLostEvent(None, conn=self, title=_('Could not connect to "%s"') % self.name, msg=_('Please check if Avahi or Bonjour is installed.'))) self.disconnect() return result = self.connection.connect(show, msg) if not result: app.nec.push_incoming_event(OurShowEvent(None, conn=self, show='offline')) self.status = 'offline' if result is False: app.nec.push_incoming_event(ConnectionLostEvent(None, conn=self, title=_('Could not start local service'), msg=_('Unable to bind to port %d.' % self.port))) else: # result is None app.nec.push_incoming_event(ConnectionLostEvent(None, conn=self, title=_('Could not start local service'), msg=_('Please check if avahi/bonjour-daemon is running.'))) self.disconnect() return else: self.connection.announce() self.roster = self.connection.getRoster() app.nec.push_incoming_event(NetworkEvent('roster-received', conn=self, roster=self.roster.copy(), received_from_server=True)) # display contacts already detected and resolved for jid in self.roster.keys(): app.nec.push_incoming_event(NetworkEvent( 'roster-info', conn=self, jid=jid, nickname=self.roster.getName(jid), sub='both', ask='no', groups=self.roster.getGroups(jid), avatar_sha=None)) self._on_presence(jid) self.connected = STATUS_LIST.index(show) # refresh all contacts data every five seconds self.call_resolve_timeout = True GLib.timeout_add_seconds(5, self._on_resolve_timeout) return True
def connect_and_init(self, show, msg): # to check for errors from zeroconf check = True if not self.connect(show, msg): return check = self.connection.announce() # stay offline when zeroconf does something wrong if check: self._set_state(ClientState.CONNECTED) app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self)) app.nec.push_incoming_event( OurShowEvent(None, conn=self, show=show)) else: # show notification that avahi or system bus is down self._set_state(ClientState.DISCONNECTED) app.nec.push_incoming_event( OurShowEvent(None, conn=self, show='offline')) self._status = 'offline' app.nec.push_incoming_event( ConnectionLostEvent( None, conn=self, title=_('Could not change status of account "%s"') % self.name, msg=_('Please check if avahi-daemon is running.')))
def connect_and_init(self, show, msg): # to check for errors from zeroconf check = True if not self.connect(show, msg): return if show != 'invisible': check = self.connection.announce() else: self.connected = STATUS_LIST.index(show) app.nec.push_incoming_event(NetworkEvent('signed-in', conn=self)) # stay offline when zeroconf does something wrong if check: app.nec.push_incoming_event( OurShowEvent(None, conn=self, show=show)) else: # show notification that avahi or system bus is down self.connected = 0 app.nec.push_incoming_event( OurShowEvent(None, conn=self, show='offline')) self.status = 'offline' app.nec.push_incoming_event( ConnectionLostEvent( None, conn=self, title=_('Could not change status of account "%s"') % self.name, msg=_('Please check if avahi-daemon is running.')))
def _update_status(self, show, msg, idle_time=None): if self.connection.set_show_msg(show, msg): app.nec.push_incoming_event(OurShowEvent(None, conn=self, show=show)) else: # show notification that avahi or system bus is down app.nec.push_incoming_event(OurShowEvent(None, conn=self, show='offline')) self.status = 'offline' app.nec.push_incoming_event(ConnectionLostEvent(None, conn=self, title=_('Could not change status of account "%s"') % self.name, msg=_('Please check if avahi-daemon is running.')))
def _change_to_invisible(self, msg): if self.connection.remove_announce(): app.nec.push_incoming_event(OurShowEvent(None, conn=self, show='invisible')) else: # show notification that avahi or system bus is down app.nec.push_incoming_event(OurShowEvent(None, conn=self, show='offline')) self.status = 'offline' app.nec.push_incoming_event(ConnectionLostEvent(None, conn=self, title=_('Could not change status of account "%s"') % self.name, msg=_('Please check if avahi-daemon is running.')))