• 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 #define MARSHAL( type ) \
125  case TQVariant::type: \
126  { \
127  reply << prop.to##type(); \
128  break; \
129  }
130 
131 #define DEMARSHAL( type, val ) \
132  case TQVariant::type: \
133  { \
134  val v; \
135  stream >> v; \
136  prop = TQVariant( v ); \
137  break; \
138  }
139 
140 bool KDCOPPropertyProxy::processPropertyRequest( const TQCString &fun, const TQByteArray &data,
141  TQCString &replyType, TQByteArray &replyData,
142  TQObject *object )
143 {
144  if ( fun == "property(TQCString)" )
145  {
146  TQCString propName;
147  TQDataStream stream( data, IO_ReadOnly );
148  stream >> propName;
149 
150  replyType = "TQVariant";
151  TQDataStream reply( replyData, IO_WriteOnly );
152  reply << object->property( propName );
153  return true;
154  }
155 
156  if ( fun == "setProperty(TQCString,TQVariant)" )
157  {
158  TQCString propName;
159  TQVariant propValue;
160  TQDataStream stream( data, IO_ReadOnly );
161  stream >> propName >> propValue;
162 
163  replyType = "bool";
164  TQDataStream reply( replyData, IO_WriteOnly );
165  reply << (TQ_INT8)object->setProperty( propName, propValue );
166  return true;
167  }
168 
169  if ( fun == "propertyNames(bool)" )
170  {
171  TQ_INT8 b;
172  TQDataStream stream( data, IO_ReadOnly );
173  stream >> b;
174 
175  TQValueList<TQCString> res;
176  TQStrList props = object->metaObject()->propertyNames( static_cast<bool>( b ) );
177  TQStrListIterator it( props );
178  for (; it.current(); ++it )
179  res.append( it.current() );
180 
181  replyType = "TQValueList<TQCString>";
182  TQDataStream reply( replyData, IO_WriteOnly );
183  reply << res;
184  return true;
185  }
186 
187  bool set;
188  TQCString propName, arg;
189 
190  bool res = decodePropertyRequestInternal( fun, object, set, propName, arg );
191  if ( !res )
192  return false;
193 
194  if ( set )
195  {
196  TQVariant prop;
197  TQDataStream stream( data, IO_ReadOnly );
198 
199  TQVariant::Type type = TQVariant::nameToType( arg );
200  if ( type == TQVariant::Invalid )
201  return false;
202 
203  typedef TQValueList<TQVariant> ListType;
204  typedef TQStringVariantMap MapType;
205 
206  switch ( type )
207  {
208  DEMARSHAL( Cursor, TQCursor )
209  DEMARSHAL( Bitmap, TQBitmap )
210  DEMARSHAL( PointArray, TQPointArray )
211  DEMARSHAL( Region, TQRegion )
212  DEMARSHAL( List, ListType )
213  DEMARSHAL( Map, MapType )
214  DEMARSHAL( String, TQString )
215  DEMARSHAL( CString, TQCString )
216  DEMARSHAL( StringList, TQStringList )
217  DEMARSHAL( Font, TQFont )
218  DEMARSHAL( Pixmap, TQPixmap )
219  DEMARSHAL( Image, TQImage )
220  DEMARSHAL( Brush, TQBrush )
221  DEMARSHAL( Point, TQPoint )
222  DEMARSHAL( Rect, TQRect )
223  DEMARSHAL( Size, TQSize )
224  DEMARSHAL( Color, TQColor )
225  DEMARSHAL( Palette, TQPalette )
226  DEMARSHAL( ColorGroup, TQColorGroup )
227  case TQVariant::IconSet:
228  {
229  TQPixmap val;
230  stream >> val;
231  prop = TQVariant( TQIconSet( val ) );
232  }
233  break;
234  DEMARSHAL( Int, int )
235  DEMARSHAL( UInt, uint )
236  case TQVariant::Bool:
237  {
238  TQ_INT8 v;
239  stream >> v;
240  prop = TQVariant( static_cast<bool>( v ) );
241  }
242  break;
243  DEMARSHAL( Double, double )
244  default:
245  return false;
246  }
247 
248  replyType = "void";
249  return object->setProperty( propName, prop );
250  }
251  else
252  {
253  TQVariant prop = object->property( propName );
254 
255  if ( prop.type() == TQVariant::Invalid )
256  return false;
257 
258  replyType = prop.typeName();
259  TQDataStream reply( replyData, IO_WriteOnly );
260 
261  switch ( prop.type() )
262  {
263  MARSHAL( Cursor )
264  MARSHAL( Bitmap )
265  MARSHAL( PointArray )
266  MARSHAL( Region )
267  MARSHAL( List )
268  MARSHAL( Map )
269  MARSHAL( String )
270  MARSHAL( CString )
271  MARSHAL( StringList )
272  MARSHAL( Font )
273  MARSHAL( Pixmap )
274  MARSHAL( Image )
275  MARSHAL( Brush )
276  MARSHAL( Point )
277  MARSHAL( Rect )
278  MARSHAL( Size )
279  MARSHAL( Color )
280  MARSHAL( Palette )
281  MARSHAL( ColorGroup )
282  case TQVariant::IconSet:
283  reply << prop.toIconSet().pixmap();
284  break;
285  MARSHAL( Int )
286  MARSHAL( UInt )
287  case TQVariant::Bool:
288  reply << (TQ_INT8)prop.toBool();
289  break;
290  MARSHAL( Double )
291  default:
292  return false;
293  }
294 
295 #undef MARSHAL
296 #undef DEMARSHAL
297 
298  return true;
299  }
300 
301  return false;
302 }
303 
304 bool KDCOPPropertyProxy::decodePropertyRequestInternal( const TQCString &fun, TQObject *object, bool &set,
305  TQCString &propName, TQCString &arg )
306 {
307  if ( fun.length() < 3 )
308  return false;
309 
310  set = false;
311 
312  propName = fun;
313 
314  if ( propName.left( 3 ) == "set" )
315  {
316  propName.detach();
317  set = true;
318  propName = propName.mid( 3 );
319  int p1 = propName.find( '(' );
320 
321  uint len = propName.length();
322 
323  if ( propName[ len - 1 ] != ')' )
324  return false;
325 
326  arg = propName.mid( p1+1, len - p1 - 2 );
327  propName.truncate( p1 );
328  propName[ 0 ] = tolower( propName[ 0 ] );
329  }
330  else
331  propName.truncate( propName.length() - 2 );
332 
333  if ( !object->metaObject()->propertyNames( true ).contains( propName ) )
334  return false;
335 
336  return true;
337 }
KDCOPPropertyProxy::~KDCOPPropertyProxy
~KDCOPPropertyProxy()
Destructor.
Definition: kdcoppropertyproxy.cpp:57
KDCOPPropertyProxy::KDCOPPropertyProxy
KDCOPPropertyProxy(TQObject *object)
Convenience constructor.
Definition: kdcoppropertyproxy.cpp:51
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.9.1
This website is maintained by Timothy Pearson.