awesome: Show email counts in first wibox

This commit is contained in:
Tom Willemsen 2013-02-01 12:18:26 +01:00
parent 582e822177
commit 44a9da16e7

View file

@ -8,10 +8,13 @@ local beautiful = require("beautiful")
-- Notification library -- Notification library
local naughty = require("naughty") local naughty = require("naughty")
local menubar = require("menubar") local menubar = require("menubar")
local lfs = require("lfs")
awful.rules = require("awful.rules") awful.rules = require("awful.rules")
require("awful.autofocus") require("awful.autofocus")
local maildir_base = os.getenv("HOME") .. "/documents/mail/"
function ror(program, cls) function ror(program, cls)
local rorfunc = function () local rorfunc = function ()
local matcher = function (c) local matcher = function (c)
@ -31,6 +34,25 @@ function ror_combo(mod, key, program, class)
function () awful.util.spawn(program) end)) function () awful.util.spawn(program) end))
end end
function new_mail(maildir)
local count = 0
for file in lfs.dir(maildir_base .. maildir .. "/new") do
if file ~= "." and file ~= ".." then
count = count + 1
end
end
for file in lfs.dir(maildir_base .. maildir .. "/cur") do
if string.sub(file, -1) ~= "S" and file ~= "."
and file ~= ".." then
count = count + 1
end
end
return count
end
----- Error handling ----- Error handling
-- Check if awesome encountered an error during startup and fell back -- Check if awesome encountered an error during startup and fell back
-- to another config (This code will only ever execute for the -- to another config (This code will only ever execute for the
@ -135,12 +157,32 @@ mypromptbox = {}
mylayoutbox = {} mylayoutbox = {}
mytaglist = {} mytaglist = {}
mytasklist = {} mytasklist = {}
mymaillist = wibox.widget.textbox()
mymaillist:set_text(
string.format(" ryu: %d gmail: %d aethon: %d 9f: %d",
new_mail('ryuslash.org/inbox'),
new_mail('gmail/inbox'),
new_mail('aethon/inbox'),
new_mail('ninthfloor/inbox')))
mymaillisttimer = timer({ timeout = 60 })
mymaillisttimer:connect_signal(
"timeout",
function ()
mymaillist:set_text(
string.format(" ryu: %d gmail: %d aethon: %d 9f: %d",
new_mail('ryuslash.org/inbox'),
new_mail('gmail/inbox'),
new_mail('aethon/inbox'),
new_mail('ninthfloor/inbox')))
end)
mymaillisttimer:start()
for s = 1, screen.count() do for s = 1, screen.count() do
-- Create a promptbox for each screen -- Create a promptbox for each screen
mypromptbox[s] = awful.widget.prompt() mypromptbox[s] = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using. -- Create an imagebox widget which will contains an icon
-- We need one layoutbox per screen. -- indicating which layout we're using. We need one layoutbox per
-- screen.
mylayoutbox[s] = awful.widget.layoutbox(s) mylayoutbox[s] = awful.widget.layoutbox(s)
-- Create a taglist widget -- Create a taglist widget
mytaglist[s] = awful.widget.taglist( mytaglist[s] = awful.widget.taglist(
@ -161,7 +203,10 @@ for s = 1, screen.count() do
-- Widgets that are aligned to the right -- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal() local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray()) end if s == 1 then
right_layout:add(mymaillist)
right_layout:add(wibox.widget.systray())
end
right_layout:add(mytextclock) right_layout:add(mytextclock)
right_layout:add(mylayoutbox[s]) right_layout:add(mylayoutbox[s])