From 57aa4d51e37228333e56e98d9af3bfe7b278e2d1 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 5 Jun 2014 16:38:56 -0500 Subject: add icons for the vpn exit nodes --- Makefile | 2 +- changes/feature-country-code-flag | 1 + data/images/countries/nl.png | Bin 0 -> 453 bytes data/images/countries/tr.png | Bin 0 -> 492 bytes data/images/countries/us.png | Bin 0 -> 609 bytes data/resources/eipstatus.qrc | 7 +++++++ src/leap/bitmask/config/flags.py | 2 ++ src/leap/bitmask/gui/eip_status.py | 24 +++++++++++++++++++++++ src/leap/bitmask/gui/mainwindow.py | 1 + src/leap/bitmask/gui/ui/eip_status.ui | 21 +++++++++++++------- src/leap/bitmask/services/eip/eipconfig.py | 28 +++++++++++++++++++++++---- src/leap/bitmask/services/eip/vpnlauncher.py | 9 ++++++++- 12 files changed, 82 insertions(+), 13 deletions(-) create mode 100644 changes/feature-country-code-flag create mode 100644 data/images/countries/nl.png create mode 100644 data/images/countries/tr.png create mode 100644 data/images/countries/us.png create mode 100644 data/resources/eipstatus.qrc diff --git a/Makefile b/Makefile index 358af126..73437449 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ PROJFILE = data/bitmask.pro #UI files to compile UI_FILES = loggerwindow.ui mainwindow.ui wizard.ui login.ui preferences.ui eip_status.ui mail_status.ui eippreferences.ui advanced_key_management.ui #Qt resource files to compile -RESOURCES = locale.qrc loggerwindow.qrc mainwindow.qrc icons.qrc +RESOURCES = locale.qrc loggerwindow.qrc mainwindow.qrc icons.qrc eipstatus.qrc #pyuic4 and pyrcc4 binaries PYUIC = pyside-uic diff --git a/changes/feature-country-code-flag b/changes/feature-country-code-flag new file mode 100644 index 00000000..b7b53626 --- /dev/null +++ b/changes/feature-country-code-flag @@ -0,0 +1 @@ +- Show flag of country for eip exit node, if available. Related: #1232 diff --git a/data/images/countries/nl.png b/data/images/countries/nl.png new file mode 100644 index 00000000..fe44791e Binary files /dev/null and b/data/images/countries/nl.png differ diff --git a/data/images/countries/tr.png b/data/images/countries/tr.png new file mode 100644 index 00000000..be32f77e Binary files /dev/null and b/data/images/countries/tr.png differ diff --git a/data/images/countries/us.png b/data/images/countries/us.png new file mode 100644 index 00000000..10f451fe Binary files /dev/null and b/data/images/countries/us.png differ diff --git a/data/resources/eipstatus.qrc b/data/resources/eipstatus.qrc new file mode 100644 index 00000000..5d0f2924 --- /dev/null +++ b/data/resources/eipstatus.qrc @@ -0,0 +1,7 @@ + + + ../images/countries/nl.png + ../images/countries/tr.png + ../images/countries/us.png + + diff --git a/src/leap/bitmask/config/flags.py b/src/leap/bitmask/config/flags.py index 6b70659d..2f3fdde4 100644 --- a/src/leap/bitmask/config/flags.py +++ b/src/leap/bitmask/config/flags.py @@ -55,3 +55,5 @@ OPENVPN_VERBOSITY = 1 # Skip the checks in the wizard, use for testing purposes only! SKIP_WIZARD_CHECKS = False + +CURRENT_VPN_COUNTRY = None diff --git a/src/leap/bitmask/gui/eip_status.py b/src/leap/bitmask/gui/eip_status.py index 280ce79e..69ef2616 100644 --- a/src/leap/bitmask/gui/eip_status.py +++ b/src/leap/bitmask/gui/eip_status.py @@ -24,6 +24,7 @@ from functools import partial from PySide import QtCore, QtGui +from leap.bitmask.config import flags from leap.bitmask.services import get_service_display_name, EIP_SERVICE from leap.bitmask.platform_init import IS_LINUX from leap.bitmask.util.averages import RateMovingAverage @@ -416,6 +417,7 @@ class EIPStatusWidget(QtGui.QWidget): Sets the state of the widget to how it should look after EIP has stopped """ + self.set_country_code("") self._reset_traffic_rates() self.ui.eip_bandwidth.hide() @@ -582,6 +584,25 @@ class EIPStatusWidget(QtGui.QWidget): self.tr("Routing traffic through: {0}").format( provider)) + ccode = flags.CURRENT_VPN_COUNTRY + if ccode is not None: + self.set_country_code(ccode) + + def set_country_code(self, code): + """ + Set the pixmap of the given country code + + :param code: the country code + :type code: str + """ + if code is not None and len(code) == 2: + img = ":/images/countries/%s.png" % (code.lower(),) + else: + img = None + cc = self.ui.lblGatewayCountryCode + cc.setPixmap(QtGui.QPixmap(img)) + cc.setToolTip(code) + def aborted(self): """ Notify the state machine that EIP was aborted for some reason. @@ -704,3 +725,6 @@ class EIPStatusWidget(QtGui.QWidget): """ self.set_eip_status("", error=error) self.set_eip_status_icon("error") + +import eipstatus_rc +assert(eipstatus_rc) diff --git a/src/leap/bitmask/gui/mainwindow.py b/src/leap/bitmask/gui/mainwindow.py index a3b81fde..c22c8892 100644 --- a/src/leap/bitmask/gui/mainwindow.py +++ b/src/leap/bitmask/gui/mainwindow.py @@ -1465,6 +1465,7 @@ class MainWindow(QtGui.QMainWindow): self._already_started_eip = True # check for connectivity + # we might want to leave a little time here... self._check_name_resolution(domain) def _check_name_resolution(self, domain): diff --git a/src/leap/bitmask/gui/ui/eip_status.ui b/src/leap/bitmask/gui/ui/eip_status.ui index 01d6b371..ee24ca71 100644 --- a/src/leap/bitmask/gui/ui/eip_status.ui +++ b/src/leap/bitmask/gui/ui/eip_status.ui @@ -28,7 +28,7 @@ 0 - + Turn On @@ -51,7 +51,7 @@ - + @@ -70,7 +70,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -105,7 +105,7 @@ - + Qt::Horizontal @@ -118,7 +118,7 @@ - + @@ -239,13 +239,20 @@ - + Allow unencrypted traffic + + + + + + + diff --git a/src/leap/bitmask/services/eip/eipconfig.py b/src/leap/bitmask/services/eip/eipconfig.py index 09a3d257..e7419b22 100644 --- a/src/leap/bitmask/services/eip/eipconfig.py +++ b/src/leap/bitmask/services/eip/eipconfig.py @@ -110,7 +110,7 @@ class VPNGatewaySelector(object): def get_gateways_list(self): """ - Returns the existing gateways, sorted by timezone proximity. + Return the existing gateways, sorted by timezone proximity. :rtype: list of tuples (location, ip) (str, IPv4Address or IPv6Address object) @@ -148,16 +148,36 @@ class VPNGatewaySelector(object): def get_gateways(self): """ - Returns the 4 best gateways, sorted by timezone proximity. + Return the 4 best gateways, sorted by timezone proximity. :rtype: list of IPv4Address or IPv6Address object. """ gateways = [ip for location, ip in self.get_gateways_list()][:4] return gateways + def get_gateways_country_code(self): + """ + Return a dict with ipaddress -> country code mapping. + + :rtype: dict + """ + country_codes = {} + + locations = self._eipconfig.get_locations() + gateways = self._eipconfig.get_gateways() + + for idx, gateway in enumerate(gateways): + gateway_location = gateway.get('location') + + ip = self._eipconfig.get_gateway_ip(idx) + if gateway_location is not None: + ccode = locations[gateway['location']]['country_code'] + country_codes[ip] = ccode + return country_codes + def _get_timezone_distance(self, offset): ''' - Returns the distance between the local timezone and + Return the distance between the local timezone and the one with offset 'offset'. :param offset: the distance of a timezone to GMT. @@ -179,7 +199,7 @@ class VPNGatewaySelector(object): def _get_local_offset(self): ''' - Returns the distance between GMT and the local timezone. + Return the distance between GMT and the local timezone. :rtype: int ''' diff --git a/src/leap/bitmask/services/eip/vpnlauncher.py b/src/leap/bitmask/services/eip/vpnlauncher.py index dcb48e8a..9629afae 100644 --- a/src/leap/bitmask/services/eip/vpnlauncher.py +++ b/src/leap/bitmask/services/eip/vpnlauncher.py @@ -25,6 +25,7 @@ import stat from abc import ABCMeta, abstractmethod from functools import partial +from leap.bitmask.config import flags from leap.bitmask.config.leapsettings import LeapSettings from leap.bitmask.config.providerconfig import ProviderConfig from leap.bitmask.platform_init import IS_LINUX @@ -122,9 +123,9 @@ class VPNLauncher(object): leap_settings = LeapSettings() domain = providerconfig.get_domain() gateway_conf = leap_settings.get_selected_gateway(domain) + gateway_selector = VPNGatewaySelector(eipconfig) if gateway_conf == leap_settings.GATEWAY_AUTOMATIC: - gateway_selector = VPNGatewaySelector(eipconfig) gateways = gateway_selector.get_gateways() else: gateways = [gateway_conf] @@ -133,6 +134,12 @@ class VPNLauncher(object): logger.error('No gateway was found!') raise VPNLauncherException('No gateway was found!') + # this only works for selecting the first gateway, as we're + # currently doing. + ccodes = gateway_selector.get_gateways_country_code() + gateway_ccode = ccodes[gateways[0]] + flags.CURRENT_VPN_COUNTRY = gateway_ccode + logger.debug("Using gateways ips: {0}".format(', '.join(gateways))) return gateways -- cgit v1.2.3