+ local artist = self._currentsong.artist
+ local title = self._currentsong.title
+ local file = self._currentsong.file
+ if artist and title then
+ text = string.format("%s - %s", artist, title)
+ elseif title or file then
+ text = string.format("%s", title or file )
+ else
+ text = "-"
+ end
+ self._textbox.text = text
+end
+
+local function sec_to_min(sec)
+ local m, s = math.modf((sec or 0.0) / 60)
+ return string.format('%d:%02d', m, math.floor(s * 60))
+end
+
+local function song_duration(elapsed, duration)
+ return sec_to_min(elapsed) .. "/" .. sec_to_min(duration)
+end
+
+local dbg = require("gears.debug")
+function widget:get_albumart()
+ local art = self._albumart
+ -- dbg.dump(art)
+ -- dbg.dump(self._albumart.binary)
+ if art and art.binary then
+ local path = '/tmp/test.jpg'
+ local f = io.open(path, 'w')
+ f:write(art.binary)
+ f:close()
+ return path
+ else
+ return beautiful.mpd_default_album
+ end
+end
+
+function widget:get_info()
+ local status, song = self._status, self._currentsong
+ if not status.state then return nil end
+ if not status.song then return nil end
+
+ local info = {}
+ info.title = status.state .. " " .. status.song .. "/" .. status.playlistlength .. " " .. song_duration(status.elapsed, status.duration)
+ if not song.artist then
+ info.text = string.format("%s", song.title or song.file)
+ else
+ info.text = string.format("%s - %s", song.artist, song.title)
+ end
+ if song.album then
+ info.text = info.text .. "\n" .. tostring(song.album or "")
+ end
+
+ return info
+end
+
+function widget:popup_show()
+ if self._notification then return end
+
+ local table = self:get_info()
+ if not table then return end
+
+ self._timer:start()
+ self._notification = naughty.notify(
+ { title = table.title
+ , icon = self:get_albumart()
+ , icon_size = 64
+ , text = table.text
+ , timeout = 0
+ , destroy = function() self._timer:stop(); self._notification = nil end
+ })
+end
+
+function widget:popup_hide(delay)
+ local function destroy()
+ if self._hover then return end
+ if not self._notification then return end
+ naughty.destroy(self._notification)
+ self._notification = nil
+ end
+
+ if not delay then
+ destroy()
+ return
+ end
+
+ if self._hide_timer and self._hide_timer.started then
+ self._hide_timer.timeout = delay
+ self._hide_timer:again()
+ else
+ self._hide_timer = timer(
+ { timeout = delay
+ , autostart = true
+ , single_shot = true
+ , callback = destroy
+ })