Warning, file /sdk/kde-dev-scripts/kf5/convert-kprogressdialog.pl was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #!/usr/bin/perl -w 0002 0003 # Laurent Montel <montel@kde.org> (2014) 0004 # KProgressDialog->QProgressDialog 0005 # find -iname "*.cpp" -o -iname "*.h" |xargs kde-dev-scripts/kf5/convert-kprogressdialog.pl 0006 # TODO need to improve it. 0007 use strict; 0008 use File::Basename; 0009 use lib dirname($0); 0010 use functionUtilkde; 0011 0012 foreach my $file (@ARGV) { 0013 0014 my $modified; 0015 open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n"; 0016 my %varname = (); 0017 my @l = map { 0018 my $orig = $_; 0019 my $regexp = qr/ 0020 ^(\s*) # (1) Indentation, possibly "Classname *" (the ? means non-greedy) 0021 (.*?) # (2) Possibly "Classname *" (the ? means non-greedy) 0022 (\w+) # (3) variable name 0023 \s*=\s* # assignment 0024 new\s+KProgressDialog\s*\((.*)\) # (4) new KProgressDialog(...,...,...,...); 0025 (.*)$ # (5) afterreg 0026 /x; # /x Enables extended whitespace mode 0027 if (my ($indent, $left, $var, $args, $afterreg) = $_ =~ $regexp) { 0028 warn "Found KProgressDialog $var \n"; 0029 $varname{$var} = 1; 0030 my $constructor_regexp = qr/ 0031 ^([^,]*)\s* # parent 0032 (?:,\s([^,]*))? # caption 0033 (?:,\s([^,]*))? # text 0034 (.*)$ # after 0035 /x; 0036 if ( my ($parent, $caption, $text, $after) = $args =~ $constructor_regexp ) { 0037 $_ = $indent . $left . "$var = new QProgressDialog($parent);\n"; 0038 if (defined $caption) { 0039 $_ .= $indent . "$var\-\>setWindowTitle($caption);\n"; 0040 } 0041 if (defined $text) { 0042 $_ .= $indent . "$var\-\>setLabelText($text);\n"; 0043 } 0044 } 0045 } 0046 my $regexpLocal = qr/ 0047 ^(\s*) # (1) Indentation 0048 KProgressDialog\s+ 0049 (\w+) # (2) variable name 0050 (.*)/x; # /x Enables extended whitespace mode 0051 if (my ($left, $var, $args) = $_ =~ $regexpLocal) { 0052 $varname{$var} = 1; 0053 my $constructor_regexp = qr/ 0054 ^([^,]*)\s* # parent 0055 (?:,\s([^,]*))? # caption 0056 (?:,\s([^,]*))? # text 0057 (.*)$ # after 0058 /x; 0059 if ( my ($parent, $caption, $text, $after) = $args =~ $constructor_regexp ) { 0060 $_ = $left . "QProgressDialog $var$parent);\n"; 0061 if (defined $caption) { 0062 $_ .= $left . "$var\.setWindowTitle($caption);\n"; 0063 } 0064 if (defined $text) { 0065 $_ .= $left . "$var\.setLabelText($text\n"; 0066 } 0067 } 0068 } 0069 if (/(\w+)\.progressBar\(\)\-\>setMaximum\b/) { 0070 my $variable = $1; 0071 if (defined $varname{$variable}) { 0072 s/$variable\.progressBar\(\)\-\>setMaximum\b/$variable\.setMaximum/; 0073 } 0074 } 0075 if (/(\w+)\.progressBar\(\)\-\>setMinimum\b/) { 0076 my $variable = $1; 0077 if (defined $varname{$variable}) { 0078 s/$variable\-\>progressBar\(\)\.setMinimum\b/$variable\.setMinimum/; 0079 } 0080 } 0081 if (/(\w+)\.progressBar\(\)\-\>setValue\b/) { 0082 my $variable = $1; 0083 if (defined $varname{$variable}) { 0084 s/$variable\.progressBar\(\)\-\>setValue\b/$variable\.setValue/; 0085 } 0086 } 0087 if (/(\w+)\.progressBar\(\)\-\>value\b/) { 0088 my $variable = $1; 0089 if (defined $varname{$variable}) { 0090 s/$variable\.progressBar\(\)\-\>value\b/$variable\.value/; 0091 } 0092 } 0093 if (/(\w+)\.progressBar\(\)\-\>setRange\b/) { 0094 my $variable = $1; 0095 if (defined $varname{$variable}) { 0096 s/$variable\.progressBar\(\)\-\>setRange\b/$variable\.setRange/; 0097 } 0098 } 0099 if (/(\w+)\.wasCancelled\s*\(\)/) { 0100 my $variable = $1; 0101 if (defined $varname{$variable}) { 0102 s/$variable\.wasCancelled\s*\(\)/$variable\.wasCanceled()/; 0103 } 0104 } 0105 if (/(\w+)\.setAllowCancel\s*\(\s*false\s*\);/) { 0106 my $variable = $1; 0107 if (defined $varname{$variable}) { 0108 s/$variable\.setAllowCancel\s*\(\s*false\s*\);/$variable\.setCancelButton\(0\);/; 0109 } 0110 } 0111 if (/(\w+)\.setAllowCancel\s*\(\s*true\s*\);/) { 0112 my $variable = $1; 0113 if (defined $varname{$variable}) { 0114 $_ = ""; 0115 } 0116 } 0117 if (/(\w+)\.setShowCancel\s*\(\s*false\s*\);/) { 0118 my $variable = $1; 0119 if (defined $varname{$variable}) { 0120 s/$variable\.setShowCancel\s*\(\s*false\s*\);/$variable\.setCancelButton\(0\);/; 0121 } 0122 } 0123 0124 if (/(\w+)\-\>setShowCancel\s*\(\s*false\s*\);/) { 0125 my $variable = $1; 0126 if (defined $varname{$variable}) { 0127 s/$variable\-\>setShowCancel\s*\(\s*false\s*\);/$variable\-\>setCancelButton\(0\);/; 0128 } 0129 } 0130 0131 0132 if (/(\w+)\-\>progressBar\(\)\-\>setMaximum\b/) { 0133 my $variable = $1; 0134 if (defined $varname{$variable}) { 0135 s/$variable\-\>progressBar\(\)\-\>setMaximum\b/$variable\-\>setMaximum/; 0136 } 0137 } 0138 if (/(\w+)\-\>progressBar\(\)\-\>setMinimum\b/) { 0139 my $variable = $1; 0140 if (defined $varname{$variable}) { 0141 s/$variable\-\>progressBar\(\)\-\>setMinimum\b/$variable\-\>setMinimum/; 0142 } 0143 } 0144 if (/(\w+)\-\>progressBar\(\)\-\>setValue\b/) { 0145 my $variable = $1; 0146 if (defined $varname{$variable}) { 0147 s/$variable\-\>progressBar\(\)\-\>setValue\b/$variable\-\>setValue/; 0148 } 0149 } 0150 if (/(\w+)\-\>progressBar\(\)\-\>value\b/) { 0151 my $variable = $1; 0152 if (defined $varname{$variable}) { 0153 s/$variable\-\>progressBar\(\)\-\>value\b/$variable\-\>value/; 0154 } 0155 } 0156 if (/(\w+)\-\>progressBar\(\)\-\>setRange\b/) { 0157 my $variable = $1; 0158 if (defined $varname{$variable}) { 0159 s/$variable\-\>progressBar\(\)\-\>setRange\b/$variable\-\>setRange/; 0160 } 0161 } 0162 if (/(\w+)\-\>wasCancelled\s*\(\)/) { 0163 my $variable = $1; 0164 if (defined $varname{$variable}) { 0165 s/$variable\-\>wasCancelled\s*\(\)/$variable\-\>wasCanceled()/; 0166 } 0167 } 0168 if (/(\w+)\-\>setAllowCancel\s*\(\s*false\s*\);/) { 0169 my $variable = $1; 0170 if (defined $varname{$variable}) { 0171 s/$variable\-\>setAllowCancel\s*\(\s*false\s*\);/$variable\-\>setCancelButton\(0\);/; 0172 } 0173 } 0174 if (/(\w+)\-\>setAllowCancel\s*\(\s*true\s*\);/) { 0175 my $variable = $1; 0176 if (defined $varname{$variable}) { 0177 $_ = ""; 0178 } 0179 } 0180 if ( /\s*connect\s*\(\s*(\w+),\s*SIGNAL\s*\(\s*cancelClicked\s*\(\s*\)/ ) { 0181 if (defined $varname{$1} ) { 0182 s/cancelClicked/canceled/; 0183 } 0184 } 0185 0186 s/\bKProgressDialog\b/QProgressDialog/g; 0187 s/\<KProgressDialog\b\>/\<QProgressDialog>/ if (/#include/); 0188 s/\<kprogressdialog.h\>/\<QProgressDialog>/ if (/#include/); 0189 $modified ||= $orig ne $_; 0190 $_; 0191 } <$FILE>; 0192 0193 if ($modified) { 0194 open (my $OUT, ">", $file); 0195 print $OUT @l; 0196 close ($OUT); 0197 } 0198 } 0199 0200 functionUtilkde::diffFile( "@ARGV" );