Exemple #1
0
 def __init__(self, account, uri, display_name, parent=None):
     super(PendingWatcherDialog, self).__init__(parent)
     self.setWindowFlags(self.windowFlags() | Qt.WindowStaysOnTopHint)
     self.setAttribute(Qt.WA_DeleteOnClose)
     with Resources.directory:
         self.setupUi(self)
     default_font_size = self.uri_label.fontInfo().pointSizeF()
     name_font_size = limit(default_font_size + 3, max=14)
     font = self.name_label.font()
     font.setPointSizeF(name_font_size)
     self.name_label.setFont(font)
     addressbook_manager = addressbook.AddressbookManager()
     try:
         self.contact = next(
             contact for contact in addressbook_manager.get_contacts()
             if uri in (addr.uri for addr in contact.uris))
     except StopIteration:
         self.contact = None
     else:
         display_name = self.contact.name
         icon_manager = IconManager()
         icon = icon_manager.get(self.contact.id)
         if icon is not None:
             self.user_icon.setPixmap(icon.pixmap(48))
     self.description_label.setText(
         'Wants to subscribe to your availability information at {}'.format(
             account.id))
     self.name_label.setText(display_name or uri)
     self.uri_label.setText(uri)
     self.accept_button.released.connect(self._accept_watcher)
     self.block_button.released.connect(self._block_watcher)
     self.position = None
     self.timer = QTimer()
     self.timer.timeout.connect(self._SH_TimerFired)
     self.timer.start(60000)
Exemple #2
0
    def _NH_SIPAccountGotPresenceWinfo(self, notification):
        addressbook_manager = addressbook.AddressbookManager()
        account = notification.sender
        watcher_list = notification.data.watcher_list

        self._winfo_map.setdefault(account.id, {})
        if notification.data.state == 'full':
            self._winfo_map[account.id].clear()

        for watcher in watcher_list:
            uri = self.sip_prefix_re.sub('', watcher.sipuri)
            if uri != account.id:
                # Skip own URI, XCAP may be down and policy may not be inplace yet
                self._winfo_map[account.id].setdefault(watcher.status, set()).add(uri)

        pending_watchers = self._winfo_map[account.id].setdefault('pending', set()) | self._winfo_map[account.id].setdefault('waiting', set())
        for uri in pending_watchers:
            # check if there is a policy
            try:
                next(policy for policy in addressbook_manager.get_policies() if policy.uri == uri and policy.presence.policy != 'default')
            except StopIteration:
                # check if there is a contact
                try:
                    next(contact for contact in addressbook_manager.get_contacts() if contact.presence.policy != 'default' and uri in (addr.uri for addr in contact.uris))
                except StopIteration:
                    # TODO: add display name -Saul
                    if uri not in self._winfo_timers:
                        self._winfo_timers[uri] = reactor.callLater(600, self._winfo_timers.pop, uri, None)
                        notification.center.post_notification('SIPAccountGotPendingWatcher', sender=account, data=NotificationData(uri=uri, display_name=None, event='presence'))
Exemple #3
0
 def __init__(self, account, uri, display_name, parent=None):
     super(PendingWatcherDialog, self).__init__(parent)
     self.setWindowFlags(Qt.WindowStaysOnTopHint)
     self.setAttribute(Qt.WA_DeleteOnClose)
     with Resources.directory:
         self.setupUi(self)
     addressbook_manager = addressbook.AddressbookManager()
     try:
         self.contact = next(
             contact for contact in addressbook_manager.get_contacts()
             if uri in (addr.uri for addr in contact.uris))
     except StopIteration:
         self.contact = None
     else:
         display_name = self.contact.name
         icon_manager = IconManager()
         icon = icon_manager.get(self.contact.id)
         if icon is not None:
             self.user_icon.setPixmap(icon.pixmap(32))
     self.account_label.setText(u'For account %s' % account.id)
     self.name_label.setText(display_name or uri)
     self.uri_label.setText(uri)
     font = self.name_label.font()
     font.setPointSizeF(self.uri_label.fontInfo().pointSizeF() + 3)
     font.setFamily("Sans Serif")
     self.name_label.setFont(font)
     self.accept_button.released.connect(self._accept_watcher)
     self.block_button.released.connect(self._block_watcher)
     self.position = None
     self.timer = QTimer()
     self.timer.timeout.connect(self._SH_TimerFired)
     self.timer.start(60000)
Exemple #4
0
    def _process_presence_data(self, uris=None):
        addressbook_manager = addressbook.AddressbookManager()

        def service_sort_key(service):
            timestamp = service.timestamp.value if service.timestamp else epoch
            if service.status.extended is not None:
                return 100, timestamp
            elif service.status.basic == 'open':
                return 10, timestamp
            else:
                return 0, timestamp

        current_pidf_map = {}
        contact_pidf_map = {}

        # If no URIs were provided, process all of them
        if not uris:
            uris = list(chain(*(iter(item.keys()) for item in self._pidf_map.values())))

        for uri, pidf_list in chain(*(iter(x.items()) for x in self._pidf_map.values())):
            current_pidf_map.setdefault(uri, []).extend(pidf_list)

        for uri in uris:
            pidf_list = current_pidf_map.get(uri, [])
            for contact in (contact for contact in addressbook_manager.get_contacts() if uri in (self.sip_prefix_re.sub('', contact_uri.uri) for contact_uri in contact.uris)):
                contact_pidf_map.setdefault(contact, []).extend(pidf_list)

        for contact, pidf_list in contact_pidf_map.items():
            if not pidf_list:
                state = note = icon = None
            else:
                services = list(chain(*(list(pidf_doc.services) for pidf_doc in pidf_list)))
                services.sort(key=service_sort_key, reverse=True)
                service = services[0]
                if service.status.extended:
                    state = str(service.status.extended)
                else:
                    state = 'available' if service.status.basic == 'open' else 'offline'
                note = str(next(iter(service.notes))) if service.notes else None
                icon_url = str(service.icon) if service.icon else None

                if icon_url:
                    url, token, icon_hash = icon_url.partition('#blink-icon')
                    if token:
                        if contact.icon and icon_hash == contact.icon.etag:
                            # Fast path, icon hasn't changed
                            icon = None
                        else:
                            # New icon, client uses fast path mechanism
                            icon = ContactIcon.fetch(icon_url, etag=None, descriptor_etag=icon_hash)
                    else:
                        icon = ContactIcon.fetch(icon_url, etag=contact.icon.etag if contact.icon else None)
                else:
                    icon = None
            self._update_presence_state(contact, state, note, icon)