2 * kPPP: A pppd front end for the KDE project
6 * Copyright (C) 1997 Bernd Johannes Wuebben
7 * wuebben@math.cornell.edu
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
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
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include <QVBoxLayout>
28 #include <QHBoxLayout>
29 #include <QGridLayout>
31 #include <QCloseEvent>
32 #include "conwindow.h"
39 extern PPPData gpppdata
;
41 ConWindow::ConWindow(QWidget
*parent
, const char *name
, QWidget
*mainwidget
,
50 accountingEnabled(false),
51 volumeAccountingEnabled(false)
54 info1
= new QLabel(i18n("Connected at:"), this);
55 info2
= new QLabel("", this);
57 timelabel1
= new QLabel(i18n("Time connected:"), this);
58 timelabel2
= new QLabel("000:00:00", this);
60 vollabel
= new QLabel(i18n("Volume:"), this);
61 volinfo
= new QLabel("", this);
63 // now the stuff for accounting
64 session_bill_l
= new QLabel(i18n("Session bill:"), this);
65 session_bill
= new QLabel("", this);
66 total_bill_l
= new QLabel(i18n("Total bill:"), this);
67 total_bill
= new QLabel("", this);
69 setWindowTitle("kppp");
71 cancelbutton
= new QPushButton(this);
72 cancelbutton
->setText(i18n("&Disconnect"));
73 connect(cancelbutton
, SIGNAL(clicked()), mainwidget
, SLOT(disconnect()));
75 statsbutton
= new QPushButton(this);
76 statsbutton
->setText(i18n("De&tails"));
77 statsbutton
->setFocus();
78 connect(statsbutton
, SIGNAL(clicked()), mainwidget
, SLOT(showStats()));
80 clocktimer
= new QTimer(this);
81 connect(clocktimer
, SIGNAL(timeout()), SLOT(timeclick()));
83 // read window position from config file
85 gpppdata
.winPosConWin(p_x
, p_y
);
86 setGeometry(p_x
, p_y
, 320, 110);
89 ConWindow::~ConWindow() {
93 // save window position when window was closed
94 bool ConWindow::event(QEvent
*e
) {
95 if (e
->type() == QEvent::Hide
)
97 gpppdata
.setWinPosConWin(x(), y());
101 return QWidget::event(e
);
104 QString
ConWindow::prettyPrintVolume(unsigned int n
) {
106 const QString quant
[] = {i18n("Byte"), i18n("KiB"),
107 i18n("MiB"), i18n("GiB"), QString()};
110 while(n
>= 1024 && !quant
[idx
].isNull()) {
119 QString s
= KGlobal::locale()->formatNumber( n1
, idx
==0 ? 0 : 1 );
120 s
+= ' ' + quant
[idx
];
124 void ConWindow::accounting(bool on
) {
125 // cache accounting settings
126 accountingEnabled
= on
;
127 volumeAccountingEnabled
= gpppdata
.VolAcctEnabled();
134 tl1
= new QVBoxLayout(this);
138 QHBoxLayout
*tl
= new QHBoxLayout
;
144 if(gpppdata
.VolAcctEnabled())
147 l1
= new QGridLayout();
150 l1
->setColumnStretch(0, 0);
151 l1
->setColumnStretch(1, 1);
153 info2
->setAlignment(Qt::AlignRight
|Qt::AlignVCenter
);
154 timelabel2
->setAlignment(Qt::AlignRight
|Qt::AlignVCenter
);
155 session_bill
->setAlignment(Qt::AlignRight
|Qt::AlignVCenter
);
156 total_bill
->setAlignment(Qt::AlignRight
|Qt::AlignVCenter
);
157 volinfo
->setAlignment(Qt::AlignRight
|Qt::AlignVCenter
);
158 // make sure that there's enough space for the bills
159 QString s1
= session_bill
->text();
160 QString s2
= total_bill
->text();
161 QString s3
= volinfo
->text();
163 session_bill
->setText("888888.88 XXX");
164 total_bill
->setText("888888.88 XXX");
165 volinfo
->setText("8888.8 MB");
166 session_bill
->setFixedSize(session_bill
->sizeHint());
167 total_bill
->setFixedSize(total_bill
->sizeHint());
168 volinfo
->setFixedSize(volinfo
->sizeHint());
169 session_bill
->setText(s1
);
170 total_bill
->setText(s2
);
171 volinfo
->setText(s3
);
173 l1
->addWidget(info1
, 0, 0);
174 l1
->addWidget(info2
, 0, 1);
175 l1
->addWidget(timelabel1
, 1, 0);
176 l1
->addWidget(timelabel2
, 1, 1);
177 if(accountingEnabled
) {
178 session_bill_l
->show();
179 session_bill
->show();
180 total_bill_l
->show();
182 l1
->addWidget(session_bill_l
, 2, 0);
183 l1
->addWidget(session_bill
, 2, 1);
184 l1
->addWidget(total_bill_l
, 3, 0);
185 l1
->addWidget(total_bill
, 3, 1);
187 if(volumeAccountingEnabled
) {
190 l1
->addWidget(vollabel
, 4, 0);
191 l1
->addWidget(volinfo
, 4, 1);
198 session_bill_l
->hide();
199 session_bill
->hide();
200 total_bill_l
->hide();
203 if(volumeAccountingEnabled
) {
206 l1
->addWidget(vollabel
, 2, 0);
207 l1
->addWidget(volinfo
, 2, 1);
215 QVBoxLayout
*l2
= new QVBoxLayout();
219 l2
->addWidget(statsbutton
);
220 l2
->addWidget(cancelbutton
);
226 setFixedSize(sizeHint());
228 do not overwrite position read from config
229 // If this gets re-enabled, fix it for Xinerama before committing to CVS.
230 setGeometry((QApplication::desktop()->width() - width()) / 2,
231 (QApplication::desktop()->height() - height())/2,
238 void ConWindow::dock() {
239 DockWidget::dock_widget
->show();
244 void ConWindow::startClock() {
250 title
= gpppdata
.accname();
252 if(gpppdata
.get_show_clock_on_caption()){
255 setWindowTitle(title
);
257 timelabel2
->setText("00:00:00");
258 clocktimer
->start(1000);
262 void ConWindow::setConnectionSpeed(const QString
&speed
) {
263 info2
->setText(speed
);
267 void ConWindow::stopClock() {
272 void ConWindow::timeclick() {
273 QString tooltip
= i18n("Connection: %1\n"
275 "Time connected: %3",
276 gpppdata
.accname(), info2
->text(),
279 if(accountingEnabled
)
280 tooltip
+= i18n("\nSession Bill: %1\nTotal Bill: %2",
281 session_bill
->text(), total_bill
->text());
283 if(volumeAccountingEnabled
) {
285 volinfo
->setEnabled(true);
286 int bytes
= gpppdata
.totalBytes();
287 volinfo
->setText(prettyPrintVolume(bytes
));
307 time_string
.sprintf("%02d:%02d",hours
,minutes
);
310 time_string2
.sprintf("%d d %02d:%02d:%02d",
311 days
,hours
,minutes
,seconds
);
314 time_string2
.sprintf("%02d:%02d:%02d",hours
,minutes
,seconds
);
316 caption_string
= gpppdata
.accname();
317 caption_string
+= ' ';
318 caption_string
+= time_string
;
321 timelabel2
->setText(time_string2
);
323 if(gpppdata
.get_show_clock_on_caption() && (seconds
== 1)){
324 // we update the Caption only once per minute not every second
325 // otherwise I get a flickering icon
326 setWindowTitle(caption_string
);
329 DockWidget::dock_widget
->setToolTip( tooltip
);
333 void ConWindow::closeEvent( QCloseEvent
*e
){
334 // we don't want to lose the
335 // conwindow since this is our last connection kppp.
336 // if we lost it we could only kill the program by hand to get on with life.
339 if(gpppdata
.get_dock_into_panel())
344 void ConWindow::slotAccounting(const QString
&total
, const QString
&session
) {
345 total_bill
->setText(total
);
346 session_bill
->setText(session
);
349 #include "conwindow.moc"