From 5fd4fb1a51b3b8541e204159b6151dafb76a2a41 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 21 Feb 2013 15:09:37 -0600 Subject: Second part of prior commit --- kmymoney2/widgets/maketdewidgets.in | 197 ++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100755 kmymoney2/widgets/maketdewidgets.in (limited to 'kmymoney2/widgets/maketdewidgets.in') diff --git a/kmymoney2/widgets/maketdewidgets.in b/kmymoney2/widgets/maketdewidgets.in new file mode 100755 index 0000000..364ca1b --- /dev/null +++ b/kmymoney2/widgets/maketdewidgets.in @@ -0,0 +1,197 @@ +#!@PERL@ + +# copied from KDELIBS 3.1.4 +# modified for usage with KMyMoney + +use strict; +use vars qw($group $incpath $name $out @includes $init $destroy %widgets); + +sub usage +{ + print STDERR "$_[0]\n" if @_; + print STDERR < ...] +Generates a Qt designer-plugin for the widget set defined in widget spec +or STDIN if no filename is given + +Options: + -g default widget group name to display in designer + (default: KDE) + -i path to prepend to include file (default: none) + -n name of the plugin class to generate + (default: WidgetsPlugin) + -o write output to filename (default: STDOUT) +EOT + exit 1; +} + +sub warning($) { print STDERR "Warning: $_[0]\n" } + +my ($class, %defs); +sub addwidget +{ + return if $class =~ /^(Includes|Init|Destroy)$/; + if(! exists $defs{IncludeFile}) { + $defs{IncludeFile} = join('/', $incpath, lc "$class.h") if ($incpath ne ""); + $defs{IncludeFile} = lc "$class.h" unless ($incpath ne ""); + } + $defs{ImplClass} = $class unless exists $defs{ImplClass}; + $defs{Group} = $group unless exists $defs{Group}; + $defs{ToolTip} = $class unless exists $defs{ToolTip}; + $defs{WhatsThis} = $class unless exists $defs{Long}; + $defs{IconSet} = lc "$class.png" unless exists $defs{IconSet}; + $defs{ConstructorArgs} = '(parent, name)' unless exists $defs{ConstructorArgs}; + $defs{IsContainer} = $defs{IsContainer} ? 'true' : 'false'; + $widgets{$class} = { %defs }; +} + +$group = 'KDE'; +$incpath = ""; + +while ($ARGV[0] =~ /^-/) +{ + my $opt = shift @ARGV; + usage "missing parameter for $opt" unless @ARGV; + if ($opt eq '-g') { $group = shift @ARGV } + elsif ($opt eq '-n') { $name = shift @ARGV } + elsif ($opt eq '-o') { $out = shift @ARGV } + elsif ($opt eq '-i') { $incpath = shift @ARGV } + else { usage "Unknown option $opt" } +} + +$name = "${group}WidgetsPlugin" unless $name; +warning "classname changed to \"$name\"" + if $name =~ s/(^[^A-Za-z_]+|[^A-Za-z0-9_])/_/g; + +while (<>) +{ + chomp; + next if /^(#|\s*$)/; + + if (/^\s*\[([A-Za-z_][A-Za-z0-9_:]*)\]\s*$/) + { + addwidget if $class; + %defs = {}; + $class = $1; + next; + } + elsif (/^\s*\[(.*)\]\s*$/) { die "Invalid class name \"$1\"" } + die "Not in a widget definition" unless $class; + if ($class eq 'Includes') { push @includes, $_ } + elsif ($class eq 'Init') { $init .= "\n\t$_" } + elsif ($class eq 'Destroy') { $destroy .= "\n\t$_" } + elsif (/^\s*(IncludeFile|ImplClass|Group|ToolTip|WhatsThis|IconSet|ConstructorArgs|IsContainer)\s*=\s*(.*)\s*/) + { + $defs{$1} = $2; + } + else { die "Syntax error on line $." } +} +addwidget if $class; + +warning "Nothing to do", exit 0 unless %widgets; + +my @keys = sort keys %widgets; + +if ($out) { open OUT, ">$out" or die "Can't open $out for writing" } +else { open OUT, ">&STDOUT" } + +(my $scriptname = $0) =~ s|^.*/||; +print OUT < +// for pixmap search +#include + +EOT + +print OUT map { "#include \"$_\"\n" } @includes, map { $widgets{$_}->{IncludeFile} } @keys; + +print OUT < WidgetInfos; + WidgetInfos m_widgets; +}; + +${name}::$name() +{ + WidgetInfo widget; +EOT + +print OUT map { my $w = $_; "\n", (map { my $attr = ucfirst $_; <{IsContainer}; + m_widgets.insert("$_", widget); +EOT + +print OUT <{ImplClass}$widgets{$_}->{ConstructorArgs}; +EOT + +print OUT <