示例#1
0
    def tableView_acceptDrop_row_dropOperation_(self, table, info, row, dropOperation):
        pboard = info.draggingPasteboard()
        if not self.management_enabled:
            return False

        if pboard.availableTypeFromArray_(["dragged-contact"]):
            group, contact = eval(pboard.stringForType_("dragged-contact"))
            if contact is None and group is not None:
                try:
                    g = NSApp.delegate().contactsWindowController.model.contactGroupsList[group]
                    if type(g) == BlinkContactGroup:
                        for contact in g.contacts:
                            uri = contact.uri
                            if uri:
                                uri = sip_prefix_pattern.sub("", str(uri))
                            self.updatePolicyAction(self.account, self.event, uri, self.defaultPolicy)
                        return True
                except KeyError:
                    return False

        if pboard.availableTypeFromArray_(["x-blink-sip-uri"]):
            uri = str(pboard.stringForType_("x-blink-sip-uri"))
            if uri:
                uri = sip_prefix_pattern.sub("", str(uri))
            self.updatePolicyAction(self.account, self.event, uri, self.defaultPolicy)
            return True

        return False
示例#2
0
    def tableView_acceptDrop_row_dropOperation_(self, table, info, row,
                                                dropOperation):
        pboard = info.draggingPasteboard()
        if not self.management_enabled:
            return False

        if pboard.availableTypeFromArray_(["dragged-contact"]):
            group, contact = eval(pboard.stringForType_("dragged-contact"))
            if contact is None and group is not None:
                try:
                    g = NSApp.delegate(
                    ).contactsWindowController.model.contactGroupsList[group]
                    if type(g) == BlinkContactGroup:
                        for contact in g.contacts:
                            uri = contact.uri
                            if uri:
                                uri = sip_prefix_pattern.sub("", str(uri))
                            self.updatePolicyAction(self.account, self.event,
                                                    uri, self.defaultPolicy)
                        return True
                except KeyError:
                    return False

        if pboard.availableTypeFromArray_(["x-blink-sip-uri"]):
            uri = str(pboard.stringForType_("x-blink-sip-uri"))
            if uri:
                uri = sip_prefix_pattern.sub("", str(uri))
            self.updatePolicyAction(self.account, self.event, uri,
                                    self.defaultPolicy)
            return True

        return False
    def addRemoveParticipant_(self, sender):
        if sender.selectedSegment() == 0:
            participant = self.participant.stringValue().strip().lower()

            if participant and "@" not in participant and self.default_domain:
                participant = '%s@%s' % (participant, self.default_domain)

            if participant:
                participant = sip_prefix_pattern.sub("", str(participant))

            if not participant or not validateParticipant(participant):
                NSRunAlertPanel("Add New Participant", "Participant must be a valid SIP addresses.", "OK", None, None)
                return

            if participant not in self._participants:
                self._participants.append(participant)
                self.participantsTable.reloadData()
                self.participantsTable.scrollRowToVisible_(len(self._participants)-1)
                self.participant.setStringValue_('')
        elif sender.selectedSegment() == 1:
            participant = self.selectedParticipant()
            if participant is None and self._participants:
                participant = self._participants[-1]
            if participant is not None:
                self._participants.remove(participant)
                self.participantsTable.reloadData()
    def addRemoveParticipant_(self, sender):
        if sender.selectedSegment() == 0:
            participant = self.participant.stringValue().strip().lower()

            if participant and "@" not in participant and self.default_domain:
                participant = '%s@%s' % (participant, self.default_domain)

            if participant:
                participant = sip_prefix_pattern.sub("", str(participant))

            if not participant or not validateParticipant(participant):
                NSRunAlertPanel("Add New Participant",
                                "Participant must be a valid SIP addresses.",
                                "OK", None, None)
                return

            if participant not in self._participants:
                self._participants.append(participant)
                self.participantsTable.reloadData()
                self.participantsTable.scrollRowToVisible_(
                    len(self._participants) - 1)
                self.participant.setStringValue_('')
        elif sender.selectedSegment() == 1:
            participant = self.selectedParticipant()
            if participant is None and self._participants:
                participant = self._participants[-1]
            if participant is not None:
                self._participants.remove(participant)
                self.participantsTable.reloadData()
    def addRemoveParticipant_(self, sender):
        if sender.selectedSegment() == 0:
            participant = self.participant.stringValue().strip().lower()

            if participant and "@" not in participant and self.default_domain:
                participant = '%s@%s' % (participant, self.default_domain)

            if participant:
                participant = sip_prefix_pattern.sub("", str(participant))

            if not participant or not validateParticipant(participant):
                NSRunAlertPanel(NSLocalizedString("Add New Participant", "Window title"),
                                NSLocalizedString("Participant must be a valid SIP address. ", "Label"),
                                NSLocalizedString("OK", "Button title"),
                                None, None)
                return

            if participant not in self._participants:
                self._participants.append(participant)
                self.startWhenParticipantsAvailable.setEnabled_(True)
                self.participantsTable.reloadData()
                self.participantsTable.scrollRowToVisible_(len(self._participants)-1)
                self.participant.setStringValue_('')
        elif sender.selectedSegment() == 1:
            participant = self.selectedParticipant()
            if participant is None and self._participants:
                participant = self._participants[-1]
            if participant is not None:
                self._participants.remove(participant)
                self.startWhenParticipantsAvailable.setEnabled_(bool(len(self._participants)))
                if len(self._participants) == 0:
                    self.startWhenParticipantsAvailable.setState_(NSOffState)
                self.participantsTable.reloadData()
示例#6
0
    def render_pidf(self):
        if not self.contact:
            return
        has_locations = False
        status_label = ''
        if self.contact.presence_state['devices']:
            has_locations = any(device['location'] for device in list(self.contact.presence_state['devices'].values()) if device['location'] is not None)
            count = len(self.contact.presence_state['devices'])
            if count == 1:
                status_label = NSLocalizedString("One device available", "Label")
            elif count > 1:
                status_label = NSLocalizedString("%d devices available" % count, "Label")

        splitViewFrame = self.splitView.frame()
        mapViewFrame = self.mapViewSplitView.frame()
        pidfViewFrame = self.pidfView.frame()

        if has_locations:
            if mapViewFrame.size.height == 0:
                mapViewFrame.size.height = SPLITTER_HEIGHT
                self.mapViewSplitView.setFrame_(mapViewFrame)
                pidfViewFrame.size.height -= SPLITTER_HEIGHT
                self.pidfView.setFrame_(pidfViewFrame)
            self.mapView.setContact(self.contact)
            nr_countries = len(self.mapView.selectedCountries)
            if nr_countries == 1:
                status_label += NSLocalizedString(" in one country", "Label")
            elif nr_countries > 1:
                status_label +=  NSLocalizedString(" in %d countries" % nr_countries, "Label")
        else:
            mapViewFrame.size.height = 0
            self.mapViewSplitView.setFrame_(mapViewFrame)
            pidfViewFrame.size.height = splitViewFrame.size.height
            self.pidfView.setFrame_(pidfViewFrame)

        self.statusLabel.setStringValue_(status_label)

        text = ''
        for pidf in self.contact.pidfs:
            text += self.build_pidf_text(pidf) + '\n\n'

        if self.contact.presence_state['pending_authorizations']:
            text += "Pending authorizations:\n"

        pending_authorizations = self.contact.presence_state['pending_authorizations']
        for key in list(pending_authorizations.keys()):
            text += "    Subscription to %s from account %s\n" % (sip_prefix_pattern.sub('', key), pending_authorizations[key])

        self.presenceText.textStorage().deleteCharactersInRange_(NSMakeRange(0, self.presenceText.textStorage().length()))
        astring = NSAttributedString.alloc().initWithString_(text)
        self.presenceText.textStorage().appendAttributedString_(astring)

        image = presence_status_for_contact(self.contact)
        if image:
            icon = NSImage.imageNamed_(image)
            icon.setScalesWhenResized_(True)
            icon.setSize_(NSMakeSize(12,12))
            self.presence_icon.setImage_(icon)
    def render_pidf(self):
        if not self.contact:
            return
        has_locations = False
        status_label = ''
        if self.contact.presence_state['devices']:
            has_locations = any(device['location'] for device in self.contact.presence_state['devices'].values() if device['location'] is not None)
            count = len(self.contact.presence_state['devices'])
            if count == 1:
                status_label = 'One device available'
            elif count > 1:
                status_label = '%d devices available' % count

        splitViewFrame = self.splitView.frame()
        mapViewFrame = self.mapViewSplitView.frame()
        pidfViewFrame = self.pidfView.frame()

        if has_locations:
            if mapViewFrame.size.height == 0:
                mapViewFrame.size.height = SPLITTER_HEIGHT
                self.mapViewSplitView.setFrame_(mapViewFrame)
                pidfViewFrame.size.height -= SPLITTER_HEIGHT
                self.pidfView.setFrame_(pidfViewFrame)
            self.mapView.setContact(self.contact)
            nr_countries = len(self.mapView.selectedCountries)
            if nr_countries == 1:
                status_label += ' in one country'
            elif nr_countries > 1:
                status_label += ' in %d countries' % nr_countries
        else:
            mapViewFrame.size.height = 0
            self.mapViewSplitView.setFrame_(mapViewFrame)
            pidfViewFrame.size.height = splitViewFrame.size.height
            self.pidfView.setFrame_(pidfViewFrame)

        self.statusLabel.setStringValue_(status_label)

        text = ''
        for pidf in self.contact.pidfs:
            text += self.build_pidf_text(pidf) + '\n\n'

        if self.contact.presence_state['pending_authorizations']:
            text += "Pending authorizations:\n"

        pending_authorizations = self.contact.presence_state['pending_authorizations']
        for key in pending_authorizations.keys():
            text += "    Subscription to %s from account %s\n" % (sip_prefix_pattern.sub('', key), pending_authorizations[key])

        self.presenceText.textStorage().deleteCharactersInRange_(NSMakeRange(0, self.presenceText.textStorage().length()))
        astring = NSAttributedString.alloc().initWithString_(text)
        self.presenceText.textStorage().appendAttributedString_(astring)

        image = presence_status_for_contact(self.contact)
        if image:
            icon = NSImage.imageNamed_(image)
            icon.setScalesWhenResized_(True)
            icon.setSize_(NSMakeSize(12,12))
            self.presence_icon.setImage_(icon)
 def tableView_validateDrop_proposedRow_proposedDropOperation_(self, table, info, row, oper):
     if info.draggingPasteboard().availableTypeFromArray_(["x-blink-sip-uri"]):
         participant = info.draggingPasteboard().stringForType_("x-blink-sip-uri")
         if participant:
             participant = sip_prefix_pattern.sub("", str(participant))
         if participant and "@" not in participant and self.default_domain:
             participant = '%s@%s' % (participant, self.default_domain)
         if participant is None or not validateParticipant(participant):
             return NSDragOperationNone
         return NSDragOperationGeneric
     else:
         return NSDragOperationNone
 def tableView_validateDrop_proposedRow_proposedDropOperation_(self, table, info, row, oper):
     participant = info.draggingPasteboard().stringForType_("x-blink-sip-uri")
     if participant and "@" not in participant and self.default_domain:
         participant = '%s@%s' % (participant, self.default_domain)
     if participant:
         participant = sip_prefix_pattern.sub("", str(participant))
     try:
         if participant is None or not validateParticipant(participant):
             return NSDragOperationNone
     except:
         return NSDragOperationNone
     return NSDragOperationGeneric
示例#10
0
    def _NH_SIPAccountWatcherinfoGotData(self, notification):
        account = notification.sender
        watchers = notification.data.pending
        for w in watchers:
            if w.status in ("pending", "waiting"):
                uri = sip_prefix_pattern.sub("", str(w.sipuri))
                pendingWatcher = PendingWatcher(address=uri, account=str(account.id), event='presence', confirm=True)
                hasWatcher = any(watcher for watcher in self.pendingWatchers if watcher.account == pendingWatcher.account and watcher.event == pendingWatcher.event and watcher.address == pendingWatcher.address)
                if not hasWatcher:
                    BlinkLogger().log_info(u"New presence subscriber %s for account %s" %(pendingWatcher.address, pendingWatcher.account))
                    self.pendingWatchers.append(pendingWatcher)

        if self.pendingWatchers and self.initial_checked_pending:
            self.showPendingWatchers()
示例#11
0
    def addRemoveParticipant_(self, sender):
        if sender.selectedSegment() == 0:
            participant = self.participant.stringValue().strip().lower()
            if participant:
                participant = sip_prefix_pattern.sub("", str(participant))
            self.addParticipant(participant)
        elif sender.selectedSegment() == 1:
            participant = self.selectedParticipant()
            if participant is None and self._participants:
                participant = self._participants[-1]
            if participant is not None:
                self._participants.remove(participant)
                self.participantsTable.reloadData()

        self.removeAllParticipants.setHidden_(False if len(self._participants) > 1 else True)
示例#12
0
 def tableView_acceptDrop_row_dropOperation_(self, table, info, row, oper):
     participant = info.draggingPasteboard().stringForType_("x-blink-sip-uri")
     if participant and "@" not in participant and self.default_domain:
         participant = '%s@%s' % (participant, self.default_domain)
     if participant:
         participant = sip_prefix_pattern.sub("", str(participant))
     try:
         if participant not in self._participants:
             self._participants.append(participant)
             self.participantsTable.reloadData()
             self.participantsTable.scrollRowToVisible_(len(self._participants)-1)
             return True
     except:
         pass
     return False
    def addContactUriToInvitationList(self, participant):
        if participant and "@" not in participant and self.default_domain:
            participant = '%s@%s' % (participant, self.default_domain)

        if participant:
            participant = sip_prefix_pattern.sub("", str(participant))

        try:
            if participant not in self._participants:
                self._participants.append(participant)
                self.startWhenParticipantsAvailable.setEnabled_(True)
                self.participantsTable.reloadData()
                self.removeAllParticipants.setHidden_(False if len(self._participants) > 1 else True)
                self.participantsTable.scrollRowToVisible_(len(self._participants)-1)
        except:
            pass
    def addContactUriToInvitationList(self, participant):
        if participant and "@" not in participant and self.default_domain:
            participant = '%s@%s' % (participant, self.default_domain)

        if participant:
            participant = sip_prefix_pattern.sub("", str(participant))

        try:
            if participant not in self._participants:
                self._participants.append(participant)
                self.startWhenParticipantsAvailable.setEnabled_(True)
                self.participantsTable.reloadData()
                self.removeAllParticipants.setHidden_(False if len(self._participants) > 1 else True)
                self.participantsTable.scrollRowToVisible_(len(self._participants)-1)
        except:
            pass
示例#15
0
    def addRemoveParticipant_(self, sender):
        if sender.selectedSegment() == 0:
            participant = self.participant.stringValue().strip().lower()
            if participant:
                participant = sip_prefix_pattern.sub("", str(participant))
            self.addParticipant(participant)
        elif sender.selectedSegment() == 1:
            participant = self.selectedParticipant()
            if participant is None and self._participants:
                participant = self._participants[-1]
            if participant is not None:
                self._participants.remove(participant)
                self.participantsTable.reloadData()

        self.removeAllParticipants.setHidden_(
            False if len(self._participants) > 1 else True)
示例#16
0
    def tableView_validateDrop_proposedRow_proposedDropOperation_(self, table, info, row, oper):
        pboard = info.draggingPasteboard()
        if not self.management_enabled:
            return NSDragOperationNone

        if pboard.availableTypeFromArray_(["dragged-contact"]):
            group, contact = eval(pboard.stringForType_("dragged-contact"))
            if contact is None:
                return NSDragOperationAll

        if pboard.availableTypeFromArray_(["x-blink-sip-uri"]):
            uri = str(pboard.stringForType_("x-blink-sip-uri"))
            if uri:
                uri = sip_prefix_pattern.sub("", str(uri))
            return NSDragOperationAll

        return NSDragOperationNone
示例#17
0
 def tableView_acceptDrop_row_dropOperation_(self, table, info, row, oper):
     participant = info.draggingPasteboard().stringForType_(
         "x-blink-sip-uri")
     if participant and "@" not in participant and self.default_domain:
         participant = '%s@%s' % (participant, self.default_domain)
     if participant:
         participant = sip_prefix_pattern.sub("", str(participant))
     try:
         if participant not in self._participants:
             self._participants.append(participant)
             self.participantsTable.reloadData()
             self.participantsTable.scrollRowToVisible_(
                 len(self._participants) - 1)
             return True
     except:
         pass
     return False
示例#18
0
    def tableView_validateDrop_proposedRow_proposedDropOperation_(
            self, table, info, row, oper):
        pboard = info.draggingPasteboard()
        if not self.management_enabled:
            return NSDragOperationNone

        if pboard.availableTypeFromArray_(["dragged-contact"]):
            group, contact = eval(pboard.stringForType_("dragged-contact"))
            if contact is None:
                return NSDragOperationAll

        if pboard.availableTypeFromArray_(["x-blink-sip-uri"]):
            uri = str(pboard.stringForType_("x-blink-sip-uri"))
            if uri:
                uri = sip_prefix_pattern.sub("", str(uri))
            return NSDragOperationAll

        return NSDragOperationNone
示例#19
0
    def _NH_SIPAccountWatcherinfoGotData(self, notification):
        account = notification.sender
        watchers = notification.data.pending
        for w in watchers:
            if w.status in ("pending", "waiting"):
                uri = sip_prefix_pattern.sub("", str(w.sipuri))
                pendingWatcher = PendingWatcher(address=uri,
                                                account=str(account.id),
                                                event='presence',
                                                confirm=True)
                hasWatcher = any(watcher for watcher in self.pendingWatchers
                                 if watcher.account == pendingWatcher.account
                                 and watcher.event == pendingWatcher.event
                                 and watcher.address == pendingWatcher.address)
                if not hasWatcher:
                    BlinkLogger().log_info(
                        u"New presence subscriber %s for account %s" %
                        (pendingWatcher.address, pendingWatcher.account))
                    self.pendingWatchers.append(pendingWatcher)

        if self.pendingWatchers and self.initial_checked_pending:
            self.showPendingWatchers()