18 |
18 |
19 class CycloneDXMetaDataDialog(QDialog, Ui_CycloneDXMetaDataDialog): |
19 class CycloneDXMetaDataDialog(QDialog, Ui_CycloneDXMetaDataDialog): |
20 """ |
20 """ |
21 Class implementing a dialog to edit the metadata of the CycloneDX SBOM. |
21 Class implementing a dialog to edit the metadata of the CycloneDX SBOM. |
22 """ |
22 """ |
|
23 |
23 ComponentTypeMapping = { |
24 ComponentTypeMapping = { |
24 ComponentType.APPLICATION: QCoreApplication.translate( |
25 ComponentType.APPLICATION: QCoreApplication.translate( |
25 "CycloneDXMetaDataDialog", "Application"), |
26 "CycloneDXMetaDataDialog", "Application" |
|
27 ), |
26 ComponentType.CONTAINER: QCoreApplication.translate( |
28 ComponentType.CONTAINER: QCoreApplication.translate( |
27 "CycloneDXMetaDataDialog", "Container"), |
29 "CycloneDXMetaDataDialog", "Container" |
|
30 ), |
28 ComponentType.DEVICE: QCoreApplication.translate( |
31 ComponentType.DEVICE: QCoreApplication.translate( |
29 "CycloneDXMetaDataDialog", "Device"), |
32 "CycloneDXMetaDataDialog", "Device" |
|
33 ), |
30 ComponentType.FILE: QCoreApplication.translate( |
34 ComponentType.FILE: QCoreApplication.translate( |
31 "CycloneDXMetaDataDialog", "File"), |
35 "CycloneDXMetaDataDialog", "File" |
|
36 ), |
32 ComponentType.FIRMWARE: QCoreApplication.translate( |
37 ComponentType.FIRMWARE: QCoreApplication.translate( |
33 "CycloneDXMetaDataDialog", "Firmware"), |
38 "CycloneDXMetaDataDialog", "Firmware" |
|
39 ), |
34 ComponentType.FRAMEWORK: QCoreApplication.translate( |
40 ComponentType.FRAMEWORK: QCoreApplication.translate( |
35 "CycloneDXMetaDataDialog", "Framework"), |
41 "CycloneDXMetaDataDialog", "Framework" |
|
42 ), |
36 ComponentType.LIBRARY: QCoreApplication.translate( |
43 ComponentType.LIBRARY: QCoreApplication.translate( |
37 "CycloneDXMetaDataDialog", "Library"), |
44 "CycloneDXMetaDataDialog", "Library" |
|
45 ), |
38 ComponentType.OPERATING_SYSTEM: QCoreApplication.translate( |
46 ComponentType.OPERATING_SYSTEM: QCoreApplication.translate( |
39 "CycloneDXMetaDataDialog", "Operating System"), |
47 "CycloneDXMetaDataDialog", "Operating System" |
|
48 ), |
40 } |
49 } |
41 |
50 |
42 def __init__(self, metadata=None, parent=None): |
51 def __init__(self, metadata=None, parent=None): |
43 """ |
52 """ |
44 Constructor |
53 Constructor |
45 |
54 |
46 @param metadata dictionary containing metadata to populate the dialog |
55 @param metadata dictionary containing metadata to populate the dialog |
47 (defaults to None) |
56 (defaults to None) |
48 @type dict (optional) |
57 @type dict (optional) |
49 @param parent reference to the parent widget (defaults to None) |
58 @param parent reference to the parent widget (defaults to None) |
50 @type QWidget (optional) |
59 @type QWidget (optional) |
51 """ |
60 """ |
52 super().__init__(parent) |
61 super().__init__(parent) |
53 self.setupUi(self) |
62 self.setupUi(self) |
54 |
63 |
55 self.__populateComponentTypeSelector() |
64 self.__populateComponentTypeSelector() |
56 self.__populateLicenseSelector() |
65 self.__populateLicenseSelector() |
57 |
66 |
58 if metadata: |
67 if metadata: |
59 # populate the dialog from given metadata dictionary |
68 # populate the dialog from given metadata dictionary |
60 self.nameEdit.setText(metadata["Name"]) |
69 self.nameEdit.setText(metadata["Name"]) |
61 self.versionEdit.setText(metadata["Version"]) |
70 self.versionEdit.setText(metadata["Version"]) |
62 self.descriptionEdit.setPlainText(metadata["Description"]) |
71 self.descriptionEdit.setPlainText(metadata["Description"]) |
65 self.licenseComboBox.setCurrentText(metadata["License"]) |
74 self.licenseComboBox.setCurrentText(metadata["License"]) |
66 self.manufacturerEdit.setText(metadata["Manufacturer"]) |
75 self.manufacturerEdit.setText(metadata["Manufacturer"]) |
67 self.supplierEdit.setText(metadata["Supplier"]) |
76 self.supplierEdit.setText(metadata["Supplier"]) |
68 index = self.typeComboBox.findData(metadata["Type"]) |
77 index = self.typeComboBox.findData(metadata["Type"]) |
69 self.typeComboBox.setCurrentIndex(index) |
78 self.typeComboBox.setCurrentIndex(index) |
70 |
79 |
71 self.nameEdit.textChanged.connect(self.__updateOkButton) |
80 self.nameEdit.textChanged.connect(self.__updateOkButton) |
72 self.typeComboBox.currentTextChanged.connect(self.__updateOkButton) |
81 self.typeComboBox.currentTextChanged.connect(self.__updateOkButton) |
73 self.licenseComboBox.currentTextChanged.connect(self.__updateOkButton) |
82 self.licenseComboBox.currentTextChanged.connect(self.__updateOkButton) |
74 |
83 |
75 self.__updateOkButton() |
84 self.__updateOkButton() |
76 |
85 |
77 def __populateComponentTypeSelector(self): |
86 def __populateComponentTypeSelector(self): |
78 """ |
87 """ |
79 Private method to populate the component type selector. |
88 Private method to populate the component type selector. |
80 """ |
89 """ |
81 self.typeComboBox.addItem("", "") |
90 self.typeComboBox.addItem("", "") |
82 for componentType, displayStr in sorted( |
91 for componentType, displayStr in sorted( |
83 CycloneDXMetaDataDialog.ComponentTypeMapping.items(), |
92 CycloneDXMetaDataDialog.ComponentTypeMapping.items(), key=lambda x: x[1] |
84 key=lambda x: x[1] |
|
85 ): |
93 ): |
86 self.typeComboBox.addItem(displayStr, componentType) |
94 self.typeComboBox.addItem(displayStr, componentType) |
87 |
95 |
88 def __populateLicenseSelector(self): |
96 def __populateLicenseSelector(self): |
89 """ |
97 """ |
90 Private method to populate the license selector with the list of trove |
98 Private method to populate the license selector with the list of trove |
91 license types. |
99 license types. |
92 """ |
100 """ |
93 self.licenseComboBox.addItem("") |
101 self.licenseComboBox.addItem("") |
94 self.licenseComboBox.addItems(sorted( |
102 self.licenseComboBox.addItems( |
95 classifier.split("::")[-1].strip() |
103 sorted( |
96 for classifier in trove_classifiers.classifiers |
104 classifier.split("::")[-1].strip() |
97 if classifier.startswith("License ::") |
105 for classifier in trove_classifiers.classifiers |
98 )) |
106 if classifier.startswith("License ::") |
99 |
107 ) |
|
108 ) |
|
109 |
100 @pyqtSlot() |
110 @pyqtSlot() |
101 def __updateOkButton(self): |
111 def __updateOkButton(self): |
102 """ |
112 """ |
103 Private slot to update the enabled state of the OK button. |
113 Private slot to update the enabled state of the OK button. |
104 """ |
114 """ |
105 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
115 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
106 bool(self.nameEdit.text()) and |
116 bool(self.nameEdit.text()) |
107 bool(self.typeComboBox.currentText()) and |
117 and bool(self.typeComboBox.currentText()) |
108 bool(self.licenseComboBox.currentText()) |
118 and bool(self.licenseComboBox.currentText()) |
109 ) |
119 ) |
110 |
120 |
111 def getMetaData(self): |
121 def getMetaData(self): |
112 """ |
122 """ |
113 Public method to get the entered data. |
123 Public method to get the entered data. |
114 |
124 |
115 @return dictionary containing the metadata. |
125 @return dictionary containing the metadata. |
116 @rtype dict |
126 @rtype dict |
117 """ |
127 """ |
118 return { |
128 return { |
119 "Name": self.nameEdit.text(), |
129 "Name": self.nameEdit.text(), |