[PATCH] Support for KUrl in KConfigXT and KCModule's

Andreas Pakulat apaku at gmx.de
Tue Mar 20 00:11:21 GMT 2007


On 19.03.07 11:33:17, Aaron J. Seigo wrote:
> On March 19, 2007, Andreas Pakulat wrote:
> > as proposed I added support for KUrl to KConfigXT and
> > KConfigDialogManager, the attached patch adds a new
> > KConfigSkeletonItem and adds the two missing signals for
> > change-notification to KConfigDialogManager. Luckily KUrlRequester
> 
> please follow the kdelibs style guidelines. otherwise, looks good.
> 
> > I'm not sure wether KUrl::List is needed as I don't see any widgets that
> > work on such a type, but it should be relatively easy to add support for
> > that.
> 
> widgets are only half the question; kconfigxt is used without UIs as well =)

Ok, here's an updated patch. Changes that are included:

a) the test for kconfig_compiler
b) Support for KUrl::List
c) using 4 space indentation for the new code in kconfigskeleton (I
don't think reformatting all of the class is a good idea, as I only tuch
a small part)

As I said I will commit this next week to give all people a chance to
comment.

Andreas

-- 
Is that really YOU that is reading this?
-------------- next part --------------
Index: kdecore/config/kconfigskeleton.cpp
===================================================================
--- kdecore/config/kconfigskeleton.cpp	(Revision 644373)
+++ kdecore/config/kconfigskeleton.cpp	(Arbeitskopie)
@@ -104,6 +104,45 @@ KConfigSkeleton::ItemPath::ItemPath( con
 {
 }
 
+KConfigSkeleton::ItemUrl::ItemUrl( const QString &_group, const QString &_key,
+                                    KUrl &reference,
+                                    const KUrl &defaultValue )
+  : KConfigSkeletonGenericItem<KUrl>( _group, _key, reference, defaultValue )
+{
+}
+
+void KConfigSkeleton::ItemUrl::writeConfig( KConfig *config )
+{
+    if ( mReference != mLoadedValue ) // WABA: Is this test needed?
+    {
+        KConfigGroup cg(config, mGroup );
+        if ((mDefault == mReference) && !config->hasDefault( mKey))
+            cg.revertToDefault( mKey );
+        else
+            cg.writeEntry<QString>( mKey, mReference.url() );
+    }
+}
+
+void KConfigSkeleton::ItemUrl::readConfig( KConfig *config )
+{
+    KConfigGroup cg(config, mGroup );
+
+    mReference = KUrl( cg.readEntry<QString>( mKey, mDefault.url() ) );
+    mLoadedValue = mReference;
+
+    readImmutability( cg );
+}
+
+void KConfigSkeleton::ItemUrl::setProperty(const QVariant & p)
+{
+    mReference = p.value<KUrl>();
+}
+
+QVariant KConfigSkeleton::ItemUrl::property() const
+{
+    return QVariant::fromValue(mReference);
+}
+
 KConfigSkeleton::ItemProperty::ItemProperty( const QString &_group,
                                         const QString &_key,
                                         QVariant &reference,
@@ -723,6 +762,46 @@ void KConfigSkeleton::ItemPathList::writ
   }
 }
 
+KConfigSkeleton::ItemUrlList::ItemUrlList( const QString &_group, const QString &_key,
+                                            KUrl::List &reference,
+                                            const KUrl::List &defaultValue )
+  : KConfigSkeletonGenericItem<KUrl::List>( _group, _key, reference, defaultValue )
+{
+}
+
+void KConfigSkeleton::ItemUrlList::readConfig( KConfig *config )
+{
+    KConfigGroup cg(config, mGroup );
+    if ( !cg.hasKey( mKey ) )
+        mReference = mDefault;
+    else
+        mReference = KUrl::List( cg.readEntry<QStringList>( mKey, mDefault.toStringList() ) );
+    mLoadedValue = mReference;
+
+    readImmutability( cg );
+}
+
+void KConfigSkeleton::ItemUrlList::writeConfig( KConfig *config )
+{
+    if ( mReference != mLoadedValue ) // WABA: Is this test needed?
+    {
+        KConfigGroup cg(config, mGroup );
+        if ((mDefault == mReference) && !cg.hasDefault( mKey))
+            cg.revertToDefault( mKey );
+        else
+            cg.writeEntry<QStringList>( mKey, mReference.toStringList() );
+    }
+}
+
+void KConfigSkeleton::ItemUrlList::setProperty(const QVariant & p)
+{
+    mReference = p.value<KUrl::List>();
+}
+
+QVariant KConfigSkeleton::ItemUrlList::property() const
+{
+    return QVariant::fromValue<KUrl::List>(mReference);
+}
 
 KConfigSkeleton::ItemIntList::ItemIntList( const QString &_group, const QString &_key,
                                       QList<int> &reference,
Index: kdecore/config/kconfigskeleton.h
===================================================================
--- kdecore/config/kconfigskeleton.h	(Revision 644373)
+++ kdecore/config/kconfigskeleton.h	(Arbeitskopie)
@@ -30,6 +30,7 @@
 #include <qrect.h>
 #include <qstringlist.h>
 #include <qvariant.h>
+#include <kurl.h>
 #include <kdelibs_export.h>
 #include <ksharedconfig.h>
 #include <kconfiggroup.h>
@@ -444,6 +445,31 @@ public:
              const QString & defaultValue = QString());
   };
 
+    /**
+     * Class for handling a url preferences item.
+     */
+    class KDECORE_EXPORT ItemUrl:public KConfigSkeletonGenericItem < KUrl >
+    {
+    public:
+
+        /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem
+         */
+        ItemUrl(const QString & _group, const QString & _key,
+                   KUrl & reference,
+                   const KUrl & defaultValue = KUrl());
+
+        /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */
+        void writeConfig(KConfig * config);
+
+        /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
+        void readConfig(KConfig * config);
+
+        /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
+        void setProperty(const QVariant & p);
+
+        /** @copydoc KConfigSkeletonItem::property() */
+        QVariant property() const;
+    };
 
   /**
    * Class for handling a QVariant preferences item.
@@ -878,6 +904,29 @@ public:
     void writeConfig(KConfig * config);
   };
 
+    /**
+     * Class for handling a url list preferences item.
+     */
+    class KDECORE_EXPORT ItemUrlList:public KConfigSkeletonGenericItem < KUrl::List >
+    {
+    public:
+        /** @copydoc KConfigSkeletonGenericItem::KConfigSkeletonGenericItem */
+        ItemUrlList(const QString & _group, const QString & _key,
+                     KUrl::List & reference,
+                     const KUrl::List & defaultValue = KUrl::List());
+
+        /** @copydoc KConfigSkeletonItem::readConfig(KConfig*) */
+        void readConfig(KConfig * config);
+
+        /** @copydoc KConfigSkeletonItem::writeConfig(KConfig*) */
+        void writeConfig(KConfig * config);
+
+        /** @copydoc KConfigSkeletonItem::setProperty(const QVariant&) */
+        void setProperty(const QVariant & p);
+
+        /** @copydoc KConfigSkeletonItem::property() */
+        QVariant property() const;
+    };
 
   /**
    * Class for handling an integer list preferences item.
Index: kdecore/kconfig_compiler/tests/test10.kcfgc
===================================================================
--- kdecore/kconfig_compiler/tests/test10.kcfgc	(Revision 0)
+++ kdecore/kconfig_compiler/tests/test10.kcfgc	(Revision 0)
@@ -0,0 +1,4 @@
+# Code generation options for kconfig_compiler
+File=test10.kcfg
+ClassName=Test10
+Singleton=true
Index: kdecore/kconfig_compiler/tests/test10.cpp.ref
===================================================================
--- kdecore/kconfig_compiler/tests/test10.cpp.ref	(Revision 0)
+++ kdecore/kconfig_compiler/tests/test10.cpp.ref	(Revision 0)
@@ -0,0 +1,40 @@
+// This file is generated by kconfig_compiler from test10.kcfg.
+// All changes you do to this file will be lost.
+
+#include "test10.h"
+
+#include <kstaticdeleter.h>
+
+Test10 *Test10::mSelf = 0;
+static KStaticDeleter<Test10> staticTest10Deleter;
+
+Test10 *Test10::self()
+{
+  if ( !mSelf ) {
+    staticTest10Deleter.setObject( mSelf, new Test10() );
+    mSelf->readConfig();
+  }
+
+  return mSelf;
+}
+
+Test10::Test10(  )
+  : KConfigSkeleton( QLatin1String( "test10rc" ) )
+{
+  mSelf = this;
+  setCurrentGroup( QLatin1String( "Foo" ) );
+
+  KConfigSkeleton::ItemUrl  *itemFooBar;
+  itemFooBar = new KConfigSkeleton::ItemUrl( currentGroup(), QLatin1String( "foo bar" ), mFooBar );
+  addItem( itemFooBar, QLatin1String( "FooBar" ) );
+  KConfigSkeleton::ItemUrlList  *itemBarFoo;
+  itemBarFoo = new KConfigSkeleton::ItemUrlList( currentGroup(), QLatin1String( "bar foo" ), mBarFoo );
+  addItem( itemBarFoo, QLatin1String( "BarFoo" ) );
+}
+
+Test10::~Test10()
+{
+  if ( mSelf == this )
+    staticTest10Deleter.setObject( mSelf, 0, false );
+}
+
Index: kdecore/kconfig_compiler/tests/test10main.cpp
===================================================================
--- kdecore/kconfig_compiler/tests/test10main.cpp	(Revision 0)
+++ kdecore/kconfig_compiler/tests/test10main.cpp	(Revision 0)
@@ -0,0 +1,30 @@
+/*
+Copyright (c) 2007 Andreas Pakulat <apaku at gmx.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.
+*/
+
+#include "test10.h"
+#include "kcomponentdata.h"
+
+int main( int, char** )
+{
+  KComponentData i("test");
+  Test10 *t = Test10::self();
+  delete t;
+}
Index: kdecore/kconfig_compiler/tests/test10.h.ref
===================================================================
--- kdecore/kconfig_compiler/tests/test10.h.ref	(Revision 0)
+++ kdecore/kconfig_compiler/tests/test10.h.ref	(Revision 0)
@@ -0,0 +1,54 @@
+// This file is generated by kconfig_compiler from test10.kcfg.
+// All changes you do to this file will be lost.
+#ifndef TEST10_H
+#define TEST10_H
+
+#include <kconfigskeleton.h>
+#include <kdebug.h>
+
+class Test10 : public KConfigSkeleton
+{
+  public:
+
+    static Test10 *self();
+    ~Test10();
+
+
+    /**
+      Get foo bar
+    */
+    static
+    KUrl fooBar()
+    {
+      return self()->mFooBar;
+    }
+
+
+    /**
+      Get bar foo
+    */
+    static
+    KUrl::List barFoo()
+    {
+      return self()->mBarFoo;
+    }
+
+    static
+    void writeConfig()
+    {
+      static_cast<KConfigSkeleton*>(self())->writeConfig();
+    }
+  protected:
+    Test10();
+    static Test10 *mSelf;
+
+
+    // Foo
+    KUrl mFooBar;
+    KUrl::List mBarFoo;
+
+  private:
+};
+
+#endif
+
Index: kdecore/kconfig_compiler/tests/CMakeLists.txt
===================================================================
--- kdecore/kconfig_compiler/tests/CMakeLists.txt	(Revision 644373)
+++ kdecore/kconfig_compiler/tests/CMakeLists.txt	(Arbeitskopie)
@@ -144,6 +144,19 @@ target_link_libraries(test9  ${KDE4_KDEC
 
 ########### next target ###############
 
+set(test10_SRCS test10main.cpp )
+
+kde4_automoc(${test10_SRCS})
+
+gen_kcfg_test_source(test10 test10_SRCS)
+
+kde4_add_executable(test10 NOGUI ${test10_SRCS})
+
+target_link_libraries(test10  ${KDE4_KDECORE_LIBS} )
+
+
+########### next target ###############
+
 set(test_dpointer_SRCS test_dpointer_main.cpp )
 
 kde4_automoc(${test_dpointer_SRCS})
Index: kdecore/kconfig_compiler/tests/test10.kcfg
===================================================================
--- kdecore/kconfig_compiler/tests/test10.kcfg	(Revision 0)
+++ kdecore/kconfig_compiler/tests/test10.kcfg	(Revision 0)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<kcfg xmlns="http://www.kde.org/standards/kcfg/1.0"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xsi:schemaLocation="http://www.kde.org/standards/kcfg/1.0
+                          http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
+  <kcfgfile name="test10rc"/>
+
+  <group name="Foo">
+      <entry name="FooBar" key="foo bar" type="Url"/>
+      <entry name="BarFoo" key="bar foo" type="UrlList"/>
+  </group>
+
+</kcfg>
Index: kdecore/kconfig_compiler/kcfg.xsd
===================================================================
--- kdecore/kconfig_compiler/kcfg.xsd	(Revision 644373)
+++ kdecore/kconfig_compiler/kcfg.xsd	(Arbeitskopie)
@@ -179,6 +179,8 @@
             <xsd:enumeration value="Path"/>
             <xsd:enumeration value="PathList"/>
             <xsd:enumeration value="Password"/>
+            <xsd:enumeration value="Url"/>
+            <xsd:enumeration value="UrlList"/>
         </xsd:restriction>
     </xsd:simpleType>
     
Index: kdecore/kconfig_compiler/kconfig_compiler.cpp
===================================================================
--- kdecore/kconfig_compiler/kconfig_compiler.cpp	(Revision 644373)
+++ kdecore/kconfig_compiler/kconfig_compiler.cpp	(Arbeitskopie)
@@ -763,6 +763,8 @@ QString param( const QString &type )
     else if ( type == "Path" )        return "const QString &";
     else if ( type == "PathList" )    return "const QStringList &";
     else if ( type == "Password" )    return "const QString &";
+    else if ( type == "Url" )         return "const KUrl &";
+    else if ( type == "UrlList" )     return "const KUrl::List &";
     else {
         std::cerr <<"kconfig_compiler does not support type \""<< type <<"\""<<std::endl;
         return "QString"; //For now, but an assert would be better
@@ -793,6 +795,8 @@ QString cppType( const QString &type )
     else if ( type == "Path" )        return "QString";
     else if ( type == "PathList" )    return "QStringList";
     else if ( type == "Password" )    return "QString";
+    else if ( type == "Url" )         return "KUrl";
+    else if ( type == "UrlList" )     return "KUrl::List";
     else {
         std::cerr<<"kconfig_compiler does not support type \""<< type <<"\""<<std::endl;
         return "QString"; //For now, but an assert would be better
@@ -820,6 +824,8 @@ QString defaultValue( const QString &typ
     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 if ( type == "Url" )         return "KUrl()";
+    else if ( type == "UrlList" )     return "KUrl::List()";
     else {
         std::cerr<<"Error, kconfig_compiler doesn't support the \""<< type <<"\" type!"<<std::endl;
         return "QString"; //For now, but an assert would be better
Index: kdeui/dialogs/kconfigdialogmanager.cpp
===================================================================
--- kdeui/dialogs/kconfigdialogmanager.cpp	(Revision 644373)
+++ kdeui/dialogs/kconfigdialogmanager.cpp	(Arbeitskopie)
@@ -136,6 +136,8 @@ void KConfigDialogManager::initMaps()
     s_changedMap->insert( "KTextBrowser", SIGNAL(sourceChanged(const QString &)));
     s_changedMap->insert( "KTextEdit", SIGNAL(textChanged()));
     s_changedMap->insert( "KUrlRequester",  SIGNAL(textChanged (const QString& )));
+    s_changedMap->insert( "KUrlRequester",  SIGNAL(returnPressed (const QString& )));
+    s_changedMap->insert( "KUrlRequester",  SIGNAL(urlSelected (const KUrl& )));
     s_changedMap->insert( "KIntNumInput", SIGNAL(valueChanged (int)));
     s_changedMap->insert( "KIntSpinBox", SIGNAL(valueChanged (int)));
     s_changedMap->insert( "KDoubleNumInput", SIGNAL(valueChanged (double)));
Index: kdecore/util/conversion_check.h
===================================================================
--- kdecore/util/conversion_check.h	(Revision 644373)
+++ kdecore/util/conversion_check.h	(Arbeitskopie)
@@ -30,6 +30,7 @@
 #include <qpoint.h>
 #include <qsize.h>
 #include <qrect.h>
+#include <kurl.h>
 #include <qvariant.h>
 
 namespace ConversionCheck {
@@ -111,7 +112,8 @@ QVConversions(QPointF, unsupported, supp
 QVConversions(QByteArray, supported, supported);
 QVConversions(QStringList, unsupported, supported);
 QVConversions(QVariantList, unsupported, supported);
-
+QVConversions(KUrl, supported, supported);
+QVConversions(KUrl::List, unsupported, supported);
 }
 
 #endif


More information about the kde-core-devel mailing list