From 15763e59a9814a21c27366bb9a53feb961438c6d Mon Sep 17 00:00:00 2001 From: Christophe Simon Date: Sat, 19 Oct 2013 17:58:34 +0200 Subject: [PATCH] Added mcabber unread buffers widget. --- rc.lua | 9 +++--- rc/im.lua | 12 ------- rc/wibox.lua | 4 ++- themes/gits/icons/im.png | Bin 0 -> 215 bytes themes/gits/theme.lua | 1 + widgets/im.lua | 39 +++++++++++++++++++++++ widgets/vicious/mcabber.lua | 61 ++++++++++++++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 17 deletions(-) create mode 100644 themes/gits/icons/im.png create mode 100644 widgets/im.lua create mode 100644 widgets/vicious/mcabber.lua diff --git a/rc.lua b/rc.lua index 274a024..c9ebef7 100644 --- a/rc.lua +++ b/rc.lua @@ -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 @@ -122,10 +123,6 @@ end utils.rc.loadrc('menu') -- }}} --- {{{ Wibox -utils.rc.loadrc('wibox') --- }}} - -- {{{ Naughty utils.rc.loadrc('naughty') -- }}} @@ -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') diff --git a/rc/im.lua b/rc/im.lua index b6ab7fb..9e91440 100644 --- a/rc/im.lua +++ b/rc/im.lua @@ -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 diff --git a/rc/wibox.lua b/rc/wibox.lua index acb8eb4..152a495 100644 --- a/rc/wibox.lua +++ b/rc/wibox.lua @@ -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, diff --git a/themes/gits/icons/im.png b/themes/gits/icons/im.png new file mode 100644 index 0000000000000000000000000000000000000000..90674838ef5a0727856535f761fcecd1609c3999 GIT binary patch literal 215 zcmeAS@N?(olHy`uVBq!ia0vp^d?3uh1|;P@bT0xawj^(N7a$D;Kb?2i11Zh|kH}&M z25w;xW@MN(M*=9wUgGKN%6^winBUa6=ITNjpiqjZi(`n!`KuGWxf%?3T<%9`-}}Eq zOIF-XFw-^W +-- * (c) 2009, Lucas de Vries +--------------------------------------------------- + +-- {{{ 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 ' n/a ' + end + + local unread = mcabber_get_unread_buffers() + if unread > 0 then + return ' ' .. unread .. ' ' + else + return ' 0 ' + end +end +-- }}} + +return setmetatable(count, { __call = function(_, ...) return worker(...) end })