]> 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:

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