Show
Ignore:
Timestamp:
02/02/06 03:33:35 (3 years ago)
Author:
hipplej
Message:

A little more progress on the graph. All that's left is drawing the lines.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/bwgraph/bwgraph.cpp

    r216 r223  
    2727#define DATETIME_FMT  "MMM dd hh:mm:ss:zzz" 
    2828 
    29 /** Default constructor **/ 
     29/** Default constructor */ 
    3030BandwidthGraph::BandwidthGraph(TorControl *torControl, QWidget *parent, Qt::WFlags f) 
    3131: QDialog(parent, f) 
    3232{ 
    33   /** Invoke Qt Designer generated QObject setup routine */ 
     33  /* Invoke Qt Designer generated QObject setup routine */ 
    3434  ui.setupUi(this); 
    3535 
    36   /** Create Bandwidth Graph related QObjects */ 
     36  /* Create Bandwidth Graph related QObjects */ 
    3737  _settings = new VidaliaSettings(); 
    38   _timer = new QTimer(this); 
    39    
    40   /** Bind events to actions */ 
     38   
     39  /* Bind events to actions */ 
    4140  createActions(); 
    4241 
    43   /** Ask Tor to notify us about bandwidth updates */ 
     42  /* Ask Tor to notify us about bandwidth updates */ 
    4443  _torControl = torControl; 
    4544  _torControl->setEvent(TorEvents::Bandwidth, this, true); 
    46    
    47   /** Start the update timer **/ 
    48   _timer->start(REFRESH_RATE); 
    49  
    50   /** Initialize Sent/Receive data counters */ 
     45 
     46  /* Initialize Sent/Receive data counters */ 
    5147  reset(); 
    52  
    53   /** Hide Bandwidth Graph Settings frame */ 
     48   
     49  /* Hide Bandwidth Graph Settings frame */ 
    5450  showSettingsFrame(false); 
    5551 
    56   /** Turn off opacity group on unsupported platforms */ 
     52  /* Turn off opacity group on unsupported platforms */ 
    5753#if defined(Q_WS_WIN) 
    5854  if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) { 
     
    6662} 
    6763 
    68 /** Default destructor **/ 
     64/** Default destructor */ 
    6965BandwidthGraph::~BandwidthGraph() 
    7066{ 
     
    7268    delete _settings; 
    7369  } 
    74   /* Unregister this object for bandwidth update events */ 
    75   _torControl->setEvent(TorEvents::Bandwidth, this, false); 
    7670} 
    7771 
     
    7973 Custom event handler. Checks if the event is a bandwidth update event. If it 
    8074 is, it will add the data point to the history and updates the graph. 
    81 **/ 
     75*/ 
    8276void 
    8377BandwidthGraph::customEvent(QEvent *event) 
     
    9185/** 
    9286 Binds events to actions 
    93 **/ 
     87*/ 
    9488void 
    9589BandwidthGraph::createActions() 
    9690{ 
    97 //  connect(_timer, SIGNAL(timeout()), 
    98 //      this, SLOT(updateGraph())); 
    99    
    10091  connect(ui.btnToggleSettings, SIGNAL(toggled(bool)), 
    10192      this, SLOT(showSettingsFrame(bool))); 
     
    115106 
    116107/** 
    117  Fetches new statistics and plots them on the graph 
    118  and adds them to the data counters 
    119 **/ 
     108 Adds new data to the graph and the counters 
     109*/ 
    120110void 
    121111BandwidthGraph::updateGraph(quint64 bytesRead, quint64 bytesWritten) 
    122112{ 
    123   // add data points to graph 
    124   // add data value to counters 
    125  
    126   /* Obviously this isn't what you're going to do with the data, but this lets 
    127    * you see that it's working in the meantime. */ 
    128   ui.lblSent->setText(QString::number(bytesRead)); 
    129   ui.lblReceived->setText(QString::number(bytesWritten)); 
     113  /* Send the data in kilobits */ 
     114  ui.frmGraph->addPoints(bytesRead/1000.0, bytesWritten/1000.0); 
     115  ui.lblSent->setText(addDataToStr(bytesWritten, _totalSent)); 
     116  ui.lblReceived->setText(addDataToStr(bytesRead, _totalReceived)); 
     117} 
     118 
     119/** 
     120 Adds data to the total counters and returns a correctly 
     121 formatted string with the correct size suffix 
     122*/ 
     123QString 
     124BandwidthGraph::addDataToStr(quint64 data, quint64 &total) 
     125{ 
     126  total += data; 
     127 
     128  /* Determine the correct size suffix */ 
     129  if (total < 1000) { 
     130    /* Use bytes suffix */ 
     131    return tr("%1 bytes").arg(total, 0); 
     132  } else if (total < 1000000) { 
     133    /* Use KB suffix */ 
     134    return tr("%1 KB").arg(total/1000.0, 0, 'f', 2); 
     135  } else if (total < 1000000000) { 
     136    /* Use MB suffix */ 
     137    return tr("%1 MB").arg(total/1000000.0, 0, 'f', 2); 
     138  } else { 
     139    /* Use GB suffix */ 
     140    return tr("%1 MB").arg(total/1000000000.0, 0, 'f', 2); 
     141  } 
    130142} 
    131143 
    132144/** 
    133145 Loads the saved Bandwidth Graph settings 
    134 **/ 
     146*/ 
    135147void 
    136148BandwidthGraph::loadSettings() 
    137149{ 
    138   /** Set window opacity slider widget **/ 
     150  /* Set window opacity slider widget */ 
    139151  ui.sldrOpacity->setValue(_settings->getBWGraphOpacity()); 
    140152 
    141   /** Set the line filter checkboxes accordingly **/ 
     153  /* Set the line filter checkboxes accordingly */ 
    142154  uint filter = _settings->getBWGraphFilter(); 
    143155  ui.chkReceiveRate->setChecked(filter & BWGRAPH_REC); 
    144156  ui.chkSendRate->setChecked(filter & BWGRAPH_SEND); 
    145157 
    146   /** Set graph frame settings **/ 
     158  /* Set graph frame settings */ 
    147159  ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(), 
    148160                               ui.chkSendRate->isChecked()); 
     
    151163/**  
    152164 Resets the Sent/Received data counters and the log start time 
    153 **/ 
     165*/ 
    154166void 
    155167BandwidthGraph::reset() 
    156168{ 
    157   /** Reset the data counter labels **/ 
    158   ui.lblSent->setText(tr("0.0 MB")); 
    159   ui.lblReceived->setText(tr("0.0 MB")); 
    160  
    161   /** Reset the log start timer **/ 
     169  /* Reset the data total counters */ 
     170  _totalSent = 0; 
     171  _totalReceived = 0; 
     172   
     173  /* Reset the data counter labels */ 
     174  ui.lblSent->setText(tr("0 bytes")); 
     175  ui.lblReceived->setText(tr("0 bytes")); 
     176 
     177  /* Reset the data counter clock */ 
    162178  ui.lblStartTime->setText(QDateTime::currentDateTime().toString(DATETIME_FMT)); 
    163179 
    164   /** Reset the graph **/ 
     180  /* Reset the graph */ 
    165181  ui.frmGraph->resetGraph(); 
    166182} 
     
    168184/** 
    169185 Saves the Bandwidth Graph settings and adjusts the graph if necessary 
    170 **/ 
     186*/ 
    171187void 
    172188BandwidthGraph::saveChanges() 
    173189{ 
    174   /** Hide the settings frame and reset toggle button **/ 
     190  /* Hide the settings frame and reset toggle button */ 
    175191  showSettingsFrame(false); 
    176192   
    177   /** Save the opacity **/ 
     193  /* Save the opacity */ 
    178194  _settings->setBWGraphOpacity(ui.sldrOpacity->value()); 
    179195 
    180   /** Save the line filter values **/ 
     196  /* Save the line filter values */ 
    181197  _settings->setBWGraphFilter(BWGRAPH_REC, ui.chkReceiveRate->isChecked()); 
    182198  _settings->setBWGraphFilter(BWGRAPH_SEND, ui.chkSendRate->isChecked()); 
    183199 
    184   /** Update the graph frame settings **/ 
     200  /* Update the graph frame settings */ 
    185201  ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(), 
    186202                               ui.chkSendRate->isChecked()); 
     
    189205/**  
    190206 Simply restores the previously saved settings 
    191 **/ 
     207*/ 
    192208void  
    193209BandwidthGraph::cancelChanges() 
     
    202218/**  
    203219 Toggles the Settings pane on and off, changes toggle button text 
    204 **/ 
     220*/ 
    205221void 
    206222BandwidthGraph::showSettingsFrame(bool show) 
     
    219235/** 
    220236 Sets the opacity of the Bandwidth Graph window 
    221 **/ 
     237*/ 
    222238void 
    223239BandwidthGraph::setOpacity(int value) 
     
    225241  qreal newValue = value / 100.0; 
    226242 
    227   /** Opacity only supported by Mac and Win32 **/ 
     243  /* Opacity only supported by Mac and Win32 */ 
    228244  #if defined(Q_WS_MAC) 
    229245    this->setWindowOpacity(newValue); 
     
    239255/**  
    240256 Overloads the default show() slot so we can set opacity 
    241 **/ 
     257*/ 
    242258void 
    243259BandwidthGraph::show()