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 $parentFolderFileSuffix
14 # Run from the icon/ directory.
16 # Examples: (being inside the icons folder)
17 # ./import/import_theme.pl ~/oxygen-icons oxygen
18 # ./import/import_theme.pl ~/breeze-icons/icons breeze ICONS
19 # ./import/import_theme.pl ~/breeze-icons/icons-dark breezedark ICONS
26 my $themefolder = shift;
28 my $source = "../src";
29 my $themename = shift;
30 $themename = $themename ? $themename : "oxygen";
31 my $qrcfile_kde = $themename . ".qrc";
32 my $parentFolderFileSuffix = shift;
34 my $whitelistfile = "import/whitelist-icons";
35 my $blacklistfile = "import/blacklisted-icons";
36 my $extrafile = "import/extra-icons.qrc." . $themename;
45 # First, load the icon blacklist
46 open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n";
49 next unless my ($name) = /([-\w]+)\s*/;
50 $blacklist{$name} = 1;
54 my $hasthemeblacklist = 1;
55 open BLACKLIST, "<$blacklistfile.$themename" or $hasthemeblacklist = 0;
56 if ($hasthemeblacklist) {
59 next unless my ($name) = /([-\w]+)\s*/;
60 $blacklist{$name} = 1;
61 $themeblacklist{$name} = 1;
65 print "Info: No theme specific blacklist found...\n";
68 # We now grep the source for things like SmallIcon("fubar") and generate size and name from that
69 print "Grepping $source for requested icons...\n";
70 my @results = `grep -r QIcon::fromTheme\\(\\" $source`;
72 next unless my ($name) = /\W+QIcon::fromTheme\(\"([-\w]+)/;
74 unless exists $blacklist{$name};
78 open WHITELIST, "<$whitelistfile" or die "Could not open $whitelistfile\n";
81 next unless my ($name) = /([-\w]+)\s*/;
83 unless exists $themeblacklist{$name};
88 my $hasthemeextrafile = 1;
90 open EXTRAFILE, "<$extrafile" or $hasthemeextrafile = 0;
91 if($hasthemeextrafile) {
93 $extrafilecontent = <EXTRAFILE>;
96 $extrafilecontent = "";
99 # Clean old output dir
100 print "Removing old $themename...\n";
101 system("rm -rf $themename");
106 print "Copying icons from $themefolder...\n";
107 opendir (BASEDIR, "$themefolder") or die "Could not open theme basedir\n";
108 my $scalableFound = 0;
109 foreach my $parent (readdir BASEDIR) {
110 next unless (-d "$themefolder/$parent");
111 $scalableFound = $scalableFound ? 1 : $parent eq 'scalable';
112 next if $parent eq '.' or $parent eq '..' or $parent eq 'scalable' or $parent =~ /\..*/;
113 my $ischildcat = $parent =~ /\d+x\d+/ ? 1 : 0;
114 opendir (SIZEDIR, "$themefolder/$parent") or die "Could not open dir $parent\n";
115 foreach my $child (readdir SIZEDIR) {
116 next if $child eq '.' or $child eq '..';
117 my $cat = $ischildcat ? $child : $parent;
118 opendir (CATDIR, "$themefolder/$parent/$child") or die "Could not open category dir\n";
119 foreach my $icon (readdir CATDIR) {
120 my $iconname = $icon;
121 $iconname =~ s/\.png$//;
122 $iconname =~ s/\.svg$//;
123 next unless exists $req_icons{$iconname};
124 $scalables{$cat}{$iconname} = 1;
125 system "mkdir -p $themename/$parent/$child" and die "Could not create category dir\n";
126 system "cp -aL $themefolder/$parent/$child/$icon $themename/$parent/$child"
127 and die "Error while copying file $parent/$child/$icon\n";
128 #print "Copy: $themefolder/$parent/$child/$icon\n";
129 $found_icons{$iconname} = 1;
138 if ($scalableFound) {
139 foreach my $cat (keys %scalables) {
140 system "mkdir -p $themename/scalable/$cat" and die "Could not create category dir\n";
141 foreach my $scalable (keys %{$scalables{$cat}}) {
142 system "cp -aL $themefolder/scalable/$cat/$scalable.svgz $themename/scalable/$cat/$scalable.svgz";
147 # Warn if we have still icons left
148 foreach my $icon (keys %req_icons) {
149 next if defined $found_icons{$icon};
150 print "Warning: Missing icon $icon\n";
154 system "cp $themefolder/AUTHORS $themefolder/CONTRIBUTING $themefolder/COPYING* $themefolder/index.theme $themename/";
156 if($parentFolderFileSuffix) {
157 system "cp $themefolder/../AUTHORS*$parentFolderFileSuffix $themefolder/../CONTRIBUTING*$parentFolderFileSuffix $themefolder/../COPYING*$parentFolderFileSuffix $themename/";
162 generate_qrc($themename, $qrcfile_kde, $extrafilecontent);
166 ########################################################################################
172 find(\&push_icon_path, $dir);
173 @file_list = sort(@file_list );
174 my $files = join "\n", @file_list;
177 ." <qresource prefix=\"/icons\">\n"
179 ."$extrafilecontent\n"
183 open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n";
189 return unless /\.png$/ or /\.svg$/ or /^index.theme$/;
191 push @file_list, " <file>$File::Find::name</file>";