aboutsummaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
authorAdrian C. (anrxc) <anrxc@sysphere.org>2010-04-02 01:08:12 +0200
committerAdrian C. (anrxc) <anrxc@sysphere.org>2010-04-02 01:08:12 +0200
commit448275a3865d1db82a6fc37d60548da8b865e5e0 (patch)
treeed0b9134b26d2002ec289210fb0915f41b26d59f /widgets
parenta9347ec0d033aa08d77fcc75c35d88514f9e84f5 (diff)
downloadvicious-legacy-448275a3865d1db82a6fc37d60548da8b865e5e0.tar.xz
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.
Diffstat (limited to 'widgets')
-rw-r--r--widgets/cpu.lua2
-rw-r--r--widgets/dio.lua2
-rw-r--r--widgets/gmail.lua9
-rw-r--r--widgets/mbox.lua6
-rw-r--r--widgets/mboxc.lua2
-rw-r--r--widgets/mdir.lua2
-rw-r--r--widgets/net.lua2
-rw-r--r--widgets/org.lua2
-rw-r--r--widgets/pkg.lua2
-rw-r--r--widgets/raid.lua21
-rw-r--r--widgets/weather.lua28
-rw-r--r--widgets/wifi.lua20
12 files changed, 50 insertions, 48 deletions
diff --git a/widgets/cpu.lua b/widgets/cpu.lua
index 3dfc22f..2673021 100644
--- a/widgets/cpu.lua
+++ b/widgets/cpu.lua
@@ -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 = {}
diff --git a/widgets/dio.lua b/widgets/dio.lua
index e886dac..4aa7002 100644
--- a/widgets/dio.lua
+++ b/widgets/dio.lua
@@ -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
diff --git a/widgets/gmail.lua b/widgets/gmail.lua
index b2f0d8c..c772be8 100644
--- a/widgets/gmail.lua
+++ b/widgets/gmail.lua
@@ -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])
diff --git a/widgets/mbox.lua b/widgets/mbox.lua
index 475d018..be64e03 100644
--- a/widgets/mbox.lua
+++ b/widgets/mbox.lua
@@ -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
diff --git a/widgets/mboxc.lua b/widgets/mboxc.lua
index 6de1066..c928cd3 100644
--- a/widgets/mboxc.lua
+++ b/widgets/mboxc.lua
@@ -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
diff --git a/widgets/mdir.lua b/widgets/mdir.lua
index 94522e7..464d9a1 100644
--- a/widgets/mdir.lua
+++ b/widgets/mdir.lua
@@ -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
diff --git a/widgets/net.lua b/widgets/net.lua
index 9fd221f..9eda942 100644
--- a/widgets/net.lua
+++ b/widgets/net.lua
@@ -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,
diff --git a/widgets/org.lua b/widgets/org.lua
index e6c622e..2d563b2 100644
--- a/widgets/org.lua
+++ b/widgets/org.lua
@@ -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
diff --git a/widgets/pkg.lua b/widgets/pkg.lua
index 0e4ba90..15389a9 100644
--- a/widgets/pkg.lua
+++ b/widgets/pkg.lua
@@ -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" },
diff --git a/widgets/raid.lua b/widgets/raid.lua
index eaf7825..3f9ef43 100644
--- a/widgets/raid.lua
+++ b/widgets/raid.lua
@@ -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
diff --git a/widgets/weather.lua b/widgets/weather.lua
index 7a114c0..f54fbc3 100644
--- a/widgets/weather.lua
+++ b/widgets/weather.lua
@@ -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/"
diff --git a/widgets/wifi.lua b/widgets/wifi.lua
index 61dee12..2e400bc 100644
--- a/widgets/wifi.lua
+++ b/widgets/wifi.lua
@@ -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")