Signed-off-by: Julien Danjou <[email protected]>
---
 freedesktop/desktop.lua |    2 +-
 freedesktop/menu.lua    |    8 +++---
 freedesktop/utils.lua   |   57 ++++++++++++++--------------------------------
 3 files changed, 23 insertions(+), 44 deletions(-)

diff --git a/freedesktop/desktop.lua b/freedesktop/desktop.lua
index 254c446..7cb30cc 100644
--- a/freedesktop/desktop.lua
+++ b/freedesktop/desktop.lua
@@ -78,7 +78,7 @@ function add_desktop_icons(arg)
         if program.show then
             add_icon({
                 label = arg.showlabels and program.name or nil,
-                icon = program.icon,
+                icon = program.icon_path,
                 screen = arg.screen,
                 click = function () awful.util.spawn(program.cmdline) end
             })
diff --git a/freedesktop/menu.lua b/freedesktop/menu.lua
index ccdaa0b..2f77252 100644
--- a/freedesktop/menu.lua
+++ b/freedesktop/menu.lua
@@ -28,10 +28,10 @@ programs['Other'] = {}
 for i, program in ipairs(utils.parse_dir('/usr/share/applications/')) do
 
     -- check whether to include in the menu
-    if program.show and program.name and program.cmdline then
+    if program.show and program.Name and program.cmdline then
         local target_category = nil
-        if program.categories then
-            for category in string.gfind(program.categories, '[^;]+') do
+        if program.Categories then
+            for category in string.gfind(program.Categories, '[^;]+') do
                 if programs[category] then
                     target_category = category
                 end
@@ -40,7 +40,7 @@ for i, program in 
ipairs(utils.parse_dir('/usr/share/applications/')) do
             target_category = 'Other'
         end
         if target_category then
-            table.insert(programs[target_category], { program.name, 
program.cmdline, program.icon })
+            table.insert(programs[target_category], { program.Name, 
program.cmdline, program.icon })
         end
     end
 
diff --git a/freedesktop/utils.lua b/freedesktop/utils.lua
index 2696ec8..9afaf76 100644
--- a/freedesktop/utils.lua
+++ b/freedesktop/utils.lua
@@ -68,51 +68,30 @@ end
 function parse(file, icons_sizes)
     local program = { show = true, file = file }
     for line in io.lines(file) do
-        -- command line
-        if string.sub(line, 1, 5) == 'Exec=' then
-            program.exec = string.sub(line, 6, -1)
-        end
-
-        -- categories
-        if string.sub(line, 1, 11) == 'Categories=' then
-            program.categories = string.sub(line, 12, -1)
-        end
-
-        -- program name
-        if string.sub(line, 1, 5) == 'Name=' then
-            program.name = string.sub(line, 6, -1)
-        end
-
-        -- wheter to show the program or not
-        if string.sub(line, 1, 11) == 'OnlyShowIn=' then
-            program.show = false
-            for desktop in string.gfind(line, '[^;]+') do
-                if string.lower(desktop) == 'awesome' then
-                    program.show = true
-                end
-            end
+        for key, value in line:gmatch("(%w+)=(.+)") do
+            program[key] = value
         end
+    end
 
-        -- detect program icon
-        if string.sub(line, 1, 5) == 'Icon=' then
-            local icon = string.sub(line, 6, -1)
-            program.icon = lookup_icon({ icon = icon, icon_sizes = icon_sizes 
or all_icon_sizes })
-        end
+    -- Only show the program if there is not OnlyShowIn attribute
+    -- or if it's equal to 'awesome'
+    if program.OnlyShowIn ~= nil and program.OnlyShowIn ~= "awesome" then
+        program.show = false
+    end
 
-        -- detect programas that need a terminal
-        if line == 'Terminal=true' then
-            program.needs_terminal = true
-        end
+    -- Look up for a icon.
+    if program.Icon then
+        program.icon_path = lookup_icon({ icon = program.Icon, icon_sizes = 
all_icon_sizes })
     end
 
-    if program.exec then
-        local cmdline = string.gsub(program.exec, '%%c', program.name)
-        cmdline = string.gsub(cmdline, '%%[fuFU]', '')
-        cmdline = string.gsub(cmdline, '%%k', program.file)
-        if program.icon then
-            cmdline = string.gsub(cmdline, '%%i', '--icon ' .. program.icon)
+    if program.Exec then
+        local cmdline = program.Exec:gsub('%%c', program.Name)
+        cmdline = cmdline:gsub('%%[fuFU]', '')
+        cmdline = cmdline:gsub('%%k', program.file)
+        if program.icon_path then
+            cmdline = cmdline:gsub('%%i', '--icon ' .. program.icon_path)
         end
-        if program.needs_terminal then
+        if program.Terminal == "true" then
             cmdline = terminal .. ' -e ' .. cmdline
         end
         program.cmdline = cmdline
-- 
1.6.1.3


-- 
To unsubscribe, send mail to [email protected].

Reply via email to