def __registering_timeout_cb(self, data): try: odev = self.device_manager.get_main_device() if odev.is_attached() == True: self.carrier_selection_dialog.hide() return False else: if self.reg_attempts == 0: self.carrier_combobox_hbox.show() self.carrier_scan_progressbar.hide() self.cancel_button.set_sensitive(True) self.refresh_button.set_sensitive(True) model = self.carrier_combobox.get_model() if len(model) > 0: self.ok_button.set_sensitive(True) else: self.ok_button.set_sensitive(False) self.run(refresh=False) return False else: self.reg_attempts = self.reg_attempts - 1 return True except: tgcm.error("Exception") return False
def newFunc(*args, **kwargs): device = args[0] if not device.has_capability(MOBILE_MANAGER_DEVICE_STATE_INTERFACE_URI) : tgcm.error("Raise DeviceHasNotCapability") raise DeviceHasNotCapability return func(*args, **kwargs)
def __init__(self): self._conf = Config.Config(tgcm.country_support) self._bus = dbus.SystemBus() # Attempt to connect to a hypothetical existing TGCM # logging service. That must fail because that service # must be executed by TGCM exclusively try: self.__attempt_connection_logging_service() # There is an existing TGCM logging service in the # system, so it must be closed tgcm.warning('Existing TGCM Logging Service found!') self.__call_exit() except dbus.exceptions.DBusException: # It's not necessary to do nothing because that is the # expected behavior pass # Start the TGCM logging service and attempt to connect # to it try: self.__start_tgcm_logging_service() self.__attempt_connection_logging_service() self.__configure_connection_log() except OSError, err: tgcm.error('Could not execute TGCM Logging Service: %s' % err)
def __registering_timeout_cb(self, data): try: odev = self.device_manager.get_main_device() if odev.is_attached() == True: self.carrier_selection_dialog.hide() return False else: if self.reg_attempts == 0: self.carrier_combobox_hbox.show() self.carrier_scan_progressbar.hide() self.cancel_button.set_sensitive(True) self.refresh_button.set_sensitive(True) model = self.carrier_combobox.get_model() if len(model) > 0 : self.ok_button.set_sensitive(True) else: self.ok_button.set_sensitive(False) self.run(refresh=False) return False else: self.reg_attempts = self.reg_attempts - 1 return True except : tgcm.error("Exception") return False
def newFunc(*args, **kwargs): device = args[0] if not device.has_capability( MOBILE_MANAGER_DEVICE_STATE_INTERFACE_URI): tgcm.error("Raise DeviceHasNotCapability") raise DeviceHasNotCapability return func(*args, **kwargs)
def connect_to_bus(self): success = self._connection_manager.connect_to_bus(self) if not success: tgcm.error("No se ha encontrado el ppp manager") error_dialog(markup=MSG_CONN_MANAGER_NO_PPP_MANAGER_TITLE, \ msg=MSG_CONN_MANAGER_NO_PPP_MANAGER) return False else: return True
def connect_to_bus (self): success = self._connection_manager.connect_to_bus(self) if not success: tgcm.error("No se ha encontrado el ppp manager") error_dialog(markup=MSG_CONN_MANAGER_NO_PPP_MANAGER_TITLE, \ msg=MSG_CONN_MANAGER_NO_PPP_MANAGER) return False else: return True
def __on_change_pin_button_clicked(self, widget): device = self.device_manager.get_main_device() if (device is not None) and (device.get_type() == tgcm.core.DeviceManager.DEVICE_MODEM): pin_active = device.is_pin_active() if pin_active == None : return elif pin_active == True: dialog = tgcm.ui.windows.ChangePinDialog(self._settings.get_dialog()) dialog.run() else: tgcm.error("This device or not exist or not has the capability")
def __create_temporal_file(self, template_dict): try: os.system("rm -rf /tmp/em-*") # creo el fichero temporal fd, file_name = tempfile.mkstemp("", "em-") f = os.fdopen(fd, "w") f.write(TEMPLATE_DATA % template_dict) f.close() return file_name except Exception, msg: tgcm.error("error creando temporal file url %s " % msg) return None
def __init__(self, parent=None): self.device_manager = tgcm.core.FreeDesktop.DeviceManager() self.main_modem = self.device_manager.main_modem self.device_dialer = tgcm.core.FreeDesktop.DeviceDialer() self.windows_dir = os.path.join(tgcm.windows_dir, self.__class__.__name__) gtk_builder_magic(self, \ filename=os.path.join(self.windows_dir, 'CarrierDialog.ui'), \ prefix='cd') # -- Block the passed parent otherwise the Dock if parent is None: parent = tgcm.ui.ThemedDock().get_main_window() self.carrier_selection_dialog.set_transient_for(parent) odev = self.device_manager.get_main_device() if odev != None and odev.get_type( ) == tgcm.core.DeviceManager.DEVICE_MODEM: status = odev.pin_status() if not status == MobileManager.PIN_STATUS_READY: return else: tgcm.error("Exception") return self.carrier_combobox_changed_id = self.carrier_combobox.connect( "changed", self.__carrier_combobox_cb, None) cell = gtk.CellRendererPixbuf() self.carrier_combobox.pack_start(cell, False) self.carrier_combobox.add_attribute(cell, "stock_id", 0) cell = gtk.CellRendererText() self.carrier_combobox.pack_start(cell, False) self.carrier_combobox.add_attribute(cell, 'text', 1) self.carrier_selection_dialog.connect( "delete-event", self.__carrier_dialog_delete_event_cb, None) self.main_modem.connect("main-modem-removed", self.__main_modem_removed_cb) self.refresh_button.connect("clicked", self.__refresh_button_cb, None) self.ok_button.connect("clicked", self.__ok_button_cb, None) self.cancel_button.connect("clicked", self.__cancel_button_cb, None) self.timer = gobject.timeout_add(100, self.__progress_timeout_cb, None) self.carrier_combobox_hbox.show() self.carrier_scan_progressbar.hide() self.reg_attempts = 0 self.__scanning = False
def __create_temporal_file(self,template_dict): try: os.system("rm -rf /tmp/em-*") # creo el fichero temporal fd ,file_name = tempfile.mkstemp("","em-") f = os.fdopen(fd,"w") f.write(TEMPLATE_DATA % template_dict) f.close() return file_name except Exception ,msg: tgcm.error("error creando temporal file url %s " % msg) return None
def __on_change_pin_button_clicked(self, widget): device = self.device_manager.get_main_device() if (device is not None) and (device.get_type() == tgcm.core.DeviceManager.DEVICE_MODEM): pin_active = device.is_pin_active() if pin_active == None: return elif pin_active == True: dialog = tgcm.ui.windows.ChangePinDialog( self._settings.get_dialog()) dialog.run() else: tgcm.error("This device or not exist or not has the capability")
def __init__(self, parent=None): self.device_manager = tgcm.core.FreeDesktop.DeviceManager() self.main_modem = self.device_manager.main_modem self.device_dialer = tgcm.core.FreeDesktop.DeviceDialer() self.windows_dir = os.path.join(tgcm.windows_dir , self.__class__.__name__) gtk_builder_magic(self, \ filename=os.path.join(self.windows_dir, 'CarrierDialog.ui'), \ prefix='cd') # -- Block the passed parent otherwise the Dock if parent is None: parent = tgcm.ui.ThemedDock().get_main_window() self.carrier_selection_dialog.set_transient_for(parent) odev = self.device_manager.get_main_device() if odev != None and odev.get_type() == tgcm.core.DeviceManager.DEVICE_MODEM : status = odev.pin_status() if not status == MobileManager.PIN_STATUS_READY : return else: tgcm.error("Exception") return self.carrier_combobox_changed_id = self.carrier_combobox.connect("changed", self.__carrier_combobox_cb, None) cell = gtk.CellRendererPixbuf() self.carrier_combobox.pack_start(cell, False) self.carrier_combobox.add_attribute(cell, "stock_id",0) cell = gtk.CellRendererText() self.carrier_combobox.pack_start(cell, False) self.carrier_combobox.add_attribute(cell, 'text', 1) self.carrier_selection_dialog.connect("delete-event", self.__carrier_dialog_delete_event_cb, None) self.main_modem.connect("main-modem-removed", self.__main_modem_removed_cb) self.refresh_button.connect("clicked",self.__refresh_button_cb, None) self.ok_button.connect("clicked",self.__ok_button_cb, None) self.cancel_button.connect("clicked",self.__cancel_button_cb, None) self.timer = gobject.timeout_add (100, self.__progress_timeout_cb, None) self.carrier_combobox_hbox.show() self.carrier_scan_progressbar.hide() self.reg_attempts = 0 self.__scanning = False
def launch_secure_url(self, url, parent=None): #tgcm.debug("LANZANDO URL SEGURA %s" % url) current_login, current_password = self.conf.get_celular_info() if self.__should_ask_password() : response, current_login, current_password = self.__run_security_dialog(parent) if response != gtk.RESPONSE_OK: return template_dict = {"url" : url, "login": current_login, "password": current_password} file_name =self.__create_temporal_file(template_dict) if file_name is not None: webbrowser.open(file_name) else: tgcm.error("ERROR creando fichero temporal")
def __refresh_ads_success_hook(self, raw_xml, url_id): if raw_xml is None: return tgcm.debug('Advertising petition (%s) successful' % url_id) try: image_url, ad_url = self.__process_advertising_xml(raw_xml) ad_info = (url_id, image_url, ad_url) tgcm.debug('Download advertising image (%s): %s' % \ (url_id, image_url)) request = DownloadHelper.DownloadHelper2(image_url) request.read_async(self.__download_ad_success_hook, \ success_param=ad_info) except ET.ParseError, err: tgcm.error('Error parsing advertising XML: %s' % err)
def launch_secure_url(self, url, parent=None): #tgcm.debug("LANZANDO URL SEGURA %s" % url) current_login, current_password = self.conf.get_celular_info() if self.__should_ask_password(): response, current_login, current_password = self.__run_security_dialog( parent) if response != gtk.RESPONSE_OK: return template_dict = { "url": url, "login": current_login, "password": current_password } file_name = self.__create_temporal_file(template_dict) if file_name is not None: webbrowser.open(file_name) else: tgcm.error("ERROR creando fichero temporal")
def __read_async(self, success_hook, success_param, timeout, chunk_size): self.request = urllib2.Request(self._url, self._data, self._headers) try: response = self._opener.open(self.request, None, timeout) data = self.__chunk_read(response, report_hook=self.__async_report_hook) except urllib2.URLError as err: tgcm.error('Error downloading "%s": %s' % (self._url, err)) data = None except urllib2.HTTPError as err: tgcm.error('Error downloading "%s": %s' % (self._url, err)) data = None except Exception as err: tgcm.error('Error downloading "%s": %s' % (self._url, err)) data = None gobject.idle_add(success_hook, data, success_param) return False
def __read_async(self, success_hook, success_param, timeout, chunk_size): self.request = urllib2.Request(self._url, self._data, self._headers) try: response = self._opener.open(self.request, None, timeout) data = self.__chunk_read(response, \ report_hook=self.__async_report_hook) except urllib2.URLError as err: tgcm.error('Error downloading "%s": %s' % (self._url, err)) data = None except urllib2.HTTPError as err: tgcm.error('Error downloading "%s": %s' % (self._url, err)) data = None except Exception as err: tgcm.error('Error downloading "%s": %s' % (self._url, err)) data = None gobject.idle_add(success_hook, data, success_param) return False
class Advertising(gobject.GObject): __metaclass__ = Singleton.Singleton __gsignals__ = { 'updated': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, ()), } def __init__(self): gobject.GObject.__init__(self) self.config = Config.Config() theme_manager = Theme.ThemeManager() self._static_images = {} for url_id in ('main', 'service'): image_file = theme_manager.get_icon('ads', 'banner_%s.png' % url_id) image = (gtk.gdk.pixbuf_new_from_file(image_file), None) self._static_images[url_id] = image self._advertising = {} self.__load_static_images() device_dialer = FreeDesktop.DeviceDialer() device_dialer.connect('connected', self.__on_connected_cb) device_dialer.connect('disconnected', self.__on_disconnected_cb) def __load_static_images(self): for url_id in ('main', 'service'): image = self._static_images[url_id] self._advertising[url_id] = image def get_dock_advertising(self): return self._advertising['main'] def get_service_advertising(self): return self._advertising['service'] def refresh(self): now = datetime.datetime.now() service_id = self.config.get_ads_service_id() sp_id = self.config.get_ads_sp_id() sp_password = self.config.get_ads_sp_password() consumer_key = '%s@%s' % (service_id, sp_id) timestamp = now.strftime('%Y%m%d%H%M%S') m = md5.new() m.update('%s%s%s' % (sp_id, sp_password, timestamp)) signature = m.hexdigest().upper() ui = self.config.get_ads_ui() ai = 'rqid0001' token = ''.join(random.choice(string.ascii_uppercase + string.digits) \ for x in range(8)) header = [] header.append('SDPBasicAuth realm="SDPAPIs"') header.append('consumer_key="%s"' % consumer_key) header.append('signature_method="MD5"') header.append('signature="%s"' % signature) header.append('requestor_type="1"') header.append('requestor_id="%s"' % ui) header.append('token="%s"' % token) header.append('timestamp="%s"' % timestamp) header.append('version="0.1"') header = ', '.join(header) for url_id in ('main', 'service'): url = self.config.get_ads_url(url_id) url = url.replace('%ui%', ui) url = url.replace('%ai%', ai) tgcm.debug('Advertising petition (%s): %s, %s' % \ (url_id, url, header)) request = DownloadHelper.DownloadHelper2(url) request.add_header('Authorization', header) request.read_async(self.__refresh_ads_success_hook, \ success_param=url_id) def __refresh_ads_success_hook(self, raw_xml, url_id): if raw_xml is None: return tgcm.debug('Advertising petition (%s) successful' % url_id) try: image_url, ad_url = self.__process_advertising_xml(raw_xml) ad_info = (url_id, image_url, ad_url) tgcm.debug('Download advertising image (%s): %s' % \ (url_id, image_url)) request = DownloadHelper.DownloadHelper2(image_url) request.read_async(self.__download_ad_success_hook, \ success_param=ad_info) except ET.ParseError, err: tgcm.error('Error parsing advertising XML: %s' % err) except Exception, err: tgcm.error('Unknown advertising error: %s' % err)
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
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