From 5d8727531e51aeac39b5589181130c5e414316ec Mon Sep 17 00:00:00 2001 From: Christophe Simon Date: Sun, 20 Oct 2013 18:39:26 +0200 Subject: [PATCH] Added gmail plugin. --- rc.lua | 1 + rc/wibox.lua | 9 ++++-- themes/gits/icons/gmail.png | Bin 0 -> 233 bytes themes/gits/theme.lua | 1 + widgets/gmail.lua | 56 ++++++++++++++++++++++++++++++++++++ widgets/im.lua | 18 ++++++++++++ widgets/vicious/gmail.lua | 56 ++++++++++++++++++++++++++++++++++++ 7 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 themes/gits/icons/gmail.png create mode 100644 widgets/gmail.lua create mode 100644 widgets/vicious/gmail.lua diff --git a/rc.lua b/rc.lua index c9ebef7..2cdb315 100644 --- a/rc.lua +++ b/rc.lua @@ -40,6 +40,7 @@ widgets.net = require("widgets.net") widgets.spacer = require("widgets.spacer") widgets.volume = require("widgets.volume") widgets.im = require("widgets.im") +widgets.gmail = require("widgets.gmail") -- }}} -- {{{ Variable definitions diff --git a/rc/wibox.lua b/rc/wibox.lua index 152a495..d312db9 100644 --- a/rc/wibox.lua +++ b/rc/wibox.lua @@ -28,9 +28,6 @@ for s = 1, screen.count() do mylayoutbox[s], widgets.clock.widget(), s == 1 and widget({ type = "systray" }) or nil, - widgets.spacer.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, @@ -49,6 +46,12 @@ for s = 1, screen.count() do widgets.spacer.widget(), widgets.volume.widget(), widgets.volume.icon(), + widgets.spacer.widget(), + widgets.gmail.widget(), + widgets.gmail.icon(), + widgets.spacer.widget(), + widgets.im.widget(), + widgets.im.icon(), layout = awful.widget.layout.horizontal.rightleft } end diff --git a/themes/gits/icons/gmail.png b/themes/gits/icons/gmail.png new file mode 100644 index 0000000000000000000000000000000000000000..31ed0b1e12ffe14168a038a90179f365cafda271 GIT binary patch literal 233 zcmeAS@N?(olHy`uVBq!ia0vp^d?3uh1|;P@bT0xawj^(N7a$D;Kb?2i11Zh|kH}&M z25w;xW@MN(M*=9wUgGKN%6^wigjZJA^~yaapir5oi(`n!`KuRgxeqz;uswJlr5kqT z=FR{A&&#|~X_9{~^w7f3+QM{#;>q8viH1{8DL$W*&Z(&yQM>c|3B^4JrGhzMNG(yG zH(%gl@PvAy?-mb4`@-jB1!%vLH0ODECo#G?s_%P}y~srQ;yz`)sXx{U{CqFVy~;en WL)<$dTrmac0tQc4KbLh*2~7Z~XiJ>{ literal 0 HcmV?d00001 diff --git a/themes/gits/theme.lua b/themes/gits/theme.lua index 01c1a7f..4ebdadb 100644 --- a/themes/gits/theme.lua +++ b/themes/gits/theme.lua @@ -162,6 +162,7 @@ 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" +theme.widget_gmail = themedir.."/icons/gmail.png" -- }}} return theme diff --git a/widgets/gmail.lua b/widgets/gmail.lua new file mode 100644 index 0000000..8b26229 --- /dev/null +++ b/widgets/gmail.lua @@ -0,0 +1,56 @@ +-- 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 gmail = require("widgets.vicious.gmail") +local beautiful = beautiful +local widget_init = widget +local image = image + +module("widgets.gmail") + +local _gmailicon = nil +local _gmailwidget = nil +local _gmailenabled = true + + +local function gmail_toggle() + if _gmailenabled then + vicious.unregister(_gmailwidget, true) + _gmailwidget.text = ' dis ' + else + vicious.activate(_gmailwidget) + end + _gmailenabled = not _gmailenabled +end + + +function icon() + if _gmailicon == nil then + _gmailicon = widget_init({ type = "imagebox" }) + _gmailicon.image = image(beautiful.widget_gmail) + end + return _gmailicon +end + + +function widget() + if _gmailwidget == nil then + _gmailwidget = widget_init({ type = "textbox" }) + _gmailwidget:buttons(awful.util.table.join( + awful.button({ }, 1, function () + gmail_toggle() + end))) + vicious.register(_gmailwidget, gmail,'$1', 30) + end + return _gmailwidget +end + +-- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/widgets/im.lua b/widgets/im.lua index 05008de..18fdee9 100644 --- a/widgets/im.lua +++ b/widgets/im.lua @@ -19,6 +19,19 @@ module("widgets.im") local _imicon = nil local _imwidget = nil +local _imenabled = true + + +local function im_toggle() + if _imenabled then + vicious.unregister(_imwidget, true) + _imwidget.text = ' dis ' + else + vicious.activate(_imwidget) + end + _imenabled = not _imenabled +end + function icon() if _imicon == nil then @@ -28,9 +41,14 @@ function icon() return _imicon end + function widget() if _imwidget == nil then _imwidget = widget_init({ type = "textbox" }) + _imwidget:buttons(awful.util.table.join( + awful.button({ }, 1, function () + im_toggle() + end))) vicious.register(_imwidget, mcabber,'$1', 5) end return _imwidget diff --git a/widgets/vicious/gmail.lua b/widgets/vicious/gmail.lua new file mode 100644 index 0000000..73eae91 --- /dev/null +++ b/widgets/vicious/gmail.lua @@ -0,0 +1,56 @@ +--------------------------------------------------- +-- Licensed under the GNU General Public License v2 +-- * (c) 2010, Adrian C. +-- * (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 rss = "https://mail.google.com/mail/feed/atom" +local count = {} + + +-- {{{ Checks if mcabber is running +local function gmail_get_unread_messages() + 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, "([%d]+)") + if count then + unread = tonumber(count) + break + end + end + f:close() + return unread +end +-- }}} + + +-- {{{ Date widget type +local function worker(format, warg) +-- if not mcabber_running() then +-- return ' n/a ' +-- end + + local unread = gmail_get_unread_messages() + if unread > 0 then + return ' ' .. unread .. ' ' + else + return ' 0 ' + end +end +-- }}} + +return setmetatable(count, { __call = function(_, ...) return worker(...) end }) + +-- vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4