You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
4.5 KiB
158 lines
4.5 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2003 Matthias Kretz <kretz@kde.org>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License version 2 as published by the Free Software Foundation.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
Boston, MA 02110-1301, USA.
|
||
|
|
||
|
*/
|
||
|
|
||
|
#include "ksettings/dispatcher.h"
|
||
|
|
||
14 years ago
|
#include <tqsignal.h>
|
||
15 years ago
|
|
||
|
#include <kstaticdeleter.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kconfig.h>
|
||
|
#include <assert.h>
|
||
|
|
||
|
namespace KSettings
|
||
|
{
|
||
|
|
||
|
//class Dispatcher::DispatcherPrivate
|
||
|
//{
|
||
|
//};
|
||
|
|
||
|
static KStaticDeleter<Dispatcher> ksd_kpd;
|
||
|
|
||
|
Dispatcher * Dispatcher::m_self = 0;
|
||
|
|
||
|
Dispatcher * Dispatcher::self()
|
||
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << endl;
|
||
|
if( m_self == 0 )
|
||
|
ksd_kpd.setObject( m_self, new Dispatcher() );
|
||
|
return m_self;
|
||
|
}
|
||
|
|
||
14 years ago
|
Dispatcher::Dispatcher( TQObject * parent, const char * name )
|
||
|
: TQObject( parent, name )
|
||
15 years ago
|
//, d( 0 )
|
||
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << endl;
|
||
|
}
|
||
|
|
||
|
Dispatcher::~Dispatcher()
|
||
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << endl;
|
||
|
//delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
void Dispatcher::registerInstance( TDEInstance * instance, TQObject * recv, const char * slot )
|
||
15 years ago
|
{
|
||
|
assert( instance != 0 );
|
||
12 years ago
|
// keep the TDEInstance around and call
|
||
15 years ago
|
// instance->config()->reparseConfiguration when the app should reparse
|
||
14 years ago
|
TQCString instanceName = instance->instanceName();
|
||
15 years ago
|
kdDebug( 701 ) << k_funcinfo << instanceName << endl;
|
||
|
m_instanceName[ recv ] = instanceName;
|
||
14 years ago
|
TQSignal * sig;
|
||
13 years ago
|
if( m_instanceInfo.contains( instanceName ) )
|
||
15 years ago
|
{
|
||
|
sig = m_instanceInfo[ instanceName ].signal;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
sig = new TQSignal( this, "signal dispatcher" );
|
||
15 years ago
|
m_instanceInfo[ instanceName ].signal = sig;
|
||
|
m_instanceInfo[ instanceName ].instance = instance;
|
||
|
}
|
||
|
sig->connect( recv, slot );
|
||
|
|
||
|
++m_instanceInfo[ instanceName ].count;
|
||
14 years ago
|
connect( recv, TQT_SIGNAL( destroyed( TQObject * ) ), this, TQT_SLOT( unregisterInstance( TQObject * ) ) );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEConfig * Dispatcher::configForInstanceName( const TQCString & instanceName )
|
||
15 years ago
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << endl;
|
||
13 years ago
|
if( m_instanceInfo.contains( instanceName ) )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEInstance * inst = m_instanceInfo[ instanceName ].instance;
|
||
15 years ago
|
if( inst )
|
||
|
return inst->config();
|
||
|
}
|
||
|
//if( fallback )
|
||
|
//return new KSimpleConfig( instanceName );
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQStrList Dispatcher::instanceNames() const
|
||
15 years ago
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << endl;
|
||
14 years ago
|
TQStrList names;
|
||
|
for( TQMap<TQCString, InstanceInfo>::ConstIterator it = m_instanceInfo.begin(); it != m_instanceInfo.end(); ++it )
|
||
15 years ago
|
if( ( *it ).count > 0 )
|
||
|
names.append( it.key() );
|
||
|
return names;
|
||
|
}
|
||
|
|
||
14 years ago
|
void Dispatcher::reparseConfiguration( const TQCString & instanceName )
|
||
15 years ago
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << instanceName << endl;
|
||
|
// check if the instanceName is valid:
|
||
13 years ago
|
if( ! m_instanceInfo.contains( instanceName ) )
|
||
15 years ago
|
return;
|
||
12 years ago
|
// first we reparse the config of the instance so that the TDEConfig object
|
||
15 years ago
|
// will be up to date
|
||
|
m_instanceInfo[ instanceName ].instance->config()->reparseConfiguration();
|
||
14 years ago
|
TQSignal * sig = m_instanceInfo[ instanceName ].signal;
|
||
15 years ago
|
if( sig )
|
||
|
{
|
||
|
kdDebug( 701 ) << "emit signal to instance" << endl;
|
||
|
sig->activate();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Dispatcher::syncConfiguration()
|
||
|
{
|
||
14 years ago
|
for( TQMap<TQCString, InstanceInfo>::ConstIterator it = m_instanceInfo.begin(); it != m_instanceInfo.end(); ++it )
|
||
15 years ago
|
{
|
||
|
( *it ).instance->config()->sync();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void Dispatcher::unregisterInstance( TQObject * obj )
|
||
15 years ago
|
{
|
||
|
kdDebug( 701 ) << k_funcinfo << endl;
|
||
14 years ago
|
TQCString name = m_instanceName[ obj ];
|
||
15 years ago
|
m_instanceName.remove( obj ); //obj will be destroyed when we return, so we better remove this entry
|
||
|
--m_instanceInfo[ name ].count;
|
||
|
if( m_instanceInfo[ name ].count == 0 )
|
||
|
{
|
||
|
delete m_instanceInfo[ name ].signal;
|
||
|
m_instanceInfo.remove( name );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
//X TDEInstance * Dispatcher::instanceForName( const TQCString & instanceName )
|
||
15 years ago
|
//X {
|
||
|
//X return m_instanceInfo[ instanceName ].instance;
|
||
|
//X }
|
||
|
|
||
|
} //namespace
|
||
|
|
||
|
#include "dispatcher.moc"
|
||
|
|
||
|
// vim: sw=4 sts=4 et
|