# Decompiled with PyLingual (https://pylingual.io)
# Internal filename: Src\Login.py
# Bytecode version: 3.9.0beta5 (3425)
# Source timestamp: 1970-01-01 00:00:00 UTC (0)

from PyQt5 import uic
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QDialog, QApplication
from Src.RunUi import UI
from Src.Support import get_time, get_windows_uuid, generate_license_key, validate_license_key

class LoginWidget(QDialog):

    def __init__(self):
        super(LoginWidget, self).__init__()
        uic.loadUi('./Ui/login.ui', self)
        self.setWindowIcon(QIcon('./Ui/icon.ico'))
        uuid = get_windows_uuid()
        self.computer_id_in.setText(uuid)
        self.activate_btn.clicked.connect(self.check_activate)
        self.copy_id_btn.clicked.connect(self.copy_clipboard)
        self.paste_key_btn.clicked.connect(self.paste_clipboard)

    def copy_clipboard(self):
        string = self.computer_id_in.text()
        clipboard = QApplication.clipboard()
        clipboard.setText(string)

    def paste_clipboard(self):
        clipboard = QApplication.clipboard()
        string = clipboard.text()
        self.activate_key_in.setText(string)

    def check_activate(self):
        key = self.activate_key_in.text()
        active_status, activate_message = validate_license_key(key)
        self.status_label.setText(activate_message)
        if active_status:
            with open('./Input/Token.txt', 'w') as writer:
                writer.write(key)
            self.open_main_window(activate_message)

    def login_instant(self):
        try:
            with open('./Input/Token.txt', 'r') as reader:
                key = reader.read()
            active_status, activate_message = validate_license_key(key)
            if active_status:
                self.open_main_window(activate_message)
        except:
            pass

    def open_main_window(self, activate_message):
        self.main_window = UI(activate_message)
        self.main_window.show()
        self.hide()