• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KUtils

dispatcher.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2003 Matthias Kretz <kretz@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016     Boston, MA 02110-1301, USA.
00017 
00018 */
00019 
00020 #include "dispatcher.h"
00021 #include "dispatcher_p.h"
00022 
00023 #include <kdebug.h>
00024 #include <kconfig.h>
00025 #include <kcomponentdata.h>
00026 #include <assert.h>
00027 #include <kglobal.h>
00028 
00029 namespace KSettings
00030 {
00031 
00032 namespace Dispatcher
00033 {
00034 
00035 K_GLOBAL_STATIC(DispatcherPrivate, d)
00036 
00037 void registerComponent(const KComponentData &componentData, QObject *recv, const char *slot)
00038 {
00039     Q_ASSERT(componentData.isValid());
00040     // keep the KComponentData around and call
00041     // componentData.config()->reparseConfiguration when the app should reparse
00042     QString componentName = componentData.componentName();
00043     kDebug(701) << componentName;
00044     d->m_componentName[recv] = componentName;
00045     if (!d->m_componentInfo.contains(componentName)) {
00046         d->m_componentInfo[componentName].componentData = componentData;
00047     }
00048     d->m_componentInfo[componentName].slotList.append(ComponentInfo::Slot(recv, slot));
00049 
00050     ++(d->m_componentInfo[componentName].count);
00051     QObject::connect(recv, SIGNAL(destroyed(QObject *)), d, SLOT(unregisterComponent(QObject *)));
00052 }
00053 
00054 KSharedConfig::Ptr configForComponentName(const QString &componentName)
00055 {
00056     kDebug(701) ;
00057     if (d->m_componentInfo.contains(componentName)) {
00058         KComponentData componentData = d->m_componentInfo[componentName].componentData;
00059         if (componentData.isValid()) {
00060             return componentData.config();
00061         }
00062     }
00063     kError(701) << "configForComponentName('" << componentName.constData()
00064         << "') could not find the KComponentData object" << endl;
00065     Q_ASSERT(!d->m_componentInfo.isEmpty());
00066     return d->m_componentInfo.constBegin()->componentData.config();
00067 }
00068 
00069 QList<QString> componentNames()
00070 {
00071     kDebug(701) ;
00072     QList<QString> names;
00073     for (QMap<QString, ComponentInfo>::ConstIterator it = d->m_componentInfo.constBegin(); it != d->m_componentInfo.constEnd(); ++it) {
00074         if ((*it).count > 0) {
00075             names.append(it.key());
00076         }
00077     }
00078     return names;
00079 }
00080 
00081 void reparseConfiguration(const QString & componentName)
00082 {
00083     kDebug(701) << componentName;
00084     // check if the componentName is valid:
00085     if (! d->m_componentInfo.contains(componentName)) {
00086         return;
00087     }
00088     // first we reparse the config of the componentData so that the KConfig object
00089     // will be up to date
00090     KSharedConfig::Ptr config = d->m_componentInfo[componentName].componentData.config();
00091     config->reparseConfiguration();
00092     foreach(const ComponentInfo::Slot& slot, d->m_componentInfo[componentName].slotList ) {
00093         QMetaObject::invokeMethod(slot.first, slot.second);
00094     }
00095 }
00096 
00097 void syncConfiguration()
00098 {
00099     for (QMap<QString, ComponentInfo>::ConstIterator it = d->m_componentInfo.constBegin(); it != d->m_componentInfo.constEnd(); ++it) {
00100         KSharedConfig::Ptr config = (*it).componentData.config();
00101         config->sync();
00102     }
00103 }
00104 
00105 void DispatcherPrivate::unregisterComponent(QObject *obj)
00106 {
00107     if (!m_componentName.contains(obj)) {
00108       kWarning(701) << k_funcinfo << "Tried to unregister an object which is not already registered.";
00109       return;
00110     }
00111 
00112     QString name = m_componentName[obj];
00113     m_componentName.remove(obj); //obj will be destroyed when we return, so we better remove this entry
00114     --(m_componentInfo[name].count);
00115     kDebug(701) << "componentName=" << name << "refcount=" << m_componentInfo[name].count;
00116     Q_ASSERT(m_componentInfo[name].count >= 0);
00117     if (m_componentInfo[name].count == 0) {
00118         m_componentInfo.remove(name);
00119     }
00120 }
00121 
00122 } // namespace Dispatcher
00123 } // namespace KSettings
00124 
00125 #include "dispatcher_p.moc"

KUtils

Skip menu "KUtils"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal