summaryrefslogtreecommitdiffstats
path: root/kjsembed/slotutils.cpp
blob: 58670e215397366c552fb4c51d80104bdb50fa34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
/*
 *  Copyright (C) 2001-2003, Richard J. Moore <rich@kde.org>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 */

#include <qobject.h>
#include <qobjectlist.h>
#include <qdialog.h>
#include <qlistbox.h>
#include <qlistview.h>
#include <qmetaobject.h>
#include <qregexp.h>
#include <qsignal.h>
#include <qstrlist.h>
#include <qtimer.h>
#include <qvariant.h>
#include <qdatetime.h>
#include <qstringlist.h>

#include <private/qucom_p.h>
#include <private/qucomextra_p.h>

#ifndef QT_ONLY
#include <klistview.h>
#include <kurl.h>
#else // QT_ONLY
#include "qtstubs.h"
#endif // QT_ONLY

#include <kjs/interpreter.h>
#include <kjs/types.h>
#include <kjs/ustring.h>

#include "kjsembedpart.h"
#include "jssecuritypolicy.h"

#include "global.h"
#include "jsfactory.h"
#include "slotproxy.h"
#include "jsvalueproxy.h"
#include "jsopaqueproxy.h"

#include "jsobjectproxy_imp.h"

#include "slotutils.h"

namespace KJSEmbed {
namespace Bindings {

JSSlotUtils::JSSlotUtils()
{
}

JSSlotUtils::~JSSlotUtils()
{
}

bool JSSlotUtils::connect( QObject *sender, const char *sig, QObject *recv, const char *dest )
{
    if ( (!sender) || (!recv) )
	return false;

    // Source
    QString si = QString("2%1").arg(sig);
    const char *sigc = si.ascii();

    // Connect to slot
    if ( recv->metaObject()->findSlot(dest, true) >= 0 ) {
	QString sl = QString("1%1").arg(dest);
	const char *slotc = sl.ascii();

	//kdDebug(80001) << "connect: "<<sender->name()<<" "<<sigc<<", slot "<<recv->name()<<" "<<slotc<< endl;
	bool ok = QObject::connect( sender, sigc, recv, slotc );
	if (ok)
	    return true;
    }

    // Connect to signal
    if ( recv->metaObject()->findSignal(dest, true) >= 0 ) {
	QString si2 = QString("2%1").arg(dest);
	const char *sig2c = si2.ascii();

	kdDebug(80001) << "connect: "<<sender->name()<<" "<<sigc<<", sig "<<recv->name()<<" "<<sig2c<< endl;
	bool ok = QObject::connect( sender, sigc, recv, sig2c );
	if (ok)
	    return true;
    }

    return false;
}

KJS::Boolean JSSlotUtils::disconnect( KJS::ExecState */*exec*/, KJS::Object &/*self*/,
				    QObject *sender, const char *sig,
				    QObject *recv, const char *dest )
{
    if ( (!sender) || (!recv) )
	return KJS::Boolean(false);

    bool ok;

    // Source
    QString si = QString("2%1").arg(sig);
    const char *sigc = si.ascii();

    // Disconnect from slot
    if ( recv->metaObject()->findSlot(dest, true) >= 0 ) {
	QString sl = QString("1%1").arg(dest);
	const char *slotc = sl.ascii();

	//kdDebug(80001) << "disconnect: "<<sender->name()<<" "<<sigc<<", slot "<<recv->name()<<" "<<slotc<< endl;
	ok = QObject::disconnect( sender, sigc, recv, slotc );
	if (ok)
	    return KJS::Boolean(ok);
    }

    // Disonnect to signal
    if ( recv->metaObject()->findSignal(dest, true) >= 0 ) {
	QString si2("2");
	si2 = si2 + dest;
	const char *sig2c = si2.ascii();

	//kdDebug(80001)<< "disconnect: "<<sender->name()<<" "<<sigc<<", sig "<<recv->name()<<" "<<sig2c<< endl;
	ok = QObject::disconnect( sender, sigc, recv, sig2c );
	if (ok)
	    return KJS::Boolean(ok);
    }

    return KJS::Boolean(false);
}

KJS::Value JSSlotUtils::extractValue( KJS::ExecState *exec, QUObject *uo, JSObjectProxy *parent )
{
    QCString typenm( uo->type->desc() );
    kdDebug(80001) << "JSSlotUtils:extractValue() " << typenm << endl;

    if ( typenm == "null" )
	return KJS::Null();
    else if ( typenm == "bool" )
	return KJS::Boolean( static_QUType_bool.get(uo) );
    else if ( typenm == "int" )
	return KJS::Number( static_QUType_int.get(uo) );
    else if ( typenm == "double" )
	return KJS::Number( static_QUType_double.get(uo) );
    else if ( typenm == "charstar" )
	return KJS::String( static_QUType_charstar.get(uo) );
    else if ( typenm == "QString" )
	return KJS::String( static_QUType_QString.get(uo) );
    else if ( typenm == "QVariant" )
	return convertToValue( exec, static_QUType_QVariant.get(uo) );
    else if ( typenm == "ptr" ) {
	void *ptr = static_QUType_ptr.get(uo);

	// If it's a QObject and we know the parent
	if ( ptr && parent ) {
	    QObject *qobj = (QObject *)(ptr); // Crash in kst
	    return parent->part()->factory()->createProxy( exec, qobj, parent);
	}
    }

    kdWarning(80001) << "JSSlotUtils:extractValue() Failed (" << typenm << ")" << endl;
    QString msg = i18n( "Value of type (%1) is not supported." ).arg( typenm );
    throwError(exec, msg,KJS::TypeError);
    return KJS::Null();
}

//
// Add a value to a QUObject.
//

void JSSlotUtils::implantInt( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v )
{
    static_QUType_int.set( uo, v.toInteger( exec ) );
}

void JSSlotUtils::implantCharStar( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v )
{
    static_QUType_charstar.set( uo, v.toString( exec ).ascii() );
}

void JSSlotUtils::implantBool( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v )
{
    static_QUType_bool.set( uo, v.toBoolean( exec ) );
}

void JSSlotUtils::implantDouble( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v )
{
    static_QUType_double.set( uo, v.toNumber( exec ) );
}

void JSSlotUtils::implantQString( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v )
{
    static_QUType_QString.set( uo, v.toString(exec).qstring() );
}

void JSSlotUtils::implantCString( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v )
{
    static_QUType_charstar.set( uo, v.toString(exec).ascii() );
}

void JSSlotUtils::implantURL( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v,KURL *url )
{
    *url = QString( v.toString(exec).qstring() );
    static_QUType_ptr.set( uo, url );
}

void JSSlotUtils::implantColor( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QColor *color )
{
    bool ok;
    QString s( v.toString(exec).qstring() );

    if ( s.startsWith("#") ) {

	QRegExp re("#([0-9a-f][0-9a-f]){3,4}");
	re.setCaseSensitive( false );

	if ( re.search(s) != -1 ) {
	    uint r = re.cap(1).toUInt(&ok, 16);
	    uint g = re.cap(2).toUInt(&ok, 16);
	    uint b = re.cap(3).toUInt(&ok, 16);

	    if ( re.numCaptures() == 3 )
		*color = QColor(r,g,b);
	    else if ( re.numCaptures() == 4 ) {
		uint a = re.cap(4).toUInt(&ok, 16);
		uint pix = r;
		pix = pix << 8;
		pix = pix | g;
		pix = pix << 8;
		pix = pix | b;
		pix = pix << 8;
		pix = pix | a;

		*color = QColor( qRgba(r,g,b,a), pix );
	    }
	}

    }
    else {
	// Try for a named color
	*color = QColor( s );
    }

    static_QUType_ptr.set( uo, color );
}

void JSSlotUtils::implantPoint( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QPoint *point )
{
    KJS::Object o = v.toObject( exec );
    if ( !o.isValid() )
	return;

    int x, y;
    KJS::Identifier zero("0"), one("1"), ex("x"), wi("y");

    if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) ) {
	x = o.get( exec, zero ).toInteger(exec);
	y = o.get( exec, one ).toInteger(exec);
    }
    else if ( o.hasProperty(exec, ex) && o.hasProperty(exec, wi) ) {
	x = o.get( exec, ex ).toInteger(exec);
	y = o.get( exec, wi ).toInteger(exec);
    }
    else
	return;

    *point = QPoint( x, y );
    static_QUType_ptr.set( uo, point );
}

void JSSlotUtils::implantSize( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QSize *size )
{
    KJS::Object o = v.toObject( exec );
    if ( !o.isValid() )
	return;

    int w, h;
    KJS::Identifier zero("0"), one("1"), wid("width"), hih("height");

    if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one) ) {
	w = o.get( exec, zero ).toInteger(exec);
	h = o.get( exec, one ).toInteger(exec);
    }
    else if ( o.hasProperty(exec, wid) && o.hasProperty(exec, hih) ) {
	w = o.get( exec, wid ).toInteger(exec);
	h = o.get( exec, hih ).toInteger(exec);
    }
    else
	return;

    *size = QSize( w, h );
    static_QUType_ptr.set( uo, size );
}

void JSSlotUtils::implantRect( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QRect *rect )
{
    KJS::Object o = v.toObject( exec );
    if ( !o.isValid() )
	return;

    int x, y, w, h;
    KJS::Identifier zero("0"), one("1"), two("2"), three("3");
    KJS::Identifier ex("x"), wi("y"), wid("width"), hih("height");

    if ( o.hasProperty(exec, zero) && o.hasProperty(exec, one)
	 && o.hasProperty(exec, two) && o.hasProperty(exec, three) ) {
	x = o.get( exec, zero ).toInteger(exec);
	y = o.get( exec, one ).toInteger(exec);
	w = o.get( exec, two ).toInteger(exec);
	h = o.get( exec, three ).toInteger(exec);
    }
    else if ( o.hasProperty(exec, ex) && o.hasProperty(exec, wi)
	      && o.hasProperty(exec, wid) && o.hasProperty(exec, hih) ) {
	x = o.get( exec, ex ).toInteger(exec);
	y = o.get( exec, wi ).toInteger(exec);
	w = o.get( exec, wid ).toInteger(exec);
	h = o.get( exec, hih ).toInteger(exec);
    }
    else
	return;

    *rect = QRect( x, y, w, h );
    static_QUType_ptr.set( uo, rect );
}

void JSSlotUtils::implantDate(  KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QDate *date )
{
	QDateTime jsDate = convertDateToDateTime(exec, v);
	date->setYMD( jsDate.date().year(), jsDate.date().month(), jsDate.date().day() );
	static_QUType_ptr.set( uo, date );
}

void JSSlotUtils::implantStringList(KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QStringList *lst )
{
  *lst = convertArrayToStringList(exec,v);
  static_QUType_ptr.set(uo,lst);
}

void JSSlotUtils::implantTime( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QTime *time )
{
	QDateTime jsDate = convertDateToDateTime(exec, v);
	time->setHMS( jsDate.time().hour(), jsDate.time().minute(), jsDate.time().second() );
	static_QUType_ptr.set( uo, time );
}

void JSSlotUtils::implantDateTime( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QDateTime *datetime  )
{
	QDateTime jsDate = convertDateToDateTime(exec, v);
	datetime->setDate( jsDate.date() );
	datetime->setTime( jsDate.time() );
	static_QUType_ptr.set( uo, datetime );
}

void JSSlotUtils::implantPixmap( KJS::ExecState *exec, QUObject *uo, const KJS::Value &v, QPixmap *pix )
{
    *pix = convertToVariant(exec, v).toPixmap() ;
    static_QUType_ptr.set( uo, pix );
}

bool JSSlotUtils::implantQVariant( KJS::ExecState *, QUObject *uo, const KJS::Value &v)
{
    JSValueProxy *prx = JSProxy::toValueProxy( v.imp() );
    if ( !prx )
	return false;
    kdDebug(80001) << "We got a " << prx->typeName() << endl;

    static_QUType_QVariant.set( uo, prx->toVariant() );
    return true;
}

bool JSSlotUtils::implantValueProxy( KJS::ExecState *, QUObject *uo,
				     const KJS::Value &val, const QString &clazz )
{
    JSValueProxy *prx = JSProxy::toValueProxy( val.imp() );
    if ( !prx )
	return false;
    if ( prx->typeName() != clazz )
	return false;

    kdDebug(80001) << "We got a " << prx->typeName() << " and is valid " << prx->toVariant().isValid() << endl;
    QVariant var = prx->toVariant();
    kdDebug(80001) << "We got a " << var.typeName()<< " and is valid " << var.isValid() << endl;
    static_QUType_QVariant.set( uo, var );
    return var.isValid();
}

bool JSSlotUtils::implantOpaqueProxy( KJS::ExecState *, QUObject *uo,
				      const KJS::Value &v, const QString &clazz )
{
    JSOpaqueProxy *prx = JSProxy::toOpaqueProxy( v.imp() );
    if ( !prx )
	return false;
    if ( prx->typeName() != clazz )
	return false;

    static_QUType_ptr.set( uo, prx->toNative<void>() );
    return true;
}

bool JSSlotUtils::implantObjectProxy( KJS::ExecState *, QUObject *uo,
				      const KJS::Value &v, const QString &clazz )
{
    JSObjectProxy *prx = JSProxy::toObjectProxy( v.imp() );
    if ( !prx )
	return false;

    if ( !prx->object()->inherits( clazz.latin1() ) )
	return false;

    static_QUType_ptr.set( uo, prx->toObjectProxy()->object() );
    return true;
}

int JSSlotUtils::findSignature( const QString &sig )
{
    // No args
    if ( sig.contains("()") )
	return SignatureNone;

    // One arg
    if ( sig.contains("(int)") )
	return SignatureInt;
    else if ( sig.contains("(uint)") )
	return SignatureUInt;
    else if ( sig.contains("(long)") )
	return SignatureLong;
    else if ( sig.contains("(ulong)") )
	return SignatureULong;
    else if ( sig.contains("(bool)") )
	return SignatureBool;
    else if ( sig.contains("(double)") )
	return SignatureDouble;

    else if ( sig.contains("(const QString&)") )
	return SignatureString;
    else if ( sig.contains("(const QCString&)") )
	return SignatureCString;
    else if ( sig.contains("(const char*)") )
	return SignatureCString;
    else if ( sig.contains("(const KURL&)") )
	return SignatureURL;
    else if ( sig.contains("(const QColor&)") )
	return SignatureColor;
    else if ( sig.contains("(const QPoint&)") )
	return SignaturePoint;
    else if ( sig.contains("(const QRect&)") )
	return SignatureRect;
    else if ( sig.contains("(const QSize&)") )
	return SignatureSize;
    else if ( sig.contains("(const QPixmap&)") )
	return SignaturePixmap;
    else if ( sig.contains("(const QFont&)") )
	return SignatureFont;
    else if ( sig.contains("(const QDate&)") )
	return SignatureDate;
    else if ( sig.contains("(const QTime&)") )
	return SignatureTime;
    else if ( sig.contains("(const QDateTime&)") )
	return SignatureDateTime;
    else if ( sig.contains("(const QImage&)") )
	return SignatureImage;
    else if ( sig.contains("(QWidget*)") )
	return SignatureQWidget;
    // Two args
    else if ( sig.contains("(const QDate&, const QDate&)") )
	return SignatureDateDate;
    else if ( sig.contains("(const QColor&, const QString&)") )
	return SignatureColorString;

    else if ( sig.contains("(const QString&,const QString&,const QString&)") )
	return SignatureStringStringString;

    else if ( sig.contains("(const QString&,const QString&)") )
	return SignatureStringString;
    else if ( sig.contains("(int,int)") )
	return SignatureIntInt;
    else if ( sig.contains("(int,int,int,int)") )
	return SignatureIntIntIntInt;
    else if ( sig.contains("(int,int,int,int,int)") )
	return SignatureIntIntIntIntInt;
    else if ( sig.contains("(int,int,int,int,bool)") )
	return SignatureIntIntIntIntBool;

    else if ( sig.contains("(const QString&,int)") )
	return SignatureStringInt;
    else if ( sig.contains("(const QString&,uint)") )
	return SignatureStringInt;

    else if ( sig.contains("(const KURL&,const KURL&)") )
	return SignatureURLURL;
    else if ( sig.contains("(const KURL&,const QString&)") )
	return SignatureURLString;
    else if ( sig.contains("(const QString&,const KURL&)") )
	return SignatureStringURL;
    else if ( sig.contains("(const QRect&,bool)") )
	return SignatureRectBool;
    else if ( sig.contains("(const QString&,bool)") )
	return SignatureStringBool;
    else if ( sig.contains("(int,bool)") )
	return SignatureIntBool;
    else if ( sig.contains("(int,int,bool)") )
	return SignatureIntIntBool;
    else if ( sig.contains("(int,int,const QString&)") )
	return SignatureIntIntString;
    else if ( sig.contains("(const QString&,bool,int)") )
	return SignatureStringBoolInt;
    else if ( sig.contains("(const QString&,bool,bool)") )
	return SignatureStringBoolBool;
    else if ( sig.contains("(const QString&,int,int)") )
	return SignatureStringIntInt;
    else if ( sig.contains("(int,const QColor&,bool)") )
	return SignatureIntColorBool;
    else if ( sig.contains("(int,const QColor&)") )
	return SignatureIntColor;

    else if ( sig.contains("(int,int,float,float)") )
	return SignatureIntIntFloatFloat;
    else if ( sig.contains("(const QString&,bool,bool,bool)") )
	return SignatureStringBoolBoolBool;
    else if ( sig.contains("(int,int,int,int,int,int)") )
	return SignatureIntIntIntIntIntInt;

    // Handle anything that falls through
    if ( sig.contains("QString") || sig.contains("QColor") ||
	sig.contains("int") || sig.contains("bool") ||
        sig.contains("float") || sig.contains("KURL") ||
        sig.contains("QVariant") || sig.contains("QSize") ||
        sig.contains("QRect") || sig.contains("QPixmap") ||
        sig.contains("QCString") || sig.contains("QPoint") ||
	sig.contains("double") || sig.contains("QFont") ||
	sig.contains("QDate") || sig.contains("QTime") ||
	sig.contains("QDateTime") || sig.contains("QStringList") ||
	sig.contains("QWidget") || sig.contains("QObject") ||
	sig.contains("QPen") || sig.contains("QImage") )
	   return SignatureCustom;

    kdWarning(80001) << "findSignature: not supported type " << sig << endl;
    return SignatureNotSupported;
}

#define MAX_SUPPORTED_ARGS (12)

KJS::Value JSSlotUtils::invokeSlot( KJS::ExecState *exec, KJS::Object &, const KJS::List &args,
				    JSObjectProxyImp *proxyimp )
{
    QUObject uo[ MAX_SUPPORTED_ARGS ] = { QUObject(), QUObject(), QUObject(),
					  QUObject(), QUObject(), QUObject(),
					  QUObject(), QUObject(), QUObject(),
					  QUObject(), QUObject(), QUObject() };

    KJS::Value retValue;
    JSObjectProxy *proxy = proxyimp->objectProxy();
    QCString slotname( proxyimp->slotName() );
    int sigid = proxyimp->signature();
    QPtrList<uint> uintlist;
    uintlist.setAutoDelete(true);
    QObject *obj = proxy->object();
    int slotid = obj->metaObject()->findSlot( slotname, true );
    if ( slotid == -1 )
    {
	QString msg = i18n( "Slot %1 was not found." ).arg( slotname );
  return throwError(exec, msg,KJS::ReferenceError);
    }

    if ( args.size() > MAX_SUPPORTED_ARGS )
    {
	QString msg = i18n( "Slots with more than %1 arguments are not supported." ).arg( MAX_SUPPORTED_ARGS );
  return throwError(exec, msg,KJS::ReferenceError);
    }
    // Keep args in scope for duration of the method.
    KURL url[MAX_SUPPORTED_ARGS];
    QColor color[MAX_SUPPORTED_ARGS];
    QPoint point[MAX_SUPPORTED_ARGS];
    QSize size[MAX_SUPPORTED_ARGS];
    QRect rect[MAX_SUPPORTED_ARGS];
    QDate date[MAX_SUPPORTED_ARGS];
    QDateTime datetime[MAX_SUPPORTED_ARGS];
    QTime time[MAX_SUPPORTED_ARGS];
    QPixmap pix[MAX_SUPPORTED_ARGS];
    QStringList slst[MAX_SUPPORTED_ARGS];
    
    bool notsupported = true;

    if ( args.size() == 1 ) {
	//kdDebug( 80001 ) << "One Arg" << endl;
	switch (sigid) {
	    case SignatureInt:
		implantInt( exec, uo+1, args[0] );
		break;
	    case SignatureBool:
		implantBool( exec, uo+1, args[0] );
		break;
	    case SignatureString:
		implantQString( exec, uo+1, args[0] );
		break;
	    case SignatureCString:
		implantCString( exec, uo+1, args[0] );
		break;
	    case SignatureDouble:
		implantDouble( exec, uo+1, args[0] );
		break;
	    case SignatureURL:
		implantURL( exec, uo+1, args[0], &url[0] );
		break;
	    case SignatureColor:
		implantColor( exec, uo+1, args[0], &color[0] );
		break;
	    case SignaturePoint:
		implantPoint( exec, uo+1, args[0], &point[0] );
		break;
	    case SignatureSize:
		implantSize( exec, uo+1, args[0], &size[0] );
		break;
	    case SignatureRect:
		implantRect( exec, uo+1, args[0], &rect[0] );
		break;
	    default:
		notsupported = true;
		break;
	}

    } else if ( args.size() == 2 ) {
	//kdDebug( 80001 ) << "Two Args" << endl;
	switch (sigid) {
	    case SignatureIntInt:
		implantInt( exec, uo+1, args[0] );
		implantInt( exec, uo+2, args[1] );
		break;
	    case SignatureStringInt:
		implantQString( exec, uo+1, args[0] );
		implantInt( exec, uo+2, args[1] );
		break;
	    case SignatureRectBool:
		implantRect( exec, uo+1, args[0], &rect[0] );
		implantBool( exec, uo+2, args[1] );
		break;
	    case SignatureStringString:
		implantQString( exec, uo+1, args[0] );
		implantQString( exec, uo+2, args[1] );
		break;
	    case SignatureStringBool:
		implantQString( exec, uo+1, args[0] );
		implantBool( exec, uo+2, args[1] );
		break;
	    case SignatureIntColor:
		implantInt( exec, uo+1, args[0] );
		implantColor( exec, uo+2, args[1], &color[0] );
		break;
	    case SignatureURLURL:
		implantURL( exec, uo+1, args[0], &url[0] );
		implantURL( exec, uo+2, args[1], &url[1] );
		break;
	    case SignatureURLString:
		implantURL( exec, uo+1, args[0], &url[0] );
		implantQString( exec, uo+2, args[1] );
		break;
	    case SignatureStringURL:
		implantQString( exec, uo+1, args[0] );
		implantURL( exec, uo+2, args[1], &url[0] );
		break;

	    default:
		notsupported = true;
		break;
	}

    } else  {
	//kdDebug( 80001 ) << args.size() << " Args" << endl;
	notsupported = false;
	switch (sigid) {
	    case SignatureNone:
		break;
	    case SignatureStringStringString:
		if ( args.size() != 3 )
		    return KJS::Null();
		implantQString( exec, uo+1, args[0] );
		implantQString( exec, uo+2, args[1] );
		implantQString( exec, uo+3, args[2] );
		break;
	    case SignatureIntIntString:
		if ( args.size() != 3 )
		    return KJS::Null();
		implantInt( exec, uo+1, args[0] );
		implantInt( exec, uo+2, args[1] );
		implantQString( exec, uo+3, args[2] );
		break;
	    case SignatureIntIntIntInt:
		if ( args.size() != 4 )
		    return KJS::Null();
		implantInt( exec, uo+1, args[0] );
		implantInt( exec, uo+2, args[1] );
		implantInt( exec, uo+3, args[2] );
		implantInt( exec, uo+4, args[3] );
		break;
	    case SignatureIntIntIntIntBool:
		if ( args.size() != 5 )
		    return KJS::Null();
		implantInt( exec, uo+1, args[0] );
		implantInt( exec, uo+2, args[1] );
		implantInt( exec, uo+3, args[2] );
		implantInt( exec, uo+4, args[3] );
		implantBool( exec, uo+5, args[4] );
		break;
	    case SignatureIntIntIntIntIntInt:
		if ( args.size() != 6 )
		    return KJS::Null();
		implantInt( exec, uo+1, args[0] );
		implantInt( exec, uo+2, args[1] );
		implantInt( exec, uo+3, args[2] );
		implantInt( exec, uo+4, args[3] );
		implantInt( exec, uo+5, args[4] );
		implantInt( exec, uo+6, args[5] );
		break;
	    default:
		notsupported = true;
	}
    }

    if ( notsupported ) {
	//kdDebug( 80001 ) << "Trying method 2" << endl;
        // Rip apart the call signature to get the args slow but effective.
	notsupported = false;
	int argsStart = slotname.find('(');
	int argsEnd = slotname.find(')');
        QString fargs = slotname.mid( argsStart+1, argsEnd-argsStart-1 );

	// Iterate over the parameters
        QStringList argList = QStringList::split(',', fargs, true);
	uint count = QMIN( argList.count(), MAX_SUPPORTED_ARGS );

	kdDebug( 80001 ) << "======== arg count " << count << endl;
        for( uint idx = 0; idx < count; idx++ ) {
	    kdDebug( 80001 ) << "======== Handling arg " << idx << endl;

	    QString arg = argList[idx];
	    arg = arg.replace("const", "");
	    arg = arg.replace("&", "");
	    arg = arg.simplifyWhiteSpace();
	    kdDebug( 80001 ) << "Testing " << arg.latin1() << endl;

	    if(arg.contains("uint") == 1) {
		unsigned int *unsignedint=new uint;
		*unsignedint=args[idx].toUInt32(exec);
		uintlist.append(unsignedint);
		static_QUType_ptr.set( uo+1+idx, unsignedint) ;
	    }
	    else if( arg.contains("int") == 1 )
		implantInt( exec, uo+1+idx, args[idx] );
	    else if ( arg.contains("double") == 1 )
		implantDouble(exec,  uo+1+idx, args[idx]);
	    else if ( arg.contains("QStringList") == 1 )
		implantStringList( exec, uo+1+idx, args[idx], &slst[idx] );
	    else if ( arg.contains("QString") == 1 )
		implantQString(exec,  uo+1+idx, args[idx] );
	    else if ( arg.contains("QCString") == 1 )
		implantCString(exec,  uo+1+idx, args[idx] );
	    else if ( arg.contains("bool") == 1 )
		implantBool( exec, uo+1+idx, args[idx] );
	    else if ( arg.contains("KURL") == 1 )
		implantURL( exec, uo+1+idx, args[idx], &url[idx] );
	    else if ( arg.contains("QColor") == 1 )
	        implantColor( exec, uo+1+idx, args[idx], &color[idx] );
	    else if ( arg.contains("QPoint") == 1 )
		implantPoint( exec, uo+1+idx, args[idx], &point[idx] );
	   else if ( arg.contains("QSize") == 1 )
		implantSize( exec, uo+1+idx, args[idx], &size[idx] );
	   else if ( arg.contains("QRect") == 1 )
		implantRect( exec, uo+1+idx, args[idx], &rect[idx] );
	   else if ( arg.contains("QDate") == 1 )
		implantDate( exec, uo+1+idx, args[idx], &date[idx] );
	   else if ( arg.contains("QTime") == 1 )
		implantTime( exec, uo+1+idx, args[idx], &time[idx] );
	   else if ( arg.contains("QDateTime") == 1 )
		implantDateTime( exec, uo+1+idx, args[idx], &datetime[idx] );
	   else if ( arg.contains("QPixmap") == 1 )
		implantPixmap( exec, uo+1+idx, args[idx], &pix[idx] );
	   else if ( arg.contains("char") == 1)
	        implantCharStar( exec, uo+1+idx, args[idx] );
	    else if ( ( arg.contains("QObject") == 1 ) || ( arg.contains("QWidget") == 1 ) )
	   {
	   	kdDebug( 80001 ) << "Doing a QObject" << endl;
		notsupported = !implantObjectProxy( exec, uo+1+idx, args[idx], "QObject" );
	   }
	    else if ( QVariant::nameToType(arg.latin1()) != QVariant::Invalid ) {
		bool ok = implantValueProxy( exec, uo+1+idx, args[idx], arg );
		if ( !ok ) {
		    notsupported = true;
		    break;
		}
		else
		{
			kdDebug( 80001 ) << "Implanted the variant " << static_QUType_QVariant.get(uo+1+idx).isValid() << endl;
		}
	    }
	    /* else if ( ( arg.contains("QVariant") == 1 ) ||
	        ( arg.contains("QPen") == 1 ) || (arg.contains("QFont") == 1 )  ||
		( arg.contains("QBrush") == 1 ))
		if(!implantQVariant(exec,  uo+1+idx, args[idx] )){
		    notsupported = true;
		    break;
		} */
	    else if ( arg.contains("*") == 1 ) {
		QRegExp re("(\\w+)\\*");
		if ( re.search(arg) >= 0 ) {
		    bool ok = implantObjectProxy( exec, uo+1+idx, args[idx], re.cap(1) );
		    if ( !ok ) {
			ok = implantOpaqueProxy( exec, uo+1+idx, args[idx], re.cap(1) );
			if ( !ok ) {
			    notsupported = true;
			    break;
			}
		    }
		}
		else {
		    notsupported = true;
		    break;
		}
	    }  else {
		notsupported = true;
		break; // Abort on the first unsupported parameter
	    }
        }
    }

    if ( notsupported ) {
	kdWarning(80001) << "Signature " << slotname << " has not been implemented" << endl;
	return KJS::Null();
    } else {
        kdDebug(80001) << "Call Signature: " << slotname << endl;

	obj->qt_invoke( slotid, uo );
    }
    // Handle return types
    QCString ret( proxyimp->returnType() );
    if ( ret.isEmpty() ) {
	// Basic type (void, int etc.)
	return extractValue( exec, uo );
    }

    // Object type
    kdDebug(80001) << "Handling a pointer return of type " << ret << endl;

    if ( proxy->part()->factory()->isQObject(ret) ) {
	kdDebug(80001) << "Return type is QObject " << ret << endl;
	return extractValue( exec, uo, proxy );
    }

    // Opaque type
    kdDebug(80001) << "Return type is opaque " << ret << endl;

    JSOpaqueProxy *opaque = new JSOpaqueProxy(static_QUType_ptr.get(uo), ret.data());
    //opaque->setValue(  );

    KJS::Object opaqueObj( opaque );
    opaque->addBindings( exec, opaqueObj );

    return opaqueObj;
}

} // namespace KJSEmbed::Bindings
} // namespace KJSEmbed

// Local Variables:
// c-basic-offset: 4
// End: