• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kdcoppropertyproxy.cpp
1 /* This file is part of the KDE project
2  Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "kdcoppropertyproxy.h"
21 
22 #include <tqstrlist.h>
23 #include <tqmetaobject.h>
24 #include <tqvariant.h>
25 #include <tqcursor.h>
26 #include <tqbitmap.h>
27 #include <tqregion.h>
28 #include <tqpointarray.h>
29 #include <tqiconset.h>
30 #include <tqfont.h>
31 #include <tqimage.h>
32 #include <tqbrush.h>
33 #include <tqpalette.h>
34 
35 #include <ctype.h>
36 #include <assert.h>
37 
38 class KDCOPPropertyProxyPrivate
39 {
40 public:
41  KDCOPPropertyProxyPrivate()
42  {
43  }
44  ~KDCOPPropertyProxyPrivate()
45  {
46  }
47 
48  TQObject *m_object;
49 };
50 
51 KDCOPPropertyProxy::KDCOPPropertyProxy( TQObject *object )
52 {
53  d = new KDCOPPropertyProxyPrivate;
54  d->m_object = object;
55 }
56 
57 KDCOPPropertyProxy::~KDCOPPropertyProxy()
58 {
59  delete d;
60 }
61 
62 bool KDCOPPropertyProxy::isPropertyRequest( const TQCString &fun )
63 {
64  return isPropertyRequest( fun, d->m_object );
65 }
66 
67 bool KDCOPPropertyProxy::processPropertyRequest( const TQCString &fun, const TQByteArray &data,
68  TQCString &replyType, TQByteArray &replyData )
69 {
70  return processPropertyRequest( fun, data, replyType, replyData, d->m_object );
71 }
72 
73 TQValueList<TQCString> KDCOPPropertyProxy::functions()
74 {
75  return functions( d->m_object );
76 }
77 
78 bool KDCOPPropertyProxy::isPropertyRequest( const TQCString &fun, TQObject *object )
79 {
80  if ( fun == "property(TQCString)" ||
81  fun == "setProperty(TQCString,TQVariant)" ||
82  fun == "propertyNames(bool)" )
83  return true;
84 
85  bool set;
86  TQCString propName, arg;
87  return decodePropertyRequestInternal( fun, object, set, propName, arg );
88 }
89 
90 TQValueList<TQCString> KDCOPPropertyProxy::functions( TQObject *object )
91 {
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)";
96 
97  TQMetaObject *metaObj = object->metaObject();
98  TQStrList properties = metaObj->propertyNames( true );
99  TQStrListIterator it( properties );
100  for (; it.current(); ++it )
101  {
102  const TQMetaProperty *metaProp = metaObj->property( metaObj->findProperty( it.current(), true ), true );
103 
104  assert( metaProp );
105 
106  TQCString name = it.current();
107  name.prepend( " " );
108  name.prepend( metaProp->type() );
109  name.append( "()" );
110  res << name;
111 
112  if ( metaProp->writable() )
113  {
114  TQCString setName = it.current();
115  setName[ 0 ] = toupper( setName[ 0 ] );
116  setName = "void set" + setName + "(" + metaProp->type() + " " + it.current() + ")";
117  res << setName;
118  }
119  }
120 
121  return res;
122 }
123 
124 bool KDCOPPropertyProxy::processPropertyRequest( const TQCString &fun, const TQByteArray &data,
125  TQCString &replyType, TQByteArray &replyData,
126  TQObject *object )
127 {
128  if ( fun == "property(TQCString)" )
129  {
130  TQCString propName;
131  TQDataStream stream( data, IO_ReadOnly );
132  stream >> propName;
133 
134  replyType = "TQVariant";
135  TQDataStream reply( replyData, IO_WriteOnly );
136  reply << object->property( propName );
137  return true;
138  }
139 
140  if ( fun == "setProperty(TQCString,TQVariant)" )
141  {
142  TQCString propName;
143  TQVariant propValue;
144  TQDataStream stream( data, IO_ReadOnly );
145  stream >> propName >> propValue;
146 
147  replyType = "bool";
148  TQDataStream reply( replyData, IO_WriteOnly );
149  reply << (TQ_INT8)object->setProperty( propName, propValue );
150  return true;
151  }
152 
153  if ( fun == "propertyNames(bool)" )
154  {
155  TQ_INT8 b;
156  TQDataStream stream( data, IO_ReadOnly );
157  stream >> b;
158 
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() );
164 
165  replyType = "TQValueList<TQCString>";
166  TQDataStream reply( replyData, IO_WriteOnly );
167  reply << res;
168  return true;
169  }
170 
171  bool set;
172  TQCString propName, arg;
173 
174  bool res = decodePropertyRequestInternal( fun, object, set, propName, arg );
175  if ( !res )
176  return false;
177 
178  if ( set )
179  {
180  TQVariant prop;
181  TQDataStream stream( data, IO_ReadOnly );
182 
183  TQVariant::Type type = TQVariant::nameToType( arg );
184  if ( type == TQVariant::Invalid )
185  return false;
186 
187 #define DEMARSHAL( type, val ) \
188  case TQVariant::type: \
189  { \
190  val v; \
191  stream >> v; \
192  prop = TQVariant( v ); \
193  } \
194  break;
195 
196  typedef TQValueList<TQVariant> ListType;
197  typedef TQMap<TQString,TQVariant> MapType;
198 
199  switch ( type )
200  {
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:
221  {
222  TQPixmap val;
223  stream >> val;
224  prop = TQVariant( TQIconSet( val ) );
225  }
226  break;
227  DEMARSHAL( Int, int )
228  DEMARSHAL( UInt, uint )
229  case TQVariant::Bool:
230  {
231  TQ_INT8 v;
232  stream >> v;
233  prop = TQVariant( static_cast<bool>( v ), 1 );
234  }
235  break;
236  DEMARSHAL( Double, double )
237  default:
238  return false;
239  }
240 
241  replyType = "void";
242  return object->setProperty( propName, prop );
243  }
244  else
245  {
246  TQVariant prop = object->property( propName );
247 
248  if ( prop.type() == TQVariant::Invalid )
249  return false;
250 
251  replyType = prop.typeName();
252  TQDataStream reply( replyData, IO_WriteOnly );
253 
254 #define MARSHAL( type ) \
255  case TQVariant::type: \
256  reply << prop.to##type(); \
257  break;
258 
259  switch ( prop.type() )
260  {
261  MARSHAL( Cursor )
262  MARSHAL( Bitmap )
263  MARSHAL( PointArray )
264  MARSHAL( Region )
265  MARSHAL( List )
266  MARSHAL( Map )
267  MARSHAL( String )
268  MARSHAL( CString )
269  MARSHAL( StringList )
270  MARSHAL( Font )
271  MARSHAL( Pixmap )
272  MARSHAL( Image )
273  MARSHAL( Brush )
274  MARSHAL( Point )
275  MARSHAL( Rect )
276  MARSHAL( Size )
277  MARSHAL( Color )
278  MARSHAL( Palette )
279  MARSHAL( ColorGroup )
280  case TQVariant::IconSet:
281  reply << prop.toIconSet().pixmap();
282  break;
283  MARSHAL( Int )
284  MARSHAL( UInt )
285  case TQVariant::Bool:
286  reply << (TQ_INT8)prop.toBool();
287  break;
288  MARSHAL( Double )
289  default:
290  return false;
291  }
292 
293 #undef MARSHAL
294 #undef DEMARSHAL
295 
296  return true;
297  }
298 
299  return false;
300 }
301 
302 bool KDCOPPropertyProxy::decodePropertyRequestInternal( const TQCString &fun, TQObject *object, bool &set,
303  TQCString &propName, TQCString &arg )
304 {
305  if ( fun.length() < 3 )
306  return false;
307 
308  set = false;
309 
310  propName = fun;
311 
312  if ( propName.left( 3 ) == "set" )
313  {
314  propName.detach();
315  set = true;
316  propName = propName.mid( 3 );
317  int p1 = propName.find( '(' );
318 
319  uint len = propName.length();
320 
321  if ( propName[ len - 1 ] != ')' )
322  return false;
323 
324  arg = propName.mid( p1+1, len - p1 - 2 );
325  propName.truncate( p1 );
326  propName[ 0 ] = tolower( propName[ 0 ] );
327  }
328  else
329  propName.truncate( propName.length() - 2 );
330 
331  if ( !object->metaObject()->propertyNames( true ).contains( propName ) )
332  return false;
333 
334  return true;
335 }
KDCOPPropertyProxy::KDCOPPropertyProxy
KDCOPPropertyProxy(TQObject *object)
Convenience constructor.
Definition: kdcoppropertyproxy.cpp:51
KDCOPPropertyProxy::~KDCOPPropertyProxy
~KDCOPPropertyProxy()
Destructor.
Definition: kdcoppropertyproxy.cpp:57
KDCOPPropertyProxy::functions
TQValueList< TQCString > functions()
Convenience method, when using this class as object.
Definition: kdcoppropertyproxy.cpp:73
KDCOPPropertyProxy::processPropertyRequest
bool processPropertyRequest(const TQCString &fun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData)
Convenience method, when using this class as object.
Definition: kdcoppropertyproxy.cpp:67
KDCOPPropertyProxy::isPropertyRequest
bool isPropertyRequest(const TQCString &fun)
Convenience method, when using this class as object.
Definition: kdcoppropertyproxy.cpp:62

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.13
This website is maintained by Timothy Pearson.