From 90825e2392b2d70e43c7a25b8a3752299a933894 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- korundum/rubylib/rbkconfig_compiler/Makefile.am | 28 + korundum/rubylib/rbkconfig_compiler/README.dox | 251 ++++ korundum/rubylib/rbkconfig_compiler/TODO | 1 + korundum/rubylib/rbkconfig_compiler/autoexample.rb | 49 + korundum/rubylib/rbkconfig_compiler/checkkcfg.pl | 83 ++ korundum/rubylib/rbkconfig_compiler/example.kcfg | 55 + korundum/rubylib/rbkconfig_compiler/example.rb | 40 + .../rbkconfig_compiler/exampleprefs_base.kcfgc | 18 + .../rubylib/rbkconfig_compiler/general_base.ui | 46 + korundum/rubylib/rbkconfig_compiler/kcfg.xsd | 191 +++ .../rubylib/rbkconfig_compiler/myoptions_base.ui | 35 + .../rbkconfig_compiler/rbkconfig_compiler.cpp | 1330 ++++++++++++++++++++ .../rubylib/rbkconfig_compiler/tests/Makefile.am | 40 + .../rubylib/rbkconfig_compiler/tests/myprefs.rb | 5 + .../rubylib/rbkconfig_compiler/tests/test1.kcfg | 55 + .../rubylib/rbkconfig_compiler/tests/test1.kcfgc | 18 + .../rubylib/rbkconfig_compiler/tests/test1main.rb | 4 + .../rubylib/rbkconfig_compiler/tests/test2.kcfg | 78 ++ .../rubylib/rbkconfig_compiler/tests/test2.kcfgc | 11 + .../rubylib/rbkconfig_compiler/tests/test2main.rb | 5 + .../rubylib/rbkconfig_compiler/tests/test3.kcfg | 26 + .../rubylib/rbkconfig_compiler/tests/test3.kcfgc | 12 + .../rubylib/rbkconfig_compiler/tests/test3main.rb | 4 + .../rubylib/rbkconfig_compiler/tests/test4.kcfg | 42 + .../rubylib/rbkconfig_compiler/tests/test4.kcfgc | 11 + .../rubylib/rbkconfig_compiler/tests/test4main.rb | 4 + .../rubylib/rbkconfig_compiler/tests/test5.kcfg | 42 + .../rubylib/rbkconfig_compiler/tests/test5.kcfgc | 11 + .../rubylib/rbkconfig_compiler/tests/test5main.rb | 4 + 29 files changed, 2499 insertions(+) create mode 100644 korundum/rubylib/rbkconfig_compiler/Makefile.am create mode 100644 korundum/rubylib/rbkconfig_compiler/README.dox create mode 100644 korundum/rubylib/rbkconfig_compiler/TODO create mode 100644 korundum/rubylib/rbkconfig_compiler/autoexample.rb create mode 100755 korundum/rubylib/rbkconfig_compiler/checkkcfg.pl create mode 100644 korundum/rubylib/rbkconfig_compiler/example.kcfg create mode 100644 korundum/rubylib/rbkconfig_compiler/example.rb create mode 100644 korundum/rubylib/rbkconfig_compiler/exampleprefs_base.kcfgc create mode 100644 korundum/rubylib/rbkconfig_compiler/general_base.ui create mode 100644 korundum/rubylib/rbkconfig_compiler/kcfg.xsd create mode 100644 korundum/rubylib/rbkconfig_compiler/myoptions_base.ui create mode 100644 korundum/rubylib/rbkconfig_compiler/rbkconfig_compiler.cpp create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/Makefile.am create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/myprefs.rb create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test1.kcfg create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test1.kcfgc create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test1main.rb create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test2.kcfg create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test2.kcfgc create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test2main.rb create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test3.kcfg create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test3.kcfgc create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test3main.rb create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test4.kcfg create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test4.kcfgc create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test4main.rb create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test5.kcfg create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test5.kcfgc create mode 100644 korundum/rubylib/rbkconfig_compiler/tests/test5main.rb (limited to 'korundum/rubylib/rbkconfig_compiler') diff --git a/korundum/rubylib/rbkconfig_compiler/Makefile.am b/korundum/rubylib/rbkconfig_compiler/Makefile.am new file mode 100644 index 00000000..492c6882 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/Makefile.am @@ -0,0 +1,28 @@ +SUBDIRS = . tests + +RBUIC=rbuic + +%.rb: %.ui + $(RBUIC) -tr ${UIC_TR} -kde $*.ui -o $@ + +exampleprefs_base.rb: $(srcdir)/example.kcfg rbkconfig_compiler $(srcdir)/exampleprefs_base.kcfgc + ./rbkconfig_compiler $(srcdir)/example.kcfg $(srcdir)/exampleprefs_base.kcfgc + +AM_CPPFLAGS = -I$(top_srcdir)/kdecore -I$(top_srcdir) $(all_includes) + +bin_PROGRAMS = rbkconfig_compiler + +rbkconfig_compiler_LDFLAGS = $(all_libraries) $(KDE_RPATH) +rbkconfig_compiler_LDADD = $(LIB_KDECORE) +rbkconfig_compiler_SOURCES = rbkconfig_compiler.cpp + +METASOURCES = AUTO + +TESTFILES = test1.kcfg test2.kcfg test3.kcfg test4.kcfg test5.kcfg + +check-local: + for i in $(TESTFILES); \ + do xmllint --noout --schema $(srcdir)/kcfg.xsd $(srcdir)/tests/$$i; \ + perl $(top_srcdir)/korundum/rubylib/rbkconfig_compiler/checkkcfg.pl \ + $(top_srcdir)/korundum/rubylib/rbkconfig_compiler/tests/$$i; done + diff --git a/korundum/rubylib/rbkconfig_compiler/README.dox b/korundum/rubylib/rbkconfig_compiler/README.dox new file mode 100644 index 00000000..97da4dc9 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/README.dox @@ -0,0 +1,251 @@ +/** +\page rbkconfig_compiler The KDE Configuration Compiler for Ruby + +rbkconfig_compiler generates Ruby source code from an XML file containing +information about configuration options (.kcfg) and a file that provides +the code generation options (.kcfgc) The generated class is based on +KDE::ConfigSkeleton and provides an API for the application to access its +configuration data. + +

XML description of the configuration options

+ +The structure of the .kcfg file is described by its DTD kcfg.dtd. + +The \ tag contains the name of the configuration file described. +Omitting the name will make the generated class use the default configuration +file ("rc"). + +The remaining entries in the XML file are grouped by the tag \ +which describes the corresponding group in the configuration file. + +The individual entries must have at least a name or a key. The name is used to +create accessor and modifier functions. It's also used as the key in the config +file. If \ is given, but not \, the name is constructed by removing +all spaces from \. + +An entry must also have a type. The list of allowable types is +specified in the DTD and loosely follows the list of types supported +by the Qt::Variant with exception of the clearly binary types +(e.g. Pixmap, Image...) which are not supported. Besides those basic +type the following special types are supported: + +- Path This is a string that is specially treated as a file-path. + In particular paths in the home directory are prefixed with $HOME in + when being stored in the configuration file. + +- Enum This indicates an enumeration. The possible enum values should + be provided via the \ tag. Enum values are accessed as integers + by the application but stored as string in the configuration file. This + makes it possible to add more values at a later date without breaking + compatibility. + +- IntList This indicates a list of integers. This information is provided + to the application as an Array of Integers. Useful for storing Qt::Splitter + geometries. + +An entry can optionally have a default value which is used as default when +the value isn't specified in any config file. Default values are interpreted +as literal constant values. If a default value needs to be computed +or if it needs to be obtained from a function call, the \ tag +should contain the code="true" attribute. The contents of the \ +tag is then considered to be a ruby expression. + +Additional code for computing default values can be provided via +the \ tag. The contents of the \ tag is inserted as-is. A +typical use for this is to compute a common default value which can +then be referenced by multiple entries that follow. + +

Code generation options

+ +The options for generating the Ruby sources are read from the file with the +extension .kcfgc. To generate a class add the corresponding kcfgc file to the +SOURCES line in the Makefile.am. + +The following options are read from the kcfgc file: + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDefaultDescription
Filestringprogramname.kcfgName of kcfg file containing the options the class is generated for
NameSpacestring-Optional namespace for generated class
ClassNamestring-Name of generated class (required)
InheritsstringKConfigSkeletonClass the generated class inherits from. This class must inherit + KConfigSkeleton.
Visibilitystring-Inserts visibility directive (for example KDE_EXPORT) between "class" keyword and class + name in header file
SingletonboolfalseGenerated class is a singleton.
CustomAdditionsbool-
MemberVariablesstring: public|protected|privateprivateC++ access modifier used for memeber variables holding the configuration + valuse
IncludeFilescomma separated list of strings-Names of files to be included in the header of the generated class
Mutatorstrue, false or a comma seperated list of options-If true, mutator functions for all configuration options are generated. + If false, no mutator functions are generated. If a list is provided, + mutator functions are generated for the options that are listed.
ItemAccessorsboolfalseGenerate accessor functions for the KConfigSkeletonItem objects + corresponding to the configuration options. If SetUserTexts is set, + ItemAccessors also has to be set.
SetUserTextsboolfalseSet the label and whatthis texts of the items from the kcfg file.If + SetUserTexts is set, ItemAccessors also has to be set.
GlobalEnumsboolfalseIf set to true all choices of Enum items will be created in the global + scope of the generated class. If set to false, each Enum item will get an own + namespace for its choices.
+ + +

Advanced options

+ +There are several possibilities to parameterize entries. + +- Parameterized entries + +An entry can be parameterized using a fixed range parameter specified with +the \ tag. Such parameter can either be an Enum or an int. An Enum +parameter should specify the possible enumeration values with the \ +tag. An int parameter should specify its maximum value. Its minimum value +is always 0. + +A parameterized entry is expanded to a number of entries, one for each +value in the parameter range. The name and key should contain a reference +to the parameter in the form of $(parameter-name). When expanding the entries +the $(parameter-name) part is replaced with the value of the parameter. +In the case of an Enum parameter it is replaced with the name of the +enumuration value. In the case of an int parameter it is replaced with +the numeric value of the parameter. + +Parameterized entries all share the same default value unless different +default values have been specified for specific parameter values. +This can be done with the param= attribute of the \. When a +param attribute is specified the default value only applies to that +particular parameter value. + +Example 1: +\verbatim + + + #ff0000 + #00ff00 + #0000ff + #ffff00 + +\endverbatim + +The above describes 4 color configuration entries with the following defaults: + +color_0=#ff0000 +color_1=#00ff00 +color_2=#0000ff +color_3=#ffff00 + +The configuration options will be accessible to the application via +a color(colorIndex) and a +setColor(colorIndex, v) method. + +Example 2: +\verbatim + + + + Explosion + Crash + Missile + + + boom.wav + crash.wav + missile.wav + +\endverbatim + +The above describes 3 string configuration entries with the following defaults: + +sound_Explosion=boom.wav +sound_Crash=crash.wav +sound_Missile=missile.wav + +The configuration options will be accessible to the application via +a sound(soundEvent) and a +setSound(soundEvent, v) method. + +- Parameterized groups + +...STILL TODO... + + + + + +If you have questions or comments please contact Cornelius Schumacher + or Waldo Bastian + +For Ruby specific questions please contact Richard Dale + +*/ diff --git a/korundum/rubylib/rbkconfig_compiler/TODO b/korundum/rubylib/rbkconfig_compiler/TODO new file mode 100644 index 00000000..db4137ed --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/TODO @@ -0,0 +1 @@ +- Support linebreaks in whasthis texts in the kcfg file. diff --git a/korundum/rubylib/rbkconfig_compiler/autoexample.rb b/korundum/rubylib/rbkconfig_compiler/autoexample.rb new file mode 100644 index 00000000..8526c93d --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/autoexample.rb @@ -0,0 +1,49 @@ +=begin + This file is part of KDE. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +=end + +require 'Korundum' +require 'exampleprefs_base.rb' +require 'general_base.rb' +require 'myoptions_base.rb' + + aboutData = KDE::AboutData.new( "example", I18N_NOOP("autoconfig example"), "0.1" ) + aboutData.addAuthor( "Cornelius Schumacher", nil, "schumacher@kde.org" ) + + KDE::CmdLineArgs.init( ARGV, aboutData ) + + app = KDE::Application.new + + configSkeleton = ExamplePrefsBase.new( "dummy1", "dummy2" ) + configSkeleton.readConfig() + + dialog = KDE::ConfigDialog.new( nil, "settings", configSkeleton ) + + general = GeneralBase.new(nil) + dialog.addPage( general, app.i18n("General"), "General", "" ) + + myOptions = MyOptionsBase.new( nil ) + dialog.addPage( myOptions, app.i18n("MyOptions"), "MyOptions", "" ) + + app.mainWidget = dialog + + dialog.show() + + app.exec diff --git a/korundum/rubylib/rbkconfig_compiler/checkkcfg.pl b/korundum/rubylib/rbkconfig_compiler/checkkcfg.pl new file mode 100755 index 00000000..2eddbeee --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/checkkcfg.pl @@ -0,0 +1,83 @@ +#!/usr/bin/perl + +if ( @ARGV != 1 ) { + print STDERR "Missing arg: filename\n"; + exit 1; +} + +$file = $ARGV[0]; + +$file =~ /^(.*)\.[^\.]*$/; +$filebase = $1; + +$file_h = "$filebase.h"; +$file_cpp = "$filebase.cpp"; + +$kcfgc = $file . "c"; + +$cmd = "./kconfig_compiler $file $kcfgc"; + +#print "CMD $cmd\n"; + +if ( system( $cmd ) != 0 ) { + print STDERR "Unable to run kconfig_compiler\n"; + exit 1; +} + +checkfile( $file_h ); +checkfile( $file_cpp ); + +exit 0; + +sub checkfile() +{ + my $file = shift; + + $file =~ /\/([^\/]*)$/; + my $filename = $1; + + print "Checking '$filename':\n"; + + my @ref; + if ( !open( REF, "$file.ref" ) ) { + print STDERR "Unable to open $file.ref\n"; + exit 1; + } + while( ) { + push @ref, $_; + } + close REF; + + if ( !open( READ, $filename ) ) { + print STDERR "Unable to open $filename\n"; + exit 1; + } + + $error = 0; + $i = 0; + $line = 1; + while( ) { + $out = $_; + $ref = @ref[$i++]; + + if ( $out ne $ref ) { + $error++; + print " Line $line: Expected : $ref"; + print " Line $line: Compiler output : $out"; + } + + $line++; + } + + close READ; + + if ( $error > 0 ) { + print "\n FAILED: $error errors found.\n"; + if ( $error > 5 ) { + system( "diff -u $file.ref $filename" ); + } + exit 1; + } else { + print " OK\n"; + } +} diff --git a/korundum/rubylib/rbkconfig_compiler/example.kcfg b/korundum/rubylib/rbkconfig_compiler/example.kcfg new file mode 100644 index 00000000..89d1e646 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/example.kcfg @@ -0,0 +1,55 @@ + + + qdir.h + + + + + + + + true + + + + 5 + + + + And this is a longer description of this option. Just wondering, how will the translations of those be handled? + + + + + + One + + + + + + Default String + + + + Qt::Dir.homeDirPath()+".hidden_file" + + + + 10 + + + up,down + + + + + 1 + + + diff --git a/korundum/rubylib/rbkconfig_compiler/example.rb b/korundum/rubylib/rbkconfig_compiler/example.rb new file mode 100644 index 00000000..d7ef38b1 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/example.rb @@ -0,0 +1,40 @@ +=begin + This file is part of KDE. + + Copyright (c) 2003 Cornelius Schumacher + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +=end + +require 'Korundum' +require 'exampleprefs_base.rb' + + aboutData = KDE::AboutData.new( "example", I18N_NOOP("cfgc example"), "0.1" ) + aboutData.addAuthor( "Cornelius Schumacher", nil, "schumacher@kde.org" ) + + KDE::CmdLineArgs.init( ARGV, aboutData ) + + app = KDE::Application.new + + prefs = ExamplePrefsBase.new("Trans1", "Folder2") + + prefs.readConfig() + + prefs.setAnotherOption(17) + + + qWarning("Another Option = %d" % prefs.anotherOption()) + qWarning("Another Option2 = %d" % prefs.anotherOption2()) diff --git a/korundum/rubylib/rbkconfig_compiler/exampleprefs_base.kcfgc b/korundum/rubylib/rbkconfig_compiler/exampleprefs_base.kcfgc new file mode 100644 index 00000000..957ed912 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/exampleprefs_base.kcfgc @@ -0,0 +1,18 @@ +# Code generation options for kconfig_compiler +ClassName=ExamplePrefsBase +# +# Singleton=false +# +# Inherits=KConfigSkeleton +# +# IncludeFiles=libkdepim/kpimprefs.h +# +# MemberVariables=public +# +### The following line includes the file exampleprefs_base_addon.h +### It can be used to add extra functions and variables to the +### class. +# CustomAdditions=true +# +### Provide setFooBar(int) style functions +Mutators=true diff --git a/korundum/rubylib/rbkconfig_compiler/general_base.ui b/korundum/rubylib/rbkconfig_compiler/general_base.ui new file mode 100644 index 00000000..9b41370c --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/general_base.ui @@ -0,0 +1,46 @@ + +GeneralBase + + + GeneralBase + + + + 0 + 0 + 600 + 486 + + + + AutoExampleDialog + + + + unnamed + + + + kcfg_OneOption + + + OneOption + + + + + kcfg_AnotherOption2 + + + + + textLabel1 + + + AnotherOption: + + + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/kcfg.xsd b/korundum/rubylib/rbkconfig_compiler/kcfg.xsd new file mode 100644 index 00000000..61450d25 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/kcfg.xsd @@ -0,0 +1,191 @@ + + + + + + + + Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> + Copyright (c) 2003 Waldo Bastian <bastian@kde.org> + Copyright (c) 2003 Zack Rusin <zack@kde.org> + Copyright (c) 2004 Frans Englich <frans.englich@telia.com> + + Permission to use, copy, modify and distribute this DTD + and its accompanying documentation for any purpose and without fee + is hereby granted in perpetuity, provided that the above copyright + notice and this paragraph appear in all copies. The copyright + holders make no representation about the suitability of the DTD for + any purpose. It is provided "as is" without expressed or implied + warranty. + + + + + + + A Schema for KDE's KConfigXT XML format. It is similar to the DTD + found at: + + http://www.kde.org/standards/kcfg/1.0/kcfg.dtd + + Documents valid against the Schema version are backwards compatible + to the DTD. Validating against the Schema instead of the DTD is + recommended, since the former provides better validation. + + A document instance of this Schema should have a declaration + looking like this: + + + + + + + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/myoptions_base.ui b/korundum/rubylib/rbkconfig_compiler/myoptions_base.ui new file mode 100644 index 00000000..3c0c2e6c --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/myoptions_base.ui @@ -0,0 +1,35 @@ + +MyOptionsBase + + + MyOptionsBase + + + + 0 + 0 + 600 + 486 + + + + + unnamed + + + + textLabel1 + + + MyString: + + + + + kcfg_MyString + + + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/rbkconfig_compiler.cpp b/korundum/rubylib/rbkconfig_compiler/rbkconfig_compiler.cpp new file mode 100644 index 00000000..6274e4bf --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/rbkconfig_compiler.cpp @@ -0,0 +1,1330 @@ +// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; -*- +/* + This file is part of KDE. + + Copyright (c) 2003 Cornelius Schumacher + Copyright (c) 2003 Waldo Bastian + Copyright (c) 2003 Zack Rusin + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static const KCmdLineOptions options[] = +{ + { "d", 0, 0 }, + { "directory ", I18N_NOOP("Directory to generate files in"), "." }, + { "+file.kcfg", I18N_NOOP("Input kcfg XML file"), 0 }, + { "+file.kcfgc", I18N_NOOP("Code generation options file"), 0 }, + KCmdLineLastOption +}; + + +bool globalEnums; +bool itemAccessors; +QStringList allNames; +QRegExp *validNameRegexp; + +class CfgEntry +{ + public: + struct Choice + { + QString name; + QString label; + QString whatsThis; + }; + + CfgEntry( const QString &group, const QString &type, const QString &key, + const QString &name, const QString &label, + const QString &whatsThis, const QString &code, + const QString &defaultValue, const QValueList &choices, + bool hidden ) + : mGroup( group ), mType( type ), mKey( key ), mName( name ), + mLabel( label ), mWhatsThis( whatsThis ), mCode( code ), + mDefaultValue( defaultValue ), + mChoices( choices ), mHidden( hidden ) + { + } + + void setGroup( const QString &group ) { mGroup = group; } + QString group() const { return mGroup; } + + void setType( const QString &type ) { mType = type; } + QString type() const { return mType; } + + void setKey( const QString &key ) { mKey = key; } + QString key() const { return mKey; } + + void setName( const QString &name ) { mName = name; } + QString name() const { return mName; } + + void setLabel( const QString &label ) { mLabel = label; } + QString label() const { return mLabel; } + + void setWhatsThis( const QString &whatsThis ) { mWhatsThis = whatsThis; } + QString whatsThis() const { return mWhatsThis; } + + void setDefaultValue( const QString &d ) { mDefaultValue = d; } + QString defaultValue() const { return mDefaultValue; } + + void setCode( const QString &d ) { mCode = d; } + QString code() const { return mCode; } + + void setMinValue( const QString &d ) { mMin = d; } + QString minValue() const { return mMin; } + + void setMaxValue( const QString &d ) { mMax = d; } + QString maxValue() const { return mMax; } + + void setParam( const QString &d ) { mParam = d; } + QString param() const { return mParam; } + + void setParamName( const QString &d ) { mParamName = d; } + QString paramName() const { return mParamName; } + + void setParamType( const QString &d ) { mParamType = d; } + QString paramType() const { return mParamType; } + + void setChoices( const QValueList &d ) { mChoices = d; } + QValueList choices() const { return mChoices; } + + void setParamValues( const QStringList &d ) { mParamValues = d; } + QStringList paramValues() const { return mParamValues; } + + void setParamDefaultValues( const QStringList &d ) { mParamDefaultValues = d; } + QString paramDefaultValue(int i) const { return mParamDefaultValues[i]; } + + void setParamMax( int d ) { mParamMax = d; } + int paramMax() const { return mParamMax; } + + bool hidden() const { return mHidden; } + + void dump() const + { + kdDebug() << "" << endl; + kdDebug() << " group: " << mGroup << endl; + kdDebug() << " type: " << mType << endl; + kdDebug() << " key: " << mKey << endl; + kdDebug() << " name: " << mName << endl; + kdDebug() << " label: " << mLabel << endl; +// whatsthis + kdDebug() << " code: " << mCode << endl; +// kdDebug() << " values: " << mValues.join(":") << endl; + + if (!param().isEmpty()) + { + kdDebug() << " param name: "<< mParamName << endl; + kdDebug() << " param type: "<< mParamType << endl; + kdDebug() << " paramvalues: " << mParamValues.join(":") << endl; + } + kdDebug() << " default: " << mDefaultValue << endl; + kdDebug() << " hidden: " << mHidden << endl; + kdDebug() << " min: " << mMin << endl; + kdDebug() << " max: " << mMax << endl; + kdDebug() << "" << endl; + } + + private: + QString mGroup; + QString mType; + QString mKey; + QString mName; + QString mLabel; + QString mWhatsThis; + QString mCode; + QString mDefaultValue; + QString mParam; + QString mParamName; + QString mParamType; + QValueList mChoices; + QStringList mParamValues; + QStringList mParamDefaultValues; + int mParamMax; + bool mHidden; + QString mMin; + QString mMax; +}; + + +static QString varName(const QString &n) +{ + QString result = "@"+n; + result[1] = result[1].lower(); + return result; +} + +static QString enumName(const QString &n) +{ + QString result = "Enum"+n; + result[4] = result[4].upper(); + return result; +} + +static QString enumValue(const QString &n) +{ + QString result = n; + result[0] = result[0].upper(); + return result; +} + +static QString setFunction(const QString &n) +{ + QString result = "set"+n; + result[3] = result[3].upper(); + return result; +} + + +static QString getFunction(const QString &n) +{ + QString result = n; + result[0] = result[0].lower(); + return result; +} + + +static void addQuotes( QString &s ) +{ + if ( s.left( 1 ) != "\"" ) s.prepend( "\"" ); + if ( s.right( 1 ) != "\"" ) s.append( "\"" ); +} + +static QString quoteString( const QString &s ) +{ + QString r = s; + r.replace( "\\", "\\\\" ); + r.replace( "\"", "\\\"" ); + r.replace( "\r", "" ); + r.replace( "\n", "\\n\"\n\"" ); + return "\"" + r + "\""; +} + +static QString literalString( const QString &s ) +{ + bool isAscii = true; + for(int i = s.length(); i--;) + if (s[i].unicode() > 127) isAscii = false; + + return quoteString(s); + +// if (isAscii) +// return "QString::fromLatin1( " + quoteString(s) + " )"; +// else +// return "QString::fromUtf8( " + quoteString(s) + " )"; +} + +static QString dumpNode(const QDomNode &node) +{ + QString msg; + QTextStream s(&msg, IO_WriteOnly ); + node.save(s, 0); + + msg = msg.simplifyWhiteSpace(); + if (msg.length() > 40) + return msg.left(37)+"..."; + return msg; +} + +static QString filenameOnly(QString path) +{ + int i = path.findRev('/'); + if (i >= 0) + return path.mid(i+1); + return path; +} + +static void preProcessDefault( QString &defaultValue, const QString &name, + const QString &type, + const QValueList &choices, + QString &code ) +{ + if ( type == "String" && !defaultValue.isEmpty() ) { + defaultValue = literalString(defaultValue); + + } else if ( type == "Path" && !defaultValue.isEmpty() ) { + defaultValue = literalString( defaultValue ); + + } else if ( type == "StringList" && !defaultValue.isEmpty() ) { + QTextStream rb( &code, IO_WriteOnly | IO_Append ); + if (!code.isEmpty()) + rb << endl; + +// rb << " QStringList default" << name << ";" << endl; + rb << " default" << name << " = []" << endl; + QStringList defaults = QStringList::split( ",", defaultValue ); + QStringList::ConstIterator it; + for( it = defaults.begin(); it != defaults.end(); ++it ) { + rb << " default" << name << " << \"" << *it << "\"" + << endl; + } + defaultValue = "default" + name; + + } else if ( type == "Color" && !defaultValue.isEmpty() ) { + QRegExp colorRe("\\d+,\\s*\\d+,\\s*\\d+"); + if (colorRe.exactMatch(defaultValue)) + { + defaultValue = "Qt::Color.new( " + defaultValue + " )"; + } + else + { + defaultValue = "Qt::Color.new( \"" + defaultValue + "\" )"; + } + + } else if ( type == "Enum" ) { + if ( !globalEnums ) { + QValueList::ConstIterator it; + for( it = choices.begin(); it != choices.end(); ++it ) { + if ( (*it).name == defaultValue ) { + defaultValue.prepend( enumName(name) + "_"); + break; + } + } + } + + } else if ( type == "IntList" ) { + QTextStream rb( &code, IO_WriteOnly | IO_Append ); + if (!code.isEmpty()) + rb << endl; + + rb << " default" << name << " = []" << endl; + QStringList defaults = QStringList::split( ",", defaultValue ); + QStringList::ConstIterator it; + for( it = defaults.begin(); it != defaults.end(); ++it ) { + rb << " default" << name << " << " << *it << "" + << endl; + } + defaultValue = "default" + name; + } +} + + +CfgEntry *parseEntry( const QString &group, const QDomElement &element ) +{ + bool defaultCode = false; + QString type = element.attribute( "type" ); + QString name = element.attribute( "name" ); + QString key = element.attribute( "key" ); + QString hidden = element.attribute( "hidden" ); + QString label; + QString whatsThis; + QString defaultValue; + QString code; + QString param; + QString paramName; + QString paramType; + QValueList choices; + QStringList paramValues; + QStringList paramDefaultValues; + QString minValue; + QString maxValue; + int paramMax = 0; + + QDomNode n; + for ( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement e = n.toElement(); + QString tag = e.tagName(); + if ( tag == "label" ) label = e.text(); + else if ( tag == "whatsthis" ) whatsThis = e.text(); + else if ( tag == "min" ) minValue = e.text(); + else if ( tag == "max" ) maxValue = e.text(); + else if ( tag == "code" ) code = e.text(); + else if ( tag == "parameter" ) + { + param = e.attribute( "name" ); + paramType = e.attribute( "type" ); + if ( param.isEmpty() ) { + kdError() << "Parameter must have a name: " << dumpNode(e) << endl; + return 0; + } + if ( paramType.isEmpty() ) { + kdError() << "Parameter must have a type: " << dumpNode(e) << endl; + return 0; + } + if ((paramType == "Int") || (paramType == "UInt")) + { + bool ok; + paramMax = e.attribute("max").toInt(&ok); + if (!ok) + { + kdError() << "Integer parameter must have a maximum (e.g. max=\"0\"): " << dumpNode(e) << endl; + return 0; + } + } + else if (paramType == "Enum") + { + QDomNode n2; + for ( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { + QDomElement e2 = n2.toElement(); + if (e2.tagName() == "values") + { + QDomNode n3; + for ( n3 = e2.firstChild(); !n3.isNull(); n3 = n3.nextSibling() ) { + QDomElement e3 = n3.toElement(); + if (e3.tagName() == "value") + { + paramValues.append( e3.text() ); + } + } + break; + } + } + if (paramValues.isEmpty()) + { + kdError() << "No values specified for parameter '" << param << "'." << endl; + return 0; + } + paramMax = paramValues.count()-1; + } + else + { + kdError() << "Parameter '" << param << "' has type " << paramType << " but must be of type int, uint or Enum." << endl; + return 0; + } + } + else if ( tag == "default" ) + { + if (e.attribute("param").isEmpty()) + { + defaultValue = e.text(); + if (e.attribute( "code" ) == "true") + defaultCode = true; + } + } + else if ( tag == "choices" ) { + QDomNode n2; + for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { + QDomElement e2 = n2.toElement(); + if ( e2.tagName() == "choice" ) { + QDomNode n3; + CfgEntry::Choice choice; + choice.name = e2.attribute( "name" ); + if ( choice.name.isEmpty() ) { + kdError() << "Tag requires attribute 'name'." << endl; + } + for( n3 = e2.firstChild(); !n3.isNull(); n3 = n3.nextSibling() ) { + QDomElement e3 = n3.toElement(); + if ( e3.tagName() == "label" ) choice.label = e3.text(); + if ( e3.tagName() == "whatsthis" ) choice.whatsThis = e3.text(); + } + choices.append( choice ); + } + } + } + } + + bool nameIsEmpty = name.isEmpty(); + if ( nameIsEmpty && key.isEmpty() ) { + kdError() << "Entry must have a name or a key: " << dumpNode(element) << endl; + return 0; + } + + if ( key.isEmpty() ) { + key = name; + } + + if ( nameIsEmpty ) { + name = key; + name.replace( " ", QString::null ); + } else if ( name.contains( ' ' ) ) { + kdWarning()<<"Entry '"< elements can't contain speces!"< paramMax)) + { + kdError() << "Index '" << i << "' for default value is out of range [0, "<< paramMax<<"]." << endl; + return 0; + } + + QString tmpDefaultValue = e.text(); + + if (e.attribute( "code" ) != "true") + preProcessDefault(tmpDefaultValue, name, type, choices, code); + + paramDefaultValues[i] = tmpDefaultValue; + } + } + } + + if (!validNameRegexp->exactMatch(name)) + { + if (nameIsEmpty) + kdError() << "The key '" << key << "' can not be used as name for the entry because " + "it is not a valid name. You need to specify a valid name for this entry." << endl; + else + kdError() << "The name '" << name << "' is not a valid name for an entry." << endl; + return 0; + } + + if (allNames.contains(name)) + { + if (nameIsEmpty) + kdError() << "The key '" << key << "' can not be used as name for the entry because " + "it does not result in a unique name. You need to specify a unique name for this entry." << endl; + else + kdError() << "The name '" << name << "' is not unique." << endl; + return 0; + } + allNames.append(name); + + if (!defaultCode) + { + preProcessDefault(defaultValue, name, type, choices, code); + } + + CfgEntry *result = new CfgEntry( group, type, key, name, label, whatsThis, + code, defaultValue, choices, + hidden == "true" ); + if (!param.isEmpty()) + { + result->setParam(param); + result->setParamName(paramName); + result->setParamType(paramType); + result->setParamValues(paramValues); + result->setParamDefaultValues(paramDefaultValues); + result->setParamMax(paramMax); + } + result->setMinValue(minValue); + result->setMaxValue(maxValue); + + return result; +} + +/** + Return parameter declaration for given type. +*/ +QString param( const QString &type ) +{ + if ( type == "String" ) return "const QString &"; + else if ( type == "StringList" ) return "const QStringList &"; + else if ( type == "Font" ) return "const QFont &"; + else if ( type == "Rect" ) return "const QRect &"; + else if ( type == "Size" ) return "const QSize &"; + else if ( type == "Color" ) return "const QColor &"; + else if ( type == "Point" ) return "const QPoint &"; + else if ( type == "Int" ) return "int"; + else if ( type == "UInt" ) return "uint"; + else if ( type == "Bool" ) return "bool"; + else if ( type == "Double" ) return "double"; + else if ( type == "DateTime" ) return "const QDateTime &"; + else if ( type == "Int64" ) return "Q_INT64"; + else if ( type == "UInt64" ) return "Q_UINT64"; + else if ( type == "IntList" ) return "const QValueList &"; + else if ( type == "Enum" ) return "int"; + else if ( type == "Path" ) return "const QString &"; + else if ( type == "Password" ) return "const QString &"; + else { + kdError() <<"rbkconfig_compiler does not support type \""<< type <<"\""<name() ) + "Item"; + + return "item" + e->name(); + +} + +QString newItem( const QString &type, const QString &name, const QString &key, + const QString &defaultValue, const QString ¶m = QString::null) +{ + QString t = "Item" + itemType( type ) + + ".new( currentGroup(), " + key + ", " + varName( name ) + param; + if ( type == "Enum" ) { + t += ".toInt"; + t += ", values" + name; + } else if ( type == "Path" ) { + t += ".toString"; + } else if ( type == "Int64" ) { + t += ".toLongLong"; + } else { + t += ".to" + itemType( type ); + } + if ( !defaultValue.isEmpty() ) { + t += ", "; + if ( type == "String" ) t += defaultValue; + else t+= defaultValue; + } + t += " )"; + + return t; +} + +QString addItem( const QString &type, const QString &name, const QString &key, + const QString &defaultValue, const QString ¶m = QString::null, + const QString ¶mName = QString::null ) +{ + QString t = "addItem" + itemType( type ) + + "( " + key + ", " + varName( name ) + param; + if ( type == "Enum" ) t += ", values" + name; + if ( !defaultValue.isEmpty() ) { + t += ", "; + if ( type == "String" ) t += defaultValue; + else if ( type == "Enum" ) t += enumValue(defaultValue); + else t+= defaultValue; + } + + if (!paramName.isNull()) { + t += ", \"" + paramName + "\""; + } + + t += " )"; + + return t; +} + +QString paramString(const QString &s, const CfgEntry *e, int i) +{ + QString result = s; + QString needle = "$("+e->param()+")"; + if (result.contains(needle)) + { + QString tmp; + if (e->paramType() == "Enum") + { + tmp = e->paramValues()[i]; + } + else + { + tmp = QString::number(i); + } + + result.replace(needle, tmp); + } + return result; +} + +QString paramString(const QString &group, const QStringList ¶meters) +{ + QString paramString = group; + QString arguments; + int i = 0; + for( QStringList::ConstIterator it = parameters.begin(); + it != parameters.end(); ++it) + { + if (paramString.contains("$("+*it+")")) + { + i++; + paramString.replace("$("+*it+")", "%s"); + if (i > 1) { + arguments += ", "; + } + arguments += " @param"+*it; + } + } + if (arguments.isEmpty()) + return "\""+group+"\""; + + if (i == 1) { + return "\""+paramString+"\" % "+arguments; + } else { + return "\""+paramString+"\" % ["+arguments+"]"; + } +} + +/* int i is the value of the parameter */ +QString userTextsFunctions( CfgEntry *e, QString itemVarStr=QString::null, QString i=QString::null ) +{ + QString txt; + if (itemVarStr.isNull()) itemVarStr=itemVar(e); + if ( !e->label().isEmpty() ) { + txt += " " + itemVarStr + ".setLabel( i18n("; + if ( !e->param().isEmpty() ) + txt += quoteString(e->label().replace("$("+e->param()+")", i)); + else + txt+= quoteString(e->label()); + txt+= ") )\n"; + } + if ( !e->whatsThis().isEmpty() ) { + txt += " " + itemVarStr + ".setWhatsThis( i18n("; + if ( !e->param().isEmpty() ) + txt += quoteString(e->whatsThis().replace("$("+e->param()+")", i)); + else + txt+= quoteString(e->whatsThis()); + txt+=") )\n"; + } + return txt; +} + +int main( int argc, char **argv ) +{ + KAboutData aboutData( "rbkconfig_compiler", I18N_NOOP("KDE .kcfg compiler"), "0.3", + I18N_NOOP("Ruby KConfig Compiler") , KAboutData::License_LGPL ); + aboutData.addAuthor( "Cornelius Schumacher", 0, "schumacher@kde.org" ); + aboutData.addAuthor( "Waldo Bastian", 0, "bastian@kde.org" ); + aboutData.addAuthor( "Zack Rusin", 0, "zack@kde.org" ); + aboutData.addCredit( "Reinhold Kainhofer", "Fix for parametrized entries", + "reinhold@kainhofer.com", "http://reinhold.kainhofer.com" ); + aboutData.addCredit( "Richard Dale", "Ruby port", + "Richard_Dale@tipitina.demon.co.uk", "" ); + + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + + KInstance app( &aboutData ); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + if ( args->count() < 2 ) { + kdError() << "Too few arguments." << endl; + return 1; + } + if ( args->count() > 2 ) { + kdError() << "Too many arguments." << endl; + return 1; + } + + validNameRegexp = new QRegExp("[a-zA-Z_][a-zA-Z0-9_]*"); + + QString baseDir = QFile::decodeName(args->getOption("directory")); + if (!baseDir.endsWith("/")) + baseDir.append("/"); + + QString inputFilename = args->url( 0 ).path(); + QString codegenFilename = args->url( 1 ).path(); + + if (!codegenFilename.endsWith(".kcfgc")) + { + kdError() << "Codegen options file must have extension .kcfgc" << endl; + return 1; + } + QString baseName = args->url( 1 ).fileName(); + baseName = baseName.left(baseName.length() - 6); + + KSimpleConfig codegenConfig( codegenFilename, true ); + + QString nameSpace = codegenConfig.readEntry("NameSpace"); + QString className = codegenConfig.readEntry("ClassName"); + QString inherits = codegenConfig.readEntry("Inherits"); + QString visibility = codegenConfig.readEntry("Visibility"); + if (!visibility.isEmpty()) visibility+=" "; + bool singleton = codegenConfig.readBoolEntry("Singleton", false); + bool customAddons = codegenConfig.readBoolEntry("CustomAdditions"); + QString memberVariables = codegenConfig.readEntry("MemberVariables"); + QStringList headerIncludes = codegenConfig.readListEntry("IncludeFiles"); + QStringList mutators = codegenConfig.readListEntry("Mutators"); + bool allMutators = false; + if ((mutators.count() == 1) && (mutators[0].lower() == "true")) + allMutators = true; + itemAccessors = codegenConfig.readBoolEntry( "ItemAccessors", false ); + bool setUserTexts = codegenConfig.readBoolEntry( "SetUserTexts", false ); + + globalEnums = codegenConfig.readBoolEntry( "GlobalEnums", false ); + + QFile input( inputFilename ); + + QDomDocument doc; + QString errorMsg; + int errorRow; + int errorCol; + if ( !doc.setContent( &input, &errorMsg, &errorRow, &errorCol ) ) { + kdError() << "Unable to load document." << endl; + kdError() << "Parse error in " << args->url( 0 ).fileName() << ", line " << errorRow << ", col " << errorCol << ": " << errorMsg << endl; + return 1; + } + + QDomElement cfgElement = doc.documentElement(); + + if ( cfgElement.isNull() ) { + kdError() << "No document in kcfg file" << endl; + return 1; + } + + QString cfgFileName; + bool cfgFileNameArg = false; + QStringList parameters; + QStringList includes; + + QPtrList entries; + entries.setAutoDelete( true ); + + QDomNode n; + for ( n = cfgElement.firstChild(); !n.isNull(); n = n.nextSibling() ) { + QDomElement e = n.toElement(); + + QString tag = e.tagName(); + + if ( tag == "include" ) { + QString includeFile = e.text(); + if (!includeFile.isEmpty()) + includes.append(includeFile); + + } else if ( tag == "kcfgfile" ) { + cfgFileName = e.attribute( "name" ); + cfgFileNameArg = e.attribute( "arg" ).lower() == "true"; + QDomNode n2; + for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { + QDomElement e2 = n2.toElement(); + if ( e2.tagName() == "parameter" ) { + parameters.append( e2.attribute( "name" ) ); + } + } + + } else if ( tag == "group" ) { + QString group = e.attribute( "name" ); + if ( group.isEmpty() ) { + kdError() << "Group without name" << endl; + return 1; + } + QDomNode n2; + for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) { + QDomElement e2 = n2.toElement(); + if ( e2.tagName() != "entry" ) continue; + CfgEntry *entry = parseEntry( group, e2 ); + if ( entry ) entries.append( entry ); + else { + kdError() << "Can't parse entry." << endl; + return 1; + } + } + } + } + + if ( inherits.isEmpty() ) inherits = "KDE::ConfigSkeleton"; + + if ( className.isEmpty() ) { + kdError() << "Class name missing" << endl; + return 1; + } + + if ( singleton && !parameters.isEmpty() ) { + kdError() << "Singleton class can not have parameters" << endl; + return 1; + } + + if ( singleton && cfgFileNameArg) + { + kdError() << "Singleton class can not use filename as argument." << endl; + return 1; + } + + if ( !cfgFileName.isEmpty() && cfgFileNameArg) + { + kdError() << "Having both a fixed filename and a filename as argument is not possible." << endl; + return 1; + } + + if ( entries.isEmpty() ) { + kdWarning() << "No entries." << endl; + } + +#if 0 + CfgEntry *cfg; + for( cfg = entries.first(); cfg; cfg = entries.next() ) { + cfg->dump(); + } +#endif + + QString implementationFileName = baseName + ".rb"; + + QFile implementation( baseDir + implementationFileName ); + if ( !implementation.open( IO_WriteOnly ) ) { + kdError() << "Can't open '" << implementationFileName << "for writing." << endl; + return 1; + } + + QTextStream rb( &implementation ); + + rb << "# This file is generated by rbkconfig_compiler from " << args->url(0).fileName() << "." << endl; + rb << "# All changes you do to this file will be lost." << endl; + rb << endl << "require 'Korundum'" << endl; + + if (singleton) { + rb << "require 'singleton'" << endl; + } + + rb << endl; + +// rb << "#ifndef " << ( !nameSpace.isEmpty() ? nameSpace.upper() + "_" : "" ) +// << className.upper() << "_H" << endl; +// rb << "#define " << ( !nameSpace.isEmpty() ? nameSpace.upper() + "_" : "" ) +// << className.upper() << "_H" << endl << endl; + + // Includes +// QStringList::ConstIterator it; +// for( it = headerIncludes.begin(); it != headerIncludes.end(); ++it ) { +// rb << "#include <" << *it << ">" << endl; +// } + + if ( headerIncludes.count() > 0 ) rb << endl; + +// rb << "#include " << endl << endl; + + if ( !nameSpace.isEmpty() ) + rb << "module " << nameSpace << endl << endl; + + // Class declaration header + rb << "class " << className << " < " << inherits << endl; + + if (singleton) { + rb << " include Singleton" << endl << endl; + } + + // enums + CfgEntry *e; + for( e = entries.first(); e; e = entries.next() ) { + QValueList choices = e->choices(); + if ( !choices.isEmpty() ) { + QStringList values; + QValueList::ConstIterator itChoice; + for( itChoice = choices.begin(); itChoice != choices.end(); ++itChoice ) { + if (globalEnums) { + values.append( enumValue((*itChoice).name) ); + } else { + values.append( enumName(e->name()) + "_" + (*itChoice).name ); + } + } + if (!globalEnums) { + values.append( enumName(e->name()) + "_COUNT" ); + } + int count = 0; + for ( QStringList::Iterator it = values.begin(); it != values.end(); ++it, count++ ) { + rb << " " << *it << " = " << count << endl; + } + rb << endl; + } + + QStringList values = e->paramValues(); + if ( !values.isEmpty() ) { + int count = 0; + for ( QStringList::Iterator it = values.begin(); it != values.end(); ++it, count++ ) { + if (globalEnums) { + rb << " " << enumValue(*it) << " = " << count << endl; + } else { + rb << " " << enumName(e->param()) << "_" << *it << " = " << count << endl; + } + } + if (!globalEnums) { + rb << " " << enumName(e->param()) << "_COUNT = " << count << endl; + } + rb << endl; + + rb << " def " << enumName(e->param()) << "ToString(i)" << endl; + rb << " ["; + count = 0; + for ( QStringList::Iterator it = values.begin(); it != values.end(); ++it, count++ ) { + if (count > 0) { + rb << ", "; + } + + rb << "\"" << *it << "\""; + } + + rb << "].at(i)" << endl; + rb << " end" << endl; + } + } + + rb << endl; + + for( e = entries.first(); e; e = entries.next() ) { + QString n = e->name(); + QString t = e->type(); + + // Manipulator + if (allMutators || mutators.contains(n)) + { + rb << " #" << endl; + rb << " # Set " << e->label() << endl; + rb << " #" << endl; + rb << " def " << setFunction(n) << "( "; + if (!e->param().isEmpty()) + rb << " i, "; + rb << " v )" << endl; + rb << " item = findItem( \""; + if (!e->param().isEmpty()) { + rb << e->paramName().replace("$("+e->param()+")", "%s") << "\" % "; + if ( e->paramType() == "Enum" ) { + rb << " "; + if (globalEnums) + rb << enumName(e->param()) << "ToString(i)"; + else + rb << enumName(e->param()) << "ToString(i)"; + } else { + rb << "i"; + } + } else { + rb << n << "\""; + } + rb << " )" << endl; + rb << " if !item.immutable? " << endl; + rb << " item.property = " << varName(n); + if (!e->param().isEmpty()) + rb << "[i]"; + rb << " = Qt::Variant.new( v )" << endl; + rb << " end" << endl; + rb << " end" << endl << endl; + } + + // Accessor + rb << " #" << endl; + rb << " # Get " << e->label() << endl; + rb << " #" << endl; + rb << " def " << getFunction(n) << "("; + if (!e->param().isEmpty()) + rb << " " <<" i "; + rb << ")" << endl; + rb << " " << varName(n); + if (!e->param().isEmpty()) rb << "[i]"; + rb << " = findItem( \""; + if (!e->param().isEmpty()) { + rb << e->paramName().replace("$("+e->param()+")", "%s") << "\" % "; + if ( e->paramType() == "Enum" ) { + rb << " "; + if (globalEnums) + rb << enumName(e->param()) << "ToString(i)"; + else + rb << enumName(e->param()) << "ToString(i)"; + } else { + rb << "i"; + } + } else { + rb << n << "\""; + } + rb << " ).property" << endl; + rb << " return " << varName(n); + if (!e->param().isEmpty()) rb << "[i]"; + if ( e->type() == "Enum" ) { + rb << ".toInt" << endl; + } else if ( e->type() == "Int64" ) { + rb << ".toLongLong" << endl; + } else if ( e->type() == "Path" ) { + rb << ".toString" << endl; + } else { + rb << ".to" << itemType( e->type() ) << endl; + } + rb << " end" << endl; + + // Item accessor + if ( itemAccessors ) { + rb << endl; + rb << " #" << endl; + rb << " # Get Item object corresponding to " << n << "()" + << endl; + rb << " #" << endl; + rb << " def " + << getFunction( n ) << "Item("; + if (!e->param().isEmpty()) { + rb << " " << " i "; + } + rb << ")" << endl; + rb << " return " << itemVar(e); + if (!e->param().isEmpty()) rb << "[i]"; + rb << endl << " end" << endl; + } + + rb << endl; + } + + + if (customAddons) + { + rb << " # Include custom additions" << endl; + } + + + // Constructor + rb << " def initialize( "; + if (cfgFileNameArg) + rb << " config" << (parameters.isEmpty() ? " " : ", "); + for (QStringList::ConstIterator it = parameters.begin(); + it != parameters.end(); ++it) + { + if (it != parameters.begin()) + rb << ","; + rb << " " << *it; + } + rb << " )" << endl; + + rb << " super("; + if ( !cfgFileName.isEmpty() ) rb << " \"" << cfgFileName << "\" "; + if ( cfgFileNameArg ) rb << " config "; +// if ( !cfgFileName.isEmpty() ) rb << ") "; + rb << ")" << endl; + + // Store parameters + for (QStringList::ConstIterator it = parameters.begin(); + it != parameters.end(); ++it) + { + rb << " @param" << *it << " = Qt::Variant.new( " << *it << " )" << endl; + } + + QString group; + for( e = entries.first(); e; e = entries.next() ) { + if ( e->group() != group ) { + group = e->group(); + rb << endl; + rb << " # " << group << endl; + } + if (e->param().isEmpty()) { + rb << " " << varName(e->name()) << " = Qt::Variant.new( " << rbType(e->type()) << " )"; + } else { + rb << " " << varName(e->name()) << " = [ "; + for (int i = 0; i < e->paramMax()+1; i++) { + if (i > 0) { + rb << ", "; + } + rb << "Qt::Variant.new( " << rbType(e->type()) << " )"; + } + rb << " ]"; + } + rb << endl; + } + + rb << endl; + + + group = QString::null; + for( e = entries.first(); e; e = entries.next() ) { + if ( e->group() != group ) { + if ( !group.isEmpty() ) rb << endl; + group = e->group(); + rb << " setCurrentGroup( " << paramString(group, parameters) << " )" << endl << endl; + } + + QString key = paramString(e->key(), parameters); + if ( !e->code().isEmpty()) + { + rb << e->code() << endl; + } + if ( e->type() == "Enum" ) { + rb << " values" + << e->name() << " = []" << endl; + QValueList choices = e->choices(); + QValueList::ConstIterator it; + for( it = choices.begin(); it != choices.end(); ++it ) { + rb << " choice = ItemEnum::Choice.new" << endl; + rb << " choice.name = \"" << enumValue((*it).name) << "\" " << endl; + if ( setUserTexts ) { + if ( !(*it).label.isEmpty() ) + rb << " choice.label = i18n(" << quoteString((*it).label) << ")" << endl; + if ( !(*it).whatsThis.isEmpty() ) + rb << " choice.whatsThis = i18n(" << quoteString((*it).whatsThis) << ")" << endl; + } + rb << " values" << e->name() << " << choice" << endl; + } + } + + if (e->param().isEmpty()) + { + // Normal case + rb << " " << itemVar(e) << " = " + << newItem( e->type(), e->name(), key, e->defaultValue() ) << endl; + + rb << " " << itemVar(e) << ".property = " << varName(e->name()) << endl; + + if ( !e->minValue().isEmpty() ) + rb << " " << itemVar(e) << ".setMinValue(" << e->minValue() << ")" << endl; + if ( !e->maxValue().isEmpty() ) + rb << " " << itemVar(e) << ".setMaxValue(" << e->maxValue() << ")" << endl; + + if ( setUserTexts ) + rb << userTextsFunctions( e ); + + rb << " addItem( " << itemVar(e); + QString quotedName = e->name(); + addQuotes( quotedName ); + if ( quotedName != key ) rb << ", \"" << e->name() << "\""; + rb << " )" << endl; + } + else + { + // Indexed + rb << " " << itemVar(e) << " = Array.new(" << e->paramMax()+1 << ")" << endl; + for(int i = 0; i <= e->paramMax(); i++) + { + QString defaultStr; + QString itemVarStr(itemVar(e)+QString("[%1]").arg(i)); + + if ( !e->paramDefaultValue(i).isEmpty() ) + defaultStr = e->paramDefaultValue(i); + else if ( !e->defaultValue().isEmpty() ) + defaultStr = paramString(e->defaultValue(), e, i); + else + defaultStr = defaultValue( e->type() ); + + rb << " " << itemVarStr << " = " + << newItem( e->type(), e->name(), paramString(key, e, i), defaultStr, QString("[%1]").arg(i) ) + << endl; + + rb << " " << itemVarStr << ".property = " << varName(e->name())+QString("[%1]").arg(i) << endl; + + if ( setUserTexts ) + rb << userTextsFunctions( e, itemVarStr, e->paramName() ); + + // Make mutators for enum parameters work by adding them with $(..) replaced by the + // param name. The check for isImmutable in the set* functions doesn't have the param + // name available, just the corresponding enum value (int), so we need to store the + // param names in a separate static list!. + rb << " addItem( " << itemVarStr << ", \""; + if ( e->paramType()=="Enum" ) + rb << e->paramName().replace( "$("+e->param()+")", "%1").arg(e->paramValues()[i] ); + else + rb << e->paramName().replace( "$("+e->param()+")", "%1").arg(i); + rb << "\" )" << endl; + + } + } + } + + rb << " end" << endl << endl; + + rb << "end" << endl << endl; + + if ( !nameSpace.isEmpty() ) rb << "end" << endl << endl; + + implementation.close(); +} diff --git a/korundum/rubylib/rbkconfig_compiler/tests/Makefile.am b/korundum/rubylib/rbkconfig_compiler/tests/Makefile.am new file mode 100644 index 00000000..ce61f658 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/Makefile.am @@ -0,0 +1,40 @@ +check_PROGRAMS = test1 test2 test3 test4 test5 + +CLEANFILES = test1.rb \ + test2.rb \ + test3.rb \ + test4.rb \ + test5.rb \ + md5sums + +all: $(SOURCES) + +# Splitting this with backslashses produces broken Makefiles +SOURCES = test1main.rb test1.rb test2main.rb test2.rb test3main.rb test3.rb test4main.rb test4.rb test5main.rb test5.rb + +# avoid running the below command in parallel +test1.rb: $(srcdir)/test1.kcfg ../rbkconfig_compiler $(srcdir)/test1.kcfgc + ../rbkconfig_compiler $(srcdir)/test1.kcfg $(srcdir)/test1.kcfgc + +# avoid running the below command in parallel +test2.rb: $(srcdir)/test2.kcfg ../rbkconfig_compiler $(srcdir)/test2.kcfgc + ../rbkconfig_compiler $(srcdir)/test2.kcfg $(srcdir)/test2.kcfgc + +# avoid running the below command in parallel +test3.rb: $(srcdir)/test3.kcfg ../rbkconfig_compiler $(srcdir)/test3.kcfgc + ../rbkconfig_compiler $(srcdir)/test3.kcfg $(srcdir)/test3.kcfgc + +# avoid running the below command in parallel +test4.rb: $(srcdir)/test4.kcfg ../rbkconfig_compiler $(srcdir)/test4.kcfgc + ../rbkconfig_compiler $(srcdir)/test4.kcfg $(srcdir)/test4.kcfgc + +# avoid running the below command in parallel +test5.rb: $(srcdir)/test5.kcfg ../rbkconfig_compiler $(srcdir)/test5.kcfgc + ../rbkconfig_compiler $(srcdir)/test5.kcfg $(srcdir)/test5.kcfgc + +md5sums: + $(MD5SUM) $(srcdir)/test*.ref | sed -e "s,$(srcdir)/,,; s,\.ref$$,," > md5sums + +md5check: test1.rb test2.rb test3.rb test4.rb test5.rb md5sums + $(MD5SUM) --check md5sums + diff --git a/korundum/rubylib/rbkconfig_compiler/tests/myprefs.rb b/korundum/rubylib/rbkconfig_compiler/tests/myprefs.rb new file mode 100644 index 00000000..a4f1f082 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/myprefs.rb @@ -0,0 +1,5 @@ +class MyPrefs < KDE::ConfigSkeleton + def initialize( a ) + super( a ) + end +end diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test1.kcfg b/korundum/rubylib/rbkconfig_compiler/tests/test1.kcfg new file mode 100644 index 00000000..0c0c8216 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test1.kcfg @@ -0,0 +1,55 @@ + + + qdir.h + + + + + + + + true + + + + 5 + + + + And this is a longer description of this option. Just wondering, how will the translations of those be handled? + + + + + + One + + + + + + Default String + + + + Qt::Dir.homeDirPath()+".hidden_file" + + + + 10 + + + up,down + + + + + 1 + + + diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test1.kcfgc b/korundum/rubylib/rbkconfig_compiler/tests/test1.kcfgc new file mode 100644 index 00000000..6e0edd36 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test1.kcfgc @@ -0,0 +1,18 @@ +# Code generation options for kconfig_compiler +ClassName=Test1 +# +# Singleton=false +# +# Inherits=KConfigSkeleton +# +# IncludeFiles=libkdepim/kpimprefs.h +# +# MemberVariables=public +# +### The following line includes the file exampleprefs_base_addon.h +### It can be used to add extra functions and variables to the +### class. +# CustomAdditions=true +# +### Provide setFooBar(int) style functions +Mutators=true diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test1main.rb b/korundum/rubylib/rbkconfig_compiler/tests/test1main.rb new file mode 100644 index 00000000..88a151a6 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test1main.rb @@ -0,0 +1,4 @@ +require 'Korundum' +require 'test1.rb' + +t = Test1.new(nil, nil) diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test2.kcfg b/korundum/rubylib/rbkconfig_compiler/tests/test2.kcfg new file mode 100644 index 00000000..3b19e270 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test2.kcfg @@ -0,0 +1,78 @@ + + + + + + + + WhatsThis text for AutoSave option + false + + + 10 + + + + true + + + + + + + + + + + + + + + Argl2 Whatsthis + + + + Argl3 Whatsthis + + + standardDestination + + + + + + 10 + + + + false + + + + + + holidays,webexport + + + + + + + 100, 100, 255 + + + + 255, 255, 255 + + + + + + + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test2.kcfgc b/korundum/rubylib/rbkconfig_compiler/tests/test2.kcfgc new file mode 100644 index 00000000..56620d2f --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test2.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=test2.kcfg +ClassName=Test2 +Singleton=false +Mutators=true +Inherits=MyPrefs +IncludeFiles=myprefs.h +MemberVariables=public +GlobalEnums=true +ItemAccessors=true +SetUserTexts=true diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test2main.rb b/korundum/rubylib/rbkconfig_compiler/tests/test2main.rb new file mode 100644 index 00000000..85d18f07 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test2main.rb @@ -0,0 +1,5 @@ +require 'Korundum' +require 'myprefs.rb' +require 'test2.rb' + +t = Test2.new() diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test3.kcfg b/korundum/rubylib/rbkconfig_compiler/tests/test3.kcfg new file mode 100644 index 00000000..77916da4 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test3.kcfg @@ -0,0 +1,26 @@ + + + + + + + + WhatsThis text for AutoSave option + false + + + + + + 10 + + + a string + + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test3.kcfgc b/korundum/rubylib/rbkconfig_compiler/tests/test3.kcfgc new file mode 100644 index 00000000..ca2c2205 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test3.kcfgc @@ -0,0 +1,12 @@ +# Code generation options for kconfig_compiler +File=test3.kcfg +NameSpace=TestNameSpace +ClassName=Test3 +#Singleton=false +Mutators=true +#Inherits=MyPrefs +#IncludeFiles=myprefs.h +#MemberVariables=public +GlobalEnums=true +ItemAccessors=true +#SetUserTexts=true diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test3main.rb b/korundum/rubylib/rbkconfig_compiler/tests/test3main.rb new file mode 100644 index 00000000..8c19b442 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test3main.rb @@ -0,0 +1,4 @@ +require 'Korundum' +require 'test3.rb' + +t = TestNameSpace::Test3.new() diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test4.kcfg b/korundum/rubylib/rbkconfig_compiler/tests/test4.kcfg new file mode 100644 index 00000000..1428bc0d --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test4.kcfg @@ -0,0 +1,42 @@ + + + + + + + + + defaultColor = [ Qt::red, Qt::blue, Qt::green, Qt::black ] + defaultColor[$(Number)] + + + + + right + mid + left + + + + + + + + + + Decrypt + Encrypt + PumpNDump + + + + 35 + 8 + 88 + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test4.kcfgc b/korundum/rubylib/rbkconfig_compiler/tests/test4.kcfgc new file mode 100644 index 00000000..754706df --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test4.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=test4.kcfg +ClassName=Test4 +Singleton=true +Mutators=true +#Inherits=MyPrefs +#IncludeFiles=myprefs.h +#MemberVariables=public +GlobalEnums=false +ItemAccessors=false +#SetUserTexts=true diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test4main.rb b/korundum/rubylib/rbkconfig_compiler/tests/test4main.rb new file mode 100644 index 00000000..c75f0995 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test4main.rb @@ -0,0 +1,4 @@ +require 'Korundum' +require 'test4.rb' + +t = Test4.instance() diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test5.kcfg b/korundum/rubylib/rbkconfig_compiler/tests/test5.kcfg new file mode 100644 index 00000000..1428bc0d --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test5.kcfg @@ -0,0 +1,42 @@ + + + + + + + + + defaultColor = [ Qt::red, Qt::blue, Qt::green, Qt::black ] + defaultColor[$(Number)] + + + + + right + mid + left + + + + + + + + + + Decrypt + Encrypt + PumpNDump + + + + 35 + 8 + 88 + + + + diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test5.kcfgc b/korundum/rubylib/rbkconfig_compiler/tests/test5.kcfgc new file mode 100644 index 00000000..663005e5 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test5.kcfgc @@ -0,0 +1,11 @@ +# Code generation options for kconfig_compiler +File=test5.kcfg +ClassName=Test5 +Singleton=true +Mutators=true +#Inherits=MyPrefs +#IncludeFiles=myprefs.h +#MemberVariables=public +GlobalEnums=true +ItemAccessors=false +#SetUserTexts=true diff --git a/korundum/rubylib/rbkconfig_compiler/tests/test5main.rb b/korundum/rubylib/rbkconfig_compiler/tests/test5main.rb new file mode 100644 index 00000000..cd0fbeb7 --- /dev/null +++ b/korundum/rubylib/rbkconfig_compiler/tests/test5main.rb @@ -0,0 +1,4 @@ +require 'Korundum' +require 'test5.rb' + +t = Test5.instance() -- cgit v1.2.1