FreeDesktop-Icons
view release on metacpan or search on metacpan
lib/FreeDesktop/Icons.pm view on Meta::CPAN
use warnings;
use Carp;
use vars qw($VERSION);
$VERSION="0.04";
use Config;
my $mswin = $Config{'osname'} eq 'MSWin32';
use File::Basename;
my @extensions = (
'.jpg',
'.jpeg',
'.png',
'.gif',
'.xbm',
'.xpm',
'.svg',
);
my %regsubs = (
1 => sub { return shift },
2 => sub {
my $test = shift;
$test =~ s/\-/_/g;
return $test;
},
3 => sub {
my $test = shift;
$test =~ s/\-//g;
return $test;
},
);
my @defaulticonpath = ();
if ($mswin) {
push @defaulticonpath, $ENV{ALLUSERSPROFILE} . '\Icons'
} else {
my $local = $ENV{HOME} . '/.local/share/icons';
push @defaulticonpath, $local if -e $local;
my $xdgpath = $ENV{XDG_DATA_DIRS};
if (defined $xdgpath) {
my @xdgdirs = split /\:/, $xdgpath;
for (@xdgdirs) {
push @defaulticonpath, "$_/icons";
}
}
}
=head1 SYNOPSIS
my $iconlib = new FreeDeskTop::Icons;
$iconlib->theme('Oxygen');
$iconlib->size('16');
my $imagefile = $iconlib->get('edit-copy');
=head1 DESCRIPTION
This module gives access to icon libraries on your system. It more
ore less conforms to the Free Desktop specifications here:
L<https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html>
Furthermore it allows you to add your own icon folders through the B<rawpath> method.
We have made provisions to make it work on Windows as well.
The constructor takes a list of folders where it finds the icons
libraries. If you specify nothing, it will assign default values for:
Windows: $ENV{ALLUSERSPROFILE} . '\Icons'. This package will not create
the folder if it does not exist. See also the README.md included in this distribution.
Others: $ENV{HOME} . '/.local/share/icons', and the folder 'icons' in $ENV{XDG_DATA_DIRS}.
=head1 METHODS
=over 4
=cut
sub new {
my $class = shift;
my $self = { };
bless $self, $class;
$self->{CONTEXT} = undef;
$self->{ICONSIZE} = undef;
$self->{THEME} = undef;
$self->{THEMEPOOL} = {};
$self->{THEMES} = {};
$self->{RAWPATH} = [];
$self->{SIZE} = undef;
my @iconpath = @_;
@iconpath = @defaulticonpath unless @iconpath;
$self->CollectThemes(@iconpath);
return $self;
}
=item B<availableContexts>I<($theme, >[ I<$name, $size> ] I<);>
Returns a list of available contexts. If you set $name to undef if will return
all contexts of size $size. If you set $size to undef it will return all
contexts associated with icon $name. If you set $name and $size to undef it
will return all known contexts in the theme. out $size it returns a list
of all contexts found in $theme.
=cut
sub availableContexts {
my ($self, $theme, $name, $size) = @_;
my $t = $self->getTheme($theme);
my %found = ();
if ((not defined $name) and (not defined $size)) {
my @names = keys %$t;
for (@names) {
my $si = $t->{$_};
my @sizes = keys %$si;
for (@sizes) {
( run in 2.733 seconds using v1.01-cache-2.11-cpan-2398b32b56e )