KCM questions and

Frans Englich frans.englich at telia.com
Wed Feb 4 00:07:46 GMT 2004


I've played with the following macro, which perhaps would be suiting for 
kcmodule.h The API docs says pretty much it all:

+ * The macro defines a library for a KConfig Module.
+ *
+ * @param className The class name of your module.
+ *
+ * @param modName The name of your module Without the
+ * the initial "kcm_" part. Remember, the messages target
+ * in your Makefile.am must specify the @modName AND the
+ * "kcm_" part.
+ *
+ * An example:
+ *
+ * \code
+ * // In your .cpp file:
+ * KCMODULE( useraccount, KCMUserAccount )
+ * \endcode
+ *
+ * And in your Makefile.am something similar to:
+ * \code
+ * messages: rc.cpp
+ *        # Notice the kcm_ suffice for useraccount.pot
+ *         $(XGETTEXT) *.cpp $(podir)/kcm_useraccount.pot
+ * \endcode
+ *
+ * using KCMODULE is a easier alternative to the old:
+ * \code
+ *   typedef KGenericFactory<YourKCModule, QWidget> YourKCModuleFactory;
+ *   K_EXPORT_COMPONENT_FACTORY( yourLibName, 
YourKCModuleFactory("name_of_the_po_file") );
+ * \endcode
+ *
+ */
+#define KCMODULE(mod_name, class_name) \
+       typedef KGenericFactory<className, QWidget> KDEDFactory; \
+       K_EXPORT_COMPONENT_FACTORY ( kcm_ ## modName , \
+               KDEDFactory( #mod_name ) )
+
+/**

But I've probably missed something crucial.. What do people think?

BTW, what happens if the name of the pot file is changed in the messages 
target - is it automatically taken care of or must you move files manually 
around? (If this macro is a good idea, can old code be in a simple way 
upgraded?)

Another thing which would be handy is an "overload" signal for the KCModule. 
With my crippled knowledge I can't get it to work(segfaults), nor knows if 
it's possible to do the following(or solve it another way):

//kcmodule.{cpp,h}
+   * This is a "overload" signal of the above. Emitting it is equivalent
+   * to emitting changed(true)
+   */
+  void changed();
+
+  /**
    * Indicate that the module's quickhelp has changed.
    *
    * Emit this signal whenever the module's quickhelp changes.
@@ -256,8 +300,16 @@ protected:
    */
   void setUseRootOnlyMsg(bool on);

+private slots:
+
+  /**
+   * Simple: Catches changed() and emits changed(true)
+   */
+  void bounceChanged();
+
 private:


diff -u -3 -p -r1.20 kcmodule.cpp
--- kdeui/kcmodule.cpp  22 Nov 2003 10:52:01 -0000      1.20
+++ kdeui/kcmodule.cpp  3 Feb 2004 23:59:39 -0000
@@ -38,6 +38,8 @@ public:
 KCModule::KCModule(QWidget *parent, const char *name, const QStringList &)
        : QWidget(parent, name), _btn(Help|Default|Apply)
 {
+    connect( this, SIGNAL(changed()), SLOT(bounceChanged()));
+
     kdDebug( 281 ) << "KCModule " << name << endl;
     d = new KCModulePrivate;
     d->_useRootOnlyMsg = true;
@@ -49,11 +51,18 @@ KCModule::KCModule(QWidget *parent, cons
                d->_instance = new KInstance("kcmunnamed");
     d->_hasOwnInstance = true;
     KGlobal::setActiveInstance(this->instance());
+
+}
+
+void KCModule::bounceChanged()
+{
+    emit changed(true);
 }

 KCModule::KCModule(KInstance *instance, QWidget *parent, const QStringList 
& )
     : QWidget(parent, instance ? instance->instanceName().data() : 0), 
_btn(Help|Default|Apply)
 {
+    connect( this, SIGNAL(changed(bool)), SLOT(bounceChanged()));
     kdDebug( 281 ) << "KCModule instance " << (instance ? 
instance->instanceName().data() : "none") << endl;
     d = new KCModulePrivate;
     d->_useRootOnlyMsg = true;


BTW, how do you debug libraries in kdelibs? KDE's all voodoo, kinit and black 
magic doesn't pick up changed libraries. How is this solved?

Cheers,

		Frans









More information about the kde-core-devel mailing list