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

dcop

  • dcop
  • client
marshall.cpp
1/*****************************************************************
2Copyright (c) 2000 Matthias Ettrich <ettrich@kde.org>
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION 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
26bool 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
40TQPoint 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
52TQSize 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
64TQRect 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
87TQColor mkColor( const TQString& s )
88{
89 TQColor c;
90 c.setNamedColor(s);
91 return c;
92}
93
94const char *qStringToC(const TQCString &s)
95{
96 if (s.isEmpty())
97 return "";
98 return s.data();
99}
100
101TQCString 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" )
149 {
150 TQString s;
151 stream >> s;
152 result = s.local8Bit();
153 } else if ( type == "TQCString" )
154 {
155 stream >> result;
156 } else if ( type == "QCStringList" )
157 {
158 return demarshal( stream, "TQValueList" "<" "TQCString" ">" );
159 } else if ( type == "TQStringList" )
160 {
161 return demarshal( stream, "TQValueList" "<" "TQString" ">" );
162 } else if ( type == "TQStringVariantMap" )
163 {
164 return demarshal(stream, "TQMap" "<" "TQString" "," "TQVariant" ">");
165 } else if ( type == "TQColor" )
166 {
167 TQColor c;
168 stream >> c;
169 result = TQString(c.name()).local8Bit();
170 } else if ( type == "TQSize" )
171 {
172 TQSize s;
173 stream >> s;
174 result.sprintf( "%dx%d", s.width(), s.height() );
175 } else if ( type == "TQPixmap" || type == "TQImage" )
176 {
177 TQImage i;
178 stream >> i;
179 TQByteArray ba;
180 TQBuffer buf( ba );
181 buf.open( IO_WriteOnly );
182 i.save( &buf, "XPM" );
183 result = buf.buffer();
184 } else if ( type == "TQPoint" )
185 {
186 TQPoint p;
187 stream >> p;
188 result.sprintf( "+%d+%d", p.x(), p.y() );
189 } else if ( type == "TQRect" )
190 {
191 TQRect r;
192 stream >> r;
193 result.sprintf( "%dx%d+%d+%d", r.width(), r.height(), r.x(), r.y() );
194 } else if ( type == "TQVariant" )
195 {
196 TQ_INT32 type;
197 stream >> type;
198 return demarshal( stream, TQVariant::typeToName( (TQVariant::Type)type ) );
199 } else if ( type == "DCOPRef" )
200 {
201 DCOPRef r;
202 stream >> r;
203 result.sprintf( "DCOPRef(%s,%s)", qStringToC(r.app()), qStringToC(r.object()) );
204 } else if ( type == "KURL" )
205 {
206 KURL r;
207 stream >> r;
208 result = r.url().local8Bit();
209 } else if ( type.left( 12 ) == "TQValueList" "<" )
210 {
211 if ( (uint)type.find( '>', 12 ) != type.length() - 1 )
212 return result;
213
214 TQString nestedType = type.mid( 12, type.length() - 13 );
215
216 if ( nestedType.isEmpty() )
217 return result;
218
219 TQ_UINT32 count;
220 stream >> count;
221
222 TQ_UINT32 i = 0;
223 for (; i < count; ++i )
224 {
225 TQCString arg = demarshal( stream, nestedType );
226 result += arg;
227
228 if ( i < count - 1 )
229 result += '\n';
230 }
231 } else if ( type.left( 6 ) == "TQMap" "<" )
232 {
233 int commaPos = type.find( ',', 6 );
234
235 if ( commaPos == -1 )
236 return result;
237
238 if ( (uint)type.find( '>', commaPos ) != type.length() - 1 )
239 return result;
240
241 TQString keyType = type.mid( 6, commaPos - 6 );
242 TQString valueType = type.mid( commaPos + 1, type.length() - commaPos - 2 );
243
244 TQ_UINT32 count;
245 stream >> count;
246
247 TQ_UINT32 i = 0;
248 for (; i < count; ++i )
249 {
250 TQCString key = demarshal( stream, keyType );
251
252 if ( key.isEmpty() )
253 continue;
254
255 TQCString value = demarshal( stream, valueType );
256
257 if ( value.isEmpty() )
258 continue;
259
260 result += key + "->" + value;
261
262 if ( i < count - 1 )
263 result += '\n';
264 }
265 }
266 else
267 {
268 result.sprintf( "<%s>", type.latin1());
269 }
270
271 return result;
272
273}
274
275void marshall( TQDataStream &arg, QCStringList args, uint &i, TQString type )
276{
277 if( i >= args.count() )
278 {
279 tqWarning("Not enough arguments (expected %u, got %lu).", i, args.count());
280 exit(1);
281 }
282 TQString s = TQString::fromLocal8Bit( args[ i ] );
283
284 if (type == "TQStringList") {
285 type = "TQValueList" "<" "TQString" ">";
286 }
287 if (type == "QCStringList") {
288 type = "TQValueList" "<" "TQString" ">";
289 }
290
291 if ( type == "int" )
292 arg << s.toInt();
293 else if ( type == "uint" )
294 arg << s.toUInt();
295 else if ( type == "unsigned" )
296 arg << s.toUInt();
297 else if ( type == "unsigned int" )
298 arg << s.toUInt();
299 else if ( type == "TQ_INT32" )
300 arg << s.toInt();
301 else if ( type == "TQ_INT64" ) {
302 TQVariant qv = TQVariant( s );
303 arg << qv.toLongLong();
304 }
305 else if ( type == "TQ_UINT32" )
306 arg << s.toUInt();
307 else if ( type == "TQ_UINT64" ) {
308 TQVariant qv = TQVariant( s );
309 arg << qv.toULongLong();
310 }
311 else if ( type == "long" )
312 arg << s.toLong();
313 else if ( type == "long int" )
314 arg << s.toLong();
315 else if ( type == "unsigned long" )
316 arg << s.toULong();
317 else if ( type == "unsigned long int" )
318 arg << s.toULong();
319 else if ( type == "float" )
320 arg << s.toFloat();
321 else if ( type == "double" )
322 arg << s.toDouble();
323 else if ( type == "bool" )
324 arg << mkBool( s );
325 else if ( type == "TQString" )
326 arg << s;
327 else if ( type == "TQCString" )
328 arg << TQCString( args[ i ] );
329 else if ( type == "TQColor" )
330 arg << mkColor( s );
331 else if ( type == "TQPoint" )
332 arg << mkPoint( s );
333 else if ( type == "TQSize" )
334 arg << mkSize( s );
335 else if ( type == "TQRect" )
336 arg << mkRect( s );
337 else if ( type == "KURL" )
338 arg << KURL( s );
339 else if ( type == "TQVariant" ) {
340 int tqPointKeywordLength = strlen("TQPoint");
341 int tqSizeKeywordLength = strlen("TQSize");
342 int tqRectKeywordLength = strlen("TQRect");
343 int tqColorKeywordLength = strlen("TQColor");
344 if ( s == "true" || s == "false" ) {
345 arg << TQVariant( mkBool( s ) );
346 }
347 else if ( s.left( 4 ) == "int(" ) {
348 arg << TQVariant( s.mid(4, s.length()-5).toInt() );
349 }
350 else if ( s.left( (tqPointKeywordLength+1) ) == "TQPoint" "(" ) {
351 arg << TQVariant( mkPoint( s.mid((tqPointKeywordLength+1), s.length()-(tqPointKeywordLength+2)) ) );
352 }
353 else if ( s.left( (tqSizeKeywordLength+1) ) == "TQSize" "(" ) {
354 arg << TQVariant( mkSize( s.mid((tqSizeKeywordLength+1), s.length()-(tqSizeKeywordLength+2)) ) );
355 }
356 else if ( s.left( (tqRectKeywordLength+1) ) == "TQRect" "(" ) {
357 arg << TQVariant( mkRect( s.mid((tqRectKeywordLength+1), s.length()-(tqRectKeywordLength+2)) ) );
358 }
359 else if ( s.left( (tqColorKeywordLength+1) ) == "TQColor" "(" ) {
360 arg << TQVariant( mkColor( s.mid((tqColorKeywordLength+1), s.length()-(tqColorKeywordLength+2)) ) );
361 }
362 else {
363 arg << TQVariant( s );
364 }
365 } else if ( type.startsWith("TQValueList" "<") || type == "KURL::List" ) {
366 if ( type == "KURL::List" ) {
367 type = "KURL";
368 }
369 else {
370 int tqValueListKeywordLength = strlen("TQValueList");
371 type = type.mid((tqValueListKeywordLength+1), type.length() - (tqValueListKeywordLength+2));
372 }
373 TQStringList list;
374 TQString delim = s;
375 if (delim == "[")
376 delim = "]";
377 if (delim == "(")
378 delim = ")";
379 i++;
380 TQByteArray dummy_data;
381 TQDataStream dummy_arg(dummy_data, IO_WriteOnly);
382
383 uint j = i;
384 uint count = 0;
385 // Parse list to get the count
386 while (true) {
387 if( j > args.count() )
388 {
389 tqWarning("List end-delimiter '%s' not found.", delim.latin1());
390 exit(1);
391 }
392 if( TQString::fromLocal8Bit( args[ j ] ) == delim )
393 break;
394 marshall( dummy_arg, args, j, type );
395 count++;
396 }
397 arg << (TQ_UINT32) count;
398 // Parse the list for real
399 while (true) {
400 if( i > args.count() )
401 {
402 tqWarning("List end-delimiter '%s' not found.", delim.latin1());
403 exit(1);
404 }
405 if( TQString::fromLocal8Bit( args[ i ] ) == delim )
406 break;
407 marshall( arg, args, i, type );
408 }
409 } else {
410 tqWarning( "cannot handle datatype '%s'", type.latin1() );
411 exit(1);
412 }
413 i++;
414}
DCOPRef
A DCOPRef(erence) encapsulates a remote DCOP object as a triple <app,obj,type> where type is optional...
Definition: dcopref.h:279
DCOPRef::object
TQCString object() const
Definition: dcopref.cpp:150
DCOPRef::app
TQCString app() const
Name of the application in which the object resides.
Definition: dcopref.cpp:140
KURL
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
TDEStdAccel::key
int key(StdAccel id)
TDEStdAccel::end
const TDEShortcut & end()

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
  • 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 dcop by doxygen 1.9.4
This website is maintained by Timothy Pearson.