SVN: vfmg/trunk/VFMG/Icons.pm
sparky
sparky at pld-linux.org
Sat Dec 2 22:06:10 CET 2006
Author: sparky
Date: Sat Dec 2 22:06:10 2006
New Revision: 8040
Added:
vfmg/trunk/VFMG/Icons.pm (contents, props changed)
Log:
- icon manipulation, NFY
Added: vfmg/trunk/VFMG/Icons.pm
==============================================================================
--- (empty file)
+++ vfmg/trunk/VFMG/Icons.pm Sat Dec 2 22:06:10 2006
@@ -0,0 +1,69 @@
+package VFMG::Icons;
+
+use strict;
+use warnings;
+
+our $scale_icon;
+
+my @scale;
+sub scale_icon {
+ my $icon_in = $_[0];
+ return $icon_in unless -r $icon_in;
+
+ $icon_in =~ m#^(.*/)?(.*?)(\.[^\.]*)?$#;
+ my $icon_out = "$main::opt{icons_dir}/$2.$main::opt{icons_oext}";
+
+ unless (-f $icon_out) {
+ $_ = $main::opt{convert};
+ s/\%in/$icon_in/g;
+ s/\%out/$icon_out/g;
+
+ if ( $main::opt{icons_fork} ) {
+ push @scale, $_;
+ } else {
+ system($_);
+ }
+ }
+ return $icon_out;
+}
+
+sub init {
+ warn "Icons init called";
+ unless ($main::opt{icons}) {
+ $scale_icon = sub { return "" };
+ return;
+ }
+ unless ($main::opt{icons_scale}) {
+ $scale_icon = sub { return $_[0] };
+ return;
+ }
+ $scale_icon = \&scale_icon;
+
+ return unless not -d $main::opt{icons_dir} or $main::opt{full_regen};
+ warn "Need to (re)generate all icons.\n";
+ require File::Path;
+ import File::Path qw(mkpath rmtree);
+ rmtree($main::opt{icons_dir}.".old",0,0)
+ if -e $main::opt{icons_dir}.".old";
+ rename($main::opt{icons_dir},$main::opt{icons_dir}.".old")
+ if -e $main::opt{icons_dir};
+ mkpath($main::opt{icons_dir},0,0700);
+}
+
+sub do_fork {
+ return unless scalar @scale;
+
+ warn "Scaling $#scale icons\n";
+ my $fork = fork;
+ unless ( defined $fork ) {
+ warn "Fork failed, scaling in foreground\n";
+ $fork = 0;
+ }
+ return if $fork != 0;
+
+ foreach my $cmd (@scale) {
+ system($cmd);
+ }
+}
+
+1;
More information about the pld-cvs-commit
mailing list