1#!/usr/bin/env perl 2# Copyright 2007 - 2010 Craig Drummond <craig.p.drummond@gmail.com> 3# Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com> 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU Lesser General Public License as 7# published by the Free Software Foundation; either version 2.1 of the 8# License, or (at your option) version 3, or any later version accepted 9# by the membership of KDE e.V. (or its successor approved by the 10# membership of KDE e.V.), which shall act as a proxy defined in 11# Section 6 of version 3 of the license. 12# 13# This program is distributed in the hope that it will be useful, 14# but WITHOUT ANY WARRANTY; without even the implied warranty of 15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16# Lesser General Public License for more details. 17# 18# You should have received a copy of the GNU Lesser General Public 19# License along with this library. If not, 20# see <http://www.gnu.org/licenses/>. 21 22# This perl script is called by the QtCurve Gtk2 theme, it is not intended 23# to be useful by itself. 24# 25# Usage perl map_kde_icons.pl <icon map file> <kde prefix> <kde version> <small toolbar size> <toolbar size> <dnd size> <btn size> <menu size> <dialog size> <icon theme name> <icons map file version> 26# @iconSizes = (22, 32, 22, 16, 16, 48); 27# KDE Uses 32x32 for dialogs, and 16x16 for buttons 28@iconSizes = ($ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7], $ARGV[8]); 29@gtk = ("gtk-small-toolbar", "gtk-large-toolbar", "gtk-dnd", "gtk-button", 30 "gtk-menu", "gtk-dialog" ); 31$numSizes = $#iconSizes + 1; 32$useCustom = 0; 33 34printf "#%s %s %02X%02X%02X%02X%02X%02X%02X\n", $ARGV[10], $ARGV[9], $ARGV[2], $ARGV[3], $ARGV[4], $ARGV[5], $ARGV[6], $ARGV[7], $ARGV[8]; 35printf "#This file is created, and used by, QtCurve. Alterations may be overwritten.\n"; 36print "gtk-icon-sizes=\"gtk-small-toolbar=$ARGV[3],$ARGV[3]:gtk-large-toolbar=$ARGV[4],$ARGV[4]:"; 37print "gtk-dnd=$ARGV[5],$ARGV[5]:gtk-button=$ARGV[6],$ARGV[6]:gtk-menu=$ARGV[7],$ARGV[7]:gtk-dialog=$ARGV[8],$ARGV[8]\"\n"; 38#print "gtk-dnd=$ARGV[5],$ARGV[5]:gtk-button=$ARGV[6],$ARGV[6]:gtk-menu=$ARGV[7],$ARGV[7]\"\n"; 39 40if ($ARGV[1]) 41{ 42 $baseDefault=$ARGV[1]; 43 if($ARGV[9] ne "XX") 44 { 45 $useCustom=1; 46 $baseCustom=join("", $baseDefault, "/"); 47 $baseCustom=join("", $baseCustom, "$ARGV[9]"); 48 $baseCustom=join("", $baseCustom, "/"); 49 } 50} 51 52if($ARGV[2] == "3") 53{ 54 $baseDefault=join("", $baseDefault, "/crystalsvg/"); 55} 56else 57{ 58 $baseDefault=join("", $baseDefault, "/oxygen/"); 59} 60 61open(icons, "$ARGV[0]") || die "Could not open \"$ARGV[0]\"\n"; 62 63sub checkSize 64{ 65 $fname=join("", $_[0], $_[1], "x", $_[1], "/", $_[2]); 66 if (open(tst, $fname)) 67 { 68 close(tst); 69 $fname; 70 } 71 else 72 { 73 ""; 74 } 75} 76 77sub printSize 78{ 79 if($_[0]) 80 { 81 print "\t\t{ \"$_[1]x$_[1]/$_[2]\", *, *, \"$_[3]\" },\n"; 82 $_[4]--; 83 } 84} 85 86print "\nstyle \"KDE$ARGV[2]-icons\"\n{\n"; 87 88while($entry=<icons>) 89{ 90 @iconMap=split(/ /, $entry); 91 92 for($i=0; $i<$#iconMap; $i++) 93 { 94 $iconMap[$i+1]=~s/\n//; 95 } 96 97 if($iconMap[1] == /WHAT/) 98 { 99 $got=0; 100 $use=0; 101 if($useCustom) 102 { 103 for($i=0; $i<$#iconMap && $use == 0; $i++) 104 { 105 for($index=0; $index<$numSizes; $index++) 106 { 107 $files[$index]=checkSize($baseCustom, $iconSizes[$index], $iconMap[$i+1]); 108 if($files[$index]) 109 { 110 $got++; 111 } 112 } 113 114 if($got) 115 { 116 $use=$i+1; 117 } 118 } 119 } 120 121 if($got == 0) 122 { 123 for($i=0; $i<$#iconMap && $use == 0; $i++) 124 { 125 for($index=0; $index<$numSizes; $index++) 126 { 127 $files[$index]=checkSize($baseDefault, $iconSizes[$index], $iconMap[$i+1]); 128 if($files[$index]) 129 { 130 $got++; 131 } 132 } 133 134 if($got) 135 { 136 $use=$i+1; 137 } 138 } 139 } 140 141 if($got) 142 { 143 print "\tstock[\"$iconMap[0]\"]={\n"; 144 if($got > 1) 145 { 146 for($index=0; $index<$numSizes; $index++) 147 { 148 $got=printSize($files[$index], $iconSizes[$index], $iconMap[$use], $gtk[$index], $got); 149 } 150 } 151 $found=0; 152 for($index=0; $index<$numSizes && !$found; $index++) 153 { 154 if($files[$index]) 155 { 156 print "\t\t{ \"$iconSizes[$index]x$iconSizes[$index]/$iconMap[$use]\" }\n"; 157 $found=1; 158 } 159 } 160 print "\t}\n"; 161 } 162 #else 163 #{ 164 # print "#\tstock[\"$iconMap[0]\"]=<No matching KDE icon>\n"; 165 #} 166 } 167} 168print "}\nclass \"*\" style \"KDE$ARGV[2]-icons\"\n"; 169 170close(icons); 171