kconfig_compiler PathList support

Helge Deller deller at gmx.de
Sat Feb 19 14:56:11 GMT 2005


kconfig_compiler does support the "Password" and "Path" types, but "PathList" support is still missing (for what I call "roaming user support", @see: KConfigBase::readPathListEntry()).
Some applications (e.g. amarok) currently use the similiar "StringList" type, but this is a bug since it does not support relocating the home directory.
The following patch adds the missing support for this type.
Is it OK to commit it ?

Regards,
Helge

-------------- next part --------------
Index: kconfigskeleton.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfigskeleton.h,v
retrieving revision 1.26
diff -u -p -r1.26 kconfigskeleton.h
--- kconfigskeleton.h	20 Sep 2004 19:12:09 -0000	1.26
+++ kconfigskeleton.h	19 Feb 2005 14:45:10 -0000
@@ -372,7 +372,7 @@ public:
   class KDECORE_EXPORT ItemString:public KConfigSkeletonGenericItem < QString >
   {
   public:
-    enum Type { Normal, Password, Path };
+    enum Type { Normal, Password, Path, PathList };
 
     ItemString(const QString & group, const QString & key,
                QString & reference,
@@ -756,6 +756,20 @@ public:
 
 
   /**
+   * Class for handling a path list preferences item.
+   */
+  class KDECORE_EXPORT ItemPathList:public ItemStringList
+  {
+  public:
+    ItemPathList(const QString & group, const QString & key,
+                   QStringList & reference,
+                   const QStringList & defaultValue = QStringList());
+
+    void readConfig(KConfig * config);
+  };
+
+
+  /**
    * Class for handling an integer list preferences item.
    */
   class KDECORE_EXPORT ItemIntList:public KConfigSkeletonGenericItem < QValueList < int > >
Index: kconfigskeleton.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfigskeleton.cpp,v
retrieving revision 1.17
diff -u -p -r1.17 kconfigskeleton.cpp
--- kconfigskeleton.cpp	23 Oct 2004 17:28:46 -0000	1.17
+++ kconfigskeleton.cpp	19 Feb 2005 14:45:10 -0000
@@ -56,6 +56,8 @@ void KConfigSkeleton::ItemString::writeC
       config->revertToDefault( mKey );
     else if ( mType == Path )
       config->writePathEntry( mKey, mReference );
+    else if ( mType == PathList )
+      config->writePathEntry( mKey, mReference );
     else if ( mType == Password )
       config->writeEntry( mKey, KStringHandler::obscure( mReference ) );
     else
@@ -813,6 +815,26 @@ QVariant KConfigSkeleton::ItemStringList
 }
 
 
+KConfigSkeleton::ItemPathList::ItemPathList( const QString &group, const QString &key,
+                                            QStringList &reference,
+                                            const QStringList &defaultValue )
+  : ItemStringList( group, key, reference, defaultValue )
+{
+}
+
+void KConfigSkeleton::ItemPathList::readConfig( KConfig *config )
+{
+  config->setGroup( mGroup );
+  if ( !config->hasKey( mKey ) )
+    mReference = mDefault;
+  else
+    mReference = config->readPathListEntry( mKey );
+  mLoadedValue = mReference;
+
+  readImmutability( config );
+}
+
+
 KConfigSkeleton::ItemIntList::ItemIntList( const QString &group, const QString &key,
                                       QValueList<int> &reference,
                                       const QValueList<int> &defaultValue )
Index: kconfig_compiler/kcfg.xsd
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/kcfg.xsd,v
retrieving revision 1.6
diff -u -p -r1.6 kcfg.xsd
--- kconfig_compiler/kcfg.xsd	21 Nov 2004 18:37:24 -0000	1.6
+++ kconfig_compiler/kcfg.xsd	19 Feb 2005 14:45:10 -0000
@@ -162,6 +162,7 @@
 	    <xsd:enumeration value="IntList"/>
 	    <xsd:enumeration value="Enum"/>
 	    <xsd:enumeration value="Path"/>
+	    <xsd:enumeration value="PathList"/>
 	    <xsd:enumeration value="Password"/>
 	</xsd:restriction>
     </xsd:simpleType>
Index: kconfig_compiler/example.kcfg
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/example.kcfg,v
retrieving revision 1.11
diff -u -p -r1.11 example.kcfg
--- kconfig_compiler/example.kcfg	21 Nov 2004 23:34:08 -0000	1.11
+++ kconfig_compiler/example.kcfg	19 Feb 2005 14:45:11 -0000
@@ -37,6 +37,14 @@
       <label>This is a path</label>
       <default code="true">QDir::homeDirPath()+QString::fromLatin1(".hidden_file")</default>
     </entry>
+    <entry name="MyPaths" type="PathList">
+      <label>This is a list of paths</label>
+      <default>/home,~</default>
+    </entry>
+    <entry name="MyPaths2" type="PathList">
+      <label>This is a list of paths (test2)</label>
+      <default code="true">QStringList(QDir::homeDirPath())</default>
+    </entry>
     <entry name="AnotherOption2" type="Int" key="Another Option">
       <label>Another option</label>
       <default>10</default>
Index: kconfig_compiler/kconfig_compiler.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kconfig_compiler/kconfig_compiler.cpp,v
retrieving revision 1.63
diff -u -p -r1.63 kconfig_compiler.cpp
--- kconfig_compiler/kconfig_compiler.cpp	16 Feb 2005 19:59:11 -0000	1.63
+++ kconfig_compiler/kconfig_compiler.cpp	19 Feb 2005 14:45:12 -0000
@@ -270,7 +270,7 @@ static void preProcessDefault( QString &
     } else if ( type == "Path" && !defaultValue.isEmpty() ) {
       defaultValue = literalString( defaultValue );
 
-    } else if ( type == "StringList" && !defaultValue.isEmpty() ) {
+    } else if ( (type == "StringList" || type == "PathList") && !defaultValue.isEmpty() ) {
       QTextStream cpp( &code, IO_WriteOnly | IO_Append );
       if (!code.isEmpty())
          cpp << endl;
@@ -593,6 +593,7 @@ QString param( const QString &type )
     else if ( type == "IntList" )     return "const QValueList<int> &";
     else if ( type == "Enum" )        return "int";
     else if ( type == "Path" )        return "const QString &";
+    else if ( type == "PathList" )    return "const QStringList &";
     else if ( type == "Password" )    return "const QString &";
     else {
         kdError() <<"kconfig_compiler does not support type \""<< type <<"\""<<endl;
@@ -622,6 +623,7 @@ QString cppType( const QString &type )
     else if ( type == "IntList" )     return "QValueList<int>";
     else if ( type == "Enum" )        return "int";
     else if ( type == "Path" )        return "QString";
+    else if ( type == "PathList" )    return "QStringList";
     else if ( type == "Password" )    return "QString";
     else {
         kdError()<<"kconfig_compiler does not support type \""<< type <<"\""<<endl;
@@ -648,6 +650,7 @@ QString defaultValue( const QString &typ
     else if ( type == "IntList" )     return "QValueList<int>()";
     else if ( type == "Enum" )        return "0";
     else if ( type == "Path" )        return "\"\""; // Use empty string, not null string!
+    else if ( type == "PathList" )    return "QStringList()";
     else if ( type == "Password" )    return "\"\""; // Use empty string, not null string!
     else {
         kdWarning()<<"Error, kconfig_compiler doesn't support the \""<< type <<"\" type!"<<endl;


More information about the kde-core-devel mailing list