• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeutils
 

tdeutils

  • tdeutils
  • ksettings
dispatcher.cpp
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 "ksettings/dispatcher.h"
21
22#include <tqsignal.h>
23
24#include <kstaticdeleter.h>
25#include <kdebug.h>
26#include <tdeconfig.h>
27#include <assert.h>
28
29namespace KSettings
30{
31
32//class Dispatcher::DispatcherPrivate
33//{
34//};
35
36static KStaticDeleter<Dispatcher> ksd_kpd;
37
38Dispatcher * Dispatcher::m_self = 0;
39
40Dispatcher * Dispatcher::self()
41{
42 kdDebug( 701 ) << k_funcinfo << endl;
43 if( m_self == 0 )
44 ksd_kpd.setObject( m_self, new Dispatcher() );
45 return m_self;
46}
47
48Dispatcher::Dispatcher( TQObject * parent, const char * name )
49 : TQObject( parent, name )
50 //, d( 0 )
51{
52 kdDebug( 701 ) << k_funcinfo << endl;
53}
54
55Dispatcher::~Dispatcher()
56{
57 kdDebug( 701 ) << k_funcinfo << endl;
58 //delete d;
59}
60
61void Dispatcher::registerInstance( TDEInstance * instance, TQObject * recv, const char * slot )
62{
63 assert( instance != 0 );
64 // keep the TDEInstance around and call
65 // instance->config()->reparseConfiguration when the app should reparse
66 TQCString instanceName = instance->instanceName();
67 kdDebug( 701 ) << k_funcinfo << instanceName << endl;
68 m_instanceName[ recv ] = instanceName;
69 TQSignal * sig;
70 if( m_instanceInfo.contains( instanceName ) )
71 {
72 sig = m_instanceInfo[ instanceName ].signal;
73 }
74 else
75 {
76 sig = new TQSignal( this, "signal dispatcher" );
77 m_instanceInfo[ instanceName ].signal = sig;
78 m_instanceInfo[ instanceName ].instance = instance;
79 }
80 sig->connect( recv, slot );
81
82 ++m_instanceInfo[ instanceName ].count;
83 connect( recv, TQ_SIGNAL( destroyed( TQObject * ) ), this, TQ_SLOT( unregisterInstance( TQObject * ) ) );
84}
85
86TDEConfig * Dispatcher::configForInstanceName( const TQCString & instanceName )
87{
88 kdDebug( 701 ) << k_funcinfo << endl;
89 if( m_instanceInfo.contains( instanceName ) )
90 {
91 TDEInstance * inst = m_instanceInfo[ instanceName ].instance;
92 if( inst )
93 return inst->config();
94 }
95 //if( fallback )
96 //return new KSimpleConfig( instanceName );
97 return 0;
98}
99
100TQStrList Dispatcher::instanceNames() const
101{
102 kdDebug( 701 ) << k_funcinfo << endl;
103 TQStrList names;
104 for( TQMap<TQCString, InstanceInfo>::ConstIterator it = m_instanceInfo.begin(); it != m_instanceInfo.end(); ++it )
105 if( ( *it ).count > 0 )
106 names.append( it.key() );
107 return names;
108}
109
110void Dispatcher::reparseConfiguration( const TQCString & instanceName )
111{
112 kdDebug( 701 ) << k_funcinfo << instanceName << endl;
113 // check if the instanceName is valid:
114 if( ! m_instanceInfo.contains( instanceName ) )
115 return;
116 // first we reparse the config of the instance so that the TDEConfig object
117 // will be up to date
118 m_instanceInfo[ instanceName ].instance->config()->reparseConfiguration();
119 TQSignal * sig = m_instanceInfo[ instanceName ].signal;
120 if( sig )
121 {
122 kdDebug( 701 ) << "emit signal to instance" << endl;
123 sig->activate();
124 }
125}
126
127void Dispatcher::syncConfiguration()
128{
129 for( TQMap<TQCString, InstanceInfo>::ConstIterator it = m_instanceInfo.begin(); it != m_instanceInfo.end(); ++it )
130 {
131 ( *it ).instance->config()->sync();
132 }
133}
134
135void Dispatcher::unregisterInstance( TQObject * obj )
136{
137 kdDebug( 701 ) << k_funcinfo << endl;
138 TQCString name = m_instanceName[ obj ];
139 m_instanceName.remove( obj ); //obj will be destroyed when we return, so we better remove this entry
140 --m_instanceInfo[ name ].count;
141 if( m_instanceInfo[ name ].count == 0 )
142 {
143 delete m_instanceInfo[ name ].signal;
144 m_instanceInfo.remove( name );
145 }
146}
147
148//X TDEInstance * Dispatcher::instanceForName( const TQCString & instanceName )
149//X {
150//X return m_instanceInfo[ instanceName ].instance;
151//X }
152
153} //namespace
154
155#include "dispatcher.moc"
KSettings::Dispatcher
Dispatch change notifications from the KCMs to the program.
Definition: dispatcher.h:52
KSettings::Dispatcher::syncConfiguration
void syncConfiguration()
When this slot is called the TDEConfig objects of all the registered instances are sync()ed.
Definition: dispatcher.cpp:127
KSettings::Dispatcher::self
static Dispatcher * self()
Get a reference the the Dispatcher object.
Definition: dispatcher.cpp:40
KSettings::Dispatcher::registerInstance
void registerInstance(TDEInstance *instance, TQObject *recv, const char *slot)
Register a slot to be called when the configuration for the instance has changed.
Definition: dispatcher.cpp:61
KSettings::Dispatcher::instanceNames
TQStrList instanceNames() const
Definition: dispatcher.cpp:100
KSettings::Dispatcher::reparseConfiguration
void reparseConfiguration(const TQCString &instanceName)
Call this slot when the configuration belonging to the associated instance name has changed.
Definition: dispatcher.cpp:110
KSettings::Dispatcher::configForInstanceName
TDEConfig * configForInstanceName(const TQCString &instanceName)
Definition: dispatcher.cpp:86
KStaticDeleter
TDEConfig
TDEInstance
TDEInstance::instanceName
TQCString instanceName() const
TDEInstance::config
TDEConfig * config() const
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)
KSettings
A collection of classes to create configuration dialogs that work over component boundaries.
Definition: componentsdialog.cpp:33

tdeutils

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

tdeutils

Skip menu "tdeutils"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeutils by doxygen 1.9.4
This website is maintained by Timothy Pearson.