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.
336 lines
8.4 KiB
336 lines
8.4 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 "kdcoppropertyproxy.h"
|
||
|
|
||
15 years ago
|
#include <tqstrlist.h>
|
||
|
#include <tqmetaobject.h>
|
||
|
#include <tqvariant.h>
|
||
|
#include <tqcursor.h>
|
||
|
#include <tqbitmap.h>
|
||
|
#include <tqregion.h>
|
||
|
#include <tqpointarray.h>
|
||
|
#include <tqiconset.h>
|
||
|
#include <tqfont.h>
|
||
|
#include <tqimage.h>
|
||
|
#include <tqbrush.h>
|
||
|
#include <tqpalette.h>
|
||
15 years ago
|
|
||
|
#include <ctype.h>
|
||
|
#include <assert.h>
|
||
|
|
||
|
class KDCOPPropertyProxyPrivate
|
||
|
{
|
||
|
public:
|
||
|
KDCOPPropertyProxyPrivate()
|
||
|
{
|
||
|
}
|
||
|
~KDCOPPropertyProxyPrivate()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
TQObject *m_object;
|
||
15 years ago
|
};
|
||
|
|
||
15 years ago
|
KDCOPPropertyProxy::KDCOPPropertyProxy( TQObject *object )
|
||
15 years ago
|
{
|
||
|
d = new KDCOPPropertyProxyPrivate;
|
||
|
d->m_object = object;
|
||
|
}
|
||
|
|
||
|
KDCOPPropertyProxy::~KDCOPPropertyProxy()
|
||
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPPropertyProxy::isPropertyRequest( const TQCString &fun )
|
||
15 years ago
|
{
|
||
|
return isPropertyRequest( fun, d->m_object );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPPropertyProxy::processPropertyRequest( const TQCString &fun, const TQByteArray &data,
|
||
|
TQCString &replyType, TQByteArray &replyData )
|
||
15 years ago
|
{
|
||
|
return processPropertyRequest( fun, data, replyType, replyData, d->m_object );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQValueList<TQCString> KDCOPPropertyProxy::functions()
|
||
15 years ago
|
{
|
||
|
return functions( d->m_object );
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPPropertyProxy::isPropertyRequest( const TQCString &fun, TQObject *object )
|
||
15 years ago
|
{
|
||
15 years ago
|
if ( fun == "property(TQCString)" ||
|
||
|
fun == "setProperty(TQCString,TQVariant)" ||
|
||
15 years ago
|
fun == "propertyNames(bool)" )
|
||
|
return true;
|
||
|
|
||
|
bool set;
|
||
15 years ago
|
TQCString propName, arg;
|
||
15 years ago
|
return decodePropertyRequestInternal( fun, object, set, propName, arg );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQValueList<TQCString> KDCOPPropertyProxy::functions( TQObject *object )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQValueList<TQCString> res;
|
||
|
res << "TQVariant property(TQCString property)";
|
||
|
res << "bool setProperty(TQCString name,TQVariant property)";
|
||
|
res << "TQValueList<TQCString> propertyNames(bool super)";
|
||
|
|
||
14 years ago
|
TQMetaObject *metaObj = object->tqmetaObject();
|
||
15 years ago
|
TQStrList properties = metaObj->propertyNames( true );
|
||
|
TQStrListIterator it( properties );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
{
|
||
14 years ago
|
const TQMetaProperty *metaProp = metaObj->property( metaObj->findProperty( it.current(), true ), true );
|
||
15 years ago
|
|
||
|
assert( metaProp );
|
||
|
|
||
15 years ago
|
TQCString name = it.current();
|
||
15 years ago
|
name.prepend( " " );
|
||
|
name.prepend( metaProp->type() );
|
||
|
name.append( "()" );
|
||
|
res << name;
|
||
|
|
||
|
if ( metaProp->writable() )
|
||
|
{
|
||
15 years ago
|
TQCString setName = it.current();
|
||
15 years ago
|
setName[ 0 ] = toupper( setName[ 0 ] );
|
||
|
setName = "void set" + setName + "(" + metaProp->type() + " " + it.current() + ")";
|
||
|
res << setName;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPPropertyProxy::processPropertyRequest( const TQCString &fun, const TQByteArray &data,
|
||
|
TQCString &replyType, TQByteArray &replyData,
|
||
|
TQObject *object )
|
||
15 years ago
|
{
|
||
15 years ago
|
if ( fun == "property(TQCString)" )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCString propName;
|
||
|
TQDataStream stream( data, IO_ReadOnly );
|
||
15 years ago
|
stream >> propName;
|
||
|
|
||
15 years ago
|
replyType = "TQVariant";
|
||
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
15 years ago
|
reply << object->property( propName );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
if ( fun == "setProperty(TQCString,TQVariant)" )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCString propName;
|
||
|
TQVariant propValue;
|
||
|
TQDataStream stream( data, IO_ReadOnly );
|
||
15 years ago
|
stream >> propName >> propValue;
|
||
|
|
||
|
replyType = "bool";
|
||
15 years ago
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
14 years ago
|
reply << (TQ_INT8)object->setProperty( propName, propValue );
|
||
15 years ago
|
return true;
|
||
|
}
|
||
|
|
||
|
if ( fun == "propertyNames(bool)" )
|
||
|
{
|
||
14 years ago
|
TQ_INT8 b;
|
||
15 years ago
|
TQDataStream stream( data, IO_ReadOnly );
|
||
15 years ago
|
stream >> b;
|
||
|
|
||
15 years ago
|
TQValueList<TQCString> res;
|
||
14 years ago
|
TQStrList props = object->tqmetaObject()->propertyNames( static_cast<bool>( b ) );
|
||
15 years ago
|
TQStrListIterator it( props );
|
||
15 years ago
|
for (; it.current(); ++it )
|
||
|
res.append( it.current() );
|
||
|
|
||
15 years ago
|
replyType = "TQValueList<TQCString>";
|
||
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
15 years ago
|
reply << res;
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
bool set;
|
||
15 years ago
|
TQCString propName, arg;
|
||
15 years ago
|
|
||
|
bool res = decodePropertyRequestInternal( fun, object, set, propName, arg );
|
||
|
if ( !res )
|
||
|
return false;
|
||
|
|
||
|
if ( set )
|
||
|
{
|
||
15 years ago
|
TQVariant prop;
|
||
|
TQDataStream stream( data, IO_ReadOnly );
|
||
15 years ago
|
|
||
15 years ago
|
TQVariant::Type type = TQVariant::nameToType( arg );
|
||
|
if ( type == TQVariant::Invalid )
|
||
15 years ago
|
return false;
|
||
|
|
||
|
#define DEMARSHAL( type, val ) \
|
||
15 years ago
|
case TQVariant::type: \
|
||
15 years ago
|
{ \
|
||
|
val v; \
|
||
|
stream >> v; \
|
||
15 years ago
|
prop = TQVariant( v ); \
|
||
15 years ago
|
} \
|
||
|
break;
|
||
|
|
||
15 years ago
|
typedef TQValueList<TQVariant> ListType;
|
||
|
typedef TQMap<TQString,TQVariant> MapType;
|
||
15 years ago
|
|
||
|
switch ( type )
|
||
|
{
|
||
15 years ago
|
DEMARSHAL( Cursor, TQCursor )
|
||
|
DEMARSHAL( Bitmap, TQBitmap )
|
||
|
DEMARSHAL( PointArray, TQPointArray )
|
||
|
DEMARSHAL( Region, TQRegion )
|
||
15 years ago
|
DEMARSHAL( List, ListType )
|
||
|
DEMARSHAL( Map, MapType )
|
||
15 years ago
|
DEMARSHAL( String, TQString )
|
||
|
DEMARSHAL( CString, TQCString )
|
||
|
DEMARSHAL( StringList, TQStringList )
|
||
|
DEMARSHAL( Font, TQFont )
|
||
|
DEMARSHAL( Pixmap, TQPixmap )
|
||
|
DEMARSHAL( Image, TQImage )
|
||
|
DEMARSHAL( Brush, TQBrush )
|
||
|
DEMARSHAL( Point, TQPoint )
|
||
|
DEMARSHAL( Rect, TQRect )
|
||
|
DEMARSHAL( Size, TQSize )
|
||
|
DEMARSHAL( Color, TQColor )
|
||
|
DEMARSHAL( Palette, TQPalette )
|
||
|
DEMARSHAL( ColorGroup, TQColorGroup )
|
||
|
case TQVariant::IconSet:
|
||
15 years ago
|
{
|
||
15 years ago
|
TQPixmap val;
|
||
15 years ago
|
stream >> val;
|
||
15 years ago
|
prop = TQVariant( TQIconSet( val ) );
|
||
15 years ago
|
}
|
||
|
break;
|
||
|
DEMARSHAL( Int, int )
|
||
|
DEMARSHAL( UInt, uint )
|
||
15 years ago
|
case TQVariant::Bool:
|
||
15 years ago
|
{
|
||
14 years ago
|
TQ_INT8 v;
|
||
15 years ago
|
stream >> v;
|
||
15 years ago
|
prop = TQVariant( static_cast<bool>( v ), 1 );
|
||
15 years ago
|
}
|
||
|
break;
|
||
|
DEMARSHAL( Double, double )
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
replyType = "void";
|
||
|
return object->setProperty( propName, prop );
|
||
|
}
|
||
|
else
|
||
|
{
|
||
15 years ago
|
TQVariant prop = object->property( propName );
|
||
15 years ago
|
|
||
15 years ago
|
if ( prop.type() == TQVariant::Invalid )
|
||
15 years ago
|
return false;
|
||
|
|
||
|
replyType = prop.typeName();
|
||
15 years ago
|
TQDataStream reply( replyData, IO_WriteOnly );
|
||
15 years ago
|
|
||
|
#define MARSHAL( type ) \
|
||
15 years ago
|
case TQVariant::type: \
|
||
15 years ago
|
reply << prop.to##type(); \
|
||
|
break;
|
||
|
|
||
|
switch ( prop.type() )
|
||
|
{
|
||
|
MARSHAL( Cursor )
|
||
|
MARSHAL( Bitmap )
|
||
|
MARSHAL( PointArray )
|
||
|
MARSHAL( Region )
|
||
|
MARSHAL( List )
|
||
|
MARSHAL( Map )
|
||
|
MARSHAL( String )
|
||
|
MARSHAL( CString )
|
||
|
MARSHAL( StringList )
|
||
|
MARSHAL( Font )
|
||
|
MARSHAL( Pixmap )
|
||
|
MARSHAL( Image )
|
||
|
MARSHAL( Brush )
|
||
|
MARSHAL( Point )
|
||
|
MARSHAL( Rect )
|
||
|
MARSHAL( Size )
|
||
|
MARSHAL( Color )
|
||
|
MARSHAL( Palette )
|
||
|
MARSHAL( ColorGroup )
|
||
15 years ago
|
case TQVariant::IconSet:
|
||
15 years ago
|
reply << prop.toIconSet().pixmap();
|
||
|
break;
|
||
|
MARSHAL( Int )
|
||
|
MARSHAL( UInt )
|
||
15 years ago
|
case TQVariant::Bool:
|
||
14 years ago
|
reply << (TQ_INT8)prop.toBool();
|
||
15 years ago
|
break;
|
||
|
MARSHAL( Double )
|
||
|
default:
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
#undef MARSHAL
|
||
|
#undef DEMARSHAL
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool KDCOPPropertyProxy::decodePropertyRequestInternal( const TQCString &fun, TQObject *object, bool &set,
|
||
|
TQCString &propName, TQCString &arg )
|
||
15 years ago
|
{
|
||
|
if ( fun.length() < 3 )
|
||
|
return false;
|
||
|
|
||
|
set = false;
|
||
|
|
||
|
propName = fun;
|
||
|
|
||
|
if ( propName.left( 3 ) == "set" )
|
||
|
{
|
||
|
propName.detach();
|
||
|
set = true;
|
||
|
propName = propName.mid( 3 );
|
||
14 years ago
|
int p1 = propName.find( '(' );
|
||
15 years ago
|
|
||
|
uint len = propName.length();
|
||
|
|
||
|
if ( propName[ len - 1 ] != ')' )
|
||
|
return false;
|
||
|
|
||
|
arg = propName.mid( p1+1, len - p1 - 2 );
|
||
|
propName.truncate( p1 );
|
||
|
propName[ 0 ] = tolower( propName[ 0 ] );
|
||
|
}
|
||
|
else
|
||
|
propName.truncate( propName.length() - 2 );
|
||
|
|
||
14 years ago
|
if ( !object->tqmetaObject()->propertyNames( true ).contains( propName ) )
|
||
15 years ago
|
return false;
|
||
|
|
||
|
return true;
|
||
|
}
|