Created
February 15, 2015 05:23
-
-
Save voldyman/8b6ad2bec7206a925fbc to your computer and use it in GitHub Desktop.
This program can be used to list all the desktop files that are detected when using a specific menu file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Author: Akshay Shekher | |
* | |
* build: valac --pkg gio-unix-2.0 --pkg libgnome-menu-3.0 -X -DGMENU_I_KNOW_THIS_IS_UNSTABLE applist.vala | |
* run: ./applist gnome-applications.menu | |
* or ./applist pantheon-applications.menu | |
*/ | |
int main(string[] args) { | |
if (args.length < 2) { | |
print ("Please specify the file to load\n"); | |
return 1; | |
} | |
var apps_menu = new GMenu.Tree(args[1], | |
GMenu.TreeFlags.INCLUDE_EXCLUDED); | |
try { | |
if (!apps_menu.load_sync ()) { | |
print ("Could not load menu"); | |
} | |
} catch (Error e) { | |
print ("Error loading menu file: %s", e.message); | |
return 0; | |
} | |
var iter = apps_menu.get_root_directory ().iter (); | |
assert (iter != null); | |
print ("Dir: %s\n", apps_menu.get_root_directory ().get_name ()); | |
process (iter); | |
return 0; | |
} | |
void process(GMenu.TreeIter iter) { | |
GMenu.TreeItemType type; | |
while((type = iter.next ()) != GMenu.TreeItemType.INVALID) { | |
switch (type) { | |
case GMenu.TreeItemType.ALIAS: | |
case GMenu.TreeItemType.ENTRY: | |
var entry = iter.get_entry (); | |
var appinfo = entry.get_app_info (); | |
var desktop_file = entry.get_desktop_file_path (); | |
print ("App: %s\nDesktop File: %s\n\n", appinfo.get_display_name (), | |
desktop_file); | |
break; | |
case GMenu.TreeItemType.DIRECTORY: | |
process (iter.get_directory ().iter ()); | |
break; | |
default: | |
print ("Some Other Type"); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment