1 #include "newpalacios.h"
3 VmInfoWidget::VmInfoWidget(QWidget* parent) :
9 VmInfoWidget::~VmInfoWidget() {
13 void VmInfoWidget::setInfoView() {
14 // Create the main tree widget
15 mVmInfoView = new QTreeWidget();
16 mVmInfoView->setColumnCount(2);
17 QStringList headerLabels;
18 headerLabels << "Property" << "Value";
19 mVmInfoView->setHeaderLabels(headerLabels);
22 void VmInfoWidget::setupUi() {
23 QVBoxLayout* vmDetailsLayout = new QVBoxLayout(this);
24 vmDetailsLayout->addWidget(mVmInfoView);
25 setLayout(vmDetailsLayout);
28 void VmInfoWidget::parseAttribute(const QDomElement &element,
29 QTreeWidgetItem* parent) {
30 QDomNamedNodeMap atts = element.attributes();
32 for (unsigned int i=0; i<atts.length(); i++) {
33 QTreeWidgetItem* item = new QTreeWidgetItem(parent);
35 item->setText(0, "[" + atts.item(i).nodeName() +"]");
36 item->setText(1, "[" + atts.item(i).nodeValue() +"]");
40 void VmInfoWidget::parseText(const QDomElement &element,
41 QTreeWidgetItem* parent) {
42 QString value = element.text();
43 parent->setText(1, value);
46 void VmInfoWidget::parseElement(const QDomElement &element,
47 QTreeWidgetItem* parent) {
49 QTreeWidgetItem* item = new QTreeWidgetItem(parent);
51 if (element.tagName().compare("memory") == 0) {
53 item->setText(0, "memory");
54 parseAttribute(element, item);
55 parseText(element, item);
57 } else if (element.tagName().compare("telemetry") == 0) {
59 item->setText(0, "telemetry");
60 parseText(element, item);
62 } else if (element.tagName().compare("extensions") == 0) {
64 item->setText(0, "extensions");
65 QDomNode child = element.firstChild();
66 while (!child.isNull()) {
67 if (!child.isElement()) {
68 child = child.nextSibling();
72 parseElement(child.toElement(), item);
73 child = child.nextSibling();
76 } else if (element.tagName().compare("extension") == 0) {
78 item->setText(0, "extension");
79 parseAttribute(element, item);
80 parseText(element, item);
82 } else if (element.tagName().compare("paging") == 0) {
84 item->setText(0, "paging");
85 parseAttribute(element, item);
86 QDomNode child = element.firstChild();
87 while (!child.isNull()) {
88 if (!child.isElement()) {
89 child = child.nextSibling();
93 parseElement(child.toElement(), item);
94 child = child.nextSibling();
97 } else if (element.tagName().compare("strategy") == 0) {
98 item->setText(0, "strategy");
99 parseText(element, item);
101 } else if (element.tagName().compare("large_pages") == 0) {
102 item->setText(0, "large_pages");
103 parseText(element, item);
105 } else if (element.tagName().compare("schedule_hz") == 0) {
107 item->setText(0, "schedule_hz");
108 parseText(element, item);
110 } else if (element.tagName().compare("cores") == 0) {
112 item->setText(0, "cores");
113 parseAttribute(element, item);
115 } else if (element.tagName().compare("core") == 0) {
116 item->setText(0, "core");
118 } else if (element.tagName().compare("memmap") == 0) {
119 item->setText(0, "memmap");
120 QDomNode child = element.firstChild();
121 while (!child.isNull()) {
123 if (!child.isElement()) {
124 child = child.nextSibling();
128 parseElement(child.toElement(), item);
129 child = child.nextSibling();
132 } else if (element.tagName().compare("region") == 0) {
133 item->setText(0, "region");
134 QDomNode child = element.firstChild();
135 while (!child.isNull()) {
136 if (!child.isElement()) {
137 child = child.nextSibling();
141 parseElement(child.toElement(), item);
142 child = child.nextSibling();
145 } else if (element.tagName().compare("start") == 0) {
146 item->setText(0, "start");
147 parseText(element, item);
149 } else if (element.tagName().compare("end") == 0) {
150 item->setText(0, "end");
151 parseText(element, item);
153 } else if (element.tagName().compare("host_addr") == 0) {
154 item->setText(0, "host_addr");
155 parseText(element, item);
157 } else if (element.tagName().compare("files") == 0) {
158 item->setText(0, "files");
159 QDomNode child = element.firstChild();
160 while (!child.isNull()) {
161 if (!child.isElement()) {
162 child = child.nextSibling();
166 parseElement(child.toElement(), item);
167 child = child.nextSibling();
170 } else if (element.tagName().compare("file") == 0) {
171 item->setText(0, "file");
172 parseAttribute(element, item);
174 } else if (element.tagName().compare("devices") == 0) {
176 item->setText(0, "devices");
177 QDomNode child = element.firstChild();
178 while (!child.isNull()) {
179 if (!child.isElement()) {
180 child = child.nextSibling();
184 parseElement(child.toElement(), item);
185 child = child.nextSibling();
188 } else if (element.tagName().compare("device") == 0) {
190 item->setText(0, "device");
191 parseAttribute(element, item);
192 QDomNode child = element.firstChild();
193 while (!child.isNull()) {
194 if (!child.isElement()) {
195 child = child.nextSibling();
199 parseElement(child.toElement(), item);
200 child = child.nextSibling();
203 } else if (element.tagName().compare("storage") == 0) {
204 item->setText(0, "storage");
205 parseText(element, item);
207 } else if (element.tagName().compare("apic") == 0) {
208 item->setText(0, "apic");
209 parseText(element, item);
211 } else if (element.tagName().compare("bus") == 0) {
212 // Bus tag, is seen in many device tags
214 } else if (element.tagName().compare("vendor_id") == 0) {
215 item->setText(0, "vendor_id");
216 parseText(element, item);
218 } else if (element.tagName().compare("device_id") == 0) {
219 item->setText(0, "device_id");
220 parseText(element, item);
222 } else if (element.tagName().compare("irq") == 0) {
223 item->setText(0, "irq");
224 parseText(element, item);
226 } else if (element.tagName().compare("controller") == 0) {
227 // Controller tag, is also seen in some device files
228 item->setText(0, "controller");
229 parseText(element, item);
231 } else if (element.tagName().compare("file") == 0) {
232 item->setText(0, "file");
233 parseText(element, item);
235 } else if (element.tagName().compare("frontend") == 0) {
236 item->setText(0, "frontend");
237 parseAttribute(element, item);
238 QDomNode child = element.firstChild();
239 while (!child.isNull()) {
240 if (!child.isElement()) {
241 child = child.nextSibling();
245 parseElement(child.toElement(), item);
246 child = child.nextSibling();
249 } else if (element.tagName().compare("model") == 0) {
250 item->setText(0, "model");
251 parseText(element, item);
253 } else if (element.tagName().compare("type") == 0) {
254 item->setText(0, "type");
255 parseText(element, item);
257 } else if (element.tagName().compare("bus_num") == 0) {
258 item->setText(0, "bus_num");
259 parseText(element, item);
261 } else if (element.tagName().compare("drive_num") == 0) {
262 item->setText(0, "drive_num");
263 parseText(element, item);
265 } else if (element.tagName().compare("path") == 0) {
266 item->setText(0, "path");
267 parseText(element, item);
269 } else if (element.tagName().compare("ip") == 0) {
270 item->setText(0, "ip");
271 parseText(element, item);
273 } else if (element.tagName().compare("port") == 0) {
274 item->setText(0, "port");
275 parseText(element, item);
277 } else if (element.tagName().compare("tag") == 0) {
278 item->setText(0, "tag");
279 parseText(element, item);
281 } else if (element.tagName().compare("size") == 0) {
282 item->setText(0, "size");
283 parseText(element, item);
285 } else if (element.tagName().compare("mac") == 0) {
286 item->setText(0, "mac");
287 parseText(element, item);
289 } else if (element.tagName().compare("name") == 0) {
290 item->setText(0, "name");
291 parseText(element, item);
293 } else if (element.tagName().compare("ports") == 0) {
294 item->setText(0, "ports");
295 QDomNode child = element.firstChild();
296 while (!child.isNull()) {
297 if (!child.isElement()) {
298 child = child.nextSibling();
302 parseElement(child.toElement(), item);
303 child = child.nextSibling();
306 } else if (element.tagName().compare("mode") == 0) {
307 item->setText(0, "mode");
308 parseText(element, item);
313 void VmInfoWidget::updateInfoView(VmInfo* vm) {
315 QFile file(vm->getVmConfigFile());
316 if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
317 qDebug() << "File cannot be opened!";
322 QDomDocument doc("vm_config");
323 if (!doc.setContent(&file)) {
324 qDebug() << "Error setting content";
331 QTreeWidgetItem* rootItem = new QTreeWidgetItem();
332 QDomElement root = doc.documentElement();
334 rootItem->setText(0, root.tagName());
335 parseAttribute(root, rootItem);
336 mVmInfoView->takeTopLevelItem(0);
337 mVmInfoView->addTopLevelItem(rootItem);
340 QDomNode n = root.firstChild();
341 while (!n.isNull()) {
344 parseElement(n.toElement(), rootItem);
350 mVmInfoView->expandAll();
353 void VmInfoWidget::deleteVm() {
354 QTreeWidgetItem* item = mVmInfoView->takeTopLevelItem(0);