.kdevdlg -> .ui converter

Bernd Gehrmann bernd at physik.hu-berlin.de
Sun Oct 15 21:08:03 UTC 2000


I just felt like hacking a small script that converts .kdevdlg 
files into .ui files :-) It's very primitive and incomplete, but
nevertheless it could be useful for some people...
 
I don't have the time to maintain it, but maybe someone else here?
 
Usage:
  kdevdlg2ui < foo.kdevdlg > foo.ui
 
Bernd.  
-------------- next part --------------
#!/usr/bin/perl

# Copyright (c) 2000 Bernd Gehrmann <bernd at physik.hu-berlin.de>
# 
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# 
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# 
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


print "<!DOCTYPE UI><UI>\n";

while (<STDIN>) {
        parseItem("") if (/\s*item (.*)\s*/);
}

print "</UI>";
exit 0;


sub parseItem {

        my ( $className ) = @_;
        my ( $line, $firstitem );
        my ( $name, $varname, $x, $y, $width, $height, $text, $title );
        my ( $minvalue, $maxvalue, $insertionpolicy, $orientation, $isreadonly );
        my ( $vscrollbarmode, $hscrollbarmode );
        my ( $items, $columns );

        $firstitem = 1;
        $line = <STDIN>;
        if (! ($line =~ /^\s*\{\s*$/) ) {
                die "Unexpected line: $line\n";
        }

        while ($line = <STDIN>) {

                if ( ($line =~ /^\s*\}\s*$/ || $line =~ /^\s*item\s*(.*)\s*$/) && $firstitem) {
                        # Flush declaration
                        $firstitem = 0;
                        if (!$className) {
                                print "<class>$name</class>\n";
                                $className = "QDialog";
                        }
                        $className = "QFrame" if ($className eq "KSeparator");
                        $name = $varname unless $varname eq "this";
                        print "<widget>\n<class>$className</class>\n";
                        print "<property stdset=\"1\">\n";
                        print "<name>name</name>\n<cstring>$name</cstring>\n";
                        print "</property>\n";
                        print "<property stdset=\"1\">\n";
                        print "<name>geometry</name>\n<rect>";
                        print "<x>$x</x><y>$y</y><width>$width</width><height>$height</height>\n";
                        print "</rect></property>\n";
                        $varname = null; $name = null; 
                        $x = null; $y = null; $width = null; $height = $null;
                        dumpProp("text", "string", $text); $text = null;
                        dumpProp("title", "string", $title); $title = null;
                        dumpProp("minValue", "number", $minvalue); $minvalue = null;
                        dumpProp("maxValue", "number", $maxvalue); $maxvalue = null;
                        dumpProp("insertionPolicy", "enum", $insertionpolicy); $insertionpolicy = null;
                        dumpProp("orientation", "enum", $orientation); $orientation = null;
                        dumpProp("readOnly", "bool", $isreadonly); $isreadonly = null;
                        dumpProp("vScrollBarMode", "enum", $vscrollbarmode); $vscrollbarmode = null;
                        dumpProp("hScrollBarMode", "enum", $hscrollbarmode); $hscrollbarmode = null;
                        dumpList("item", $items); $items = null;
                        dumpList("column", $columns); $columns = null;
                }

                if ($line =~ /^\s*\}\s*$/) {
                        # End of widget
                        print "</widget>\n";
                        return;
                } elsif ($line =~ /^\s*item\s*(.*)\s*$/) {
                        parseItem($1);
                } elsif ($line =~ /^\s*Name=\"(.*)\s*\"$/) {
                        $name = $1;
                } elsif ($line =~ /^\s*VarName=\"(.*)\s*\"$/) {
                        $varname = $1;
                } elsif ($line =~ /^\s*X=\"(.*)\s*\"$/) {
                        $x = $1;
                } elsif ($line =~ /^\s*Y=\"(.*)\s*\"$/) {
                        $y = $1;
                } elsif ($line =~ /^\s*Width=\"(.*)\s*\"$/) {
                        $width = $1;
                } elsif ($line =~ /^\s*Height=\"(.*)\s*\"$/) {
                        $height = $1;
                } elsif ($line =~ /^\s*Text=\"(.*)\s*\"$/) {
                        $text = $1;
                } elsif ($line =~ /^\s*Title=\"(.*)\s*\"$/) {
                        $title = $1;
                } elsif ($line =~ /^\s*MinValue=\"(.*)\s*\"$/) {
                        $minvalue = $1;
                } elsif ($line =~ /^\s*MaxValue=\"(.*)\s*\"$/) {
                        $maxvalue = $1;
                } elsif ($line =~ /^\s*InsertionPolicy=\"(.*)\s*\"$/) {
                        $insertionpolicy = $1;
                } elsif ($line =~ /^\s*Orientation=\"(.*)\s*\"$/) {
                        $orientation = $1;
                } elsif ($line =~ /^\s*isReadOnly=\"(.*)\s*\"$/) {
                        $isreadonly = $1;
                } elsif ($line =~ /^\s*vScrollBarMode=\"(.*)\s*\"$/) {
                        $vscrollbarmode = $1;
                } elsif ($line =~ /^\s*hScrollBarMode=\"(.*)\s*\"$/) {
                        $hscrollbarmode = $1;
                } elsif ($line =~ /^\s*Entries=\"(.*)\s*\"$/) {
                        $items = $1;
                } elsif ($line =~ /^\s*Columns=\"(.*)\s*\"$/) {
                        $columns = $1;
                }
        }

        die "Unexpected end of file\n";

}


sub dumpProp {

        my ( $var, $type, $value ) = @_;

        if ($value) {
                print "<property stdset=\"1\">\n";
                print "<name>$var</name>\n<$type>$value</$type>\n";
                print "</property>";
        }

}


sub dumpList {

        my ( $var, $entries ) = @_;

        if ($entries) {
                my @entrylist = split(/\\n/, $entries);
                foreach $entry (@entrylist) {
                        print "<$var><property>\n";
                        print "<name>text</name><string>$entry</string>\n";
                        print "</property></$var>\n";
                }
        }

}



More information about the KDevelop-devel mailing list