3 # This script scans the Quassel source for required icons and imports the needed
4 # icons (and only them) from a full icon theme.
5 # Additional icons can be specified in whitelisted-icons; you can also blacklist icons.
7 # NOTE: Unless you are a Quassel developer and need to bump the icons we ship, you shouldn't
8 # need to use this script!
10 # USAGE: ./import/import_theme.pl $srcthemedir $themename
13 # import_theme.pl ~/oxygen-icons oxygen
14 # import_theme.pl ~/breeze-icons/icons breeze
15 # import_theme.pl ~/breeze-icons/icons-dark breeze-dark
24 my $scriptroot = File::Basename::dirname(File::Spec->rel2abs($0));
25 my $srcroot = File::Spec->catdir($scriptroot, "..", "..");
26 my $srcdir = File::Spec->catdir($srcroot, "src");
28 my $srcthemedir = shift;
29 my $themename = shift;
32 die "Theme directory must be given\n" unless length $srcthemedir;
33 die "Theme directory \"$srcthemedir\" not found\n" unless -e $srcthemedir and -d $srcthemedir;
34 die "Theme name must not be empty\n" unless length $themename;
36 my $destbasedir = File::Spec->catdir($srcroot, "3rdparty", "icons");
37 my $destthemedir = File::Spec->catdir($destbasedir, $themename);
39 my $whitelistfile = "$scriptroot/whitelisted-icons";
40 my $blacklistfile = "$scriptroot/blacklisted-icons";
47 # Add whitelisted icons
48 open WHITELIST, "<$whitelistfile" or die "Could not open $whitelistfile\n";
51 next unless my ($name) = /([-\w]+)\s*/;
52 $req_icons{$name} = 1;
56 # Load the icon blacklist
57 open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n";
60 next unless my ($name) = /([-\w]+)\s*/;
61 $blacklist{$name} = 1;
65 # We now grep the source for icon::get() to find required icons
66 print "Grepping $srcdir for required icons...\n";
67 my @results = `grep -r icon::get $srcdir`;
69 next unless my (@names) = /\W+icon::get\((?:\"([-\w]+)\")|(?:\{\s*\"([-\w]+)\"(?:,\s*\"([-\w]+)\")*\s*\})/;
71 $req_icons{$_} = 1 unless not defined or exists $blacklist{$_};
75 # Clean old output dir
76 print "Removing old $destthemedir...\n";
77 system("rm -rf $destthemedir");
82 print "Copying icons from $srcthemedir...\n";
83 opendir (BASEDIR, "$srcthemedir") or die "Could not open theme basedir\n";
84 my $scalableFound = 0;
85 foreach my $parent (readdir BASEDIR) {
86 next unless (-d "$srcthemedir/$parent");
87 $scalableFound = $scalableFound ? 1 : $parent eq 'scalable';
88 next if $parent eq '.' or $parent eq '..' or $parent eq 'scalable' or $parent =~ /\..*/;
89 my $ischildcat = $parent =~ /\d+x\d+/ ? 1 : 0;
90 opendir (SIZEDIR, "$srcthemedir/$parent") or die "Could not open dir $parent\n";
91 foreach my $child (readdir SIZEDIR) {
92 next if $child eq '.' or $child eq '..';
93 my $cat = $ischildcat ? $child : $parent;
94 opendir (CATDIR, "$srcthemedir/$parent/$child") or die "Could not open category dir\n";
95 foreach my $icon (readdir CATDIR) {
97 $iconname =~ s/\.png$//;
98 $iconname =~ s/\.svg$//;
99 next unless exists $req_icons{$iconname};
100 $scalables{$cat}{$iconname} = 1;
101 system "mkdir -p $destthemedir/$parent/$child" and die "Could not create category dir\n";
102 system "cp -aL $srcthemedir/$parent/$child/$icon $destthemedir/$parent/$child"
103 and die "Error while copying file $parent/$child/$icon\n";
104 print "Copy: $srcthemedir/$parent/$child/$icon\n";
105 $found_icons{$iconname} = 1;
114 if ($scalableFound) {
115 foreach my $cat (keys %scalables) {
116 system "mkdir -p $destthemedir/scalable/$cat" and die "Could not create category dir\n";
117 foreach my $scalable (keys %{$scalables{$cat}}) {
118 system "cp -aL $srcthemedir/scalable/$cat/$scalable.svgz $destthemedir/scalable/$cat/$scalable.svgz";
123 # Warn if we have still icons left
124 foreach my $icon (keys %req_icons) {
125 next if defined $found_icons{$icon};
126 print "Warning: Missing icon $icon\n";
130 system "cp -aL $srcthemedir/AUTHORS* $srcthemedir/CONTRIBUTING* $srcthemedir/COPYING* $srcthemedir/index.theme $destthemedir/ | true";
133 #my $qrcfile = $themename."_icon_theme.qrc";
134 #$qrcfile =~ s/-/_/g;
135 my $qrcfile = File::Spec->catdir($destbasedir, ($themename."_icon_theme.qrc") =~ s/-/_/gr);
136 print "Generating $qrcfile...\n";
141 return unless /\.png$/ or /\.svg$/ or /^index.theme$/;
142 push @file_list, " <file>".$File::Find::name =~ s|^$destbasedir/||gr."</file>";
145 find(\&push_icon_path, $destthemedir);
146 @file_list = sort(@file_list);
147 my $files = join "\n", @file_list;
150 ." <qresource prefix=\"/icons\">\n"
155 open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n";