Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

conwindow.cpp

Go to the documentation of this file.
00001 /*
00002  *            kPPP: A pppd front end for the KDE project
00003  *
00004  * $Id: conwindow.cpp,v 1.5 2003/08/09 17:14:55 kergoth Exp $
00005  *
00006  *            Copyright (C) 1997 Bernd Johannes Wuebben
00007  *                   wuebben@math.cornell.edu
00008  *
00009  * This program is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This program is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this program; if not, write to the Free
00021  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00022  */
00023 
00024 #include <qtooltip.h>
00025 #include <qdialog.h>
00026 #include "conwindow.h"
00027 #include "pppdata.h"
00028 
00029 
00030 ConWindow::ConWindow(PPPData *pd, QWidget *parent, const char *name,
00031                      QDialog *mainwidget )
00032   : QWidget(parent, name, 0),
00033     minutes(0),
00034     seconds(0),
00035     hours(0),
00036     days(0),
00037     tl1(0),
00038     _pppdata(pd)
00039 {
00040   info1 = new QLabel(QObject::tr("Connected at:"), this);
00041   info2 = new QLabel("", this);
00042 
00043   timelabel1 = new QLabel(QObject::tr("Time connected:"), this);
00044   timelabel2 = new QLabel("000:00:00", this);
00045 
00046   vollabel = new QLabel(QObject::tr("Volume:"), this);
00047   volinfo  = new QLabel("", this);
00048 
00049   // now the stuff for accounting
00050   session_bill_l = new QLabel(QObject::tr("Session Bill:"), this);
00051   session_bill = new QLabel("", this);
00052   total_bill_l = new QLabel(QObject::tr("Total Bill:"), this);
00053   total_bill = new QLabel("", this);
00054 
00055   this->setCaption("kppp");
00056 
00057   cancelbutton = new QPushButton(this);
00058   cancelbutton->setText(QObject::tr("Disconnect"));
00059   connect(cancelbutton, SIGNAL(clicked()), mainwidget, SLOT(disconnect()));
00060 
00061  //  statsbutton = new QPushButton(this);
00062 //   statsbutton->setText(QObject::tr("Details"));
00063 //   statsbutton->setFocus();
00064 //   connect(statsbutton, SIGNAL(clicked()), mainwidget, SLOT(showStats()));
00065 
00066   clocktimer = new QTimer(this);
00067   connect(clocktimer, SIGNAL(timeout()), SLOT(timeclick()));
00068 
00069   // read window position from config file
00070 //  int p_x, p_y;
00071 //   PPPData::data()->winPosConWin(p_x, p_y);
00072 //   setGeometry(p_x, p_y, 320, 110);
00073 }
00074 
00075 ConWindow::~ConWindow() {
00076   stopClock();
00077 }
00078 
00079 // save window position when window was closed
00080 bool ConWindow::event(QEvent *e) {
00081   if (e->type() == QEvent::Hide)
00082   {
00083 //    PPPData::data()->setWinPosConWin(x(), y());
00084     return true;
00085   }
00086   else
00087     return QWidget::event(e);
00088 }
00089 
00090 QString ConWindow::prettyPrintVolume(unsigned int n) {
00091   int idx = 0;
00092   const QString quant[] = {QObject::tr("Byte"), QObject::tr("KB"),
00093                    QObject::tr("MB"), QObject::tr("GB"), QString::null};
00094 
00095   float n1 = n;
00096   while(n >= 1024 && quant[idx] != QString::null) {
00097     idx++;
00098     n /= 1024;
00099   }
00100 
00101   int i = idx;
00102   while(i--)
00103     n1 = n1 / 1024.0;
00104 
00105   QString s = QString::number( n1, 'f', idx==0 ? 0 : 1 ); //KGlobal::locale()->formatNumber( n1, idx==0 ? 0 : 1 );
00106   s += " " + quant[idx];
00107   return s;
00108 }
00109 
00110 // void ConWindow::accounting(bool on) {
00111 //   // cache accounting settings
00112 //   accountingEnabled = on;
00113 // //  volumeAccountingEnabled = PPPData::data()->VolAcctEnabled();
00114 
00115 //   // delete old layout
00116 //   if(tl1 != 0)
00117 //     delete tl1;
00118 
00119 //   // add layout now
00120 //   tl1 = new QVBoxLayout(this, 10, 10);
00121 //   tl1->addSpacing(5);
00122 //   QHBoxLayout *tl = new QHBoxLayout;
00123 //   tl1->addLayout(tl);
00124 //   tl->addSpacing(20);
00125 //   QGridLayout *l1;
00126 
00127 //   int vol_lines = 0;
00128 // //   if(_pppdata->VolAcctEnabled())
00129 // //     vol_lines = 1;
00130 
00131 //   if(accountingEnabled)
00132 //     l1 = new QGridLayout(4 + vol_lines, 2, 5);
00133 //   else
00134 //     l1 = new QGridLayout(2 + vol_lines, 2, 5);
00135 //   tl->addLayout(l1);
00136 //   l1->setColStretch(0, 0);
00137 //   l1->setColStretch(1, 1);
00138 
00139 //   info2->setAlignment(AlignRight|AlignVCenter);
00140 //   timelabel2->setAlignment(AlignRight|AlignVCenter);
00141 //   session_bill->setAlignment(AlignRight|AlignVCenter);
00142 //   total_bill->setAlignment(AlignRight|AlignVCenter);
00143 //   volinfo->setAlignment(AlignRight|AlignVCenter);
00144 //   // make sure that there's enough space for the bills
00145 //   QString s1 = session_bill->text();
00146 //   QString s2 = total_bill->text();
00147 //   QString s3 = volinfo->text();
00148 
00149 //   session_bill->setText("888888.88 XXX");
00150 //   total_bill->setText("888888.88 XXX");
00151 //   volinfo->setText("8888.8 MB");
00152 //   session_bill->setFixedSize(session_bill->sizeHint());
00153 //   total_bill->setFixedSize(total_bill->sizeHint());
00154 //   volinfo->setFixedSize(volinfo->sizeHint());
00155 //   session_bill->setText(s1);
00156 //   total_bill->setText(s2);
00157 //   volinfo->setText(s3);
00158 
00159 //   l1->addWidget(info1, 0, 0);
00160 //   l1->addWidget(info2, 0, 1);
00161 //   l1->addWidget(timelabel1, 1, 0);
00162 //   l1->addWidget(timelabel2, 1, 1);
00163 //   if(accountingEnabled) {
00164 //     session_bill_l->show();
00165 //     session_bill->show();
00166 //     total_bill_l->show();
00167 //     total_bill->show();
00168 //     l1->addWidget(session_bill_l, 2, 0);
00169 //     l1->addWidget(session_bill, 2, 1);
00170 //     l1->addWidget(total_bill_l, 3, 0);
00171 //     l1->addWidget(total_bill, 3, 1);
00172 
00173 //     if(volumeAccountingEnabled) {
00174 //       vollabel->show();
00175 //       volinfo->show();
00176 //       l1->addWidget(vollabel, 4, 0);
00177 //       l1->addWidget(volinfo, 4, 1);
00178 //     } else {
00179 //       vollabel->hide();
00180 //       volinfo->hide();
00181 //     }
00182 
00183 //   } else {
00184 //     session_bill_l->hide();
00185 //     session_bill->hide();
00186 //     total_bill_l->hide();
00187 //     total_bill->hide();
00188 
00189 //     if(volumeAccountingEnabled) {
00190 //       vollabel->show();
00191 //       volinfo->show();
00192 //       l1->addWidget(vollabel, 2, 0);
00193 //       l1->addWidget(volinfo, 2, 1);
00194 //     } else {
00195 //       vollabel->hide();
00196 //       volinfo->hide();
00197 //     }
00198 //   }
00199 
00200 //   tl->addSpacing(10);
00201 //   QVBoxLayout *l2 = new QVBoxLayout(5);
00202 //   tl->addLayout(l2);
00203 //   l2->addStretch(1);
00204 // //  l2->addWidget(statsbutton);
00205 //   l2->addWidget(cancelbutton);
00206 
00207 //   l2->addStretch(1);
00208 
00209 //   tl1->addSpacing(5);
00210 
00211 //   setFixedSize(sizeHint());
00212 // /*
00213 //   do not overwrite position read from config
00214 //   setGeometry((QApplication::desktop()->width() - width()) / 2,
00215 //            (QApplication::desktop()->height() - height())/2,
00216 //            width(),
00217 //            height());
00218 // */
00219 // }
00220 
00221 
00222 // void ConWindow::dock() {
00223 // //  DockWidget::dock_widget->show();
00224 //   this->hide();
00225 // }
00226 
00227 
00228 void ConWindow::startClock() {
00229   minutes = 0;
00230   seconds = 0;
00231   hours = 0;
00232   QString title ;
00233 
00234   title = _pppdata->accname();
00235 
00236   if(_pppdata->get_show_clock_on_caption()){
00237     title += " 00:00" ;
00238   }
00239   this->setCaption(title);
00240 
00241   timelabel2->setText("00:00:00");
00242   clocktimer->start(1000);
00243 }
00244 
00245 
00246 void ConWindow::setConnectionSpeed(const QString &speed) {
00247   info2->setText(speed);
00248 }
00249 
00250 
00251 void ConWindow::stopClock() {
00252   clocktimer->stop();
00253 }
00254 
00255 
00256 void ConWindow::timeclick() {
00257 //   QString tooltip = QObject::tr("Connection: %1\n"
00258 //                       "Connected at: %2\n"
00259 //                       "Time connected: %3")
00260 //                  .arg(_pppdata->accname()).arg(info2->text())
00261 //                  .arg(time_string2);
00262 
00263 //   if(accountingEnabled)
00264 //       tooltip += QObject::tr("\nSession Bill: %1\nTotal Bill: %2")
00265 //               .arg(session_bill->text()).arg(total_bill->text());
00266 //   // volume accounting
00267 //   if(volumeAccountingEnabled) {
00268 
00269 //     volinfo->setEnabled(TRUE);
00270 //     int bytes = _pppdata->totalBytes();
00271 //     volinfo->setText(prettyPrintVolume(bytes));
00272 //   }
00273 
00274 //   seconds++;
00275 
00276 //   if(seconds >= 60 ) {
00277 //     minutes ++;
00278 //     seconds = 0;
00279 //   }
00280 
00281 //   if (minutes >= 60){
00282 //     minutes = 0;
00283 //     hours ++;
00284 //   }
00285 
00286 //   if( hours >= 24){
00287 //     days ++;
00288 //     hours = 0;
00289 //   }
00290 
00291 //   time_string.sprintf("%02d:%02d",hours,minutes);
00292 //   time_string2 = "";
00293 //   if (days)
00294 //       time_string2.sprintf("%d d %02d:%02d:%02d",
00295 //                         days,hours,minutes,seconds);
00296 
00297 //   else
00298 //     time_string2.sprintf("%02d:%02d:%02d",hours,minutes,seconds);
00299 
00300 //   caption_string = _pppdata->accname();
00301 //   caption_string += " ";
00302 //   caption_string += time_string;
00303 
00304 
00305 //   timelabel2->setText(time_string2);
00306 
00307 //   if(_pppdata->get_show_clock_on_caption() && (seconds == 1)){
00308 //     // we update the Caption only once per minute not every second
00309 //     // otherwise I get a flickering icon
00310 //     this->setCaption(caption_string);
00311 //   }
00312 
00313 //  QToolTip::add(DockWidget::dock_widget, tooltip);
00314 }
00315 
00316 
00317 void ConWindow::closeEvent( QCloseEvent *e ){
00318   // we don't want to lose the
00319   // conwindow since this is our last connection kppp.
00320   // if we lost it we could only kill the program by hand to get on with life.
00321   e->ignore();
00322 
00323 //   if(_pppdata->get_dock_into_panel())
00324 //     dock();
00325 }
00326 
00327 
00328 void ConWindow::slotAccounting(QString total, QString session) {
00329   total_bill->setText(total);
00330   session_bill->setText(session);
00331 }
00332 
00333 

Generated on Sat Nov 5 16:17:49 2005 for OPIE by  doxygen 1.4.2