3
class MenuDir : Object {
4
public string id { get; set; }
5
public string name { get; set; }
6
public string icon { get; set; }
7
public string directory { get; set; }
8
public string[] included;
9
public string[] excluded;
12
public void complete (KeyFile file) {
14
file.load_from_file ("/usr/share/desktop-directories/%s".printf (directory), 0);
15
name = file.get_string ("Desktop Entry", "Name");
16
icon = file.get_string ("Desktop Entry", "Icon");
18
GLib.debug ("Error retrieving datas for %s: %s\n", directory, e.message);
29
private const MarkupParser parser = {
30
opening_item,// when an element opens
31
closing_item, // when an element closes
32
get_text, // when text is found
33
null, // when comments are found
34
null // when errors occur
37
private string menu_file;
38
private MarkupParseContext context;
39
private MenuDir[] dirlist;
41
private int level = 0;
42
private string last_item;
43
private bool include = true;
46
public MenuDir[] parse () {
48
FileUtils.get_contents (menu_file, out file, null);
49
context.parse (file, file.length);
54
public MenuParser (string menu_file) {
55
context = new MarkupParseContext(
56
parser, // the structure with the callbacks
57
0, // MarkupParseFlags
58
this, // extra argument for the callbacks, methods in this case
59
null // when the parsing ends
63
this.menu_file = menu_file;
67
void opening_item (MarkupParseContext context, string name, string[] attr, string[] vals) throws MarkupError {
82
void closing_item (MarkupParseContext context, string name) throws MarkupError {
94
private bool check_whitespaces (string str) {
95
return (str.strip() == "" ? true : false);
98
void get_text (MarkupParseContext context, string text, size_t text_len) throws MarkupError {
99
if (check_whitespaces (text)) { return; }
106
dir.directory = text;
110
dir.included += text;
112
dir.excluded += text;