Warning, file /sdk/kde-dev-scripts/kf5/remove-kde4support.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 # find -iname "*.cpp"|xargs kde-dev-scripts/kf5/remove-kde4support.pl
0005
0006 use strict;
0007 use File::Basename;
0008 use lib dirname(\$0);
0009 use functionUtilkde;
0010
0011 foreach my \$file (@ARGV) {
0012
0013     my \$modified;
0014     my \$needQApplicationHeader;
0015     my \$needQDesktopWidgetHeader;
0016     my \$needKColorScheme;
0017     my \$needQStandardPaths;
0018     my \$needKFormat;
0019     my \$needQFontDatabase;
0020     my \$needQDir;
0021     my \$needKComponentData;
0022     my \$removeKdemacros;
0023     my \$needQMimeDatabase;
0024     my \$needKHelpClient;
0025     my \$needKlocalizedString;
0026     open(my \$FILE, "<", \$file) or warn "We can't open file \$file:\$!\n";
0027     my @l = map {
0028         my \$orig = \$_;
0029
0030         s/\bQ_WS_WIN/Q_OS_WIN/g;
0031         s/\bQ_WS_MAC/Q_OS_MAC/g;
0032
0033
0034         s/\bkasciistricmp\b/qstricmp/;
0035         s/KGlobal::config\(\)/KSharedConfig::openConfig()/g;
0036
0037         # convert KCategoryDrawerV2 and KCategoryDrawerV3 to KCategoryDrawer
0038         s/KCategoryDrawerV3/KCategoryDrawer/g;
0039         s/KCategoryDrawerV2/KCategoryDrawer/g;
0040
0041         if ( /KLocale::global\(\)\-\>removeAcceleratorMarker/ ) {
0042            warn "removeAcceleratorMarker found \n";
0043            s,KLocale::global\(\)\-\>removeAcceleratorMarker\b,KLocalizedString::removeAcceleratorMarker,;
0044            \$needKlocalizedString = 1;
0045         }
0046
0047         if (/KToolInvocation::invokeHelp/) {
0048            s/KToolInvocation::invokeHelp/KHelpClient::invokeHelp/;
0049            \$needKHelpClient = 1;
0050         }
0051
0052         s,::self\(\)\-\>writeConfig\(\),::self\(\)\-\>save\(\),;
0053         s,::self\(\)->readConfig\(\),::self\(\)\-\>load\(\),;
0054         if (/KGlobalSettings::dndEventDelay/) {
0055            s,KGlobalSettings::dndEventDelay\b,QApplication::startDragDistance,;
0056            \$needQApplicationHeader = 1;
0057         }
0058         if (/KGlobalSettings::desktopGeometry/) {
0059            s,KGlobalSettings::desktopGeometry\b,QApplication::desktop\(\)\-\>screenGeometry,;
0060            \$needQApplicationHeader = 1;
0061            \$needQDesktopWidgetHeader = 1;
0062         }
0063         if (/KGlobalSettings::createApplicationPalette/) {
0064            s,KGlobalSettings::createApplicationPalette\b,KColorScheme::createApplicationPalette,;
0065            \$needKColorScheme = 1;
0066         }
0067         if (/KGlobalSettings::documentPath/) {
0068            s,KGlobalSettings::documentPath\(\),QStandardPaths::writableLocation\(QStandardPaths::DocumentsLocation\),;
0069            \$needQStandardPaths = 1;
0070         }
0071         if (/KGlobalSettings::desktopPath/) {
0072            s,KGlobalSettings::desktopPath\(\),QStandardPaths::writableLocation\(QStandardPaths::DesktopLocation\),;
0073            \$needQStandardPaths = 1;
0074         }
0075         if (/KGlobalSettings::musicPath/) {
0076            s,KGlobalSettings::musicPath\(\),QStandardPaths::writableLocation\(QStandardPaths::MusicLocation\),;
0077            \$needQStandardPaths = 1;
0078         }
0079         if (/KGlobalSettings::videosPath/) {
0080            s,KGlobalSettings::videosPath\(\),QStandardPaths::writableLocation\(QStandardPaths::MoviesLocation\),;
0081            \$needQStandardPaths = 1;
0082         }
0083         if (/KGlobalSettings::downloadPath/) {
0084            s,KGlobalSettings::downloadPath\(\),QStandardPaths::writableLocation\(QStandardPaths::DownloadLocation\),;
0085            \$needQStandardPaths = 1;
0086         }
0087         if (/KGlobalSettings::picturesPath/) {
0088            s,KGlobalSettings::picturesPath\(\),QStandardPaths::writableLocation\(QStandardPaths::PicturesLocation\),;
0089            \$needQStandardPaths = 1;
0090         }
0091
0092         s/\bKGlobal::charsets\s*\(\)/KCharsets::charsets\(\)/;
0093
0094         if (/KGlobal::locale\(\)\-\>formatByteSize/) {
0095            s,KGlobal::locale\(\)\-\>formatByteSize,KFormat\(\).formatByteSize,g;
0096            \$needKFormat = 1;
0097         }
0098
0099         if (/KGlobal::locale\(\)\-\>prettyFormatDuration/) {
0100            s,KGlobal::locale\(\)\-\>prettyFormatDuration,KFormat\(\).formatSpelloutDuration,g;
0101            \$needKFormat = 1;
0102         }
0103
0104         if (/KGlobal::locale\(\)\-\>insertCatalog/) {
0105            s/KGlobal::locale\(\)\-\>insertCatalog/\/\/KF5 port: remove this line and define TRANSLATION_DOMAIN in CMakeLists.txt instead\n\/\/KLocale::global\(\)\-\>insertCatalog/;
0106         }
0107         s/\bKGlobal::locale\s*\(\)/KLocale::global\(\)/g;
0108
0109         if (/KGlobalSettings::generalFont/) {
0110            s,KGlobalSettings::generalFont\s*\(\s*\),QFontDatabase::systemFont\(QFontDatabase::GeneralFont\),g;
0111            \$needQFontDatabase = 1;
0112         }
0113         if (/KGlobalSettings::fixedFont/) {
0114            s,KGlobalSettings::fixedFont\s*\(\s*\),QFontDatabase::systemFont\(QFontDatabase::FixedFont\),g;
0115            \$needQFontDatabase = 1;
0116         }
0117         if (/KGlobalSettings::windowTitleFont/) {
0118            s,KGlobalSettings::windowTitleFont\s*\(\s*\),QFontDatabase::systemFont\(QFontDatabase::TitleFont\),g;
0119            \$needQFontDatabase = 1;
0120         }
0121         if (/KGlobalSettings::smallestReadableFont/) {
0122            s,KGlobalSettings::smallestReadableFont\s*\(\s*\),QFontDatabase::systemFont\(QFontDatabase::SmallestReadableFont\),g;
0123            \$needQFontDatabase = 1;
0124         }
0125
0126         if (/KGlobalSettings::contrast\b/) {
0127            s,KGlobalSettings::contrast\b,KColorScheme::contrast,g;
0128            \$needKColorScheme = 1;
0129         }
0130         if (/KGlobalSettings::contrastF\b/) {
0131            s,KGlobalSettings::contrastF\b,KColorScheme::contrastF,g;
0132            \$needKColorScheme = 1;
0133         }
0134         if (/KStandardDirs::makeDir\b/) {
0135            \$needQDir = 1;
0136            s,KStandardDirs::makeDir\b,QDir\(\)\.mkpath,;
0137         }
0138         if (/KGlobal::activeComponent\b/) {
0139            s,KGlobal::activeComponent\b,KComponentData::activeComponent,;
0140            \$needKComponentData = 1;
0141         }
0142         if (/KGlobal::setActiveComponent\b/) {
0143            s,KGlobal::setActiveComponent\b,KComponentData::setActiveComponent,;
0144            \$needKComponentData = 1;
0145         }
0146         if (/KUrl::fromPath/) {
0147            s,KUrl::fromPath\b,QUrl::fromLocalFile,;
0148         }
0149
0150         s/KUrl::toPercentEncoding\b/QUrl::toPercentEncoding/g;
0151         s/KUrl::fromPercentEncoding\b/QUrl::fromPercentEncoding/g;
0152
0153         if (/KDE_EXPORT KCModule/) {
0154            s,KDE_EXPORT KCModule,Q_DECL_EXPORT KCModule,;
0155            \$removeKdemacros = 1;
0156         }
0157         if (/KConfigSkeleton::usrReadConfig\b/) {
0158            s,KConfigSkeleton::usrReadConfig\b,KConfigSkeleton::usrRead,;
0159         }
0160         if (/KApplication::clipboard\b/) {
0161            s,KApplication::clipboard\b,QApplication::clipboard,;
0162         }
0163         if (/KApplication::isRightToLeft\b/) {
0164            s,KApplication::isRightToLeft\b,QApplication::isRightToLeft,;
0165         }
0166         s,KViewStateSaver\b,KConfigViewStateSaver,;
0167         s/\<KViewStateSaver\b\>/\<KConfigViewStateSaver>/ if (/#include/);
0168         s/\<kviewstatesaver\.h\>/\<KConfigViewStateSaver\>/ if (/#include/);
0169         my \$regexp = qr/
0170            ^(\s*)                        # (1) Indentation, possibly "Classname *" (the ? means non-greedy)
0171            (.*?)                         # (2) Possibly "Classname *" (the ? means non-greedy)
0172            KMimeType::extractKnownExtension(.*)\$                         # (3) afterreg
0173            /x; # /x Enables extended whitespace mode
0174         if (my (\$indent, \$left, \$after) = \$_ =~ \$regexp) {
0175            \$_ = \$indent . "QMimeDatabase db;\n";
0176            \$_ .= \$indent . "\$left" . "db.suffixForFileName" . \$after . "\n";
0177            \$needQMimeDatabase = 1;
0178         }
0179
0180         my \$regexpEscape = qr/
0181            ^(\s*)            # (1) Indentation
0182            (.*?)             # (2) Possibly "Classname *" (the ? means non-greedy)
0183            Qt::escape
0184            \${functionUtilkde::paren_begin}3\${functionUtilkde::paren_end}  # (3) (args)
0185            (.*)\$                        # (4) end
0186            /x; # /x Enables extended whitespace mode
0187         if (my (\$indent, \$left, \$args, \$end) = \$_ =~ \$regexpEscape) {
0188            #warn "found escape \$args \n";
0189            \$args =~ s/^\(\s*//;
0190            \$args =~ s/\s*\)\$//;
0191            if (\$args =~ /^\*/) {
0192              \$_ = \$indent . \$left . "(\$args).toHtmlEscaped()" . \$end . "\n";
0193
0194            } else {
0195              \$_ = \$indent . \$left . "\$args.toHtmlEscaped()" . \$end . "\n";
0196            }
0197         }
0198
0199         \$modified ||= \$orig ne \$_;
0200         \$_;
0201     } <\$FILE>;
0202
0203     if (\$modified) {
0204         open (my \$OUT, ">", \$file);
0205         print \$OUT @l;
0206         close (\$OUT);
0207         if (\$needQApplicationHeader) {
0208            functionUtilkde::addIncludeInFile(\$file, "QApplication");
0209         }
0210         if (\$needQDesktopWidgetHeader) {
0211            functionUtilkde::addIncludeInFile(\$file, "QDesktopWidget");
0212         }
0213         if (\$needKColorScheme) {
0214            functionUtilkde::addIncludeInFile(\$file, "KColorScheme");
0215         }
0216         if (\$needQStandardPaths) {
0217            functionUtilkde::addIncludeInFile(\$file, "QStandardPaths");
0218         }
0219         if (\$needKFormat) {
0220            functionUtilkde::addIncludeInFile(\$file, "KFormat");
0221         }
0222         if (\$needQFontDatabase) {
0223            functionUtilkde::addIncludeInFile(\$file, "QFontDatabase");
0224         }
0225         if (\$needQDir) {
0226            functionUtilkde::addIncludeInFile(\$file, "QDir");
0227         }
0228         if (\$needKComponentData) {
0229            functionUtilkde::addIncludeInFile(\$file, "KComponentData");
0230         }
0231         if (\$removeKdemacros) {
0232            functionUtilkde::removeIncludeInFile(\$file, "kdemacros.h");
0233         }
0234         if (\$needQMimeDatabase) {
0235            functionUtilkde::addIncludeInFile(\$file, "QMimeDatabase");
0236         }
0237         if (\$needKHelpClient) {
0238            functionUtilkde::addIncludeInFile(\$file, "KHelpClient");
0239         }
0240         if ( \$needKlocalizedString ) {
0241            functionUtilkde::addIncludeInFile(\$file, "KLocalizedString");
0242         }
0243     }
0244 }
0245
0246 functionUtilkde::diffFile( "@ARGV" );```