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 _NH_BlinkFileTransferDidEnd(self, notification): if notification.data.error: self.sizeText.setTextColor_(NSColor.redColor()) if type(self.transfer) == OutgoingPushFileTransferHandler: self.retryButton.setHidden_(False) else: self.sizeText.setTextColor_(NSColor.blueColor()) if self.transfer.direction == 'incoming': self.revealButton.setHidden_(False) self.fromText.setStringValue_(self.transfer.target_text) self.sizeText.setStringValue_(self.transfer.progress_text) self.failed = notification.data.error self.done = True self.relayoutForDone()
def _NH_BlinkFileTransferDidFail(self, notification): self.sizeText.setTextColor_(NSColor.redColor()) self.checksumProgressBar.setHidden_(True) self.checksumProgressBar.stopAnimation_(None) self.progressBar.setHidden_(True) self.progressBar.stopAnimation_(None) self.updateProgressInfo() self.stopButton.setHidden_(True) if type(self.transfer) == OutgoingPushFileTransferHandler: self.retryButton.setHidden_(False) self.relayoutForDone() self.done = True self.failed = True
def handle_remote_response(self, same_secrets=False): if not same_secrets: self.statusText.setTextColor_(NSColor.redColor()) self.statusText.setStringValue_(NSLocalizedString("Identity verification failed. Try again later.", "Label")) result = False else: self.stream.encryption.verified = True self.statusText.setTextColor_(NSColor.greenColor()) self.statusText.setStringValue_(NSLocalizedString("Identity verification succeeded", "Label")) self.controller.revalidateToolbar() self.controller.updateEncryptionWidgets() result = True self._finish(result) return result
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 initWithFrame_oldTransfer_(self, frame, transferInfo): self = NSView.initWithFrame_(self, frame) if self: self.oldTransferInfo = transferInfo self.file_path = transferInfo.file_path self.remote_uri = transferInfo.remote_uri self.local_uri = transferInfo.local_uri NSBundle.loadNibNamed_owner_("FileTransferItemView", self) self.updateIcon(NSWorkspace.sharedWorkspace().iconForFile_( self.file_path)) self.nameText.setStringValue_(os.path.basename(self.file_path)) self.fromText.setStringValue_( 'To %s from account %s' % (transferInfo.remote_uri, transferInfo.local_uri) if transferInfo.direction == 'outgoing' else 'From %s to account %s' % (transferInfo.remote_uri, transferInfo.local_uri)) self.revealButton.setHidden_(not os.path.exists(self.file_path)) time_print = format_date(transferInfo.time) if transferInfo.status == "completed": self.sizeText.setTextColor_(NSColor.blueColor()) t = NSLocalizedString("Completed transfer of ", "Label") status = t + "%s %s" % (format_size(transferInfo.file_size, 1024), time_print) else: self.sizeText.setTextColor_(NSColor.redColor()) status = "%s %s" % (transferInfo.status.title(), time_print) self.sizeText.setStringValue_(status) frame.size = self.view.frame().size self.setFrame_(frame) self.addSubview_(self.view) self.relayoutForDone() if transferInfo.direction == "outgoing" and transferInfo.status != "completed" and os.path.exists( self.file_path): self.retryButton.setHidden_(False) self.done = True return self
def append_error_line(self, textView, line): red = NSDictionary.dictionaryWithObject_forKey_(NSColor.redColor(), NSForegroundColorAttributeName) textView.textStorage().appendAttributedString_(NSAttributedString.alloc().initWithString_attributes_(line+"\n", red)) textView.scrollRangeToVisible_(NSMakeRange(textView.textStorage().length()-1, 1))
def importButtonClicked_(self, sender): BlinkLogger().log_info("Import private key") pincode = str(self.pincode.stringValue()).strip() data = self.encryptedKeyPair.decode() keyPair = self.decrypt(data, pincode) try: keyPair = keyPair.decode() except UnicodeDecodeError as e: self.status.setTextColor_(NSColor.redColor()) BlinkLogger().log_error("Import private key failed: %s" % str(e)) self.status.setStringValue_( NSLocalizedString("Key import failed", "status label")) else: public_key_checksum_match = re.findall( r"--PUBLIC KEY SHA1 CHECKSUM--(\w+)--", keyPair) private_key_checksum_match = re.findall( r"--PRIVATE KEY SHA1 CHECKSUM--(\w+)--", keyPair) if (public_key_checksum_match): public_key_checksum = public_key_checksum_match[0] else: public_key_checksum = None if (private_key_checksum_match): private_key_checksum = private_key_checksum_match[0] else: private_key_checksum = None public_key = '' private_key = '' start_public = False start_private = False for l in keyPair.split("\n"): if l == "-----BEGIN RSA PUBLIC KEY-----": start_public = True start_private = False if l == "-----END RSA PUBLIC KEY-----": public_key = public_key + l start_public = False start_private = False if l == "-----BEGIN RSA PRIVATE KEY-----": start_public = False start_private = True if l == "-----END RSA PRIVATE KEY-----": private_key = private_key + l start_public = False start_private = False if start_public: public_key = public_key + l + '\n' if start_private: private_key = private_key + l + '\n' if (public_key and private_key and public_key_checksum): self.importButton.setEnabled_(False) BlinkLogger().log_info("Key imported sucessfully") self.status.setTextColor_(NSColor.greenColor()) self.status.setStringValue_( NSLocalizedString("Key imported sucessfully", "status label")) self.checksum.setStringValue_(public_key_checksum) self.account.sms.private_key = private_key self.account.sms.public_key = public_key self.account.sms.public_key_checksum = public_key_checksum self.account.save() if self.dealloc_timer is None: self.dealloc_timer = NSTimer.timerWithTimeInterval_target_selector_userInfo_repeats_( 6.0, self, "deallocTimer:", None, True) NSRunLoop.currentRunLoop().addTimer_forMode_( self.dealloc_timer, NSRunLoopCommonModes) NSRunLoop.currentRunLoop().addTimer_forMode_( self.dealloc_timer, NSEventTrackingRunLoopMode) else: BlinkLogger().log_error("Key import failed") self.status.setStringValue_( NSLocalizedString("Key import failed", "status label")) self.status.setTextColor_(NSColor.redColor())
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)