[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [vidalia-plugins/master] Finish tutorial plugin



commit 3087bc3c51bbbe4f36aaa6bfa532f60869af1b77
Author: Tomás Touceda <chiiph@xxxxxxxxxxxxxx>
Date:   Tue Apr 17 19:48:18 2012 -0300

    Finish tutorial plugin
---
 tutorial/tutorial.js |   75 ++++++++++++++++++++++++++++++++++++------
 tutorial/tutorial.ui |   88 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+), 11 deletions(-)

diff --git a/tutorial/tutorial.js b/tutorial/tutorial.js
index 197928e..24d55f9 100644
--- a/tutorial/tutorial.js
+++ b/tutorial/tutorial.js
@@ -4,19 +4,60 @@ importExtension("qt.gui");
 importExtension("qt.uitools");
 
 var tutorial = {
+    From: "From",
+    Sent: "Sent",
+    Recv: "Recv",
+
     start: function() {
 		    vdebug("Tutorial@start");
         torControl["bandwidthUpdate(quint64, quint64)"].connect(this, this.saveBandwidth);
+        this.tab = new VidaliaTab("Display bandwidth history", "BandwidthHistory");
+
+        this.recv = parseInt(this.tab.getSetting(this.Sent, 0));
+        this.sent = parseInt(this.tab.getSetting(this.Recv, 0));
+        this.from = this.tab.getSetting(this.From, "");
+
+        if(this.from.length == 0)
+            this.from = QDateTime.currentDateTime().toString();
+
+        // null labels so that we don't update them until the GUI is created
+        this.lblFrom = null;
+        this.lblSent = null;
+        this.lblRecv = null;
     },
 
     saveBandwidth: function(recv, sent) {
         vdebug("Tutorial::Recv", recv);
         vdebug("Totorial::Sent", sent);
+
+        this.recv += recv;
+        this.sent += sent;
+        this.tab.saveSetting(this.Recv, this.recv);
+        this.tab.saveSetting(this.Sent, this.sent);
+        this.tab.saveSetting(this.From, this.from);
+
+        if(this.lblFrom)
+            this.lblFrom.text = this.from;
+        if(this.lblSent)
+            this.lblSent.text = this.sent.toString();
+        if(this.lblRecv)
+            this.lblRecv.text = this.recv.toString();
+    },
+
+    resetCounters: function() {
+        this.recv = 0;
+        this.sent = 0;
+        this.from = QDateTime.currentDateTime().toString();
+        this.saveBandwidth(0,0);
     },
 
     buildGUI: function() {
         vdebug("Tutorial@buildGUI");
         // Load the GUI file
+
+        if(this.tab)
+            delete this.tab;
+
         this.tab = new VidaliaTab("Display bandwidth history", "BandwidthHistory");
 
         var file = new QFile(pluginPath+"/tutorial/tutorial.ui");
@@ -28,25 +69,37 @@ var tutorial = {
         this.tab.setLayout(layout);
         file.close();
 
-        var groupBox = this.widget.children()[findWidget(this.widget, "browserBox")];
-        if(groupBox == null) {
+        var grpBandwidth = this.widget.children()[findWidget(this.widget, "grpBandwidth")];
+        if(grpBandwidth == null)
+            return this.tab;
+
+        this.lblFrom = grpBandwidth.children()[findWidget(grpBandwidth, "lblFrom")];
+        if(this.lblFrom == null)
+            return this.tab;
+
+        this.lblSent = grpBandwidth.children()[findWidget(grpBandwidth, "lblSent")];
+        if(this.lblSent == null)
+            return this.tab;
+
+        this.lblRecv = grpBandwidth.children()[findWidget(grpBandwidth, "lblRecv")];
+        if(this.lblRecv == null)
+            return this.tab;
+
+        this.btnReset = grpBandwidth.children()[findWidget(grpBandwidth, "btnReset")];
+        if(this.btnReset == null)
             return this.tab;
-        }
 
-        this.btnSave = this.widget.children()[findWidget(this.widget, "btnSave")];
-        if(this.btnSave != null) {
-            this.btnSave["clicked()"].connect(this, this.saveSettings);
-        }
+        this.lblFrom.text = this.from;
+        this.lblSent.text = this.sent.toString();
+        this.lblRecv.text = this.recv.toString();
 
-        this.btnLaunch = groupBox.children()[findWidget(groupBox, "btnLaunch")];
-        if(this.btnLaunch != null) {
-            this.btnLaunch["clicked()"].connect(this, this.startSubProcess);
-        }
+        this.btnReset["clicked()"].connect(this, this.resetCounters);
 
         return this.tab;
     },
 
     stop: function() {
         vdebug("Tutorial@stop");
+        this.saveBandwidth(0,0);
     },
 };
diff --git a/tutorial/tutorial.ui b/tutorial/tutorial.ui
new file mode 100644
index 0000000..317c70c
--- /dev/null
+++ b/tutorial/tutorial.ui
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Form</class>
+ <widget class="QWidget" name="Form">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QGroupBox" name="grpBandwidth">
+     <property name="title">
+      <string>Bandwidth history</string>
+     </property>
+     <layout class="QGridLayout" name="gridLayout">
+      <item row="2" column="0">
+       <widget class="QLabel" name="lblSentLabel_2">
+        <property name="text">
+         <string>&lt;b&gt;Recieved:&lt;/b&gt;</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="0">
+       <widget class="QLabel" name="lblSentLabel">
+        <property name="text">
+         <string>&lt;b&gt;Sent:&lt;/b&gt;</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="0">
+       <widget class="QLabel" name="lblFromLabel">
+        <property name="text">
+         <string>&lt;b&gt;From:&lt;/b&gt;</string>
+        </property>
+        <property name="alignment">
+         <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+        </property>
+       </widget>
+      </item>
+      <item row="0" column="1" colspan="2">
+       <widget class="QLabel" name="lblFrom">
+        <property name="text">
+         <string>TextLabel</string>
+        </property>
+       </widget>
+      </item>
+      <item row="1" column="1" colspan="2">
+       <widget class="QLabel" name="lblSent">
+        <property name="text">
+         <string>TextLabel</string>
+        </property>
+       </widget>
+      </item>
+      <item row="2" column="1" colspan="2">
+       <widget class="QLabel" name="lblRecv">
+        <property name="text">
+         <string>TextLabel</string>
+        </property>
+       </widget>
+      </item>
+      <item row="4" column="2">
+       <widget class="QPushButton" name="btnReset">
+        <property name="text">
+         <string>Reset</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits