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

[tor-commits] [vidalia-plugins/master] Allow user to enable or disable bandwidth scheduler



commit 025a6f5a0b54adf534ab90fb57be08f2272c3750
Author: Feroze Naina <ferozenaina@xxxxxxxxx>
Date:   Sun Aug 19 23:23:03 2012 +0530

    Allow user to enable or disable bandwidth scheduler
---
 bwscheduler/bwscheduler.js |   69 +++++++++++++++++++++++++++----------------
 bwscheduler/bwscheduler.ui |    4 +-
 2 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/bwscheduler/bwscheduler.js b/bwscheduler/bwscheduler.js
index 1f8b754..2ce553b 100644
--- a/bwscheduler/bwscheduler.js
+++ b/bwscheduler/bwscheduler.js
@@ -5,6 +5,7 @@ importExtension("qt.uitools");
 importExtension("qt.network");
 
 var bwscheduler = {
+    SETTING_ENABLED: "BandwidthSchedulerEnabled",
 
     weekDays : ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"],
 
@@ -20,35 +21,37 @@ var bwscheduler = {
     },
 
     updateRate: function() {
-        torrc.clear(["BandwidthRate", "BandwidthBurst"]);
-
-        var currentTime = QTime.currentTime();
-        var today = new Date()
-
-        var size = this.settings.beginReadArray("schedules");
-
-        for (var i = 0; i < size; i++) {
-            this.settings.setArrayIndex(i);
-            var day = this.settings.value("cmbDay");
-            var startTime = QTime.fromString(this.settings.value("timeStart"), "hh:mm");
-            var endTime = QTime.fromString(this.settings.value("timeEnd"), "hh:mm");
-            var bwRate = this.settings.value("spinRate");
-            var bwUnit = this.settings.value("cmbUnit");
-
-            if (startTime <= currentTime && currentTime <= endTime) {
-                if (day == "Everyday") {
-                    torrc.setValue("BandwidthRate" , bwRate + " " + bwUnit);
-                    torrc.setValue("BandwidthBurst" , bwRate + " " + bwUnit);
-                }
-                else if (day == this.weekDays[today.getDay()]) {
-                    torrc.setValue("BandwidthRate" , bwRate + " " + bwUnit);
-                    torrc.setValue("BandwidthBurst" , bwRate + " " + bwUnit);
+        if (this.settings.value(this.SETTING_ENABLED) == "true") {
+            torrc.clear(["BandwidthRate", "BandwidthBurst"]);
+
+            var currentTime = QTime.currentTime();
+            var today = new Date()
+
+            var size = this.settings.beginReadArray("schedules");
+
+            for (var i = 0; i < size; i++) {
+                this.settings.setArrayIndex(i);
+                var day = this.settings.value("cmbDay");
+                var startTime = QTime.fromString(this.settings.value("timeStart"), "hh:mm");
+                var endTime = QTime.fromString(this.settings.value("timeEnd"), "hh:mm");
+                var bwRate = this.settings.value("spinRate");
+                var bwUnit = this.settings.value("cmbUnit");
+
+                if (startTime <= currentTime && currentTime <= endTime) {
+                    if (day == "Everyday") {
+                        torrc.setValue("BandwidthRate" , bwRate + " " + bwUnit);
+                        torrc.setValue("BandwidthBurst" , bwRate + " " + bwUnit);
+                    }
+                    else if (day == this.weekDays[today.getDay()]) {
+                        torrc.setValue("BandwidthRate" , bwRate + " " + bwUnit);
+                        torrc.setValue("BandwidthBurst" , bwRate + " " + bwUnit);
+                    }
                 }
             }
-        }
 
-        this.settings.endArray();
-        torrc.apply(torControl);
+            this.settings.endArray();
+            torrc.apply(torControl);
+        }
     },
 
     updateList: function() {
@@ -240,16 +243,30 @@ var bwscheduler = {
         if (this.btnDiscard == null)
             return this.tab;
 
+        this.chkEnabled['stateChanged(int)'].connect(this, this.toggleEnabled);
         this.btnAdd['clicked()'].connect(this, this.addService);
         this.btnRemove['clicked()'].connect(this, this.removeServices);
         this.btnApply['clicked()'].connect(this, this.applyServices);
         this.btnDiscard['clicked()'].connect(this, this.updateList);
 
+        this.chkEnabled.setCheckState((this.settings.value(this.SETTING_ENABLED, "false") == "true")?Qt.Checked:Qt.Unchecked);
+
         this.updateList();
 
         return this.tab;
     },
 
+    toggleEnabled: function() {
+        var enableScheduler = (this.chkEnabled.checkState() == Qt.Checked) ? true : false;
+        this.settings.setValue(this.SETTING_ENABLED, enableScheduler.toString());
+        this.scrollArea.setEnabled(enableScheduler);
+        this.btnAdd.setEnabled(enableScheduler);
+
+        if (! enableScheduler) {
+            torrc.clear(["BandwidthRate", "BandwidthBurst"]);
+            torrc.apply(torControl);
+        }
+    },
 
     stop: function() {
         vdebug("Tutorial@stop");
diff --git a/bwscheduler/bwscheduler.ui b/bwscheduler/bwscheduler.ui
index 9b270f6..4daf621 100644
--- a/bwscheduler/bwscheduler.ui
+++ b/bwscheduler/bwscheduler.ui
@@ -30,7 +30,7 @@
    <item row="1" column="0" colspan="6">
     <widget class="QScrollArea" name="scrollArea">
      <property name="enabled">
-      <bool>true</bool>
+      <bool>false</bool>
      </property>
      <property name="minimumSize">
       <size>
@@ -123,7 +123,7 @@
    <item row="0" column="4">
     <widget class="QPushButton" name="btnAdd">
      <property name="enabled">
-      <bool>true</bool>
+      <bool>false</bool>
      </property>
      <property name="minimumSize">
       <size>



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