Esempio n. 1
0
def add_profile():
    """
        Prompt the user to add a profile. Called when user hit "Add" button.
        Will call find_profile function. When new GPS location or wifi data is detected,
        then prompt the user to enter the name of the new profile.
        if profile found, then prompt the user that the profile already existed, prompt user to update the profile:
        Hitting OK to update, cancel to exit without updating the profile.
   """
    droid.dialogCreateSpinnerProgress("SCANNING LOCATION", "POLLING")
    droid.dialogShow()    
    gps_location=gps_stuff.poll_gps()
    wifi_network = wifi_stuff.wifi_scan();
    droid.dialogDismiss()
    selected_networks = wifi_stuff.get_selected_wifi(wifi_network)
    if len(wifi_network) > 0 or gps_location != {}:
        if len(selected_networks) <= 0 and len(wifi_network) > 0:
            while True:
                droid.dialogCreateAlert('You must choose at least 1 wifi network')
                droid.dialogSetNegativeButtonText('OK')
                droid.dialogShow()
                response = droid.dialogGetResponse().result
                if 'negative' in response[u'which']:
                    droid.dialogDismiss()
                    selected_networks = wifi_stuff.get_selected_wifi(wifi_network)
                    if len(selected_networks) > 0:
                        break
        
        p = find_profile(gps_location, wifi_networks=selected_networks)
        if p in list and p!='DEFAULT':
            droid.dialogCreateAlert('This location already exists in profile: ' + p + " Press OK to update the " + p + "profile with the newly detected wifi data." )
            droid.dialogSetPositiveButtonText('OK')
            droid.dialogSetNegativeButtonText('Cancel')
            droid.dialogShow()
            response = droid.dialogGetResponse().result
            if 'negative' not in response[u'which']:
                update_exist_profile(p,gps_location, selected_networks) 
            show_main_menu()
        else:            
            res = droid.dialogGetInput('Please enter profile name').result
            if res == None or len(res) == 0:
                show_main_menu()
            elif len(res) > MAX_PROFILE_LENGTH:
                while True:
                    droid.dialogDismiss()
                    res = droid.dialogGetInput('Name max is eight character! Please enter profile name again.').result
                    if res == None:
                        show_main_menu()
                    elif len(res) <= MAX_PROFILE_LENGTH:
                        break
            if len(res) <= MAX_PROFILE_LENGTH:
                if res not in list:
                    list.append(res)
                    put_new_profile(res,gps_location,selected_networks)
                else:
                    droid.dialogCreateAlert('Are you sure to override the existing ' + res + ' profile?', 'Choose OK to confirm')
                    droid.dialogSetPositiveButtonText('OK')
                    droid.dialogSetNegativeButtonText('Cancel')
                    droid.dialogShow()
                    response = droid.dialogGetResponse().result
                    if 'negative' not in response[u'which']:
                        put_new_profile(res,gps_location,selected_networks)
                read_settings(list.index(res))
    
    else:
        droid.dialogCreateAlert("Can't detect any valid location: No GPS data or WIFI data detected!" )
        droid.dialogShow()
        time.sleep(3)
        droid.dialogDismiss()
        show_main_menu()
Esempio n. 2
0
    #The default polling interval
    interval=60
    
    #loop forever
    while working:

        #Show the class that polling is happening
        droid.dialogCreateSpinnerProgress("SCANNING LOCATION", "POLLING")
        droid.dialogShow()

        #Give the dialog time to start
        time.sleep(3)

        #Get a list of current wifi networks first since it is
        #faster than getting gps
        current_networks=wifi_stuff.wifi_scan()
 

        #Try to find a profile that includes at least one of the wifi
        #networks present
        profile=locator_menu.find_profile(wifi_networks=current_networks)

        #If we were able to find a network other than the default
        if profile !="DEFAULT":

            #Apply the profile
            apply_profile(profile)
            
            #Get rid of the progress form.  We are done scanning.
            droid.dialogDismiss()