20 #include "kdcoppropertyproxy.h"
22 #include <tqstrlist.h>
23 #include <tqmetaobject.h>
24 #include <tqvariant.h>
28 #include <tqpointarray.h>
29 #include <tqiconset.h>
33 #include <tqpalette.h>
38 class KDCOPPropertyProxyPrivate
41 KDCOPPropertyProxyPrivate()
44 ~KDCOPPropertyProxyPrivate()
53 d =
new KDCOPPropertyProxyPrivate;
68 TQCString &replyType, TQByteArray &replyData )
80 if ( fun ==
"property(TQCString)" ||
81 fun ==
"setProperty(TQCString,TQVariant)" ||
82 fun ==
"propertyNames(bool)" )
86 TQCString propName, arg;
87 return decodePropertyRequestInternal( fun,
object,
set, propName, arg );
92 TQValueList<TQCString> res;
93 res <<
"TQVariant property(TQCString property)";
94 res <<
"bool setProperty(TQCString name,TQVariant property)";
95 res <<
"TQValueList<TQCString> propertyNames(bool super)";
97 TQMetaObject *metaObj =
object->metaObject();
98 TQStrList properties = metaObj->propertyNames(
true );
99 TQStrListIterator it( properties );
100 for (; it.current(); ++it )
102 const TQMetaProperty *metaProp = metaObj->property( metaObj->findProperty( it.current(), true ),
true );
106 TQCString name = it.current();
108 name.prepend( metaProp->type() );
112 if ( metaProp->writable() )
114 TQCString setName = it.current();
115 setName[ 0 ] = toupper( setName[ 0 ] );
116 setName =
"void set" + setName +
"(" + metaProp->type() +
" " + it.current() +
")";
125 TQCString &replyType, TQByteArray &replyData,
128 if ( fun ==
"property(TQCString)" )
131 TQDataStream stream( data, IO_ReadOnly );
134 replyType =
"TQVariant";
135 TQDataStream reply( replyData, IO_WriteOnly );
136 reply <<
object->property( propName );
140 if ( fun ==
"setProperty(TQCString,TQVariant)" )
144 TQDataStream stream( data, IO_ReadOnly );
145 stream >> propName >> propValue;
148 TQDataStream reply( replyData, IO_WriteOnly );
149 reply << (TQ_INT8)object->setProperty( propName, propValue );
153 if ( fun ==
"propertyNames(bool)" )
156 TQDataStream stream( data, IO_ReadOnly );
159 TQValueList<TQCString> res;
160 TQStrList props =
object->metaObject()->propertyNames( static_cast<bool>( b ) );
161 TQStrListIterator it( props );
162 for (; it.current(); ++it )
163 res.append( it.current() );
165 replyType =
"TQValueList<TQCString>";
166 TQDataStream reply( replyData, IO_WriteOnly );
172 TQCString propName, arg;
174 bool res = decodePropertyRequestInternal( fun,
object,
set, propName, arg );
181 TQDataStream stream( data, IO_ReadOnly );
183 TQVariant::Type type = TQVariant::nameToType( arg );
184 if ( type == TQVariant::Invalid )
187 #define DEMARSHAL( type, val ) \
188 case TQVariant::type: \
192 prop = TQVariant( v ); \
196 typedef TQValueList<TQVariant> ListType;
197 typedef TQMap<TQString,TQVariant> MapType;
201 DEMARSHAL( Cursor, TQCursor )
202 DEMARSHAL( Bitmap, TQBitmap )
203 DEMARSHAL( PointArray, TQPointArray )
204 DEMARSHAL( Region, TQRegion )
205 DEMARSHAL( List, ListType )
206 DEMARSHAL( Map, MapType )
207 DEMARSHAL( String, TQString )
208 DEMARSHAL( CString, TQCString )
209 DEMARSHAL( StringList, TQStringList )
210 DEMARSHAL( Font, TQFont )
211 DEMARSHAL( Pixmap, TQPixmap )
212 DEMARSHAL( Image, TQImage )
213 DEMARSHAL( Brush, TQBrush )
214 DEMARSHAL( Point, TQPoint )
215 DEMARSHAL( Rect, TQRect )
216 DEMARSHAL( Size, TQSize )
217 DEMARSHAL( Color, TQColor )
218 DEMARSHAL( Palette, TQPalette )
219 DEMARSHAL( ColorGroup, TQColorGroup )
220 case TQVariant::IconSet:
224 prop = TQVariant( TQIconSet( val ) );
227 DEMARSHAL( Int,
int )
228 DEMARSHAL( UInt, uint )
229 case TQVariant::Bool:
233 prop = TQVariant( static_cast<bool>( v ), 1 );
236 DEMARSHAL( Double,
double )
242 return object->setProperty( propName, prop );
246 TQVariant prop =
object->property( propName );
248 if ( prop.type() == TQVariant::Invalid )
251 replyType = prop.typeName();
252 TQDataStream reply( replyData, IO_WriteOnly );
254 #define MARSHAL( type ) \
255 case TQVariant::type: \
256 reply << prop.to##type(); \
259 switch ( prop.type() )
263 MARSHAL( PointArray )
269 MARSHAL( StringList )
279 MARSHAL( ColorGroup )
280 case TQVariant::IconSet:
281 reply << prop.toIconSet().pixmap();
285 case TQVariant::Bool:
286 reply << (TQ_INT8)prop.toBool();
302 bool KDCOPPropertyProxy::decodePropertyRequestInternal(
const TQCString &fun, TQObject *
object,
bool &
set,
303 TQCString &propName, TQCString &arg )
305 if ( fun.length() < 3 )
312 if ( propName.left( 3 ) ==
"set" )
316 propName = propName.mid( 3 );
317 int p1 = propName.find(
'(' );
319 uint len = propName.length();
321 if ( propName[ len - 1 ] !=
')' )
324 arg = propName.mid( p1+1, len - p1 - 2 );
325 propName.truncate( p1 );
326 propName[ 0 ] = tolower( propName[ 0 ] );
329 propName.truncate( propName.length() - 2 );
331 if ( !object->metaObject()->propertyNames(
true ).contains( propName ) )