summaryrefslogtreecommitdiffstats
path: root/ksirc/puke/pprogress.cpp
blob: 41838bca54536db5403f92e813ebd86e4ea05a9c (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
#include <stdio.h>


#include <kdebug.h>

#include "pprogress.h"

PObject *
PProgress::createWidget(CreateArgs &ca) 
{
  PProgress *pw = new PProgress(ca.tqparent);
  KSProgress *ksp;
  if(ca.tqparent != 0 && ca.tqparent->widget()->isWidgetType() == TRUE)
    ksp = new KSProgress((TQWidget *) ca.tqparent->widget());
  else
    ksp = new KSProgress();
  pw->setWidget(ksp);
  pw->setWidgetId(ca.pwI);
  return pw;
}


PProgress::PProgress( PObject *tqparent) 
  : PWidget(tqparent)
{
  //  kdDebug(5008) << "PProgress PProgress called" << endl;
  ksp = 0;
}

PProgress::~PProgress() 
{
  //  kdDebug(5008) << "PProgress: in destructor" << endl;
  /*
  delete widget(); // Delete the frame
  ksp=0;      // Set it to 0
  setWidget(ksp); // Now set all widget() calls to 0.
  */
}

void PProgress::messageHandler(int fd, PukeMessage *pm) 
{
  //  kdDebug(5008) << "PProgress handler called" << endl;
  PukeMessage pmRet;
  if(widget() == 0){
    qWarning("Null widget");
    return;
  }
  switch(pm->iCommand){
  case PUKE_KSPROGRESS_SET_RANGE:
    {
      int start=0, stop=1;
      int found = sscanf(pm->cArg, "%d\t%d", &start, &stop);
      if(found != 2)
	throw(errorCommandFailed(PUKE_INVALID,13));
      if(start >= stop){
          stop = start+1;
          start = 0;
      }
      
      widget()->setRange(start, stop);
      pmRet.iCommand = PUKE_KSPROGRESS_SET_RANGE_ACK;
      pmRet.iWinId = pm->iWinId;
      pmRet.iArg = 0;
      pmRet.cArg = 0;
      emit outputMessage(fd, &pmRet);
      break;
    }
  case PUKE_KSPROGRESS_SET_TOPTEXT:
    widget()->setTopText(TQString(pm->cArg));
    pmRet.iCommand = PUKE_KSPROGRESS_SET_TOPTEXT;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_KSPROGRESS_SET_BOTTEXT:
    widget()->setBotText(TQString(pm->cArg));
    pmRet.iCommand = PUKE_KSPROGRESS_SET_BOTTEXT;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
    break;
  case PUKE_KSPROGRESS_SET_VALUE:
    widget()->setValue(pm->iArg);
    pmRet.iCommand = PUKE_KSPROGRESS_SET_VALUE_ACK;
    pmRet.iWinId = pm->iWinId;
    pmRet.iArg = 0;
    pmRet.cArg = 0;
    emit outputMessage(fd, &pmRet);
    break;        
  default:
    PWidget::messageHandler(fd, pm);
  }
}

void PProgress::cancelPressed(){ 
  kdDebug(5008) << "Cancel Pressed" << endl;
  PukeMessage pmRet;
  pmRet.iCommand = PUKE_KSPROGRESS_CANCEL_ACK;
  pmRet.iWinId = widgetIden().iWinId;
  pmRet.iArg = 0;
  pmRet.cArg = 0;
  emit outputMessage(widgetIden().fd, &pmRet);
}

void PProgress::setWidget(TQObject *_f) 
{
  //  kdDebug(5008) << "PProgress setWidget called" << endl;
  if(_f != 0 && _f->inherits("KSProgress") == FALSE)
  {
     errorInvalidSet(_f);
     return;
  }

  ksp = (KSProgress *) _f;
  if(widget() != 0){
    connect(widget(), TQT_SIGNAL(cancel()),
            this, TQT_SLOT(cancelPressed()));
  }
  PWidget::setWidget(ksp);

}


KSProgress *PProgress::widget() 
{
  //  kdDebug(5008) << "PProgress widget called" << endl;
  return ksp;
}

#include "pprogress.moc"