Example #1
0
    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.')))
Example #2
0
    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.')))
    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
Example #6
0
 def _on_name_conflictCB(self, alt_name):
     self.disconnect()
     app.nec.push_incoming_event(
         OurShowEvent(None, conn=self, show='offline'))
     app.nec.push_incoming_event(
         NetworkEvent('zeroconf-name-conflict',
                      conn=self,
                      alt_name=alt_name))
Example #7
0
    def disconnect(self, reconnect=True, immediately=True):
        log.info('Start disconnecting zeroconf')
        if reconnect:
            self.time_to_reconnect = 5
        else:
            self.time_to_reconnect = None

        self._set_state(ClientState.DISCONNECTED)
        if self.connection:
            self.connection.disconnect()
            self.connection = None
            # stop calling the timeout
            self.call_resolve_timeout = False
        app.nec.push_incoming_event(
            OurShowEvent(None, conn=self, show='offline'))
    def disconnect(self, reconnect=True, immediately=True):
        log.info('Start disconnecting zeroconf')
        if reconnect:
            if app.account_is_connected(self.name):
                # we cannot change our status to offline or connecting
                # after we auth to server
                self.old_show = STATUS_LIST[self.connected]

            # random number to show we wait network manager to send
            # us a reconenct
            self.time_to_reconnect = 5
        else:
            self.time_to_reconnect = None

        self.connected = 0
        if self.connection:
            self.connection.disconnect()
            self.connection = None
            # stop calling the timeout
            self.call_resolve_timeout = False
        app.nec.push_incoming_event(OurShowEvent(None, conn=self,
            show='offline'))
Example #9
0
 def _on_abort_clicked(self, _button):
     self._con.disconnect(reconnect=False)
     app.nec.push_incoming_event(
         OurShowEvent(None, conn=self._con, show='offline'))
     self.destroy()
Example #10
0
 def _on_disconnect(self):
     self._set_state(ClientState.DISCONNECTED)
     app.nec.push_incoming_event(
         OurShowEvent(None, conn=self, show='offline'))
Example #11
0
 def _on_disconnect(self):
     self.connected = 0
     app.nec.push_incoming_event(OurShowEvent(None, conn=self,
         show='offline'))