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 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())
Exemplo n.º 3
0
    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
class ConferenceFileCell(NSTextFieldCell):
    conference_file = None

    nameAttrs = NSDictionary.dictionaryWithObjectsAndKeys_(
      NSFont.systemFontOfSize_(12.0), NSFontAttributeName)

    nameAttrs_highlighted = NSDictionary.dictionaryWithObjectsAndKeys_(
      NSFont.systemFontOfSize_(12.0), NSFontAttributeName,
      NSColor.whiteColor(), NSForegroundColorAttributeName)

    infoAttrs = NSDictionary.dictionaryWithObjectsAndKeys_(
      NSFont.systemFontOfSize_(NSFont.labelFontSize()-1), NSFontAttributeName,
      NSColor.grayColor(), NSForegroundColorAttributeName)

    infoAttrs_highlighted = NSDictionary.dictionaryWithObjectsAndKeys_(
      NSFont.systemFontOfSize_(NSFont.labelFontSize()-1), NSFontAttributeName,
      NSColor.whiteColor(), NSForegroundColorAttributeName)

    def drawingRectForBounds_(self, rect):
        return rect

    @objc.python_method
    def cellSize(self):
        if self.conference_file is None:
            return objc.super(ConferenceFileCell, self).cellSize()
        return NSMakeSize(100, 30)

    def drawWithFrame_inView_(self, frame, view):
        if self.conference_file is None:
            tmp = frame
            return objc.super(ConferenceFileCell, self).drawWithFrame_inView_(tmp, view)

        self.drawIcon(self.conference_file.icon, 2, frame.origin.y+3, 28, 28)

        # 1st line: file name
        frame.origin.x = 35
        frame.origin.y += 2
        attrs = self.nameAttrs if not self.isHighlighted() else self.nameAttrs_highlighted
        self.conference_file.name.drawAtPoint_withAttributes_(frame.origin, attrs)

        # 2nd line: file sender
        point = frame.origin
        point.y += 15
        attrs = self.infoAttrs if not self.isHighlighted() else self.infoAttrs_highlighted
        self.conference_file.sender.drawAtPoint_withAttributes_(point, attrs)

    @objc.python_method
    def drawIcon(self, icon, origin_x, origin_y, size_x, size_y):
        size = icon.size()
        rect = NSMakeRect(0, 0, size.width, size.height)
        trect = NSMakeRect(origin_x, origin_y, (size_y/size.height) * size.width, size_x)
        icon.drawInRect_fromRect_operation_fraction_respectFlipped_hints_(trect, rect, NSCompositeSourceOver, 1.0, True, None)
Exemplo n.º 5
0
    def initialize(self):
        paraStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy()
        paraStyle.setAlignment_(NSCenterTextAlignment)

        self.badgeAttributes = NSMutableDictionary.dictionaryWithObjectsAndKeys_(NSFont.boldSystemFontOfSize_(8),
                                NSFontAttributeName, NSColor.whiteColor(), NSForegroundColorAttributeName,
                                paraStyle, NSParagraphStyleAttributeName)
Exemplo n.º 6
0
 def initWithFrame_(self, frame):
     self = super(ListView, self).initWithFrame_(frame)
     if self:
         self.setBackgroundColor_(NSColor.whiteColor())
         NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, "windowChangedKey:", NSWindowDidBecomeKeyNotification, None)
         NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, "windowChangedKey:", NSWindowDidResignKeyNotification, None)
     return self
    def initialize(self):
        paraStyle = NSParagraphStyle.defaultParagraphStyle().mutableCopy()
        paraStyle.setAlignment_(NSCenterTextAlignment)

        self.badgeAttributes = NSMutableDictionary.dictionaryWithObjectsAndKeys_(
            NSFont.boldSystemFontOfSize_(8), NSFontAttributeName,
            NSColor.whiteColor(), NSForegroundColorAttributeName, paraStyle,
            NSParagraphStyleAttributeName)
Exemplo n.º 8
0
    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()
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
 def initWithFrame_(self, frame):
     self = objc.super(ListView, self).initWithFrame_(frame)
     if self:
         self.setBackgroundColor_(NSColor.whiteColor())
         NSNotificationCenter.defaultCenter(
         ).addObserver_selector_name_object_(
             self, "windowChangedKey:", NSWindowDidBecomeKeyNotification,
             None)
         NSNotificationCenter.defaultCenter(
         ).addObserver_selector_name_object_(
             self, "windowChangedKey:", NSWindowDidResignKeyNotification,
             None)
     return self
    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
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
    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
Exemplo n.º 15
0
    def drawRect_(self, rect):
        rect = NSInsetRect(self.bounds(), 1.5, 1.5)
        if not self.conferencing:
            NSColor.whiteColor().set()
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                rect, 5.0, 5.0)
            path.fill()

        if self.conferencing:
            if self.draggedOut:
                NSColor.whiteColor().set()
            else:
                # bgcolor for conference area
                NSColor.colorWithDeviceRed_green_blue_alpha_(
                    196 / 255.0, 230 / 255.0, 254 / 255.0, 1.0).set()
            border = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                rect, 5.0, 5.0)
            border.setLineWidth_(1)
            border.fill()
            NSColor.grayColor().set()
            border.stroke()

            # hack: if we're the 1st item, draw the border around all conferenced boxes
            subviews = self.superview().subviews()
            if subviews.objectAtIndex_(0) == self:
                # first in conference list
                rect.size.height += 5
                rect.origin.y -= 5
                path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                    rect, 5.0, 5.0)
            else:
                prev = None
                last = True
                for view in subviews:
                    if prev == self:
                        last = not view.conferencing
                        break
                    prev = view
                # last in conference list
                if last:
                    rect.size.height += 5
                    path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                        rect, 5.0, 5.0)
                else:
                    rect.origin.y -= 5
                    rect.size.height += 10
                    path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                        rect, 5.0, 5.0)

            if self.selected or self.highlighted:
                path.setLineWidth_(3)
            else:
                path.setLineWidth_(1)
            if self.highlighted:
                NSColor.orangeColor().set()
            else:
                NSColor.grayColor().set()
            if self.selected or self.highlighted:
                path.stroke()
        elif self.highlighted:
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                rect, 5.0, 5.0)
            path.setLineWidth_(3)
            NSColor.orangeColor().set()
            path.stroke()
        elif self.selected:
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                rect, 5.0, 5.0)
            path.setLineWidth_(3)
            NSColor.grayColor().set()
            path.stroke()
        else:
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(
                rect, 5.0, 5.0)
            path.setLineWidth_(1)
            NSColor.grayColor().set()
            path.stroke()
Exemplo n.º 16
0
    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)
Exemplo n.º 17
0
    def drawRect_(self, rect):
        rect = NSInsetRect(self.bounds(), 1.5, 1.5)
        if not self.conferencing:
            NSColor.whiteColor().set()
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
            path.fill()

        if self.conferencing:
            if self.draggedOut:
                NSColor.whiteColor().set()
            else:
                # bgcolor for conference area
                NSColor.colorWithDeviceRed_green_blue_alpha_(196/255.0, 230/255.0, 254/255.0, 1.0).set()
            border = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
            border.setLineWidth_(1)
            border.fill()
            NSColor.grayColor().set()
            border.stroke()

            # hack: if we're the 1st item, draw the border around all conferenced boxes
            subviews = self.superview().subviews()
            if subviews.objectAtIndex_(0) == self:
                # first in conference list
                rect.size.height += 5
                rect.origin.y -= 5
                path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
            else:
                prev = None
                last = True
                for view in subviews:
                    if prev == self:
                        last = not view.conferencing
                        break
                    prev = view
                # last in conference list
                if last:
                    rect.size.height += 5
                    path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
                else:
                    rect.origin.y -= 5
                    rect.size.height += 10
                    path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)

            if self.selected or self.highlighted:
                path.setLineWidth_(3)
            else:
                path.setLineWidth_(1)
            if self.highlighted:
                NSColor.orangeColor().set()
            else:
                NSColor.grayColor().set()
            if self.selected or self.highlighted:
                path.stroke()
        elif self.highlighted:
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
            path.setLineWidth_(3)
            NSColor.orangeColor().set()
            path.stroke()
        elif self.selected:
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
            path.setLineWidth_(3)
            NSColor.grayColor().set()
            path.stroke()
        else:
            path = NSBezierPath.bezierPathWithRoundedRect_xRadius_yRadius_(rect, 5.0, 5.0)
            path.setLineWidth_(1)
            NSColor.grayColor().set()
            path.stroke()
Exemplo n.º 18
0
    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()
Exemplo n.º 19
0
    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)
Exemplo n.º 20
0
class ContactCell(NSTextFieldCell):
    contact = None
    view = None
    frame = None

    audioIcon = NSImage.imageNamed_("audio_16")
    audioHoldIcon = NSImage.imageNamed_("paused_16")
    chatIcon = NSImage.imageNamed_("pencil_16")
    screenIcon = NSImage.imageNamed_("display_16")
    locationIcon = NSImage.imageNamed_("location")
    nightIcon = NSImage.imageNamed_("moon")

    style = NSParagraphStyle.defaultParagraphStyle().mutableCopy()
    style.setLineBreakMode_(NSLineBreakByTruncatingTail)
    firstLineAttributes = NSDictionary.dictionaryWithObjectsAndKeys_(
        NSFont.systemFontOfSize_(12.0), NSFontAttributeName, style,
        NSParagraphStyleAttributeName)
    firstLineAttributes_highlighted = NSDictionary.dictionaryWithObjectsAndKeys_(
        NSFont.systemFontOfSize_(12.0), NSFontAttributeName,
        NSColor.whiteColor(), NSForegroundColorAttributeName, style,
        NSParagraphStyleAttributeName)
    secondLineAttributes = NSDictionary.dictionaryWithObjectsAndKeys_(
        NSFont.systemFontOfSize_(NSFont.labelFontSize() - 1),
        NSFontAttributeName, NSColor.grayColor(),
        NSForegroundColorAttributeName, style, NSParagraphStyleAttributeName)
    secondLineAttributes_highlighted = NSDictionary.dictionaryWithObjectsAndKeys_(
        NSFont.systemFontOfSize_(NSFont.labelFontSize() - 1),
        NSFontAttributeName, NSColor.whiteColor(),
        NSForegroundColorAttributeName, style, NSParagraphStyleAttributeName)

    def setContact_(self, contact):
        self.contact = contact

    def setMessageIcon_(self, icon):
        self.messageIcon = icon

    def drawingRectForBounds_(self, rect):
        return rect

    def cellSize(self):
        if self.contact is None:
            return objc.super(ContactCell, self).cellSize()
        return NSMakeSize(100, 30)

    def drawWithFrame_inView_(self, frame, view):
        if self.contact is None:
            return objc.super(ContactCell,
                              self).drawWithFrame_inView_(frame, view)

        self.frame = frame
        self.view = view

        try:
            icon = self.contact.avatar.icon
            self.drawIcon(icon, 2, self.frame.origin.y + 3, 28, 28)

            self.drawActiveMedia()
            self.drawFirstLine()
            self.drawSecondLine()
            self.drawPresenceIcon()
        except Exception:
            pass

    @objc.python_method
    def drawFirstLine(self):
        frame = self.frame
        frame.origin.x = 35
        frame.origin.y += 2

        rect = NSMakeRect(frame.origin.x, frame.origin.y,
                          frame.size.width - 10, frame.size.height)
        attrs = self.firstLineAttributes if not self.isHighlighted(
        ) else self.firstLineAttributes_highlighted
        self.stringValue().drawInRect_withAttributes_(rect, attrs)

    @objc.python_method
    def drawSecondLine(self):
        frame = self.frame
        frame.origin.y += 15
        if self.contact.detail:
            rect = NSMakeRect(frame.origin.x, frame.origin.y,
                              frame.size.width - 25, frame.size.height)
            attrs = self.secondLineAttributes if not self.isHighlighted(
            ) else self.secondLineAttributes_highlighted
            self.contact.detail.drawInRect_withAttributes_(rect, attrs)

    @objc.python_method
    def drawActiveMedia(self):
        if type(self.contact) not in (BlinkConferenceContact,
                                      BlinkMyselfConferenceContact):
            return

        padding = 16
        left = self.frame.size.width - 8
        if 'audio-onhold' in self.contact.active_media:
            left = left - padding
            self.drawIcon(self.audioHoldIcon, left, self.frame.origin.y + 14,
                          16, 16)
        elif 'audio' in self.contact.active_media:
            left = left - padding
            self.drawIcon(self.audioIcon, left, self.frame.origin.y + 14, 16,
                          16)

        if 'message' in self.contact.active_media:
            left = left - padding
            self.drawIcon(self.chatIcon, left, self.frame.origin.y + 14, 16,
                          16)

        if 'screen' in self.contact.active_media:
            left = left - padding - 2
            self.drawIcon(self.screenIcon, left, self.frame.origin.y + 14, 16,
                          16)

    @objc.python_method
    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)

    @objc.python_method
    def drawIcon(self, icon, origin_x, origin_y, size_x, size_y):
        size = icon.size()
        if not size or not size.height:
            return
        rect = NSMakeRect(0, 0, size.width, size.height)
        trect = NSMakeRect(origin_x, origin_y,
                           (size_y / size.height) * size.width, size_x)
        icon.drawInRect_fromRect_operation_fraction_respectFlipped_hints_(
            trect, rect, NSCompositeSourceOver, 1.0, True, None)