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
|
#!/usr/bin/perl -w
# David Faure <faure@kde.org>
# KGenericFactory + K_EXPORT_COMPONENT_FACTORY -> K_PLUGIN_FACTORY + K_EXPORT_PLUGIN
use strict;
use File::Basename;
use lib dirname($0);
use functionUtilkde;
my $plugin;
my $factory;
my $looking_for_plugin = 0;
foreach my $file (@ARGV) {
functionUtilkde::substInFile {
s!kgenericfactory\.h!kpluginfactory.h!g;
s!<KGenericFactory>!<KPluginFactory>!g;
s!<KParts/GenericFactory>!<KPluginFactory>!g;
s!kparts/factory.h!kpluginfactory.h!g;
s!kparts/genericfactory.h!kpluginfactory.h!g;
s!<KParts/Factory>!<KPluginFactory>!g;
if (/typedef KGenericFactory<(.*)>\s*(.*);/ || /typedef KParts::GenericFactory<(.*)>\s*(.*);/) {
$plugin = $1;
$factory = $2;
# Ignore ",BaseClassForParentArg" in $plugin
if ($plugin =~ s/,(.*)//) {
print STDERR "Warning, parent argument for plugin was $1, needs to be changed to QObject, or you need a create function\n";
print STDERR " (see koffice/libs/main/KoDocInfoPropsFactory.cpp for an example)\n";
}
$_ = "K_PLUGIN_FACTORY($factory, registerPlugin<$plugin>();)\n";
}
if (/([A-Za-z_]*)::createPartObject/) {
$factory = $1;
$looking_for_plugin = 1; # the "new FooPart" must be somewhere nearby
}
if ($looking_for_plugin && /\s*new \s*([A-Za-z]+)/) {
$plugin = $1;
$looking_for_plugin = 0;
$_ = "K_PLUGIN_FACTORY($factory, registerPlugin<$plugin>();)\n" .
"K_EXPORT_PLUGIN($factory(\"TODO_componentName\", \"TODO_catalogName\"))\n" .
"// TODO: remove createPartObject method, and the factory class\n" . $_;
}
if (/:\s*public\s*KParts::Factory/) {
$_ = "// TODO: remove factory class\n" . $_;
}
# Factory without arguments
if (/K_EXPORT_COMPONENT_FACTORY\(\s*(\w*),\s*([^\(\)]*?)(?:\(\))?\s*\)/) {
my $libname_ignored = $1;
my $factory2 = $2;
die "Expected $factory, got $factory2" if (defined $factory && $factory ne $factory2);
$_ = "K_EXPORT_PLUGIN($factory2)\n";
}
if (/K_EXPORT_COMPONENT_FACTORY\(\s*(\w*),\s*(\w*)\(\s*([^\)]*)\s*\)\s*\)/) {
my $libname_ignored = $1;
my $factory2 = $2;
my $catalogname = $3;
die "Expected $factory, got $factory2" if ($factory ne $factory2);
$_ = "K_EXPORT_PLUGIN($factory($catalogname))\n";
}
# All in one call, like K_EXPORT_COMPONENT_FACTORY(spreadsheetshape, KGenericFactory<TableShapePlugin>("TableShape"))
if (/K_EXPORT_COMPONENT_FACTORY\s*\(\s*(\w*),\s*KGenericFactory\s*<(\w*)>\s*\(\s*(\"[^\"]*\")\s*\)\s*\)/) {
my $libname_ignored = $1;
my $plugin = $2;
my $factory = $plugin . "Factory";
my $catalogname = $3;
$_ = "K_PLUGIN_FACTORY($factory, registerPlugin<$plugin>();)\n";
$_ .= "K_EXPORT_PLUGIN($factory($catalogname))\n";
}
# Incremental fixing... can be removed later
$plugin = $1 if (/registerPlugin<(.*)>/);
$factory = $1 if (/K_PLUGIN_FACTORY\((\w*),/);
} $file;
# Now that we know the plugin name, fix its constructor signature, if by chance it's in the same file
if (defined $plugin) {
functionUtilkde::substInFile {
if (/${plugin}::$plugin/) {
if (s/QStringList/QVariantList/) {
} elsif (/(.*)\((QWidget\s*\*\s*[^ ,]*\s*,\s*QObject\s*\*\s*\w*)\)(.*)/) {
$_ = "$1($2, const QVariantList&)$3\n";
}
}
} $file;
my $header = $file;
$header =~ s/\.cpp$/.h/;
$header =~ s/\.cc$/.h/;
my $headerChanged = 0;
functionUtilkde::substInFile {
if (/${plugin}\(/) {
if (s/QStringList/QVariantList/) {
$headerChanged = 1;
} elsif (/(.*)\((QWidget\s*\*\s*[^ ,]*\s*,\s*QObject\s*\*\s*\w*[^,\)]*)\)(.*)/) {
$_ = "$1($2, const QVariantList&)$3\n";
$headerChanged = 1;
}
}
} $header;
if ($headerChanged) {
functionUtilkde::addIncludeInFile( $header, "QVariantList");
}
}
}
functionUtilkde::diffFile( @ARGV );
|