1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
/* 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"
#include <qstrlist.h>
#include <qmetaobject.h>
#include <qvariant.h>
#include <qcursor.h>
#include <qbitmap.h>
#include <qregion.h>
#include <qpointarray.h>
#include <qiconset.h>
#include <qfont.h>
#include <qimage.h>
#include <qbrush.h>
#include <qpalette.h>
#include <ctype.h>
#include <assert.h>
class KDCOPPropertyProxyPrivate
{
public:
KDCOPPropertyProxyPrivate()
{
}
~KDCOPPropertyProxyPrivate()
{
}
QObject *m_object;
};
KDCOPPropertyProxy::KDCOPPropertyProxy( QObject *object )
{
d = new KDCOPPropertyProxyPrivate;
d->m_object = object;
}
KDCOPPropertyProxy::~KDCOPPropertyProxy()
{
delete d;
}
bool KDCOPPropertyProxy::isPropertyRequest( const QCString &fun )
{
return isPropertyRequest( fun, d->m_object );
}
bool KDCOPPropertyProxy::processPropertyRequest( const QCString &fun, const QByteArray &data,
QCString &replyType, QByteArray &replyData )
{
return processPropertyRequest( fun, data, replyType, replyData, d->m_object );
}
QValueList<QCString> KDCOPPropertyProxy::functions()
{
return functions( d->m_object );
}
bool KDCOPPropertyProxy::isPropertyRequest( const QCString &fun, QObject *object )
{
if ( fun == "property(QCString)" ||
fun == "setProperty(QCString,QVariant)" ||
fun == "propertyNames(bool)" )
return true;
bool set;
QCString propName, arg;
return decodePropertyRequestInternal( fun, object, set, propName, arg );
}
QValueList<QCString> KDCOPPropertyProxy::functions( QObject *object )
{
QValueList<QCString> res;
res << "QVariant property(QCString property)";
res << "bool setProperty(QCString name,QVariant property)";
res << "QValueList<QCString> propertyNames(bool super)";
QMetaObject *metaObj = object->metaObject();
QStrList properties = metaObj->propertyNames( true );
QStrListIterator it( properties );
for (; it.current(); ++it )
{
const QMetaProperty *metaProp = metaObj->property( metaObj->findProperty( it.current(), true ), true );
assert( metaProp );
QCString name = it.current();
name.prepend( " " );
name.prepend( metaProp->type() );
name.append( "()" );
res << name;
if ( metaProp->writable() )
{
QCString setName = it.current();
setName[ 0 ] = toupper( setName[ 0 ] );
setName = "void set" + setName + "(" + metaProp->type() + " " + it.current() + ")";
res << setName;
}
}
return res;
}
bool KDCOPPropertyProxy::processPropertyRequest( const QCString &fun, const QByteArray &data,
QCString &replyType, QByteArray &replyData,
QObject *object )
{
if ( fun == "property(QCString)" )
{
QCString propName;
QDataStream stream( data, IO_ReadOnly );
stream >> propName;
replyType = "QVariant";
QDataStream reply( replyData, IO_WriteOnly );
reply << object->property( propName );
return true;
}
if ( fun == "setProperty(QCString,QVariant)" )
{
QCString propName;
QVariant propValue;
QDataStream stream( data, IO_ReadOnly );
stream >> propName >> propValue;
replyType = "bool";
QDataStream reply( replyData, IO_WriteOnly );
reply << (Q_INT8)object->setProperty( propName, propValue );
return true;
}
if ( fun == "propertyNames(bool)" )
{
Q_INT8 b;
QDataStream stream( data, IO_ReadOnly );
stream >> b;
QValueList<QCString> res;
QStrList props = object->metaObject()->propertyNames( static_cast<bool>( b ) );
QStrListIterator it( props );
for (; it.current(); ++it )
res.append( it.current() );
replyType = "QValueList<QCString>";
QDataStream reply( replyData, IO_WriteOnly );
reply << res;
return true;
}
bool set;
QCString propName, arg;
bool res = decodePropertyRequestInternal( fun, object, set, propName, arg );
if ( !res )
return false;
if ( set )
{
QVariant prop;
QDataStream stream( data, IO_ReadOnly );
QVariant::Type type = QVariant::nameToType( arg );
if ( type == QVariant::Invalid )
return false;
#define DEMARSHAL( type, val ) \
case QVariant::type: \
{ \
val v; \
stream >> v; \
prop = QVariant( v ); \
} \
break;
typedef QValueList<QVariant> ListType;
typedef QMap<QString,QVariant> MapType;
switch ( type )
{
DEMARSHAL( Cursor, QCursor )
DEMARSHAL( Bitmap, QBitmap )
DEMARSHAL( PointArray, QPointArray )
DEMARSHAL( Region, QRegion )
DEMARSHAL( List, ListType )
DEMARSHAL( Map, MapType )
DEMARSHAL( String, QString )
DEMARSHAL( CString, QCString )
DEMARSHAL( StringList, QStringList )
DEMARSHAL( Font, QFont )
DEMARSHAL( Pixmap, QPixmap )
DEMARSHAL( Image, QImage )
DEMARSHAL( Brush, QBrush )
DEMARSHAL( Point, QPoint )
DEMARSHAL( Rect, QRect )
DEMARSHAL( Size, QSize )
DEMARSHAL( Color, QColor )
DEMARSHAL( Palette, QPalette )
DEMARSHAL( ColorGroup, QColorGroup )
case QVariant::IconSet:
{
QPixmap val;
stream >> val;
prop = QVariant( QIconSet( val ) );
}
break;
DEMARSHAL( Int, int )
DEMARSHAL( UInt, uint )
case QVariant::Bool:
{
Q_INT8 v;
stream >> v;
prop = QVariant( static_cast<bool>( v ), 1 );
}
break;
DEMARSHAL( Double, double )
default:
return false;
}
replyType = "void";
return object->setProperty( propName, prop );
}
else
{
QVariant prop = object->property( propName );
if ( prop.type() == QVariant::Invalid )
return false;
replyType = prop.typeName();
QDataStream reply( replyData, IO_WriteOnly );
#define MARSHAL( type ) \
case QVariant::type: \
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 )
case QVariant::IconSet:
reply << prop.toIconSet().pixmap();
break;
MARSHAL( Int )
MARSHAL( UInt )
case QVariant::Bool:
reply << (Q_INT8)prop.toBool();
break;
MARSHAL( Double )
default:
return false;
}
#undef MARSHAL
#undef DEMARSHAL
return true;
}
return false;
}
bool KDCOPPropertyProxy::decodePropertyRequestInternal( const QCString &fun, QObject *object, bool &set,
QCString &propName, QCString &arg )
{
if ( fun.length() < 3 )
return false;
set = false;
propName = fun;
if ( propName.left( 3 ) == "set" )
{
propName.detach();
set = true;
propName = propName.mid( 3 );
int p1 = propName.find( '(' );
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 );
if ( !object->metaObject()->propertyNames( true ).contains( propName ) )
return false;
return true;
}
|