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";
43 # First, load the icon blacklist
44 open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n";
47 next unless my ($name) = /([-\w]+)\s*/;
48 $blacklist{$name} = 1;
52 my $hasthemeblacklist = 1;
53 open BLACKLIST, "<$blacklistfile.$themename" or $hasthemeblacklist = 0;
54 if ($hasthemeblacklist) {
57 next unless my ($name) = /([-\w]+)\s*/;
58 $blacklist{$name} = 1;
59 $themeblacklist{$name} = 1;
63 print "Info: No theme specific blacklist found...\n";
66 # We now grep the source for things like SmallIcon("fubar") and generate size and name from that
67 print "Grepping $source for requested icons...\n";
68 my @results = `grep -r QIcon::fromTheme\\(\\" $source`;
70 next unless my ($name) = /\W+QIcon::fromTheme\(\"([-\w]+)/;
72 unless exists $blacklist{$name};
76 open WHITELIST, "<$whitelistfile" or die "Could not open $whitelistfile\n";
79 next unless my ($name) = /([-\w]+)\s*/;
81 unless exists $themeblacklist{$name};
85 # Clean old output dir
86 print "Removing old $themename...\n";
87 system("rm -rf $themename");
92 print "Copying icons from $themefolder...\n";
93 opendir (BASEDIR, "$themefolder") or die "Could not open theme basedir\n";
94 my $scalableFound = 0;
95 foreach my $parent (readdir BASEDIR) {
96 next unless (-d "$themefolder/$parent");
97 $scalableFound = $scalableFound ? 1 : $parent eq 'scalable';
98 next if $parent eq '.' or $parent eq '..' or $parent eq 'scalable' or $parent =~ /\..*/;
99 my $ischildcat = $parent =~ /\d+x\d+/ ? 1 : 0;
100 opendir (SIZEDIR, "$themefolder/$parent") or die "Could not open dir $parent\n";
101 foreach my $child (readdir SIZEDIR) {
102 next if $child eq '.' or $child eq '..';
103 my $cat = $ischildcat ? $child : $parent;
104 opendir (CATDIR, "$themefolder/$parent/$child") or die "Could not open category dir\n";
105 foreach my $icon (readdir CATDIR) {
106 my $iconname = $icon;
107 $iconname =~ s/\.png$//;
108 $iconname =~ s/\.svg$//;
109 next unless exists $req_icons{$iconname};
110 $scalables{$cat}{$iconname} = 1;
111 system "mkdir -p $themename/$parent/$child" and die "Could not create category dir\n";
112 system "cp -aL $themefolder/$parent/$child/$icon $themename/$parent/$child"
113 and die "Error while copying file $parent/$child/$icon\n";
114 #print "Copy: $themefolder/$parent/$child/$icon\n";
115 $found_icons{$iconname} = 1;
124 if ($scalableFound) {
125 foreach my $cat (keys %scalables) {
126 system "mkdir -p $themename/scalable/$cat" and die "Could not create category dir\n";
127 foreach my $scalable (keys %{$scalables{$cat}}) {
128 system "cp -aL $themefolder/scalable/$cat/$scalable.svgz $themename/scalable/$cat/$scalable.svgz";
133 # Warn if we have still icons left
134 foreach my $icon (keys %req_icons) {
135 next if defined $found_icons{$icon};
136 print "Warning: Missing icon $icon\n";
140 system "cp $themefolder/AUTHORS $themefolder/CONTRIBUTING $themefolder/COPYING* $themefolder/index.theme $themename/";
142 if($parentFolderFileSuffix) {
143 system "cp $themefolder/../AUTHORS*$parentFolderFileSuffix $themefolder/../CONTRIBUTING*$parentFolderFileSuffix $themefolder/../COPYING*$parentFolderFileSuffix $themename/";
148 generate_qrc($themename, $qrcfile_kde, $extrafilecontent);
152 ########################################################################################
158 find(\&push_icon_path, $dir);
159 @file_list = sort(@file_list );
160 my $files = join "\n", @file_list;
163 ." <qresource prefix=\"/icons\">\n"
168 open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n";
174 return unless /\.png$/ or /\.svg$/ or /^index.theme$/;
176 push @file_list, " <file>$File::Find::name</file>";