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

KUtils

  • 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
29namespace KSettings
30{
31
32namespace Dispatcher
33{
34
35K_GLOBAL_STATIC(DispatcherPrivate, d)
36
37void 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
54KSharedConfig::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
69QList<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
81void 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
97void 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
105void 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"
KComponentData
KComponentData::isValid
bool isValid() const
KComponentData::config
const KSharedConfig::Ptr & config() const
KSettings::Dispatcher::DispatcherPrivate
Definition: dispatcher_p.h:47
KSettings::Dispatcher::DispatcherPrivate::m_componentName
QMap< QObject *, QString > m_componentName
Definition: dispatcher_p.h:51
KSettings::Dispatcher::DispatcherPrivate::unregisterComponent
void unregisterComponent(QObject *)
Definition: dispatcher.cpp:105
KSettings::Dispatcher::DispatcherPrivate::m_componentInfo
QMap< QString, ComponentInfo > m_componentInfo
Definition: dispatcher_p.h:50
KSharedPtr< KSharedConfig >
KSharedPtr::constData
const T * constData() const
QList
QMap
QObject
QPair
dispatcher.h
dispatcher_p.h
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
k_funcinfo
#define k_funcinfo
kDebug
#define kDebug
kWarning
#define kWarning
kcomponentdata.h
kconfig.h
kdebug.h
kglobal.h
config
KSharedConfigPtr config()
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
KSettings::Dispatcher::configForComponentName
KSharedConfig::Ptr configForComponentName(const QString &componentName)
Definition: dispatcher.cpp:54
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
KSettings::Dispatcher::componentNames
QList< QString > componentNames()
Definition: dispatcher.cpp:69
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
KSettings
A collection of classes to create configuration dialogs that work over component boundaries.
Definition: componentsdialog.cpp:34
name
const char * name(StandardAction id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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