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.
160 lines
4.1 KiB
160 lines
4.1 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 1999 Simon Hausmann <hausmann@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 as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
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 "kdcopactionproxy.h"
|
||
|
|
||
|
#include <dcopclient.h>
|
||
|
#include <kapplication.h>
|
||
|
#include <kaction.h>
|
||
|
#include <kdebug.h>
|
||
|
#include <kdcoppropertyproxy.h>
|
||
|
|
||
|
#include <ctype.h>
|
||
|
|
||
|
class KDCOPActionProxy::KDCOPActionProxyPrivate
|
||
|
{
|
||
|
public:
|
||
|
KDCOPActionProxyPrivate()
|
||
|
{
|
||
|
}
|
||
|
~KDCOPActionProxyPrivate()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
KActionCollection *m_actionCollection;
|
||
|
DCOPObject *m_parent;
|
||
15 years ago
|
TQCString m_prefix;
|
||
15 years ago
|
int m_pos;
|
||
|
};
|
||
|
|
||
|
KDCOPActionProxy::KDCOPActionProxy( KActionCollection *actionCollection, DCOPObject *parent )
|
||
|
{
|
||
|
init( actionCollection, parent );
|
||
|
}
|
||
|
|
||
|
KDCOPActionProxy::KDCOPActionProxy( DCOPObject *parent )
|
||
|
{
|
||
|
init( 0, parent );
|
||
|
}
|
||
|
|
||
|
void KDCOPActionProxy::init( KActionCollection *collection, DCOPObject *parent )
|
||
|
{
|
||
|
d = new KDCOPActionProxyPrivate;
|
||
|
d->m_actionCollection = collection;
|
||
|
d->m_parent = parent;
|
||
|
d->m_prefix = parent->objId() + "/action/";
|
||
|
d->m_pos = d->m_prefix.length();
|
||
|
}
|
||
|
|
||
|
KDCOPActionProxy::~KDCOPActionProxy()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQValueList<KAction *>KDCOPActionProxy::actions() const
|
||
15 years ago
|
{
|
||
|
if ( !d->m_actionCollection )
|
||
15 years ago
|
return TQValueList<KAction *>();
|
||
15 years ago
|
|
||
|
return d->m_actionCollection->actions();
|
||
|
}
|
||
|
|
||
|
KAction *KDCOPActionProxy::action( const char *name ) const
|
||
|
{
|
||
|
if ( !d->m_actionCollection )
|
||
|
return 0;
|
||
|
|
||
|
return d->m_actionCollection->action( name );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQCString KDCOPActionProxy::actionObjectId( const TQCString &name ) const
|
||
15 years ago
|
{
|
||
|
return d->m_prefix + name;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQMap<TQCString,DCOPRef> KDCOPActionProxy::actionMap( const TQCString &appId ) const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQMap<TQCString,DCOPRef> res;
|
||
15 years ago
|
|
||
15 years ago
|
TQCString id = appId;
|
||
15 years ago
|
if ( id.isEmpty() )
|
||
|
id = kapp->dcopClient()->appId();
|
||
|
|
||
15 years ago
|
TQValueList<KAction *> lst = actions();
|
||
|
TQValueList<KAction *>::ConstIterator it = lst.begin();
|
||
|
TQValueList<KAction *>::ConstIterator end = lst.end();
|
||
15 years ago
|
for (; it != end; ++it )
|
||
|
res.insert( (*it)->name(), DCOPRef( id, actionObjectId( (*it)->name() ) ) );
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPActionProxy::process( const TQCString &obj, const TQCString &fun, const TQByteArray &data,
|
||
|
TQCString &replyType, TQByteArray &replyData )
|
||
15 years ago
|
{
|
||
|
if ( obj.left( d->m_pos ) != d->m_prefix )
|
||
|
return false;
|
||
|
|
||
|
KAction *act = action( obj.mid( d->m_pos ) );
|
||
|
if ( !act )
|
||
|
return false;
|
||
|
|
||
|
return processAction( obj, fun, data, replyType, replyData, act );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPActionProxy::processAction( const TQCString &, const TQCString &fun, const TQByteArray &data,
|
||
|
TQCString &replyType, TQByteArray &replyData, KAction *action )
|
||
15 years ago
|
{
|
||
|
if ( fun == "activate()" )
|
||
|
{
|
||
|
replyType = "void";
|
||
|
action->activate();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if ( fun == "isPlugged()" )
|
||
|
{
|
||
|
replyType = "bool";
|
||
15 years ago
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
14 years ago
|
reply << (TQ_INT8)action->isPlugged();
|
||
15 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
if ( fun == "functions()" )
|
||
|
{
|
||
15 years ago
|
TQValueList<TQCString> res;
|
||
15 years ago
|
res << "QCStringList functions()";
|
||
|
res << "void activate()";
|
||
|
res << "bool isPlugged()";
|
||
|
|
||
|
res += KDCOPPropertyProxy::functions( action );
|
||
|
|
||
|
replyType = "QCStringList";
|
||
15 years ago
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
15 years ago
|
reply << res;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return KDCOPPropertyProxy::processPropertyRequest( fun, data, replyType, replyData, action );
|
||
|
}
|
||
|
|
||
|
void KDCOPActionProxy::virtual_hook( int id, void* data )
|
||
|
{ DCOPObjectProxy::virtual_hook( id, data ); }
|
||
|
|