From 07cf86c7a797ebee26050e604509381107bff81f Mon Sep 17 00:00:00 2001 From: Manuel Nickschas Date: Tue, 15 May 2018 21:14:09 +0200 Subject: [PATCH] icons: Adapt and improve icon import script No longer require running it from inside a specific directory. Remove theme-specific blacklists, as they are not needed anymore. Modernize and improve the code a bit. --- icons/import/blacklisted-icons | 16 ++- icons/import/blacklisted-icons.breeze | 1 - icons/import/blacklisted-icons.breezedark | 1 - icons/import/blacklisted-icons.oxygen | 2 - icons/import/extra-icons | 1 - icons/import/import_theme.pl | 167 ++++++++++------------ icons/import/whitelist-icons | 1 - icons/import/whitelisted-icons | 1 + 8 files changed, 89 insertions(+), 101 deletions(-) delete mode 100644 icons/import/blacklisted-icons.breeze delete mode 100644 icons/import/blacklisted-icons.breezedark delete mode 100644 icons/import/blacklisted-icons.oxygen delete mode 100644 icons/import/extra-icons delete mode 100644 icons/import/whitelist-icons create mode 100644 icons/import/whitelisted-icons diff --git a/icons/import/blacklisted-icons b/icons/import/blacklisted-icons index cbee47ca..420872f6 100644 --- a/icons/import/blacklisted-icons +++ b/icons/import/blacklisted-icons @@ -1,4 +1,16 @@ -inactive-quassel -message-quassel +# Specify icon names that are found in the source, but should not be added + +# We want to provide the application icon ourselves +quassel + +# Quassel-specific icons connect-quassel disconnect-quassel +message-quassel +message-quassel-tray +message-quassel-tray-inverted +inactive-quassel +inactive-quassel-tray +inactive-quassel-tray-inverted +active-quassel-tray +active-quassel-tray-inverted diff --git a/icons/import/blacklisted-icons.breeze b/icons/import/blacklisted-icons.breeze deleted file mode 100644 index 416c9043..00000000 --- a/icons/import/blacklisted-icons.breeze +++ /dev/null @@ -1 +0,0 @@ -quassel \ No newline at end of file diff --git a/icons/import/blacklisted-icons.breezedark b/icons/import/blacklisted-icons.breezedark deleted file mode 100644 index 416c9043..00000000 --- a/icons/import/blacklisted-icons.breezedark +++ /dev/null @@ -1 +0,0 @@ -quassel \ No newline at end of file diff --git a/icons/import/blacklisted-icons.oxygen b/icons/import/blacklisted-icons.oxygen deleted file mode 100644 index 5efd1383..00000000 --- a/icons/import/blacklisted-icons.oxygen +++ /dev/null @@ -1,2 +0,0 @@ -irc-channel-parted -irc-channel-joined diff --git a/icons/import/extra-icons b/icons/import/extra-icons deleted file mode 100644 index 40fce8f3..00000000 --- a/icons/import/extra-icons +++ /dev/null @@ -1 +0,0 @@ -quassel diff --git a/icons/import/import_theme.pl b/icons/import/import_theme.pl index 8e56c27a..6ac923b9 100755 --- a/icons/import/import_theme.pl +++ b/icons/import/import_theme.pl @@ -1,46 +1,59 @@ #!/usr/bin/perl -# This script scans the Quassel source for requested icons and imports the needed -# icons (and only them) from a KDE theme (by default Oxygen). -# This relies on all icons being requested using one of the convenience constructors in -# (K)IconLoader, like this: -# widget->setIcon(SmallIcon("fubar")); -# Additional icons can be specified in whitelist-icons; you can also blacklist icons. +# This script scans the Quassel source for required icons and imports the needed +# icons (and only them) from a full icon theme. +# Additional icons can be specified in whitelisted-icons; you can also blacklist icons. # # NOTE: Unless you are a Quassel developer and need to bump the icons we ship, you shouldn't # need to use this script! -# USAGE: ./import/import_theme.pl $systhemefolder $themename $parentFolderFileSuffix -# Run from the icon/ directory. +# USAGE: ./import/import_theme.pl $srcthemedir $themename # -# Examples: (being inside the icons folder) -# ./import/import_theme.pl ~/oxygen-icons oxygen -# ./import/import_theme.pl ~/breeze-icons/icons breeze ICONS -# ./import/import_theme.pl ~/breeze-icons/icons-dark breezedark ICONS +# Examples: +# import_theme.pl ~/oxygen-icons oxygen +# import_theme.pl ~/breeze-icons/icons breeze +# import_theme.pl ~/breeze-icons/icons-dark breeze-dark use strict; use warnings; -use Data::Dumper; + +use File::Basename; use File::Find; +use File::Spec; -my $themefolder = shift; +my $scriptroot = File::Basename::dirname(File::Spec->rel2abs($0)); +my $srcroot = File::Spec->catdir($scriptroot, "..", ".."); +my $srcdir = File::Spec->catdir($srcroot, "src"); -my $source = "../src"; +my $srcthemedir = shift; my $themename = shift; -$themename = $themename ? $themename : "oxygen"; -my $qrcfile_kde = $themename . ".qrc"; -my $parentFolderFileSuffix = shift; -my $whitelistfile = "import/whitelist-icons"; -my $blacklistfile = "import/blacklisted-icons"; +# Sanity checks +die "Theme directory must be given\n" unless length $srcthemedir; +die "Theme directory \"$srcthemedir\" not found\n" unless -e $srcthemedir and -d $srcthemedir; +die "Theme name must not be empty\n" unless length $themename; + +my $destbasedir = File::Spec->catdir($srcroot, "3rdparty", "icons"); +my $destthemedir = File::Spec->catdir($destbasedir, $themename); + +my $whitelistfile = "$scriptroot/whitelisted-icons"; +my $blacklistfile = "$scriptroot/blacklisted-icons"; my %req_icons; my %found_icons; -my %blacklist; -my %themeblacklist; my %whitelist; +my %blacklist; -# First, load the icon blacklist +# Add whitelisted icons +open WHITELIST, "<$whitelistfile" or die "Could not open $whitelistfile\n"; +while() { + s/#.*//; + next unless my ($name) = /([-\w]+)\s*/; + $req_icons{$name} = 1; +} +close WHITELIST; + +# Load the icon blacklist open BLACKLIST, "<$blacklistfile" or die "Could not open $blacklistfile\n"; while() { s/#.*//; @@ -49,69 +62,45 @@ while() { } close BLACKLIST; -my $hasthemeblacklist = 1; -open BLACKLIST, "<$blacklistfile.$themename" or $hasthemeblacklist = 0; -if ($hasthemeblacklist) { - while() { - s/#.*//; - next unless my ($name) = /([-\w]+)\s*/; - $blacklist{$name} = 1; - $themeblacklist{$name} = 1; - } - close BLACKLIST; -} else { - print "Info: No theme specific blacklist found...\n"; -} - -# We now grep the source for things like SmallIcon("fubar") and generate size and name from that -print "Grepping $source for requested icons...\n"; -my @results = `grep -r QIcon::fromTheme\\(\\" $source`; +# We now grep the source for QIcon::fromTheme("fubar") to find required icons +print "Grepping $srcdir for required icons...\n"; +my @results = `grep -r QIcon::fromTheme\\(\\" $srcdir`; foreach(@results) { next unless my ($name) = /\W+QIcon::fromTheme\(\"([-\w]+)/; $req_icons{$name} = 1 unless exists $blacklist{$name}; } -# Add whitelist icons -open WHITELIST, "<$whitelistfile" or die "Could not open $whitelistfile\n"; -while() { - s/#.*//; - next unless my ($name) = /([-\w]+)\s*/; - $req_icons{$name} = 1 - unless exists $themeblacklist{$name}; -} -close WHITELIST; - # Clean old output dir -print "Removing old $themename...\n"; -system("rm -rf $themename"); +print "Removing old $destthemedir...\n"; +system("rm -rf $destthemedir"); # Now copy the icons my %scalables; -print "Copying icons from $themefolder...\n"; -opendir (BASEDIR, "$themefolder") or die "Could not open theme basedir\n"; +print "Copying icons from $srcthemedir...\n"; +opendir (BASEDIR, "$srcthemedir") or die "Could not open theme basedir\n"; my $scalableFound = 0; foreach my $parent (readdir BASEDIR) { - next unless (-d "$themefolder/$parent"); + next unless (-d "$srcthemedir/$parent"); $scalableFound = $scalableFound ? 1 : $parent eq 'scalable'; next if $parent eq '.' or $parent eq '..' or $parent eq 'scalable' or $parent =~ /\..*/; my $ischildcat = $parent =~ /\d+x\d+/ ? 1 : 0; - opendir (SIZEDIR, "$themefolder/$parent") or die "Could not open dir $parent\n"; + opendir (SIZEDIR, "$srcthemedir/$parent") or die "Could not open dir $parent\n"; foreach my $child (readdir SIZEDIR) { next if $child eq '.' or $child eq '..'; my $cat = $ischildcat ? $child : $parent; - opendir (CATDIR, "$themefolder/$parent/$child") or die "Could not open category dir\n"; + opendir (CATDIR, "$srcthemedir/$parent/$child") or die "Could not open category dir\n"; foreach my $icon (readdir CATDIR) { my $iconname = $icon; $iconname =~ s/\.png$//; $iconname =~ s/\.svg$//; next unless exists $req_icons{$iconname}; $scalables{$cat}{$iconname} = 1; - system "mkdir -p $themename/$parent/$child" and die "Could not create category dir\n"; - system "cp -aL $themefolder/$parent/$child/$icon $themename/$parent/$child" + system "mkdir -p $destthemedir/$parent/$child" and die "Could not create category dir\n"; + system "cp -aL $srcthemedir/$parent/$child/$icon $destthemedir/$parent/$child" and die "Error while copying file $parent/$child/$icon\n"; - #print "Copy: $themefolder/$parent/$child/$icon\n"; + print "Copy: $srcthemedir/$parent/$child/$icon\n"; $found_icons{$iconname} = 1; } closedir CATDIR; @@ -123,9 +112,9 @@ closedir BASEDIR; # Copy scalables if ($scalableFound) { foreach my $cat (keys %scalables) { - system "mkdir -p $themename/scalable/$cat" and die "Could not create category dir\n"; + system "mkdir -p $destthemedir/scalable/$cat" and die "Could not create category dir\n"; foreach my $scalable (keys %{$scalables{$cat}}) { - system "cp -aL $themefolder/scalable/$cat/$scalable.svgz $themename/scalable/$cat/$scalable.svgz"; + system "cp -aL $srcthemedir/scalable/$cat/$scalable.svgz $destthemedir/scalable/$cat/$scalable.svgz"; } } } @@ -137,41 +126,33 @@ foreach my $icon (keys %req_icons) { } # Copy license etc. -system "cp $themefolder/AUTHORS $themefolder/CONTRIBUTING $themefolder/COPYING* $themefolder/index.theme $themename/"; - -if($parentFolderFileSuffix) { - system "cp $themefolder/../AUTHORS*$parentFolderFileSuffix $themefolder/../CONTRIBUTING*$parentFolderFileSuffix $themefolder/../COPYING*$parentFolderFileSuffix $themename/"; -} +system "cp -aL $srcthemedir/AUTHORS* $srcthemedir/CONTRIBUTING* $srcthemedir/COPYING* $srcthemedir/index.theme $destthemedir/ | true"; # Generate .qrc -my @file_list; -generate_qrc($themename, $qrcfile_kde, $extrafilecontent); +#my $qrcfile = $themename."_icon_theme.qrc"; +#$qrcfile =~ s/-/_/g; +my $qrcfile = File::Spec->catdir($destbasedir, ($themename."_icon_theme.qrc") =~ s/-/_/gr); +print "Generating $qrcfile...\n"; -print "Done.\n"; - -######################################################################################## -sub generate_qrc { - my $dir = shift; - my $qrcfile = shift; - - @file_list = (); - find(\&push_icon_path, $dir); - @file_list = sort(@file_list ); - my $files = join "\n", @file_list; - - my $qrc = "\n" - ." \n" - ."$files\n" - ." \n" - ."\n"; - - open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n"; - print QRC $qrc; - close QRC; -} +my @file_list = (); sub push_icon_path { return unless /\.png$/ or /\.svg$/ or /^index.theme$/; - - push @file_list, " $File::Find::name"; + push @file_list, " ".$File::Find::name =~ s|^$destbasedir/||gr.""; } + +find(\&push_icon_path, $destthemedir); +@file_list = sort(@file_list); +my $files = join "\n", @file_list; + +my $qrc = "\n" + ." \n" + ."$files\n" + ." \n" + ."\n"; + +open QRC, ">$qrcfile" or die "Could not open $qrcfile for writing!\n"; +print QRC $qrc; +close QRC; + +print "Done.\n"; diff --git a/icons/import/whitelist-icons b/icons/import/whitelist-icons deleted file mode 100644 index 40fce8f3..00000000 --- a/icons/import/whitelist-icons +++ /dev/null @@ -1 +0,0 @@ -quassel diff --git a/icons/import/whitelisted-icons b/icons/import/whitelisted-icons new file mode 100644 index 00000000..3dedef30 --- /dev/null +++ b/icons/import/whitelisted-icons @@ -0,0 +1 @@ +# Specify icon names that need to be added, but are not found automatically -- 2.20.1