From 59f97e46c85e7727aa9b5e87da5c419d428a00c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Touceda?= Date: Wed, 24 Jul 2013 13:50:42 -0300 Subject: Logout at close if the user logged in --- src/leap/gui/mainwindow.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/leap/gui') diff --git a/src/leap/gui/mainwindow.py b/src/leap/gui/mainwindow.py index 6fe3e72d..8a729bae 100644 --- a/src/leap/gui/mainwindow.py +++ b/src/leap/gui/mainwindow.py @@ -1322,6 +1322,11 @@ class MainWindow(QtGui.QMainWindow): """ logger.debug('About to quit, doing cleanup...') + if self._srp_auth is not None: + if self._srp_auth.get_session_id() is not None or \ + self._srp_auth.get_token() is not None: + self._srp_auth.logout() + logger.debug('Cleaning pidfiles') self._cleanup_pidfiles() -- cgit v1.2.3 From db18ad67d4149b5f5a6f68db1f52abd91f6f9373 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 25 Jul 2013 11:41:15 +0200 Subject: reset rates when disconnecting --- src/leap/gui/statuspanel.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/leap/gui') diff --git a/src/leap/gui/statuspanel.py b/src/leap/gui/statuspanel.py index ac0f5162..3e0377f9 100644 --- a/src/leap/gui/statuspanel.py +++ b/src/leap/gui/statuspanel.py @@ -126,6 +126,16 @@ class StatusPanelWidget(QtGui.QWidget): self._up_rate = RateMovingAverage() self._down_rate = RateMovingAverage() + def _reset_traffic_rates(self): + """ + Resets up and download rates, and cleans up the labels. + """ + self._up_rate.reset() + self._down_rate.reset() + zeroed = {VPNManager.TUNTAP_WRITE_KEY: 0, + VPNManager.TUNTAP_READ_KEY: 0} + self.update_vpn_status(zeroed) + def _update_traffic_rates(self, up, down): """ Updates up and download rates. @@ -286,6 +296,7 @@ class StatusPanelWidget(QtGui.QWidget): Sets the state of the widget to how it should look after EIP has stopped """ + self._reset_traffic_rates() self.ui.btnEipStartStop.setText(self.tr("Turn ON")) self.ui.btnEipStartStop.disconnect(self) self.ui.btnEipStartStop.clicked.connect( -- cgit v1.2.3 From b9c3fcd9ea6469185f7e7f483eeffb7b346e9dad Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 25 Jul 2013 17:38:28 +0200 Subject: Make the rates clickable to alternate between rates and totals. Closes: #3249, #3232 --- src/leap/gui/statuspanel.py | 99 ++++++++++++++++++++++++++++++++++-------- src/leap/gui/ui/statuspanel.ui | 63 +++++++++++++++++++++++---- 2 files changed, 135 insertions(+), 27 deletions(-) (limited to 'src/leap/gui') diff --git a/src/leap/gui/statuspanel.py b/src/leap/gui/statuspanel.py index 3e0377f9..7c824e01 100644 --- a/src/leap/gui/statuspanel.py +++ b/src/leap/gui/statuspanel.py @@ -75,8 +75,12 @@ class RateMovingAverage(object): traff = [traffic for (ts, traffic) in data] times = [ts for (ts, traffic) in data] - deltatraffic = traff[-1] - first(traff) - deltat = (times[-1] - first(times)).seconds + try: + deltatraffic = traff[-1] - first(traff) + deltat = (times[-1] - first(times)).seconds + except IndexError: + deltatraffic = 0 + deltat = 0 try: rate = float(deltatraffic) / float(deltat) / 1024 @@ -84,6 +88,15 @@ class RateMovingAverage(object): rate = 0 return rate + def get_total(self): + """ + Gets the total accumulated throughput. + """ + try: + return self._data[-1][1] / 1024 + except TypeError: + return 0 + class StatusPanelWidget(QtGui.QWidget): """ @@ -93,6 +106,10 @@ class StatusPanelWidget(QtGui.QWidget): start_eip = QtCore.Signal() stop_eip = QtCore.Signal() + DISPLAY_TRAFFIC_RATES = True + RATE_STR = "%14.2f KB/s" + TOTAL_STR = "%14.2f Kb" + def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) @@ -118,6 +135,27 @@ class StatusPanelWidget(QtGui.QWidget): self._set_eip_icons() self._set_traffic_rates() + self._make_status_clickable() + + def _make_status_clickable(self): + """ + Makes upload and download figures clickable. + """ + onclicked = self._on_VPN_status_clicked + self.ui.btnUpload.clicked.connect(onclicked) + self.ui.btnDownload.clicked.connect(onclicked) + + def _on_VPN_status_clicked(self): + """ + SLOT + TRIGGER: self.ui.btnUpload.clicked + self.ui.btnDownload.clicked + + Toggles between rate and total throughput display for vpn + status figures. + """ + self.DISPLAY_TRAFFIC_RATES = not self.DISPLAY_TRAFFIC_RATES + self.update_vpn_status(None) # refresh def _set_traffic_rates(self): """ @@ -126,15 +164,16 @@ class StatusPanelWidget(QtGui.QWidget): self._up_rate = RateMovingAverage() self._down_rate = RateMovingAverage() + self.ui.btnUpload.setText(self.RATE_STR % (0,)) + self.ui.btnDownload.setText(self.RATE_STR % (0,)) + def _reset_traffic_rates(self): """ Resets up and download rates, and cleans up the labels. """ self._up_rate.reset() self._down_rate.reset() - zeroed = {VPNManager.TUNTAP_WRITE_KEY: 0, - VPNManager.TUNTAP_READ_KEY: 0} - self.update_vpn_status(zeroed) + self.update_vpn_status(None) def _update_traffic_rates(self, up, down): """ @@ -151,7 +190,7 @@ class StatusPanelWidget(QtGui.QWidget): def _get_traffic_rates(self): """ - Gets the traffic rates. + Gets the traffic rates (in KB/s). :returns: a tuple with the (up, down) rates :rtype: tuple @@ -161,6 +200,18 @@ class StatusPanelWidget(QtGui.QWidget): return (up.get_average(), down.get_average()) + def _get_traffic_totals(self): + """ + Gets the traffic total throughput (in Kb). + + :returns: a tuple with the (up, down) totals + :rtype: tuple + """ + up = self._up_rate + down = self._down_rate + + return (up.get_total(), down.get_total()) + def _set_eip_icons(self): """ Sets the EIP status icons for the main window and for the tray @@ -317,18 +368,30 @@ class StatusPanelWidget(QtGui.QWidget): TRIGGER: VPN.status_changed Updates the download/upload labels based on the data provided - by the VPN thread - """ - upload = float(data[VPNManager.TUNTAP_WRITE_KEY] or "0") - download = float(data[VPNManager.TUNTAP_READ_KEY] or "0") - self._update_traffic_rates(upload, download) - uprate, downrate = self._get_traffic_rates() - - upload_str = "%14.2f KB/s" % (uprate,) - self.ui.lblUpload.setText(upload_str) - - download_str = "%14.2f KB/s" % (downrate,) - self.ui.lblDownload.setText(download_str) + by the VPN thread. + + :param data: a dictionary with the tcp/udp write and read totals. + If data is None, we just will refresh the display based + on the previous data. + :type data: dict + """ + if data: + upload = float(data[VPNManager.TCPUDP_WRITE_KEY] or "0") + download = float(data[VPNManager.TCPUDP_READ_KEY] or "0") + self._update_traffic_rates(upload, download) + + if self.DISPLAY_TRAFFIC_RATES: + uprate, downrate = self._get_traffic_rates() + upload_str = self.RATE_STR % (uprate,) + download_str = self.RATE_STR % (downrate,) + + else: # display total throughput + uptotal, downtotal = self._get_traffic_totals() + upload_str = self.TOTAL_STR % (uptotal,) + download_str = self.TOTAL_STR % (downtotal,) + + self.ui.btnUpload.setText(upload_str) + self.ui.btnDownload.setText(download_str) def update_vpn_state(self, data): """ diff --git a/src/leap/gui/ui/statuspanel.ui b/src/leap/gui/ui/statuspanel.ui index fd675d35..3482ac7c 100644 --- a/src/leap/gui/ui/statuspanel.ui +++ b/src/leap/gui/ui/statuspanel.ui @@ -6,7 +6,7 @@ 0 0 - 542 + 384 477 @@ -140,9 +140,33 @@ - + + + + 0 + 0 + + + + + 100 + 0 + + + + + 120 + 16777215 + + + + PointingHandCursor + - 0.0 KB/s + 0.0 KB/s + + + true @@ -172,10 +196,34 @@ - - + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 120 + 16777215 + + + + PointingHandCursor + - 0.0 KB/s + 0.0 KB/s + + + true @@ -233,9 +281,6 @@ - lblProvider - status_rows - globalStatusBox -- cgit v1.2.3