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 $quassel_icons = "oxygen";
24 my $output = "oxygen_kde";
25 my $qrcfile_quassel = "oxygen.qrc";
26 my $qrcfile_kde = "oxygen_kde.qrc";
28 my $extrafile = "import/extra-icons";
29 my $blacklistfile = "import/blacklisted-icons";
44 # First, load the icon blacklist
45 # Format: icon-name 16 22 32
46 open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n";
49 next unless my ($name, $sizes) = /([-\w]+)\s+(\d+(?:\s+\d+)*)?/;
50 $blacklist{$name} = $sizes;
54 # We now grep the source for things like SmallIcon("fubar") and generate size and name from that
55 print "Grepping $source for requested icons...\n";
56 my @results = `grep -r Icon\\(\\" $source`;
58 next unless my ($type, $name) = /\W+(\s|Desktop|Bar|MainBar|Small|Panel|Dialog)Icon\("([-\w]+)/;
59 $type = "Desktop" if $type =~ /\s+/;
60 my $size = $sizes{$type};
61 $req_icons{$size}{$name} = 1
62 unless exists $blacklist{$name} and ($blacklist{$name} == undef or $blacklist{$name} =~ /$size/);
66 open EXTRA, "<$extrafile" or die "Could not open $extrafile\n";
69 next unless my ($name, $sizes) = /([-\w]+)\s+(\d+(?:\s+\d+)*)/;
70 foreach(split /\s+/, $sizes) {
71 $req_icons{$_}{$name} = 1;
76 # Clean old output dir
77 print "Removing old $output...\n";
78 system("rm -rf $output");
83 print "Copying icons from $oxygen...\n";
84 foreach my $size (keys %req_icons) {
85 my $sizestr = $size.'x'.$size;
86 opendir (BASEDIR, "$oxygen/$sizestr") or die "Could not open dir for size $size\n";
87 foreach my $cat (readdir BASEDIR) {
88 next if $cat eq '.' or $cat eq '..';
89 system "mkdir -p $output/$sizestr/$cat" and die "Could not create category dir\n";
90 system "mkdir -p $output/scalable/$cat" and die "Could not create category dir\n";
91 opendir (CATDIR, "$oxygen/$sizestr/$cat") or die "Could not open category dir\n";
92 foreach my $icon (readdir CATDIR) {
94 next unless exists $req_icons{$size}{$icon};
95 $scalables{"$cat/$icon"} = 1;
96 system "cp -a $oxygen/$sizestr/$cat/$icon.png $output/$sizestr/$cat"
97 and die "Error while copying file $sizestr/$cat/$icon.png\n";
98 # print "Copy: $oxygen/$sizestr/$cat/$icon.png\n";
99 delete $req_icons{$size}{$icon};
107 foreach my $scalable (keys %scalables) {
108 system "cp -a $oxygen/scalable/$scalable.svgz $output/scalable/$scalable.svgz";
111 # Warn if we have still icons left
112 foreach my $size (keys %req_icons) {
113 foreach my $missing (keys %{ $req_icons{$size} }) {
114 print "Warning: Missing icon $missing (size $size)\n";
120 generate_qrc($quassel_icons, $qrcfile_quassel);
121 generate_qrc($output, $qrcfile_kde);
125 ########################################################################################
131 find(\&push_icon_path, $dir);
132 my $files = join "\n", @file_list;
135 ." <qresource prefix=\"/icons\">\n"
140 open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n";
146 return unless /\.png$/;
147 my $alias = $File::Find::name;
148 $alias =~ s,^[^/]*(.*),$1,;
150 push @file_list, " <file alias=\"oxygen$alias\">$File::Find::name</file>";