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

Andreas Pakulat apaku at gmx.de
Mon Mar 19 15:27:25 GMT 2007


Hi,

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
already defines url/setUrl as user property and thus no further changes
are needed. Also included is a proper change to kconfig_compiler to use
the new KConfigSkeletonItem in the .kcfg files. 

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.

One problematic thing is that any app that wants to use KUrl wrapped in
a QVariant needs to call qRegisterMetaType<KUrl>("KUrl");. I think this
should be somewhere in kconfig or maybe even KUrl code, but I'm not sure
where to put it, so any comments welcome regarding that. KUrl
constructor might be a good enough place, as calling the function
multiple times doesn't seem to be a problem.

Andreas

-- 
You will give someone a piece of your mind, which you can ill afford.
-------------- next part --------------
Index: kdecore/config/kconfigskeleton.cpp
===================================================================
--- kdecore/config/kconfigskeleton.cpp	(Revision 642947)
+++ 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,
Index: kdecore/config/kconfigskeleton.h
===================================================================
--- kdecore/config/kconfigskeleton.h	(Revision 642947)
+++ 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.
Index: kdecore/kconfig_compiler/kcfg.xsd
===================================================================
--- kdecore/kconfig_compiler/kcfg.xsd	(Revision 642947)
+++ kdecore/kconfig_compiler/kcfg.xsd	(Arbeitskopie)
@@ -179,6 +179,7 @@
             <xsd:enumeration value="Path"/>
             <xsd:enumeration value="PathList"/>
             <xsd:enumeration value="Password"/>
+            <xsd:enumeration value="Url"/>
         </xsd:restriction>
     </xsd:simpleType>
     
Index: kdecore/kconfig_compiler/kconfig_compiler.cpp
===================================================================
--- kdecore/kconfig_compiler/kconfig_compiler.cpp	(Revision 642947)
+++ kdecore/kconfig_compiler/kconfig_compiler.cpp	(Arbeitskopie)
@@ -763,6 +763,7 @@ 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 {
         std::cerr <<"kconfig_compiler does not support type \""<< type <<"\""<<std::endl;
         return "QString"; //For now, but an assert would be better
@@ -793,6 +794,7 @@ 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 {
         std::cerr<<"kconfig_compiler does not support type \""<< type <<"\""<<std::endl;
         return "QString"; //For now, but an assert would be better
@@ -820,6 +822,7 @@ 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()"; // Use empty string, not null string!
     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 642947)
+++ 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)));


More information about the kde-core-devel mailing list