# Path: asammdf/blocks/utils.py
# def extract_encryption_information(comment: str) -> dict[str, str]:
#     info = {}
#     if comment.startswith("<ATcomment") and "<encrypted>" in comment:
# 
#         try:
#             comment = ET.fromstring(comment)
#             for match in comment.findall(".//extensions/extension"):
#                 encrypted = match.find("encrypted").text.strip().lower() == "true"
#                 algorithm = match.find("algorithm").text.strip().lower()
#                 original_md5_sum = match.find("original_md5_sum").text.strip().lower()
#                 original_size = int(match.find("original_size").text)
# 
#                 info["encrypted"] = encrypted
#                 info["algorithm"] = algorithm
#                 info["original_md5_sum"] = original_md5_sum
#                 info["original_size"] = original_size
#                 break
#         except:
#             pass
# 
#     return info
# 
# Path: asammdf/gui/ui/resource_rc.py
# def qInitResources():
# def qCleanupResources():
# 
# Path: asammdf/gui/ui/attachment.py
# class Ui_Attachment(object):
#     def setupUi(self, Attachment):
#         Attachment.setObjectName("Attachment")
#         Attachment.resize(717, 205)
#         self.horizontalLayout = QtWidgets.QHBoxLayout(Attachment)
#         self.horizontalLayout.setObjectName("horizontalLayout")
#         self.number = QtWidgets.QLabel(Attachment)
#         self.number.setObjectName("number")
#         self.horizontalLayout.addWidget(self.number)
#         self.fields = QtWidgets.QTreeWidget(Attachment)
#         self.fields.setMinimumSize(QtCore.QSize(0, 187))
#         self.fields.setObjectName("fields")
#         self.fields.header().setVisible(True)
#         self.fields.header().setMinimumSectionSize(100)
#         self.horizontalLayout.addWidget(self.fields)
#         self.extract_btn = QtWidgets.QPushButton(Attachment)
#         icon = QtGui.QIcon()
#         icon.addPixmap(QtGui.QPixmap(":/export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
#         self.extract_btn.setIcon(icon)
#         self.extract_btn.setObjectName("extract_btn")
#         self.horizontalLayout.addWidget(self.extract_btn)
#         self.horizontalLayout.setStretch(1, 1)
# 
#         self.retranslateUi(Attachment)
#         QtCore.QMetaObject.connectSlotsByName(Attachment)
# 
#     def retranslateUi(self, Attachment):
#         _translate = QtCore.QCoreApplication.translate
#         Attachment.setWindowTitle(_translate("Attachment", "Form"))
#         self.number.setText(_translate("Attachment", "Number"))
#         self.fields.headerItem().setText(0, _translate("Attachment", "Item"))
#         self.fields.headerItem().setText(1, _translate("Attachment", "Value"))
#         self.extract_btn.setText(_translate("Attachment", "Extract"))


from pathlib import Path
from PyQt5 import QtWidgets
from ...blocks.utils import extract_encryption_information
from ..ui import resource_rc as resource_rc
from ..ui.attachment import Ui_Attachment
# -*- coding: utf-8 -*-




class Attachment(Ui_Attachment, QtWidgets.QWidget):
    def __init__(self, index, mdf, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setupUi(self)

        self.extract_btn.clicked.connect(self.extract)
        self.mdf = mdf
        self.index = index

    def extract(self, event=None):
        attachment = self.mdf.attachments[self.index]

# Path: asammdf/blocks/utils.py
# def extract_encryption_information(comment: str) -> dict[str, str]:
#     info = {}
#     if comment.startswith("<ATcomment") and "<encrypted>" in comment:
# 
#         try:
#             comment = ET.fromstring(comment)
#             for match in comment.findall(".//extensions/extension"):
#                 encrypted = match.find("encrypted").text.strip().lower() == "true"
#                 algorithm = match.find("algorithm").text.strip().lower()
#                 original_md5_sum = match.find("original_md5_sum").text.strip().lower()
#                 original_size = int(match.find("original_size").text)
# 
#                 info["encrypted"] = encrypted
#                 info["algorithm"] = algorithm
#                 info["original_md5_sum"] = original_md5_sum
#                 info["original_size"] = original_size
#                 break
#         except:
#             pass
# 
#     return info
# 
# Path: asammdf/gui/ui/resource_rc.py
# def qInitResources():
# def qCleanupResources():
# 
# Path: asammdf/gui/ui/attachment.py
# class Ui_Attachment(object):
#     def setupUi(self, Attachment):
#         Attachment.setObjectName("Attachment")
#         Attachment.resize(717, 205)
#         self.horizontalLayout = QtWidgets.QHBoxLayout(Attachment)
#         self.horizontalLayout.setObjectName("horizontalLayout")
#         self.number = QtWidgets.QLabel(Attachment)
#         self.number.setObjectName("number")
#         self.horizontalLayout.addWidget(self.number)
#         self.fields = QtWidgets.QTreeWidget(Attachment)
#         self.fields.setMinimumSize(QtCore.QSize(0, 187))
#         self.fields.setObjectName("fields")
#         self.fields.header().setVisible(True)
#         self.fields.header().setMinimumSectionSize(100)
#         self.horizontalLayout.addWidget(self.fields)
#         self.extract_btn = QtWidgets.QPushButton(Attachment)
#         icon = QtGui.QIcon()
#         icon.addPixmap(QtGui.QPixmap(":/export.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
#         self.extract_btn.setIcon(icon)
#         self.extract_btn.setObjectName("extract_btn")
#         self.horizontalLayout.addWidget(self.extract_btn)
#         self.horizontalLayout.setStretch(1, 1)
# 
#         self.retranslateUi(Attachment)
#         QtCore.QMetaObject.connectSlotsByName(Attachment)
# 
#     def retranslateUi(self, Attachment):
#         _translate = QtCore.QCoreApplication.translate
#         Attachment.setWindowTitle(_translate("Attachment", "Form"))
#         self.number.setText(_translate("Attachment", "Number"))
#         self.fields.headerItem().setText(0, _translate("Attachment", "Item"))
#         self.fields.headerItem().setText(1, _translate("Attachment", "Value"))
#         self.extract_btn.setText(_translate("Attachment", "Extract"))


# Path: asammdf/gui/widgets/attachment.py
from pathlib import Path
from PyQt5 import QtWidgets
from ...blocks.utils import extract_encryption_information
from ..ui import resource_rc as resource_rc
from ..ui.attachment import Ui_Attachment

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




class Attachment(Ui_Attachment, QtWidgets.QWidget):
    def __init__(self, index, mdf, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setupUi(self)

        self.extract_btn.clicked.connect(self.extract)
        self.mdf = mdf
        self.index = index

    def extract(self, event=None):
        attachment = self.mdf.attachments[self.index]

        encryption_info = extract_encryption_information(attachment.comment)