# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'job-log-dialog.ui'
#
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


try:
    from qt.core import Qt, QDialog, QLabel, QMessageBox, QPushButton, QVBoxLayout, QProgressBar, QWidget, QComboBox, QHBoxLayout, QPlainTextEdit, QSize, QSizePolicy
except ImportError:
    from PyQt5.Qt import Qt, QDialog, QLabel, QMessageBox, QPushButton, QVBoxLayout, QProgressBar, QWidget, QComboBox, QHBoxLayout, QPlainTextEdit, QSize, QSizePolicy

from PyQt5 import QtCore, QtGui, QtWidgets


class JobLogDialog(QDialog):
    
    def __init__(self, gui, icon, *args):
        QDialog.__init__(self, gui)
        self.gui = gui
        self.db = gui.current_db        
        
        self.setObjectName("Dialog")
        self.resize(678, 569)
        self.verticalLayout = QtWidgets.QVBoxLayout(self)
        self.verticalLayout.setObjectName("verticalLayout")
        self.label = QtWidgets.QLabel(self)
        self.label.setStyleSheet("font-weight:bold;")
        self.label.setTextFormat(QtCore.Qt.PlainText)
        self.label.setObjectName("label")
        self.verticalLayout.addWidget(self.label)
        self.textBrowser = QtWidgets.QTextEdit(self)
        self.textBrowser.setFrameShape(QtWidgets.QFrame.WinPanel)
        self.textBrowser.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.textBrowser.setObjectName("textBrowser")
        self.verticalLayout.addWidget(self.textBrowser)
        self.buttonBox = QtWidgets.QDialogButtonBox(self)
        self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
        self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Ok)
        self.buttonBox.setObjectName("buttonBox")
        self.verticalLayout.addWidget(self.buttonBox)

        self.retranslateUi(self)
        self.buttonBox.accepted.connect(self.accept) # type: ignore
        self.buttonBox.rejected.connect(self.reject) # type: ignore
        QtCore.QMetaObject.connectSlotsByName(self)
        self.load_logfile()
    
    def load_logfile(self):
        self.log_file = 'AI Custom Tag Extractor - Job.log'
        from calibre.constants import CONFIG_DIR_MODE, config_dir
        import os
        self.log_file = os.path.join(config_dir, 'plugins') + os.sep + self.log_file
        with open(self.log_file, "r") as file:
            text = [line.rstrip() for line in file]
        for line in text:
            self.textBrowser.append(line)
    
    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        Dialog.label.setText(_translate("Dialog", "Job Log:"))
        Dialog.textBrowser.setDocumentTitle(_translate("Dialog", "JobLog"))
        Dialog.textBrowser.setPlaceholderText(_translate("Dialog", "Loading Log..."))