def populate_wifi_panel(self, scan=True): # remove everything from the existing panel self.WFP.reset() self.toggle_controls(False, ALL_WIRELESS_CONTROLS) if osmc_network.is_wifi_available(): if osmc_network.is_wifi_enabled(): self.populate_wifi_networks(scan) if self.conn_ssid: self.update_manual_DHCP_button(WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_IP_VALUES, WIRELESS_IP_LABELS) self.populate_ip_controls(self.current_network_config, WIRELESS_IP_VALUES) self.toggle_controls(True, [ WIRELESS_ADAPTER_TOGGLE, WIRELESS_SCAN_BUTTON, WIRELESS_NETWORKS, WIRELESS_DHCP_MANUAL_BUTTON ]) else: # not connected to a network self.toggle_controls(True, [ WIRELESS_ADAPTER_TOGGLE, WIRELESS_SCAN_BUTTON, WIRELESS_NETWORKS ]) self.clear_ip_controls(WIRELESS_IP_VALUES) self.setFocusId(WIRELESS_SCAN_BUTTON) else: self.setFocusId(WIRELESS_ADAPTER_TOGGLE) adapterRadioButton = self.getControl(WIRELESS_ADAPTER_TOGGLE) adapterRadioButton.setSelected(osmc_network.is_wifi_enabled()) adapterRadioButton.setEnabled(True)
def populate_wifi_panel(self, scan=False): if osmc_network.is_wifi_available(): if osmc_network.is_wifi_enabled(): # Start the wifi population thread threadRunning = False for t in threading.enumerate(): if t.getName() == WIFI_THREAD_NAME: threadRunning = True if not threadRunning: log('Starting ' + WIFI_THREAD_NAME) self.wifi_populate_bot = wifi_populate_bot(scan, self.getControl(5000), self.conn_ssid) self.wifi_populate_bot.setDaemon(True) self.wifi_populate_bot.start() self.current_network_config = osmc_network.get_connected_wifi() self.conn_ssid = None log(self.current_network_config) if 'SSID' in self.current_network_config: self.conn_ssid = self.current_network_config['SSID'] if self.conn_ssid: if 'Address' in self.current_network_config: self.update_manual_DHCP_button(WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_IP_VALUES, WIRELESS_IP_LABELS) self.populate_ip_controls(self.current_network_config, WIRELESS_IP_VALUES) self.toggle_controls(True, [WIRELESS_ADAPTER_TOGGLE, WIRELESS_NETWORKS, WIRELESS_DHCP_MANUAL_BUTTON]) if osmc_network.has_internet_connection(): # 'Status' 'Connected' status = lang(32044) + ': ' + lang(32046) else: # 'Status' 'No internet' status = lang(32044) + ': ' + lang(32047) self.wireless_status_label.setLabel(status) else: # not connected to a network self.hide_controls(WIRELESS_IP_VALUES + WIRELESS_IP_LABELS + [WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_APPLY_BUTTON, WIRELESS_RESET_BUTTON]) self.toggle_controls(True, [WIRELESS_ADAPTER_TOGGLE, WIRELESS_NETWORKS]) self.clear_ip_controls(WIRELESS_IP_VALUES) # 'Status' 'No wireless Connection' status = lang(32044) + ': ' + lang(32050) self.wireless_status_label.setLabel(status) else: # Wifi disabled self.hide_controls(ALL_WIRELESS_CONTROLS) # 'Status' 'disabled' status = lang(32044) + ': ' + lang(32048) self.wireless_status_label.setLabel(status) adapterRadioButton = self.getControl(WIRELESS_ADAPTER_TOGGLE) adapterRadioButton.setSelected(osmc_network.is_wifi_enabled()) adapterRadioButton.setEnabled(True) else: # Wifi not available self.toggle_controls(False, ALL_WIRELESS_CONTROLS) waitForNetworkRadioButton = self.getControl(WIRELESS_WAIT_FOR_NETWORK) waitForNetworkRadioButton.setSelected(osmc_network.is_connman_wait_for_network_enabled()) waitForNetworkRadioButton.setEnabled(True)
def toggle_wifi(self): self.WFP.reset() item = xbmcgui.ListItem(lang(32016)) self.toggle_controls(False, ALL_WIRELESS_CONTROLS) self.WFP.addItem(item) osmc_network.toggle_wifi_state(not osmc_network.is_wifi_enabled()) # 5 second wait to allow connman to make the changes before refreshing time.sleep(5) if not osmc_network.is_wifi_enabled(): self.current_network_config = {}
def toggle_wifi(self): self.show_busy_dialogue() self.WFP.reset() self.hide_controls(ALL_WIRELESS_CONTROLS) self.toggle_controls(True, [WIRELESS_NETWORKS]) osmc_network.toggle_wifi_state(not osmc_network.is_wifi_enabled()) # 5 second wait to allow connman to make the changes before refreshing time.sleep(5) if not osmc_network.is_wifi_enabled(): self.current_network_config = {} self.clear_busy_dialogue()
def toggle_wifi(self): self.WFP.reset() item = xbmcgui.ListItem(lang(32016)) self.hide_controls(ALL_WIRELESS_CONTROLS) self.toggle_controls(True, [WIRELESS_NETWORKS]) self.WFP.addItem(item) osmc_network.toggle_wifi_state(not osmc_network.is_wifi_enabled()) # 5 second wait to allow connman to make the changes before refreshing time.sleep(5) if not osmc_network.is_wifi_enabled(): self.current_network_config = {}
def run(self): running_dict = {} runs = 0 while not self.exit: # ask the thread to exit if wifi is no longer enabled if not osmc_network.is_wifi_enabled(): self.stop_thread() # only run the network check every 2 seconds, but allow the exit command to be checked every 10ms if runs % 200 == 0 and not self.exit: log('Updating Wifi networks') wifis = osmc_network.get_wifi_networks() running_dict.update(wifis) self.update_list_control(running_dict) # find any connected setting and load its values into the controls for k, v in running_dict.iteritems(): try: if v.getProperty('Connected') == 'True': self.current_network_config = self.get_wireless_config(k) self.populate_ip_controls(v, WIRELESS_IP_VALUES) except: pass if not self.exit and runs % 600 == 0: # every minute re-scan wifi unless the thread has been asked to exit self.wifi_scanner_bot = wifi_scanner_bot() self.wifi_scanner_bot.setDaemon(True) self.wifi_scanner_bot.start() xbmc.sleep(10) runs += 1 log('Wifi thread ended')
def run(self): running_dict = {} runs = 0 while not self.exit: # ask the thread to exit if wifi is no longer enabled if not osmc_network.is_wifi_enabled(): self.stop_thread() # only run the network check every 2 seconds, but allow the exit command to be checked every 10ms if runs % 200 == 0 and not self.exit: log('Updating Wifi networks') wifis = osmc_network.get_wifi_networks() running_dict.update(wifis) self.update_list_control(running_dict) # find any connected setting and load its values into the controls for k, v in running_dict.iteritems(): try: if v.getProperty('Connected') == 'True': self.current_network_config = self.get_wireless_config( k) self.populate_ip_controls(v, WIRELESS_IP_VALUES) except: pass if not self.exit and runs % 600 == 0: # every minute re-scan wifi unless the thread has been asked to exit self.wifi_scanner_bot = wifi_scanner_bot() self.wifi_scanner_bot.setDaemon(True) self.wifi_scanner_bot.start() xbmc.sleep(10) runs += 1 log('Wifi thread ended')
def populate_wifi_panel(self, scan=False): # remove everything from the existing panel if osmc_network.is_wifi_available(): if osmc_network.is_wifi_enabled(): self.populate_wifi_networks(scan) self.current_network_config = osmc_network.get_connected_wifi() self.conn_ssid = None if 'SSID' in self.current_network_config: self.conn_ssid = self.current_network_config['SSID'] if self.conn_ssid: self.update_manual_DHCP_button(WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_IP_VALUES, WIRELESS_IP_LABELS) self.populate_ip_controls(self.current_network_config, WIRELESS_IP_VALUES) self.toggle_controls(True, [WIRELESS_ADAPTER_TOGGLE, WIRELESS_SCAN_BUTTON, WIRELESS_NETWORKS, WIRELESS_DHCP_MANUAL_BUTTON]) if osmc_network.has_internet_connection(): # 'Status' 'Connected' status = lang(32044) + ': ' + lang(32046) else: # 'Status' 'No internet' status = lang(32044) + ': ' + lang(32047) self.wireless_status_label.setLabel(status) else:# not connected to a network self.hide_controls(WIRELESS_IP_VALUES + WIRELESS_IP_LABELS + [WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_APPLY_BUTTON, WIRELESS_RESET_BUTTON]) self.toggle_controls(True, [WIRELESS_ADAPTER_TOGGLE, WIRELESS_SCAN_BUTTON, WIRELESS_NETWORKS]) self.clear_ip_controls(WIRELESS_IP_VALUES) # 'Status' 'No wireless Connection' status = lang(32044) + ': ' + lang(32050) self.wireless_status_label.setLabel(status) else:# Wifi disabled self.hide_controls(ALL_WIRELESS_CONTROLS) # 'Status' 'disabled' status = lang(32044) + ': ' + lang(32048) self.wireless_status_label.setLabel(status) adapterRadioButton = self.getControl(WIRELESS_ADAPTER_TOGGLE) adapterRadioButton.setSelected(osmc_network.is_wifi_enabled()) adapterRadioButton.setEnabled(True) else:# Wifi not available self.toggle_controls(False, ALL_WIRELESS_CONTROLS) waitForNetworkRadioButton = self.getControl(WIRELESS_WAIT_FOR_NETWORK) waitForNetworkRadioButton.setSelected(osmc_network.is_connman_wait_for_network_enabled()) waitForNetworkRadioButton.setEnabled(True)
def setup_networking_from_preseed(self): wired = False connected = False if self.preseed_data['Interface'].startswith( 'wlan') and osmc_network.is_wifi_available(): if not osmc_network.is_wifi_enabled(): self.toggle_wifi() ssid = self.preseed_data['SSID'] encrypted = False preseed_password = None if 'Password' in self.preseed_data: encrypted = True preseed_password = self.preseed_data['Password'] connected = self.connect_to_wifi(ssid, encrypted, preseed_password, True) if self.preseed_data is None or self.preseed_data[ 'Interface'].startswith('eth') or not connected: wired = True if not osmc_network.is_ethernet_enabled(): self.toggle_ethernet() self.current_network_config = self.get_wired_config() connected = True if connected: if self.preseed_data is None or 'dhcp' in self.preseed_data[ 'Method']: self.current_network_config['Method'] = 'dhcp' else: self.current_network_config['Method'] = 'manual' self.current_network_config['Address'] = self.preseed_data[ 'Address'] self.current_network_config['Netmask'] = self.preseed_data[ 'Netmask'] if 'Gateway' in self.preseed_data: self.current_network_config['Gateway'] = self.preseed_data[ 'Gateway'] if 'DNS_1' in self.preseed_data: self.current_network_config['DNS_1'] = self.preseed_data[ 'DNS_1'] if 'DNS_2' in self.preseed_data: self.current_network_config['DNS_2'] = self.preseed_data[ 'DNS_2'] osmc_network.apply_network_changes(self.current_network_config) if wired: self.populate_wired_panel() else: self.populate_wifi_panel(False)
def setup_networking_from_preseed(self): wired = False connected = False if self.preseed_data['Interface'].startswith('wlan') and osmc_network.is_wifi_available(): if not osmc_network.is_wifi_enabled(): self.toggle_wifi() ssid = self.preseed_data['SSID'] encrypted = False preseed_password = None if 'Password' in self.preseed_data: encrypted = True preseed_password = self.preseed_data['Password'] connected = self.connect_to_wifi(ssid, encrypted, preseed_password, True) if self.preseed_data is None or self.preseed_data['Interface'].startswith('eth') or not connected: wired = True if not osmc_network.is_ethernet_enabled(): self.toggle_ethernet() self.current_network_config = self.get_wired_config() connected = True if connected: if self.preseed_data is None or 'dhcp' in self.preseed_data['Method']: self.current_network_config['Method'] = 'dhcp' else: self.current_network_config['Method'] = 'manual' self.current_network_config['Address'] = self.preseed_data['Address'] self.current_network_config['Netmask'] = self.preseed_data['Netmask'] if 'Gateway' in self.preseed_data: self.current_network_config['Gateway'] = self.preseed_data['Gateway'] if 'DNS_1' in self.preseed_data: self.current_network_config['DNS_1'] = self.preseed_data['DNS_1'] if 'DNS_2' in self.preseed_data: self.current_network_config['DNS_2'] = self.preseed_data['DNS_2'] osmc_network.apply_network_changes(self.current_network_config) if wired: self.populate_wired_panel() else: self.populate_wifi_panel(False)
def populate_wifi_panel(self, scan=False): if osmc_network.is_wifi_available(): if osmc_network.is_wifi_enabled(): # Start the wifi population thread threadRunning = False for t in threading.enumerate(): if t.getName() == WIFI_THREAD_NAME: threadRunning = True if not threadRunning: log('Starting ' + WIFI_THREAD_NAME) self.wifi_populate_bot = wifi_populate_bot( scan, self.getControl(5000), self.conn_ssid) self.wifi_populate_bot.setDaemon(True) self.wifi_populate_bot.start() self.current_network_config = osmc_network.get_connected_wifi() self.conn_ssid = None log(self.current_network_config) if 'SSID' in self.current_network_config: self.conn_ssid = self.current_network_config['SSID'] if self.conn_ssid: if 'Address' in self.current_network_config: self.update_manual_DHCP_button( WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_IP_VALUES, WIRELESS_IP_LABELS) self.populate_ip_controls(self.current_network_config, WIRELESS_IP_VALUES) self.toggle_controls(True, [ WIRELESS_ADAPTER_TOGGLE, WIRELESS_NETWORKS, WIRELESS_DHCP_MANUAL_BUTTON ]) if osmc_network.has_internet_connection(): # 'Status' 'Connected' status = lang(32044) + ': ' + lang(32046) else: # 'Status' 'No internet' status = lang(32044) + ': ' + lang(32047) self.wireless_status_label.setLabel(status) else: # not connected to a network self.hide_controls( WIRELESS_IP_VALUES + WIRELESS_IP_LABELS + [ WIRELESS_DHCP_MANUAL_BUTTON, WIRELESS_APPLY_BUTTON, WIRELESS_RESET_BUTTON ]) self.toggle_controls( True, [WIRELESS_ADAPTER_TOGGLE, WIRELESS_NETWORKS]) self.clear_ip_controls(WIRELESS_IP_VALUES) # 'Status' 'No wireless Connection' status = lang(32044) + ': ' + lang(32050) self.wireless_status_label.setLabel(status) else: # Wifi disabled self.hide_controls(ALL_WIRELESS_CONTROLS) # 'Status' 'disabled' status = lang(32044) + ': ' + lang(32048) self.wireless_status_label.setLabel(status) adapterRadioButton = self.getControl(WIRELESS_ADAPTER_TOGGLE) adapterRadioButton.setSelected(osmc_network.is_wifi_enabled()) adapterRadioButton.setEnabled(True) else: # Wifi not available self.toggle_controls(False, ALL_WIRELESS_CONTROLS) waitForNetworkRadioButton = self.getControl(WIRELESS_WAIT_FOR_NETWORK) waitForNetworkRadioButton.setSelected( osmc_network.is_connman_wait_for_network_enabled()) waitForNetworkRadioButton.setEnabled(True)