From a0b39365a3bd8a731094666458ac7173fc463454 Mon Sep 17 00:00:00 2001 From: SimplifiedPrivacy Date: Tue, 10 Nov 2026 14:45:46 -0500 Subject: [PATCH] Phasing out legacy edit page --- gui/v2/actions/menu_coordinator.py | 17 - gui/v2/ui/pages/editor_page.py | 1018 ---------------------------- 2 files changed, 1035 deletions(-) delete mode 100755 gui/v2/ui/pages/editor_page.py diff --git a/gui/v2/actions/menu_coordinator.py b/gui/v2/actions/menu_coordinator.py index cb5e66b..f828786 100644 --- a/gui/v2/actions/menu_coordinator.py +++ b/gui/v2/actions/menu_coordinator.py @@ -3,7 +3,6 @@ from core.models.manage.database_recovery import wipe_and_kill_entire_app from core.infrastructure.state_management.global_state_controller import connected_system_profile_id, connected_session_profile_ids, is_connected from core.observers.Notifications import Notifications, EventType from core.models.enum_models import ProtocolChoice -from core.services.profiles.update_profile import update_profile # from core.controllers.SessionStateController import SessionStateController # from core.services.networking.systemwide.systemwide_wireguard import change_port_then_reconnect @@ -388,22 +387,6 @@ def delete_profile_action(profile_id: int, ui_caller: Callable) -> Result: return Result(valid=True) # this doesn't mean it deleted, just that it launched. -def edit_profile( - profile_id: int, - key: str, - new_value: str, - ui_caller: Callable -): - """Thread in background the updating of the profile""" - take_action( - action=update_profile, - ui_caller=ui_caller, - profile_id=profile_id, - key=key, - new_value=new_value - ) - - @register_action(ResultError.DELETE_DB) def shut_down_and_wipe() -> Result: """Attempt a graceful close of profiles, then wipe the database regardless.""" diff --git a/gui/v2/ui/pages/editor_page.py b/gui/v2/ui/pages/editor_page.py deleted file mode 100755 index bf0f298..0000000 --- a/gui/v2/ui/pages/editor_page.py +++ /dev/null @@ -1,1018 +0,0 @@ -import os - -from PyQt6.QtWidgets import ( - QLabel, QPushButton, QLineEdit, QTextEdit, QFrame, QDialog, - QVBoxLayout, QHBoxLayout, QMessageBox, QGraphicsDropShadowEffect -) -from PyQt6.QtGui import QPixmap, QIcon, QPainter, QColor, QTransform -from PyQt6.QtCore import Qt, QSize, QTimer, QPointF -from PyQt6 import QtCore, QtGui - -from core.infrastructure.state_management.global_state_controller import is_synced -from core.controllers.ProfileController import ProfileController -from core.controllers.LocationController import LocationController -from core.models.Result import Result, ResultError -from core.controllers.profile_state.data_filters import get_supported_protocols_for_location -from core.models.BaseProfile import ProfileType - -from gui.v2.ui.styles.css.editor_css import BUTTON_STYLE_ONE -from gui.v2.ui.pages.Page import Page -from gui.v2.ui.pages.browser_page import BrowserPage -from gui.v2.ui.pages.location_page import LocationPage -from gui.v2.ui.pages.screen_page import ScreenPage -from gui.v2.ui.popups.confirmation_popup import ConfirmationPopup -from gui.v2.ui.popups.error_popup import ErrorPopup -from gui.v2.workers.page_data_worker import PageDataWorker -from gui.v2.actions.menu_profiles import match_core_profiles -from gui.v2.actions.menu_coordinator import edit_profile, sync_now -class EditorPage(Page): - SINGBOX_PROTOCOLS = ("hysteria2", "vless") - PROTOCOL_BUTTON_ASSETS = { - "hysteria2": "hystria2", - } - - def __init__(self, page_stack, main_window, prepared=None): - super().__init__("Editor", page_stack, main_window) - self.page_stack = page_stack - self.update_status = main_window - self.connection_manager = main_window.connection_manager - self.labels = [] - self.buttons = [] - self.title.setGeometry(570, 40, 185, 40) - self.title.setText("Edit Profile") - - self.button_apply.setVisible(True) - self.button_apply.clicked.connect(self.go_selected) - - self.button_back.setVisible(True) - try: - self.button_back.clicked.disconnect() - except TypeError: - pass - self.button_back.clicked.connect(self.go_back) - - self.name_handle = QLabel(self) - self.name_handle.setGeometry(110, 70, 400, 30) - self.name_handle.setStyleSheet('color: #cacbcb;') - self.name_handle.setText("Profile Name:") - - self.name_hint = QLabel(self) - self.name_hint.setGeometry(265, 100, 190, 20) - self.name_hint.setStyleSheet( - 'color: #888888; font-size: 10px; font-style: italic;') - self.name_hint.setText("Click here to edit profile name") - self.name_hint.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter) - - self.name = QLineEdit(self) - self.name.setPlaceholderText("Enter name") - self.name.setGeometry(265, 70, 190, 30) - self.name.setStyleSheet( - "color: cyan; border: 1px solid #666666; border-radius: 3px; background-color: rgba(0, 0, 0, 0.3);") - self.name.setCursor(QtCore.Qt.CursorShape.IBeamCursor) - self.name.focusInEvent = lambda event: self.name_hint.hide() - self.name.focusOutEvent = lambda event: self.name_hint.show( - ) if not self.name.text() else self.name_hint.hide() - - self.name.textChanged.connect( - lambda text: self.name_hint.hide() if text else self.name_hint.show()) - - self.temp_changes = {} - self.original_values = {} - self.res_hint_shown = False - self.display.setGeometry(QtCore.QRect(0, 60, 540, 405)) - self.display.hide() - - self.garaje = QLabel(self) - self.garaje.setGeometry(QtCore.QRect(0, 70, 540, 460)) - - self.brow_disp = QLabel(self) - self.brow_disp.setGeometry(QtCore.QRect(0, 50, 540, 460)) - self.brow_disp.setPixmap( - QPixmap(os.path.join(self.btn_path, "browser only.png"))) - self.brow_disp.hide() - self.brow_disp.lower() - - self._prefetched_profiles = prepared - self._editor_workers = set() - self.is_synced = is_synced() - - def showEvent(self, event): - """Refresh data. This runs every time the widget is displayed""" - self.is_synced = is_synced() - - @staticmethod - def prepare_data(custom_window): - return ProfileController.get_all() - - def _selected_profiles_str(self): - menu_page = self.find_menu_page() - if menu_page is not None and menu_page.selected_profiles: - return ', '.join( - [f"Profile_{profile['profile_number']}" for profile in menu_page.selected_profiles]) - profile_id = getattr(self.update_status, 'current_profile_id', None) - if profile_id is not None: - return f"Profile_{int(profile_id)}" - return '' - - def update_name_value(self): - original_name = self.data_profile.get('name', '') - new_name = self.name.text() - if original_name != new_name: - self.update_temp_value('name', new_name) - else: - pass - - def go_back(self): - selected_profiles_str = self._selected_profiles_str() - if self.has_unsaved_changes(selected_profiles_str): - self.show_unsaved_changes_popup() - else: - self.custom_window.navigator.navigate("menu") - - def find_menu_page(self): - return self.custom_window.navigator.get_cached("menu") - - def find_resume_page(self): - return self.custom_window.navigator.get_cached("resume") - - def find_protocol_page(self): - return self.custom_window.navigator.get_cached("protocol") - - def showEvent(self, event): - super().showEvent(event) - self.res_hint_shown = False - if self._selected_profile_in_cache(): - self.extraccion() - return - worker = PageDataWorker("editor", EditorPage.prepare_data, self.custom_window) - worker.data_ready.connect( - lambda name, profiles: self._on_editor_data_ready(profiles)) - worker.failed.connect( - lambda name, error: self._on_editor_data_failed(error)) - worker.finished.connect( - lambda w=worker: self._cleanup_editor_worker(w)) - self._editor_workers.add(worker) - worker.start() - - def _on_editor_data_ready(self, profiles): - self._prefetched_profiles = profiles - self.extraccion() - - def _on_editor_data_failed(self, error): - self.update_status.update_status(f"Editor data load failed: {error}") - self.extraccion() - - def _cleanup_editor_worker(self, worker): - self._editor_workers.discard(worker) - worker.deleteLater() - - def _selected_profile_in_cache(self): - if not self._prefetched_profiles: - return False - selected = self._selected_profiles_str() - if not selected: - return False - try: - profile_id = int(selected.split('_')[1]) - except (IndexError, ValueError): - return False - return profile_id in self._prefetched_profiles - - def extraccion(self): - self.data_profile = {} - for label in self.labels: - label.deleteLater() - self.labels = [] - for button in self.buttons: - button.deleteLater() - self.buttons = [] - - selected_profiles_str = self._selected_profiles_str() - menu_page = self.find_menu_page() - if menu_page: - if self._prefetched_profiles is not None: - new_profiles = self._prefetched_profiles - else: - new_profiles = ProfileController.get_all() - self.profiles_data = match_core_profiles( - new_profiles, - getattr(self.update_status, "gui_config_file", None), - ) - self.data_profile = self.profiles_data[selected_profiles_str].copy( - ) - - profile_id = int(selected_profiles_str.split('_')[1]) - self.data_profile['id'] = profile_id - - if selected_profiles_str in self.temp_changes: - for key, value in self.temp_changes[selected_profiles_str].items(): - self.data_profile[key] = value - - self.name.textChanged.connect(self.update_name_value) - self.evaluate_option_labels(self.data_profile, selected_profiles_str) - - - def evaluate_option_labels(self, data_profile, selected_profile_str): - """Figure out which data can be changed, so the UI only displays those choices""" - - protocol = data_profile.get("protocol", None) - profile_type = data_profile.get("connection", None) - location_codes = data_profile.get("location", None) - - if not profile_type or not protocol or not location_codes: - error_msg = "This profile lacks a profile type, protocol, or location." - self.show_a_popup(message=error_msg, title="Missing fields") - return - - - print(f"in evaluate_option_labels, location_codes is {location_codes} and profile_type is {profile_type}") - supported_protocols_result = get_supported_protocols_for_location(location_codes=location_codes, profile_type=profile_type) - - if not supported_protocols_result.valid: - error_msg = "This profile lacks supported locations." - self.show_a_popup(message=error_msg, title="Invalid location") - return - - supported_protocols = supported_protocols_result.data - - if not supported_protocols: - error_msg = "This profile lacks supported locations." - self.show_a_popup(message=error_msg, title="Invalid location") - - if profile_type == "system-wide": - self.process_and_show_labels(data_profile, { - "protocol": supported_protocols, - "connection": ['system-wide'], - "location": self.connection_manager.get_location_list(), - }, selected_profile_str) - - else: - # Session profiles can't change protocols yet. - self.process_and_show_labels(data_profile, { - "protocol": [protocol], - "connection": ['browser-only', 'system-wide'], - "location": self.connection_manager.get_location_list(), - "browser": self.connection_manager.get_browser_list(), - "dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', '')) - }, selected_profile_str) - - # elif protocol in self.SINGBOX_PROTOCOLS: - - # elif protocol == "residential" or protocol == "hidetor": - # self.process_and_show_labels(data_profile, { - # "protocol": ['residential', 'wireguard', 'hidetor'], - # "connection": ['tor', 'just proxy'], - # "location": self.connection_manager.get_location_list(), - # "browser": self.connection_manager.get_browser_list(), - # "dimentions": self.connection_manager.get_available_resolutions(data_profile.get('id', '')) - # }, selected_profile_str) - - # elif protocol == "open": - # self.process_and_show_labels(data_profile, { - # "protocol": ['open'] - # }, selected_profile_str) - - - def process_and_show_labels(self, data_profile, parameters, selected_profile_str): - """Populate the images in the center of the arrows, on the right hand side, with relevant choices""" - - protocol = data_profile.get('protocol', "") - connection = data_profile.get('connection', "") - location = data_profile.get('location', "") - profile_id = data_profile.get('id') - profile_obj = ProfileController.get(profile_id) - - operator_name_string = profile_obj.location.operator.name - print(f"operator_name_string is {operator_name_string}") - - country_garaje = location - name = data_profile.get('name', "") - self.name.setText(name) - - if protocol == "hidetor": - if connection == "just proxy": - self.display.setPixmap(QPixmap(os.path.join( - self.btn_path, f"icon_{location}.png"))) - else: - self.display.setPixmap(QPixmap(os.path.join( - self.btn_path, f"hdtor_{location}.png"))) - self.display.show() - self.display.setGeometry(0, 100, 400, 394) - - self.display.setScaledContents(True) - - self.garaje.hide() - self.brow_disp.hide() - - if protocol == "wireguard": - self.display.setGeometry(0, 60, 540, 405) - self.display.show() - self.display.setPixmap(QPixmap(os.path.join( - self.btn_path, f"wireguard_{location}.png"))) - self.garaje.hide() - if connection == "browser-only": - is_supported = data_profile.get('browser_supported', False) - image_name = "browser only.png" if is_supported else "unsupported_browser_only.png" - self.brow_disp.setPixmap( - QPixmap(os.path.join(self.btn_path, image_name))) - self.brow_disp.show() - else: - self.brow_disp.hide() - - if protocol in self.SINGBOX_PROTOCOLS: - if protocol == "vless": - self.display.setGeometry(0, 90, 540, 405) - else: - self.display.setGeometry(0, 60, 540, 405) - self.display.show() - # self.display.setPixmap(self._encrypted_proxy_display_pixmap( - # protocol, location).scaled( - - if operator_name_string == 'Simplified Privacy': - singbox_image_path = f"{protocol}_{location}.png" - else: - singbox_image_path = "system_wide_global.png" - - print(f"using singbox_image_path of {singbox_image_path}") - self.display.setPixmap(QPixmap(os.path.join( - self.btn_path, singbox_image_path)).scaled( - self.display.size(), - Qt.AspectRatioMode.KeepAspectRatio, - Qt.TransformationMode.SmoothTransformation)) - self.garaje.hide() - self.brow_disp.hide() - - if protocol == "residential": - self.display.setGeometry(0, 60, 540, 405) - self.brow_disp.show() - self.garaje.show() - - self.display.hide() - if country_garaje: - country_garaje = 'brazil' - self.garaje.setPixmap(QPixmap(os.path.join( - self.btn_path, f"{country_garaje} garaje.png"))) - - # profile_id = data_profile.get('id') - # profile_obj = ProfileController.get(profile_id) - - location_info = None - if location: - try: - if '_' in location: - country_code, location_code = location.split('_', 1) - location_info = LocationController.get( - country_code, location_code) - except Exception: - location_info = None - - operator_name = "" - l_name = "" - o_name = "" - n_key = "" - - if location_info: - if hasattr(location_info, 'operator') and location_info.operator: - operator_name = location_info.operator.name - o_name = location_info.operator.name - n_key = location_info.operator.nostr_public_key - - l_name = f"{location_info.country_name}, {location_info.name}" if hasattr( - location_info, 'country_name') else "" - - if operator_name != 'Simplified Privacy' and operator_name != "" and protocol not in ('hidetor', *self.SINGBOX_PROTOCOLS): - text_color = "white" - if profile_obj and profile_obj.is_session_profile(): - text_color = "black" - - l_img = QLabel(self) - l_img.setGeometry(20, 125, 150, 150) - pixmap_loc = QPixmap(os.path.join( - self.btn_path, f"icon_{location}.png")) - l_img.setPixmap(pixmap_loc) - l_img.setScaledContents(True) - l_img.show() - self.labels.append(l_img) - - info_txt = QTextEdit(self) - info_txt.setGeometry(180, 120, 300, 250) - info_txt.setReadOnly(True) - info_txt.setFrameStyle(QFrame.Shape.NoFrame) - info_txt.setStyleSheet( - f"background: transparent; border: none; color: {text_color}; font-size: 19px;") - info_txt.setVerticalScrollBarPolicy( - Qt.ScrollBarPolicy.ScrollBarAlwaysOff) - info_txt.setHorizontalScrollBarPolicy( - Qt.ScrollBarPolicy.ScrollBarAlwaysOff) - info_txt.setWordWrapMode( - QtGui.QTextOption.WrapMode.WrapAtWordBoundaryOrAnywhere) - info_txt.setText( - f"Location: {l_name}\n\nOperator: {o_name}") - info_txt.show() - self.labels.append(info_txt) - - nostr_txt = QTextEdit(self) - nostr_txt.setGeometry(20, 300, 450, 170) - nostr_txt.setReadOnly(True) - nostr_txt.setFrameStyle(QFrame.Shape.NoFrame) - nostr_txt.setStyleSheet( - f"background: transparent; border: none; color: {text_color}; font-size: 21px;") - nostr_txt.setVerticalScrollBarPolicy( - Qt.ScrollBarPolicy.ScrollBarAlwaysOff) - nostr_txt.setHorizontalScrollBarPolicy( - Qt.ScrollBarPolicy.ScrollBarAlwaysOff) - nostr_txt.setWordWrapMode( - QtGui.QTextOption.WrapMode.WrapAnywhere) - nostr_txt.setText(f"Nostr: {n_key}") - nostr_txt.show() - self.labels.append(nostr_txt) - - for i, key in enumerate(parameters.keys()): - if key == 'browser': - browser_value = f"{data_profile.get(key, '')}" - split_value = browser_value.split(':', 1) - browser_type = split_value[0] - browser_version = split_value[1] if len( - split_value) > 1 else '' - browser_value = f"{browser_type} {browser_version}" - if browser_version == '': - browser_version = data_profile.get('browser_version', '') - browser_value = f"{browser_type} {browser_version}" - fallback_path = os.path.join( - self.btn_path, "default_browser_button.png") - normalized_browser = browser_value.strip().lower() - unknown_browser = ( - not normalized_browser - or normalized_browser == "unknown" - or normalized_browser.startswith("unknown browser") - ) - if connection == 'system-wide': - base_image = QPixmap() - elif unknown_browser: - base_image = QPixmap(fallback_path) - if base_image.isNull(): - base_image = BrowserPage.create_browser_button_image( - "Browser", fallback_path, True) - else: - base_image = BrowserPage.create_browser_button_image( - browser_value, self.btn_path) - if base_image.isNull(): - base_image = BrowserPage.create_browser_button_image( - browser_value, fallback_path, True) - elif key == 'location': - current_value = f"{data_profile.get(key, '')}" - image_path = os.path.join( - self.btn_path, f"button_{current_value}.png") - base_image = QPixmap(image_path) - locations = self.connection_manager.get_location_info( - current_value) - provider = locations.operator.name if locations and hasattr( - locations, 'operator') else None - fallback_path = os.path.join( - self.btn_path, "default_location_button.png") - if base_image.isNull(): - if locations and hasattr(locations, 'country_name'): - location_name = locations.country_name - base_image = LocationPage.create_location_button_image( - location_name, fallback_path, provider) - else: - base_image = LocationPage.create_location_button_image( - current_value, fallback_path, provider) - else: - if locations and hasattr(locations, 'country_name'): - base_image = LocationPage.create_location_button_image( - f'{locations.country_code}_{locations.code}', fallback_path, provider, image_path) - else: - base_image = LocationPage.create_location_button_image( - current_value, fallback_path, provider, image_path) - - elif key == 'dimentions': - current_value = f"{data_profile.get(key, '')}" - if current_value != 'None': - base_image = ScreenPage.create_resolution_button_image( - self, current_value) - else: - current_value = data_profile.get(key, '') - if key == 'protocol': - image_path = self._protocol_button_asset(current_value) - else: - image_path = os.path.join( - self.btn_path, f"{current_value}_button.png") - base_image = QPixmap(image_path) - - if key == 'dimentions': - label = QPushButton(self) - label.setGeometry(565, 90 + i * 80, 185, 75) - label.setFlat(True) - label.setStyleSheet("border: none; background: transparent;") - original_icon = QIcon(base_image) - label.setIconSize(QSize(185, 75)) - label.setCursor(QtCore.Qt.CursorShape.PointingHandCursor) - label.clicked.connect(self.show_custom_res_dialog) - - template_path = os.path.join( - self.btn_path, "resolution_template_button.png") - template_pixmap = QPixmap(template_path).scaled( - 187, 75) if os.path.exists(template_path) else None - - if not getattr(self, 'res_hint_shown', False) and connection != 'system-wide': - self.res_hint_shown = True - if template_pixmap: - label.setIcon(QIcon(template_pixmap)) - else: - label.setIcon(QIcon()) - - hint_label = QLabel("Click here to customize", label) - hint_label.setGeometry(15, 0, 155, 75) - hint_label.setWordWrap(True) - hint_label.setAlignment( - QtCore.Qt.AlignmentFlag.AlignCenter) - hint_label.setStyleSheet( - "color: #00ffff; font-weight: bold; font-size: 16px; background: transparent;") - hint_label.setCursor( - QtCore.Qt.CursorShape.PointingHandCursor) - hint_label.setAttribute( - QtCore.Qt.WidgetAttribute.WA_TransparentForMouseEvents) - shadow = QGraphicsDropShadowEffect(hint_label) - shadow.setBlurRadius(20) - shadow.setColor(QColor(0, 255, 255)) - shadow.setOffset(0, 0) - hint_label.setGraphicsEffect(shadow) - - def restore(): - try: - if hint_label and not hint_label.isHidden(): - hint_label.hide() - label.setIcon(original_icon) - except: - pass - QTimer.singleShot(3500, restore) - else: - label.setIcon(original_icon) - else: - label = QLabel(key, self) - label.setGeometry(565, 90 + i * 80, 185, 75) - label.setPixmap(base_image) - label.setScaledContents(True) - - label.show() - self.labels.append(label) - - try: - if key == 'browser': - value_index = [item.replace( - ':', ' ') for item in parameters[key]].index(browser_value) - else: - value_index = parameters[key].index(current_value) - except ValueError: - value_index = 0 - - prev_button = QPushButton(self) - prev_button.setGeometry(535, 90 + i * 80, 30, 75) - prev_button.clicked.connect( - lambda _, k=key, idx=value_index: self.show_previous_value(k, idx, parameters)) - prev_button.show() - icon_path = os.path.join(self.btn_path, f"UP_button.png") - icon = QPixmap(icon_path) - transform = QTransform().rotate(180) - rotated_icon = icon.transformed(transform) - - prev_button.setIcon(QIcon(rotated_icon)) - prev_button.setIconSize(prev_button.size()) - - if (key == 'location' or key == 'browser') and not is_synced(): - w = prev_button.width() - h = prev_button.height() - outline_pix = QPixmap(w, h) - outline_pix.fill(Qt.GlobalColor.transparent) - painter = QPainter(outline_pix) - painter.setRenderHint(QPainter.RenderHint.Antialiasing) - pen = QtGui.QPen(QColor(0, 255, 0)) - pen.setWidth(3) - painter.setPen(pen) - painter.setBrush(Qt.BrushStyle.NoBrush) - left_points = [ - QPointF(w*0.65, h*0.15), QPointF(w*0.25, h*0.50), QPointF(w*0.65, h*0.85)] - painter.drawPolygon(QtGui.QPolygonF(left_points)) - painter.end() - prev_button.setIcon(QIcon(outline_pix)) - prev_button.setIconSize(prev_button.size()) - - if (key == 'location' or key == 'browser') and not is_synced(): - prev_button.setStyleSheet(BUTTON_STYLE_ONE) - - self.buttons.append(prev_button) - - next_button = QPushButton(self) - next_button.setGeometry(750, 90 + i * 80, 30, 75) - - next_button.clicked.connect( - lambda _, k=key, idx=value_index: self.show_next_value(k, idx, parameters)) - next_button.show() - self.buttons.append(next_button) - next_button.setIcon( - QIcon(os.path.join(self.btn_path, f"UP_button.png"))) - next_button.setIconSize(next_button.size()) - if (key == 'location' or key == 'browser') and not is_synced(): - w = next_button.width() - h = next_button.height() - outline_pix_r = QPixmap(w, h) - outline_pix_r.fill(Qt.GlobalColor.transparent) - painter_r = QPainter(outline_pix_r) - painter_r.setRenderHint(QPainter.RenderHint.Antialiasing) - pen_r = QtGui.QPen(QColor(0, 255, 0)) - pen_r.setWidth(3) - painter_r.setPen(pen_r) - painter_r.setBrush(Qt.BrushStyle.NoBrush) - right_points = [ - QPointF(w*0.35, h*0.15), QPointF(w*0.75, h*0.50), QPointF(w*0.35, h*0.85)] - painter_r.drawPolygon(QtGui.QPolygonF(right_points)) - painter_r.end() - next_button.setIcon(QIcon(outline_pix_r)) - next_button.setIconSize(next_button.size()) - - if (key == 'location' or key == 'browser') and not is_synced(): - next_button.setStyleSheet(""" - QPushButton { - background-color: transparent; - border: none; - } - QPushButton:hover { - background-color: rgba(0, 255, 0, 0.1); - border-radius: 3px; - } - QPushButton:pressed { - background-color: rgba(0, 255, 0, 0.2); - border-radius: 3px; - } - """) - - prev_button.setVisible(True) - next_button.setVisible(True) - - # can't change profile type - if key == 'connection': - prev_button.setDisabled(True) - next_button.setDisabled(True) - - # can't change session protocols (yet), because Tor is a different billing system than wireguard/vless/hy, - if connection == 'browser-only' and key == 'protocol': - prev_button.setDisabled(True) - next_button.setDisabled(True) - - # disables session profile options for system-profiles, where they are not relevant: - if connection == 'system-wide' and (key == 'browser' or key == 'dimentions'): - prev_button.setVisible(False) - next_button.setVisible(False) - - - - def _protocol_button_asset(self, protocol): - asset_name = self.PROTOCOL_BUTTON_ASSETS.get(protocol, protocol) - return os.path.join(self.btn_path, f"{asset_name}_button.png") - - # def _encrypted_proxy_display_pixmap(self, protocol, location): - # pixmap = QPixmap(os.path.join(self.btn_path, f"{protocol}.png")) - # if pixmap.isNull(): - # pixmap = QPixmap(os.path.join(self.btn_path, "system_wide_global.png")) - # if pixmap.isNull(): - # return pixmap - - # location_pixmap = QPixmap(os.path.join( - # self.btn_path, f"icon_mini_{location}.png")) - # if location_pixmap.isNull(): - # location_pixmap = QPixmap(os.path.join( - # self.btn_path, "default_location_mini.png")) - # if location_pixmap.isNull(): - # return pixmap - - # icon_size = max(42, min(72, int(min(pixmap.width(), pixmap.height()) * 0.22))) - # location_pixmap = location_pixmap.scaled( - # icon_size, - # icon_size, - # Qt.AspectRatioMode.KeepAspectRatio, - # Qt.TransformationMode.SmoothTransformation) - # x = int(pixmap.width() * 0.58) - # if protocol == 'hysteria2': - # y = int(pixmap.height() * 0.35) - # else: - # y = int(pixmap.height() * 0.30) - # x = min(max(0, x), max(0, pixmap.width() - location_pixmap.width())) - # y = min(max(0, y), max(0, pixmap.height() - location_pixmap.height())) - - # painter = QPainter(pixmap) - # painter.drawPixmap(x, y, location_pixmap) - # painter.end() - # return pixmap - - # def on_sync_complete_for_edit_profile(self, available_locations, available_browsers, status, is_tor, locations, all_browsers): - # if status: - # self.update_status.update_status('Sync complete.') - # self.extraccion() - # else: - # self.update_status.update_status( - # 'Sync failed. Please try again later.') - - def on_sync_complete(self, result: Result): - if result.valid: - self.is_synced = True - self.update_status.update_status('Sync complete.') - self.extraccion() - else: - self.update_status.update_status( - 'Sync failed. Please try again later.') - - def show_previous_value(self, key: str, index: int, parameters: dict) -> None: - if key == 'browser' or key == 'location': - if not is_synced(): - self.update_status.update_status('Syncing in progress..') - sync_now(ui_caller=self.on_sync_complete) - - # self.update_status.sync() - # self.update_status.worker_thread.sync_output.connect( - # self.on_sync_complete_for_edit_profile) - return - - values = parameters.get(key, []) - if not values: - self.update_status.update_status( - f"No {key} data available. Sync the database and try again.") - return - - previous_index = (index - 1) % len(values) - previous_value = values[previous_index] - self.update_temp_value(key, previous_value) - - def show_next_value(self, key: str, index: int, parameters: dict) -> None: - if key == 'browser' or key == 'location': - if not is_synced(): - self.update_status.update_status('Syncing in progress..') - sync_now(ui_caller=self.on_sync_complete) - - # self.update_status.sync() - # self.update_status.worker_thread.sync_output.connect( - # self.on_sync_complete_for_edit_profile) - return - - values = parameters.get(key, []) - if not values: - self.update_status.update_status( - f"No {key} data available. Sync the database and try again.") - return - - next_index = (index + 1) % len(values) - next_value = values[next_index] - - self.update_temp_value(key, next_value) - - def update_temp_value(self, key: str, new_value: str) -> None: - selected_profiles_str = self._selected_profiles_str() - if selected_profiles_str not in self.temp_changes: - self.temp_changes[selected_profiles_str] = {} - self.original_values[selected_profiles_str] = self.data_profile.copy( - ) - - self.temp_changes[selected_profiles_str][key] = new_value - self.extraccion() - - def show_custom_res_dialog(self): - dialog = QDialog(self) - dialog.setWindowTitle("Custom Resolution") - dialog.setFixedSize(300, 150) - dialog.setModal(True) - dialog.setStyleSheet(""" - QDialog { - background-color: #2c3e50; - border: 2px solid #00ffff; - border-radius: 10px; - } - QLabel { - color: white; - font-size: 12px; - } - QLineEdit { - background-color: #34495e; - color: white; - border: 1px solid #00ffff; - border-radius: 5px; - padding: 5px; - font-size: 12px; - } - QPushButton { - background-color: #2c3e50; - color: white; - border: 2px solid #00ffff; - border-radius: 5px; - padding: 8px; - font-size: 12px; - } - QPushButton:hover { - background-color: #34495e; - } - """) - - layout = QVBoxLayout() - input_layout = QHBoxLayout() - width_label = QLabel("Width:") - width_input = QLineEdit() - width_input.setPlaceholderText("1920") - height_label = QLabel("Height:") - height_input = QLineEdit() - height_input.setPlaceholderText("1080") - - input_layout.addWidget(width_label) - input_layout.addWidget(width_input) - input_layout.addWidget(height_label) - input_layout.addWidget(height_input) - - button_layout = QHBoxLayout() - ok_button = QPushButton("OK") - cancel_button = QPushButton("Cancel") - button_layout.addWidget(cancel_button) - button_layout.addWidget(ok_button) - - layout.addLayout(input_layout) - layout.addLayout(button_layout) - dialog.setLayout(layout) - - def validate_and_accept(): - try: - width = int(width_input.text()) - height = int(height_input.text()) - if width <= 0 or height <= 0: - return - host_w = self.custom_window.host_screen_width - host_h = self.custom_window.host_screen_height - - adjusted = False - if width > host_w: - width = host_w - 50 - adjusted = True - if height > host_h: - height = host_h - 50 - adjusted = True - - if adjusted: - QMessageBox.information( - dialog, "Notice", "Adjusted to fit host size") - - self.update_temp_value('dimentions', f"{width}x{height}") - dialog.accept() - except ValueError: - pass - - ok_button.clicked.connect(validate_and_accept) - cancel_button.clicked.connect(dialog.reject) - - width_input.returnPressed.connect(validate_and_accept) - height_input.returnPressed.connect(validate_and_accept) - - dialog.exec() - - def has_unsaved_changes(self, profile_str: str) -> bool: - return profile_str in self.temp_changes and bool(self.temp_changes[profile_str]) - - def show_apply_changes_popup(self, selected_profiles_str: str) -> bool: - if selected_profiles_str not in self.temp_changes: - return False - temp_changes = self.temp_changes[selected_profiles_str] - current_data = self.original_values[selected_profiles_str] - - current_browser = f"{current_data.get('browser', '')} {current_data.get('browser_version', '')}" - - if 'location' in temp_changes and temp_changes['location'] != current_data.get('location'): - message = "A new location would require a new subscription code.\nDo you want to proceed with erasing the old one?" - elif 'browser' in temp_changes and temp_changes['browser'] != current_browser: - message = "Changing the browser would delete all data associated with it. Proceed?" - else: - return False - - self.popup = ConfirmationPopup( - self, - message=message, - action_button_text="Continue", - cancel_button_text="Cancel" - ) - self.popup.setWindowModality(Qt.WindowModality.ApplicationModal) - self.popup.finished.connect( - lambda result: self.handle_apply_changes_response(result)) - self.popup.show() - return True - - def show_unsaved_changes_popup(self) -> None: - self.popup = ConfirmationPopup( - self, - message="You have unsaved changes. Do you want to continue?", - action_button_text="Continue", - cancel_button_text="Cancel" - ) - self.popup.setWindowModality(Qt.WindowModality.ApplicationModal) - self.popup.finished.connect( - lambda result: self.handle_unsaved_changes_response(result)) - self.popup.show() - - def _refresh_menu_and_navigate(self): - menu_page = self.find_menu_page() - if menu_page is not None and hasattr(menu_page, 'refresh_menu_buttons'): - menu_page.refresh_menu_buttons() - self.custom_window.navigator.navigate("menu") - - def handle_apply_changes_response(self, result: bool) -> None: - if result: - self.commit_changes() - self._refresh_menu_and_navigate() - - def handle_unsaved_changes_response(self, result: bool) -> None: - if result: - self.temp_changes.clear() - self._refresh_menu_and_navigate() - - def go_selected(self) -> None: - selected_profiles_str = self._selected_profiles_str() - - if selected_profiles_str in self.temp_changes and self.temp_changes[selected_profiles_str]: - needs_confirmation = self.show_apply_changes_popup( - selected_profiles_str) - if not needs_confirmation: - self.commit_changes() - self._refresh_menu_and_navigate() - - else: - self.custom_window.navigator.navigate("menu") - - def commit_changes(self) -> None: - selected_profiles_str = self._selected_profiles_str() - if selected_profiles_str in self.temp_changes: - for key, new_value in self.temp_changes[selected_profiles_str].items(): - self.update_core_profiles(key, new_value) - - self.temp_changes.pop(selected_profiles_str, None) - self.original_values.pop(selected_profiles_str, None) - self._prefetched_profiles = None - - def update_core_profiles(self, key, new_value): - """Send to action module to update the profile data""" - profile_id = int(self.update_status.current_profile_id) - self.which_key_changed = key - - edit_profile( - profile_id=profile_id, - key=key, - new_value=new_value, - ui_caller=self.recieve_edit_result - ) - - def recieve_edit_result(self, result: Result): - """After edit is complete, display the result.""" - if result.valid: - self.update_status.update_status( - f'Updated profile') - - if self.which_key_changed == "resolution": - self.update_res = True - - if result.data == "edit_to_session": - self.edit_to_session() - - else: - self.show_a_popup(message=result.message, title=str(result.error_type.value)) - self.update_status.update_status(result.message) - - - def edit_to_session(self): - id = int(self.update_status.current_profile_id) - profile = self.data_profile - default_app = 'firefox:123.0' - default_resolution = '1024x760' - location_code = self.connection_manager.get_location_info( - profile.get('location')) - - connection_type = 'tor' - - profile_data = { - 'id': int(id), - 'name': profile.get('name'), - 'country_code': location_code.country_code, - 'code': location_code.code, - 'application': default_app, - 'connection_type': connection_type, - 'resolution': default_resolution, - } - resume_page = self.find_resume_page() - if resume_page: - resume_page.handle_core_action_create_profile( - 'CREATE_SESSION_PROFILE', profile_data, 'session') - - - def show_a_popup(self, message: str, title: str = "Error"): - """Display a popup with an error""" - error_popup = ErrorPopup( - choice=False, - title=title, - message=message, - end_app = False, - on_answer = None, - passed_result = None, - ) - - error_popup.show()