summaryrefslogtreecommitdiffstats
path: root/ksirc/puke/pobject.cpp
blob: 9e46e0421b33a95a471234ccf42920fe8515387a (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
#include "pobject.h"
#include "commands.h"


PObject::PObject(TQObject *pobject, const char *name) 
  : TQObject(pobject, name)
{
  // Connect slots as needed
  obj = 0;
  setWidget(0);
  manualTerm = FALSE;
  deleteAble = TRUE;
  m_hasError = false;
}

PObject::~PObject() 
{
  if(isDeleteAble())
    delete widget();
  obj = 0;
  setWidget(0);
}

PObject *PObject::createWidget(CreateArgs &ca) 
{
  PObject *pw = new PObject(ca.parent);
  TQObject *o;
  if(ca.parent != 0)
    o = new TQObject(ca.parent->widget());
  else
    o = new TQObject();
  pw->setWidget(o);
  pw->setWidgetId(ca.pwI);
  pw->setPukeController(ca.pc);
  return pw;
}

void PObject::messageHandler(int fd, PukeMessage *pm) 
{
  PukeMessage pmRet;
  if(pm->iCommand == PUKE_WIDGET_DELETE){
    /**
     * Emit the ack before the delete since we don't exist afterwards.
     */
    pmRet.iCommand = PUKE_WIDGET_DELETE_ACK;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);

    manTerm();
    delete this;
  }
  if(pm->iCommand == PUKE_RELEASEWIDGET){
    /**
     * Emit the ack before the delete since we don't exist afterwards.
     */
    pmRet.iCommand = PUKE_RELEASEWIDGET_ACK;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);

    /**
     * By setting the widget to 0 we loose the pointer and then don't delete it
     */
    setWidget(0);
    manTerm();
    delete this;
  }
  else {
    qWarning("PObject: Unkown Command: %d", pm->iCommand);
    pmRet.iCommand = PUKE_INVALID;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
  }
}

void PObject::setWidget(TQObject *_o) 
{
  // Disconnect everything from the object we where listning too
  // Just in case it fires something off, we don't want to get it
  if(widget() != 0){
    disconnect(widget(), TQT_SIGNAL(destroyed()),
               this, TQT_SLOT(swidgetDestroyed()));
  }
  
  obj = _o;
  if(obj != 0){
    connect(widget(), TQT_SIGNAL(destroyed()),
	    this, TQT_SLOT(swidgetDestroyed()));
  }
}

TQObject *PObject::widget() 
{
  //  kdDebug(5008) << "PObject widget called" << endl;
  return obj;
}

void PObject::setWidgetId(widgetId *pwI) 
{
  wI = *pwI;
  //  kdDebug(5008) << "PObject: set widget id " << wI.iWinId << endl;
}

widgetId PObject::widgetIden() 
{
  //  kdDebug(5008) << "PObject: called widget id " << wI.iWinId << endl;
  return wI;
}

void PObject::swidgetDestroyed(){ 
  setWidget(0x0);
  if(manualTerm == FALSE){
    manTerm();
    delete this;
  }
}

PukeController *PObject::controller() { 
  
  return pController;
}

void PObject::manTerm() {
  manualTerm = TRUE;
}

void PObject::errorInvalidSet(TQObject *_w)
{ 
  m_error = TQString("Tried setting a %1 to %2").arg(_w->className()).arg(className());
  m_hasError = true;
}
#include "pobject.moc"