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" )
152 result = s.local8Bit();
153 }
else if ( type ==
"TQCString" )
156 }
else if ( type ==
"QCStringList" )
158 return demarshal( stream,
"TQValueList" "<" "TQCString" ">" );
159 }
else if ( type ==
"TQStringList" )
161 return demarshal( stream,
"TQValueList" "<" "TQString" ">" );
162 }
else if ( type ==
"TQStringVariantMap" )
164 return demarshal(stream,
"TQMap" "<" "TQString" "," "TQVariant" ">");
165 }
else if ( type ==
"TQColor" )
169 result = TQString(c.name()).local8Bit();
170 }
else if ( type ==
"TQSize" )
174 result.sprintf(
"%dx%d", s.width(), s.height() );
175 }
else if ( type ==
"TQPixmap" || type ==
"TQImage" )
181 buf.open( IO_WriteOnly );
182 i.save( &buf,
"XPM" );
183 result = buf.buffer();
184 }
else if ( type ==
"TQPoint" )
188 result.sprintf(
"+%d+%d", p.x(), p.y() );
189 }
else if ( type ==
"TQRect" )
193 result.sprintf(
"%dx%d+%d+%d", r.width(), r.height(), r.x(), r.y() );
194 }
else if ( type ==
"TQVariant" )
198 return demarshal( stream, TQVariant::typeToName( (TQVariant::Type)type ) );
199 }
else if ( type ==
"DCOPRef" )
203 result.sprintf(
"DCOPRef(%s,%s)", qStringToC(r.
app()), qStringToC(r.
object()) );
204 }
else if ( type ==
"KURL" )
208 result = r.
url().local8Bit();
209 }
else if ( type.left( 12 ) ==
"TQValueList" "<" )
211 if ( (uint)type.find(
'>', 12 ) != type.length() - 1 )
214 TQString nestedType = type.mid( 12, type.length() - 13 );
216 if ( nestedType.isEmpty() )
223 for (; i < count; ++i )
225 TQCString arg = demarshal( stream, nestedType );
231 }
else if ( type.left( 6 ) ==
"TQMap" "<" )
233 int commaPos = type.find(
',', 6 );
235 if ( commaPos == -1 )
238 if ( (uint)type.find(
'>', commaPos ) != type.length() - 1 )
241 TQString keyType = type.mid( 6, commaPos - 6 );
242 TQString valueType = type.mid( commaPos + 1, type.length() - commaPos - 2 );
248 for (; i < count; ++i )
250 TQCString
key = demarshal( stream, keyType );
255 TQCString value = demarshal( stream, valueType );
257 if ( value.isEmpty() )
260 result +=
key +
"->" + value;
268 result.sprintf(
"<%s>", type.latin1());
275 void marshall( TQDataStream &arg, QCStringList args, uint &i, TQString type )
277 if( i >= args.count() )
279 tqWarning(
"Not enough arguments (expected %u, got %lu).", i, args.count());
282 TQString s = TQString::fromLocal8Bit( args[ i ] );
284 if (type ==
"TQStringList") {
285 type =
"TQValueList" "<" "TQString" ">";
287 if (type ==
"QCStringList") {
288 type =
"TQValueList" "<" "TQString" ">";
293 else if ( type ==
"uint" )
295 else if ( type ==
"unsigned" )
297 else if ( type ==
"unsigned int" )
299 else if ( type ==
"TQ_INT32" )
301 else if ( type ==
"TQ_INT64" ) {
302 TQVariant qv = TQVariant( s );
303 arg << qv.toLongLong();
305 else if ( type ==
"TQ_UINT32" )
307 else if ( type ==
"TQ_UINT64" ) {
308 TQVariant qv = TQVariant( s );
309 arg << qv.toULongLong();
311 else if ( type ==
"long" )
313 else if ( type ==
"long int" )
315 else if ( type ==
"unsigned long" )
317 else if ( type ==
"unsigned long int" )
319 else if ( type ==
"float" )
321 else if ( type ==
"double" )
323 else if ( type ==
"bool" )
325 else if ( type ==
"TQString" )
327 else if ( type ==
"TQCString" )
328 arg << TQCString( args[ i ] );
329 else if ( type ==
"TQColor" )
331 else if ( type ==
"TQPoint" )
333 else if ( type ==
"TQSize" )
335 else if ( type ==
"TQRect" )
337 else if ( type ==
"KURL" )
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 ) );
347 else if ( s.left( 4 ) ==
"int(" ) {
348 arg << TQVariant( s.mid(4, s.length()-5).toInt() );
350 else if ( s.left( (tqPointKeywordLength+1) ) ==
"TQPoint" "(" ) {
351 arg << TQVariant( mkPoint( s.mid((tqPointKeywordLength+1), s.length()-(tqPointKeywordLength+2)) ) );
353 else if ( s.left( (tqSizeKeywordLength+1) ) ==
"TQSize" "(" ) {
354 arg << TQVariant( mkSize( s.mid((tqSizeKeywordLength+1), s.length()-(tqSizeKeywordLength+2)) ) );
356 else if ( s.left( (tqRectKeywordLength+1) ) ==
"TQRect" "(" ) {
357 arg << TQVariant( mkRect( s.mid((tqRectKeywordLength+1), s.length()-(tqRectKeywordLength+2)) ) );
359 else if ( s.left( (tqColorKeywordLength+1) ) ==
"TQColor" "(" ) {
360 arg << TQVariant( mkColor( s.mid((tqColorKeywordLength+1), s.length()-(tqColorKeywordLength+2)) ) );
363 arg << TQVariant( s );
365 }
else if ( type.startsWith(
"TQValueList" "<") || type ==
"KURL::List" ) {
366 if ( type ==
"KURL::List" ) {
370 int tqValueListKeywordLength = strlen(
"TQValueList");
371 type = type.mid((tqValueListKeywordLength+1), type.length() - (tqValueListKeywordLength+2));
380 TQByteArray dummy_data;
381 TQDataStream dummy_arg(dummy_data, IO_WriteOnly);
387 if( j > args.count() )
389 tqWarning(
"List end-delimiter '%s' not found.", delim.latin1());
392 if( TQString::fromLocal8Bit( args[ j ] ) == delim )
394 marshall( dummy_arg, args, j, type );
397 arg << (TQ_UINT32) count;
400 if( i > args.count() )
402 tqWarning(
"List end-delimiter '%s' not found.", delim.latin1());
405 if( TQString::fromLocal8Bit( args[ i ] ) == delim )
407 marshall( arg, args, i, type );
410 tqWarning(
"cannot handle datatype '%s'", type.latin1() );
A DCOPRef(erence) encapsulates a remote DCOP object as a triple <app,obj,type> where type is optional...
TQCString app() const
Name of the application in which the object resides.
TQString url(int _trailing=0, int encoding_hint=0) const
const TDEShortcut & end()