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

dcop

  • dcop
  • client
marshall.cpp
1 /*****************************************************************
2 Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 
21 ******************************************************************/
22 
23 #define KDE_QT_ONLY
24 #include "../../tdecore/kurl.cpp"
25 
26 bool mkBool( const TQString& s )
27 {
28  if ( s.lower() == "true" )
29  return true;
30  if ( s.lower() == "yes" )
31  return true;
32  if ( s.lower() == "on" )
33  return true;
34  if ( s.toInt() != 0 )
35  return true;
36 
37  return false;
38 }
39 
40 TQPoint mkPoint( const TQString &str )
41 {
42  const char *s = str.latin1();
43  char *end;
44  while(*s && !isdigit(*s) && *s != '-') s++;
45  int x = strtol(s, &end, 10);
46  s = (const char *)end;
47  while(*s && !isdigit(*s) && *s != '-') s++;
48  int y = strtol(s, &end, 10);
49  return TQPoint( x, y );
50 }
51 
52 TQSize mkSize( const TQString &str )
53 {
54  const char *s = str.latin1();
55  char *end;
56  while(*s && !isdigit(*s) && *s != '-') s++;
57  int w = strtol(s, &end, 10);
58  s = (const char *)end;
59  while(*s && !isdigit(*s) && *s != '-') s++;
60  int h = strtol(s, &end, 10);
61  return TQSize( w, h );
62 }
63 
64 TQRect mkRect( const TQString &str )
65 {
66  const char *s = str.latin1();
67  char *end;
68  while(*s && !isdigit(*s) && *s != '-') s++;
69  int p1 = strtol(s, &end, 10);
70  s = (const char *)end;
71  bool legacy = (*s == 'x');
72  while(*s && !isdigit(*s) && *s != '-') s++;
73  int p2 = strtol(s, &end, 10);
74  s = (const char *)end;
75  while(*s && !isdigit(*s) && *s != '-') s++;
76  int p3 = strtol(s, &end, 10);
77  s = (const char *)end;
78  while(*s && !isdigit(*s) && *s != '-') s++;
79  int p4 = strtol(s, &end, 10);
80  if (legacy)
81  {
82  return TQRect( p3, p4, p1, p2 );
83  }
84  return TQRect( p1, p2, p3, p4 );
85 }
86 
87 TQColor mkColor( const TQString& s )
88 {
89  TQColor c;
90  c.setNamedColor(s);
91  return c;
92 }
93 
94 const char *qStringToC(const TQCString &s)
95 {
96  if (s.isEmpty())
97  return "";
98  return s.data();
99 }
100 
101 TQCString demarshal( TQDataStream &stream, const TQString &type )
102 {
103  TQCString result;
104 
105  if ( type == "int" || type == "TQ_INT32" )
106  {
107  int i;
108  stream >> i;
109  result.setNum( i );
110  } else if ( type == "uint" || type == "TQ_UINT32" || type == "unsigned int" )
111  {
112  uint i;
113  stream >> i;
114  result.setNum( i );
115  } else if ( type == "long" || type == "long int" )
116  {
117  long l;
118  stream >> l;
119  result.setNum( l );
120  } else if ( type == "unsigned long" || type == "unsigned long int" )
121  {
122  unsigned long l;
123  stream >> l;
124  result.setNum( l );
125  } else if ( type == "float" )
126  {
127  float f;
128  stream >> f;
129  result.setNum( f, 'f' );
130  } else if ( type == "double" )
131  {
132  double d;
133  stream >> d;
134  result.setNum( d, 'f' );
135  } else if ( type == "TQ_INT64" ) {
136  TQ_INT64 i;
137  stream >> i;
138  result.sprintf( "%lld", i );
139  } else if ( type == "TQ_UINT64" ) {
140  TQ_UINT64 i;
141  stream >> i;
142  result.sprintf( "%llu", i );
143  } else if ( type == "bool" )
144  {
145  bool b;
146  stream >> b;
147  result = b ? "true" : "false";
148  } else if ( type == TQSTRING_OBJECT_NAME_STRING )
149  {
150  TQString s;
151  stream >> s;
152  result = s.local8Bit();
153  } else if ( type == TQCSTRING_OBJECT_NAME_STRING )
154  {
155  stream >> result;
156  } else if ( type == "QCStringList" )
157  {
158  return demarshal( stream, TQVALUELIST_OBJECT_NAME_STRING "<" TQCSTRING_OBJECT_NAME_STRING ">" );
159  } else if ( type == TQSTRINGLIST_OBJECT_NAME_STRING )
160  {
161  return demarshal( stream, TQVALUELIST_OBJECT_NAME_STRING "<" TQCSTRING_OBJECT_NAME_STRING ">" );
162  } else if ( type == TQCOLOR_OBJECT_NAME_STRING )
163  {
164  TQColor c;
165  stream >> c;
166  result = TQString(c.name()).local8Bit();
167  } else if ( type == TQSIZE_OBJECT_NAME_STRING )
168  {
169  TQSize s;
170  stream >> s;
171  result.sprintf( "%dx%d", s.width(), s.height() );
172  } else if ( type == TQPIXMAP_OBJECT_NAME_STRING || type == TQIMAGE_OBJECT_NAME_STRING )
173  {
174  TQImage i;
175  stream >> i;
176  TQByteArray ba;
177  TQBuffer buf( ba );
178  buf.open( IO_WriteOnly );
179  i.save( &buf, "XPM" );
180  result = buf.buffer();
181  } else if ( type == TQPOINT_OBJECT_NAME_STRING )
182  {
183  TQPoint p;
184  stream >> p;
185  result.sprintf( "+%d+%d", p.x(), p.y() );
186  } else if ( type == TQRECT_OBJECT_NAME_STRING )
187  {
188  TQRect r;
189  stream >> r;
190  result.sprintf( "%dx%d+%d+%d", r.width(), r.height(), r.x(), r.y() );
191  } else if ( type == TQVARIANT_OBJECT_NAME_STRING )
192  {
193  TQ_INT32 type;
194  stream >> type;
195  return demarshal( stream, TQVariant::typeToName( (TQVariant::Type)type ) );
196  } else if ( type == "DCOPRef" )
197  {
198  DCOPRef r;
199  stream >> r;
200  result.sprintf( "DCOPRef(%s,%s)", qStringToC(r.app()), qStringToC(r.object()) );
201  } else if ( type == "KURL" )
202  {
203  KURL r;
204  stream >> r;
205  result = r.url().local8Bit();
206  } else if ( type.left( 11 ) == TQVALUELIST_OBJECT_NAME_STRING "<" )
207  {
208  if ( (uint)type.find( '>', 11 ) != type.length() - 1 )
209  return result;
210 
211  TQString nestedType = type.mid( 11, type.length() - 12 );
212 
213  if ( nestedType.isEmpty() )
214  return result;
215 
216  TQ_UINT32 count;
217  stream >> count;
218 
219  TQ_UINT32 i = 0;
220  for (; i < count; ++i )
221  {
222  TQCString arg = demarshal( stream, nestedType );
223  result += arg;
224 
225  if ( i < count - 1 )
226  result += '\n';
227  }
228  } else if ( type.left( 5 ) == TQMAP_OBJECT_NAME_STRING "<" )
229  {
230  int commaPos = type.find( ',', 5 );
231 
232  if ( commaPos == -1 )
233  return result;
234 
235  if ( (uint)type.find( '>', commaPos ) != type.length() - 1 )
236  return result;
237 
238  TQString keyType = type.mid( 5, commaPos - 5 );
239  TQString valueType = type.mid( commaPos + 1, type.length() - commaPos - 2 );
240 
241  TQ_UINT32 count;
242  stream >> count;
243 
244  TQ_UINT32 i = 0;
245  for (; i < count; ++i )
246  {
247  TQCString key = demarshal( stream, keyType );
248 
249  if ( key.isEmpty() )
250  continue;
251 
252  TQCString value = demarshal( stream, valueType );
253 
254  if ( value.isEmpty() )
255  continue;
256 
257  result += key + "->" + value;
258 
259  if ( i < count - 1 )
260  result += '\n';
261  }
262  }
263  else
264  {
265  result.sprintf( "<%s>", type.latin1());
266  }
267 
268  return result;
269 
270 }
271 
272 void marshall( TQDataStream &arg, QCStringList args, uint &i, TQString type )
273 {
274  if( i >= args.count() )
275  {
276  tqWarning("Not enough arguments (expected %u, got %lu).", i, args.count());
277  exit(1);
278  }
279  TQString s = TQString::fromLocal8Bit( args[ i ] );
280 
281  if (type == TQSTRINGLIST_OBJECT_NAME_STRING) {
282  type = TQVALUELIST_OBJECT_NAME_STRING "<" TQSTRING_OBJECT_NAME_STRING ">";
283  }
284  if (type == "QCStringList") {
285  type = TQVALUELIST_OBJECT_NAME_STRING "<" TQSTRING_OBJECT_NAME_STRING ">";
286  }
287 
288  if ( type == "int" )
289  arg << s.toInt();
290  else if ( type == "uint" )
291  arg << s.toUInt();
292  else if ( type == "unsigned" )
293  arg << s.toUInt();
294  else if ( type == "unsigned int" )
295  arg << s.toUInt();
296  else if ( type == "TQ_INT32" )
297  arg << s.toInt();
298  else if ( type == "TQ_INT64" ) {
299  TQVariant qv = TQVariant( s );
300  arg << qv.toLongLong();
301  }
302  else if ( type == "TQ_UINT32" )
303  arg << s.toUInt();
304  else if ( type == "TQ_UINT64" ) {
305  TQVariant qv = TQVariant( s );
306  arg << qv.toULongLong();
307  }
308  else if ( type == "long" )
309  arg << s.toLong();
310  else if ( type == "long int" )
311  arg << s.toLong();
312  else if ( type == "unsigned long" )
313  arg << s.toULong();
314  else if ( type == "unsigned long int" )
315  arg << s.toULong();
316  else if ( type == "float" )
317  arg << s.toFloat();
318  else if ( type == "double" )
319  arg << s.toDouble();
320  else if ( type == "bool" )
321  arg << mkBool( s );
322  else if ( type == TQSTRING_OBJECT_NAME_STRING )
323  arg << s;
324  else if ( type == TQCSTRING_OBJECT_NAME_STRING )
325  arg << TQCString( args[ i ] );
326  else if ( type == TQCOLOR_OBJECT_NAME_STRING )
327  arg << mkColor( s );
328  else if ( type == TQPOINT_OBJECT_NAME_STRING )
329  arg << mkPoint( s );
330  else if ( type == TQSIZE_OBJECT_NAME_STRING )
331  arg << mkSize( s );
332  else if ( type == TQRECT_OBJECT_NAME_STRING )
333  arg << mkRect( s );
334  else if ( type == "KURL" )
335  arg << KURL( s );
336  else if ( type == TQVARIANT_OBJECT_NAME_STRING ) {
337  int tqPointKeywordLength = strlen(TQPOINT_OBJECT_NAME_STRING);
338  int tqSizeKeywordLength = strlen(TQSIZE_OBJECT_NAME_STRING);
339  int tqRectKeywordLength = strlen(TQRECT_OBJECT_NAME_STRING);
340  int tqColorKeywordLength = strlen(TQCOLOR_OBJECT_NAME_STRING);
341  if ( s == "true" || s == "false" ) {
342  arg << TQVariant( mkBool( s ), 42 );
343  }
344  else if ( s.left( 4 ) == "int(" ) {
345  arg << TQVariant( s.mid(4, s.length()-5).toInt() );
346  }
347  else if ( s.left( (tqPointKeywordLength+1) ) == TQPOINT_OBJECT_NAME_STRING "(" ) {
348  arg << TQVariant( mkPoint( s.mid((tqPointKeywordLength+1), s.length()-(tqPointKeywordLength+2)) ) );
349  }
350  else if ( s.left( (tqSizeKeywordLength+1) ) == TQSIZE_OBJECT_NAME_STRING "(" ) {
351  arg << TQVariant( mkSize( s.mid((tqSizeKeywordLength+1), s.length()-(tqSizeKeywordLength+2)) ) );
352  }
353  else if ( s.left( (tqRectKeywordLength+1) ) == TQRECT_OBJECT_NAME_STRING "(" ) {
354  arg << TQVariant( mkRect( s.mid((tqRectKeywordLength+1), s.length()-(tqRectKeywordLength+2)) ) );
355  }
356  else if ( s.left( (tqColorKeywordLength+1) ) == TQCOLOR_OBJECT_NAME_STRING "(" ) {
357  arg << TQVariant( mkColor( s.mid((tqColorKeywordLength+1), s.length()-(tqColorKeywordLength+2)) ) );
358  }
359  else {
360  arg << TQVariant( s );
361  }
362  } else if ( type.startsWith(TQVALUELIST_OBJECT_NAME_STRING "<") || type == "KURL::List" ) {
363  if ( type == "KURL::List" ) {
364  type = "KURL";
365  }
366  else {
367  int tqValueListKeywordLength = strlen(TQVALUELIST_OBJECT_NAME_STRING);
368  type = type.mid((tqValueListKeywordLength+1), type.length() - (tqValueListKeywordLength+2));
369  }
370  TQStringList list;
371  TQString delim = s;
372  if (delim == "[")
373  delim = "]";
374  if (delim == "(")
375  delim = ")";
376  i++;
377  TQByteArray dummy_data;
378  TQDataStream dummy_arg(dummy_data, IO_WriteOnly);
379 
380  uint j = i;
381  uint count = 0;
382  // Parse list to get the count
383  while (true) {
384  if( j > args.count() )
385  {
386  tqWarning("List end-delimiter '%s' not found.", delim.latin1());
387  exit(1);
388  }
389  if( TQString::fromLocal8Bit( args[ j ] ) == delim )
390  break;
391  marshall( dummy_arg, args, j, type );
392  count++;
393  }
394  arg << (TQ_UINT32) count;
395  // Parse the list for real
396  while (true) {
397  if( i > args.count() )
398  {
399  tqWarning("List end-delimiter '%s' not found.", delim.latin1());
400  exit(1);
401  }
402  if( TQString::fromLocal8Bit( args[ i ] ) == delim )
403  break;
404  marshall( arg, args, i, type );
405  }
406  } else {
407  tqWarning( "cannot handle datatype '%s'", type.latin1() );
408  exit(1);
409  }
410  i++;
411 }
KURL
TDEStdAccel::key
int key(StdAccel) KDE_DEPRECATED
DCOPRef
A DCOPRef(erence) encapsulates a remote DCOP object as a triple where type is optional...
Definition: dcopref.h:278
TDEStdAccel::end
const TDEShortcut & end()
KURL::KURL
KURL()
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const

dcop

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

dcop

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