Пример #1
0
    def __linkbutton_global_uri_hook(self, widget, url):
        '''
        Global URI hook to gtk.LinkButton widgets. This hook check if there is an
        active connection before opening the URI, and if that is not the case it
        displays an error dialog
        '''

        result = urlparse.urlparse(url)

        # Help URI: open the help manual
        if result.scheme == 'help':
            sections = [result.netloc]
            self.__openhelp(sections)

        # Dialog URI: open a specific configuration dialog
        elif result.scheme == 'dialog':
            dialog_id = result.netloc

            # Change billing day dialog
            if dialog_id == 'change_billing_day':
                self.traffic_zone.show_change_billing_day_dialog()

            # Unrecognized dialog, do nothing
            else:
                pass

        # URL URI: check if there is an active connection before opening the URI, and if
        # that is not the case it displays an error dialog
        else:
            is_connected = self._conn_manager.is_connected()
            if is_connected:
                webbrowser.open(url)
            else:
                title = _('Not connected')
                markup = _(
                    'The web page cannot be opened because you are not connected'
                )
                message = _('Please connect and try again')

                toplevel = widget.get_toplevel()
                parent = toplevel if toplevel.is_toplevel() else None

                warning_dialog(message,
                               markup=markup,
                               title=title,
                               parent=parent)
Пример #2
0
    def close_app(self):
        _close = True
        main_modem = tgcm.core.MainModem.MainModem()
        if main_modem.is_connected():
            app_name = self._conf.get_app_name()
            response = warning_dialog( \
                    msg=MSG_CONN_MANAGER_APP_CLOSE % (app_name, app_name), \
                    title=MSG_CONN_MANAGER_APP_CLOSE_TITLE, \
                    buttons=gtk.BUTTONS_OK_CANCEL)

            # -- If the user responds with OK we will close the application
            # -- even some failures are detected. This is the behavior under
            # -- windows too.
            if response == gtk.RESPONSE_OK:
                # -- Avoid the automatic reconnection as we are going to exit
                self.reconnect_on_disconnect = False

                # -- Get the reference to the NM object for disconnecting correctly
                nm_dev = main_modem.current_device().nm_dev
                nm_dev.Disconnect()

                # -- Wait until the modem is off but use a timeout for the worst case!
                time_start = time.time()
                timeout = 10  # -- Arbitrary timeout value
                time_end = (time_start + timeout)
                while (time_end > time.time()) and (main_modem.is_connected()):
                    while gtk.events_pending():
                        gtk.main_iteration()

                # -- If the modem is still connected we have a problem. In that
                # -- case show an error message but go ahead closing
                # -- the Tgcm so that the user disconnects the modem manually
                if main_modem.is_connected():
                    if tgcm.country_support == 'de':
                        msgInfo = _(
                            "Please try removing the Mobile Internet Device for assuring\nthat the WWAN connection is down."
                        )
                    else:
                        msgInfo = _(
                            "Please try removing the Mobile Internet Device for assuring\nthat the 2G/3G/4G connection is down."
                        )

                    error_dialog(markup=_("Unexpected disconnection failure"), \
                            msg=msgInfo)
                else:
                    main_modem.turn_off()

                _close = True
            else:
                _close = False
        else:
            main_modem.turn_off()
            _close = True

        return _close
Пример #3
0
    def __linkbutton_global_uri_hook(self, widget, url):
        '''
        Global URI hook to gtk.LinkButton widgets. This hook check if there is an
        active connection before opening the URI, and if that is not the case it
        displays an error dialog
        '''

        result = urlparse.urlparse(url)

        # Help URI: open the help manual
        if result.scheme == 'help':
            sections = [result.netloc]
            self.__openhelp(sections)

        # Dialog URI: open a specific configuration dialog
        elif result.scheme == 'dialog':
            dialog_id = result.netloc

            # Change billing day dialog
            if dialog_id == 'change_billing_day':
                self.traffic_zone.show_change_billing_day_dialog()

            # Unrecognized dialog, do nothing
            else:
                pass

        # URL URI: check if there is an active connection before opening the URI, and if
        # that is not the case it displays an error dialog
        else:
            is_connected = self._conn_manager.is_connected()
            if is_connected:
                webbrowser.open(url)
            else:
                title = _('Not connected')
                markup = _('The web page cannot be opened because you are not connected')
                message = _('Please connect and try again')

                toplevel = widget.get_toplevel()
                parent = toplevel if toplevel.is_toplevel() else None

                warning_dialog(message, markup=markup, title=title, parent=parent)
Пример #4
0
    def close_app(self):
        _close = True
        main_modem = tgcm.core.MainModem.MainModem()
        if main_modem.is_connected():
            app_name = self._conf.get_app_name()
            response = warning_dialog( \
                    msg=MSG_CONN_MANAGER_APP_CLOSE % (app_name, app_name), \
                    title=MSG_CONN_MANAGER_APP_CLOSE_TITLE, \
                    buttons=gtk.BUTTONS_OK_CANCEL)

            # -- If the user responds with OK we will close the application
            # -- even some failures are detected. This is the behavior under
            # -- windows too.
            if response == gtk.RESPONSE_OK:
                # -- Avoid the automatic reconnection as we are going to exit
                self.reconnect_on_disconnect = False

                # -- Get the reference to the NM object for disconnecting correctly
                nm_dev = main_modem.current_device().nm_dev
                nm_dev.Disconnect()

                # -- Wait until the modem is off but use a timeout for the worst case!
                time_start = time.time()
                timeout = 10  # -- Arbitrary timeout value
                time_end = (time_start + timeout)
                while (time_end > time.time()) and (main_modem.is_connected()):
                    while gtk.events_pending():
                        gtk.main_iteration()

                # -- If the modem is still connected we have a problem. In that
                # -- case show an error message but go ahead closing
                # -- the Tgcm so that the user disconnects the modem manually
                if main_modem.is_connected():
                    if tgcm.country_support == 'de':
                        msgInfo=_("Please try removing the Mobile Internet Device for assuring\nthat the WWAN connection is down.")
                    else:
                        msgInfo=_("Please try removing the Mobile Internet Device for assuring\nthat the 2G/3G/4G connection is down.")

                    error_dialog(markup=_("Unexpected disconnection failure"), \
                            msg=msgInfo)
                else:
                    main_modem.turn_off()

                _close = True
            else:
                _close = False
        else:
            main_modem.turn_off()
            _close = True

        return _close
Пример #5
0
    def connect_to_connection(self, connection_settings = None, force_connection = False, \
                action = None, bookmark_info = None, url = None, smart_connector = False):
        self.abort_now_flag = False
        self.smart_connector=smart_connector
        device_type=connection_settings["deviceType"]
        connection_name=connection_settings["name"]
        tgcm.info("Trying to connect to %s" % connection_name)
        if self.connect_to_bus() != True:
            return -1

        network_connection_status = self._connection_manager.ppp_manager.nmConnectionState()

        if (device_type==tgcm.core.FreeDesktop.DEVICE_WLAN or device_type==tgcm.core.FreeDesktop.DEVICE_WLAN_PROFILE):
            odev = self.mcontroller.get_wifi_device()
            if odev == None:
                return -1
            if self._connection_settings_manager.is_wifi_ap_available(connection_settings)==False:
                return -1

        if (device_type==tgcm.core.FreeDesktop.DEVICE_WIRED):
            odev = self.mcontroller.get_wired_device()
            if odev == None:
                return -1

        elif (device_type==tgcm.core.FreeDesktop.DEVICE_MODEM):

            if self._connection_manager.is_device_selected() == False:
                return -1

            odev = self.mcontroller.get_main_device()

            if odev.get_card_status() is not CARD_STATUS_READY:
                return -1

            if odev == None or odev.get_type() != tgcm.core.DeviceManager.DEVICE_MODEM:
                self.show_no_available_device_error()
                return -1

            if odev.is_roaming() and  bool(self._conf.check_policy('show-roaming-warning')):
                if tgcm.country_support == "es":
                    message = _("You are about to connect you in roaming and your customary data fares do not apply for the traffic that consummate abroad. Inform yourself of your roaming data fares in the 22119 (free call cost in the European Union; from other countries applicable price to calls with destination Spain according to roaming fare of the line). To control your bill you can define alerts in Escritorio Movistar and will receive notifications when reaching a certain amount of data spent.")
                else:
                    message = _("You're about to connect while abroad. Network operators have different charges for data usage and costs can soon mount up. To set up alerts so you know approximately how much data you have used go to Settings / Alerts.")
                title = _("Roaming alert")
                response = warning_dialog(msg=message, title=title)
                if response != gtk.RESPONSE_OK:
                    return -2

            if not odev.has_capability(MOBILE_MANAGER_DEVICE_STATE_INTERFACE_URI) :
                self.cardmanager = None
            else:
                self.cardmanager = odev
                if network_connection_status == PPP_STATUS_DISCONNECTED:
                    if self.cardmanager.get_card_status() != CARD_STATUS_READY:
                        if smart_connector == False:
                            error_dialog(markup=MSG_CONN_MANAGER_NO_CARDMANAGER_TITLE, \
                                    msg=MSG_CONN_MANAGER_NO_CARDMANAGER)
                        return -1

        if action != None:
            self.action = action

        if bookmark_info != None:
            self.bookmark_info = bookmark_info

        if url != None:
            self.url = url

        if network_connection_status == NetworkManager.State.CONNECTED :
            if self.actual_connection is not None and connection_settings["uuid"]==self.actual_connection["uuid"]:
                self.launch_service()
                return 0

            if force_connection == False:
                ret = self.__detect_active_connection_dialog(connection_name, action, bookmark_info)
            else:
                ret = 3

            if ret == 1 or ret < 0:
                return 0 #Cancelled by the user
            elif ret == 2 :
                self.launch_service()
                return 0
            elif ret == 3:
                self._connection_manager.ppp_manager.stop()
                gtk_sleep(0.1);
                self.waiting_connection = connection_settings


        self.reconnect_on_disconnect=None

        password=None
        if connection_settings["ask_password"] == True:
            password = self._ask_password (connection_name)
            if password is None:
                return 0 #Cancelled by the user


        #Reload connection info from gconf based on SIM characteristics
        try:
            if (connection_settings["origin"]!="networkmanager" or connection_settings["ask_password"]==True):
                connection_settings=self._connection_settings_manager.get_connection_info_dict_from_gconf(connection_settings['gconf_path'])
                self._connection_settings_manager.add_wwan_connection(connection_settings,write_gconf_if_required=False,update_if_possible=True,password=password)
                gtk_sleep(1.5);
                #time.sleep(1) #We must give some time to update the connection

        except (RuntimeError, TypeError, NameError):
            tgcm.error("Error in update")
            pass


        self._conf.set_proxy(connection_settings)

        ret=self._connection_manager.ppp_manager.start(connection_settings,odev)
        if ret!=0:
            self.action = None
            self.bookmark_info =None

        return ret
Пример #6
0
    def connect_to_connection(self, connection_settings = None, force_connection = False, \
                action = None, bookmark_info = None, url = None, smart_connector = False):
        self.abort_now_flag = False
        self.smart_connector = smart_connector
        device_type = connection_settings["deviceType"]
        connection_name = connection_settings["name"]
        tgcm.info("Trying to connect to %s" % connection_name)
        if self.connect_to_bus() != True:
            return -1

        network_connection_status = self._connection_manager.ppp_manager.nmConnectionState(
        )

        if (device_type == tgcm.core.FreeDesktop.DEVICE_WLAN
                or device_type == tgcm.core.FreeDesktop.DEVICE_WLAN_PROFILE):
            odev = self.mcontroller.get_wifi_device()
            if odev == None:
                return -1
            if self._connection_settings_manager.is_wifi_ap_available(
                    connection_settings) == False:
                return -1

        if (device_type == tgcm.core.FreeDesktop.DEVICE_WIRED):
            odev = self.mcontroller.get_wired_device()
            if odev == None:
                return -1

        elif (device_type == tgcm.core.FreeDesktop.DEVICE_MODEM):

            if self._connection_manager.is_device_selected() == False:
                return -1

            odev = self.mcontroller.get_main_device()

            if odev.get_card_status() is not CARD_STATUS_READY:
                return -1

            if odev == None or odev.get_type(
            ) != tgcm.core.DeviceManager.DEVICE_MODEM:
                self.show_no_available_device_error()
                return -1

            if odev.is_roaming() and bool(
                    self._conf.check_policy('show-roaming-warning')):
                if tgcm.country_support == "es":
                    message = _(
                        "You are about to connect you in roaming and your customary data fares do not apply for the traffic that consummate abroad. Inform yourself of your roaming data fares in the 22119 (free call cost in the European Union; from other countries applicable price to calls with destination Spain according to roaming fare of the line). To control your bill you can define alerts in Escritorio Movistar and will receive notifications when reaching a certain amount of data spent."
                    )
                else:
                    message = _(
                        "You're about to connect while abroad. Network operators have different charges for data usage and costs can soon mount up. To set up alerts so you know approximately how much data you have used go to Settings / Alerts."
                    )
                title = _("Roaming alert")
                response = warning_dialog(msg=message, title=title)
                if response != gtk.RESPONSE_OK:
                    return -2

            if not odev.has_capability(
                    MOBILE_MANAGER_DEVICE_STATE_INTERFACE_URI):
                self.cardmanager = None
            else:
                self.cardmanager = odev
                if network_connection_status == PPP_STATUS_DISCONNECTED:
                    if self.cardmanager.get_card_status() != CARD_STATUS_READY:
                        if smart_connector == False:
                            error_dialog(markup=MSG_CONN_MANAGER_NO_CARDMANAGER_TITLE, \
                                    msg=MSG_CONN_MANAGER_NO_CARDMANAGER)
                        return -1

        if action != None:
            self.action = action

        if bookmark_info != None:
            self.bookmark_info = bookmark_info

        if url != None:
            self.url = url

        if network_connection_status == NetworkManager.State.CONNECTED:
            if self.actual_connection is not None and connection_settings[
                    "uuid"] == self.actual_connection["uuid"]:
                self.launch_service()
                return 0

            if force_connection == False:
                ret = self.__detect_active_connection_dialog(
                    connection_name, action, bookmark_info)
            else:
                ret = 3

            if ret == 1 or ret < 0:
                return 0  #Cancelled by the user
            elif ret == 2:
                self.launch_service()
                return 0
            elif ret == 3:
                self._connection_manager.ppp_manager.stop()
                gtk_sleep(0.1)
                self.waiting_connection = connection_settings

        self.reconnect_on_disconnect = None

        password = None
        if connection_settings["ask_password"] == True:
            password = self._ask_password(connection_name)
            if password is None:
                return 0  #Cancelled by the user

        #Reload connection info from gconf based on SIM characteristics
        try:
            if (connection_settings["origin"] != "networkmanager"
                    or connection_settings["ask_password"] == True):
                connection_settings = self._connection_settings_manager.get_connection_info_dict_from_gconf(
                    connection_settings['gconf_path'])
                self._connection_settings_manager.add_wwan_connection(
                    connection_settings,
                    write_gconf_if_required=False,
                    update_if_possible=True,
                    password=password)
                gtk_sleep(1.5)
                #time.sleep(1) #We must give some time to update the connection

        except (RuntimeError, TypeError, NameError):
            tgcm.error("Error in update")
            pass

        self._conf.set_proxy(connection_settings)

        ret = self._connection_manager.ppp_manager.start(
            connection_settings, odev)
        if ret != 0:
            self.action = None
            self.bookmark_info = None

        return ret