24 #include "../../tdecore/kurl.cpp"
26 bool mkBool(
const TQString& s )
28 if ( s.lower() ==
"true" )
30 if ( s.lower() ==
"yes" )
32 if ( s.lower() ==
"on" )
40 TQPoint mkPoint(
const TQString &str )
42 const char *s = str.latin1();
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 );
52 TQSize mkSize(
const TQString &str )
54 const char *s = str.latin1();
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 );
64 TQRect mkRect(
const TQString &str )
66 const char *s = str.latin1();
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);
82 return TQRect( p3, p4, p1, p2 );
84 return TQRect( p1, p2, p3, p4 );
87 TQColor mkColor(
const TQString& s )
94 const char *qStringToC(
const TQCString &s)
101 TQCString demarshal( TQDataStream &stream,
const TQString &type )
105 if ( type ==
"int" || type ==
"TQ_INT32" )
110 }
else if ( type ==
"uint" || type ==
"TQ_UINT32" || type ==
"unsigned int" )
115 }
else if ( type ==
"long" || type ==
"long int" )
120 }
else if ( type ==
"unsigned long" || type ==
"unsigned long int" )
125 }
else if ( type ==
"float" )
129 result.setNum( f,
'f' );
130 }
else if ( type ==
"double" )
134 result.setNum( d,
'f' );
135 }
else if ( type ==
"TQ_INT64" ) {
138 result.sprintf(
"%lld", i );
139 }
else if ( type ==
"TQ_UINT64" ) {
142 result.sprintf(
"%llu", i );
143 }
else if ( type ==
"bool" )
147 result = b ?
"true" :
"false";
148 }
else if ( type == TQSTRING_OBJECT_NAME_STRING )
152 result = s.local8Bit();
153 }
else if ( type == TQCSTRING_OBJECT_NAME_STRING )
156 }
else if ( type ==
"QCStringList" )
158 return demarshal( stream, TQVALUELIST_OBJECT_NAME_STRING
"<" TQCSTRING_OBJECT_NAME_STRING
">" );
159 }
else if ( type == TQSTRINGLIST_OBJECT_NAME_STRING )
161 return demarshal( stream, TQVALUELIST_OBJECT_NAME_STRING
"<" TQCSTRING_OBJECT_NAME_STRING
">" );
162 }
else if ( type == TQCOLOR_OBJECT_NAME_STRING )
166 result = TQString(c.name()).local8Bit();
167 }
else if ( type == TQSIZE_OBJECT_NAME_STRING )
171 result.sprintf(
"%dx%d", s.width(), s.height() );
172 }
else if ( type == TQPIXMAP_OBJECT_NAME_STRING || type == TQIMAGE_OBJECT_NAME_STRING )
178 buf.open( IO_WriteOnly );
179 i.save( &buf,
"XPM" );
180 result = buf.buffer();
181 }
else if ( type == TQPOINT_OBJECT_NAME_STRING )
185 result.sprintf(
"+%d+%d", p.x(), p.y() );
186 }
else if ( type == TQRECT_OBJECT_NAME_STRING )
190 result.sprintf(
"%dx%d+%d+%d", r.width(), r.height(), r.x(), r.y() );
191 }
else if ( type == TQVARIANT_OBJECT_NAME_STRING )
195 return demarshal( stream, TQVariant::typeToName( (TQVariant::Type)type ) );
196 }
else if ( type ==
"DCOPRef" )
200 result.sprintf(
"DCOPRef(%s,%s)", qStringToC(r.app()), qStringToC(r.object()) );
201 }
else if ( type ==
"KURL" )
205 result = r.
url().local8Bit();
206 }
else if ( type.left( 11 ) == TQVALUELIST_OBJECT_NAME_STRING
"<" )
208 if ( (uint)type.find(
'>', 11 ) != type.length() - 1 )
211 TQString nestedType = type.mid( 11, type.length() - 12 );
213 if ( nestedType.isEmpty() )
220 for (; i < count; ++i )
222 TQCString arg = demarshal( stream, nestedType );
228 }
else if ( type.left( 5 ) == TQMAP_OBJECT_NAME_STRING
"<" )
230 int commaPos = type.find(
',', 5 );
232 if ( commaPos == -1 )
235 if ( (uint)type.find(
'>', commaPos ) != type.length() - 1 )
238 TQString keyType = type.mid( 5, commaPos - 5 );
239 TQString valueType = type.mid( commaPos + 1, type.length() - commaPos - 2 );
245 for (; i < count; ++i )
247 TQCString
key = demarshal( stream, keyType );
252 TQCString value = demarshal( stream, valueType );
254 if ( value.isEmpty() )
257 result += key +
"->" + value;
265 result.sprintf(
"<%s>", type.latin1());
272 void marshall( TQDataStream &arg, QCStringList args, uint &i, TQString type )
274 if( i >= args.count() )
276 tqWarning(
"Not enough arguments (expected %u, got %lu).", i, args.count());
279 TQString s = TQString::fromLocal8Bit( args[ i ] );
281 if (type == TQSTRINGLIST_OBJECT_NAME_STRING) {
282 type = TQVALUELIST_OBJECT_NAME_STRING
"<" TQSTRING_OBJECT_NAME_STRING
">";
284 if (type ==
"QCStringList") {
285 type = TQVALUELIST_OBJECT_NAME_STRING
"<" TQSTRING_OBJECT_NAME_STRING
">";
290 else if ( type ==
"uint" )
292 else if ( type ==
"unsigned" )
294 else if ( type ==
"unsigned int" )
296 else if ( type ==
"TQ_INT32" )
298 else if ( type ==
"TQ_INT64" ) {
299 TQVariant qv = TQVariant( s );
300 arg << qv.toLongLong();
302 else if ( type ==
"TQ_UINT32" )
304 else if ( type ==
"TQ_UINT64" ) {
305 TQVariant qv = TQVariant( s );
306 arg << qv.toULongLong();
308 else if ( type ==
"long" )
310 else if ( type ==
"long int" )
312 else if ( type ==
"unsigned long" )
314 else if ( type ==
"unsigned long int" )
316 else if ( type ==
"float" )
318 else if ( type ==
"double" )
320 else if ( type ==
"bool" )
322 else if ( type == TQSTRING_OBJECT_NAME_STRING )
324 else if ( type == TQCSTRING_OBJECT_NAME_STRING )
325 arg << TQCString( args[ i ] );
326 else if ( type == TQCOLOR_OBJECT_NAME_STRING )
328 else if ( type == TQPOINT_OBJECT_NAME_STRING )
330 else if ( type == TQSIZE_OBJECT_NAME_STRING )
332 else if ( type == TQRECT_OBJECT_NAME_STRING )
334 else if ( type ==
"KURL" )
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 );
344 else if ( s.left( 4 ) ==
"int(" ) {
345 arg << TQVariant( s.mid(4, s.length()-5).toInt() );
347 else if ( s.left( (tqPointKeywordLength+1) ) == TQPOINT_OBJECT_NAME_STRING
"(" ) {
348 arg << TQVariant( mkPoint( s.mid((tqPointKeywordLength+1), s.length()-(tqPointKeywordLength+2)) ) );
350 else if ( s.left( (tqSizeKeywordLength+1) ) == TQSIZE_OBJECT_NAME_STRING
"(" ) {
351 arg << TQVariant( mkSize( s.mid((tqSizeKeywordLength+1), s.length()-(tqSizeKeywordLength+2)) ) );
353 else if ( s.left( (tqRectKeywordLength+1) ) == TQRECT_OBJECT_NAME_STRING
"(" ) {
354 arg << TQVariant( mkRect( s.mid((tqRectKeywordLength+1), s.length()-(tqRectKeywordLength+2)) ) );
356 else if ( s.left( (tqColorKeywordLength+1) ) == TQCOLOR_OBJECT_NAME_STRING
"(" ) {
357 arg << TQVariant( mkColor( s.mid((tqColorKeywordLength+1), s.length()-(tqColorKeywordLength+2)) ) );
360 arg << TQVariant( s );
362 }
else if ( type.startsWith(TQVALUELIST_OBJECT_NAME_STRING
"<") || type ==
"KURL::List" ) {
363 if ( type ==
"KURL::List" ) {
367 int tqValueListKeywordLength = strlen(TQVALUELIST_OBJECT_NAME_STRING);
368 type = type.mid((tqValueListKeywordLength+1), type.length() - (tqValueListKeywordLength+2));
377 TQByteArray dummy_data;
378 TQDataStream dummy_arg(dummy_data, IO_WriteOnly);
384 if( j > args.count() )
386 tqWarning(
"List end-delimiter '%s' not found.", delim.latin1());
389 if( TQString::fromLocal8Bit( args[ j ] ) == delim )
391 marshall( dummy_arg, args, j, type );
394 arg << (TQ_UINT32) count;
397 if( i > args.count() )
399 tqWarning(
"List end-delimiter '%s' not found.", delim.latin1());
402 if( TQString::fromLocal8Bit( args[ i ] ) == delim )
404 marshall( arg, args, i, type );
407 tqWarning(
"cannot handle datatype '%s'", type.latin1() );
int key(StdAccel) KDE_DEPRECATED
A DCOPRef(erence) encapsulates a remote DCOP object as a triple
where type is optional...
const TDEShortcut & end()
TQString url(int _trailing=0, int encoding_hint=0) const