diff options
Diffstat (limited to 'src/er_xdg_pipe_menu_desktop_entry.erl')
| -rw-r--r-- | src/er_xdg_pipe_menu_desktop_entry.erl | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/er_xdg_pipe_menu_desktop_entry.erl b/src/er_xdg_pipe_menu_desktop_entry.erl index bbd2594..9a71013 100644 --- a/src/er_xdg_pipe_menu_desktop_entry.erl +++ b/src/er_xdg_pipe_menu_desktop_entry.erl @@ -3,8 +3,9 @@ %% %% Reads the `[Desktop Entry]' group of a desktop entry file and %% extracts the fields needed to build a menu item: `Name', `Exec' -%% and (optionally) `Icon'. Other groups (e.g. `[Desktop Action ...]') -%% and localized keys (e.g. `Name[fr]') are ignored. +%% and (optionally) `Icon' and `Categories'. Other groups (e.g. +%% `[Desktop Action ...]') and localized keys (e.g. `Name[fr]') are +%% ignored. %% @end %%%------------------------------------------------------------------- @@ -16,7 +17,7 @@ -define(GROUP, <<"Desktop Entry">>). -define(WANTED_KEYS, [ - <<"Name">>, <<"Exec">>, <<"Icon">>, <<"NoDisplay">>, <<"Hidden">>, <<"Type">> + <<"Name">>, <<"Exec">>, <<"Icon">>, <<"Categories">>, <<"NoDisplay">>, <<"Hidden">>, <<"Type">> ]). -define(FIELD_CODES, "fFuUdDnNickvm"). @@ -99,11 +100,20 @@ to_entry(Fields) -> name = Name, exec = strip_field_codes(Exec), icon = maps:get(<<"Icon">>, Fields, undefined), + categories = parse_categories(maps:get(<<"Categories">>, Fields, undefined)), hidden = is_hidden(Fields) }} end end. +%% `Categories' is a `;'-separated list, conventionally with a +%% trailing separator (e.g. `Utility;Development;'); empty segments +%% from that trailing separator (or repeated ones) are dropped. +parse_categories(undefined) -> + []; +parse_categories(Bin) -> + [C || C <- binary:split(Bin, <<";">>, [global]), C =/= <<>>]. + %% Niche variations (e.g. a Type-less override dropped into %% ~/.local/share/applications) are left to be special-cased there %% rather than accounted for here. |
