def addImageFile(self, path): path = os.path.normpath(path) if os.path.dirname(path) != self.storage_folder: # scale and copy the image to our photo dir try: image = NSImage.alloc().initWithContentsOfFile_(path) except: NSRunAlertPanel( NSLocalizedString("Camera Capture Error", "Window title"), NSLocalizedString("%s is not a valid image", "Label") % path, NSLocalizedString("OK", "Button title"), None, None) return size = image.size() if size.width > 128 or size.height > 128: image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(128, 128 * size.height / size.width)) finalpath = self.storage_folder + "/" + os.path.basename(path) prefix, ext = os.path.splitext(finalpath) i = 0 while os.path.exists(finalpath): finalpath = prefix + str(i) + ext image.TIFFRepresentation().writeToFile_atomically_( finalpath, False) self.refreshLibrary()
def awakeFromNib(self): smileys = SmileyManager().get_smiley_list() menu = self.smileyButton.menu() while menu.numberOfItems() > 0: menu.removeItemAtIndex_(0) bigText = NSAttributedString.alloc().initWithString_attributes_( " ", NSDictionary.dictionaryWithObject_forKey_( NSFont.systemFontOfSize_(16), NSFontAttributeName)) for text, file in smileys: image = NSImage.alloc().initWithContentsOfFile_(file) if not image: print("cant load %s" % file) continue image.setScalesWhenResized_(True) image.setSize_(NSMakeSize(16, 16)) atext = bigText.mutableCopy() atext.appendAttributedString_( NSAttributedString.alloc().initWithString_(text)) item = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( text, "insertSmiley:", "") menu.addItem_(item) item.setTarget_(self) item.setAttributedTitle_(atext) item.setRepresentedObject_( NSAttributedString.alloc().initWithString_(text)) item.setImage_(image)
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 removeSession(self, session): self.sessionControllersManager.ringer.stop_ringing(session) if not self.sessions.has_key(session): return if self.answeringMachineTimers.has_key(session): self.answeringMachineTimers[session].invalidate() del self.answeringMachineTimers[session] if self.autoAnswerTimers.has_key(session): self.autoAnswerTimers[session].invalidate() del self.autoAnswerTimers[session] if len(self.sessions) <= 1: self.close() NotificationCenter().discard_observer(self, sender=session) view = self.sessions[session] view.removeFromSuperview() self.sessionsListView.relayout() frame = self.sessionsListView.frame() frame.origin.y = self.extraHeight - 14 frame.size.height = self.sessionsListView.minimumHeight() self.sessionsListView.setFrame_(frame) height = frame.size.height + self.extraHeight size = NSMakeSize(NSWidth(self.panel.frame()), height) screenSize = NSScreen.mainScreen().frame().size if size.height > (screenSize.height * 2) / 3: size.height = (screenSize.height * 2) / 3 frame = self.panel.frame() frame.size.height = size.height frame.size.height = NSHeight(self.panel.frameRectForContentRect_(frame)) self.panel.setFrame_display_animate_(frame, True, True) del self.sessions[session] if session in self.proposals: del self.proposals[session] if not self.sessions: self.unMuteAfterSpeechDidEnd()
def show(self, item): if not self.items: #self.statusItem = NSStatusBar.systemStatusBar().statusItemWithLength_(30) self.statusItem = Null self.menu = NSMenu.alloc().init() image = NSImage.imageNamed_("display").copy() image.setSize_(NSMakeSize(24, 24)) self.statusItem.setImage_(image) self.statusItem.setMenu_(self.menu) self.items.append(item) mitem = self.menu.addItemWithTitle_action_keyEquivalent_( NSLocalizedString("%s - Waiting", "Menu item") % item.sessionController.titleLong, "activateItem:", "") mitem.setTag_(item.sessionController.identifier) mitem.setTarget_(self)
def _NH_CameraSnapshotDidSucceed(self, notification): self.photoView.setHidden_(False) self.captureView.setHidden_(True) self.previewButton.setHidden_(False) self.countdownCheckbox.setHidden_(True) self.mirrorButton.setHidden_(True) self.captureButton.setHidden_(True) self.useButton.setEnabled_(True) self.captured_image = notification.data.image image = notification.data.image image.setScalesWhenResized_(True) h = self.photoView.frame().size.height w = h * self.captured_image.size().width / self.captured_image.size( ).height image.setSize_(NSMakeSize(w, h)) self.photoView.setImage_(image)
def initWithSwitcher_item_(self, switcher, item): self = NSView.initWithFrame_(self, NSMakeRect(0, 2, 100, 18)) if self: self.closeIcon.setSize_(NSMakeSize(12, 12)) self.closeButton = NSButton.alloc().initWithFrame_( NSMakeRect(3, 5, 12, 14)) self.closeButton.setImagePosition_(NSImageOnly) self.closeButton.setButtonType_(NSMomentaryChangeButton) self.closeButton.cell().setBezelStyle_(NSSmallSquareBezelStyle) self.closeButton.setBordered_(False) self.closeButton.setImage_(self.closeIcon) self.closeButton.setAutoresizingMask_(NSViewMaxXMargin | NSViewMaxYMargin) self.closeButton.setHidden_(True) self.addSubview_(self.closeButton) self.switcher = switcher self.item = item return self
def updateIcon(self, icon): image = NSImage.alloc().initWithSize_(NSMakeSize(48, 48)) image.lockFocus() size = icon.size() icon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint((48 - size.width) / 2, (48 - size.height) / 2), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) # overlay file transfer direction icon if type(self.transfer) == OutgoingPushFileTransferHandler or ( self.oldTransferInfo and self.oldTransferInfo.direction == "outgoing"): icon = NSImage.imageNamed_("outgoing_file") else: icon = NSImage.imageNamed_("incoming_file") icon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(2, 4), NSMakeRect(0, 0, size.width, size.height), NSCompositeSourceOver, 1) image.unlockFocus() self.icon.setImage_(image)
def _addIncomingSession(self, session, streams, is_update_proposal): view = self.getItemView() self.sessions[session] = view settings = SIPSimpleSettings() stream_type_list = list(set(stream.type for stream in streams)) if len(self.sessions) == 1: if "screen-sharing" in stream_type_list: base_text = NSLocalizedString("Screen Sharing from %s", "Label") elif "video" in stream_type_list: base_text = NSLocalizedString("Video call from %s", "Label") elif "audio" in stream_type_list: base_text = NSLocalizedString("Audio call from %s", "Label") elif stream_type_list == ["file-transfer"]: base_text = NSLocalizedString("File transfer from %s", "Label") elif stream_type_list == ["chat"]: base_text = NSLocalizedString("Chat from %s", "Label") else: base_text = NSLocalizedString("Call from %s", "Label") title = base_text % format_identity_to_string(session.remote_identity, check_contact=True, format='compact') self.panel.setTitle_(title) if settings.sounds.enable_speech_synthesizer: self.speak_text = title self.startSpeechSynthesizerTimer() else: self.panel.setTitle_(NSLocalizedString("Multiple Incoming Calls", "Label")) NotificationCenter().add_observer(self, sender=session) subjectLabel = view.viewWithTag_(1) fromLabel = view.viewWithTag_(2) accountLabel = view.viewWithTag_(3) acceptButton = view.viewWithTag_(5) rejectButton = view.viewWithTag_(7) accepyOnlyButton = view.viewWithTag_(6) busyButton = view.viewWithTag_(8) callerIcon = view.viewWithTag_(99) chatIcon = view.viewWithTag_(31) audioIcon = view.viewWithTag_(32) fileIcon = view.viewWithTag_(33) screenIcon = view.viewWithTag_(34) videoIcon = view.viewWithTag_(35) stream_types = [s.type for s in streams] session_manager = SessionManager() have_audio_call = any(s for s in session_manager.sessions if s is not session and s.streams and 'audio' in (stream.type for stream in s.streams)) if not have_audio_call: self.startSpeechRecognition() typeCount = 0 if 'audio' in stream_types: frame = audioIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount audioIcon.setFrame_(frame) audioIcon.setHidden_(False) if not is_update_proposal: frame = view.frame() frame.size.height += 20 # give extra space for the counter label view.setFrame_(frame) if session.account.audio.auto_accept: have_audio_call = any(s for s in session_manager.sessions if s is not session and s.streams and 'audio' in (stream.type for stream in s.streams)) if not have_audio_call: self.enableAutoAnswer(view, session, session.account.audio.answer_delay) elif settings.answering_machine.enabled or (is_anonymous(session.remote_identity.uri) and session.account.pstn.anonymous_to_answering_machine): self.enableAnsweringMachine(view, session) if 'chat' in stream_types: frame = chatIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount chatIcon.setFrame_(frame) chatIcon.setHidden_(False) if 'screen-sharing' in stream_types: frame = screenIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount screenIcon.setFrame_(frame) screenIcon.setHidden_(False) if 'video' in stream_types: #have_video_call = any(s for s in session_manager.sessions if s is not session and s.streams and 'video' in (stream.type for stream in s.streams)) #if not have_video_call: # NSApp.delegate().contactsWindowController.showLocalVideoWindow() frame = videoIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount videoIcon.setFrame_(frame) videoIcon.setHidden_(False) is_file_transfer = False if 'file-transfer' in stream_types: is_file_transfer = True frame = fileIcon.frame() typeCount+= 1 frame.origin.x = NSMaxX(view.frame()) - 10 - (NSWidth(frame) + 10) * typeCount fileIcon.setFrame_(frame) fileIcon.setHidden_(False) if settings.file_transfer.auto_accept and NSApp.delegate().contactsWindowController.my_device_is_active: BlinkLogger().log_info(u"Auto answer enabled for file transfers from known contacts") self.enableAutoAnswer(view, session, random.uniform(10, 20)) self.sessionsListView.addSubview_(view) frame = self.sessionsListView.frame() frame.origin.y = self.extraHeight - 14 frame.size.height = self.sessionsListView.minimumHeight() self.sessionsListView.setFrame_(frame) height = frame.size.height + self.extraHeight size = NSMakeSize(NSWidth(self.panel.frame()), height) screenSize = NSScreen.mainScreen().frame().size if size.height > (screenSize.height * 2) / 3: size.height = (screenSize.height * 2) / 3 frame = self.panel.frame() frame.size.height = size.height frame.size.height = NSHeight(self.panel.frameRectForContentRect_(frame)) self.panel.setFrame_display_animate_(frame, True, True) self.sessionsListView.relayout() acceptButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(0)) rejectButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(2)) busyButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(3)) # no Busy or partial accept option for Stream Update Proposals busyButton.setHidden_(is_update_proposal or is_file_transfer) accepyOnlyButton.setHidden_(is_update_proposal) if is_file_transfer: busyButton.setAttributedTitle_("") if is_update_proposal: subject, only_button_title, only_button_object = self.format_subject_for_incoming_reinvite(session, streams) only_button_title = "" else: subject, only_button_title, only_button_object = self.format_subject_for_incoming_invite(session, streams) subjectLabel.setStringValue_(subject) accepyOnlyButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(only_button_object)) frame = subjectLabel.frame() frame.size.width = NSWidth(self.sessionsListView.frame()) - 80 - 40 * typeCount subjectLabel.setFrame_(frame) has_audio_streams = any(s for s in reduce(lambda a,b:a+b, [session.proposed_streams for session in self.sessions.keys()], []) if s.type=="audio") caller_contact = NSApp.delegate().contactsWindowController.getFirstContactMatchingURI(session.remote_identity.uri) if caller_contact: if caller_contact.icon: callerIcon.setImage_(caller_contact.icon) if not is_update_proposal and caller_contact.auto_answer and NSApp.delegate().contactsWindowController.my_device_is_active: if has_audio_streams: if not NSApp.delegate().contactsWindowController.has_audio: BlinkLogger().log_info(u"Auto answer enabled for this contact") video_requested = any(s for s in session.blink_supported_streams if s.type == "video") if video_requested and not settings.video.enable_when_auto_answer: blink_supported_streams = [s for s in session.blink_supported_streams if s.type != "video"] session.blink_supported_streams = blink_supported_streams self.enableAutoAnswer(view, session, session.account.audio.answer_delay) else: video_requested = any(s for s in session.blink_supported_streams if s.type == "video") if video_requested and not settings.video.enable_when_auto_answer: blink_supported_streams = [s for s in session.blink_supported_streams if s.type != "video"] session.blink_supported_streams = blink_supported_streams BlinkLogger().log_info(u"Auto answer enabled for this contact") self.enableAutoAnswer(view, session, session.account.audio.answer_delay) fromLabel.setStringValue_(u"%s" % format_identity_to_string(session.remote_identity, check_contact=True, format='full')) fromLabel.sizeToFit() if has_audio_streams: outdev = settings.audio.output_device indev = settings.audio.input_device if outdev == u"system_default": outdev = SIPManager()._app.engine.default_output_device if indev == u"system_default": indev = SIPManager()._app.engine.default_input_device outdev = outdev.strip() if outdev is not None else 'None' indev = indev.strip() if indev is not None else 'None' if outdev != indev: if indev.startswith('Built-in Mic') and outdev.startswith(u'Built-in Out'): self.deviceLabel.setStringValue_(NSLocalizedString("Using Built-in Microphone and Output", "Label")) else: self.deviceLabel.setStringValue_(NSLocalizedString("Using %s for output ", "Label") % outdev.strip() + NSLocalizedString(" and %s for input", "Label") % indev.strip()) else: self.deviceLabel.setStringValue_(NSLocalizedString("Using audio device", "Label") + " " + outdev.strip()) BlinkLogger().log_info(u"Using input/output audio devices: %s/%s" % (indev.strip(), outdev.strip())) self.deviceLabel.sizeToFit() self.deviceLabel.setHidden_(False) else: self.deviceLabel.setHidden_(True) acceptButton.setTitle_(NSLocalizedString("Accept", "Button title")) accepyOnlyButton.setTitle_(only_button_title or "") if False and sum(a.enabled for a in AccountManager().iter_accounts())==1: accountLabel.setHidden_(True) else: accountLabel.setHidden_(False) if isinstance(session.account, BonjourAccount): accountLabel.setStringValue_(NSLocalizedString("To Bonjour account", "Label")) else: to = format_identity_to_string(session.account) accountLabel.setStringValue_(NSLocalizedString("To %s", "Label") % to) accountLabel.sizeToFit() if len(self.sessions) == 1: self.acceptAllButton.setTitle_(NSLocalizedString("Accept", "Button title")) self.acceptAllButton.setHidden_(False) self.acceptButton.setTitle_(only_button_title or "") self.acceptButton.setHidden_(not only_button_title) self.rejectButton.setTitle_(NSLocalizedString("Reject", "Button title")) self.acceptAllButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(0)) self.rejectButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(2)) self.busyButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(3)) self.acceptButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(only_button_object)) self.answeringMachineButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(4)) self.conferenceButton.cell().setRepresentedObject_(NSNumber.numberWithInt_(5)) self.busyButton.setHidden_(is_update_proposal or is_file_transfer) for i in (5, 6, 7, 8): view.viewWithTag_(i).setHidden_(True) else: self.acceptAllButton.setHidden_(False) self.acceptAllButton.setTitle_(NSLocalizedString("Accept All", "Button title")) self.acceptButton.setHidden_(True) self.busyButton.setHidden_(is_update_proposal or is_file_transfer) self.rejectButton.setTitle_(NSLocalizedString("Reject All", "Button title")) for v in self.sessions.values(): for i in (5, 6, 7, 8): btn = v.viewWithTag_(i) btn.setHidden_(len(btn.attributedTitle()) == 0) if not has_audio_streams or is_update_proposal: self.answeringMachineButton.setHidden_(True) else: self.answeringMachineButton.setHidden_(not settings.answering_machine.show_in_alert_panel) if not self.isConferencing: self.conferenceButton.setHidden_(True) else: self.conferenceButton.setHidden_(False)
def drawRect_(self, rect): r = self.bounds() r.size.width -= 0.5 r.size.height += 4 if self.draggedOut: NSColor.colorWithDeviceWhite_alpha_(0.4, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( r, 5, 5) path.fill() else: if self == self.switcher.activeItem(): NSColor.controlColor().set() else: NSColor.colorWithDeviceWhite_alpha_(0.6, 1.0).set() path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( r, 5, 5) path.fill() NSColor.colorWithDeviceRed_green_blue_alpha_(0.3, 0.3, 0.3, 1.0).set() path.stroke() if self.badgeLabel and not self.mouseInside and not self.busyIndicator and not self.composing: # draw the number in redbadge indicator gradient = NSGradient.alloc().initWithStartingColor_endingColor_( NSColor.colorWithDeviceRed_green_blue_alpha_(0.9, 0.2, 0.2, 1), NSColor.colorWithDeviceRed_green_blue_alpha_(1.0, 0.2, 0.2, 1)) size = self.badgeLabel.size() size.width += 4 if size.width < 12: size.width = 12 bez = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_( NSMakeRect(3, 5, size.width, 12), 6, 6) gradient.drawInBezierPath_angle_(bez, 90 + 45) self.badgeLabel.drawInRect_(NSMakeRect(3, 5, size.width, 12)) if not self.mouseInside and not self.busyIndicator and self.composing: rect = NSZeroRect.copy() rect.size = self.composeIcon.size() self.composeIcon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(1, 3), rect, NSCompositeSourceOver, 1) if not self.busyIndicator and self.screen_sharing_active: rect = NSZeroRect.copy() rect.size = self.screenIcon.size() self.screenIcon.drawAtPoint_fromRect_operation_fraction_( NSMakePoint(17, 3), rect, NSCompositeSourceOver, 1) if not self.draggedOut: shadow = NSShadow.alloc().init() shadow.setShadowOffset_(NSMakeSize(0, -1)) if self == self.switcher.activeItem(): shadow.setShadowColor_(NSColor.whiteColor()) else: shadow.setShadowColor_( NSColor.colorWithDeviceWhite_alpha_(0.7, 1.0)) para = NSParagraphStyle.defaultParagraphStyle().mutableCopy() para.setLineBreakMode_(NSLineBreakByTruncatingTail) para.setAlignment_(NSCenterTextAlignment) attribs = NSDictionary.dictionaryWithObjectsAndKeys_( NSFont.systemFontOfSize_(11), NSFontAttributeName, shadow, NSShadowAttributeName, para, NSParagraphStyleAttributeName) rect = self.bounds() rect.origin.y -= 3 rect.origin.x += 20 rect.origin.x = rect.origin.x + 12 if self.screen_sharing_active else rect.origin.x rect.size.width -= 46 rect.size.width = rect.size.width - 12 if self.screen_sharing_active else rect.size.width self.label.drawInRect_withAttributes_(rect, attribs)
def cellSize(self): if self.conference_file is None: return objc.super(ConferenceFileCell, self).cellSize() return NSMakeSize(100, 30)
def cellSize(self): if self.contact is None: return objc.super(ContactCell, self).cellSize() return NSMakeSize(100, 30)