2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
2010-03-12 21:56:17 +01:00
|
|
|
local tonumber = tonumber
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
local io = { popen = io.popen }
|
2009-08-01 23:11:41 +02:00
|
|
|
local setmetatable = setmetatable
|
2010-03-12 21:56:17 +01:00
|
|
|
local string = { gmatch = string.gmatch }
|
2009-11-03 01:19:37 +01:00
|
|
|
local helpers = require("vicious.helpers")
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
2010-03-12 21:56:17 +01:00
|
|
|
-- Mpd: provides Music Player Daemon information
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.mpd
|
|
|
|
local mpd = {}
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
|
|
|
|
-- {{{ MPD widget type
|
2009-11-03 01:19:37 +01:00
|
|
|
local function worker(format, warg)
|
2010-03-12 21:56:17 +01:00
|
|
|
local mpd_state = {
|
|
|
|
["{volume}"] = 0,
|
|
|
|
["{state}"] = "N/A",
|
|
|
|
["{Artist}"] = "N/A",
|
|
|
|
["{Title}"] = "N/A",
|
|
|
|
["{Album}"] = "N/A",
|
2010-08-22 14:59:05 +02:00
|
|
|
["{Genre}"] = "N/A",
|
|
|
|
--["{Name}"] = "N/A",
|
|
|
|
--["{file}"] = "N/A",
|
2010-03-12 21:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
-- Fallback to MPD defaults
|
2011-04-25 18:37:00 +02:00
|
|
|
local pass = warg and (warg.password or warg[1]) or "\"\""
|
|
|
|
local host = warg and (warg.host or warg[2]) or "127.0.0.1"
|
|
|
|
local port = warg and (warg.port or warg[3]) or "6600"
|
2010-03-12 21:56:17 +01:00
|
|
|
|
|
|
|
-- Construct MPD client options
|
|
|
|
local mpdh = "telnet://"..host..":"..port
|
|
|
|
local echo = "echo 'password "..pass.."\nstatus\ncurrentsong\nclose'"
|
|
|
|
|
|
|
|
-- Get data from MPD server
|
|
|
|
local f = io.popen(echo.." | curl --connect-timeout 1 -fsm 3 "..mpdh)
|
|
|
|
|
|
|
|
for line in f:lines() do
|
|
|
|
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
|
|
|
if k == "volume" then mpd_state["{"..k.."}"] = v and tonumber(v)
|
|
|
|
elseif k == "state" then mpd_state["{"..k.."}"] = helpers.capitalize(v)
|
|
|
|
elseif k == "Artist" then mpd_state["{"..k.."}"] = helpers.escape(v)
|
|
|
|
elseif k == "Title" then mpd_state["{"..k.."}"] = helpers.escape(v)
|
|
|
|
elseif k == "Album" then mpd_state["{"..k.."}"] = helpers.escape(v)
|
|
|
|
elseif k == "Genre" then mpd_state["{"..k.."}"] = helpers.escape(v)
|
2010-08-22 14:59:05 +02:00
|
|
|
--elseif k == "Name" then mpd_state["{"..k.."}"] = helpers.escape(v)
|
|
|
|
--elseif k == "file" then mpd_state["{"..k.."}"] = helpers.escape(v)
|
2010-03-12 21:56:17 +01:00
|
|
|
end
|
2009-11-03 01:19:37 +01:00
|
|
|
end
|
|
|
|
end
|
2010-03-12 21:56:17 +01:00
|
|
|
f:close()
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
2010-03-12 21:56:17 +01:00
|
|
|
return mpd_state
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
end
|
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
2012-06-15 18:07:05 +02:00
|
|
|
return setmetatable(mpd, { __call = function(_, ...) return worker(...) end })
|