<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# Copyright: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QDialog, QMessageBox

from resources.settings_dialog_rc import Ui_settingsDialog
from util import utils, passwdFn


class SettingsDialog(QDialog, Ui_settingsDialog):
    """
    Dialog for entering and updating current
    """

    settings_changed = pyqtSignal()

    def __init__(self, settings, employees, parent=None):
        """Initialize the dialog"""
        super(SettingsDialog, self).__init__(parent)
        self.setupUi(self)  # setup ui from resource file
        self._settings = settings
        self._employees = employees
        self._work = self._settings.active

        # assign values to input fields
        self.editUserMail.setText(self._settings.active["usermail"])
        self.editUserPass.setText(self._settings.active["userpass"])
        self.editUserCountry.setText(self._settings.active["usercountry"])
        self.editHttp.setText(self._settings.active["http"])
        self.editSmtp.setText(self._settings.active["smtp"])
        self.editPort.setText(str(self._settings.active["port"]))
        self.editMailTo.setText(self._settings.active["mailto"])
        self.checkServerData.setChecked(utils.int2bool(self._settings.active["sc"]))
        self.editMailServer.setText(self._settings.active["mailserver"])
        self.editMailPort.setText(str(self._settings.active["mailport"]))
        self.editMailUser.setText(self._settings.active["mailuser"])
        self.editMailPass.setText(self._settings.active["mailpass"])
        # connect to signals
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)

    def accept(self):
        """
        User buttonbox_accepted_action current
        """
        # assign input fields to current
        self._work["usermail"] = self.editUserMail.text().lower()
        self._work["userpass"] = self.editUserPass.text()
        self._work["usercountry"] = self.editUserCountry.text().lower()
        self._work["http"] = self.editHttp.text().lower()
        self._work["smtp"] = self.editSmtp.text().lower()
        self._work["port"] = self.editPort.text()
        self._work["mailto"] = self.editMailTo.text().lower()
        self._work["sc"] = utils.bool2int(self.checkServerData.isChecked())
        self._work["mailserver"] = self.editMailServer.text().lower()
        self._work["mailport"] = self.editMailPort.text()
        self._work["mailuser"] = self.editMailUser.text()
        self._work["mailpass"] = self.editMailPass.text()
        # check validity of important settings
        checkok = True
        items = []
        if self._work["usermail"] == "":
            items.append("Bruger email (fane 1)")
            checkok = False
        if self._work["userpass"] == "":
            items.append("Bruger kode (fane 1)")
            checkok = False
        if self._work["usercountry"] == "":
            items.append("Bruger land (fane 1)")
            checkok = False
        if self._work["smtp"] == "":
            items.append("SMTP server (fane 2)")
            checkok = False
        if self._work["port"] == "":
            items.append("SMTP port (fane 2)")
            checkok = False
        if self._work["mailto"] == "":
            items.append("Ordremodtager (fane 2)")
            checkok = False
        if self._work["http"] == "":
            items.append("Web server (fane 2)")
            checkok = False
        # inform user about settings validity
        if not checkok:
            msgbox = QMessageBox()
            msgbox.warning(self,
                           self.tr("Eordre"),
                           self.tr("Der er mangler i dine indstillinger!\n{}".format("\n".join(items))),
                           QMessageBox.Ok)
            return False
        # update password in settings
        if len(self._work["userpass"]) < 97:
            self._work["userpass"] = passwdFn.hash_password(self._work["userpass"])
        if len(self._work["mailpass"]) < 97:
            self._work["mailpass"] = passwdFn.hash_password(self._work["mailpass"])
        self._settings.active = self._work<commit_msg>code clenaup<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# Copyright: <NAME> <echo "ZmhAdWV4LmRrCg==" | base64 -d>
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QDialog, QMessageBox

from resources.settings_dialog_rc import Ui_settingsDialog
from util import utils, passwdFn


class SettingsDialog(QDialog, Ui_settingsDialog):
    """
    Dialog for entering and updating current
    """

    settings_changed = pyqtSignal()

    def __init__(self, settings, employees, parent=None):
        """Initialize the dialog"""
        super(SettingsDialog, self).__init__(parent)
        self.setupUi(self)  # setup ui from resource file
        self._settings = settings
        self._employees = employees
        self._work = self._settings.active

        # assign values to input fields
        self.editUserMail.setText(self._settings.purchase_order_line["usermail"])
        self.editUserPass.setText(self._settings.purchase_order_line["userpass"])
        self.editUserCountry.setText(self._settings.purchase_order_line["usercountry"])
        self.editHttp.setText(self._settings.purchase_order_line["http"])
        self.editSmtp.setText(self._settings.purchase_order_line["smtp"])
        self.editPort.setText(str(self._settings.purchase_order_line["port"]))
        self.editMailTo.setText(self._settings.purchase_order_line["mailto"])
        self.checkServerData.setChecked(utils.int2bool(self._settings.purchase_order_line["sc"]))
        self.editMailServer.setText(self._settings.purchase_order_line["mailserver"])
        self.editMailPort.setText(str(self._settings.purchase_order_line["mailport"]))
        self.editMailUser.setText(self._settings.purchase_order_line["mailuser"])
        self.editMailPass.setText(self._settings.purchase_order_line["mailpass"])
        # connect to signals
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)

    def accept(self):
        """
        User buttonbox_accepted_action current
        """
        # assign input fields to current
        self._work["usermail"] = self.editUserMail.text().lower()
        self._work["userpass"] = self.editUserPass.text()
        self._work["usercountry"] = self.editUserCountry.text().lower()
        self._work["http"] = self.editHttp.text().lower()
        self._work["smtp"] = self.editSmtp.text().lower()
        self._work["port"] = self.editPort.text()
        self._work["mailto"] = self.editMailTo.text().lower()
        self._work["sc"] = utils.bool2int(self.checkServerData.isChecked())
        self._work["mailserver"] = self.editMailServer.text().lower()
        self._work["mailport"] = self.editMailPort.text()
        self._work["mailuser"] = self.editMailUser.text()
        self._work["mailpass"] = self.editMailPass.text()
        # check validity of important settings
        checkok = True
        items = []
        if self._work["usermail"] == "":
            items.append("Bruger email (fane 1)")
            checkok = False
        if self._work["userpass"] == "":
            items.append("Bruger kode (fane 1)")
            checkok = False
        if self._work["usercountry"] == "":
            items.append("Bruger land (fane 1)")
            checkok = False
        if self._work["smtp"] == "":
            items.append("SMTP server (fane 2)")
            checkok = False
        if self._work["port"] == "":
            items.append("SMTP port (fane 2)")
            checkok = False
        if self._work["mailto"] == "":
            items.append("Ordremodtager (fane 2)")
            checkok = False
        if self._work["http"] == "":
            items.append("Web server (fane 2)")
            checkok = False
        # inform user about settings validity
        if not checkok:
            msgbox = QMessageBox()
            msgbox.warning(self, "Eordre",
                           "Der er mangler i dine indstillinger!\n{}".format("\n".join(items)),
                           QMessageBox.Ok)
            return False
        # update password in settings
        if len(self._work["userpass"]) < 97:
            self._work["userpass"] = <PASSWORD>Fn.hash_password(self._work["userpass"])
        if len(self._work["mailpass"]) < 97:
            self._work["mailpass"] = <PASSWORD>Fn.hash_password(self._work["mailpass"])
        self._settings.active = self._work
{'fraction_non_alphanumeric': 0.13667936365673314, 'fraction_numerical': 0.005377548734035402, 'mean_word_length': 2.672151378033731, 'pattern_counts': {'":': 14, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4196436', 'n_tokens_mistral': 2679, 'n_tokens_neox': 2627, 'n_words': 462}