/usr/bin/fixuifiles is in kdesdk-scripts 4:4.13.0-0ubuntu1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | #!/usr/bin/perl -w
# fixuifiles processes .ui files and removes some insanity:
# * Too high minimum Qt version (see $minversion_* in the top of the script)
# * Hardcoded untranslatable Alt+Letter accels (auto-added by Qt Designer)
# * Captions that are equal to classname (auto-added by Qt Designer)
# This script is licensed under the GPL version 2.
# (c) 2004 David Faure <faure@kde.org>
# Based on fixkdeincludes, (c) 2001-2003 Dirk Mueller <mueller@kde.org>
use strict;
use File::Basename;
use Cwd;
# Fix the version number in .ui files if it's bigger than this:
my $default_minversion_maj = 4;
my $default_minversion_min = 0;
# Known words which are ok as captions
my %knowncaptions = (
'Settings' => '',
'Statistics' => '',
'General' => '',
'Tracks' => '',
'Constants' => '',
'Preferences' => '',
'Encryption' => ''
);
# declaration of useful subroutines
sub process_ui_file($);
sub find_ui_files($);
sub read_required_version($);
# some global variables
my $verbose = 0; # turns on debugging
my $omit_Qt_check = 0; # turns off Qt version checking
my @explicitfiles = (); # filled in if passing files on the command line
my $minversion_maj = $default_minversion_maj;
my $minversion_min = $default_minversion_min;
while (defined ($ARGV[0]))
{
$_ = shift;
if (/^--help$|^-h$/) {
print "Usage: fixuifiles [OPTIONS] files...\n";
print "Options are:\n";
print "\t-v, --verbose\tBe verbose\n";
print "\t--omitqtcheck\tDoes not check for Qt minimum version\n";
exit 0;
}
elsif (/^--verbose$|^-v$/) {
$verbose = 1;
}elsif (/^--omitqtcheck/) {
$omit_Qt_check = 1;
}
elsif (!/^-/) {
push @explicitfiles, $_;
}
}
# Find .ui files in the given dir
sub find_ui_files($)
{
my ( $dir ) = @_;
opendir (DIR, "$dir") || die "Couldn't read '$dir'\n";
my @files = grep { /^.*\.ui$/ } readdir(DIR);
closedir(DIR);
#print "found files: [ " . join(' ', @files) . " ] in $dir\n" if ($verbose);
# prefix them with $dir
my @retfiles = ();
foreach my $file(@files) {
push @retfiles, "$dir/$file";
}
return @retfiles;
}
# Ensure the version at the top of the file is not too high
sub fix_version($)
{
my $srcfile = shift @_;
open(SRC, "< $srcfile") || die "fix_version: couldn't open '$srcfile'\n";
my @contents = <SRC>;
my @fixedcontents = ();
close(SRC);
my $needfix = 0;
my $foundversion = 0;
foreach my $line (@contents) {
if (!$foundversion && $line =~ m/version=\"([0-9]+)\.([0-9]+)(\.[0-9]+)?\"/) {
my $version_maj = $1;
my $version_min = $2;
if ( $version_maj > $minversion_maj ||
( $version_maj == $minversion_maj && $version_min > $minversion_min ) ) {
$line =~ s/version=\"[0-9]+\.[0-9]+\"/version=\"$minversion_maj.$minversion_min\"/o;
$needfix = 1;
print "$srcfile: version was $version_maj.$version_min, set to $minversion_maj.$minversion_min\n";
}
$foundversion = 1;
}
push @fixedcontents, $line;
}
if (!$foundversion) {
# TODO improve so that the script adds the necessary line
print "$srcfile has no UI version, please fix it\n";
}
if ($needfix) {
open(SRC, "> $srcfile") || die "fix_version: couldn't open '$srcfile' for writing\n";
print SRC @fixedcontents;
close(SRC);
}
}
# Ensure no auto-added Alt+letter accel exists - those are untranslatable
sub fix_accels($)
{
my $srcfile = shift @_;
open(SRC, "< $srcfile") || die "fix_accels: couldn't open '$srcfile'\n";
my @contents = <SRC>;
close(SRC);
return if ( !grep( /<string>Alt\+[A-Z]<\/string>/, @contents ));
my @fixedcontents = ();
my $firstline;
my $accelsremoved = 0;
my $inside_accel = 0;
# inside_accel is 0 before <property>
# 1 after <property> and before <string>
# 2 after <string> if alt+letter, and before </property>
foreach my $line (@contents) {
if ( $inside_accel == 1 ) {
if ( $line =~ m/<string>(Alt\+[A-Z])<\/string>/ ) {
print "$srcfile: accel $1 removed\n" if ($verbose);
$inside_accel = 2;
$accelsremoved++;
} else { # Not alt+letter, keep accel
push @fixedcontents, $firstline;
$inside_accel = 0;
}
}
if ($line =~ m/property name=\"shortcut\"/) {
$inside_accel = 1;
$firstline = $line;
}
if ($inside_accel == 0) {
push @fixedcontents, $line;
}
$inside_accel = 0 if ($inside_accel && $line =~ m/<\/property>/);
}
if ($accelsremoved) {
print "$srcfile: $accelsremoved shortcut removed\n";
open(SRC, "> $srcfile") || die "fix_accels: couldn't open '$srcfile' for writing\n";
print SRC @fixedcontents;
close(SRC);
}
}
# Ensure no auto-added caption exists - it's pretty stupid to have to
# translate Form1 or MyClassName
sub fix_captions($)
{
my $srcfile = shift @_;
open(SRC, "< $srcfile") || die "fix_captions: couldn't open '$srcfile'\n";
my @contents = <SRC>;
close(SRC);
my @fixedcontents = ();
my $firstline;
my $class = "";
my $captionsremoved = 0;
my $inside_caption = 0;
# inside_caption is 0 before <property>
# 1 after <property> and before <string>
# 2 after <string> if caption should be removed, and before </property>
foreach my $line (@contents) {
$class = $1 if ($line =~ m/<class>(.*)<\/class>/);
if ( $inside_caption == 1 ) {
$line =~ m/<string.*\>(.*)<\/string>/ || die "Malformed XML (no string under caption/windowTitle) in file $srcfile";
my $caption = $1;
print "$srcfile: caption='$caption' class='$class'\n" if ($verbose);
if ( ( $caption eq $class && !defined $knowncaptions{$caption} ) ||
($caption =~ m/Form[0-9]*/) ) {
if ( $caption =~ m/^[A-Z][a-z]*$/ ) {
print "$srcfile: removing caption '$caption' (warning! could be real caption)\n";
} else {
print "$srcfile: removing caption '$caption'\n";
}
$inside_caption = 2;
$captionsremoved++;
} else { # Real caption, keep it
print "$srcfile: keeping caption '$caption'\n" if ($verbose);
push @fixedcontents, $firstline;
$inside_caption = 0;
}
}
if ($line =~ m/property name=\"windowTitle\"/) {
$inside_caption = 1;
$firstline = $line;
}
if ($inside_caption == 0) {
push @fixedcontents, $line;
}
$inside_caption = 0 if ($inside_caption && $line =~ m/<\/property>/);
}
if ($captionsremoved) {
open(SRC, "> $srcfile") || die "fix_captions: couldn't open '$srcfile' for writing\n";
print SRC @fixedcontents;
close(SRC);
}
}
# Find a .qt_minversion in $dir or any parent directory.
sub read_required_version($)
{
my $dir = Cwd::abs_path( shift @_ );
$minversion_maj = $default_minversion_maj;
$minversion_min = $default_minversion_min;
while ( length($dir) > 1 ) {
my $versfile = "$dir/.qt_minversion";
my $version;
if ( open (VERSFILE, "< $versfile") ) {
while (<VERSFILE>) {
$version = $_ if (!/^#/);
}
close(VERSFILE);
}
if (defined $version && $version =~ m/([0-9]+)\.([0-9]+)/) {
$minversion_maj = $1;
$minversion_min = $2;
print "Found min version $1.$2 in $versfile\n" if ($verbose);
return;
}
$dir = dirname($dir);
}
}
# Process one .ui file
sub process_ui_file($)
{
my $file = shift @_;
&read_required_version( dirname($file) );
print "Checking: $file\n" if($verbose);
&fix_version($file) if(!$omit_Qt_check);
&fix_accels($file);
&fix_captions($file);
}
#############################################################################
# here is the main logic
#
# process files from the command line, if any
if ( $#explicitfiles >= 0 ) {
foreach my $file( @explicitfiles ) {
&process_ui_file( $file );
}
exit 0;
}
# first generate a list of subdirectories
my @dirlist = ();
push @dirlist, ".";
foreach my $dir ( @dirlist ) {
opendir (DIR, "$dir") || warn "Couldn't read '$dir'";
my $subdir = "";
while( $subdir = readdir(DIR)) {
next if ($subdir =~ /^\./);
next if !( -d "$dir/$subdir");
push @dirlist, "$dir/$subdir";
}
closedir(DIR);
}
# now iterate over all subdirs
foreach my $dir(@dirlist) {
my @uifile = find_ui_files($dir);
foreach my $file(@uifile) {
&process_ui_file($file);
}
}
|