#!/usr/bin/perl -w

=head1 NAME

dh_icons - Update Freedesktop icon caches

=cut

use strict;
use File::Find;
use Debian::Debhelper::Dh_Lib;

=head1 SYNOPSIS

B<dh_icons> [S<I<debhelper options>>] [B<-p<package>>]

=head1 DESCRIPTION

dh_icons is a debhelper program that updates Freedesktop icon caches
when needed, using the gtk-update-icon-cache program provided by GTK+2.0.
Currently this program does not handle installation of the files, though it
may do so at a later date. It takes care of adding maintainer script
fragments to call F<gtk-update-icon-cache>.

=cut

init();

foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmp=tmpdir($package);
	my $icondir="$tmp/usr/share/icons";
	if (-d $icondir) {
		my $dirlist = "";
		opendir(DIRHANDLE, $icondir);
		while (my $subdir = readdir(DIRHANDLE)) {
			next if $subdir =~ /^\./;
			my $needs_cache = "0";
			find sub {
				$needs_cache = "1" if (-f and (/\.png$/ or /\.svg$/ or /\.jpg$/));
			}, "$icondir/$subdir" ;
			$dirlist = "$dirlist $subdir" if ($needs_cache eq "1");
		}
		if ($dirlist ne "" and not $dh{NOSCRIPTS}) {
			autoscript($package,"postinst","postinst-icons","s%#DIRLIST#%$dirlist%");
			autoscript($package,"prerm","prerm-icons","s%#DIRLIST#%$dirlist%");
			autoscript($package,"postrm","postrm-icons","s%#DIRLIST#%$dirlist%");
		}
	}
}

=head1 SEE ALSO

L<debhelper>

This program is a part of debhelper.

=head1 AUTHOR

Ross Burton <ross@burtonini.com>
Jordi Mallach <jordi@debian.org>
Josselin Mouette <joss@debian.org>

=cut
