3 # This script scans the Quassel source for requested icons and imports the needed
4 # icons (and only them) from a KDE theme (by default Oxygen).
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 whitelist-icons; you can also blacklist icons.
10 # NOTE: Unless you are a Quassel developer and need to bump the icons we ship, you shouldn't
11 # need to use this script!
13 # USAGE: ./import/import_theme.pl $systhemefolder $themename
14 # Run from the icon/ directory.
20 my $themefolder = shift;
22 my $source = "../src";
23 my $themename = shift;
24 $themename = $themename ? $themename : "oxygen";
25 my $qrcfile_kde = $themename . ".qrc";
27 my $whitelistfile = "import/whitelist-icons";
28 my $blacklistfile = "import/blacklisted-icons";
29 my $extrafile = "import/extra-icons.qrc." . $themename;
38 # First, load the icon blacklist
39 open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n";
42 next unless my ($name) = /([-\w]+)\s*/;
43 $blacklist{$name} = 1;
47 my $hasthemeblacklist = 1;
48 open BLACKLIST, "<$blacklistfile.$themename" or $hasthemeblacklist = 0;
49 if ($hasthemeblacklist) {
52 next unless my ($name) = /([-\w]+)\s*/;
53 $blacklist{$name} = 1;
54 $themeblacklist{$name} = 1;
58 print "Info: No theme specific blacklist found...\n";
61 # We now grep the source for things like SmallIcon("fubar") and generate size and name from that
62 print "Grepping $source for requested icons...\n";
63 my @results = `grep -r QIcon::fromTheme\\(\\" $source`;
65 next unless my ($name) = /\W+QIcon::fromTheme\(\"([-\w]+)/;
67 unless exists $blacklist{$name};
71 open WHITELIST, "<$whitelistfile" or die "Could not open $whitelistfile\n";
74 next unless my ($name) = /([-\w]+)\s*/;
76 unless exists $themeblacklist{$name};
81 my $hasthemeextrafile = 1;
83 open EXTRAFILE, "<$extrafile" or $hasthemeextrafile = 0;
84 if($hasthemeextrafile) {
86 $extrafilecontent = <EXTRAFILE>;
89 $extrafilecontent = "";
92 # Clean old output dir
93 print "Removing old $themename...\n";
94 system("rm -rf $themename");
99 print "Copying icons from $themefolder...\n";
100 opendir (BASEDIR, "$themefolder") or die "Could not open theme basedir\n";
101 my $scalableFound = 0;
102 foreach my $parent (readdir BASEDIR) {
103 next unless (-d "$themefolder/$parent");
104 $scalableFound = $scalableFound ? 1 : $parent eq 'scalable';
105 next if $parent eq '.' or $parent eq '..' or $parent eq 'scalable' or $parent =~ /\..*/;
106 my $ischildcat = $parent =~ /\d+x\d+/ ? 1 : 0;
107 opendir (SIZEDIR, "$themefolder/$parent") or die "Could not open dir $parent\n";
108 foreach my $child (readdir SIZEDIR) {
109 next if $child eq '.' or $child eq '..';
110 my $cat = $ischildcat ? $child : $parent;
111 opendir (CATDIR, "$themefolder/$parent/$child") or die "Could not open category dir\n";
112 foreach my $icon (readdir CATDIR) {
113 my $iconname = $icon;
114 $iconname =~ s/\.png$//;
115 $iconname =~ s/\.svg$//;
116 next unless exists $req_icons{$iconname};
117 $scalables{$cat}{$iconname} = 1;
118 system "mkdir -p $themename/$parent/$child" and die "Could not create category dir\n";
119 system "cp -aL $themefolder/$parent/$child/$icon $themename/$parent/$child"
120 and die "Error while copying file $parent/$child/$icon\n";
121 #print "Copy: $themefolder/$parent/$child/$icon\n";
122 $found_icons{$iconname} = 1;
131 if ($scalableFound) {
132 foreach my $cat (keys %scalables) {
133 system "mkdir -p $themename/scalable/$cat" and die "Could not create category dir\n";
134 foreach my $scalable (keys $scalables{$cat}) {
135 system "cp -aL $themefolder/scalable/$cat/$scalable.svgz $themename/scalable/$cat/$scalable.svgz";
140 # Warn if we have still icons left
141 foreach my $icon (keys %req_icons) {
142 next if defined $found_icons{$icon};
143 print "Warning: Missing icon $icon\n";
147 system "cp $themefolder/AUTHORS $themefolder/CONTRIBUTING $themefolder/COPYING $themefolder/index.theme $themename/";
151 generate_qrc($themename, $qrcfile_kde, $extrafilecontent);
155 ########################################################################################
161 find(\&push_icon_path, $dir);
162 @file_list = sort(@file_list );
163 my $files = join "\n", @file_list;
166 ." <qresource prefix=\"/icons\">\n"
168 ."$extrafilecontent\n"
172 open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n";
178 return unless /\.png$/ or /\.svg$/ or /^index.theme$/;
180 push @file_list, " <file>$File::Find::name</file>";