def makeDragImage(self): if self.delegate is None: return image = NSImage.alloc().initWithSize_(self.frame().size) image.lockFocus() frame = self.frame() frame.origin = NSZeroPoint rect = NSInsetRect(frame, 1.5, 1.5) if self.conferencing and not self.draggedOut: NSColor.selectedControlColor().colorWithAlphaComponent_(0.7).set() else: NSColor.whiteColor().colorWithAlphaComponent_(0.7).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0) path.fill() if self.selected: path.setLineWidth_(3) NSColor.grayColor().set() else: path.setLineWidth_(1) NSColor.grayColor().set() path.stroke() NSColor.blackColor().set() point = NSMakePoint(8, NSMaxY(frame)-20) uri = format_identity_to_string(self.delegate.sessionController.remotePartyObject, check_contact=False, format='compact') NSString.stringWithString_(uri).drawAtPoint_withAttributes_(point, NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.boldSystemFontOfSize_(12), NSFontAttributeName)) point = NSMakePoint(8, 6) if self.conferencing: NSString.stringWithString_(NSLocalizedString("Drop outside to remove from conference", "Audio session label")).drawAtPoint_withAttributes_(point, NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.systemFontOfSize_(10), NSFontAttributeName)) else: audio_sessions = [sess.hasStreamOfType("audio") for sess in NSApp.delegate().contactsWindowController.sessionControllersManager.sessionControllers] if self.delegate.transferEnabled: text = NSLocalizedString("Drop this over a session or contact", "Audio session label") if len(audio_sessions) > 1 else NSLocalizedString("Drop this over a contact to transfer", "Audio session label") else: text = NSLocalizedString("Drop this over a session to conference", "Audio session label") NSString.stringWithString_(text).drawAtPoint_withAttributes_(point, NSDictionary.dictionaryWithObjectsAndKeys_(NSFont.systemFontOfSize_(10), NSFontAttributeName)) icon = NSImage.imageNamed_("NSEveryone") rect = frame s = icon.size() p = NSMakePoint(NSWidth(rect) - s.width - 8, rect.size.height - s.height - 8) r = NSMakeRect(0, 0, s.width, s.height) icon.drawAtPoint_fromRect_operation_fraction_(p, r, NSCompositeSourceOver, 0.5) image.unlockFocus() return image
def okClicked_(self, sender): self.statusText.setTextColor_(NSColor.blackColor()) if self.finished: self.window.orderOut_(self) return secret = self.secretText.stringValue().encode('utf-8') if not secret: return if self.response: self.ctx.smpGotSecret(secret, appdata={'stream': self.chatController.stream}) self.progressBar.setIndeterminate_(False) self.progressBar.setDoubleValue_(6) self.continueButton.setEnabled_(False) self.statusText.setStringValue_('Responding to verification request...') else: try: qtext = self.questionText.stringValue() if qtext: self.ctx.smpInit(secret, question=qtext.encode('utf-8'), appdata={'stream': self.chatController.stream}) else: self.ctx.smpInit(secret, appdata={'stream': self.chatController.stream}) self.progressBar.setIndeterminate_(False) self.progressBar.setDoubleValue_(3) self.statusText.setStringValue_('Verification request sent') self.continueButton.setEnabled_(False) except potr.context.NotEncryptedError, e: self.statusText.setStringValue_('Chat session is not OTR encrypted') except RuntimeError, e: self.statusText.setStringValue_('OTR encryption error: %s' % e)
def drawRect_(self, rect): NSImageView.drawRect_(self, rect) if self.cropRectangle: rect = NSZeroRect rect.size = self.frame().size NSColor.whiteColor().set() NSFrameRect(self.cropRectangle) clip = NSBezierPath.bezierPathWithRect_(rect) clip.setWindingRule_(NSEvenOddWindingRule) clip.appendBezierPathWithRect_(self.cropRectangle) clip.addClip() NSColor.blackColor().colorWithAlphaComponent_(0.6).set() NSBezierPath.bezierPathWithRect_(rect).fill()
def getButtonImageForState(self, size, pushed): image = NSImage.alloc().initWithSize_(size) image.lockFocus() rect = NSMakeRect(1, 1, size.width-1, size.height-1) NSColor.clearColor().set() NSRectFill(rect) try: NSColor.blackColor().set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 8.0, 8.0) path.fill() path.setLineWidth_(2) NSColor.grayColor().set() path.stroke() finally: image.unlockFocus() return image
def setSelected_(self, flag): if flag: self.nameText.setTextColor_(NSColor.whiteColor()) self.fromText.setTextColor_(NSColor.whiteColor()) self.sizeText.setTextColor_(NSColor.whiteColor()) else: self.nameText.setTextColor_(NSColor.blackColor()) self.fromText.setTextColor_(NSColor.grayColor()) if self.failed: self.sizeText.setTextColor_(NSColor.redColor()) else: self.sizeText.setTextColor_(NSColor.grayColor())
def __init__(self, account, encryptedKeyPair): NSBundle.loadNibNamed_owner_("ImportPrivateKeyWindow", self) self.account = account self.encryptedKeyPair = encryptedKeyPair self.checksum.setStringValue_('') self.importButton.setEnabled_(False) self.window.makeFirstResponder_(self.pincode) self.status.setTextColor_(NSColor.blackColor()) self.status.setStringValue_( NSLocalizedString("Enter pincode to decrypt the key", "status label"))
def initWithFrame_(self, frame): """ basic constructor for views. here we init colors and gradients """ self = super(CBGraphView, self).initWithFrame_(frame) if self: self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_(50/255.0, 50/255.0, 50/255.0, 1.0) self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_(33/255.0, 104/255.0, 198/255.0, 1.0) self.lineColorAboveLimit = NSColor.redColor() self.borderColor = NSColor.whiteColor() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_(NSColor.blackColor(), self.gradientGray) self.grad.retain() return self
def initWithFrame_(self, frame): """ basic constructor for views. here we init colors and gradients """ self = objc.super(CBGraphView, self).initWithFrame_(frame) if self: self.gradientGray = NSColor.colorWithCalibratedRed_green_blue_alpha_( 50 / 255.0, 50 / 255.0, 50 / 255.0, 1.0) self.lineColor = NSColor.colorWithCalibratedRed_green_blue_alpha_( 33 / 255.0, 104 / 255.0, 198 / 255.0, 1.0) self.lineColorAboveLimit = NSColor.redColor() self.borderColor = NSColor.whiteColor() self.grad = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.blackColor(), self.gradientGray) self.grad.retain() return self
def okClicked_(self, sender): self.statusText.setTextColor_(NSColor.blackColor()) if self.finished: self.window.orderOut_(self) return secret = self.secretText.stringValue() secret = secret.encode() if secret else None if self.requested_by_remote: self.controller.sessionController.log_info("OTR SMP verification will be answered") self.stream.encryption.smp_answer(secret) self.smp_running = True self.progressBar.setDoubleValue_(6) else: qtext = self.questionText.stringValue() qtext = qtext.encode() if qtext else None self.controller.sessionController.log_info("OTR SMP verification will be requested") self.stream.encryption.smp_verify(secret, qtext) self.progressBar.setIndeterminate_(False) self.smp_running = True self.progressBar.setDoubleValue_(3) self.statusText.setStringValue_(NSLocalizedString("Verification request sent", "Label")) self.continueButton.setEnabled_(False)
def makeDragImage(self): if self.delegate is None: return image = NSImage.alloc().initWithSize_(self.frame().size) image.lockFocus() frame = self.frame() frame.origin = NSZeroPoint rect = NSInsetRect(frame, 1.5, 1.5) if self.conferencing and not self.draggedOut: NSColor.selectedControlColor().colorWithAlphaComponent_(0.7).set() else: NSColor.whiteColor().colorWithAlphaComponent_(0.7).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( rect, 5.0, 5.0) path.fill() if self.selected: path.setLineWidth_(3) NSColor.grayColor().set() else: path.setLineWidth_(1) NSColor.grayColor().set() path.stroke() NSColor.blackColor().set() point = NSMakePoint(8, NSMaxY(frame) - 20) uri = format_identity_to_string( self.delegate.sessionController.remoteIdentity, check_contact=False, format='compact') NSString.stringWithString_(uri).drawAtPoint_withAttributes_( point, NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.boldSystemFontOfSize_(12), NSFontAttributeName)) point = NSMakePoint(8, 6) if self.conferencing: NSString.stringWithString_( NSLocalizedString( "Drop outside to remove from conference", "Audio status label")).drawAtPoint_withAttributes_( point, NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(10), NSFontAttributeName)) else: audio_sessions = [ sess.hasStreamOfType("audio") for sess in NSApp.delegate().contactsWindowController. sessionControllersManager.sessionControllers ] if self.delegate.transferEnabled: text = NSLocalizedString( "Drop this over a session or contact", "Audio status label" ) if len(audio_sessions) > 1 else NSLocalizedString( "Drop this over a contact to transfer", "Audio status label") else: text = NSLocalizedString( "Drop this over a session to conference", "Audio status label") NSString.stringWithString_(text).drawAtPoint_withAttributes_( point, NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(10), NSFontAttributeName)) icon = NSImage.imageNamed_("NSEveryone") rect = frame s = icon.size() p = NSMakePoint( NSWidth(rect) - s.width - 8, rect.size.height - s.height - 8) r = NSMakeRect(0, 0, s.width, s.height) icon.drawAtPoint_fromRect_operation_fraction_(p, r, NSCompositeSourceOver, 0.5) image.unlockFocus() return image
def handle_tlv(self, tlvs): self.statusText.setTextColor_(NSColor.blackColor()) if tlvs: fingerprint = self.ctx.getCurrentKey() is1qtlv = self.get_tlv(tlvs, potr.proto.SMP1QTLV) # check for TLV_SMP_ABORT or state = CHEATED if self.smp_running and not self.ctx.smpIsValid(): self.statusText.setTextColor_(NSColor.redColor()) self.statusText.setStringValue_('Verification failed. You may try again later.') self._finish() # check for TLV_SMP1 elif self.get_tlv(tlvs, potr.proto.SMP1TLV): self.statusText.setStringValue_('Verification request received') self.smp_running = True self.question = None self.show(True) self.progressBar.setIndeterminate_(False) self.progressBar.setDoubleValue_(3) # check for TLV_SMP1Q elif is1qtlv: self.smp_running = True self.question = is1qtlv.msg self.show(True) self.progressBar.setIndeterminate_(False) self.progressBar.setDoubleValue_(3) # check for TLV_SMP2 elif self.get_tlv(tlvs, potr.proto.SMP2TLV): self.progressBar.setIndeterminate_(False) self.progressBar.setDoubleValue_(6) self.statusText.setStringValue_('Verification in progress...') # check for TLV_SMP3 elif self.get_tlv(tlvs, potr.proto.SMP3TLV): if self.ctx.smpIsSuccess(): self.statusText.setTextColor_(NSColor.greenColor()) self.statusText.setStringValue_('Verification succeeded') if fingerprint: self.chatController.otr_account.setTrust(self.chatController.sessionController.remoteSIPAddress, str(fingerprint), 'verified') self.chatController.chatWindowController.revalidateToolbar() self.chatController.updateEncryptionWidgets() self._finish() else: self.statusText.setTextColor_(NSColor.redColor()) self.statusText.setStringValue_('Verification failed. You may try again later.') self._finish() # check for TLV_SMP4 elif self.get_tlv(tlvs, potr.proto.SMP4TLV): if self.ctx.smpIsSuccess(): self.statusText.setTextColor_(NSColor.greenColor()) self.statusText.setStringValue_('Verification succeeded') if fingerprint: self.chatController.otr_account.setTrust(self.chatController.sessionController.remoteSIPAddress, str(fingerprint), 'verified') self.chatController.chatWindowController.revalidateToolbar() self.chatController.updateEncryptionWidgets() self._finish() else: self.statusText.setTextColor_(NSColor.redColor()) self.statusText.setStringValue_('Verification failed. You may try again later.') self._finish()
def drawPresenceIcon(self): status = 'offline' if type(self.contact) is BlinkMyselfConferenceContact: account = self.contact.account if account.enabled and account.presence.enabled: settings = SIPSimpleSettings() status = settings.presence_state.status.lower() elif type(self.contact) is BlinkConferenceContact: blink_contact = self.contact.presence_contact if type(blink_contact) is not BlinkPresenceContact: return if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif type(self.contact) is BlinkHistoryViewerContact: blink_contact = self.contact.presence_contact if type(blink_contact) is not BlinkPresenceContact: return if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif type(self.contact) is HistoryBlinkContact: blink_contact = self.contact.contact if type(blink_contact) is not BlinkPresenceContact: return if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif isinstance(self.contact, BlinkPresenceContact): blink_contact = self.contact if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif type(self.contact) is BonjourBlinkContact: account = BonjourAccount() if not account.presence.enabled: return blink_contact = self.contact status = presence_status_for_contact(blink_contact) elif type(self.contact) is SystemAddressBookBlinkContact: return elif type(self.contact) is LdapSearchResultContact: return elif type(self.contact) is SearchResultContact: return if not status: return try: icon = presence_status_icons[status] except KeyError: pass has_locations = None if type(self.contact) is BlinkPresenceContact: try: has_locations = any(device['location'] for device in self.contact.presence_state['devices'].values() if device['location'] is not None) except KeyError: pass frame = self.frame frame.origin.y -= 17 if has_locations: left = self.view.frame().size.width - 22 self.drawIcon(self.locationIcon, left, self.frame.origin.y +14, 16, 16) # presence bar frame.size.width = 5 if type(self.contact) in (BlinkConferenceContact, BlinkMyselfConferenceContact): frame.size.height = 14 frame.origin.y += 15 frame.origin.x = self.view.frame().size.width - 6 rect = NSInsetRect(frame, 0, 0) if status == 'available': NSColor.greenColor().set() elif status == 'away': NSColor.yellowColor().set() elif status == 'busy': NSColor.redColor().set() else: NSColor.whiteColor().set() border = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 2.0, 2.0) border.setLineWidth_(0.08) border.fill() NSColor.blackColor().set() border.stroke()
def drawPresenceIcon(self): status = 'offline' if type(self.contact) is BlinkMyselfConferenceContact: account = self.contact.account if account.enabled and account.presence.enabled: settings = SIPSimpleSettings() status = settings.presence_state.status.lower() elif type(self.contact) is BlinkConferenceContact: blink_contact = self.contact.presence_contact if not isinstance(blink_contact, BlinkPresenceContact): return if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif type(self.contact) is BlinkHistoryViewerContact: blink_contact = self.contact.presence_contact if not isinstance(blink_contact, BlinkPresenceContact): return if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif type(self.contact) is HistoryBlinkContact: blink_contact = self.contact.contact if not isinstance(blink_contact, BlinkPresenceContact): return if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif isinstance(self.contact, BlinkPresenceContact): blink_contact = self.contact if not blink_contact.contact.presence.subscribe: return status = presence_status_for_contact(blink_contact) elif type(self.contact) is BonjourBlinkContact: account = BonjourAccount() if not account.presence.enabled: return blink_contact = self.contact status = presence_status_for_contact(blink_contact) elif type(self.contact) is SystemAddressBookBlinkContact: return elif type(self.contact) is LdapSearchResultContact: return elif type(self.contact) is SearchResultContact: return if not status: return try: icon = presence_status_icons[status] except KeyError: pass has_locations = None if isinstance(self.contact, (BlinkOnlineContact, BlinkPresenceContact)): try: has_locations = any(device['location'] for device in list( self.contact.presence_state['devices'].values()) if device['location'] is not None) except KeyError: pass frame = self.frame frame.origin.y -= 17 #if has_locations: # left = self.view.frame().size.width - 22 # self.drawIcon(self.locationIcon, left, self.frame.origin.y +14, 16, 16) # presence bar frame.size.width = 5 if type(self.contact) in (BlinkConferenceContact, BlinkMyselfConferenceContact): frame.size.height = 14 frame.origin.y += 15 frame.origin.x = self.view.frame().size.width - 6 rect = NSInsetRect(frame, 0, 0) if status == 'available': NSColor.greenColor().set() elif status == 'away': NSColor.yellowColor().set() elif status == 'busy': NSColor.redColor().set() else: NSColor.whiteColor().set() border = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( rect, 2.0, 2.0) border.setLineWidth_(0.08) border.fill() NSColor.blackColor().set() border.stroke() # sleep icon if isinstance(self.contact, (BlinkOnlineContact, BlinkPresenceContact)): if self.contact.presence_state['time_offset'] is not None: ctime = datetime.datetime.utcnow( ) + self.contact.presence_state['time_offset'] hour = int(ctime.strftime("%H")) if hour > 21 or hour < 7: left = self.view.frame().size.width - 26 self.drawIcon(self.nightIcon, left, self.frame.origin.y + 14, 16, 16)