Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
whomwah committed Jan 8, 2014
2 parents 5bdd059 + 714e1e1 commit be6657d
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ nbproject
sparkle/release
sparkle/release/*
sparkle/config/dsa_priv.pem
*.dat*
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
GIT
remote: [email protected]:kyan/kyan_jukebox_websocket_lib.git
revision: 93fe1c35e8065ee8710c59648f287b3fdc1963ed
revision: f702e1268351d140d8c7ee7ba6b587ade0cfeaa3
specs:
kyan_jukebox (0.1.6)
kyan_jukebox (0.1.9)

GEM
remote: https://rubygems.org/
Expand Down
2 changes: 0 additions & 2 deletions app/_buttons/vote_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ def initWithVote vote

if vote
button.cell.setImage(NSImage.imageNamed(NSImageNameAddTemplate))
button.setToolTip(" Vote Up ")
else
button.cell.setImage(NSImage.imageNamed(NSImageNameRemoveTemplate))
button.setToolTip(" Vote Down ")
end
end
end
Expand Down
89 changes: 89 additions & 0 deletions app/_views/album_art_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class AlbumArtView < NSImageView

def init
super.tap do |v|
v.setTranslatesAutoresizingMaskIntoConstraints(false)
v.setEditable(false)
v.setImageScaling(NSImageScaleAxesIndependently)

@vote_view = VoteView.new
v.addSubview(@vote_view)

@vote_slider_in_progress = false

slidein_vote_view
end
end

def slidein_vote_view
return if @vote_slider_in_progress

new_frame = @vote_view.frame
new_frame.origin.x += VOTE_VIEW_W

@vote_slider_in_progress = true
NSAnimationContext.beginGrouping
NSAnimationContext.currentContext.setCompletionHandler(
lambda do
timer = NSTimer.scheduledTimerWithTimeInterval(
5.0,
target:self,
selector:'slideout_vote_view',
userInfo:nil,
repeats: false
)
NSRunLoop.mainRunLoop.addTimer(timer, forMode:NSRunLoopCommonModes)
end
)
NSAnimationContext.currentContext.setDuration(0.5)
@vote_view.animator.setFrame(new_frame)
NSAnimationContext.endGrouping
end

def slideout_vote_view
new_frame = @vote_view.frame
new_frame.origin.x -= VOTE_VIEW_W

NSAnimationContext.beginGrouping
NSAnimationContext.currentContext.setCompletionHandler(
lambda do
@vote_slider_in_progress = false
end
)
NSAnimationContext.currentContext.setDuration(0.5)
@vote_view.animator.setFrame(new_frame)
NSAnimationContext.endGrouping
end

def handle_vote(score, rating)
@vote_view.do_vote(score, rating)
slidein_vote_view
end

def drawRect(dirtyRect)
super dirtyRect

@vote_view.removeFromSuperview
addSubview(@vote_view, positioned:NSWindowAbove, relativeTo:nil)
end

def mouseEntered(event)
slidein_vote_view
end

def updateTrackingAreas
if @trackingArea != nil
removeTrackingArea(@trackingArea)
end

@trackingArea = NSTrackingArea.alloc.initWithRect(
[[0,frame.size.height-VOTE_VIEW_H],[VOTE_VIEW_W,frame.size.height]],
options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways,
owner:self,
userInfo:nil
)

addTrackingArea(@trackingArea)
end

end
45 changes: 39 additions & 6 deletions app/_views/nowplaying_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,28 @@ def track
@jukebox.track unless @jukebox.nil?
end

def rating
@jukebox.rating unless @jukebox.nil?
end

private

def valid_jb_data?(key)
@jukebox.whats_changed.include?(key)
end

def should_update?
valid_jb_data?(:track) || valid_jb_data?(:rating)
end

def update_data!
if @jukebox
if @jukebox && should_update?
update_image
update_title
update_artist
update_album
update_addedby
update_votes
end

invalidateIntrinsicContentSize
Expand Down Expand Up @@ -133,10 +146,7 @@ def draw_album_box
end

def draw_image_box
NSImageView.new.tap do |v|
v.setTranslatesAutoresizingMaskIntoConstraints(false)
v.setEditable(false)
end
AlbumArtView.new
end

def draw_addedby_box
Expand Down Expand Up @@ -180,7 +190,7 @@ def update_album
paragraph.setLineBreakMode(NSLineBreakByTruncatingTail)

txt = track.album.attrd({
'NSFont' => NSFont.fontWithName("Lucida Grande", size:10),
'NSFont' => NSFont.fontWithName("Lucida Grande", size:9),
'NSColor' => NSColor.grayColor,
'NSParagraphStyle' => paragraph
}) unless track.album.nil?
Expand Down Expand Up @@ -216,4 +226,27 @@ def update_image
end
end
end

def update_votes
score = if valid_jb_data?(:track)
track.rating unless track.nil?
elsif valid_jb_data?(:rating)
rating.rating unless rating.nil?
end

if superview
uvote_button = superview.viewWithTag(U_VOTE_BUTTON)
dvote_button = superview.viewWithTag(D_VOTE_BUTTON)

if !uvote_button.nil?
uvote_button.setToolTip(rating.p_ratings)
end

if !dvote_button.nil?
dvote_button.setToolTip(rating.n_ratings)
end
end

@image.handle_vote(score, rating)
end
end
6 changes: 6 additions & 0 deletions app/_views/vote_buttons_view.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class VoteButtonsView < NSView

attr_reader :up_vote_button, :down_vote_button

def init
super.tap do |v|
v.translatesAutoresizingMaskIntoConstraints = false
Expand Down Expand Up @@ -51,10 +53,14 @@ def init

def up_vote_button
@up_vote_button ||= VoteButton.alloc.initWithVote(true)
@up_vote_button.tag = U_VOTE_BUTTON
@up_vote_button
end

def down_vote_button
@down_vote_button ||= VoteButton.alloc.initWithVote(false)
@down_vote_button.tag = D_VOTE_BUTTON
@down_vote_button
end

end
71 changes: 71 additions & 0 deletions app/_views/vote_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
class VoteView < NSView

def init
super.tap do |v|
v.frame = [[0-VOTE_VIEW_W,50-VOTE_VIEW_H],[VOTE_VIEW_W,VOTE_VIEW_H]]

@label = NSTextField.new.tap do |txt|
txt.setEditable(false)
txt.frame = [[3,2],[20,14]]
txt.setSelectable(false)
txt.setBezeled(false)
txt.setDrawsBackground(false)
txt.setAlignment(NSCenterTextAlignment)
end

v.addSubview(@label)
end
end

def do_vote(score, rating)
# grey
bg_col = NSColor.colorWithCalibratedRed(0.227, green:0.251, blue:0.337, alpha:0.8)
fg_col = NSColor.whiteColor

if score.nil?
score = "#"
# lightgrey
bg_col = NSColor.colorWithCalibratedRed(0.7, green:0.7, blue:0.7, alpha:0.8)
fg_col = NSColor.whiteColor
else
# green
if score > 0
bg_col = NSColor.colorWithCalibratedRed(0, green:0.93, blue:0, alpha:0.8)
fg_col = NSColor.blackColor
end

# red
if score < 0
bg_col = NSColor.colorWithCalibratedRed(0.9, green:0.4, blue:0.3, alpha:0.8)
fg_col = NSColor.blackColor
end
end

txt = score.to_s.attrd({
'NSFont' => NSFont.fontWithName("Helvetica Bold", size:10),
'NSColor' => fg_col
})
@label.setAttributedStringValue(txt)
@bg_color = bg_col
end

def drawRect(dirtyRect)
draw_backing if @bg_color

super dirtyRect
end

def draw_backing
radius = 15.0

path = NSBezierPath.bezierPath
path.moveToPoint([0,0])
path.lineToPoint([VOTE_VIEW_W-radius,0])
path.curveToPoint([VOTE_VIEW_W,0+radius], controlPoint1:[VOTE_VIEW_W,0], controlPoint2:[VOTE_VIEW_W,0])
path.lineToPoint([VOTE_VIEW_W,VOTE_VIEW_H])
path.lineToPoint([0,VOTE_VIEW_H])
path.lineToPoint([0,0])
@bg_color.setFill
path.fill
end
end
2 changes: 1 addition & 1 deletion app/_windows/jukebox_control_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def canBecomeMainWindow

def register_vote(button)
if VoteHandler.register(button.vote)
puts "#{button.vote} vote registered"
puts "vote registered"
else
puts "vote registerinf failed!"
end
Expand Down
15 changes: 13 additions & 2 deletions app/app_delegate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ def build_jukebox_controls(sender)
@jukebox_controls.setup(jukebox)
@jukebox_controls.window.makeKeyAndOrderFront(self)
App.shared.activateIgnoringOtherApps(true)

update_jukebox_controls_button_state(NSOnState)
end

def hide_jukebox_controls
update_jukebox_controls_button_state(NSOffState)
@jukebox_controls.close unless @jukebox_controls.nil?
end

def build_jukebox
Expand All @@ -47,8 +54,7 @@ def jukebox
end

def jukebox_available?
true
#WebsocketConnector.instance.connected? && !jukebox.nil?
WebsocketConnector.instance.connected? && !jukebox.nil?
end

def connect_to_websocket_server
Expand All @@ -61,4 +67,9 @@ def connect_to_websocket_server
def userNotificationCenter(center, shouldPresentNotification:notification)
true
end

def update_jukebox_controls_button_state(state)
butt = @menu.itemWithTag(MENU_CONSOLE_BUTT)
butt.setState(state) unless butt.nil?
end
end
9 changes: 9 additions & 0 deletions app/config/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
WEBSOCKET_URL = "ws://#{WEBSOCKET_HOST}:8081"
VOTE_URL = "http://#{WEBSOCKET_HOST}/external?"

DEFAULT_MENU_WIDTH=250.0

TRACK_TITLE=1
TRACK_ARTIST=2
TRACK_ARTWORK_URL=3
TRACK_ALBUM=4

VOTE_VIEW_H=19
VOTE_VIEW_W=21

U_VOTE_BUTTON=32
D_VOTE_BUTTON=33

MENU_NOWPLAYING=111
MENU_CONSOLE_BUTT=222

JB_MESSAGE_RECEIVED="JukeboxMessageReceived"
JB_UPDATED="JukeboxUpdated"
2 changes: 1 addition & 1 deletion app/lib/jukebox_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(jukebox)
end

def self.build
jb = KyanJukebox::Notify.new([:track, :playlist])
jb = KyanJukebox::Notify.new([:track, :playlist, :rating])
jb.json_parser = BW::JSON

new jb
Expand Down
Loading

0 comments on commit be6657d

Please sign in to comment.