+function widget:popup_oneshot(timeout)
+ if self._notification then
+ self:popup_hide()
+ self:popup_show()
+ else
+ self:popup_show()
+ end
+ self:popup_hide(5)
+end
+
+function widget:error_handler(err)
+ self._textbox:set_text("Error: " .. tostring(err))
+ self._status = {}
+end
+
+function widget:run()
+ self._status = {}
+
+ self._connection = mpc.new(nil, nil, nil, function(err) self:error_handler(err) end,
+ "player", function(conn)
+ conn:send("status", function(err, status)
+ local songchanged = self._status.songid ~= status.songid
+ local statechanged = self._status.state ~= status.state
+ self._status = status
+ if not songchanged then
+ self:update_widget()
+ if statechanged then
+ self:popup_oneshot(5)
+ end
+ return
+ end
+
+ conn:send("currentsong", function(_, song)
+ self._currentsong = song
+ conn:albumart(song.file, function(_, art)
+ self._albumart = art
+ self:update_widget()
+ self:popup_oneshot(5)
+ end)
+ end)
+ end)
+ end
+ )
+
+ self._keep_alive_timer = timer {
+ timeout = 1
+ , autostart = true
+ , callback = function() self._connection:connect() end
+ , call_now = true
+ }
+