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

Fix muted problem. To know if the sound is mute we have to check if mute == "yes...
[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 mouse        = mouse
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.contrib.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(scr_pos)
36     task:hide()
37
38     local f, c_text
39
40     if task.followmouse then
41         local scrp = mouse.screen
42     else
43         local scrp = scr_pos or task.scr_pos
44     end
45
46     f = io.popen('task')
47     c_text = "<span font='"
48              .. task.font .. " "
49              .. task.font_size .. "'>"
50              .. f:read("*all"):gsub("\n*$", "")
51              .. "</span>"
52     f:close()
53
54     task_notification = naughty.notify({ title = "[task next]",
55                                          text = c_text,
56                                          icon = task.notify_icon,
57                                          position = task.position,
58                                          fg = task.fg,
59                                          bg = task.bg,
60                                          timeout = task.timeout,
61                                          screen = scrp
62                                      })
63 end
64
65 function task:prompt_add()
66   awful.prompt.run({ prompt = "Add task: " },
67       mypromptbox[mouse.screen].widget,
68       function (...)
69           local f = io.popen("task add " .. ...)
70           c_text = "\n<span font='"
71                    .. task.font .. " "
72                    .. task.font_size .. "'>"
73                    .. f:read("*all")
74                    .. "</span>"
75           f:close()
76
77           naughty.notify({
78               text     = c_text,
79               icon     = task.notify_icon,
80               position = task.position,
81               fg       = task.fg,
82               bg       = task.bg,
83               timeout  = task.timeout,
84           })
85       end,
86       nil,
87       awful.util.getdir("cache") .. "/history_task_add")
88 end
89
90 function task:prompt_search()
91   awful.prompt.run({ prompt = "Search task: " },
92       mypromptbox[mouse.screen].widget,
93       function (...)
94           local f = io.popen("task " .. ...)
95           c_text = f:read("*all"):gsub(" \n*$", "")
96           f:close()
97
98           if string.len(c_text) == 0
99           then
100               c_text = "No results found."
101           else
102               c_text = "<span font='"
103                        .. task.font .. " "
104                        .. task.font_size .. "'>"
105                        .. c_text
106                        .. "</span>"
107           end
108
109           naughty.notify({
110               title    = "[task next " .. ... .. "]",
111               text     = c_text,
112               icon     = task.notify_icon,
113               position = task.position,
114               fg       = task.fg,
115               bg       = task.bg,
116               timeout  = task.timeout,
117               screen   = mouse.screen
118           })
119       end,
120       nil,
121       awful.util.getdir("cache") .. "/history_task")
122 end
123
124 function task:attach(widget, args)
125     local args       = args or {}
126
127     task.font_size   = tonumber(args.font_size) or 12
128     task.font        = beautiful.font:sub(beautiful.font:find(""),
129                        beautiful.font:find(" "))
130     task.fg          = args.fg or beautiful.fg_normal or "#FFFFFF"
131     task.bg          = args.bg or beautiful.bg_normal or "#FFFFFF"
132     task.position    = args.position or "top_right"
133     task.timeout     = args.timeout or 7
134     task.scr_pos     = args.scr_pos or 1
135     task.followmouse = args.followmouse or false
136
137     task.notify_icon = icons_dir .. "/taskwarrior/task.png"
138     task.notify_icon_small = icons_dir .. "/taskwarrior/tasksmall.png"
139
140     widget:connect_signal("mouse::enter", function () task:show(task.scr_pos) end)
141     widget:connect_signal("mouse::leave", function () task:hide() end)
142 end
143
144 return setmetatable(task, { __call = function(_, ...) return create(...) end })