Diffstat (limited to 'noncore/settings/networksettings/ppp/conwindow.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/ppp/conwindow.cpp | 243 |
1 files changed, 120 insertions, 123 deletions
diff --git a/noncore/settings/networksettings/ppp/conwindow.cpp b/noncore/settings/networksettings/ppp/conwindow.cpp index 20d705d..9136ca0 100644 --- a/noncore/settings/networksettings/ppp/conwindow.cpp +++ b/noncore/settings/networksettings/ppp/conwindow.cpp | |||
@@ -22,37 +22,34 @@ | |||
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" | 27 | //#include "docking.h" |
28 | #include "pppdata.h" | 28 | #include "pppdata.h" |
29 | // #include "pppstats.h" | 29 | // #include "pppstats.h" |
30 | // #include <klocale.h> | 30 | // #include <klocale.h> |
31 | #define i18n QObject::tr | 31 | #define i18n QObject::tr |
32 | // #include <kglobal.h> | 32 | // #include <kglobal.h> |
33 | 33 | ||
34 | extern PPPData gpppdata; | ||
35 | 34 | ||
36 | ConWindow::ConWindow(QWidget *parent, const char *name, QDialog *mainwidget ) | 35 | ConWindow::ConWindow(PPPData *pd, QWidget *parent, const char *name, |
37 | // PPPStats *st) | 36 | QDialog *mainwidget ) |
38 | : QWidget(parent, name, 0), | 37 | : QWidget(parent, name, 0), |
39 | minutes(0), | 38 | minutes(0), |
40 | seconds(0), | 39 | seconds(0), |
41 | hours(0), | 40 | hours(0), |
42 | days(0), | 41 | days(0), |
43 | tl1(0), | 42 | tl1(0), |
44 | // stats(st), | 43 | _pppdata(pd) |
45 | accountingEnabled(false), | ||
46 | volumeAccountingEnabled(false) | ||
47 | { | 44 | { |
48 | info1 = new QLabel(i18n("Connected at:"), this); | 45 | info1 = new QLabel(i18n("Connected at:"), this); |
49 | info2 = new QLabel("", this); | 46 | info2 = new QLabel("", this); |
50 | 47 | ||
51 | timelabel1 = new QLabel(i18n("Time connected:"), this); | 48 | timelabel1 = new QLabel(i18n("Time connected:"), this); |
52 | timelabel2 = new QLabel("000:00:00", this); | 49 | timelabel2 = new QLabel("000:00:00", this); |
53 | 50 | ||
54 | vollabel = new QLabel(i18n("Volume:"), this); | 51 | vollabel = new QLabel(i18n("Volume:"), this); |
55 | volinfo = new QLabel("", this); | 52 | volinfo = new QLabel("", this); |
56 | 53 | ||
57 | // now the stuff for accounting | 54 | // now the stuff for accounting |
58 | session_bill_l = new QLabel(i18n("Session Bill:"), this); | 55 | session_bill_l = new QLabel(i18n("Session Bill:"), this); |
@@ -106,185 +103,185 @@ QString ConWindow::prettyPrintVolume(unsigned int n) { | |||
106 | n /= 1024; | 103 | n /= 1024; |
107 | } | 104 | } |
108 | 105 | ||
109 | int i = idx; | 106 | int i = idx; |
110 | while(i--) | 107 | while(i--) |
111 | n1 = n1 / 1024.0; | 108 | n1 = n1 / 1024.0; |
112 | 109 | ||
113 | QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 ); | 110 | QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 ); |
114 | s += " " + quant[idx]; | 111 | s += " " + quant[idx]; |
115 | return s; | 112 | return s; |
116 | } | 113 | } |
117 | 114 | ||
118 | void ConWindow::accounting(bool on) { | 115 | // void ConWindow::accounting(bool on) { |
119 | // cache accounting settings | 116 | // // cache accounting settings |
120 | accountingEnabled = on; | 117 | // accountingEnabled = on; |
121 | volumeAccountingEnabled = PPPData::data()->VolAcctEnabled(); | 118 | // // volumeAccountingEnabled = PPPData::data()->VolAcctEnabled(); |
122 | |||
123 | // delete old layout | ||
124 | if(tl1 != 0) | ||
125 | delete tl1; | ||
126 | |||
127 | // add layout now | ||
128 | tl1 = new QVBoxLayout(this, 10, 10); | ||
129 | tl1->addSpacing(5); | ||
130 | QHBoxLayout *tl = new QHBoxLayout; | ||
131 | tl1->addLayout(tl); | ||
132 | tl->addSpacing(20); | ||
133 | QGridLayout *l1; | ||
134 | |||
135 | int vol_lines = 0; | ||
136 | if(PPPData::data()->VolAcctEnabled()) | ||
137 | vol_lines = 1; | ||
138 | |||
139 | if(accountingEnabled) | ||
140 | l1 = new QGridLayout(4 + vol_lines, 2, 5); | ||
141 | else | ||
142 | l1 = new QGridLayout(2 + vol_lines, 2, 5); | ||
143 | tl->addLayout(l1); | ||
144 | l1->setColStretch(0, 0); | ||
145 | l1->setColStretch(1, 1); | ||
146 | |||
147 | info2->setAlignment(AlignRight|AlignVCenter); | ||
148 | timelabel2->setAlignment(AlignRight|AlignVCenter); | ||
149 | session_bill->setAlignment(AlignRight|AlignVCenter); | ||
150 | total_bill->setAlignment(AlignRight|AlignVCenter); | ||
151 | volinfo->setAlignment(AlignRight|AlignVCenter); | ||
152 | // make sure that there's enough space for the bills | ||
153 | QString s1 = session_bill->text(); | ||
154 | QString s2 = total_bill->text(); | ||
155 | QString s3 = volinfo->text(); | ||
156 | |||
157 | session_bill->setText("888888.88 XXX"); | ||
158 | total_bill->setText("888888.88 XXX"); | ||
159 | volinfo->setText("8888.8 MB"); | ||
160 | session_bill->setFixedSize(session_bill->sizeHint()); | ||
161 | total_bill->setFixedSize(total_bill->sizeHint()); | ||
162 | volinfo->setFixedSize(volinfo->sizeHint()); | ||
163 | session_bill->setText(s1); | ||
164 | total_bill->setText(s2); | ||
165 | volinfo->setText(s3); | ||
166 | |||
167 | l1->addWidget(info1, 0, 0); | ||
168 | l1->addWidget(info2, 0, 1); | ||
169 | l1->addWidget(timelabel1, 1, 0); | ||
170 | l1->addWidget(timelabel2, 1, 1); | ||
171 | if(accountingEnabled) { | ||
172 | session_bill_l->show(); | ||
173 | session_bill->show(); | ||
174 | total_bill_l->show(); | ||
175 | total_bill->show(); | ||
176 | l1->addWidget(session_bill_l, 2, 0); | ||
177 | l1->addWidget(session_bill, 2, 1); | ||
178 | l1->addWidget(total_bill_l, 3, 0); | ||
179 | l1->addWidget(total_bill, 3, 1); | ||
180 | |||
181 | if(volumeAccountingEnabled) { | ||
182 | vollabel->show(); | ||
183 | volinfo->show(); | ||
184 | l1->addWidget(vollabel, 4, 0); | ||
185 | l1->addWidget(volinfo, 4, 1); | ||
186 | } else { | ||
187 | vollabel->hide(); | ||
188 | volinfo->hide(); | ||
189 | } | ||
190 | 119 | ||
191 | } else { | 120 | // // delete old layout |
192 | session_bill_l->hide(); | 121 | // if(tl1 != 0) |
193 | session_bill->hide(); | 122 | // delete tl1; |
194 | total_bill_l->hide(); | ||
195 | total_bill->hide(); | ||
196 | |||
197 | if(volumeAccountingEnabled) { | ||
198 | vollabel->show(); | ||
199 | volinfo->show(); | ||
200 | l1->addWidget(vollabel, 2, 0); | ||
201 | l1->addWidget(volinfo, 2, 1); | ||
202 | } else { | ||
203 | vollabel->hide(); | ||
204 | volinfo->hide(); | ||
205 | } | ||
206 | } | ||
207 | 123 | ||
208 | tl->addSpacing(10); | 124 | // // add layout now |
209 | QVBoxLayout *l2 = new QVBoxLayout(5); | 125 | // tl1 = new QVBoxLayout(this, 10, 10); |
210 | tl->addLayout(l2); | 126 | // tl1->addSpacing(5); |
211 | l2->addStretch(1); | 127 | // QHBoxLayout *tl = new QHBoxLayout; |
212 | // l2->addWidget(statsbutton); | 128 | // tl1->addLayout(tl); |
213 | l2->addWidget(cancelbutton); | 129 | // tl->addSpacing(20); |
130 | // QGridLayout *l1; | ||
214 | 131 | ||
215 | l2->addStretch(1); | 132 | // int vol_lines = 0; |
133 | // // if(_pppdata->VolAcctEnabled()) | ||
134 | // // vol_lines = 1; | ||
216 | 135 | ||
217 | tl1->addSpacing(5); | 136 | // if(accountingEnabled) |
137 | // l1 = new QGridLayout(4 + vol_lines, 2, 5); | ||
138 | // else | ||
139 | // l1 = new QGridLayout(2 + vol_lines, 2, 5); | ||
140 | // tl->addLayout(l1); | ||
141 | // l1->setColStretch(0, 0); | ||
142 | // l1->setColStretch(1, 1); | ||
143 | |||
144 | // info2->setAlignment(AlignRight|AlignVCenter); | ||
145 | // timelabel2->setAlignment(AlignRight|AlignVCenter); | ||
146 | // session_bill->setAlignment(AlignRight|AlignVCenter); | ||
147 | // total_bill->setAlignment(AlignRight|AlignVCenter); | ||
148 | // volinfo->setAlignment(AlignRight|AlignVCenter); | ||
149 | // // make sure that there's enough space for the bills | ||
150 | // QString s1 = session_bill->text(); | ||
151 | // QString s2 = total_bill->text(); | ||
152 | // QString s3 = volinfo->text(); | ||
153 | |||
154 | // session_bill->setText("888888.88 XXX"); | ||
155 | // total_bill->setText("888888.88 XXX"); | ||
156 | // volinfo->setText("8888.8 MB"); | ||
157 | // session_bill->setFixedSize(session_bill->sizeHint()); | ||
158 | // total_bill->setFixedSize(total_bill->sizeHint()); | ||
159 | // volinfo->setFixedSize(volinfo->sizeHint()); | ||
160 | // session_bill->setText(s1); | ||
161 | // total_bill->setText(s2); | ||
162 | // volinfo->setText(s3); | ||
163 | |||
164 | // l1->addWidget(info1, 0, 0); | ||
165 | // l1->addWidget(info2, 0, 1); | ||
166 | // l1->addWidget(timelabel1, 1, 0); | ||
167 | // l1->addWidget(timelabel2, 1, 1); | ||
168 | // if(accountingEnabled) { | ||
169 | // session_bill_l->show(); | ||
170 | // session_bill->show(); | ||
171 | // total_bill_l->show(); | ||
172 | // total_bill->show(); | ||
173 | // l1->addWidget(session_bill_l, 2, 0); | ||
174 | // l1->addWidget(session_bill, 2, 1); | ||
175 | // l1->addWidget(total_bill_l, 3, 0); | ||
176 | // l1->addWidget(total_bill, 3, 1); | ||
218 | 177 | ||
219 | setFixedSize(sizeHint()); | 178 | // if(volumeAccountingEnabled) { |
220 | /* | 179 | // vollabel->show(); |
221 | do not overwrite position read from config | 180 | // volinfo->show(); |
222 | setGeometry((QApplication::desktop()->width() - width()) / 2, | 181 | // l1->addWidget(vollabel, 4, 0); |
223 | (QApplication::desktop()->height() - height())/2, | 182 | // l1->addWidget(volinfo, 4, 1); |
224 | width(), | 183 | // } else { |
225 | height()); | 184 | // vollabel->hide(); |
226 | */ | 185 | // volinfo->hide(); |
227 | } | 186 | // } |
228 | 187 | ||
188 | // } else { | ||
189 | // session_bill_l->hide(); | ||
190 | // session_bill->hide(); | ||
191 | // total_bill_l->hide(); | ||
192 | // total_bill->hide(); | ||
229 | 193 | ||
230 | void ConWindow::dock() { | 194 | // if(volumeAccountingEnabled) { |
231 | // DockWidget::dock_widget->show(); | 195 | // vollabel->show(); |
232 | this->hide(); | 196 | // volinfo->show(); |
233 | } | 197 | // l1->addWidget(vollabel, 2, 0); |
198 | // l1->addWidget(volinfo, 2, 1); | ||
199 | // } else { | ||
200 | // vollabel->hide(); | ||
201 | // volinfo->hide(); | ||
202 | // } | ||
203 | // } | ||
204 | |||
205 | // tl->addSpacing(10); | ||
206 | // QVBoxLayout *l2 = new QVBoxLayout(5); | ||
207 | // tl->addLayout(l2); | ||
208 | // l2->addStretch(1); | ||
209 | // // l2->addWidget(statsbutton); | ||
210 | // l2->addWidget(cancelbutton); | ||
211 | |||
212 | // l2->addStretch(1); | ||
213 | |||
214 | // tl1->addSpacing(5); | ||
215 | |||
216 | // setFixedSize(sizeHint()); | ||
217 | // /* | ||
218 | // do not overwrite position read from config | ||
219 | // setGeometry((QApplication::desktop()->width() - width()) / 2, | ||
220 | // (QApplication::desktop()->height() - height())/2, | ||
221 | // width(), | ||
222 | // height()); | ||
223 | // */ | ||
224 | // } | ||
225 | |||
226 | |||
227 | // void ConWindow::dock() { | ||
228 | // // DockWidget::dock_widget->show(); | ||
229 | // this->hide(); | ||
230 | // } | ||
234 | 231 | ||
235 | 232 | ||
236 | void ConWindow::startClock() { | 233 | void ConWindow::startClock() { |
237 | minutes = 0; | 234 | minutes = 0; |
238 | seconds = 0; | 235 | seconds = 0; |
239 | hours = 0; | 236 | hours = 0; |
240 | QString title ; | 237 | QString title ; |
241 | 238 | ||
242 | title = PPPData::data()->accname(); | 239 | title = _pppdata->accname(); |
243 | 240 | ||
244 | if(PPPData::data()->get_show_clock_on_caption()){ | 241 | if(_pppdata->get_show_clock_on_caption()){ |
245 | title += " 00:00" ; | 242 | title += " 00:00" ; |
246 | } | 243 | } |
247 | this->setCaption(title); | 244 | this->setCaption(title); |
248 | 245 | ||
249 | timelabel2->setText("00:00:00"); | 246 | timelabel2->setText("00:00:00"); |
250 | clocktimer->start(1000); | 247 | clocktimer->start(1000); |
251 | } | 248 | } |
252 | 249 | ||
253 | 250 | ||
254 | void ConWindow::setConnectionSpeed(const QString &speed) { | 251 | void ConWindow::setConnectionSpeed(const QString &speed) { |
255 | info2->setText(speed); | 252 | info2->setText(speed); |
256 | } | 253 | } |
257 | 254 | ||
258 | 255 | ||
259 | void ConWindow::stopClock() { | 256 | void ConWindow::stopClock() { |
260 | clocktimer->stop(); | 257 | clocktimer->stop(); |
261 | } | 258 | } |
262 | 259 | ||
263 | 260 | ||
264 | void ConWindow::timeclick() { | 261 | void ConWindow::timeclick() { |
265 | // QString tooltip = i18n("Connection: %1\n" | 262 | // QString tooltip = i18n("Connection: %1\n" |
266 | // "Connected at: %2\n" | 263 | // "Connected at: %2\n" |
267 | // "Time connected: %3") | 264 | // "Time connected: %3") |
268 | // .arg(PPPData::data()->accname()).arg(info2->text()) | 265 | // .arg(_pppdata->accname()).arg(info2->text()) |
269 | // .arg(time_string2); | 266 | // .arg(time_string2); |
270 | 267 | ||
271 | // if(accountingEnabled) | 268 | // if(accountingEnabled) |
272 | // tooltip += i18n("\nSession Bill: %1\nTotal Bill: %2") | 269 | // tooltip += i18n("\nSession Bill: %1\nTotal Bill: %2") |
273 | // .arg(session_bill->text()).arg(total_bill->text()); | 270 | // .arg(session_bill->text()).arg(total_bill->text()); |
274 | // // volume accounting | 271 | // // volume accounting |
275 | // if(volumeAccountingEnabled) { | 272 | // if(volumeAccountingEnabled) { |
276 | 273 | ||
277 | // volinfo->setEnabled(TRUE); | 274 | // volinfo->setEnabled(TRUE); |
278 | // int bytes = PPPData::data()->totalBytes(); | 275 | // int bytes = _pppdata->totalBytes(); |
279 | // volinfo->setText(prettyPrintVolume(bytes)); | 276 | // volinfo->setText(prettyPrintVolume(bytes)); |
280 | // } | 277 | // } |
281 | 278 | ||
282 | // seconds++; | 279 | // seconds++; |
283 | 280 | ||
284 | // if(seconds >= 60 ) { | 281 | // if(seconds >= 60 ) { |
285 | // minutes ++; | 282 | // minutes ++; |
286 | // seconds = 0; | 283 | // seconds = 0; |
287 | // } | 284 | // } |
288 | 285 | ||
289 | // if (minutes >= 60){ | 286 | // if (minutes >= 60){ |
290 | // minutes = 0; | 287 | // minutes = 0; |
@@ -296,46 +293,46 @@ void ConWindow::timeclick() { | |||
296 | // hours = 0; | 293 | // hours = 0; |
297 | // } | 294 | // } |
298 | 295 | ||
299 | // time_string.sprintf("%02d:%02d",hours,minutes); | 296 | // time_string.sprintf("%02d:%02d",hours,minutes); |
300 | // time_string2 = ""; | 297 | // time_string2 = ""; |
301 | // if (days) | 298 | // if (days) |
302 | // time_string2.sprintf("%d d %02d:%02d:%02d", | 299 | // time_string2.sprintf("%d d %02d:%02d:%02d", |
303 | // days,hours,minutes,seconds); | 300 | // days,hours,minutes,seconds); |
304 | 301 | ||
305 | // else | 302 | // else |
306 | // time_string2.sprintf("%02d:%02d:%02d",hours,minutes,seconds); | 303 | // time_string2.sprintf("%02d:%02d:%02d",hours,minutes,seconds); |
307 | 304 | ||
308 | // caption_string = PPPData::data()->accname(); | 305 | // caption_string = _pppdata->accname(); |
309 | // caption_string += " "; | 306 | // caption_string += " "; |
310 | // caption_string += time_string; | 307 | // caption_string += time_string; |
311 | 308 | ||
312 | 309 | ||
313 | // timelabel2->setText(time_string2); | 310 | // timelabel2->setText(time_string2); |
314 | 311 | ||
315 | // if(PPPData::data()->get_show_clock_on_caption() && (seconds == 1)){ | 312 | // if(_pppdata->get_show_clock_on_caption() && (seconds == 1)){ |
316 | // // we update the Caption only once per minute not every second | 313 | // // we update the Caption only once per minute not every second |
317 | // // otherwise I get a flickering icon | 314 | // // otherwise I get a flickering icon |
318 | // this->setCaption(caption_string); | 315 | // this->setCaption(caption_string); |
319 | // } | 316 | // } |
320 | 317 | ||
321 | // QToolTip::add(DockWidget::dock_widget, tooltip); | 318 | // QToolTip::add(DockWidget::dock_widget, tooltip); |
322 | } | 319 | } |
323 | 320 | ||
324 | 321 | ||
325 | void ConWindow::closeEvent( QCloseEvent *e ){ | 322 | void ConWindow::closeEvent( QCloseEvent *e ){ |
326 | // we don't want to lose the | 323 | // we don't want to lose the |
327 | // conwindow since this is our last connection kppp. | 324 | // conwindow since this is our last connection kppp. |
328 | // if we lost it we could only kill the program by hand to get on with life. | 325 | // if we lost it we could only kill the program by hand to get on with life. |
329 | e->ignore(); | 326 | e->ignore(); |
330 | 327 | ||
331 | if(PPPData::data()->get_dock_into_panel()) | 328 | // if(_pppdata->get_dock_into_panel()) |
332 | dock(); | 329 | // dock(); |
333 | } | 330 | } |
334 | 331 | ||
335 | 332 | ||
336 | void ConWindow::slotAccounting(QString total, QString session) { | 333 | void ConWindow::slotAccounting(QString total, QString session) { |
337 | total_bill->setText(total); | 334 | total_bill->setText(total); |
338 | session_bill->setText(session); | 335 | session_bill->setText(session); |
339 | } | 336 | } |
340 | 337 | ||
341 | 338 | ||