home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ksettings / dispatcher.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-22  |  4.3 KB  |  134 lines

  1. /*  This file is part of the KDE project
  2.     Copyright (C) 2003 Matthias Kretz <kretz@kde.org>
  3.  
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License version 2 as published by the Free Software Foundation.
  7.  
  8.     This library is distributed in the hope that it will be useful,
  9.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.     Library General Public License for more details.
  12.  
  13.     You should have received a copy of the GNU Library General Public License
  14.     along with this library; see the file COPYING.LIB.  If not, write to
  15.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.     Boston, MA 02110-1301, USA.
  17.  
  18. */
  19.  
  20. #ifndef KSETTINGS_DISPATCHER_H
  21. #define KSETTINGS_DISPATCHER_H
  22.  
  23. #include <qobject.h>
  24. #include <qmap.h>
  25. #include <kdelibs_export.h>
  26.  
  27. class QCString;
  28. class QSignal;
  29. class QStrList;
  30. template<class T> class KStaticDeleter;
  31. class KInstance;
  32. class KConfig;
  33.  
  34. namespace KSettings
  35. {
  36.  
  37. /**
  38.  * @ingroup settings
  39.  * @short Dispatch change notifications from the KCMs to the program.
  40.  *
  41.  * Since your program does not have direct control over the KCMs that get loaded
  42.  * into the KConfigureDialog you need a way to get notified. This is what you
  43.  * do:
  44.  * \code
  45.  * Dispatcher::self()->registerInstance( instance(), this, SLOT( loadSettings() ) );
  46.  * \endcode
  47.  *
  48.  * @author Matthias Kretz <kretz@kde.org>
  49.  * @since 3.2
  50.  */
  51. class KUTILS_EXPORT Dispatcher : public QObject
  52. {
  53.     friend class KStaticDeleter<Dispatcher>;
  54.  
  55.     Q_OBJECT
  56.     public:
  57.         /**
  58.          * Get a reference the the Dispatcher object.
  59.          */
  60.         static Dispatcher * self();
  61.  
  62.         /**
  63.          * Register a slot to be called when the configuration for the instance
  64.          * has changed. @p instance is the KInstance object
  65.          * that is passed to KGenericFactory (if it is used). You can query
  66.          * it with KGenericFactory<YourClassName>::instance().
  67.          * instance->instanceName() is also the same name that is put into the
  68.          * .desktop file of the KCMs for the X-KDE-ParentComponents.
  69.          *
  70.          * @param instance     The KInstance object
  71.          * @param recv         The object that should receive the signal
  72.          * @param slot         The slot to be called: SLOT( slotName() )
  73.          */
  74.         void registerInstance( KInstance * instance, QObject * recv, const char * slot );
  75.  
  76.         /**
  77.          * @return the KConfig object that belongs to the instanceName
  78.          */
  79.         KConfig * configForInstanceName( const QCString & instanceName );
  80.  
  81.         /**
  82.          * @return a list of all the instance names that are currently
  83.          * registered
  84.          */
  85.         QStrList instanceNames() const;
  86.  
  87. //X         /**
  88. //X          * @return The KInstance object belonging to the instance name you pass
  89. //X          * (only works for registered instances of course).
  90. //X          */
  91. //X         KInstance * instanceForName( const QCString & instanceName );
  92.  
  93.     public slots:
  94.         /**
  95.          * Call this slot when the configuration belonging to the associated
  96.          * instance name has changed. The registered slot will be called.
  97.          *
  98.          * @param instanceName The value of X-KDE-ParentComponents.
  99.          */
  100.         void reparseConfiguration( const QCString & instanceName );
  101.  
  102.         /**
  103.          * When this slot is called the KConfig objects of all the registered
  104.          * instances are sync()ed. This is usefull when some other KConfig
  105.          * objects will read/write from/to the same config file, so that you
  106.          * can first write out the current state of the KConfig objects.
  107.          */
  108.         void syncConfiguration();
  109.  
  110.     private slots:
  111.         void unregisterInstance( QObject * );
  112.  
  113.     private:
  114.         Dispatcher( QObject * parent = 0, const char * name = 0 );
  115.         ~Dispatcher();
  116.         static Dispatcher * m_self;
  117.  
  118.         struct InstanceInfo {
  119.             KInstance * instance;
  120.             QSignal * signal;
  121.             int count;
  122.         };
  123.         QMap<QCString, InstanceInfo> m_instanceInfo;
  124.         QMap<QObject *, QCString> m_instanceName;
  125.  
  126.         class DispatcherPrivate;
  127.         DispatcherPrivate * d;
  128. };
  129.  
  130. }
  131.  
  132. // vim: sw=4 sts=4 et
  133. #endif // KSETTINGS_DISPATCHER_H
  134.