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()
apply_profile(profile) #Get rid of the progress form. We are done scanning. droid.dialogDismiss() #Let the class know that a profile has been activated #based on the presence of wifi networks droid.makeToast("%s profile applied from wifi networks" % profile) #Set the polling interval to that indicated by the profile interval=get_polling_interval(profile) else: #Get the current gps coordinates gps_location=gps_stuff.poll_gps() #See if we can find a profile that matches the gps coordinates profile=locator_menu.find_profile(gps_location=gps_location) #If a profile was returned if profile: apply_profile(profile) #Get rid of the progress form. We are done scanning. droid.dialogDismiss() #Let the class know that a profile has been activated #based on gps location droid.makeToast("%s profile applied from GPS location" % profile)