Esempio n. 1
0
class SettingsWindow(QWidget):
    def __init__(self, translation):
        super().__init__()
        layout = QVBoxLayout()
        self.chosen_algo = ""
        self.chosen_hash = ""
        self.chosen_salt = ""
        self.chosen_key = ""
        self.window = None
        self.settings_translate = translation
        enc_key = self.settings_translate["buttons"]["encryption_key_prompt"]
        enc_key_confirm = self.settings_translate["buttons"][
            "encryption_key_confirm"]
        algorithm = self.settings_translate["buttons"]["algorithm"]
        salt_select = self.settings_translate["buttons"]["salt_select"]
        self.automatic_salt = self.settings_translate["buttons"][
            "automatic_salt"]
        self.click_salt = self.settings_translate["buttons"]["click_salt"]
        self.write_salt = self.settings_translate["buttons"]["write_salt"]
        hash = self.settings_translate["buttons"]["hash"]
        salt = self.settings_translate["buttons"]["salt"]
        close_btn = self.settings_translate["prompts"]["close_button"]

        self.setWindowIcon(QIcon(IMG_LOCATION + "win_icon.png"))
        self.setWindowTitle("Set default encryption settings")

        self.hash = QPushButton(hash)
        self.algorithm = QPushButton(algorithm)
        self.salt_selection = QPushButton(salt_select)
        self.text_box_salt = PasswordEdit(self)
        self.text_box_salt.setPlaceholderText(salt)
        self.text_box_enc_text = PasswordEdit(self)
        self.text_box_enc_text.setPlaceholderText(enc_key)
        self.text_box_enc_text_confirm = PasswordEdit(self)
        self.text_box_enc_text_confirm.setPlaceholderText(enc_key_confirm)
        self.close_button = QPushButton(close_btn)
        self.close_button.clicked.connect(self.close_settings)
        # Define Hash functions menu
        self.menu = QMenu(self)
        self.menu.setObjectName("default_hash_menu")
        self.menu.addAction("MD5")
        self.menu.addSeparator()
        self.menu.addAction("SHA-256")
        self.menu.addSeparator()
        self.menu.addAction("SHA-512")
        self.menu.addSeparator()
        self.menu.addAction("SHA3-512")
        self.hash.setMenu(self.menu)
        self.menu.triggered.connect(self.hashes)
        # Define Algorithms functions menu
        self.menu_algo = QMenu(self)
        self.menu_algo.setObjectName("default_algo_menu")
        self.menu_algo.addAction("ChaCha20")
        self.menu_algo.addSeparator()
        self.menu_algo.addAction("RSA")
        self.menu_algo.addSeparator()
        self.menu_algo.addAction("AES")
        self.algorithm.setMenu(self.menu_algo)
        self.menu_algo.triggered.connect(self.algorithms)
        # Define Salt type functions menu
        self.salt_selection_menu = QMenu(self)
        self.salt_selection_menu.setObjectName("default_salt_menu")
        self.salt_selection_menu.addAction(self.automatic_salt)
        self.salt_selection_menu.addSeparator()
        self.salt_selection_menu.addAction(self.click_salt)
        self.salt_selection_menu.addSeparator()
        self.salt_selection_menu.addAction(self.write_salt)
        self.salt_selection.setMenu(self.salt_selection_menu)
        self.salt_selection_menu.triggered.connect(self.choose_salt)
        layout.addWidget(self.hash)
        layout.addWidget(self.algorithm)
        layout.addWidget(self.salt_selection)
        #        layout.addWidget(self.salt)
        layout.addWidget(self.text_box_salt)
        layout.addWidget(self.text_box_enc_text)
        layout.addWidget(self.text_box_enc_text_confirm)
        layout.addSpacing(50)
        layout.addWidget(self.close_button)
        self.setLayout(layout)

        self.Width = 700
        self.height = int(0.8 * self.Width)
        self.setFixedSize(self.Width, self.height)
        # center the window relative to screensize
        centering = self.frameGeometry()
        centerOfScreen = QDesktopWidget().availableGeometry().center()
        centering.moveCenter(centerOfScreen)
        self.move(centering.topLeft())

    def hashes(self, language):
        self.chosen_hash = language.text()
        self.hash.setText(self.chosen_hash)
        print(language.text())
        return language

    def algorithms(self, language):
        self.chosen_algo = language.text()
        print(language.text())
        print(self.chosen_salt)
        self.algorithm.setText(self.chosen_algo)
        return language

    def choose_salt(self, salt_type):
        print("Chosen salt type: ", salt_type.text())
        if salt_type.text() == self.write_salt:
            self.text_box_salt.setFocus()
            self.salt_selection.setText(self.write_salt)
            return
        if salt_type.text() == self.automatic_salt:
            salt_gen = generate_salt.salt_generator().generate_salt()
            self.text_box_salt.setText(salt_gen)
            self.salt_selection.setText(self.automatic_salt)
            return
        self.salt_selection.setText(self.click_salt)
        self.window = salt_generation.SaltWindow(self.settings_translate, self)
        self.window.show()

    def close_settings(self, event):
        pwd_mismatch = self.settings_translate["prompts"]["password_mismatch"]
        confirm_no_enc_key_set = self.settings_translate["prompts"][
            "confirm_no_password"]
        no_enc_key_prompt = self.settings_translate["prompts"]["no_enc_key"]
        print("Chosen algorithm: ", self.chosen_algo)
        print("Chosen salt: ", self.text_box_salt.text())
        print("Chosen enc key: ", self.text_box_enc_text.text())
        print("Chosen enc key: ", self.text_box_enc_text_confirm.text())
        if str(self.text_box_enc_text.text()) == str(
                self.text_box_enc_text_confirm.text()):
            if (str(self.text_box_enc_text.text()) == ""
                    and str(self.text_box_enc_text_confirm.text()) == ""):
                confirm_no_pwd = QMessageBox.question(
                    self,
                    no_enc_key_prompt,
                    confirm_no_enc_key_set,
                    QMessageBox.Yes | QMessageBox.No,
                )
                if confirm_no_pwd == QMessageBox.Yes:
                    defaults = {
                        "hash": "",
                        "algorithm": "",
                        "salt": "",
                        "key": ""
                    }
                    if self.chosen_hash != "":
                        defaults["hash"] = self.chosen_hash
                    if self.chosen_algo != "":
                        defaults["algorithm"] = self.chosen_algo
                    if self.text_box_salt.text() != "":
                        defaults["salt"] = self.text_box_salt.text()
                    if self.text_box_enc_text.text() != "":
                        defaults["key"] = self.text_box_enc_text.text()
                    write_encryption_defaults(
                        db_location,
                        (
                            defaults["hash"],
                            defaults["algorithm"],
                            defaults["salt"],
                            defaults["key"],
                        ),
                    )
                    self.close()
                    return
                return
        if (str(self.text_box_enc_text.text()) == ""
                and str(self.text_box_enc_text_confirm.text()) == ""):
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText(pwd_mismatch)
            display = msg.exec_()
            return

        if str(self.text_box_enc_text.text()) != str(
                self.text_box_enc_text_confirm.text()):
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText(pwd_mismatch)
            display = msg.exec_()
            return

        defaults = {"hash": "", "algorithm": "", "salt": "", "key": ""}
        if self.chosen_hash != "":
            defaults["hash"] = self.chosen_hash
        if self.chosen_algo != "":
            defaults["algorithm"] = self.chosen_algo
        if self.text_box_salt.text() != "":
            defaults["salt"] = self.text_box_salt.text()
        if self.text_box_enc_text.text() != "":
            defaults["key"] = self.text_box_enc_text.text()
        write_encryption_defaults(
            db_location,
            (
                defaults["hash"],
                defaults["algorithm"],
                defaults["salt"],
                defaults["key"],
            ),
        )
        self.close()
Esempio n. 2
0
class VistaModificaDipendente(QWidget):
    def __init__(self, dipendente_selezionato, controller, callback):
        super(VistaModificaDipendente, self).__init__()

        self.dp = dipendente_selezionato
        # passo alla classe il dipendente che seleziono per avere le sue informazioni
        self.dipendente = ControlloreDipendente(dipendente_selezionato)
        self.controller = controller
        self.callback = callback
        self.info = {}
        self.combo_abilitazione = QComboBox()

        # layout di modifica dei dati del dipendente
        self.v_layout = QVBoxLayout()
        self.setFixedSize(650, 470)

        # pulsante di conferma della modifica
        btn_modifica = QPushButton("Modifica")
        btn_modifica.setStyleSheet(
            "background-color: #90ee90; font-size: 13px; font-weight: bold;")
        btn_modifica.setShortcut("Return")
        btn_modifica.clicked.connect(self.mod_dipendente)
        # pulsante di annullamento delle modifica
        btn_annulla = QPushButton("Annulla")
        btn_annulla.setStyleSheet(
            "background-color: #f08080; font-size: 13px; font-weight: bold;")
        btn_annulla.setShortcut("Esc")
        btn_annulla.clicked.connect(self.close)

        self.label_img = QLabel()
        self.label_img.setPixmap(QPixmap('listadipendenti/data/utente.png'))

        # layout superiore
        h_lay_sup = QHBoxLayout()
        v_lay_sup_sx = QVBoxLayout()
        v_lay_sup_dx = QVBoxLayout()
        v_lay_sup_sx.addStretch()
        v_lay_sup_sx.addLayout(
            self.get_form_entry(self.dipendente.get_nome_dipendente(), "Nome"))
        v_lay_sup_sx.addLayout(
            self.get_form_entry(self.dipendente.get_cognome_dipendente(),
                                "Cognome"))
        v_lay_sup_sx.addLayout(
            self.get_form_entry(self.dipendente.get_cf_dipendente(),
                                "Codice Fiscale"))
        v_lay_sup_sx.addStretch()
        v_lay_sup_dx.addWidget(self.label_img)
        h_lay_sup.addLayout(v_lay_sup_sx)
        h_lay_sup.addLayout(v_lay_sup_dx)
        # layout centrale
        h_lay_cent = QHBoxLayout()
        v_lay_cent_sx = QVBoxLayout()
        v_lay_cent_dx = QVBoxLayout()
        v_lay_cent_sx.addLayout(
            self.get_form_entry(self.dipendente.get_luogo_dipendente(),
                                "Luogo di nascita"))
        v_lay_cent_dx.addLayout(
            self.get_form_entry(self.dipendente.get_data_dipendente(),
                                "Data di nascita"))
        v_lay_cent_sx.addLayout(
            self.get_form_entry(self.dipendente.get_residenza_dipendente(),
                                "Residenza"))
        v_lay_cent_dx.addLayout(
            self.get_form_entry(self.dipendente.get_indirizzo_dipendente(),
                                "Indirizzo"))
        v_lay_cent_sx.addLayout(
            self.get_form_entry(self.dipendente.get_telefono_dipendente(),
                                "Telefono"))
        v_lay_cent_dx.addLayout(
            self.get_form_entry(self.dipendente.get_email_dipendente(),
                                "Email"))
        h_lay_cent.addLayout(v_lay_cent_sx)
        h_lay_cent.addLayout(v_lay_cent_dx)
        # layout inferiore
        v_lay_inf = QVBoxLayout()
        h_lay_inf = QHBoxLayout()
        h_lay_inf_btn = QHBoxLayout()

        password = QLabel("<b>Password</b>")
        self.password = PasswordEdit()
        self.password.setText(self.dipendente.get_password_dipendente())
        h_lay_inf.addWidget(password)
        h_lay_inf.addWidget(self.password)
        self.info["Password"] = self.password

        h_lay_inf_btn.addWidget(btn_annulla)
        h_lay_inf_btn.addWidget(btn_modifica)
        v_lay_inf.addLayout(h_lay_inf)
        v_lay_inf.addStretch()
        v_lay_inf.addLayout(h_lay_inf_btn)

        self.v_layout.addLayout(h_lay_sup)
        self.v_layout.addLayout(
            self.get_combo(["Collaboratore", "Personal Trainer"]))

        self.v_layout.addLayout(h_lay_cent)
        self.v_layout.addLayout(v_lay_inf)

        self.setLayout(self.v_layout)
        self.setWindowTitle("Modifica Dipendente")

    # ritorna layout con i campi da moficiare con relative etichette
    def get_form_entry(self, campo, tipo):
        h_lay = QHBoxLayout()
        h_lay.addWidget(QLabel("<b>{}</b>".format(tipo)))
        current_text_edit = QLineEdit(self)
        current_text_edit.setText(campo)
        h_lay.addWidget(current_text_edit)
        self.info[tipo] = current_text_edit
        return h_lay

    # ottengo i dati della combo per l'abilitazione
    def get_combo(self, lista):
        v_lay = QVBoxLayout()
        v_lay.addWidget(QLabel("<b>Abilitazione</b>"))
        combo_model = QStandardItemModel(self.combo_abilitazione)
        combo_model.appendRow(QStandardItem(""))
        for item in lista:
            combo_model.appendRow(QStandardItem(item))
        self.combo_abilitazione.setModel(combo_model)
        # setto il valore della combo con l'abilitazione attuale del dipendente
        self.combo_abilitazione.setCurrentText(
            self.dipendente.get_abilitazione_dipendente())
        v_lay.addWidget(self.combo_abilitazione)
        return v_lay

    def mod_dipendente(self):
        # recupero i valori del dizionario
        nome = self.info["Nome"].text()
        cognome = self.info["Cognome"].text()
        data_nascita = self.info["Data di nascita"].text()
        luogo_nascita = self.info["Luogo di nascita"].text()
        residenza = self.info["Residenza"].text()
        indirizzo = self.info["Indirizzo"].text()
        cf = self.info["Codice Fiscale"].text()
        telefono = self.info["Telefono"].text()
        email = self.info["Email"].text()
        abilitazione = self.combo_abilitazione.currentText()
        password = self.info["Password"].text()
        # effettuo i controlli per i dati immessi come per l'inserimento di un nuovo cliente
        if nome == "" or cognome == "" or data_nascita == "" or luogo_nascita == "" or cf == "" or telefono == "" or email == "" or abilitazione == "" or password == "":
            QMessageBox.critical(
                self, 'Errore',
                'Per favore, inserisci tutte le informazioni richieste',
                QMessageBox.Ok, QMessageBox.Ok)
        else:
            if telefono.isnumeric() and len(telefono) == 10:
                if len(cf) == 16:
                    dipendente = Dipendente(nome, cognome, data_nascita,
                                            luogo_nascita, residenza,
                                            indirizzo, cf, telefono, email,
                                            abilitazione, password)
                    self.controller.rimuovi_dalla_lista(self.dp)
                    self.controller.aggiungi_dipendente(dipendente)
                    self.callback()
                    self.close()
                else:
                    QMessageBox.critical(
                        self, 'Errore',
                        'Per favore inserisci un codice fiscale di telefono valido, 16 valori',
                        QMessageBox.Ok, QMessageBox.Ok)
            else:
                QMessageBox.critical(
                    self, 'Errore',
                    'Per favore inserisci un numero di telefono valido, 10 cifre',
                    QMessageBox.Ok, QMessageBox.Ok)
Esempio n. 3
0
class Login(QWidget):
    accesso_utente = None
    autorizzazione_accesso = None

    def __init__(self, parent=None):
        super(Login, self).__init__(parent)

        self.setWindowTitle('Login - Centro Polisportivo')
        self.setFixedSize(380, 300)
        self.controller = ControlloreListaDipendenti()
        self.setStyleSheet("background-color: Azure;")

        self.lista_suggerimenti = []
        for dipendente in self.controller.get_lista_dipendenti():
            nome = dipendente.id
            self.lista_suggerimenti.append(nome)

        # definisco un layout verticale per il login
        login_layout = QVBoxLayout()
        login_layout.setAlignment(Qt.AlignCenter)
        login_layout.setSpacing(25)
        # definisco un layout orizzontale per i pulsanti
        btn_layout = QHBoxLayout()

        # creazione campi inserimento username
        labelUsername = QLabel('<font size = "5"> <b> Username </b> </font>')
        self.username = QLineEdit()
        self.username.setCompleter(QCompleter(self.lista_suggerimenti))
        #self.username.setStyleSheet("background-color: #ffffff; font-size: 20px;")
        self.impostaGrandezzaMassima(self.username)
        self.username.setPlaceholderText('Inserisci username - id')
        # creazione campi inserimento password
        labelPassword = QLabel('<font size = "5"> <b> Password </b> </font>')
        self.password = PasswordEdit()
        #self.password.setStyleSheet("background-color: #ffffff; font-size: 20px;")
        self.impostaGrandezzaMassima(self.password)
        self.password.setPlaceholderText('Inserisci password')
        # creazione pulsante del login
        btn_login = QPushButton('Login')
        btn_login.setStyleSheet(
            "background-color: #b0c4de; font-size: 15px; font-weight: bold;")
        self.impostaGrandezzaMassima(btn_login)
        btn_login.setShortcut("Return")
        btn_login.clicked.connect(self.check_credenziali)
        # creazione pulsante esci
        btn_esci = QPushButton('Esci')
        btn_esci.setStyleSheet(
            "background-color: #b0c4de; font-size: 15px; font-weight: bold;")
        btn_esci.setShortcut("Esc")
        self.impostaGrandezzaMassima(btn_esci)
        btn_esci.clicked.connect(self.close)

        # aggiunta pulsanti al layout dei pulsanti
        btn_layout.addWidget(btn_login)
        btn_layout.addWidget(btn_esci)

        # aggiunta username al layout
        login_layout.addWidget(labelUsername)
        login_layout.addWidget(self.username)
        # aggiunta password al layout
        login_layout.addWidget(labelPassword)
        login_layout.addWidget(self.password)
        # aggiunta layout pulsanti al layout principale
        login_layout.addLayout(btn_layout)

        # setting del layout della finestra
        self.setLayout(login_layout)

    # funzione che esegue la verifica dell'utente e l'accesso all'area di competenza
    def check_credenziali(self):
        msg = QMessageBox()
        i = 0
        if self.username.text() == Amministratore().get_username(
        ) and self.password.text() == Amministratore().get_password():
            Login.autorizzazione_accesso = "Amministratore"
            self.close()
            self.vistahome = VistaHome()
            self.vistahome.show()
        else:
            for dipendente in self.controller.get_lista_dipendenti():
                i += 1
                if self.password.text(
                ) == dipendente.password and self.username.text(
                ) == dipendente.id:
                    if dipendente.abilitazione == "Personal Trainer":
                        Login.autorizzazione_accesso = "Personal Trainer"
                    if dipendente.abilitazione == "Collaboratore":
                        Login.autorizzazione_accesso = "Collaboratore"
                    Login.accesso_utente = dipendente
                    self.close()
                    self.vistahome = VistaHome()
                    self.vistahome.show()
                    break

            if i == (len(self.controller.get_lista_dipendenti())) and (
                    self.password.text() != dipendente.password
                    or self.username.text() != dipendente.id):
                if Login.autorizzazione_accesso == None:
                    msg.setWindowTitle("Login errato")
                    msg.setText('Password o Username errati. Riprova!')
                    msg.exec_()
                    # in caso di mancata autenticazione i campi di inserimento vengono resettati
                    self.password.setText("")
                    self.username.setText("")

    #imposta la grandezza massima di un "oggetto"
    def impostaGrandezzaMassima(self, oggetto):
        oggetto.setMinimumSize(25, 25)
Esempio n. 4
0
class Encrypt_page:
    def __init__(self, translations, mainwindow):
        # Define used class parameters to be set in the selections
        self.translations = translations
        self.defaults = check_encryption_defaults(db_location)
        self.filepath = ""
        self.filepath_rsa = ""
        self.salt = ""
        self.enc_key = ""
        self.parent_win = mainwindow
        if self.defaults["default_hash"] != "":
            self.chosen_algo = self.defaults["default_hash"]
        else:
            self.chosen_algo = ""
        if self.defaults["default_algo"] != "":
            self.chosen_algorithm = self.defaults["default_algo"]
        else:
            self.chosen_algorithm = ""

    def button_enc_t(self):
        self.bottom_widget.setCurrentIndex(0)
        if check_dark_mode(db_location) == "False":
            self.btn_enc_t.setStyleSheet(ENC_TEXT_PRESSED_QSS)
            self.btn_enc_f.setStyleSheet(ENC_FILE_DEPRESSED_QSS)
        else:
            self.btn_enc_t.setStyleSheet(DARK_ENC_TEXT_PRESSED_QSS)
            self.btn_enc_f.setStyleSheet(DARK_ENC_FILE_DEPRESSED_QSS)

    def button_enc_f(self):
        self.bottom_widget.setCurrentIndex(1)
        if check_dark_mode(db_location) == "False":
            self.btn_enc_t.setStyleSheet(ENC_TEXT_DEPRESSED_QSS)
            self.btn_enc_f.setStyleSheet(ENC_FILE_PRESSED_QSS)
        else:
            self.btn_enc_t.setStyleSheet(DARK_ENC_TEXT_DEPRESSED_QSS)
            self.btn_enc_f.setStyleSheet(DARK_ENC_FILE_PRESSED_QSS)

    def encryption(self):
        """
        This method handles frame for the entire encrypt tab
        """
        final_layout = QVBoxLayout()

        # DEFINE TOP WIDGET (TABS AND SWITCHING BETWEEN THEM)
        enc_button_text = self.translations["buttons"]["encrypt_text"]
        enc_button_files = self.translations["buttons"]["encrypt_files"]

        self.btn_enc_t = QPushButton(f"{enc_button_text}")
        self.btn_enc_t.setObjectName("btn_enc_t")
        self.btn_enc_t.clicked.connect(self.button_enc_t)
        self.btn_enc_f = QPushButton(f"{enc_button_files}")
        self.btn_enc_f.setObjectName("btn_enc_f")
        self.btn_enc_f.clicked.connect(self.button_enc_f)

        if check_dark_mode(db_location) == "False":
            self.btn_enc_t.setStyleSheet(ENC_TEXT_PRESSED_QSS)
        else:
            self.btn_enc_t.setStyleSheet(DARK_ENC_TEXT_PRESSED_QSS)

        top_actions = QHBoxLayout()
        top_actions.setSpacing(0)
        top_actions.setContentsMargins(0, 16, 0, 0)
        top_actions.addWidget(self.btn_enc_t)
        top_actions.addWidget(self.btn_enc_f)

        self.top_widget = QWidget()
        self.top_widget.setLayout(top_actions)

        # DEFINE BOTTOM WIDGET (TAB CONTENTS)
        self.tab_enc_t = self.tab_enc_text()
        self.tab_enc_f = self.tab_enc_files()

        self.bottom_widget = QTabWidget()
        self.bottom_widget.tabBar().setObjectName("EncryptionTab")

        self.bottom_widget.addTab(self.tab_enc_t, "")
        self.bottom_widget.addTab(self.tab_enc_f, "")

        self.bottom_widget.setCurrentIndex(0)  # default to the text tab

        # Add top and bottom parts to the layout
        final_layout.addWidget(self.top_widget)
        final_layout.addWidget(self.bottom_widget)

        # Finish layout
        main = QWidget()
        main.setLayout(final_layout)

        return main

    def tab_enc_text(self):
        """
        This method handles the text encryption tab
        """
        # init layout
        layout = QGridLayout()

        # INSERT TEXT LABEL
        text_to_enc_label = QLabel(self.translations["labels"]["insert_text_enc"])
        text_to_enc_label.setAlignment(Qt.AlignCenter)
        text_to_enc_label.setObjectName("large_label")
        layout.addWidget(text_to_enc_label, 0, 1, 1, 3)
        # INSERT TEXT BOX
        self.text_insert = QLineEdit()
        layout.addWidget(self.text_insert, 0, 4, 1, 5)

        # ALGORITHM SET LABEL
        algo_text_label = QLabel(self.translations["labels"]["set_enc_algorithm"])
        algo_text_label.setAlignment(Qt.AlignCenter)
        layout.addWidget(algo_text_label, 1, 1, 1, 3)
        # ALGORITHM DROPDOWN MENU
        algo_trans = self.translations["buttons"]["algorithm"]
        self.algo_button_ttab = QPushButton(algo_trans)
        self.algo_dropdown = QMenu()
        self.algo_dropdown.setObjectName("algo_menu_enc_text")
        for algo in ENC_ALGORITHMS:
            self.algo_dropdown.addAction(algo)
            self.algo_dropdown.addSeparator()
        self.algo_button_ttab.setMenu(self.algo_dropdown)
        self.algo_dropdown.triggered.connect(self.algorithms_text)
        if self.defaults["default_hash"] != "":
            self.algo_button_ttab.setText(self.defaults["default_hash"])
        layout.addWidget(self.algo_button_ttab, 1, 4, 1, 3)

        # ENCRYPTION KEY INPUT AND CONFIRM LABELS
        enc_text_label = QLabel(self.translations["labels"]["encryption_key_label"])
        enc_text_label.setAlignment(Qt.AlignCenter)
        enc_conf_label = QLabel(
            self.translations["labels"]["encryption_key_confirm_label"]
        )
        enc_conf_label.setAlignment(Qt.AlignCenter)
        enc_text_label.setHidden(True)
        enc_conf_label.setHidden(True)
        layout.addWidget(enc_text_label, 2, 3, 1, 1)
        layout.addWidget(enc_conf_label, 3, 2, 1, 2)

        # ENCRYPTION KEY INPUT AND CONFIRM
        self.text_box_enc_text_ttab = PasswordEdit()
        self.text_box_enc_text_ttab.setHidden(True)
        if self.defaults["default_key"] != "":
            self.text_box_enc_text_ttab.setText(self.defaults["default_key"])
        self.text_box_enc_text_confirm_ttab = PasswordEdit()
        self.text_box_enc_text_confirm_ttab.setHidden(True)
        if self.defaults["default_key"] != "":
            self.text_box_enc_text_confirm_ttab.setText(self.defaults["default_key"])
        layout.addWidget(self.text_box_enc_text_ttab, 2, 4, 1, 3)
        layout.addWidget(self.text_box_enc_text_confirm_ttab, 3, 4, 1, 3)

        # SALT INPUT LABEL
        salt_label = QLabel(self.translations["labels"]["salt_label"])
        salt_label.setAlignment(Qt.AlignCenter)
        salt_label.setObjectName("large_label")
        layout.addWidget(salt_label, 4, 1, 1, 3)
        # SALT INPUT
        self.salt_insert_box_ttab = PasswordEdit()
        if self.defaults["default_salt"] != "":
            self.salt_insert_box_ttab.setText(self.defaults["default_salt"])
        layout.addWidget(self.salt_insert_box_ttab, 4, 4, 1, 5)

        # ENCRYPT BUTTON
        enc_trans = self.translations["buttons"]["final_encrypt"]
        encrypt_button = QPushButton(enc_trans)
        encrypt_button.clicked.connect(self.encrypt_text)
        self.encrypt_result = QLineEdit()
        self.encrypt_result.setHidden(True)
        layout.addWidget(encrypt_button, 5, 2, 1, 6)
        layout.addWidget(self.encrypt_result, 6, 0, 1, 10)

        # finish and set layout
        main = QWidget()
        main.setLayout(layout)
        return main

    def filedialogopen(self):
        """
        File dialog opening method
        """
        self._files = FileDialog().fileOpen()
        self.filepath = self._files

    def filedialogopen_rsa(self):
        """
        File dialog opening method
        """
        self._files_rsa = FileDialog().fileOpen()
        self.filepath_rsa = self._files_rsa
        if self.filepath_rsa != None:
            fileout = os.path.basename(self.filepath_rsa)
            self.rsa_selection_btn.setText(fileout)
            return
        fileout = "public.pem"
        self.rsa_selection_btn.setText(fileout)

    def filedialogsave(self):
        """
        File save method
        """
        self._save = FileDialog().fileSave()

    # Encrypt parameters set and function call
    def encrypt_file(self):
        self.enc_key = self.text_box_enc_text.text()
        self.enc_key_confirm = self.text_box_enc_text_confirm.text()
        self.salt = self.salt_insert_box.text()
        filepath = self.filepath
        try:
            fileout = os.path.basename(self.filepath)
        except TypeError:
            return
        salt = self.salt
        enc_key = self.enc_key
        print(self.chosen_algorithm)
        if str(self.enc_key) != str(self.enc_key_confirm):
            pwd_mismatch = self.translations["prompts"]["password_mismatch"]
            msg = QMessageBox()
            msg.setIcon(QMessageBox.Warning)
            msg.setText(pwd_mismatch)
            display = msg.exec_()
            return
        # File out gets the name of the file for saving the file
        if self.chosen_algorithm == "AES":
            encryptor = encrypt.Encryption(password=enc_key, salt=salt)
            encryptor.encrypt_with_aes(filepath, fileout)
        if self.chosen_algorithm == "RSA":
            if self.filepath_rsa == "":
                encryptor = encrypt.Encryption(password=enc_key, salt=salt)
                encryptor.encrypt_with_rsa(
                    filename=filepath, fileout=fileout, pub_key=None
                )
            else:
                encryptor = encrypt.Encryption(password=enc_key, salt=salt)
                encryptor.encrypt_with_rsa(
                    filename=filepath, fileout=fileout, pub_key=self.filepath_rsa
                )
        if self.chosen_algorithm == "Chacha":
            encryptor = encrypt.Encryption(password=enc_key, salt=salt)
            encryptor.encrypt_with_chacha(filepath, fileout)
        # Filepath is the path for the file
        # Fileout is the name of the file, comes out with added
        # _encryted prefix after ecnryption
        inprogresslist.append(f"Encrypted: {fileout}")
        progress = self.translations["prompts"]["ready"]
        self.parent_win.right_layout.clear()
        self.parent_win.right_layout.addItems([f"{progress} ({len(inprogresslist)})"])
        self.parent_win.right_layout.addItems(inprogresslist)
        self.parent_win.right_layout.setHidden(False)
        return

    def encrypt_text(self):
        result = ""
        self.encrypt_result.setHidden(False)
        text_hasher = encrypt.Encryption(salt=self.salt_insert_box_ttab.text())
        if self.chosen_algo == "MD5":
            result = text_hasher.hash_with_md5(self.text_insert.text())
        if self.chosen_algo == "SHA-256":
            result = text_hasher.hash_with_sha256(self.text_insert.text())
        if self.chosen_algo == "SHA-512":
            result = text_hasher.hash_with_sha512(self.text_insert.text())
        if self.chosen_algo == "SHA3-512":
            result = text_hasher.hash_with_sha3_512(self.text_insert.text())
        self.encrypt_result.setText(result)

    def algorithms(self, algorithm):
        disabled_password = self.translations["prompts"]["encryption_disabled"]
        disabled_salt = self.translations["prompts"]["salt_disabled"]
        self.chosen_algorithm = algorithm.text()
        self.algo_button.setText(self.chosen_algorithm)
        if self.chosen_algorithm == "RSA":
            self.enc_text_label.setHidden(True)
            self.enc_conf_label.setHidden(True)
            self.salt_label.setHidden(True)
            self.text_box_enc_text.setHidden(True)
            self.text_box_enc_text.setDisabled(True)
            self.text_box_enc_text.setToolTip(disabled_password)
            self.text_box_enc_text_confirm.setHidden(True)
            self.text_box_enc_text_confirm.setDisabled(True)
            self.text_box_enc_text_confirm.setToolTip(disabled_password)
            self.salt_insert_box.setHidden(True)
            self.salt_insert_box.setDisabled(True)
            self.salt_insert_box.setToolTip(disabled_salt)
            self.rsa_key_selection_label.setHidden(False)
            self.rsa_selection_btn.setHidden(False)
        else:
            self.enc_text_label.setHidden(False)
            self.enc_conf_label.setHidden(False)
            self.salt_label.setHidden(False)
            self.text_box_enc_text.setHidden(False)
            self.text_box_enc_text.setDisabled(False)
            self.text_box_enc_text.setToolTip("")
            self.text_box_enc_text_confirm.setHidden(False)
            self.text_box_enc_text_confirm.setDisabled(False)
            self.text_box_enc_text.setToolTip("")
            self.salt_insert_box.setHidden(False)
            self.salt_insert_box.setDisabled(False)
            self.text_box_enc_text.setToolTip("")
            self.rsa_key_selection_label.setHidden(True)
            self.rsa_selection_btn.setHidden(True)
        self.layout.update()
        return algorithm

    def algorithms_text(self, algorithm):
        """
        Change the encryption button text to chosen algorithm
        """
        self.chosen_algo = algorithm.text()
        self.algo_button_ttab.setText(self.chosen_algo)
        self.layout.update()
        return algorithm

    def tab_enc_files(self):
        """
        This method handles the file encryption tab
        """
        # init layout
        self.layout = QGridLayout()
        self.layout.setContentsMargins(0, 0, 0, 0)

        pad = QLabel(" ")
        self.layout.addWidget(pad, 0, 8, 1, 2)
        self.layout.addWidget(pad, 0, 0, 1, 1)

        # FILE BROWSER LABEL
        file_browse_label = QLabel(self.translations["labels"]["browse_file_enc"])
        file_browse_label.setObjectName("large_label")
        file_browse_label.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(file_browse_label, 0, 2, 1, 3)
        # INSERT FILE BROWSER
        file_browse_btn = QPushButton(self.translations["buttons"]["browse_files"])
        file_browse_btn.clicked.connect(self.filedialogopen)
        self.layout.addWidget(file_browse_btn, 0, 5, 1, 3)

        # ALGORITHM SET LABEL
        self.algo_text_label = QLabel(self.translations["labels"]["set_enc_algorithm"])
        self.algo_text_label.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(self.algo_text_label, 1, 2, 1, 3)
        # ALGORITHM DROPDOWN MENU
        self.algo_button = QPushButton(self.translations["buttons"]["algorithm"])
        self.algo_dropdown = QMenu()
        self.algo_dropdown.setObjectName("algo_menu_enc_files")
        for algo in ENC_ALGORITHMS_FILES:
            self.algo_dropdown.addAction(algo)
            self.algo_dropdown.addSeparator()
        self.algo_button.setMenu(self.algo_dropdown)
        self.algo_dropdown.triggered.connect(self.algorithms)
        if self.defaults["default_algo"] != "":
            self.algo_button.setText(self.defaults["default_algo"])
        #        if self.algo_dropdown.triggered:
        #            self.algo_button.setText(self.chosen_algo)
        #            self.layout.update()
        self.layout.addWidget(self.algo_button, 1, 5, 1, 3)

        # CUSTOM RSA KEY SELECTION LABEL
        self.rsa_key_selection_label = QLabel(
            self.translations["labels"]["encryption_rsa_key_label"]
        )
        self.layout.addWidget(self.rsa_key_selection_label, 2, 3, 1, 1)
        self.rsa_key_selection_label.setHidden(True)

        # CUSTOM RSA KEY FILEOPEN PROMPT
        self.rsa_selection_btn = QPushButton(
            self.translations["buttons"]["browse_files"]
        )
        self.rsa_selection_btn.setText("public.pem")
        self.rsa_selection_btn.clicked.connect(self.filedialogopen_rsa)
        self.layout.addWidget(self.rsa_selection_btn, 2, 5, 1, 3)
        self.rsa_selection_btn.setHidden(True)

        # ENCRYPTION KEY INPUT AND CONFIRM LABELS
        self.enc_text_label = QLabel(
            self.translations["labels"]["encryption_key_label"]
        )
        self.enc_conf_label = QLabel(
            self.translations["labels"]["encryption_key_confirm_label"]
        )
        self.enc_text_label.setAlignment(Qt.AlignCenter)
        self.enc_conf_label.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(self.enc_text_label, 2, 2, 1, 2)
        self.layout.addWidget(self.enc_conf_label, 3, 2, 1, 2)
        # ENCRYPTION KEY INPUT AND CONFIRM
        self.text_box_enc_text = PasswordEdit()
        if self.defaults["default_key"] != "":
            self.text_box_enc_text.setText(self.defaults["default_key"])
        self.text_box_enc_text_confirm = PasswordEdit()
        if self.defaults["default_key"] != "":
            self.text_box_enc_text_confirm.setText(self.defaults["default_key"])
        self.layout.addWidget(self.text_box_enc_text, 2, 4, 1, 5)
        self.layout.addWidget(self.text_box_enc_text_confirm, 3, 4, 1, 5)

        # SALT INPUT LABEL
        self.salt_label = QLabel(self.translations["labels"]["salt_label"])
        self.salt_label.setObjectName("large_label")
        self.salt_label.setAlignment(Qt.AlignCenter)
        self.layout.addWidget(self.salt_label, 4, 2, 1, 2)
        # SALT INPUT
        self.salt_insert_box = PasswordEdit()
        if self.defaults["default_salt"] != "":
            self.salt_insert_box.setText(self.defaults["default_salt"])
        self.layout.addWidget(self.salt_insert_box, 4, 4, 1, 5)

        # ENCRYPT BUTTON
        self.encrypt_button = QPushButton(self.translations["buttons"]["final_encrypt"])
        self.layout.addWidget(self.encrypt_button, 5, 3, 1, 5)
        self.encrypt_button.clicked.connect(self.encrypt_file)

        # finish and set layout
        self.main = QWidget()
        self.main.setLayout(self.layout)
        return self.main