]> git.madduck.net Git - etc/awesome.git/blob - widgets/contrib/task.lua

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

88baa71e6206076b76c4d22fe6400167c8391d03
[etc/awesome.git] / widgets / contrib / task.lua
1
2 --[[
3                                                   
4      Licensed under GNU General Public License v2 
5       * (c) 2013, Luke Bonham                     
6       * (c) 2013, Jan Xie                         
7                                                   
8 --]]
9
10 local icons_dir    = require("lain.helpers").icons_dir
11
12 local awful        = require("awful")
13 local beautiful    = require("beautiful")
14 local naughty      = require("naughty")
15
16 local io           = io
17 local string       = { len = string.len }
18 local tonumber     = tonumber
19
20 local setmetatable = setmetatable
21
22 -- Taskwarrior notification
23 -- lain.widgets.task
24 local task = {}
25
26 local task_notification = nil
27
28 function task:hide()
29     if task_notification ~= nil then
30         naughty.destroy(task_notification)
31         task_notification = nil
32     end
33 end
34
35 function task:show()
36     task:hide()
37
38     local f, c_text
39
40     f = io.popen('task')
41     c_text = "<tt><span font='"
42              .. task.font .. " "
43              .. task.font_size .. "'>"
44              .. f:read("*all"):gsub("\n*$", "")
45              .. "</span></tt>"
46     f:close()
47
48     task_notification = naughty.notify({ title = "[task next]",
49                                          text = c_text,
50                                          icon = task.notify_icon,
51                                          position = task.position,
52                                          fg = task.fg,
53                                          bg = task.bg,
54                                          timeout = task.timeout })
55 end
56
57 function task:prompt_add()
58   awful.prompt.run({ prompt = "Add task: " },
59       mypromptbox[mouse.screen].widget,
60       function (...)
61           local f = io.popen("task add " .. ...)
62           c_text = "\n<tt><span font='" 
63                    .. task.font .. " "
64                    .. task.font_size .. "'>"
65                    .. f:read("*all")
66                    .. "</span></tt>"
67
68           naughty.notify({
69               text = c_text,
70               icon = task.notify_icon,
71               position = task.position,
72               fg = task.fg,
73               bg = task.bg,
74               timeout = task.timeout
75           })
76       end,
77       nil,
78       awful.util.getdir("cache") .. "/history_task_add")
79 end
80
81 function task:prompt_search()
82   awful.prompt.run({ prompt = "Search task: " },
83       mypromptbox[mouse.screen].widget,
84       function (...)
85           local f = io.popen("task " .. ...)
86           c_text = f:read("*all")
87           f:close()
88
89           if string.len(c_text) == 0
90           then
91               c_text = "No results found."
92           else
93               c_text = "<tt><span font='"
94                        .. task.font .. " "
95                        .. task.font_size .. "'>"
96                        .. c_text .. "\n"
97                        .. "</span></tt>"
98           end
99
100           naughty.notify({
101               text = c_text,
102               icon = task.notify_icon,
103               position = task.position,
104               fg = task.fg,
105               bg = task.bg,
106               timeout = task.timeout
107           })
108       end,
109       nil,
110       awful.util.getdir("cache") .. "/history_task")
111 end
112
113 function task:attach(widget, args)
114     local args     = args or {}
115
116     task.font_size = tonumber(args.font_size) or 12
117     task.font      = beautiful.font:sub(beautiful.font:find(""),
118                      beautiful.font:find(" "))
119     task.fg        = args.fg or beautiful.fg_normal or "#FFFFFF"
120     task.bg        = args.bg or beautiful.bg_normal or "#FFFFFF"
121     task.position  = args.position or "top_right"
122     task.timeout   = args.timeout or 7
123
124     task.notify_icon = icons_dir .. "/taskwarrior/task.png"
125     task.notify_icon_small = icons_dir .. "/taskwarrior/tasksmall.png"
126
127     widget:connect_signal("mouse::enter", function () task:show() end)
128     widget:connect_signal("mouse::leave", function () task:hide() end)
129 end
130
131 return setmetatable(task, { __call = function(_, ...) return create(...) end })