Exemple #1
0
    def onClick(self, controlId):
        self.msg = ""
        self.status_label.setLabel(self.msg)

        # Activate connection from list
        if controlId == self.control_list_id:
            item = self.list.getSelectedItem()
            self.make_connection(item)

            state, stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
            print 'After effect', state
            if state != 100:
                self.make_connection(item, ask_password=True)

        # Add connection button
        elif controlId == self.control_add_connection_button_id:
            self.add_hidden()
            state, stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
            if state == 120:
                self.add_hidden()

            self.updateList()

        elif controlId == self.control_cancel_button_id:
            self.closeDialog()
Exemple #2
0
    def add_wireless_sub(self, ssid, encryption, connection_created, con_path, asked=False):
        # Prompt for key
        key = ""
        if not encryption == 'NONE':
            message = 'Enter Password:'
            if asked:
                message = 'Connection Failed, please enter password again:'
            kb = xbmc.Keyboard("", message, False)

            kb.doModal()
            if (kb.isConfirmed()):
                key = kb.getText()
                errors = qfpynm.validate_wifi_input(key, encryption)

            if key == "" or errors != '':
                self.msg = getLS(30109)
                self.status_label.setLabel(self.msg)
                return True, connection_created, con_path
        if encryption == 'WEP':
            wep_alg = 'shared'
        else:
            wep_alg = ''
        if connection_created == False:
            con_path = qfpynm.add_wifi(ssid, key, encryption, wep_alg, True)
        else:
            aUUID = qfpynm.get_con_uuid_by_path(con_path)
            qfpynm.update_wifi(aUUID, key, encryption)
            qfpynm.activate_connection(aUUID)

        asked = False

        for i in range(1, 150):
            state, stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
            self.msg = stateTXT
            self.status_label.setLabel(self.msg)
            # Do not exit directly just to be sure.
            # If trying with a bad key when wifi is disconnected do not give state 60 but 30....
            # better never to disconnect wifi and only deactivate c
            if (i > 10 and state == 60) or (i > 10 and state == 30) or (state == 100 and i > 2):
                break
            time.sleep(1)
            self.msg = ''
            self.status_label.setLabel(self.msg)
            time.sleep(1)
        if state == 100:
            self.msg = getLS(30120)  # "Connected!"
            self.status_label.setLabel(self.msg)
            xbmc.executebuiltin('XBMC.ActivateWindow(Home)')
            self.close()
            return True, True, con_path
        if (state == 60 or state == 30) and encryption != "NONE":
            self.msg = getLS(30121)  # "Not Autorized!"
            self.status_label.setLabel(self.msg)
            return False, True, con_path

        self.msg = qfpynm.nm_state.get(state, '')  # "Connection failed"
        self.status_label.setLabel(self.msg)
        return True, True, con_path
 def add_wireless_sub(self, ssid, encryption, connection_created, con_path):
     #Prompt for key
     key = ""
     if not encryption == 'NONE':
         kb = xbmc.Keyboard("", getLS(30104), False)
         kb.doModal()
         if (kb.isConfirmed()):
             key=kb.getText()
             errors = qfpynm.validate_wifi_input(key,encryption)
        
         if key == "" or errors != '':
             self.msg = getLS(30109)  
             self.status_label.setLabel(self.msg)
             return True, connection_created, con_path
     if encryption == 'WEP':
         wep_alg = 'shared'
     else:
         wep_alg = ''
     if connection_created == False:
         con_path = qfpynm.add_wifi(ssid,key,encryption,wep_alg,self.disable_ipv6 )
     else:
         aUUID = qfpynm.get_con_uuid_by_path(con_path)
         qfpynm.update_wifi(aUUID, key, encryption)
         qfpynm.activate_connection(aUUID)
         
     for i in range(1, 150):
         state,stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
         self.msg = stateTXT
         self.status_label.setLabel(self.msg)
         # Do not exit directly just to be sure.
         # If trying with a bad key when wifi is disconnected do not give state 60 but 30....
         # better never to disconnect wifi and only deactivate c
         if (i > 10 and state == 60) or (i > 10 and state == 30)  or (state == 100 and i >2):
             break
         time.sleep(1)
         self.msg = ''
         self.status_label.setLabel(self.msg)
         time.sleep(1)
     if state == 100:
         self.msg = getLS(30120) #"Connected!"
         self.status_label.setLabel(self.msg)
         return True, True, con_path
     if (state == 60  or state == 30) and encryption != "NONE":
         self.msg = getLS(30121) #"Not Autorized!"
         self.status_label.setLabel(self.msg)
         return False, True, con_path
     
     self.msg = getLS(30122) #"Connection failed"
     self.status_label.setLabel(self.msg)      
     return True, True, con_path
Exemple #4
0
    def updateList(self):
        saved_wifi = []
        uuid_map = {}
        active = qfpynm.get_wireless_networks()
        wifi_connections = qfpynm.get_connections()
        self.list.reset()

        for connection in wifi_connections:
            saved_wifi.append(connection.get('ssid'))
            uuid_map[connection.get('ssid')] = connection.get('uuid')

        print "Active List: ", active

        print "Active: ", saved_wifi

        print "Wifi: ", wifi_connections

        for connection_dict in active:

            status = ''

            state, stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())

            if connection_dict['connected'] == True:
                color = 'red'
                if state == 100:
                    color = 'green'
                elif state == 50:
                    color = 'yellow'

                status = "[B][COLOR %s]*[/COLOR][/B]" % (color,)
            else:
                status = ""

            uuid = uuid_map.get(connection_dict['essid'], '')

            item = xbmcgui.ListItem(
                label=status, label2=connection_dict['essid'])
            item.setProperty('ssid', connection_dict['essid'])
            item.setProperty('uuid', uuid)
            item.setProperty('encryption', connection_dict['encrypt'])
            item.setProperty('active', str(connection_dict['connected']))

            self.list.addItem(item)
Exemple #5
0
    def onClick(self, controlId):
        self.msg = ""
        self.status_label.setLabel(self.msg)

        #Activate connection from list
        if controlId == self.control_list_id:
            #position = self.list.getSelectedPosition()

            #Get UUID
            item = self.list.getSelectedItem()

            uuid =  item.getProperty('uuid')
            encryption = item.getProperty('encryption')
            #print uuid

            self.activate_connection(uuid)
            for i in range(1, 100):
                state,stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
                msg = stateTXT
                self.status_label.setLabel(msg)
                if (state == 100 and i >2):
                    break
                if (i > 2 and state == 60):
                    if encryption not in ['WPA','WEP']:
                        print ("Strange encryption:" + encryption)
                        break
                    #Prompt for key
                    key = ""
                    kb = xbmc.Keyboard("", getLS(30104), False)
                    kb.doModal()
                    if (kb.isConfirmed()):
                        key=kb.getText()
                        errors = qfpynm.validate_wifi_input(key,encryption)

                    if key == "" or errors != '':
                        self.msg = getLS(30109)
                        self.status_label.setLabel(self.msg)
                        break

                    qfpynm.update_wifi(uuid, key, encryption)
                    qfpynm.activate_connection(uuid)
                    continue
                time.sleep(1)
                msg = ''
                self.status_label.setLabel(msg)
                time.sleep(1)
            if state == 100:
                msg = getLS(30120) #"Connected!"

            elif state == 60:
                msg = getLS(30121) #"Not Autorized!"
            else:
                msg = getLS(30122) #"Connection failed"
            self.updateList()
            self.status_label.setLabel(msg)

        #Add connection button
        elif controlId == self.control_add_connection_button_id:
            import addConnection
            addConnectionUI = addConnection.GUI("script_linux_nm1-add.xml", __cwd__, "default")
            self.close()
            del addConnectionUI

        #disconnect button
        elif controlId == self.control_disconnect_button_id:
            self.disconnect()

            for i in range(1, 20):
                state,stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
                self.msg = stateTXT
                self.status_label.setLabel(self.msg)

                if (state == 30):
                    break
                time.sleep(1)
            self.updateList()

        #Delete button
        elif controlId == self.control_delete_button_id:
            item = self.list.getSelectedItem()

            uuid =  item.getProperty('uuid')

            self.delete_connection(uuid)

            msg = getLS(30115) #Refreshing
            self.status_label.setLabel(msg)

            time.sleep(2)
            self.updateList()

            msg = getLS(30126) #Done
            self.status_label.setLabel(msg)
            self.setFocus(self.control_add_connection_button)

        #Status button
        elif controlId == self.control_status_button_id:
            state,stateTXT = qfpynm.get_nm_state()
            msg = stateTXT
            self.status_label.setLabel(msg)

        #cancel dialog
        elif controlId == self.control_cancel_button_id:
            self.closeDialog()
Exemple #6
0
    def make_connection(self, item, ask_password=False):

        if item.getProperty('active') == 'True':
            return True

        ssid = item.getProperty('ssid')
        uuid = item.getProperty('uuid')
        encryption = item.getProperty('encryption')

        # print uuid
        # if ask_password:
        #     key = ""
        #     kb = xbmc.Keyboard("", getLS(30104), False)
        #     kb.doModal()
        #     if (kb.isConfirmed()):
        #         key=kb.getText()
        #         errors = qfpynm.validate_wifi_input(key,encryption)

        #     if key == "" or errors != '':
        #         self.msg = getLS(30109)
        #         self.status_label.setLabel(self.msg)
        #     else:
        #         qfpynm.update_wifi(uuid, key, encryption)
        #         qfpynm.activate_connection(uuid)
        # else:
        if uuid != '':
            self.activate_connection(uuid)
        else:
            self.add_wireless(ssid, encryption)
            state, stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
            self.updateList()

        asked = False

        for i in range(1, 150):
            state, stateTXT = qfpynm.get_device_state(qfpynm.get_wifi_device())
            msg = stateTXT
            self.status_label.setLabel(msg)
            if (state == 100 and i > 2):
                break
            if (i > 2 and state == 60):
                if encryption not in ['WPA', 'WEP']:
                    print("Strange encryption:" + encryption)
                    break
                # Prompt for key
                key = ""

                message = 'Enter Password:'
                if asked:
                    message = 'Connection Failed, please enter password again:'

                kb = xbmc.Keyboard("", message, False)
                kb.doModal()

                if (kb.isConfirmed()):
                    key = kb.getText()
                    asked = True
                    errors = qfpynm.validate_wifi_input(key, encryption)

                if key == "" or errors != '':
                    self.msg = getLS(30109)
                    self.status_label.setLabel(self.msg)
                    break

                qfpynm.update_wifi(uuid, key, encryption)
                qfpynm.activate_connection(uuid)
                continue
            time.sleep(1)
            msg = msg
            self.status_label.setLabel(msg)

        if state == 100:
            msg = getLS(30120)  # "Connected!"

        elif state == 60:
            msg = getLS(30121)  # "Not Autorized!"
        else:
            msg = qfpynm.nm_state.get(state, '')  # "Connection failed"

        self.updateList()
        self.status_label.setLabel(msg)

        if state == 100:
            xbmc.executebuiltin('XBMC.ActivateWindow(Home)')
            self.close()
            return True
        return False