3 # This script scans the Quassel source for requested icons and imports the needed
4 # icons (and only them) from KDE's Oxygen theme.
5 # This relies on all icons being requested using one of the convenience constructors in
6 # (K)IconLoader, like this:
7 # widget->setIcon(SmallIcon("fubar"));
8 # Additional icons can be specified in extra-icons; you can also blacklist icons.
10 # NOTE: Unless you are a Quassel developer and need to bump the icons we ship, you shouldn'y
11 # need to use this script!
13 # USAGE: ./import/import_oxygen.pl $systhemefolder
14 # Run from the icon/ directory.
22 my $source = "../src";
23 my $skeleton = "oxygen_quassel";
24 my $output = "oxygen";
25 my $qrcfile = "oxygen.qrc";
27 my $extrafile = "import/extra-icons";
28 my $blacklistfile = "import/blacklisted-icons";
43 # First, load the icon blacklist
44 # Format: icon-name 16 22 32
45 open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n";
48 next unless my ($name, $sizes) = /([-\w]+)\s+(\d+(?:\s+\d+)*)?/;
49 $blacklist{$name} = $sizes;
53 # We now grep the source for things like SmallIcon("fubar") and generate size and name from that
54 print "Grepping $source for requested icons...\n";
55 my @results = `grep -r Icon\\(\\" $source`;
57 next unless my ($type, $name) = /\W+(\s|Desktop|Bar|MainBar|Small|Panel|Dialog)Icon\("([-\w]+)/;
58 $type = "Desktop" if $type =~ /\s+/;
59 my $size = $sizes{$type};
60 $req_icons{$size}{$name} = 1
61 unless exists $blacklist{$name} and ($blacklist{$name} == undef or $blacklist{$name} =~ /$size/);
65 open EXTRA, "<$extrafile" or die "Could not open $extrafile\n";
68 next unless my ($name, $sizes) = /([-\w]+)\s+(\d+(?:\s+\d+)*)/;
69 foreach(split /\s+/, $sizes) {
70 $req_icons{$_}{$name} = 1;
75 # Clean old output dir
76 print "Removing old $output...\n";
77 system("rm -rf $output");
79 print "Copying skeleton from $skeleton...\n";
80 system("cp -a $skeleton $output");
85 print "Copying icons from $oxygen...\n";
86 foreach my $size (keys %req_icons) {
87 my $sizestr = $size.'x'.$size;
88 opendir (BASEDIR, "$oxygen/$sizestr") or die "Could not open dir for size $size\n";
89 foreach my $cat (readdir BASEDIR) {
90 next if $cat eq '.' or $cat eq '..';
91 system "mkdir -p $output/$sizestr/$cat" and die "Could not create category dir\n";
92 system "mkdir -p $output/scalable/$cat" and die "Could not create category dir\n";
93 opendir (CATDIR, "$oxygen/$sizestr/$cat") or die "Could not open category dir\n";
94 foreach my $icon (readdir CATDIR) {
96 next unless exists $req_icons{$size}{$icon};
97 $scalables{"$cat/$icon"} = 1;
98 system "cp -a $oxygen/$sizestr/$cat/$icon.png $output/$sizestr/$cat"
99 and die "Error while copying file $sizestr/$cat/$icon.png\n";
100 # print "Copy: $oxygen/$sizestr/$cat/$icon.png\n";
101 delete $req_icons{$size}{$icon};
109 foreach my $scalable (keys %scalables) {
110 system "cp -a $oxygen/scalable/$scalable.svgz $output/scalable/$scalable.svgz";
113 # Warn if we have still icons left
114 foreach my $size (keys %req_icons) {
115 foreach my $missing (keys %{ $req_icons{$size} }) {
116 print "Warning: Missing icon $missing (size $size)\n";
122 find(\&push_icon_path, $output);
125 return unless /\.png$/;
126 push @file_list, " <file>$File::Find::name</file>";
129 my $files = join "\n", @file_list;
132 ." <qresource prefix=\"/icons\">\n"
137 open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n";