import os from PyQt6.QtWidgets import QApplication, QLabel, QPushButton from PyQt6.QtGui import QPixmap, QIcon from PyQt6.QtCore import Qt, QSize from PyQt6 import QtCore from gui.v2.ui.pages.Page import Page class LocationVerificationPage(Page): def __init__(self, page_stack, main_window, location_icon_name, previous_page, parent=None): super().__init__("LocationVerification", page_stack, main_window, parent) self.location_icon_name = location_icon_name self.previous_page = previous_page self.connection_manager = main_window.connection_manager self.font_style = f"font-family: '{main_window.open_sans_family}';" self.verification_info = {} self.verification_checkmarks = {} self.verification_full_values = {} self.verification_labels = {} self.verification_copy_buttons = {} self.verification_display_names = { "operator_name": "Operator Name", "provider_name": "Provider Name", "nostr_public_key": "Nostr Key", "hydraveil_public_key": "HydraVeil Key", "nostr_attestation_event_reference": "Nostr Verification" } self.setup_ui() def setup_ui(self): location_display = QLabel(self) location_display.setGeometry(0, 0, 390, 520) location_display.setAlignment(Qt.AlignmentFlag.AlignCenter) icon_path = os.path.join( self.btn_path, f"icon_{self.location_icon_name}.png") location_pixmap = QPixmap(icon_path) fallback_path = os.path.join( self.btn_path, "default_location_button.png") if location_pixmap.isNull(): location_pixmap = QPixmap(fallback_path) locations = self.connection_manager.get_location_info( self.location_icon_name) operator_name = locations.operator.name if locations and hasattr( locations, 'operator') else "" max_size = QtCore.QSize(300, 300) target_size = location_display.size().boundedTo(max_size) location_display.setPixmap(location_pixmap.scaled( target_size, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)) location_display.show() title = QLabel("Operator Information", self) title.setGeometry(350, 50, 350, 30) title.setStyleSheet( f"color: #808080; font-size: 20px; font-weight: bold; {self.font_style}") title.show() info_items = [ ("Operator Name", "operator_name", 130), ("Provider Name", "provider_name", 180), ("Nostr Key", "nostr_public_key", 230), ("HydraVeil Key", "hydraveil_public_key", 280), ("Nostr Verification", "nostr_attestation_event_reference", 330), ] label_x = 350 label_width = 150 label_height = 30 value_x = 510 value_width = 210 value_height = 30 checkmark_x = 725 checkmark_width = 30 checkmark_height = 30 copy_button_x = 750 copy_button_width = 30 copy_button_height = 30 for label_text, key, y_pos in info_items: label_widget = QLabel(label_text + ":", self) label_widget.setGeometry(label_x, y_pos, label_width, label_height) label_widget.setStyleSheet( f"color: white; font-size: 18px; {self.font_style}") label_widget.setAlignment( Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter) label_widget.show() self.verification_labels[key] = label_widget value_widget = QLabel("N/A", self) value_widget.setGeometry(value_x, y_pos, value_width, value_height) value_widget.setStyleSheet( f"color: white; font-size: 16px; {self.font_style}") value_widget.setAlignment( Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter) value_widget.show() checkmark_widget = QLabel("✓", self) checkmark_widget.setGeometry( checkmark_x, y_pos, checkmark_width, checkmark_height) checkmark_widget.setStyleSheet( f"color: #4CAF50; font-size: 28px; font-weight: bold; {self.font_style}") checkmark_widget.setAlignment(Qt.AlignmentFlag.AlignCenter) checkmark_widget.hide() self.verification_info[key] = value_widget self.verification_checkmarks[key] = checkmark_widget copy_button = QPushButton(self) copy_button.setGeometry( copy_button_x, y_pos, copy_button_width, copy_button_height) copy_button.setIcon( QIcon(os.path.join(self.btn_path, "paste_button.png"))) copy_button.setIconSize(QSize(24, 24)) copy_button.setStyleSheet(f""" QPushButton {{ background: transparent; border: none; }} QPushButton:hover {{ background: rgba(255, 255, 255, 0.1); border-radius: 4px; }} """) copy_button.clicked.connect( lambda checked=False, k=key: self.copy_verification_value(k)) copy_button.show() self.verification_copy_buttons[key] = copy_button self.back_button = QPushButton(self) self.back_button.setGeometry(720, 533, 48, 35) self.back_button.setIcon( QIcon(os.path.join(self.btn_path, "back.png"))) self.back_button.setIconSize(QSize(48, 35)) self.back_button.setStyleSheet(f""" QPushButton {{ background: transparent; border: none; }} QPushButton:hover {{ background: rgba(255, 255, 255, 0.1); border-radius: 4px; }} """) self.back_button.clicked.connect(self.go_back) self.back_button.show() self.update_verification_info() def truncate_text_by_width(self, text, widget, max_width): if not text or text == "N/A": return text metrics = widget.fontMetrics() text_width = metrics.horizontalAdvance(text) if text_width <= max_width: return text ellipsis = "..." ellipsis_width = metrics.horizontalAdvance(ellipsis) available_width = max_width - ellipsis_width if available_width <= 0: return ellipsis start_chars = 1 end_chars = 1 while True: start_text = text[:start_chars] end_text = text[-end_chars:] combined_width = metrics.horizontalAdvance( start_text + ellipsis + end_text) if combined_width <= max_width: if start_chars + end_chars >= len(text): return text start_chars += 1 if start_chars + end_chars >= len(text): return text end_chars += 1 else: if start_chars > 1: start_chars -= 1 if end_chars > 1: end_chars -= 1 break if start_chars + end_chars >= len(text): return text return text[:start_chars] + ellipsis + text[-end_chars:] def update_verification_info(self): locations = self.connection_manager.get_location_info( self.location_icon_name) value_width = 210 if not locations: for key, widget in self.verification_info.items(): widget.setText("N/A") self.verification_full_values[key] = "N/A" if key in self.verification_checkmarks: self.verification_checkmarks[key].hide() return operator = None if locations.operator: operator = locations.operator if operator: operator_name = operator.name or "N/A" self.verification_full_values["operator_name"] = operator_name display_operator = self.truncate_text_by_width( operator_name, self.verification_info["operator_name"], value_width) self.verification_info["operator_name"].setText(display_operator) provider_name = locations.provider_name if locations and hasattr( locations, 'provider_name') and locations.provider_name else "N/A" self.verification_full_values["provider_name"] = provider_name display_provider = self.truncate_text_by_width( provider_name, self.verification_info["provider_name"], value_width) self.verification_info["provider_name"].setText(display_provider) nostr_key = operator.nostr_public_key or "N/A" self.verification_full_values["nostr_public_key"] = nostr_key display_nostr = self.truncate_text_by_width( nostr_key, self.verification_info["nostr_public_key"], value_width) self.verification_info["nostr_public_key"].setText(display_nostr) hydraveil_key = operator.public_key or "N/A" self.verification_full_values["hydraveil_public_key"] = hydraveil_key display_hydraveil = self.truncate_text_by_width( hydraveil_key, self.verification_info["hydraveil_public_key"], value_width) self.verification_info["hydraveil_public_key"].setText( display_hydraveil) nostr_verification = operator.nostr_attestation_event_reference or "N/A" self.verification_full_values["nostr_attestation_event_reference"] = nostr_verification display_nostr_verif = self.truncate_text_by_width( nostr_verification, self.verification_info["nostr_attestation_event_reference"], value_width) self.verification_info["nostr_attestation_event_reference"].setText( display_nostr_verif) else: self.verification_info["operator_name"].setText("N/A") self.verification_full_values["operator_name"] = "N/A" self.verification_info["provider_name"].setText("N/A") self.verification_full_values["provider_name"] = "N/A" self.verification_info["nostr_public_key"].setText("N/A") self.verification_full_values["nostr_public_key"] = "N/A" self.verification_info["hydraveil_public_key"].setText("N/A") self.verification_full_values["hydraveil_public_key"] = "N/A" self.verification_info["nostr_attestation_event_reference"].setText( "N/A") self.verification_full_values["nostr_attestation_event_reference"] = "N/A" for key, widget in self.verification_info.items(): if key in self.verification_checkmarks: full_value = self.verification_full_values.get(key, "") if full_value and full_value != "N/A": self.verification_checkmarks[key].show() else: self.verification_checkmarks[key].hide() def copy_verification_value(self, key): full_value = self.verification_full_values.get(key, "") if full_value and full_value != "N/A": clipboard = QApplication.clipboard() clipboard.setText(full_value) display_name = self.verification_display_names.get( key, "Verification value") self.custom_window.update_status( f"{display_name} copied to clipboard") def go_back(self): if self.previous_page: self.page_stack.setCurrentIndex( self.page_stack.indexOf(self.previous_page))