1
namespace Slingshot.Backend {
3
public class GMenuEntries : GLib.Object {
5
public static Gee.ArrayList<GMenu.TreeDirectory> get_categories () {
6
var tree = GMenu.Tree.lookup ("applications.menu", GMenu.TreeFlags.INCLUDE_EXCLUDED);
7
var root = tree.get_root_directory ();
9
var main_directory_entries = new Gee.ArrayList<GMenu.TreeDirectory> ();
11
foreach (GMenu.TreeItem item in root.get_contents()) {
12
if (item.get_type() == GMenu.TreeItemType.DIRECTORY) {
13
main_directory_entries.add ((GMenu.TreeDirectory) item);
16
return main_directory_entries;
19
public static Gee.ArrayList<GMenu.TreeEntry> get_applications_for_category (GMenu.TreeDirectory category) {
20
var entries = new Gee.ArrayList<GMenu.TreeEntry> ();
22
foreach (GMenu.TreeItem item in category.get_contents ()) {
23
switch (item.get_type ()) {
24
case GMenu.TreeItemType.DIRECTORY:
25
entries.add_all (get_applications_for_category ((GMenu.TreeDirectory) item));
27
case GMenu.TreeItemType.ENTRY:
28
entries.add ((GMenu.TreeEntry) item);
35
public static Gee.ArrayList<GMenu.TreeEntry> get_all () {
36
var the_apps = new Gee.ArrayList<GMenu.TreeEntry> ();
38
var all_categories = get_categories ();
39
foreach (GMenu.TreeDirectory directory in all_categories) {
41
var this_category_apps = get_applications_for_category (directory);
43
foreach(GMenu.TreeEntry this_app in this_category_apps){
44
the_apps.add(this_app);
51
public static void enumerate_apps (Gee.ArrayList<GMenu.TreeEntry> source, Gee.HashMap<string, Gdk.Pixbuf> icons, int icon_size, out Gee.ArrayList<Gee.HashMap<string, string>> list) {
53
var icon_theme = Gtk.IconTheme.get_default();
54
list = new Gee.ArrayList<Gee.HashMap<string, string>> ();
56
foreach (GMenu.TreeEntry app in source) {
57
if (app.get_is_nodisplay() == false && app.get_is_excluded() == false && app.get_icon() != null) {
58
var app_to_add = new Gee.HashMap<string, string> ();
59
app_to_add["description"] = app.get_comment();
60
app_to_add["name"] = app.get_name();
61
app_to_add["command"] = app.get_exec();
62
app_to_add["desktop_file"] = app.get_desktop_file_path();
63
if (!icons.has_key(app_to_add["command"])) {
64
var app_icon = app.get_icon ();
65
if (icon_theme.has_icon (app_icon)) {
66
icons[app_to_add["command"]] = icon_theme.lookup_icon(app_icon, icon_size, 0).load_icon ();
67
} else if (GLib.File.new_for_path(app_icon).query_exists()) {
69
icons[app_to_add["command"]] = new Gdk.Pixbuf.from_file_at_scale (app_icon.to_string (), -1, icon_size, true);
72
icons[app_to_add["command"]] = icon_theme.lookup_icon("application-default-icon", icon_size, 0).load_icon ();
73
stdout.printf("Failed to load icon from file.\n");
76
icons[app_to_add["command"]] = icon_theme.lookup_icon("application-default-icon", icon_size, 0).load_icon ();
80
list.add (app_to_add);