5
Copyright (C) 2002 Luigi Genoni
11
#include <qmultilinedit.h>
13
#include <qbuttongroup.h>
23
void knetfilter::startlistRoutes() {
25
routes.clearArguments();
27
if ( system_has_tc == 1 )
29
routes << "ip" << "route" << "show";
33
routes << "route" << "-n";
36
bool success=routes.start(KProcess::NotifyOnExit,
40
statusbar->message(i18n("Running..."), 2000);
44
if ( system_has_tc == 1 )
46
statusbar->message(i18n("Couldn't start ip"), 2000);
50
statusbar->message(i18n("Couldn't start route"), 2000);
58
void knetfilter::startlistAddr() {
60
addr.clearArguments();
62
if ( system_has_tc == 1 )
64
addr << "ip" << "addr" << "show";
71
bool success=addr.start(KProcess::NotifyOnExit,
76
statusbar->message(i18n("Running..."), 2000);
80
if ( system_has_tc == 1 )
82
statusbar->message(i18n("Couldn't start ip"), 2000);
86
statusbar->message(i18n("Couldn't start route"), 2000);
94
void knetfilter::startlistrouteCache() {
96
routecache.clearArguments();
98
routecache << "route" << "-C" << "-n";
100
bool success=routecache.start(KProcess::NotifyOnExit,
101
KProcess::AllOutput);
104
statusbar->message(i18n("Running..."), 2000);
108
statusbar->message(i18n("Couldn't start route"), 2000);
113
void knetfilter::routeRules() {
114
if ( routeList == NULL )
118
routeList = new KNFWidget();
119
routeList->resize(480,320);
120
routeList->setCaption("Show Routes, IpAddrs, Route Cache");
122
QBoxLayout *top = new QBoxLayout(routeList, QBoxLayout::LeftToRight, 7);
123
QGridLayout *grid = new QGridLayout(7,5);
124
top->addLayout(grid,5);
126
routeBox = new QListBox(routeList);
127
grid->addMultiCellWidget(routeBox,0,5,0,5);
129
QPushButton *btnRoutes = new QPushButton(routeList);
130
btnRoutes->setText("Routes");
131
btnRoutes->setFixedHeight(btnRoutes->sizeHint().height());
132
connect(btnRoutes,SIGNAL(clicked()), this, SLOT(startlistRoutes()));
133
grid->addWidget(btnRoutes,7,0);
135
QPushButton *btnAddr = new QPushButton(routeList);
136
btnAddr->setText("IpAddr");
137
btnAddr->setFixedHeight(btnAddr->sizeHint().height());
138
connect(btnAddr,SIGNAL(clicked()), this, SLOT(startlistAddr()));
139
grid->addWidget(btnAddr,7,1);
141
QPushButton *btnrouteCache = new QPushButton(routeList);
142
btnrouteCache->setText("RT-cache");
143
btnrouteCache->setFixedHeight(btnrouteCache->sizeHint().height());
144
connect(btnrouteCache,SIGNAL(clicked()), this, SLOT(startlistrouteCache()));
145
grid->addWidget(btnrouteCache,7,2);
147
QPushButton *btnClose = new QPushButton(routeList);
148
btnClose->setText("Close");
149
btnClose->setFixedHeight(btnClose->sizeHint().height());
150
connect(btnClose,SIGNAL(clicked()), this, SLOT(closerouteRules()));
151
grid->addWidget(btnClose,7,5);
154
setCentralWidget(routeList);
158
if ( !routeList->isVisible() )
164
QMessageBox::critical(0,"Warning", "Already Running\n");
169
// And so we can also close everything ;)
171
void knetfilter::closerouteRules() {
178
void knetfilter::listRoutesDone() {
180
if (routes.normalExit() && (routes.exitStatus()==0))
181
statusbar->message(i18n("Listing Routes..."), 2000);
183
statusbar->message(i18n("Couldn't list Routes"), 2000);
188
void knetfilter::listAddrDone() {
190
if (addr.normalExit() && (addr.exitStatus()==0))
191
statusbar->message(i18n("Listing Ip Addresses..."), 2000);
193
statusbar->message(i18n("Couldn't list Ip Addresses"), 2000);
198
void knetfilter::listrouteCacheDone() {
200
if (routecache.normalExit() && (routecache.exitStatus()==0))
201
statusbar->message(i18n("Listing Route Cache..."), 2000);
203
statusbar->message(i18n("Couldn't list Route Chache"), 2000);
210
void knetfilter::listRoutes(KProcess *, char *data, int len) {
214
static QString remainder;
218
memmove(dst,data,len);
228
newindex=list.find('\n',index);
230
remainder=list.right(list.length()-index);
233
lines.append(list.mid(index,newindex-index));
239
routeBox->insertStrList(&lines);
242
routeBox->insertItem(remainder.data());
243
routeBox->setTopItem(routeBox->count()-routeBox->numItemsVisible());