summaryrefslogtreecommitdiffstats
path: root/kommander/widget/invokeclass.cpp
blob: ec08dfff36e5f4909a4269bdf2207c48d474a41d (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
//
// C++ Interface: invokeclass
//
// Description: 
//
//
// Author: Andras Mantia <amantia@kde.org>, (C) 2008
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "invokeclass.h"

#include <tqcolor.h>
#include <tqregexp.h>

InvokeClass::InvokeClass(TQObject *tqparent):TQObject(tqparent)
{
  m_acceptedSlots = acceptedSlots();
}

void InvokeClass::invokeSlot(TQObject *object, const TQString& slot, TQStringList args)
{
  TQString invokeName = slot;
  invokeName = invokeName.mid(invokeName.tqfind('('));
  invokeName.prepend(TQString::number(TQSIGNAL_CODE) + "invoke");
  TQString slotName = TQString::number(TQSLOT_CODE) + slot;  
  connect(this, invokeName.ascii(), object, slotName.ascii());

  if (args.count() == 0)  
    emit invoke();
  else
  {
    TQString slotArgStr = slot.section(TQRegExp("\\(|\\)"), 1);
    uint argNum = slotArgStr.tqcontains(',') + 1;
    for (uint i = args.count(); i < argNum; i++)
      args << "";
  //poor man's invokeMetaObject
    if (slotArgStr == m_acceptedSlots[0])
      emit invoke(args[0]);
    else if (slotArgStr == m_acceptedSlots[1])
      emit invoke(args[0], args[1]);
    else if (slotArgStr == m_acceptedSlots[2])
      emit invoke(args[0].upper()=="TRUE" || args[0] =="1"? true : false);
    else if (slotArgStr == m_acceptedSlots[3])
      emit invoke(args[0].toInt());
    else if (slotArgStr == m_acceptedSlots[4])
      emit invoke(args[0].toInt(), args[1].toInt());
    else if (slotArgStr == m_acceptedSlots[5])
      emit invoke(args[0].toInt(), args[1].toInt(), args[2].toInt());
    else if (slotArgStr == m_acceptedSlots[6])
      emit invoke(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt());
    else if (slotArgStr == m_acceptedSlots[7])
      emit invoke(TQColor(args[0]));
  }
    
  disconnect(this, invokeName.ascii(), object, slotName.ascii());
}

#include "invokeclass.moc"