NAME
Linux::DesktopFiles - Get and parse the Linux .desktop files.
SYNOPSIS
use Linux::DesktopFiles;
my $obj = Linux::DesktopFiles->new( terminalize => 1 );
print join "\n", $obj->get_desktop_files;
my $hash_ref = $obj->parse_desktop_files;
DESCRIPTION
The Linux::DesktopFiles
is a very simple module to parse .desktop files.
CONSTRUCTOR METHODS
The following constructor methods are available:
- $obj = Linux::DesktopFiles->new( %options )
-
This method constructs a new
Linux::DesktopFiles
object and returns it. Key/value pair arguments may be provided to set up the initial state. The following options correspond to attribute methods described below:KEY DEFAULT ----------- -------------------- with_icons 0 full_icon_paths 0 skip_svg_icons 0 icon_db_filename undef icon_dirs_first undef icon_dirs_second undef icon_dirs_last undef categories_case_sensitive 0 keep_empty_categories 0 use_only_my_icon_dirs 0 use_current_theme_icons 0/1 terminalize 0 terminal $ENV{TERM} home_dir $ENV{HOME} gtk_rc_filename "~/.gtkrc-2.0" true_value ['true', 'True', '1'] skip_file_name_re undef skip_app_name_re undef skip_app_command_re undef skip_file_content_re undef clean_command_name_re undef desktop_files_paths ['/usr/share/applications'] keys_to_keep ["Name", "Exec"] categories [qw( utility development education game graphics audiovideo network office settings system ) ]
Main options
- desktop_files_paths => ['dir1', 'dir2', ...]
-
Set directories where to find the .desktop files (default: /usr/share/applications)
- keys_to_keep => [qw(Icon Exec Name Comment ...)]
-
Any of the valid keys from .desktop files. This keys will be stored in the retured hash reference when calling
$obj->parse_desktop_files
. - categories => [qw(Graphics Network AudioVideo ...)]
-
Any of the valid categories from the .desktop files. Any category not listed, will be ignored.
Other options
- keep_empty_categories => 1
-
If a category is empty, keep it in the returned hash reference when parse_desktop_files is called.
- categories_case_sensitive => 1
-
Make categories case sensitive. By default, they are case insensitive in a way that "X-XFCE4" is equivalent to "x_xfce4".
- terminalize => 1
-
When Terminal is true, modify the Exec value to something like: terminal -e 'command'
- terminal => "xterm"
-
This terminal will be used when terminalize is set to a true value.
- home_dir => "/home/dir"
-
Set the home directory. This value is used to locate icons in the ~/.local/share/icons.
- gtk_rc_filename => "/path/to/.gtkrc-x.x"
-
This file is used to get the icon theme name from it. (default: ~/.gtkrc-2.0) NOTE: It works with Gtk3 as well.
- true_value => [qw(1 true True)]
-
This values are used to test for true some values from the .desktop files.
Icon options
- with_icons => 1
-
Require icons. Unless full_icon_paths is set to a true value, this option will return icon names without the extension. If an Icon value is an absolute path to an icon in the system, it will be returned as it is.
- full_icon_paths => 1
-
Full icon paths for Icon values.
- icon_db_filename => "filename.db"
-
GDBM database name used to store icon names as keys and icon paths as values for a faster lookup (used with GDBM_File). NOTE: Works in combination with full_icon_paths and with_icons
- skip_svg_icons => 1
-
Ignore .svg icons when looking for full icon paths.
- icon_dirs_first => [dir1, dir2, ...]
-
When looking for full icon paths, look in this directories first, before looking in the directories of the current icon theme.
- icon_dirs_second => [dir1, dir2, ...]
-
When looking for full icon paths, look in this directories as a second icon theme. (Before /usr/share/pixmaps)
- icon_dirs_last => [dir1, dir2, ...]
-
Look in this directories at the very last, after looked in /usr/share/pixmaps, /usr/share/icons/hicolor and some other directories.
- use_only_my_icon_dirs => 1
-
Be very strict and use only the directories specified by you in either one of icon_dirs_first, icon_dirs_second and/or icon_dirs_last
- use_current_theme_icons => 1
-
Use your current theme icons (from ~/.gtkrc-2.0), even when use_only_my_icon_dirs is set to a true value. This option is useful when you want to get only the icons from the current theme. It is usually used in combination with use_only_my_icon_dirs. When use_only_my_icon_dirs is set a false value, this option is true by default. When use_only_my_icon_dirs is set a true value, this option is false by default.
Regex options
- skip_file_name_re => qr/regex/
-
Skip .desktop files if their file names will match the regex. NOTE: File names are from the last slash to the end.
- skip_app_name_re => qr/regex/
-
Skip .desktop files based on the value of Name.
- skip_app_command_re => qr/regex/
-
Skip .desktop files based on the value of Exec.
- skip_file_content_re => qr/regex/
-
Skip .desktop files if the regex matches anywhere in the [Desktop Entry] section.
- clean_command_name_re => qr/regex/
-
Anything matched by this regex in the values of Exec will be replaced with nothing.
SUBROUTINES/METHODS
- $obj->iterate_desktop_files(\&code_ref)
-
Iterate over desktop files, one file at a time.
- $obj->get_desktop_files()
-
Get all desktop files. In list context it returns a list, but in scalar context, it returns an array reference containing the full names of the desktop files.
- $obj->get_icon_theme_name()
-
Returns the icon theme name, if any, otherwise it returns an empty string.
- $obj->get_icon_path("icon_name")
-
If full_icon_paths is set to a true value, it returns the absolute path of a icon name located in the system. If it can't found the icon name, it returns an empty string. If full_icon_paths is set to a false value, it strips the extension name of the icon (if any), and returns the icon name. If the icon name is undefined, it returns an empty string.
- $obj->parse_desktop_file("filename")
-
It returns a HASH reference which contains the keys_to_keep and the values from the desktop file specified as an argument.
- $obj->parse_desktop_files()
-
It returns a HASH reference which categories names as keys, and ARRAY references as values which contains HASH references with the keys specified in the keys_to_keep option, and values from the .desktop files.
The returned HASH reference might look something like this:
{ utility => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => "..."} ], network => [ {Exec => "...", Name => "..."}, {Exec => "...", Name => "..."} ], }
AUTHOR
Suteu "Trizen" Daniel, <trizenx@gmail.com>
COPYRIGHT AND LICENSE
Copyright (C) 2012-2013
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.