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

KUtils

  • sources
  • kde-4.14
  • kdelibs
  • kutils
  • ksettings
dispatcher.cpp
Go to the documentation of this file.
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 #include "dispatcher.h"
21 #include "dispatcher_p.h"
22 
23 #include <kdebug.h>
24 #include <kconfig.h>
25 #include <kcomponentdata.h>
26 #include <assert.h>
27 #include <kglobal.h>
28 
29 namespace KSettings
30 {
31 
32 namespace Dispatcher
33 {
34 
35 K_GLOBAL_STATIC(DispatcherPrivate, d)
36 
37 void registerComponent(const KComponentData &componentData, QObject *recv, const char *slot)
38 {
39  Q_ASSERT(componentData.isValid());
40  // keep the KComponentData around and call
41  // componentData.config()->reparseConfiguration when the app should reparse
42  QString componentName = componentData.componentName();
43  kDebug(701) << componentName;
44  d->m_componentName[recv] = componentName;
45  if (!d->m_componentInfo.contains(componentName)) {
46  d->m_componentInfo[componentName].componentData = componentData;
47  }
48  d->m_componentInfo[componentName].slotList.append(ComponentInfo::Slot(recv, slot));
49 
50  ++(d->m_componentInfo[componentName].count);
51  QObject::connect(recv, SIGNAL(destroyed(QObject*)), d, SLOT(unregisterComponent(QObject*)));
52 }
53 
54 KSharedConfig::Ptr configForComponentName(const QString &componentName)
55 {
56  kDebug(701) ;
57  if (d->m_componentInfo.contains(componentName)) {
58  KComponentData componentData = d->m_componentInfo[componentName].componentData;
59  if (componentData.isValid()) {
60  return componentData.config();
61  }
62  }
63  kError(701) << "configForComponentName('" << componentName.constData()
64  << "') could not find the KComponentData object" << endl;
65  Q_ASSERT(!d->m_componentInfo.isEmpty());
66  return d->m_componentInfo.constBegin()->componentData.config();
67 }
68 
69 QList<QString> componentNames()
70 {
71  kDebug(701) ;
72  QList<QString> names;
73  for (QMap<QString, ComponentInfo>::ConstIterator it = d->m_componentInfo.constBegin(); it != d->m_componentInfo.constEnd(); ++it) {
74  if ((*it).count > 0) {
75  names.append(it.key());
76  }
77  }
78  return names;
79 }
80 
81 void reparseConfiguration(const QString & componentName)
82 {
83  kDebug(701) << componentName;
84  // check if the componentName is valid:
85  if (! d->m_componentInfo.contains(componentName)) {
86  return;
87  }
88  // first we reparse the config of the componentData so that the KConfig object
89  // will be up to date
90  KSharedConfig::Ptr config = d->m_componentInfo[componentName].componentData.config();
91  config->reparseConfiguration();
92  foreach(const ComponentInfo::Slot& slot, d->m_componentInfo[componentName].slotList ) {
93  QMetaObject::invokeMethod(slot.first, slot.second);
94  }
95 }
96 
97 void syncConfiguration()
98 {
99  for (QMap<QString, ComponentInfo>::ConstIterator it = d->m_componentInfo.constBegin(); it != d->m_componentInfo.constEnd(); ++it) {
100  KSharedConfig::Ptr config = (*it).componentData.config();
101  config->sync();
102  }
103 }
104 
105 void DispatcherPrivate::unregisterComponent(QObject *obj)
106 {
107  if (!m_componentName.contains(obj)) {
108  kWarning(701) << k_funcinfo << "Tried to unregister an object which is not already registered.";
109  return;
110  }
111 
112  QString name = m_componentName[obj];
113  m_componentName.remove(obj); //obj will be destroyed when we return, so we better remove this entry
114  --(m_componentInfo[name].count);
115  kDebug(701) << "componentName=" << name << "refcount=" << m_componentInfo[name].count;
116  Q_ASSERT(m_componentInfo[name].count >= 0);
117  if (m_componentInfo[name].count == 0) {
118  m_componentInfo.remove(name);
119  }
120 }
121 
122 } // namespace Dispatcher
123 } // namespace KSettings
124 
125 #include "dispatcher_p.moc"
KSharedPtr
KSettings::Dispatcher::configForComponentName
KSharedConfig::Ptr configForComponentName(const QString &componentName)
Definition: dispatcher.cpp:54
QString::constData
const QChar * constData() const
QMap::contains
bool contains(const Key &key) const
kdebug.h
KSettings::Dispatcher::DispatcherPrivate::m_componentInfo
QMap< QString, ComponentInfo > m_componentInfo
Definition: dispatcher_p.h:50
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
KSettings::Dispatcher::DispatcherPrivate::unregisterComponent
void unregisterComponent(QObject *)
Definition: dispatcher.cpp:105
kconfig.h
QMap::constBegin
const_iterator constBegin() const
QMap
kError
static QDebug kError(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
KSettings::Dispatcher::DispatcherPrivate::m_componentName
QMap< QObject *, QString > m_componentName
Definition: dispatcher_p.h:51
k_funcinfo
#define k_funcinfo
KSettings::Dispatcher::syncConfiguration
void syncConfiguration()
When this function is called the KConfig objects of all the registered instances are sync()ed...
Definition: dispatcher.cpp:97
config
KSharedConfigPtr config()
QObject::name
const char * name() const
kglobal.h
KComponentData::config
const KSharedConfig::Ptr & config() const
QList::append
void append(const T &value)
QObject
dispatcher_p.h
KSettings::Dispatcher::DispatcherPrivate
Definition: dispatcher_p.h:46
QString
QList
Definition: dialog.h:29
QPair
KSettings::Dispatcher::componentNames
QList< QString > componentNames()
Definition: dispatcher.cpp:69
dispatcher.h
KSettings::Dispatcher::reparseConfiguration
void reparseConfiguration(const QString &componentName)
Call this function when the configuration belonging to the associated componentData name has changed...
Definition: dispatcher.cpp:81
QMetaObject::invokeMethod
bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QGenericReturnArgument ret, QGenericArgument val0, QGenericArgument val1, QGenericArgument val2, QGenericArgument val3, QGenericArgument val4, QGenericArgument val5, QGenericArgument val6, QGenericArgument val7, QGenericArgument val8, QGenericArgument val9)
KComponentData::isValid
bool isValid() const
KSettings::Dispatcher::registerComponent
void registerComponent(const KComponentData &componentData, QObject *recv, const char *slot)
Register a slot to be called when the configuration for the componentData has changed.
Definition: dispatcher.cpp:37
kWarning
static QDebug kWarning(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
kcomponentdata.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KComponentData
QMap::remove
int remove(const Key &key)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KUtils

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal