76 lines
2.6 KiB
Python
Executable file
76 lines
2.6 KiB
Python
Executable file
from core.controllers.ProfileController import ProfileController
|
|
|
|
|
|
class ConnectionManager:
|
|
def __init__(self):
|
|
self._connected_profiles = set()
|
|
self._is_synced = False
|
|
self._is_profile_being_enabled = {}
|
|
self.profile_button_objects = {}
|
|
self.available_resolutions = ['800x600', '1024x760', '1152x1080', '1280x1024',
|
|
'1920x1080', '2560x1440', '2560x1600', '1920x1440', '1792x1344', '2048x1152']
|
|
self._location_list = []
|
|
self._browser_list = []
|
|
|
|
def get_profile_button_objects(self, profile_id):
|
|
return self.profile_button_objects.get(profile_id, None)
|
|
|
|
def set_profile_button_objects(self, profile_id, profile_button_objects):
|
|
self.profile_button_objects[profile_id] = profile_button_objects
|
|
|
|
def get_available_resolutions(self, profile_id):
|
|
profile = ProfileController.get(profile_id)
|
|
if profile and hasattr(profile, 'resolution') and profile.resolution:
|
|
self.available_resolutions.append(profile.resolution)
|
|
return self.available_resolutions
|
|
|
|
def add_custom_resolution(self, resolution):
|
|
self.available_resolutions.append(resolution)
|
|
|
|
def add_connected_profile(self, profile_id):
|
|
self._connected_profiles.add(profile_id)
|
|
|
|
def remove_connected_profile(self, profile_id):
|
|
self._connected_profiles.discard(profile_id)
|
|
|
|
def is_profile_connected(self, profile_id):
|
|
return profile_id in self._connected_profiles
|
|
|
|
def get_connected_profiles(self):
|
|
return list(self._connected_profiles)
|
|
|
|
def set_synced(self, status):
|
|
self._is_synced = status
|
|
|
|
def is_synced(self):
|
|
return self._is_synced
|
|
|
|
def get_location_info(self, location_key):
|
|
if not location_key:
|
|
return None
|
|
try:
|
|
country_code, location_code = location_key.split('_')
|
|
for location in self._location_list:
|
|
if location.country_code == country_code and location.code == location_code:
|
|
return location
|
|
|
|
return None
|
|
except (ValueError, AttributeError):
|
|
return None
|
|
|
|
def store_locations(self, locations):
|
|
self._location_list = locations
|
|
|
|
def store_browsers(self, browsers):
|
|
self._browser_list = browsers
|
|
|
|
def get_browser_list(self):
|
|
return self._browser_list
|
|
|
|
def get_location_list(self):
|
|
if self.is_synced():
|
|
location_names = [
|
|
f'{location.country_code}_{location.code}' for location in self._location_list]
|
|
return location_names
|
|
else:
|
|
return []
|