1
1
mirror of https://github.com/danbee/persephone synced 2025-03-04 08:39:11 +00:00

Change the queue icon depending on state

This commit is contained in:
Daniel Barber 2019-02-07 21:27:24 -05:00
parent be8b286de8
commit 2c06d24276
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8

View File

@ -13,6 +13,8 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
var queue: [MPDClient.Song] = [] var queue: [MPDClient.Song] = []
var queuePos: Int32 = -1 var queuePos: Int32 = -1
var queueIcon: NSImage? = nil
let systemFontRegular = NSFont.systemFont(ofSize: 13, weight: .regular) let systemFontRegular = NSFont.systemFont(ofSize: 13, weight: .regular)
let systemFontBold = NSFont.systemFont(ofSize: 13, weight: .bold) let systemFontBold = NSFont.systemFont(ofSize: 13, weight: .bold)
@ -26,6 +28,13 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
queueView.columnAutoresizingStyle = .uniformColumnAutoresizingStyle queueView.columnAutoresizingStyle = .uniformColumnAutoresizingStyle
NotificationCenter.default.addObserver(
self,
selector: #selector(stateChanged(_:)),
name: MPDClient.stateChanged,
object: AppDelegate.mpdClient
)
NotificationCenter.default.addObserver( NotificationCenter.default.addObserver(
self, self,
selector: #selector(queueChanged(_:)), selector: #selector(queueChanged(_:)),
@ -41,6 +50,13 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
) )
} }
@objc func stateChanged(_ notification: Notification) {
guard let state = notification.userInfo?[MPDClient.stateKey] as? mpd_state
else { return }
setQueueIcon(state)
}
@objc func queueChanged(_ notification: Notification) { @objc func queueChanged(_ notification: Notification) {
guard let queue = notification.userInfo?[MPDClient.queueKey] as? [MPDClient.Song] guard let queue = notification.userInfo?[MPDClient.queueKey] as? [MPDClient.Song]
else { return } else { return }
@ -66,6 +82,17 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
) )
} }
func setQueueIcon(_ state: mpd_state) {
switch state {
case MPD_STATE_PLAY:
self.queueIcon = NSImage(named: NSImage.Name("playButton"))
case MPD_STATE_PAUSE:
self.queueIcon = NSImage(named: NSImage.Name("pauseButton"))
default:
self.queueIcon = nil
}
}
func setQueuePos(oldSongRowPos: Int, newSongRowPos: Int) { func setQueuePos(oldSongRowPos: Int, newSongRowPos: Int) {
if oldSongRowPos > 0 { if oldSongRowPos > 0 {
guard let oldSongRow = queueView.rowView(atRow: oldSongRowPos, makeIfNecessary: true) guard let oldSongRow = queueView.rowView(atRow: oldSongRowPos, makeIfNecessary: true)
@ -83,7 +110,7 @@ class QueueViewController: NSViewController, NSOutlineViewDataSource, NSOutlineV
else { return } else { return }
setRowFont(rowView: songRow, font: systemFontBold) setRowFont(rowView: songRow, font: systemFontBold)
newSongTitleCell.imageView?.image = NSImage(named: NSImage.Name("playButton")) newSongTitleCell.imageView?.image = self.queueIcon
} }
func setRowFont(rowView: NSTableRowView, font: NSFont) { func setRowFont(rowView: NSTableRowView, font: NSFont) {