[tor-commits] [vidalia/alpha] Remove Bandwidth Graph since it's now a plugin

chiiph at torproject.org chiiph at torproject.org
Fri Aug 10 01:01:22 UTC 2012


commit 0f6d7a9e09c903b9e29fd428a33af0ff3c8fdfe2
Author: Tomás Touceda <chiiph at torproject.org>
Date:   Sat Jul 21 17:08:19 2012 -0300

    Remove Bandwidth Graph since it's now a plugin
---
 changes/removeBwgraph                  |    2 +
 src/vidalia/CMakeLists.txt             |   11 -
 src/vidalia/MainWindow.cpp             |   19 --
 src/vidalia/MainWindow.h               |    5 -
 src/vidalia/bwgraph/BandwidthGraph.cpp |  260 ----------------------
 src/vidalia/bwgraph/BandwidthGraph.h   |   75 -------
 src/vidalia/bwgraph/BandwidthGraph.ui  |  374 --------------------------------
 src/vidalia/bwgraph/GraphFrame.cpp     |  351 ------------------------------
 src/vidalia/bwgraph/GraphFrame.h       |  121 ----------
 9 files changed, 2 insertions(+), 1216 deletions(-)

diff --git a/changes/removeBwgraph b/changes/removeBwgraph
new file mode 100644
index 0000000..8ae3236
--- /dev/null
+++ b/changes/removeBwgraph
@@ -0,0 +1,2 @@
+  Internal cleanups and improvements:
+  o Remove bandwidth graph since it is now a plugin.
diff --git a/src/vidalia/CMakeLists.txt b/src/vidalia/CMakeLists.txt
index 17581d2..c46a97b 100644
--- a/src/vidalia/CMakeLists.txt
+++ b/src/vidalia/CMakeLists.txt
@@ -15,7 +15,6 @@ include_directories(
   ${CMAKE_CURRENT_BINARY_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}
   ${CMAKE_CURRENT_SOURCE_DIR}/about
-  ${CMAKE_CURRENT_SOURCE_DIR}/bwgraph
   ${CMAKE_CURRENT_SOURCE_DIR}/config
   ${CMAKE_CURRENT_SOURCE_DIR}/config/torrc
   ${CMAKE_CURRENT_SOURCE_DIR}/help/browser
@@ -75,15 +74,6 @@ qt4_wrap_cpp(vidalia_SRCS
   about/LicenseDialog.h
 )
 
-## Bandwidth graph sources
-set(vidalia_SRCS ${vidalia_SRCS}
-  bwgraph/BandwidthGraph.cpp
-  bwgraph/GraphFrame.cpp
-)
-qt4_wrap_cpp(vidalia_SRCS
-  bwgraph/BandwidthGraph.h
-  bwgraph/GraphFrame.h
-)
 ## Plugin framework sources
 set(vidalia_SRCS ${vidalia_SRCS}
   plugin/PluginEngine.cpp
@@ -232,7 +222,6 @@ qt4_wrap_ui(vidalia_SRCS
   MainWindow.ui
   about/AboutDialog.ui
   about/LicenseDialog.ui
-  bwgraph/BandwidthGraph.ui
   config/AdvancedPage.ui
   config/AppearancePage.ui
   config/BridgeUsageDialog.ui
diff --git a/src/vidalia/MainWindow.cpp b/src/vidalia/MainWindow.cpp
index e40e3a3..6d78a0b 100644
--- a/src/vidalia/MainWindow.cpp
+++ b/src/vidalia/MainWindow.cpp
@@ -195,7 +195,6 @@ MainWindow::createGUI()
   // We need to create this tab at the beggining
   // and we must specify the statusBar
   _messageLog = new MessageLog(this->statusBar());
-  _graph = new BandwidthGraph(this->statusBar());
 
   addTab(&_statusTab);
   ui.tabWidget->pinTab(0);
@@ -212,7 +211,6 @@ MainWindow::createActions()
   _actionStatus = new QAction(QIcon(IMG_CONTROL_PANEL), tr("Status"), this);
   _actionNetworkMap = new QAction(QIcon(IMG_NETWORK), tr("Network Map"), this);
   _actionMessageLog= new QAction(QIcon(IMG_MESSAGELOG), tr("Message Log"), this);
-  _actionBandwidthGraph = new QAction(QIcon(IMG_BWGRAPH), tr("Bandwidth Graph"), this);
   _actionConfigure = new QAction(QIcon(IMG_CONFIG), tr("Settings"), this);
   _actionVidaliaHelp = new QAction(QIcon(IMG_HELP), tr("Help"), this);
   _actionAbout = new QAction(QIcon(IMG_ABOUT), tr("About"), this);
@@ -252,7 +250,6 @@ MainWindow::createMenuBar()
   viewMenu->addAction(_actionStatus);
   viewMenu->addAction(_actionNetworkMap);
   viewMenu->addAction(_actionMessageLog);
-  viewMenu->addAction(_actionBandwidthGraph);
   viewMenu->addSeparator();
   viewMenu->addAction(_actionConfigure);
 
@@ -298,7 +295,6 @@ MainWindow::createTrayMenu()
   QMenu *menu = new QMenu(this);
   menu->addAction(_actionStartStopTor);
   menu->addSeparator();
-  menu->addAction(_actionBandwidthGraph);
   menu->addAction(_actionMessageLog);
   menu->addAction(_actionNetworkMap);
   menu->addAction(_actionNewIdentity);
@@ -414,7 +410,6 @@ MainWindow::retranslateUi()
     _actionStartStopTor->setText(tr("Stop Tor"));
   }
 
-  _actionBandwidthGraph->setText(tr("Bandwidth Graph"));
   _actionMessageLog->setText(tr("Message Log"));
   _actionNetworkMap->setText(tr("Network Map"));
   _actionStatus->setText(tr("Status"));
@@ -444,7 +439,6 @@ MainWindow::createConnections()
 
   connect(_actionMessageLog, SIGNAL(triggered()), this, SLOT(showMessageLogTab()));
   connect(_actionConfigure, SIGNAL(triggered()), this, SLOT(showConfigDialog()));
-  connect(_actionBandwidthGraph, SIGNAL(triggered()), this, SLOT(showBandwidthTab()));
   connect(_actionAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
   connect(_actionVidaliaHelp, SIGNAL(triggered()), this, SLOT(showHelpDialog()));
   connect(_actionStatus, SIGNAL(triggered()), this, SLOT(showStatusTab()));
@@ -2016,13 +2010,6 @@ MainWindow::addTab(VidaliaTab *tab)
      * don't do anything */
     if(tab == ui.tabWidget->widget(_tabMap.indexOf(tab->getTitle())))
       return;
-
-    /** Exception for tabs that need to be always created */
-    if (tab != _messageLog &&
-        tab != &_statusTab &&
-        tab != &_netViewer &&
-        tab != _graph)
-      tab->deleteLater();
     return;
   }
 
@@ -2078,12 +2065,6 @@ MainWindow::showMessageLogTab()
   addTab(_messageLog);
 }
 
-void
-MainWindow::showBandwidthTab()
-{
-  addTab(_graph);
-}
-
 /** Creates and displays Vidalia's About dialog. */
 void
 MainWindow::showAboutDialog()
diff --git a/src/vidalia/MainWindow.h b/src/vidalia/MainWindow.h
index e5befa3..f78bc9f 100644
--- a/src/vidalia/MainWindow.h
+++ b/src/vidalia/MainWindow.h
@@ -24,7 +24,6 @@
 #include "ConfigDialog.h"
 #include "MessageLog.h"
 #include "NetViewer.h"
-#include "BandwidthGraph.h"
 #include "HelperProcess.h"
 #if defined(USE_AUTOUPDATE)
 #include "UpdateProcess.h"
@@ -137,8 +136,6 @@ private slots:
   void showMessageLogTab();
   /** Displays the General Tor Status tab */
   void showStatusTab();
-  /** Displays the Bandwidth graph tab */
-  void showBandwidthTab();
   /** Displays the Network map tab */
   void showNetViewerTab();
   /** Creates and displays Vidalia's About dialog. */
@@ -300,7 +297,6 @@ private:
   QAction *_actionStatus;
   QAction *_actionNetworkMap;
   QAction *_actionMessageLog;
-  QAction *_actionBandwidthGraph;
   QAction *_actionConfigure;
   QAction *_actionVidaliaHelp;
   QAction *_actionAbout;
@@ -317,7 +313,6 @@ private:
   StatusTab _statusTab; /**< Status tab that displays the load progress and a short log */
   MessageLog *_messageLog; /**< Message log that displays a more detailed log from Tor */
   NetViewer _netViewer; /**< Network map that draws circuits */
-  BandwidthGraph *_graph; /**< Graph that draws bandwidth usage */
 
   PluginEngine *_engine;
   QStringList _tabMap; /**< Map to handle opened tabs */
diff --git a/src/vidalia/bwgraph/BandwidthGraph.cpp b/src/vidalia/bwgraph/BandwidthGraph.cpp
deleted file mode 100644
index 71f6f15..0000000
--- a/src/vidalia/bwgraph/BandwidthGraph.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
-**  This file is part of Vidalia, and is subject to the license terms in the
-**  LICENSE file, found in the top level directory of this distribution. If you
-**  did not receive the LICENSE file with this file, you may obtain it from the
-**  Vidalia source package distributed by the Vidalia Project at
-**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
-**  including this file, may be copied, modified, propagated, or distributed
-**  except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file BandwidthGraph.cpp
-** \brief Displays a graph of Tor's bandwidth usage
-*/
-
-#include "BandwidthGraph.h"
-#include "Vidalia.h"
-
-#define BWGRAPH_LINE_SEND       (1u<<0)
-#define BWGRAPH_LINE_RECV       (1u<<1)
-#define SETTING_FILTER          "LineFilter"
-#define SETTING_OPACITY         "Opacity"
-#define SETTING_ALWAYS_ON_TOP   "AlwaysOnTop"
-#define SETTING_STYLE           "GraphStyle"
-#define DEFAULT_FILTER          (BWGRAPH_LINE_SEND|BWGRAPH_LINE_RECV)
-#define DEFAULT_ALWAYS_ON_TOP   false
-#define DEFAULT_OPACITY         100
-#define DEFAULT_STYLE           GraphFrame::AreaGraph
-
-#define ADD_TO_FILTER(f,v,b)  (f = ((b) ? ((f) | (v)) : ((f) & ~(v))))
-
-/* Define the format used for displaying the date and time */
-#define DATETIME_FMT  "MMM dd hh:mm:ss"
-
-/* Images used in the graph style drop-down */
-#define IMG_AREA_GRAPH    ":/images/16x16/graph-area.png"
-#define IMG_LINE_GRAPH    ":/images/16x16/graph-line.png"
-
-
-/** Default constructor */
-BandwidthGraph::BandwidthGraph(QStatusBar *st, QWidget *parent)
-  : VidaliaTab(tr("Bandwidth Graph"), "BandwidthGraph", parent),
-    _statusBar(st)
-{
-  /* Invoke Qt Designer generated QObject setup routine */
-  ui.setupUi(this);
-
-  /* Ask Tor to notify us about bandwidth updates */
-  Vidalia::torControl()->setEvent(TorEvents::Bandwidth);
-  connect(Vidalia::torControl(), SIGNAL(bandwidthUpdate(quint64,quint64)),
-          this, SLOT(updateGraph(quint64,quint64)));
-
-  /* Pressing 'Esc' or 'Ctrl+W' will close the window */
-//  setShortcut("Esc", SLOT(close()));
-//  setShortcut("Ctrl+W", SLOT(close()));
-
-  /* Bind events to actions */
-  createActions();
-
-  /* Initialize Sent/Receive data counters */
-  reset();
-  /* Hide Bandwidth Graph Settings frame */
-  showSettingsFrame(false);
-  /* Load the previously saved settings */
-  loadSettings();
-
-  /* Turn off opacity group on unsupported platforms */
-#if defined(Q_WS_WIN)
-  if(!(QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)
-       || QSysInfo::WindowsVersion < QSysInfo::WV_2000) {
-    ui.frmOpacity->setVisible(false);
-  }
-#endif
-
-#if defined(Q_WS_X11)
-  ui.frmOpacity->setVisible(false);
-#endif
-}
-
-/** Called when the user changes the UI translation. */
-void
-BandwidthGraph::retranslateUi()
-{
-  ui.retranslateUi(this);
-  setTitle(tr("Bandwidth Graph"));
-}
-
-/** Binds events to actions. */
-void
-BandwidthGraph::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
-BandwidthGraph::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
-BandwidthGraph::loadSettings()
-{
-  /* Set window opacity slider widget */
-  ui.sldrOpacity->setValue(getSetting(SETTING_OPACITY, DEFAULT_OPACITY).toInt());
-  setOpacity(ui.sldrOpacity->value());
-
-  /* Set whether the window appears on top. */
-  ui.chkAlwaysOnTop->setChecked(getSetting(SETTING_ALWAYS_ON_TOP,
-                                           DEFAULT_ALWAYS_ON_TOP).toBool());
-  if (ui.chkAlwaysOnTop->isChecked()) {
-    setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
-  } else {
-    setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
-  }
-
-  /* Set the line filter checkboxes accordingly */
-  uint filter = getSetting(SETTING_FILTER, DEFAULT_FILTER).toUInt();
-  ui.chkReceiveRate->setChecked(filter & BWGRAPH_LINE_RECV);
-  ui.chkSendRate->setChecked(filter & BWGRAPH_LINE_SEND);
-
-  /* Set whether we are plotting bandwidth as area graphs or not */
-  int graphStyle = getSetting(SETTING_STYLE, DEFAULT_STYLE).toInt();
-  if (graphStyle < 0 || graphStyle >= ui.cmbGraphStyle->count()) {
-    graphStyle = DEFAULT_STYLE;
-  }
-  ui.cmbGraphStyle->setCurrentIndex(graphStyle);
-  ui.frmGraph->setGraphStyle((GraphFrame::GraphStyle)graphStyle);
-
-  /* Set graph frame settings */
-  ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
-                               ui.chkSendRate->isChecked());
-}
-
-/** Resets the log start time. */
-void
-BandwidthGraph::reset()
-{
-  /* Set to current time */
-  if(_statusBar && _onTop)
-    _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
-BandwidthGraph::saveChanges()
-{
-  /* Hide the settings frame and reset toggle button */
-  showSettingsFrame(false);
-
-  /* Save the opacity and graph style */
-  saveSetting(SETTING_OPACITY, ui.sldrOpacity->value());
-  saveSetting(SETTING_STYLE, ui.cmbGraphStyle->currentIndex());
-
-  /* Save the Always On Top setting */
-  saveSetting(SETTING_ALWAYS_ON_TOP, ui.chkAlwaysOnTop->isChecked());
-  if (ui.chkAlwaysOnTop->isChecked()) {
-    setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
-  } else {
-    setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
-  }
-  setOpacity(ui.sldrOpacity->value());
-
-  /* Save the line filter values */
-  uint filter = 0;
-  ADD_TO_FILTER(filter, BWGRAPH_LINE_RECV, ui.chkReceiveRate->isChecked());
-  ADD_TO_FILTER(filter, BWGRAPH_LINE_SEND, ui.chkSendRate->isChecked());
-  saveSetting(SETTING_FILTER, filter);
-
-
-  /* Update the graph frame settings */
-  ui.frmGraph->setShowCounters(ui.chkReceiveRate->isChecked(),
-                               ui.chkSendRate->isChecked());
-  ui.frmGraph->setGraphStyle((GraphFrame::GraphStyle)ui.cmbGraphStyle->currentIndex());
-
-  /* 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
-BandwidthGraph::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
-BandwidthGraph::showSettingsFrame(bool show)
-{
-  static QSize minSize = minimumSize();
-
-  QSize newSize = size();
-  if (show) {
-    /* Extend the bottom of the bandwidth graph and show the settings */
-    ui.frmSettings->setVisible(true);
-    ui.btnToggleSettings->setChecked(true);
-    ui.btnToggleSettings->setText(tr("Hide Settings"));
-
-    /* 6 = vertical spacing between the settings frame and graph frame */
-    newSize.setHeight(newSize.height() + ui.frmSettings->height() + 6);
-  } else {
-    /* Shrink the height of the bandwidth graph and hide the settings */
-    ui.frmSettings->setVisible(false);
-    ui.btnToggleSettings->setChecked(false);
-    ui.btnToggleSettings->setText(tr("Show Settings"));
-
-    /* 6 = vertical spacing between the settings frame and graph frame */
-    newSize.setHeight(newSize.height() - ui.frmSettings->height() - 6);
-    setMinimumSize(minSize);
-  }
-  resize(newSize);
-}
-
-/** Sets the opacity of the Bandwidth Graph window. */
-void
-BandwidthGraph::setOpacity(int value)
-{
-  qreal newValue = value / 100.0;
-
-  /* Opacity only supported by Mac and Win32 */
-#if defined(Q_WS_MAC)
-  this->setWindowOpacity(newValue);
-  ui.lblPercentOpacity->setText(QString::number(value));
-#elif defined(Q_WS_WIN)
-  if (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based
-        && QSysInfo::WindowsVersion >= QSysInfo::WV_2000) {
-    this->setWindowOpacity(newValue);
-    ui.lblPercentOpacity->setText(QString::number(value));
-  }
-#else
-  Q_UNUSED(newValue);
-#endif
-}
-
diff --git a/src/vidalia/bwgraph/BandwidthGraph.h b/src/vidalia/bwgraph/BandwidthGraph.h
deleted file mode 100644
index 5017554..0000000
--- a/src/vidalia/bwgraph/BandwidthGraph.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-**  This file is part of Vidalia, and is subject to the license terms in the
-**  LICENSE file, found in the top level directory of this distribution. If you
-**  did not receive the LICENSE file with this file, you may obtain it from the
-**  Vidalia source package distributed by the Vidalia Project at
-**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
-**  including this file, may be copied, modified, propagated, or distributed
-**  except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file BandwidthGraph.h
-** \brief Displays a graph of Tor's bandwidth usage
-*/
-
-#ifndef _BWGRAPH_H
-#define _BWGRAPH_H
-
-#include "ui_BandwidthGraph.h"
-#include "VidaliaTab.h"
-#include "VidaliaSettings.h"
-#include "TorControl.h"
-
-#include <QDateTime>
-#include <QEvent>
-
-/** Redraw graph every 1000ms **/
-#define REFRESH_RATE    1000
-
-
-class BandwidthGraph : public VidaliaTab
-{
-  Q_OBJECT
-
-public:
-  /** Default constructor */
-  BandwidthGraph(QStatusBar *st = 0, QWidget *parent = 0);
-
-protected:
-  /** Called when the user changes the UI translation. */
-  virtual void retranslateUi();
-
-private slots:
-  /** Adds new data to the graph */
-  void updateGraph(quint64 bytesRead, quint64 bytesWritten);
-  /** Called when settings button is toggled */
-  void showSettingsFrame(bool show);
-  /** Called when the settings button is toggled */
-  void setOpacity(int value);
-  /** Called when the user saves settings */
-  void saveChanges();
-  /** Called when the user cancels changes settings */
-  void cancelChanges();
-  /** Called when the reset button is pressed */
-  void reset();
-
-private:
-  /** Create and bind actions to events **/
-  void createActions();
-  /** Loads the saved Bandwidth Graph settings */
-  void loadSettings();
-
-  /** A TorControl object used to talk to Tor. */
-  TorControl* _torControl;
-  /** A VidaliaSettings object that handles getting/saving settings */
-  VidaliaSettings* _settings;
-
-  QStatusBar *_statusBar;
-
-  /** Qt Designer generated object */
-  Ui::BandwidthGraph ui;
-};
-
-#endif
-
diff --git a/src/vidalia/bwgraph/BandwidthGraph.ui b/src/vidalia/bwgraph/BandwidthGraph.ui
deleted file mode 100644
index f05e7b9..0000000
--- a/src/vidalia/bwgraph/BandwidthGraph.ui
+++ /dev/null
@@ -1,374 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>BandwidthGraph</class>
- <widget class="QWidget" name="BandwidthGraph">
-  <property name="geometry">
-   <rect>
-    <x>0</x>
-    <y>0</y>
-    <width>593</width>
-    <height>487</height>
-   </rect>
-  </property>
-  <property name="windowTitle">
-   <string notr="true"/>
-  </property>
-  <layout class="QGridLayout" name="gridLayout">
-   <property name="rightMargin">
-    <number>12</number>
-   </property>
-   <property name="bottomMargin">
-    <number>12</number>
-   </property>
-   <item row="0" column="0">
-    <widget class="GraphFrame" name="frmGraph">
-     <property name="minimumSize">
-      <size>
-       <width>120</width>
-       <height>80</height>
-      </size>
-     </property>
-     <property name="font">
-      <font>
-       <pointsize>10</pointsize>
-      </font>
-     </property>
-     <property name="contextMenuPolicy">
-      <enum>Qt::NoContextMenu</enum>
-     </property>
-     <property name="frameShape">
-      <enum>QFrame::Box</enum>
-     </property>
-     <property name="frameShadow">
-      <enum>QFrame::Plain</enum>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="1">
-    <spacer name="verticalSpacer">
-     <property name="orientation">
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeType">
-      <enum>QSizePolicy::Expanding</enum>
-     </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>0</width>
-       <height>40</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="2" column="0">
-    <widget class="QFrame" name="frmSettings">
-     <property name="frameShape">
-      <enum>QFrame::StyledPanel</enum>
-     </property>
-     <property name="frameShadow">
-      <enum>QFrame::Raised</enum>
-     </property>
-     <layout class="QGridLayout" name="gridLayout_2">
-      <property name="sizeConstraint">
-       <enum>QLayout::SetDefaultConstraint</enum>
-      </property>
-      <property name="horizontalSpacing">
-       <number>10</number>
-      </property>
-      <property name="verticalSpacing">
-       <number>0</number>
-      </property>
-      <property name="margin">
-       <number>5</number>
-      </property>
-      <item row="0" column="0">
-       <widget class="QCheckBox" name="chkReceiveRate">
-        <property name="contextMenuPolicy">
-         <enum>Qt::NoContextMenu</enum>
-        </property>
-        <property name="toolTip">
-         <string/>
-        </property>
-        <property name="layoutDirection">
-         <enum>Qt::RightToLeft</enum>
-        </property>
-        <property name="text">
-         <string>Receive Rate</string>
-        </property>
-        <property name="checked">
-         <bool>false</bool>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="0">
-       <widget class="QCheckBox" name="chkSendRate">
-        <property name="contextMenuPolicy">
-         <enum>Qt::NoContextMenu</enum>
-        </property>
-        <property name="toolTip">
-         <string/>
-        </property>
-        <property name="layoutDirection">
-         <enum>Qt::RightToLeft</enum>
-        </property>
-        <property name="text">
-         <string>Send Rate</string>
-        </property>
-        <property name="checked">
-         <bool>false</bool>
-        </property>
-       </widget>
-      </item>
-      <item row="3" column="0">
-       <widget class="QCheckBox" name="chkAlwaysOnTop">
-        <property name="layoutDirection">
-         <enum>Qt::RightToLeft</enum>
-        </property>
-        <property name="text">
-         <string>Always on Top</string>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="1" colspan="3">
-       <widget class="QLabel" name="lblGraphStyle">
-        <property name="text">
-         <string>Style</string>
-        </property>
-        <property name="alignment">
-         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-        </property>
-       </widget>
-      </item>
-      <item row="0" column="4">
-       <widget class="QComboBox" name="cmbGraphStyle">
-        <item>
-         <property name="text">
-          <string/>
-         </property>
-         <property name="icon">
-          <iconset resource="../res/vidalia.qrc">
-           <normaloff>:/images/16x16/graph-line.png</normaloff>:/images/16x16/graph-line.png</iconset>
-         </property>
-        </item>
-        <item>
-         <property name="text">
-          <string/>
-         </property>
-         <property name="icon">
-          <iconset resource="../res/vidalia.qrc">
-           <normaloff>:/images/16x16/graph-area.png</normaloff>:/images/16x16/graph-area.png</iconset>
-         </property>
-        </item>
-       </widget>
-      </item>
-      <item row="3" column="6">
-       <widget class="QPushButton" name="btnCancelSettings">
-        <property name="text">
-         <string>Cancel</string>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="6">
-       <widget class="QPushButton" name="btnSaveSettings">
-        <property name="text">
-         <string>Save</string>
-        </property>
-       </widget>
-      </item>
-      <item row="2" column="5">
-       <spacer name="horizontalSpacer">
-        <property name="orientation">
-         <enum>Qt::Horizontal</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>40</width>
-          <height>20</height>
-         </size>
-        </property>
-       </spacer>
-      </item>
-      <item row="2" column="1" rowspan="2" colspan="4">
-       <widget class="QFrame" name="frmOpacity">
-        <property name="frameShape">
-         <enum>QFrame::NoFrame</enum>
-        </property>
-        <property name="frameShadow">
-         <enum>QFrame::Plain</enum>
-        </property>
-        <property name="lineWidth">
-         <number>0</number>
-        </property>
-        <layout class="QGridLayout" name="gridLayout3">
-         <property name="margin">
-          <number>0</number>
-         </property>
-         <property name="spacing">
-          <number>-1</number>
-         </property>
-         <item row="0" column="0" colspan="4">
-          <widget class="QSlider" name="sldrOpacity">
-           <property name="sizePolicy">
-            <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
-             <horstretch>0</horstretch>
-             <verstretch>0</verstretch>
-            </sizepolicy>
-           </property>
-           <property name="contextMenuPolicy">
-            <enum>Qt::NoContextMenu</enum>
-           </property>
-           <property name="toolTip">
-            <string>Changes the transparency of the Bandwidth Graph</string>
-           </property>
-           <property name="minimum">
-            <number>30</number>
-           </property>
-           <property name="maximum">
-            <number>100</number>
-           </property>
-           <property name="value">
-            <number>100</number>
-           </property>
-           <property name="sliderPosition">
-            <number>100</number>
-           </property>
-           <property name="tracking">
-            <bool>false</bool>
-           </property>
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="invertedAppearance">
-            <bool>false</bool>
-           </property>
-           <property name="tickPosition">
-            <enum>QSlider::NoTicks</enum>
-           </property>
-           <property name="tickInterval">
-            <number>10</number>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="1">
-          <widget class="QLabel" name="lblPercentOpacity">
-           <property name="minimumSize">
-            <size>
-             <width>25</width>
-             <height>0</height>
-            </size>
-           </property>
-           <property name="font">
-            <font>
-             <pointsize>10</pointsize>
-            </font>
-           </property>
-           <property name="contextMenuPolicy">
-            <enum>Qt::NoContextMenu</enum>
-           </property>
-           <property name="layoutDirection">
-            <enum>Qt::RightToLeft</enum>
-           </property>
-           <property name="text">
-            <string>100</string>
-           </property>
-           <property name="alignment">
-            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="2">
-          <widget class="QLabel" name="label">
-           <property name="font">
-            <font>
-             <pointsize>10</pointsize>
-            </font>
-           </property>
-           <property name="contextMenuPolicy">
-            <enum>Qt::NoContextMenu</enum>
-           </property>
-           <property name="text">
-            <string>% Opaque</string>
-           </property>
-          </widget>
-         </item>
-         <item row="1" column="3">
-          <spacer>
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-         <item row="1" column="0">
-          <spacer name="horizontalSpacer_2">
-           <property name="orientation">
-            <enum>Qt::Horizontal</enum>
-           </property>
-           <property name="sizeHint" stdset="0">
-            <size>
-             <width>40</width>
-             <height>20</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
-        </layout>
-       </widget>
-      </item>
-     </layout>
-    </widget>
-   </item>
-   <item row="1" column="0">
-    <layout class="QHBoxLayout">
-     <item>
-      <widget class="QPushButton" name="btnToggleSettings">
-       <property name="text">
-        <string>Show Settings</string>
-       </property>
-       <property name="checkable">
-        <bool>true</bool>
-       </property>
-      </widget>
-     </item>
-     <item>
-      <spacer>
-       <property name="orientation">
-        <enum>Qt::Horizontal</enum>
-       </property>
-       <property name="sizeHint" stdset="0">
-        <size>
-         <width>21</width>
-         <height>20</height>
-        </size>
-       </property>
-      </spacer>
-     </item>
-     <item>
-      <widget class="QPushButton" name="btnReset">
-       <property name="text">
-        <string>Reset</string>
-       </property>
-      </widget>
-     </item>
-    </layout>
-   </item>
-  </layout>
- </widget>
- <customwidgets>
-  <customwidget>
-   <class>GraphFrame</class>
-   <extends>QFrame</extends>
-   <header>bwgraph/GraphFrame.h</header>
-   <container>1</container>
-  </customwidget>
- </customwidgets>
- <resources>
-  <include location="../res/vidalia.qrc"/>
- </resources>
- <connections/>
-</ui>
diff --git a/src/vidalia/bwgraph/GraphFrame.cpp b/src/vidalia/bwgraph/GraphFrame.cpp
deleted file mode 100644
index c930816..0000000
--- a/src/vidalia/bwgraph/GraphFrame.cpp
+++ /dev/null
@@ -1,351 +0,0 @@
-/*
-**  This file is part of Vidalia, and is subject to the license terms in the
-**  LICENSE file, found in the top level directory of this distribution. If you
-**  did not receive the LICENSE file with this file, you may obtain it from the
-**  Vidalia source package distributed by the Vidalia Project at
-**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
-**  including this file, may be copied, modified, propagated, or distributed
-**  except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file GraphFrame.cpp
-** \brief Graphs a series of send and receive data points
-*/
-
-#include "GraphFrame.h"
-
-#include <QtGui>
-
-
-/** Default contructor */
-GraphFrame::GraphFrame(QWidget *parent)
-: QFrame(parent)
-{
-  /* Create Graph Frame related objects */
-  _recvData = new QList<qreal>();
-  _sendData = new QList<qreal>();
-  _painter = new QPainter();
-  _graphStyle = SolidLine;
-
-  /* Initialize graph values */
-  _recvData->prepend(0);
-  _sendData->prepend(0);
-  _maxPoints = getNumPoints();
-  _maxPosition = 0;
-  _showRecv = true;
-  _showSend = true;
-  _maxValue = MIN_SCALE;
-  _scaleWidth = 0;
-}
-
-/** Default destructor */
-GraphFrame::~GraphFrame()
-{
-  delete _painter;
-  delete _recvData;
-  delete _sendData;
-}
-
-/** Gets the width of the desktop, which is the maximum number of points
- * we can plot in the graph. */
-int
-GraphFrame::getNumPoints()
-{
-  return size().width() - _scaleWidth;
-}
-
-/** Adds new data points to the graph. */
-void
-GraphFrame::addPoints(qreal recv, qreal send)
-{
-  /* If maximum number of points plotted, remove oldest */
-  if (_sendData->size() == _maxPoints) {
-    _sendData->removeLast();
-    _recvData->removeLast();
-  }
-
-  /* Update the displayed maximum */
-  if (_maxPosition >= _maxPoints) {
-    _maxValue = MIN_SCALE;
-    foreach(qreal send, *_sendData)
-      if(send > _maxValue)
-        _maxValue = send;
-    foreach(qreal recv, *_recvData)
-      if(recv > _maxValue)
-        _maxValue = recv;
-    _maxPosition = 0;
-  }
-
-  /* Add the points to their respective lists */
-  _sendData->prepend(send);
-  _recvData->prepend(recv);
-
-  /* Add to the total counters */
-  _totalSend += send;
-  _totalRecv += recv;
-
-  bool maxUpdated = false;
-  /* Check for a new maximum value */
-  if (send > _maxValue) {
-    _maxValue = send;
-    maxUpdated = true;
-  }
-
-  if (recv > _maxValue) {
-    _maxValue = recv;
-    maxUpdated = true;
-  }
-
-  if (maxUpdated) {
-    _maxPosition = 0;
-  } else {
-    _maxPosition++;
-  }
-
-  this->update();
-}
-
-/** Clears the graph. */
-void
-GraphFrame::resetGraph()
-{
-  _recvData->clear();
-  _sendData->clear();
-  _recvData->prepend(0);
-  _sendData->prepend(0);
-  _maxValue = MIN_SCALE;
-  _totalSend = 0;
-  _totalRecv = 0;
-  this->update();
-}
-
-/** Toggles display of respective graph lines and counters. */
-void
-GraphFrame::setShowCounters(bool showRecv, bool showSend)
-{
-  _showRecv = showRecv;
-  _showSend = showSend;
-  this->update();
-}
-
-/** Overloads default QWidget::paintEvent. Draws the actual
- * bandwidth graph. */
-void
-GraphFrame::paintEvent(QPaintEvent *event)
-{
-  Q_UNUSED(event);
-
-  /* Set current graph dimensions */
-  _rec = this->frameRect();
-
-  /* Start the painter */
-  _painter->begin(this);
-
-  /* We want antialiased lines and text */
-  _painter->setRenderHint(QPainter::Antialiasing);
-  _painter->setRenderHint(QPainter::TextAntialiasing);
-
-  /* Fill in the background */
-  _painter->fillRect(_rec, QBrush(BACK_COLOR));
-  _painter->drawRect(_rec);
-
-  /* Paint the scale */
-  paintScale();
-  /* Plot the send/receive data */
-  paintData();
-  /* Paint the send/recv totals */
-  paintTotals();
-
-  /* Stop the painter */
-  _painter->end();
-}
-
-/** Paints an integral and an outline of that integral for each data set (send
- * and/or receive) that is to be displayed. The integrals will be drawn first,
- * followed by the outlines, since we want the area of overlapping integrals
- * to blend, but not the outlines of those integrals. */
-void
-GraphFrame::paintData()
-{
-  QVector<QPointF> recvPoints, sendPoints;
-
-  /* Convert the bandwidth data points to graph points */
-  recvPoints = pointsFromData(_recvData);
-  sendPoints = pointsFromData(_sendData);
-
-  if (_graphStyle == AreaGraph) {
-    /* Plot the bandwidth data as area graphs */
-    if (_showRecv)
-      paintIntegral(recvPoints, RECV_COLOR, 0.6);
-    if (_showSend)
-      paintIntegral(sendPoints, SEND_COLOR, 0.4);
-  }
-
-  /* Plot the bandwidth as solid lines. If the graph style is currently an
-   * area graph, we end up outlining the integrals. */
-  if (_showRecv)
-    paintLine(recvPoints, RECV_COLOR);
-  if (_showSend)
-    paintLine(sendPoints, SEND_COLOR);
-}
-
-/** Returns a list of points on the bandwidth graph based on the supplied set
- * of send or receive values. */
-QVector<QPointF>
-GraphFrame::pointsFromData(QList<qreal>* list)
-{
-  QVector<QPointF> points;
-  int x = _rec.width();
-  int y = _rec.height();
-  qreal scale = (y - (y/10)) / _maxValue;
-  qreal currValue;
-
-  /* Translate all data points to points on the graph frame */
-  points << QPointF(x, y);
-  for (int i = 0; i < list->size(); i++) {
-    currValue = y - (list->at(i) * scale);
-    if (x - SCROLL_STEP < _scaleWidth) {
-      points << QPointF(_scaleWidth, currValue);
-      break;
-    }
-    points << QPointF(x, currValue);
-    x -= SCROLL_STEP;
-  }
-  points << QPointF(_scaleWidth, y);
-  return points;
-}
-
-/** Plots an integral using the data points in <b>points</b>. The area will be
- * filled in using <b>color</b> and an alpha-blending level of <b>alpha</b>
- * (default is opaque). */
-void
-GraphFrame::paintIntegral(QVector<QPointF> points, QColor color, qreal alpha)
-{
-  /* Save the current brush, plot the integral, and restore the old brush */
-  QBrush oldBrush = _painter->brush();
-  color.setAlphaF(alpha);
-  _painter->setBrush(QBrush(color));
-  _painter->drawPolygon(points.data(), points.size());
-  _painter->setBrush(oldBrush);
-}
-
-/** Iterates the input list and draws a line on the graph in the appropriate
- * color. */
-void
-GraphFrame::paintLine(QVector<QPointF> points, QColor color, Qt::PenStyle lineStyle)
-{
-  /* Save the current brush, plot the line, and restore the old brush */
-  QPen oldPen = _painter->pen();
-  _painter->setPen(QPen(color, lineStyle));
-  _painter->drawPolyline(points.data(), points.size());
-  _painter->setPen(oldPen);
-}
-
-/** Paints selected total indicators on the graph. */
-void
-GraphFrame::paintTotals()
-{
-  int x = _scaleWidth + FONT_SIZE, y = 0;
-  int rowHeight = FONT_SIZE;
-
-#if !defined(Q_WS_MAC)
-  /* On Mac, we don't need vertical spacing between the text rows. */
-  rowHeight += 5;
-#endif
-
-  /* If total received is selected */
-  if (_showRecv) {
-    y = rowHeight;
-    _painter->setPen(RECV_COLOR);
-    _painter->drawText(x, y,
-        tr("Recv:") + " " + totalToStr(_totalRecv) +
-        " ("+tr("%1 KB/s").arg(_recvData->first(), 0, 'f', 2)+")");
-  }
-
-  /* If total sent is selected */
-  if (_showSend) {
-    y += rowHeight;
-    _painter->setPen(SEND_COLOR);
-    _painter->drawText(x, y,
-        tr("Sent:") + " " + totalToStr(_totalSend) +
-        " ("+tr("%1 KB/s").arg(_sendData->first(), 0, 'f', 2)+")");
-  }
-}
-
-/** Returns a formatted string with the correct size suffix. */
-QString
-GraphFrame::totalToStr(qreal total)
-{
-  /* Determine the correct size suffix */
-  if (total < 1024) {
-    /* Use KB suffix */
-    return tr("%1 KB").arg(total, 0, 'f', 2);
-  } else if (total < 1048576) {
-    /* Use MB suffix */
-    return tr("%1 MB").arg(total/1024.0, 0, 'f', 2);
-  } else {
-    /* Use GB suffix */
-    return tr("%1 GB").arg(total/1048576.0, 0, 'f', 2);
-  }
-}
-
-/** Returns the width in pixels of <b>label</b> using the current painter's
- * font. */
-int
-GraphFrame::labelWidth(const QString &label)
-{
-  int width = 0;
-  QFontMetrics fm = fontMetrics();
-
-  for (int i = 0; i < label.length(); i++)
-    width += fm.charWidth(label, i);
-  return width;
-}
-
-/** Paints the scale on the graph. */
-void
-GraphFrame::paintScale()
-{
-  QString label[4];
-  int width[4];
-  int top = _rec.y();
-  int bottom = _rec.height();
-  int scaleWidth = 0;
-  qreal pos;
-  qreal markStep = _maxValue * .25;
-  qreal paintStep = (bottom - (bottom/8)) / 4;
-
-  /* Compute each of the y-axis labels */
-  for (int i = 0; i < 4; i++) {
-    pos = bottom - ((i+1) * paintStep);
-    label[i] = tr("%1 KB/s").arg(markStep*(i+1), 0, 'f', 2);
-    width[i] = labelWidth(label[i]);
-    scaleWidth = qMax(scaleWidth, 2+width[i]);
-  }
-
-  /* Include a 5px margin between the y-axis and its labels */
-  _scaleWidth = scaleWidth + 5;
-
-  /* Draw the y-axis labels and horizontal marks in their correctly scaled
-   * locations */
-  for (int i = 0; i < 4; i++) {
-    pos = bottom - ((i+1) * paintStep);
-    _painter->setPen(SCALE_COLOR);
-    _painter->drawText(QPointF(_scaleWidth-width[i]-5, pos), label[i]);
-
-    _painter->setPen(GRID_COLOR);
-    _painter->drawLine(QPointF(_scaleWidth, pos),
-                       QPointF(_rec.width(), pos));
-  }
-
-  /* Draw the y-axis */
-  _painter->drawLine(_scaleWidth, top, _scaleWidth, bottom);
-}
-
-void
-GraphFrame::resizeEvent(QResizeEvent *ev)
-{
-  _maxPoints = ev->size().width() - _scaleWidth;
-  _maxPoints /= SCROLL_STEP;
-}
diff --git a/src/vidalia/bwgraph/GraphFrame.h b/src/vidalia/bwgraph/GraphFrame.h
deleted file mode 100644
index 06451aa..0000000
--- a/src/vidalia/bwgraph/GraphFrame.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
-**  This file is part of Vidalia, and is subject to the license terms in the
-**  LICENSE file, found in the top level directory of this distribution. If you
-**  did not receive the LICENSE file with this file, you may obtain it from the
-**  Vidalia source package distributed by the Vidalia Project at
-**  http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
-**  including this file, may be copied, modified, propagated, or distributed
-**  except according to the terms described in the LICENSE file.
-*/
-
-/*
-** \file GraphFrame.h
-** \brief Graphs a series of send and receive data points
-*/
-
-#ifndef _GRAPHFRAME_H
-#define _GRAPHFRAME_H
-
-#include <QApplication>
-#include <QDesktopWidget>
-#include <QFrame>
-#include <QPainter>
-#include <QPen>
-#include <QList>
-
-#define HOR_SPC       2   /** Space between data points */
-#define MIN_SCALE     10  /** 10 kB/s is the minimum scale */
-#define SCROLL_STEP   4   /** Horizontal change on graph update */
-
-#define BACK_COLOR    Qt::black
-#define SCALE_COLOR   Qt::green
-#define GRID_COLOR    Qt::darkGreen
-#define RECV_COLOR    Qt::cyan
-#define SEND_COLOR    Qt::yellow
-
-#define FONT_SIZE     11
-
-
-class GraphFrame : public QFrame
-{
-  Q_OBJECT
-
-public:
-  /** Bandwidth graph style. */
-  enum GraphStyle {
-    SolidLine = 0,  /**< Plot bandwidth as solid lines. */
-    AreaGraph       /**< Plot bandwidth as alpha blended area graphs. */
-  };
-
-  /** Default Constructor */
-  GraphFrame(QWidget *parent = 0);
-  /** Default Destructor */
-  ~GraphFrame();
-
-  /** Add data points. */
-  void addPoints(qreal recv, qreal send);
-  /** Clears the graph. */
-  void resetGraph();
-  /** Toggles display of data counters. */
-  void setShowCounters(bool showRecv, bool showSend);
-  /** Sets the graph style used to display bandwidth data. */
-  void setGraphStyle(GraphStyle style) { _graphStyle = style; }
-
-protected:
-  /** Overloaded QWidget::paintEvent() */
-  void paintEvent(QPaintEvent *event);
-
-private:
-  /** Returns the width in pixels of <b>label</b> using the current painter's
-   * font. */
-  int labelWidth(const QString &label);
-  /** Gets the width of the desktop, the max # of points. */
-  int getNumPoints();
-  /** Paints an integral and an outline of that integral for each data set
-   * (send and/or receive) that is to be displayed. */
-  void paintData();
-  /** Paints the send/receive totals. */
-  void paintTotals();
-  /** Paints the scale in the graph. */
-  void paintScale();
-  /** Returns a formatted string representation of total. */
-  QString totalToStr(qreal total);
-  /** Returns a list of points on the bandwidth graph based on the supplied set
-   * of send or receive values. */
-  QVector<QPointF> pointsFromData(QList<qreal>* list);
-  /** Paints a line with the data in <b>points</b>. */
-  void paintLine(QVector<QPointF> points, QColor color,
-                 Qt::PenStyle lineStyle = Qt::SolidLine);
-  /** Paints an integral using the supplied data. */
-  void paintIntegral(QVector<QPointF> points, QColor color, qreal alpha = 1.0);
-
-  void resizeEvent(QResizeEvent *ev);
-
-  /** Style with which the bandwidth data will be graphed. */
-  GraphStyle _graphStyle;
-  /** A QPainter object that handles drawing the various graph elements. */
-  QPainter* _painter;
-  /** Holds the received data points. */
-  QList<qreal> *_recvData;
-  /** Holds the sent data points. */
-  QList<qreal> *_sendData;
-  /** The current dimensions of the graph. */
-  QRect _rec;
-  /** The maximum data value plotted. */
-  qreal _maxValue;
-  /** The position of the local maximum in the displayed bandwidth */
-  int _maxPosition;
-  /** The maximum number of points to store. */
-  int _maxPoints;
-  /** The total data sent/recv. */
-  qreal _totalSend;
-  qreal _totalRecv;
-  /** Show the respective lines and counters. */
-  bool _showRecv;
-  bool _showSend;
-  /** Width (in pixels) of the scale marker area on the left side of the
-   * graph. */
-  int _scaleWidth;
-};
-
-#endif





More information about the tor-commits mailing list