Skip to content

Commit

Permalink
Enhenced im widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
geektophe committed Oct 20, 2013
1 parent ce1499e commit 304845e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 24 deletions.
4 changes: 1 addition & 3 deletions widgets/vicious/gmail.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ local count = {}

-- {{{ Checks if mcabber is running
local function gmail_get_unread_messages()
local unread = 0

if not awful.util.file_readable(os.getenv("HOME") .. "/.netrc") then
return -1
end

local unread = 0
-- Get info from the Gmail atom feed
local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. rss)

-- Could be huge don't read it all at once, info we are after is at the top
for line in f:lines() do
count = string.match(line, "<fullcount>([%d]+)</fullcount>")
Expand Down
45 changes: 24 additions & 21 deletions widgets/vicious/mcabber.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
---------------------------------------------------

-- {{{ Grab environment
local awful = require("awful")
local os = { getenv=os.getenv }
local io = { open=io.open, popen=io.popen }
local print = print
-- }}}

-- Count: provides mcabber unread buffers count
local count = {}
local statefile = os.getenv("HOME") .. "/.mcabber/mcabber.state"


-- {{{ Checks if mcabber is running
local function mcabber_get_unread_buffers()
local state_file = os.getenv("HOME") .. "/.mcabber/mcabber.state"
local f = io.open(state_file, "r")
local f = io.open(statefile, "r")
local rows = 0
for _ in f:lines() do
rows = rows + 1
Expand All @@ -30,32 +31,34 @@ end

-- {{{ Counts unread mcabber buffers
local function mcabber_running()
local fd = io.popen("pgrep mcabber")
local pid = fd:read('*a')
fd:close()

if pid:len() > 0 then
return true
else
return false
end
local fd = io.popen("pgrep mcabber")
local pid = fd:read('*a')
fd:close()

if pid:len() > 0 then
return true
else
return false
end
end
-- }}}


-- {{{ Date widget type
local function worker(format, warg)
if not mcabber_running() then
return '<span color="white" bgcolor="grey" weight="bold"> n/a </span>'
end

local unread = mcabber_get_unread_buffers()
if unread > 0 then
return '<span color="white" bgcolor="red" weight="bold"> ' .. unread .. ' </span>'
else
return '<span color="white" bgcolor="green" weight="bold"> 0 </span>'
end
if not mcabber_running() or not awful.util.file_readable(statefile) then
return '<span color="white" bgcolor="grey" weight="bold"> n/a </span>'
end

local unread = mcabber_get_unread_buffers()
if unread > 0 then
return '<span color="white" bgcolor="red" weight="bold"> ' .. unread .. ' </span>'
else
return '<span color="white" bgcolor="green" weight="bold"> 0 </span>'
end
end
-- }}}

return setmetatable(count, { __call = function(_, ...) return worker(...) end })

-- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

0 comments on commit 304845e

Please sign in to comment.