Skip to content

Commit

Permalink
Added mcabber unread buffers widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
geektophe committed Oct 19, 2013
1 parent 804d3c0 commit 15763e5
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 17 deletions.
9 changes: 5 additions & 4 deletions rc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ widgets.mem = require("widgets.mem")
widgets.net = require("widgets.net")
widgets.spacer = require("widgets.spacer")
widgets.volume = require("widgets.volume")
widgets.im = require("widgets.im")
-- }}}

-- {{{ Variable definitions
Expand Down Expand Up @@ -122,10 +123,6 @@ end
utils.rc.loadrc('menu')
-- }}}

-- {{{ Wibox
utils.rc.loadrc('wibox')
-- }}}

-- {{{ Naughty
utils.rc.loadrc('naughty')
-- }}}
Expand All @@ -134,6 +131,10 @@ utils.rc.loadrc('naughty')
utils.rc.loadrc('im')
-- }}}

-- {{{ Wibox
utils.rc.loadrc('wibox')
-- }}}

-- {{{ Programs to run at startup
-- Disabled, managed by Xsession
-- utils.rc.loadrc('startup')
Expand Down
12 changes: 0 additions & 12 deletions rc/im.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,4 @@ function mcabber_event_hook(kind, arg, jid, msg)
end
end


function mcabber_get_unread_buffers()
local state_file = os.getenv("HOME") .. "/.mcabber/mcabber.state"
local f = io.open(state_file, "r")
local rows = 0
for _ in f:lines() do
rows = rows + 1
end
f:close()
return rows
end

-- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
4 changes: 3 additions & 1 deletion rc/wibox.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ for s = 1, screen.count() do
widgets.clock.widget(),
s == 1 and widget({ type = "systray" }) or nil,
widgets.spacer.widget(),
widgets.net.widget(),
widgets.im.widget(),
widgets.im.icon(),
-- widgets.net.widget(),
utils.system.hasbattery() and widgets.spacer.widget() or nil,
utils.system.hasbattery() and widgets.bat.widget(wide) or nil,
utils.system.hasbattery() and widgets.bat.icon() or nil,
Expand Down
Binary file added themes/gits/icons/im.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions themes/gits/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ theme.widget_disk = themedir.."/icons/disk.png"
theme.widget_mpd_play = themedir.."/icons/mpd_play.png"
theme.widget_mpd_pause = themedir.."/icons/mpd_pause.png"
theme.widget_mpd_stop = themedir.."/icons/mpd_stop.png"
theme.widget_im = themedir.."/icons/im.png"
-- }}}

return theme
Expand Down
39 changes: 39 additions & 0 deletions widgets/im.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-- File system size widget definition
-- Module variables are :
--
-- widget : the wiget itself
-- icon : the associated widget icon
--
-- Note that he theme should have widget_disk attribute set

local vicious = require("vicious")
local awful = require("awful")
local blingbling = require("blingbling")
local mcabber = require("widgets.vicious.mcabber")
local beautiful = beautiful
local widget_init = widget
local image = image
local mcabber_get_unread_buffers = mcabber_get_unread_buffers

module("widgets.im")

local _imicon = nil
local _imwidget = nil

function icon()
if _imicon == nil then
_imicon = widget_init({ type = "imagebox" })
_imicon.image = image(beautiful.widget_im)
end
return _imicon
end

function widget()
if _imwidget == nil then
_imwidget = widget_init({ type = "textbox" })
vicious.register(_imwidget, mcabber,'$1', 5)
end
return _imwidget
end

-- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
61 changes: 61 additions & 0 deletions widgets/vicious/mcabber.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <[email protected]>
-- * (c) 2009, Lucas de Vries <[email protected]>
---------------------------------------------------

-- {{{ Grab environment
local os = { getenv=os.getenv }
local io = { open=io.open, popen=io.popen }
local print = print
-- }}}

-- Count: provides mcabber unread buffers count
local count = {}


-- {{{ 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 rows = 0
for _ in f:lines() do
rows = rows + 1
end
f:close()
return rows
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
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
end
-- }}}

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

0 comments on commit 15763e5

Please sign in to comment.