Changeset 223 for trunk/src/gui/bwgraph/bwgraph.cpp
- Timestamp:
- 02/02/06 03:33:35 (3 years ago)
- Files:
-
- 1 modified
-
trunk/src/gui/bwgraph/bwgraph.cpp (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gui/bwgraph/bwgraph.cpp
r216 r223 27 27 #define DATETIME_FMT "MMM dd hh:mm:ss:zzz" 28 28 29 /** Default constructor * */29 /** Default constructor */ 30 30 BandwidthGraph::BandwidthGraph(TorControl *torControl, QWidget *parent, Qt::WFlags f) 31 31 : QDialog(parent, f) 32 32 { 33 /* *Invoke Qt Designer generated QObject setup routine */33 /* Invoke Qt Designer generated QObject setup routine */ 34 34 ui.setupUi(this); 35 35 36 /* *Create Bandwidth Graph related QObjects */36 /* Create Bandwidth Graph related QObjects */ 37 37 _settings = new VidaliaSettings(); 38 _timer = new QTimer(this); 39 40 /** Bind events to actions */ 38 39 /* Bind events to actions */ 41 40 createActions(); 42 41 43 /* *Ask Tor to notify us about bandwidth updates */42 /* Ask Tor to notify us about bandwidth updates */ 44 43 _torControl = torControl; 45 44 _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 */ 51 47 reset(); 52 53 /* *Hide Bandwidth Graph Settings frame */48 49 /* Hide Bandwidth Graph Settings frame */ 54 50 showSettingsFrame(false); 55 51 56 /* *Turn off opacity group on unsupported platforms */52 /* Turn off opacity group on unsupported platforms */ 57 53 #if defined(Q_WS_WIN) 58 54 if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) { … … 66 62 } 67 63 68 /** Default destructor * */64 /** Default destructor */ 69 65 BandwidthGraph::~BandwidthGraph() 70 66 { … … 72 68 delete _settings; 73 69 } 74 /* Unregister this object for bandwidth update events */75 _torControl->setEvent(TorEvents::Bandwidth, this, false);76 70 } 77 71 … … 79 73 Custom event handler. Checks if the event is a bandwidth update event. If it 80 74 is, it will add the data point to the history and updates the graph. 81 * */75 */ 82 76 void 83 77 BandwidthGraph::customEvent(QEvent *event) … … 91 85 /** 92 86 Binds events to actions 93 * */87 */ 94 88 void 95 89 BandwidthGraph::createActions() 96 90 { 97 // connect(_timer, SIGNAL(timeout()),98 // this, SLOT(updateGraph()));99 100 91 connect(ui.btnToggleSettings, SIGNAL(toggled(bool)), 101 92 this, SLOT(showSettingsFrame(bool))); … … 115 106 116 107 /** 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 */ 120 110 void 121 111 BandwidthGraph::updateGraph(quint64 bytesRead, quint64 bytesWritten) 122 112 { 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 */ 123 QString 124 BandwidthGraph::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 } 130 142 } 131 143 132 144 /** 133 145 Loads the saved Bandwidth Graph settings 134 * */146 */ 135 147 void 136 148 BandwidthGraph::loadSettings() 137 149 { 138 /* * Set window opacity slider widget **/150 /* Set window opacity slider widget */ 139 151 ui.sldrOpacity->setValue(_settings->getBWGraphOpacity()); 140 152 141 /* * Set the line filter checkboxes accordingly **/153 /* Set the line filter checkboxes accordingly */ 142 154 uint filter = _settings->getBWGraphFilter(); 143 155 ui.chkReceiveRate->setChecked(filter & BWGRAPH_REC); 144 156 ui.chkSendRate->setChecked(filter & BWGRAPH_SEND); 145 157 146 /* * Set graph frame settings **/158 /* Set graph frame settings */ 147 159 ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(), 148 160 ui.chkSendRate->isChecked()); … … 151 163 /** 152 164 Resets the Sent/Received data counters and the log start time 153 * */165 */ 154 166 void 155 167 BandwidthGraph::reset() 156 168 { 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 */ 162 178 ui.lblStartTime->setText(QDateTime::currentDateTime().toString(DATETIME_FMT)); 163 179 164 /* * Reset the graph **/180 /* Reset the graph */ 165 181 ui.frmGraph->resetGraph(); 166 182 } … … 168 184 /** 169 185 Saves the Bandwidth Graph settings and adjusts the graph if necessary 170 * */186 */ 171 187 void 172 188 BandwidthGraph::saveChanges() 173 189 { 174 /* * Hide the settings frame and reset toggle button **/190 /* Hide the settings frame and reset toggle button */ 175 191 showSettingsFrame(false); 176 192 177 /* * Save the opacity **/193 /* Save the opacity */ 178 194 _settings->setBWGraphOpacity(ui.sldrOpacity->value()); 179 195 180 /* * Save the line filter values **/196 /* Save the line filter values */ 181 197 _settings->setBWGraphFilter(BWGRAPH_REC, ui.chkReceiveRate->isChecked()); 182 198 _settings->setBWGraphFilter(BWGRAPH_SEND, ui.chkSendRate->isChecked()); 183 199 184 /* * Update the graph frame settings **/200 /* Update the graph frame settings */ 185 201 ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(), 186 202 ui.chkSendRate->isChecked()); … … 189 205 /** 190 206 Simply restores the previously saved settings 191 * */207 */ 192 208 void 193 209 BandwidthGraph::cancelChanges() … … 202 218 /** 203 219 Toggles the Settings pane on and off, changes toggle button text 204 * */220 */ 205 221 void 206 222 BandwidthGraph::showSettingsFrame(bool show) … … 219 235 /** 220 236 Sets the opacity of the Bandwidth Graph window 221 * */237 */ 222 238 void 223 239 BandwidthGraph::setOpacity(int value) … … 225 241 qreal newValue = value / 100.0; 226 242 227 /* * Opacity only supported by Mac and Win32 **/243 /* Opacity only supported by Mac and Win32 */ 228 244 #if defined(Q_WS_MAC) 229 245 this->setWindowOpacity(newValue); … … 239 255 /** 240 256 Overloads the default show() slot so we can set opacity 241 * */257 */ 242 258 void 243 259 BandwidthGraph::show()
