mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-13 03:22:34 -04:00
* Enabled Statistics for ApplicationWindow
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1037 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
bcfb410ba4
commit
516b1684f9
6 changed files with 775 additions and 551 deletions
|
@ -17,226 +17,224 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
****************************************************************/
|
||||
|
||||
|
||||
#include "rshare.h"
|
||||
#include "StatisticDialog.h"
|
||||
//#include <control/bandwidthevent.h>
|
||||
|
||||
|
||||
/** Constructor */
|
||||
StatisticDialog::StatisticDialog(QWidget *parent)
|
||||
: MainPage(parent)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
/* Create Bandwidth Graph related QObjects */
|
||||
_settings = new RshareSettings();
|
||||
|
||||
/* Bind events to actions */
|
||||
createActions();
|
||||
|
||||
/* Ask Tor to notify us about bandwidth updates */
|
||||
// _torControl = Vidalia::torControl();
|
||||
// _torControl->setEvent(TorEvents::Bandwidth, this, true);
|
||||
|
||||
/* Initialize Sent/Receive data counters */
|
||||
reset();
|
||||
|
||||
/* Hide Bandwidth Graph Settings frame */
|
||||
showSettingsFrame(false);
|
||||
|
||||
/* Turn off opacity group on unsupported platforms */
|
||||
#if defined(Q_WS_WIN)
|
||||
if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) {
|
||||
ui.frmOpacity->setVisible(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
ui.frmOpacity->setVisible(false);
|
||||
#endif
|
||||
}
|
||||
****************************************************************/
|
||||
|
||||
/** Default destructor */
|
||||
StatisticDialog::~StatisticDialog()
|
||||
{
|
||||
delete _settings;
|
||||
|
||||
#include "rshare.h"
|
||||
#include "StatisticDialog.h"
|
||||
//#include <control/bandwidthevent.h>
|
||||
#include "rsiface/rsiface.h"
|
||||
|
||||
|
||||
/** Constructor */
|
||||
StatisticDialog::StatisticDialog(QWidget *parent)
|
||||
: MainPage(parent)
|
||||
{
|
||||
/* Invoke the Qt Designer generated object setup routine */
|
||||
ui.setupUi(this);
|
||||
|
||||
/* Create Bandwidth Graph related QObjects */
|
||||
_settings = new RshareSettings();
|
||||
|
||||
/* Bind events to actions */
|
||||
createActions();
|
||||
|
||||
/* Initialize Sent/Receive data counters */
|
||||
reset();
|
||||
|
||||
/* Hide Bandwidth Graph Settings frame */
|
||||
showSettingsFrame(false);
|
||||
|
||||
/* Turn off opacity group on unsupported platforms */
|
||||
#if defined(Q_WS_WIN)
|
||||
if(!(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003)) {
|
||||
ui.frmOpacity->setVisible(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_WS_X11)
|
||||
ui.frmOpacity->setVisible(false);
|
||||
#endif
|
||||
|
||||
QTimer *timer = new QTimer(this);
|
||||
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updategraph2status()));
|
||||
timer->start(5113);
|
||||
}
|
||||
|
||||
/**
|
||||
Custom event handler. Checks if the event is a bandwidth update event. If it
|
||||
is, it will add the data point to the history and updates the graph.
|
||||
|
||||
void
|
||||
StatisticDialog::customEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == CustomEventType::BandwidthEvent) {
|
||||
BandwidthEvent *bw = (BandwidthEvent *)event;
|
||||
updateGraph(bw->bytesRead(), bw->bytesWritten());
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
Binds events to actions
|
||||
*/
|
||||
void
|
||||
StatisticDialog::createActions()
|
||||
{
|
||||
connect(ui.btnToggleSettings, SIGNAL(toggled(bool)),
|
||||
this, SLOT(showSettingsFrame(bool)));
|
||||
|
||||
connect(ui.btnReset, SIGNAL(clicked()),
|
||||
this, SLOT(reset()));
|
||||
|
||||
connect(ui.btnSaveSettings, SIGNAL(clicked()),
|
||||
this, SLOT(saveChanges()));
|
||||
|
||||
connect(ui.btnCancelSettings, SIGNAL(clicked()),
|
||||
this, SLOT(cancelChanges()));
|
||||
|
||||
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(setOpacity(int)));
|
||||
}
|
||||
|
||||
/**
|
||||
Adds new data to the graph
|
||||
*/
|
||||
void
|
||||
StatisticDialog::updateGraph(quint64 bytesRead, quint64 bytesWritten)
|
||||
{
|
||||
/* Graph only cares about kilobytes */
|
||||
ui.frmGraph->addPoints(bytesRead/1024.0, bytesWritten/1024.0);
|
||||
}
|
||||
|
||||
/**
|
||||
Loads the saved Bandwidth Graph settings
|
||||
*/
|
||||
void
|
||||
StatisticDialog::loadSettings()
|
||||
{
|
||||
/* Set window opacity slider widget */
|
||||
ui.sldrOpacity->setValue(_settings->getBWGraphOpacity());
|
||||
|
||||
|
||||
|
||||
/* Set the line filter checkboxes accordingly */
|
||||
uint filter = _settings->getBWGraphFilter();
|
||||
ui.chkReceiveRate->setChecked(filter & BWGRAPH_REC);
|
||||
ui.chkSendRate->setChecked(filter & BWGRAPH_SEND);
|
||||
|
||||
/* Set graph frame settings */
|
||||
ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
|
||||
ui.chkSendRate->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
Resets the log start time
|
||||
*/
|
||||
void
|
||||
StatisticDialog::reset()
|
||||
{
|
||||
/* Set to current time */
|
||||
// ui.statusbar->showMessage(tr("Since:") + " " +
|
||||
// QDateTime::currentDateTime()
|
||||
// .toString(DATETIME_FMT));
|
||||
/* Reset the graph */
|
||||
ui.frmGraph->resetGraph();
|
||||
}
|
||||
|
||||
/**
|
||||
Saves the Bandwidth Graph settings and adjusts the graph if necessary
|
||||
*/
|
||||
void
|
||||
StatisticDialog::saveChanges()
|
||||
{
|
||||
/* Hide the settings frame and reset toggle button */
|
||||
showSettingsFrame(false);
|
||||
|
||||
/* Save the opacity */
|
||||
_settings->setBWGraphOpacity(ui.sldrOpacity->value());
|
||||
|
||||
|
||||
|
||||
/* Save the line filter values */
|
||||
_settings->setBWGraphFilter(BWGRAPH_REC, ui.chkReceiveRate->isChecked());
|
||||
_settings->setBWGraphFilter(BWGRAPH_SEND, ui.chkSendRate->isChecked());
|
||||
|
||||
/* Update the graph frame settings */
|
||||
ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
|
||||
ui.chkSendRate->isChecked());
|
||||
|
||||
/* A change in window flags causes the window to disappear, so make sure
|
||||
* it's still visible. */
|
||||
showNormal();
|
||||
}
|
||||
|
||||
/**
|
||||
Simply restores the previously saved settings
|
||||
*/
|
||||
void
|
||||
StatisticDialog::cancelChanges()
|
||||
{
|
||||
/* Hide the settings frame and reset toggle button */
|
||||
showSettingsFrame(false);
|
||||
|
||||
/* Reload the settings */
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
Toggles the Settings pane on and off, changes toggle button text
|
||||
*/
|
||||
void
|
||||
StatisticDialog::showSettingsFrame(bool show)
|
||||
{
|
||||
if (show) {
|
||||
ui.frmSettings->setVisible(true);
|
||||
ui.btnToggleSettings->setChecked(true);
|
||||
ui.btnToggleSettings->setText(tr("Hide Settings"));
|
||||
} else {
|
||||
ui.frmSettings->setVisible(false);
|
||||
ui.btnToggleSettings->setChecked(false);
|
||||
ui.btnToggleSettings->setText(tr("Show Settings"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the opacity of the Bandwidth Graph window
|
||||
*/
|
||||
void
|
||||
StatisticDialog::setOpacity(int value)
|
||||
{
|
||||
qreal newValue = value / 100.0;
|
||||
|
||||
/* Opacity only supported by Mac and Win32 */
|
||||
#if defined(Q_WS_MAC)
|
||||
this->setWindowOpacity(newValue);
|
||||
#elif defined(Q_WS_WIN)
|
||||
if(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003) {
|
||||
this->setWindowOpacity(newValue);
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(newValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
Overloads the default show() slot so we can set opacity
|
||||
|
||||
void
|
||||
StatisticDialog::show()
|
||||
{
|
||||
loadSettings();
|
||||
if(!this->isVisible()) {
|
||||
QMainWindow::show();
|
||||
} else {
|
||||
QMainWindow::activateWindow();
|
||||
setWindowState(windowState() & ~Qt::WindowMinimized | Qt::WindowActive);
|
||||
QMainWindow::raise();
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/** Default destructor */
|
||||
StatisticDialog::~StatisticDialog()
|
||||
{
|
||||
delete _settings;
|
||||
}
|
||||
|
||||
/**
|
||||
Custom event handler. Checks if the event is a bandwidth update event. If it
|
||||
is, it will add the data point to the history and updates the graph.
|
||||
|
||||
void
|
||||
StatisticDialog::customEvent(QEvent *event)
|
||||
{
|
||||
if (event->type() == CustomEventType::BandwidthEvent) {
|
||||
BandwidthEvent *bw = (BandwidthEvent *)event;
|
||||
updateGraph(bw->bytesRead(), bw->bytesWritten());
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
Binds events to actions
|
||||
*/
|
||||
void
|
||||
StatisticDialog::createActions()
|
||||
{
|
||||
connect(ui.btnToggleSettings, SIGNAL(toggled(bool)),
|
||||
this, SLOT(showSettingsFrame(bool)));
|
||||
|
||||
connect(ui.btnReset, SIGNAL(clicked()),
|
||||
this, SLOT(reset()));
|
||||
|
||||
connect(ui.btnSaveSettings, SIGNAL(clicked()),
|
||||
this, SLOT(saveChanges()));
|
||||
|
||||
connect(ui.btnCancelSettings, SIGNAL(clicked()),
|
||||
this, SLOT(cancelChanges()));
|
||||
|
||||
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(setOpacity(int)));
|
||||
}
|
||||
|
||||
/**
|
||||
Adds new data to the graph
|
||||
*/
|
||||
void
|
||||
StatisticDialog::updateGraph(quint64 bytesRead, quint64 bytesWritten)
|
||||
{
|
||||
/* Graph only cares about kilobytes */
|
||||
ui.frmGraph->addPoints(bytesRead, bytesWritten);
|
||||
}
|
||||
|
||||
void
|
||||
StatisticDialog::updategraph2status( )
|
||||
{
|
||||
/* set users/friends/network */
|
||||
float downKb = 0;
|
||||
float upKb = 0;
|
||||
rsicontrol -> ConfigGetDataRates(downKb, upKb);
|
||||
|
||||
updateGraph(downKb,upKb);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Loads the saved Bandwidth Graph settings
|
||||
*/
|
||||
void
|
||||
StatisticDialog::loadSettings()
|
||||
{
|
||||
/* Set window opacity slider widget */
|
||||
ui.sldrOpacity->setValue(_settings->getBWGraphOpacity());
|
||||
|
||||
|
||||
|
||||
/* Set the line filter checkboxes accordingly */
|
||||
uint filter = _settings->getBWGraphFilter();
|
||||
ui.chkReceiveRate->setChecked(filter & BWGRAPH_REC);
|
||||
ui.chkSendRate->setChecked(filter & BWGRAPH_SEND);
|
||||
|
||||
/* Set graph frame settings */
|
||||
ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
|
||||
ui.chkSendRate->isChecked());
|
||||
}
|
||||
|
||||
/**
|
||||
Resets the log start time
|
||||
*/
|
||||
void
|
||||
StatisticDialog::reset()
|
||||
{
|
||||
/* Set to current time */
|
||||
// ui.statusbar->showMessage(tr("Since:") + " " +
|
||||
// QDateTime::currentDateTime()
|
||||
// .toString(DATETIME_FMT));
|
||||
/* Reset the graph */
|
||||
ui.frmGraph->resetGraph();
|
||||
}
|
||||
|
||||
/**
|
||||
Saves the Bandwidth Graph settings and adjusts the graph if necessary
|
||||
*/
|
||||
void
|
||||
StatisticDialog::saveChanges()
|
||||
{
|
||||
/* Hide the settings frame and reset toggle button */
|
||||
showSettingsFrame(false);
|
||||
|
||||
/* Save the opacity */
|
||||
_settings->setBWGraphOpacity(ui.sldrOpacity->value());
|
||||
|
||||
|
||||
|
||||
/* Save the line filter values */
|
||||
_settings->setBWGraphFilter(BWGRAPH_REC, ui.chkReceiveRate->isChecked());
|
||||
_settings->setBWGraphFilter(BWGRAPH_SEND, ui.chkSendRate->isChecked());
|
||||
|
||||
/* Update the graph frame settings */
|
||||
ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
|
||||
ui.chkSendRate->isChecked());
|
||||
|
||||
/* A change in window flags causes the window to disappear, so make sure
|
||||
* it's still visible. */
|
||||
showNormal();
|
||||
}
|
||||
|
||||
/**
|
||||
Simply restores the previously saved settings
|
||||
*/
|
||||
void
|
||||
StatisticDialog::cancelChanges()
|
||||
{
|
||||
/* Hide the settings frame and reset toggle button */
|
||||
showSettingsFrame(false);
|
||||
|
||||
/* Reload the settings */
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
/**
|
||||
Toggles the Settings pane on and off, changes toggle button text
|
||||
*/
|
||||
void
|
||||
StatisticDialog::showSettingsFrame(bool show)
|
||||
{
|
||||
if (show) {
|
||||
ui.frmSettings->setVisible(true);
|
||||
ui.btnToggleSettings->setChecked(true);
|
||||
ui.btnToggleSettings->setText(tr("Hide Settings"));
|
||||
} else {
|
||||
ui.frmSettings->setVisible(false);
|
||||
ui.btnToggleSettings->setChecked(false);
|
||||
ui.btnToggleSettings->setText(tr("Show Settings"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Sets the opacity of the Bandwidth Graph window
|
||||
*/
|
||||
void
|
||||
StatisticDialog::setOpacity(int value)
|
||||
{
|
||||
qreal newValue = value / 100.0;
|
||||
|
||||
/* Opacity only supported by Mac and Win32 */
|
||||
#if defined(Q_WS_MAC)
|
||||
this->setWindowOpacity(newValue);
|
||||
#elif defined(Q_WS_WIN)
|
||||
if(QSysInfo::WV_2000 <= QSysInfo::WindowsVersion <= QSysInfo::WV_2003) {
|
||||
this->setWindowOpacity(newValue);
|
||||
}
|
||||
#else
|
||||
Q_UNUSED(newValue);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue