widgets: reuse existing datasets where appropriate

Gmail, mbox, raid, weather and wifi could return the old value in case
there isn't new data, no need for N/A to be so common on our wibox.
This commit is contained in:
Adrian C. (anrxc) 2010-04-02 01:08:12 +02:00
parent a9347ec0d0
commit 448275a386
12 changed files with 50 additions and 48 deletions

View File

@ -21,7 +21,7 @@ local string = {
module("vicious.widgets.cpu")
-- Initialise function tables
-- Initialize function tables
local cpu_usage = {}
local cpu_total = {}
local cpu_active = {}

View File

@ -16,7 +16,7 @@ local helpers = require("vicious.helpers")
module("vicious.widgets.dio")
-- Initialise function tables
-- Initialize function tables
local disk_usage = {}
local disk_total = {}
-- Variable definitions

View File

@ -38,16 +38,15 @@ local rss = {
-- Default is all unread
local feed = rss.unread
local mail = {
["{count}"] = 0,
["{subject}"] = "N/A"
}
-- }}}
-- {{{ Gmail widget type
local function worker(format, warg)
local mail = {
["{count}"] = 0,
["{subject}"] = "N/A"
}
-- Get info from the Gmail atom feed
local f = io.popen("curl --connect-timeout 1 -m 3 -fsn " .. feed[1])

View File

@ -16,13 +16,13 @@ local helpers = require("vicious.helpers")
module("vicious.widgets.mbox")
-- Initialize variables
local subject = "N/A"
-- {{{ Mailbox widget type
local function worker(format, warg)
if not warg then return end
-- Default value
local subject = "N/A"
-- mbox could be huge, get a 30kb chunk from EOF
if type(warg) ~= "table" then mbox = warg end
-- * attachment could be much bigger than 30kb

View File

@ -18,7 +18,7 @@ module("vicious.widgets.mboxc")
local function worker(format, warg)
if not warg then return end
-- Initialise counters
-- Initialize counters
local count = { old = 0, total = 0, new = 0 }
-- Get data from mbox files

View File

@ -18,7 +18,7 @@ module("vicious.widgets.mdir")
local function worker(format, warg)
if not warg then return end
-- Initialise counters
-- Initialize counters
local count = { new = 0, cur = 0 }
for i=1, #warg do

View File

@ -18,7 +18,7 @@ local helpers = require("vicious.helpers")
module("vicious.widgets.net")
-- Initialise function tables
-- Initialize function tables
local nets = {}
-- Variable definitions
local unit = { ["b"] = 1, ["kb"] = 1024,

View File

@ -28,7 +28,7 @@ local function worker(format, warg)
local soon = today + 24 * 3600 * 3 -- 3 days ahead is close
local future = today + 24 * 3600 * 7 -- 7 days ahead is maximum
-- Initialise counters
-- Initialize counters
local count = { past = 0, today = 0, soon = 0, future = 0 }
-- Get data from agenda files

View File

@ -18,7 +18,7 @@ module("vicious.widgets.pkg")
local function worker(format, warg)
if not warg then return end
-- Initialise counters
-- Initialize counters
local updates = 0
local manager = {
["Arch"] = { cmd = "pacman -Qu" },

View File

@ -19,20 +19,23 @@ local string = {
module("vicious.widgets.raid")
-- Initialize function tables
local mddev = {}
-- {{{ RAID widget type
local function worker(format, warg)
if not warg then return end
local found = false
local mddev = {}
mddev[warg] = {
["active"] = 0,
["assigned"] = 0
}
if not mddev[warg] then
mddev[warg] = {
["found"] = false,
["active"] = 0,
["assigned"] = 0
}
end
-- Linux manual page: md(4)
for line in io.lines("/proc/mdstat") do
if found then
if mddev[warg]["found"] then
local updev = string.match(line, "%[[_U]+%]")
for i in string.gmatch(updev, "U") do
@ -41,7 +44,7 @@ local function worker(format, warg)
break
elseif string.sub(line, 1, string.len(warg)) == warg then
found = true
mddev[warg]["found"] = true
for i in string.gmatch(line, "%[%d%]") do
mddev[warg]["assigned"] = mddev[warg]["assigned"] + 1

View File

@ -17,24 +17,24 @@ local helpers = require("vicious.helpers")
module("vicious.widgets.weather")
-- Initialize function tables
local weather = {
["{city}"] = "N/A",
["{wind}"] = "N/A",
["{windmph}"] = "N/A",
["{windkmh}"] = "N/A",
["{sky}"] = "N/A",
["{weather}"] = "N/A",
["{tempf}"] = "N/A",
["{tempc}"] = "N/A",
["{humid}"] = "N/A",
["{press}"] = "N/A"
}
-- {{{ Weather widget type
local function worker(format, warg)
if not warg then return end
-- Default values
local weather = {
["{city}"] = "N/A",
["{wind}"] = "N/A",
["{windmph}"] = "N/A",
["{windkmh}"] = "N/A",
["{sky}"] = "N/A",
["{weather}"] = "N/A",
["{tempf}"] = "N/A",
["{tempc}"] = "N/A",
["{humid}"] = "N/A",
["{press}"] = "N/A"
}
-- Get weather forceast by the station ICAO code, from:
-- * US National Oceanic and Atmospheric Administration
local noaa = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"

View File

@ -21,20 +21,20 @@ local string = {
module("vicious.widgets.wifi")
-- Initialize function tables
local winfo = {
["{ssid}"] = "N/A",
["{mode}"] = "N/A",
["{chan}"] = 0,
["{rate}"] = 0,
["{link}"] = 0,
["{sign}"] = 0
}
-- {{{ Wireless widget type
local function worker(format, warg)
if not warg then return end
-- Default values
local winfo = {
["{ssid}"] = "N/A",
["{mode}"] = "N/A",
["{chan}"] = 0,
["{rate}"] = 0,
["{link}"] = 0,
["{sign}"] = 0
}
-- Get data from iwconfig where available
local iwconfig = "/sbin/iwconfig"
local f = io.open(iwconfig, "rb")