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
|
//
// C++ Implementation:
//
// Description:
//
//
// Author: Jean-Michel PETIT <[email protected]>, (C) 2007
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include "k9processlist.h"
#include <tqstyle.h>
#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqlistview.h>
#include <tqrect.h>
#include <tqprogressbar.h>
#include <tqpixmap.h>
#include <tqapplication.h>
#include <tqeventloop.h>
#include <kpushbutton.h>
class _k9ProcessListItem : public TQListViewItem {
public:
_k9ProcessListItem(TQListView *_listview,const TQString & _text):TQListViewItem(_listview,_text) {
m_fileName="";
m_pos=0;
m_num=_listview->childCount();
}
void setFileName(const TQString &_fileName) { m_fileName=_fileName;}
void setPos(double _pos) { m_pos=_pos;}
TQString getFileName() const { return m_fileName;}
double getPos() const { return m_pos;}
int compare ( TQListViewItem * i, int col, bool ascending ) const {
return m_num-((_k9ProcessListItem*)i)->m_num;
}
private:
TQString m_fileName;
double m_pos;
int m_num;
};
k9ProcessList::k9ProcessList(TQWidget* parent, const char* name, WFlags fl) : processList(parent,name,fl)
{
m_processes.setAutoDelete(true);
m_maxProcess=4;
connect(&m_timer,TQT_SIGNAL(timeout()),this,TQT_SLOT(timeout()));
bCancel->setEnabled(false);
}
k9ProcessList::~k9ProcessList()
{
}
/*$SPECIALIZATION$*/
void k9ProcessList::timeout() {
if (m_waitSync) {
TQApplication::eventLoop()->exitLoop();
m_waitSync=false;
}
}
void k9ProcessList::bCancelClick() {
m_cancel=true;
for (k9Process *p=m_processes.first();p;p=m_processes.next()) {
if (p->isRunning())
p->kill();
}
}
void k9ProcessList::wait(int _msec) {
m_waitSync=true;
m_timer.start(_msec,true);
TQApplication::eventLoop()->enterLoop();
}
int k9ProcessList::getNbRunning() {
int res=0;
for (int i=0;i<m_processes.count();i++) {
k9Process *p=m_processes.at(i);
if (p->isRunning())
res++;
}
return res;
}
void k9ProcessList::execute() {
bCancel->setEnabled(true);
m_cancel=false;
m_error=false;
k9Process *p=NULL;
for (TQPtrListStdIterator <k9Process> it=m_processes.begin() ;it!=m_processes.end() ;++it ) {
p=(*it);
while (getNbRunning() >=m_maxProcess && ! m_cancel) {
wait(1000);
}
if (m_cancel)
break;
if (!p->start(TDEProcess::OwnGroup,TDEProcess::All))
m_error=true;
}
//waiting for processes
for (p=m_processes.first();p;p=m_processes.next()) {
if (p->isRunning())
p->sync();
}
bCancel->setEnabled(false);
}
void k9ProcessList::addProgress(const TQString &_text) {
TQListViewItem *item = new _k9ProcessListItem(lProcess,_text);
TQProgressBar b(this);
b.setProgress(100,100);
b.resize(100,40);
item->setPixmap(0,TQPixmap::grabWidget(&b,0,0,b.width(),b.height()));
}
void k9ProcessList::setProgress (k9Process * _process,int _position, int _total) {
TQProgressBar b(this);
b.setProgress(_position,_total);
b.resize(100,40);
TQListViewItem *it =m_items[_process];
it->setPixmap(0,TQPixmap::grabWidget(&b,0,0,b.width(),b.height()));
}
void k9ProcessList::setText(k9Process *_process, const TQString &_text,int _col) {
TQListViewItem *it =m_items[_process];
it->setText(_col,_text);
}
void k9ProcessList::setFileName(k9Process *_process,const TQString &_fileName) {
_k9ProcessListItem *it = (_k9ProcessListItem*)m_items[_process];
it->setFileName(_fileName);
}
void k9ProcessList::setPos(k9Process *_process,double _pos) {
_k9ProcessListItem *it = (_k9ProcessListItem*)m_items[_process];
it->setPos(_pos);
}
k9Process *k9ProcessList::addProcess(const TQString &label) {
TQString name=TQString("process%1").arg(m_items.count()) ;
k9Process *process=new k9Process(TQT_TQOBJECT(this),name.latin1());
m_processes.append(process);
TQListViewItem *item = new _k9ProcessListItem(lProcess,label);
m_items[process]=item;
setProgress(process,0,100);
connect(process,TQT_SIGNAL(processExited( TDEProcess* )),this,TQT_SLOT(processExited(TDEProcess*)));
return process;
}
void k9ProcessList::processExited(TDEProcess *_process){
if (!_process->normalExit())
m_cancel=true;
else if (_process->exitStatus() !=0 )
m_error=true;
}
#include "k9processlist.moc"
void k9ProcessList::clear() {
m_processes.clear();
m_items.clear();
}
int k9ProcessList::getMaxProcess() const {
return m_maxProcess;
}
void k9ProcessList::setMaxProcess(int _value) {
m_maxProcess = _value;
}
bool k9ProcessList::getCancel() const {
return m_cancel;
}
bool k9ProcessList::getError() const {
return m_error;
}
|