summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/ppp/conwindow.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/ppp/conwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/conwindow.cpp27
1 files changed, 11 insertions, 16 deletions
diff --git a/noncore/settings/networksettings/ppp/conwindow.cpp b/noncore/settings/networksettings/ppp/conwindow.cpp
index 9136ca0..7641bbe 100644
--- a/noncore/settings/networksettings/ppp/conwindow.cpp
+++ b/noncore/settings/networksettings/ppp/conwindow.cpp
@@ -1,338 +1,333 @@
1/* 1/*
2 * kPPP: A pppd front end for the KDE project 2 * kPPP: A pppd front end for the KDE project
3 * 3 *
4 * $Id$ 4 * $Id$
5 * 5 *
6 * Copyright (C) 1997 Bernd Johannes Wuebben 6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu 7 * wuebben@math.cornell.edu
8 * 8 *
9 * This program is free software; you can redistribute it and/or 9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either 11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version. 12 * version 2 of the License, or (at your option) any later version.
13 * 13 *
14 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details. 17 * Library General Public License for more details.
18 * 18 *
19 * You should have received a copy of the GNU Library General Public 19 * You should have received a copy of the GNU Library General Public
20 * License along with this program; if not, write to the Free 20 * License along with this program; if not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 22 */
23 23
24#include <qtooltip.h> 24#include <qtooltip.h>
25#include <qdialog.h> 25#include <qdialog.h>
26#include "conwindow.h" 26#include "conwindow.h"
27//#include "docking.h"
28#include "pppdata.h" 27#include "pppdata.h"
29// #include "pppstats.h"
30// #include <klocale.h>
31#define i18n QObject::tr
32// #include <kglobal.h>
33 28
34 29
35ConWindow::ConWindow(PPPData *pd, QWidget *parent, const char *name, 30ConWindow::ConWindow(PPPData *pd, QWidget *parent, const char *name,
36 QDialog *mainwidget ) 31 QDialog *mainwidget )
37 : QWidget(parent, name, 0), 32 : QWidget(parent, name, 0),
38 minutes(0), 33 minutes(0),
39 seconds(0), 34 seconds(0),
40 hours(0), 35 hours(0),
41 days(0), 36 days(0),
42 tl1(0), 37 tl1(0),
43 _pppdata(pd) 38 _pppdata(pd)
44{ 39{
45 info1 = new QLabel(i18n("Connected at:"), this); 40 info1 = new QLabel(QObject::tr("Connected at:"), this);
46 info2 = new QLabel("", this); 41 info2 = new QLabel("", this);
47 42
48 timelabel1 = new QLabel(i18n("Time connected:"), this); 43 timelabel1 = new QLabel(QObject::tr("Time connected:"), this);
49 timelabel2 = new QLabel("000:00:00", this); 44 timelabel2 = new QLabel("000:00:00", this);
50 45
51 vollabel = new QLabel(i18n("Volume:"), this); 46 vollabel = new QLabel(QObject::tr("Volume:"), this);
52 volinfo = new QLabel("", this); 47 volinfo = new QLabel("", this);
53 48
54 // now the stuff for accounting 49 // now the stuff for accounting
55 session_bill_l = new QLabel(i18n("Session Bill:"), this); 50 session_bill_l = new QLabel(QObject::tr("Session Bill:"), this);
56 session_bill = new QLabel("", this); 51 session_bill = new QLabel("", this);
57 total_bill_l = new QLabel(i18n("Total Bill:"), this); 52 total_bill_l = new QLabel(QObject::tr("Total Bill:"), this);
58 total_bill = new QLabel("", this); 53 total_bill = new QLabel("", this);
59 54
60 this->setCaption("kppp"); 55 this->setCaption("kppp");
61 56
62 cancelbutton = new QPushButton(this); 57 cancelbutton = new QPushButton(this);
63 cancelbutton->setText(i18n("Disconnect")); 58 cancelbutton->setText(QObject::tr("Disconnect"));
64 connect(cancelbutton, SIGNAL(clicked()), mainwidget, SLOT(disconnect())); 59 connect(cancelbutton, SIGNAL(clicked()), mainwidget, SLOT(disconnect()));
65 60
66 // statsbutton = new QPushButton(this); 61 // statsbutton = new QPushButton(this);
67// statsbutton->setText(i18n("Details")); 62// statsbutton->setText(QObject::tr("Details"));
68// statsbutton->setFocus(); 63// statsbutton->setFocus();
69// connect(statsbutton, SIGNAL(clicked()), mainwidget, SLOT(showStats())); 64// connect(statsbutton, SIGNAL(clicked()), mainwidget, SLOT(showStats()));
70 65
71 clocktimer = new QTimer(this); 66 clocktimer = new QTimer(this);
72 connect(clocktimer, SIGNAL(timeout()), SLOT(timeclick())); 67 connect(clocktimer, SIGNAL(timeout()), SLOT(timeclick()));
73 68
74 // read window position from config file 69 // read window position from config file
75// int p_x, p_y; 70// int p_x, p_y;
76// PPPData::data()->winPosConWin(p_x, p_y); 71// PPPData::data()->winPosConWin(p_x, p_y);
77// setGeometry(p_x, p_y, 320, 110); 72// setGeometry(p_x, p_y, 320, 110);
78} 73}
79 74
80ConWindow::~ConWindow() { 75ConWindow::~ConWindow() {
81 stopClock(); 76 stopClock();
82} 77}
83 78
84// save window position when window was closed 79// save window position when window was closed
85bool ConWindow::event(QEvent *e) { 80bool ConWindow::event(QEvent *e) {
86 if (e->type() == QEvent::Hide) 81 if (e->type() == QEvent::Hide)
87 { 82 {
88// PPPData::data()->setWinPosConWin(x(), y()); 83// PPPData::data()->setWinPosConWin(x(), y());
89 return true; 84 return true;
90 } 85 }
91 else 86 else
92 return QWidget::event(e); 87 return QWidget::event(e);
93} 88}
94 89
95QString ConWindow::prettyPrintVolume(unsigned int n) { 90QString ConWindow::prettyPrintVolume(unsigned int n) {
96 int idx = 0; 91 int idx = 0;
97 const QString quant[] = {i18n("Byte"), i18n("KB"), 92 const QString quant[] = {QObject::tr("Byte"), QObject::tr("KB"),
98 i18n("MB"), i18n("GB"), QString::null}; 93 QObject::tr("MB"), QObject::tr("GB"), QString::null};
99 94
100 float n1 = n; 95 float n1 = n;
101 while(n >= 1024 && quant[idx] != QString::null) { 96 while(n >= 1024 && quant[idx] != QString::null) {
102 idx++; 97 idx++;
103 n /= 1024; 98 n /= 1024;
104 } 99 }
105 100
106 int i = idx; 101 int i = idx;
107 while(i--) 102 while(i--)
108 n1 = n1 / 1024.0; 103 n1 = n1 / 1024.0;
109 104
110 QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 ); 105 QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 );
111 s += " " + quant[idx]; 106 s += " " + quant[idx];
112 return s; 107 return s;
113} 108}
114 109
115// void ConWindow::accounting(bool on) { 110// void ConWindow::accounting(bool on) {
116// // cache accounting settings 111// // cache accounting settings
117// accountingEnabled = on; 112// accountingEnabled = on;
118// // volumeAccountingEnabled = PPPData::data()->VolAcctEnabled(); 113// // volumeAccountingEnabled = PPPData::data()->VolAcctEnabled();
119 114
120// // delete old layout 115// // delete old layout
121// if(tl1 != 0) 116// if(tl1 != 0)
122// delete tl1; 117// delete tl1;
123 118
124// // add layout now 119// // add layout now
125// tl1 = new QVBoxLayout(this, 10, 10); 120// tl1 = new QVBoxLayout(this, 10, 10);
126// tl1->addSpacing(5); 121// tl1->addSpacing(5);
127// QHBoxLayout *tl = new QHBoxLayout; 122// QHBoxLayout *tl = new QHBoxLayout;
128// tl1->addLayout(tl); 123// tl1->addLayout(tl);
129// tl->addSpacing(20); 124// tl->addSpacing(20);
130// QGridLayout *l1; 125// QGridLayout *l1;
131 126
132// int vol_lines = 0; 127// int vol_lines = 0;
133// // if(_pppdata->VolAcctEnabled()) 128// // if(_pppdata->VolAcctEnabled())
134// // vol_lines = 1; 129// // vol_lines = 1;
135 130
136// if(accountingEnabled) 131// if(accountingEnabled)
137// l1 = new QGridLayout(4 + vol_lines, 2, 5); 132// l1 = new QGridLayout(4 + vol_lines, 2, 5);
138// else 133// else
139// l1 = new QGridLayout(2 + vol_lines, 2, 5); 134// l1 = new QGridLayout(2 + vol_lines, 2, 5);
140// tl->addLayout(l1); 135// tl->addLayout(l1);
141// l1->setColStretch(0, 0); 136// l1->setColStretch(0, 0);
142// l1->setColStretch(1, 1); 137// l1->setColStretch(1, 1);
143 138
144// info2->setAlignment(AlignRight|AlignVCenter); 139// info2->setAlignment(AlignRight|AlignVCenter);
145// timelabel2->setAlignment(AlignRight|AlignVCenter); 140// timelabel2->setAlignment(AlignRight|AlignVCenter);
146// session_bill->setAlignment(AlignRight|AlignVCenter); 141// session_bill->setAlignment(AlignRight|AlignVCenter);
147// total_bill->setAlignment(AlignRight|AlignVCenter); 142// total_bill->setAlignment(AlignRight|AlignVCenter);
148// volinfo->setAlignment(AlignRight|AlignVCenter); 143// volinfo->setAlignment(AlignRight|AlignVCenter);
149// // make sure that there's enough space for the bills 144// // make sure that there's enough space for the bills
150// QString s1 = session_bill->text(); 145// QString s1 = session_bill->text();
151// QString s2 = total_bill->text(); 146// QString s2 = total_bill->text();
152// QString s3 = volinfo->text(); 147// QString s3 = volinfo->text();
153 148
154// session_bill->setText("888888.88 XXX"); 149// session_bill->setText("888888.88 XXX");
155// total_bill->setText("888888.88 XXX"); 150// total_bill->setText("888888.88 XXX");
156// volinfo->setText("8888.8 MB"); 151// volinfo->setText("8888.8 MB");
157// session_bill->setFixedSize(session_bill->sizeHint()); 152// session_bill->setFixedSize(session_bill->sizeHint());
158// total_bill->setFixedSize(total_bill->sizeHint()); 153// total_bill->setFixedSize(total_bill->sizeHint());
159// volinfo->setFixedSize(volinfo->sizeHint()); 154// volinfo->setFixedSize(volinfo->sizeHint());
160// session_bill->setText(s1); 155// session_bill->setText(s1);
161// total_bill->setText(s2); 156// total_bill->setText(s2);
162// volinfo->setText(s3); 157// volinfo->setText(s3);
163 158
164// l1->addWidget(info1, 0, 0); 159// l1->addWidget(info1, 0, 0);
165// l1->addWidget(info2, 0, 1); 160// l1->addWidget(info2, 0, 1);
166// l1->addWidget(timelabel1, 1, 0); 161// l1->addWidget(timelabel1, 1, 0);
167// l1->addWidget(timelabel2, 1, 1); 162// l1->addWidget(timelabel2, 1, 1);
168// if(accountingEnabled) { 163// if(accountingEnabled) {
169// session_bill_l->show(); 164// session_bill_l->show();
170// session_bill->show(); 165// session_bill->show();
171// total_bill_l->show(); 166// total_bill_l->show();
172// total_bill->show(); 167// total_bill->show();
173// l1->addWidget(session_bill_l, 2, 0); 168// l1->addWidget(session_bill_l, 2, 0);
174// l1->addWidget(session_bill, 2, 1); 169// l1->addWidget(session_bill, 2, 1);
175// l1->addWidget(total_bill_l, 3, 0); 170// l1->addWidget(total_bill_l, 3, 0);
176// l1->addWidget(total_bill, 3, 1); 171// l1->addWidget(total_bill, 3, 1);
177 172
178// if(volumeAccountingEnabled) { 173// if(volumeAccountingEnabled) {
179// vollabel->show(); 174// vollabel->show();
180// volinfo->show(); 175// volinfo->show();
181// l1->addWidget(vollabel, 4, 0); 176// l1->addWidget(vollabel, 4, 0);
182// l1->addWidget(volinfo, 4, 1); 177// l1->addWidget(volinfo, 4, 1);
183// } else { 178// } else {
184// vollabel->hide(); 179// vollabel->hide();
185// volinfo->hide(); 180// volinfo->hide();
186// } 181// }
187 182
188// } else { 183// } else {
189// session_bill_l->hide(); 184// session_bill_l->hide();
190// session_bill->hide(); 185// session_bill->hide();
191// total_bill_l->hide(); 186// total_bill_l->hide();
192// total_bill->hide(); 187// total_bill->hide();
193 188
194// if(volumeAccountingEnabled) { 189// if(volumeAccountingEnabled) {
195// vollabel->show(); 190// vollabel->show();
196// volinfo->show(); 191// volinfo->show();
197// l1->addWidget(vollabel, 2, 0); 192// l1->addWidget(vollabel, 2, 0);
198// l1->addWidget(volinfo, 2, 1); 193// l1->addWidget(volinfo, 2, 1);
199// } else { 194// } else {
200// vollabel->hide(); 195// vollabel->hide();
201// volinfo->hide(); 196// volinfo->hide();
202// } 197// }
203// } 198// }
204 199
205// tl->addSpacing(10); 200// tl->addSpacing(10);
206// QVBoxLayout *l2 = new QVBoxLayout(5); 201// QVBoxLayout *l2 = new QVBoxLayout(5);
207// tl->addLayout(l2); 202// tl->addLayout(l2);
208// l2->addStretch(1); 203// l2->addStretch(1);
209// // l2->addWidget(statsbutton); 204// // l2->addWidget(statsbutton);
210// l2->addWidget(cancelbutton); 205// l2->addWidget(cancelbutton);
211 206
212// l2->addStretch(1); 207// l2->addStretch(1);
213 208
214// tl1->addSpacing(5); 209// tl1->addSpacing(5);
215 210
216// setFixedSize(sizeHint()); 211// setFixedSize(sizeHint());
217// /* 212// /*
218// do not overwrite position read from config 213// do not overwrite position read from config
219// setGeometry((QApplication::desktop()->width() - width()) / 2, 214// setGeometry((QApplication::desktop()->width() - width()) / 2,
220 // (QApplication::desktop()->height() - height())/2, 215 // (QApplication::desktop()->height() - height())/2,
221 // width(), 216 // width(),
222 // height()); 217 // height());
223// */ 218// */
224// } 219// }
225 220
226 221
227// void ConWindow::dock() { 222// void ConWindow::dock() {
228// // DockWidget::dock_widget->show(); 223// // DockWidget::dock_widget->show();
229// this->hide(); 224// this->hide();
230// } 225// }
231 226
232 227
233void ConWindow::startClock() { 228void ConWindow::startClock() {
234 minutes = 0; 229 minutes = 0;
235 seconds = 0; 230 seconds = 0;
236 hours = 0; 231 hours = 0;
237 QString title ; 232 QString title ;
238 233
239 title = _pppdata->accname(); 234 title = _pppdata->accname();
240 235
241 if(_pppdata->get_show_clock_on_caption()){ 236 if(_pppdata->get_show_clock_on_caption()){
242 title += " 00:00" ; 237 title += " 00:00" ;
243 } 238 }
244 this->setCaption(title); 239 this->setCaption(title);
245 240
246 timelabel2->setText("00:00:00"); 241 timelabel2->setText("00:00:00");
247 clocktimer->start(1000); 242 clocktimer->start(1000);
248} 243}
249 244
250 245
251void ConWindow::setConnectionSpeed(const QString &speed) { 246void ConWindow::setConnectionSpeed(const QString &speed) {
252 info2->setText(speed); 247 info2->setText(speed);
253} 248}
254 249
255 250
256void ConWindow::stopClock() { 251void ConWindow::stopClock() {
257 clocktimer->stop(); 252 clocktimer->stop();
258} 253}
259 254
260 255
261void ConWindow::timeclick() { 256void ConWindow::timeclick() {
262// QString tooltip = i18n("Connection: %1\n" 257// QString tooltip = QObject::tr("Connection: %1\n"
263 // "Connected at: %2\n" 258 // "Connected at: %2\n"
264 // "Time connected: %3") 259 // "Time connected: %3")
265 // .arg(_pppdata->accname()).arg(info2->text()) 260 // .arg(_pppdata->accname()).arg(info2->text())
266 // .arg(time_string2); 261 // .arg(time_string2);
267 262
268// if(accountingEnabled) 263// if(accountingEnabled)
269// tooltip += i18n("\nSession Bill: %1\nTotal Bill: %2") 264// tooltip += QObject::tr("\nSession Bill: %1\nTotal Bill: %2")
270 // .arg(session_bill->text()).arg(total_bill->text()); 265 // .arg(session_bill->text()).arg(total_bill->text());
271// // volume accounting 266// // volume accounting
272// if(volumeAccountingEnabled) { 267// if(volumeAccountingEnabled) {
273 268
274// volinfo->setEnabled(TRUE); 269// volinfo->setEnabled(TRUE);
275// int bytes = _pppdata->totalBytes(); 270// int bytes = _pppdata->totalBytes();
276// volinfo->setText(prettyPrintVolume(bytes)); 271// volinfo->setText(prettyPrintVolume(bytes));
277// } 272// }
278 273
279// seconds++; 274// seconds++;
280 275
281// if(seconds >= 60 ) { 276// if(seconds >= 60 ) {
282// minutes ++; 277// minutes ++;
283// seconds = 0; 278// seconds = 0;
284// } 279// }
285 280
286// if (minutes >= 60){ 281// if (minutes >= 60){
287// minutes = 0; 282// minutes = 0;
288// hours ++; 283// hours ++;
289// } 284// }
290 285
291// if( hours >= 24){ 286// if( hours >= 24){
292// days ++; 287// days ++;
293// hours = 0; 288// hours = 0;
294// } 289// }
295 290
296// time_string.sprintf("%02d:%02d",hours,minutes); 291// time_string.sprintf("%02d:%02d",hours,minutes);
297// time_string2 = ""; 292// time_string2 = "";
298// if (days) 293// if (days)
299// time_string2.sprintf("%d d %02d:%02d:%02d", 294// time_string2.sprintf("%d d %02d:%02d:%02d",
300 // days,hours,minutes,seconds); 295 // days,hours,minutes,seconds);
301 296
302// else 297// else
303// time_string2.sprintf("%02d:%02d:%02d",hours,minutes,seconds); 298// time_string2.sprintf("%02d:%02d:%02d",hours,minutes,seconds);
304 299
305// caption_string = _pppdata->accname(); 300// caption_string = _pppdata->accname();
306// caption_string += " "; 301// caption_string += " ";
307// caption_string += time_string; 302// caption_string += time_string;
308 303
309 304
310// timelabel2->setText(time_string2); 305// timelabel2->setText(time_string2);
311 306
312// if(_pppdata->get_show_clock_on_caption() && (seconds == 1)){ 307// if(_pppdata->get_show_clock_on_caption() && (seconds == 1)){
313// // we update the Caption only once per minute not every second 308// // we update the Caption only once per minute not every second
314// // otherwise I get a flickering icon 309// // otherwise I get a flickering icon
315// this->setCaption(caption_string); 310// this->setCaption(caption_string);
316// } 311// }
317 312
318// QToolTip::add(DockWidget::dock_widget, tooltip); 313// QToolTip::add(DockWidget::dock_widget, tooltip);
319} 314}
320 315
321 316
322void ConWindow::closeEvent( QCloseEvent *e ){ 317void ConWindow::closeEvent( QCloseEvent *e ){
323 // we don't want to lose the 318 // we don't want to lose the
324 // conwindow since this is our last connection kppp. 319 // conwindow since this is our last connection kppp.
325 // if we lost it we could only kill the program by hand to get on with life. 320 // if we lost it we could only kill the program by hand to get on with life.
326 e->ignore(); 321 e->ignore();
327 322
328// if(_pppdata->get_dock_into_panel()) 323// if(_pppdata->get_dock_into_panel())
329// dock(); 324// dock();
330} 325}
331 326
332 327
333void ConWindow::slotAccounting(QString total, QString session) { 328void ConWindow::slotAccounting(QString total, QString session) {
334 total_bill->setText(total); 329 total_bill->setText(total);
335 session_bill->setText(session); 330 session_bill->setText(session);
336} 331}
337 332
338 333