File indexing completed on 2024-11-03 05:10:32

0001 #!/usr/bin/perl
0002 # laurent Montel <montel@kde.org>
0003 # Hamish Rodda <rodda@kde.org>
0004 # Matthias Kretz <kretz@kde.org>
0005 # Convert KInstance -> KComponentData
0006 
0007 use File::Basename;
0008 use lib dirname( $0 );
0009 use functionUtilkde;
0010 use strict;
0011 
0012 open(my $F, "-|", qw(find . -type f));
0013 my $file;
0014 
0015 while ($file = <$F>) {
0016     chomp $file;
0017     next if functionUtilkde::excludeFile( $file);
0018 
0019     my $modified;
0020     my @necessaryIncludes = ();
0021     open(my $FILE, "<", $file) or warn "We can't open file $file:$!\n";
0022     my @l = map {
0023         my $orig = $_;
0024 
0025         s!#include <kinstance.h>!#include <kcomponentdata.h>!;
0026         s!#include "kinstance.h"!#include "kcomponentdata.h"!;
0027         s!kapp->instanceName\s?\(!KGlobal::mainComponent().componentName(!g;
0028         s!kapp->dirs\s?\(!KGlobal::dirs(!g;
0029         s!KApplication::kApplication\s?\(\)->dirs\s?\(!KGlobal::dirs(!g;
0030         s!kapp->aboutData\s?\(!KGlobal::mainComponent().aboutData(!g;
0031         s!kapp->caption\s?\(!KGlobal::caption(!g;
0032         s!KInstance::caption\s?\(!KGlobal::caption(!g;
0033         s!const\s*KInstance\s*\*\s*!const KComponentData &!g;
0034         s!KInstance\s*\*\s*!KComponentData !g;
0035         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*kapp->config\s?\(!KSharedConfig::Ptr \1 = KGlobal::config(!g;
0036         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*KGlobal::config\s?\(!KSharedConfig::Ptr \1 = KGlobal::config(!g;
0037         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*KGlobal::instance\s?()->config\s*\(!KSharedConfig::Ptr \1 = KGlobal::config(!g;
0038         s!KGlobal::instance\s?\(\)->!KGlobal::mainComponent().!g;
0039         s!KGlobal::instance\s?\(!KGlobal::mainComponent(!g;
0040         s!KGlobal::activeInstance\s?\(!KGlobal::activeComponent(!g;
0041         s!KGlobal::setActiveInstance\s?\(!KGlobal::setActiveComponent(!g;
0042         s!KGlobal::sharedConfig\s?\(!KGlobal::config(!g;
0043         s!->sharedConfig\s?\(!.config(!g;
0044         s!->instanceName\s?\(!.componentName(!g;
0045         s!\s*=\s*new KInstance\s*\(!(!g;
0046         s!new KInstance\s?\(!KComponentData(!g;
0047         s!KInstance!KComponentData!g;
0048         # the following might be a little too bold:
0049         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*instance->config\s?\(!KSharedConfig::Ptr \1 = componentData.config(!g;
0050         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*instance\(\)->config\s?\(!KSharedConfig::Ptr \1 = componentData().config(!g;
0051         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*_instance->config\s?\(!KSharedConfig::Ptr \1 = _componentData.config(!g;
0052         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*m_instance->config\s?\(!KSharedConfig::Ptr \1 = m_componentData.config(!g;
0053         s!KConfig\s*\*\s*([a-zA-Z0-9_]+)\s*=\s*mInstance->config\s?\(!KSharedConfig::Ptr \1 = mComponentData.config(!g;
0054         s!instanceNames\s?\(!componentNames(!g;
0055         s!\binstance->!componentData.!g;
0056         s!\b_instance->!_componentData.!g;
0057         s!\bm_instance->!m_componentData.!g;
0058         s!\bmInstance->!mComponentData.!g;
0059         s!\binstance\s?\(\)->!componentData().!g;
0060         s!\binstance\s?\(!componentData(!g;
0061         s!\bpartInstance\s?\(!partComponentData(!g;
0062         s!\bpartInstanceFromLibrary\s?\(!partComponentDataFromLibrary(!g;
0063         s!\bcreateInstance\s?\(!createComponentData(!g;
0064         #s!\binstance\b!componentData!g;
0065         s!\b_instance\b!_componentData!g;
0066         s!\bm_instance\b!m_componentData!g;
0067         s!\bmInstance\b!mComponentData!g;
0068         s!\bsetInstance\b!setComponentData!g;
0069         s!\binstanceName\b!componentName!g;
0070         # wrong changes:
0071         s!QAbstractEventDispatcher::componentData\s?\(\)\.!QAbstractEventDispatcher::instance()->!g;
0072         s!QAbstractEventDispatcher::componentData\s?\(!QAbstractEventDispatcher::instance(!g;
0073         s!QCoreApplication::componentData\s?\(\)\.!QCoreApplication::instance()->!g;
0074         s!QCoreApplication::componentData\s?\(!QCoreApplication::instance(!g;
0075         s!QApplication::componentData\s?\(\)\.!QApplication::instance()->!g;
0076         s!QApplication::componentData\s?\(!QApplication::instance(!g;
0077 
0078         if ($_ =~ /KConfigGroup/) {
0079                 push(@necessaryIncludes, "kconfiggroup.h");
0080         }
0081 
0082         $modified ||= $orig ne $_;
0083         $_;
0084     } <$FILE>;
0085 
0086     if ($modified) {
0087         open (my $OUT, ">", $file);
0088         print $OUT @l;
0089     }
0090 
0091     my %alreadyadded = {};
0092     foreach my $inc (@necessaryIncludes) {
0093         next if (defined $alreadyadded{$inc});
0094         $alreadyadded{$inc} = 1;
0095 
0096         functionUtilkde::addIncludeInFile($file, $inc);
0097     }
0098 }
0099 functionUtilkde::diffFile( "@ARGV" );
0100 # vim: et sw=4