1 | /**
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * "VirtualBox Information Dialog" dialog UI include (Qt Designer)
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006 innotek GmbH
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License as published by the Free Software Foundation,
|
---|
14 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
15 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
16 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | */
|
---|
18 |
|
---|
19 | /****************************************************************************
|
---|
20 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
21 | **
|
---|
22 | ** If you wish to add, delete or rename functions or slots use
|
---|
23 | ** Qt Designer which will update this file, preserving your code. Create an
|
---|
24 | ** init() function in place of a constructor, and a destroy() function in
|
---|
25 | ** place of a destructor.
|
---|
26 | *****************************************************************************/
|
---|
27 |
|
---|
28 |
|
---|
29 | VBoxVMInformationDlg::InfoDlgMap VBoxVMInformationDlg::mSelfArray = InfoDlgMap();
|
---|
30 |
|
---|
31 | void VBoxVMInformationDlg::createInformationDlg (const CSession &aSession,
|
---|
32 | VBoxConsoleView *aConsole)
|
---|
33 | {
|
---|
34 | CMachine machine = aSession.GetMachine();
|
---|
35 | if (mSelfArray.find (machine.GetName()) == mSelfArray.end())
|
---|
36 | {
|
---|
37 | /* creating new information dialog if there is no one existing */
|
---|
38 | mSelfArray [machine.GetName()] = new VBoxVMInformationDlg (
|
---|
39 | aConsole,
|
---|
40 | "VBoxVMInformationDlg", WType_TopLevel | WDestructiveClose);
|
---|
41 | /* read new machine data for this information dialog */
|
---|
42 | mSelfArray [machine.GetName()]->setup (aSession, aConsole);
|
---|
43 | }
|
---|
44 |
|
---|
45 | VBoxVMInformationDlg *info = mSelfArray [machine.GetName()];
|
---|
46 | info->show();
|
---|
47 | info->raise();
|
---|
48 | info->setWindowState (info->windowState() & ~WindowMinimized);
|
---|
49 | info->setActiveWindow();
|
---|
50 | }
|
---|
51 |
|
---|
52 |
|
---|
53 | void VBoxVMInformationDlg::init()
|
---|
54 | {
|
---|
55 | /* dialog initially is not polished */
|
---|
56 | mIsPolished = false;
|
---|
57 |
|
---|
58 | /* search the default button */
|
---|
59 | mDefaultButton = searchDefaultButton();
|
---|
60 | qApp->installEventFilter (this);
|
---|
61 |
|
---|
62 | /* setup a dialog icon */
|
---|
63 | setIcon (QPixmap::fromMimeSource ("description_16px.png"));
|
---|
64 |
|
---|
65 | /* statusbar initially disabled */
|
---|
66 | statusBar()->setHidden (true);
|
---|
67 |
|
---|
68 | /* setup size grip */
|
---|
69 | mSizeGrip = new QSizeGrip (centralWidget(), "mSizeGrip");
|
---|
70 | mSizeGrip->resize (mSizeGrip->sizeHint());
|
---|
71 | mSizeGrip->stackUnder (mCloseButton);
|
---|
72 |
|
---|
73 | /* logs list creation */
|
---|
74 | mInfoStack = new QTabWidget (mInfoFrame, "mInfoStack");
|
---|
75 | mInfoStack->setMargin (10);
|
---|
76 | QVBoxLayout *infoFrameLayout = new QVBoxLayout (mInfoFrame);
|
---|
77 | infoFrameLayout->addWidget (mInfoStack);
|
---|
78 |
|
---|
79 | /* details view creation */
|
---|
80 | mDetailsText = new QTextBrowser();
|
---|
81 | mDetailsText->setFrameShape (QFrame::NoFrame);
|
---|
82 | mDetailsText->setPaper (backgroundBrush());
|
---|
83 | mInfoStack->addTab (mDetailsText,
|
---|
84 | VBoxGlobal::iconSet ("settings_16px.png"),
|
---|
85 | QString::null);
|
---|
86 |
|
---|
87 | /* statistic view creation */
|
---|
88 | mStatisticText = new QTextBrowser();
|
---|
89 | mStatisticText->setFrameShape (QFrame::NoFrame);
|
---|
90 | mStatisticText->setPaper (backgroundBrush());
|
---|
91 | mInfoStack->addTab (mStatisticText,
|
---|
92 | VBoxGlobal::iconSet ("state_running_16px.png"),
|
---|
93 | QString::null);
|
---|
94 |
|
---|
95 | /* full list of statistics counters to get total info */
|
---|
96 | // mDefStatText = new QTextBrowser();
|
---|
97 | // mDefStatText->setFrameShape (QFrame::NoFrame);
|
---|
98 | // mDefStatText->setPaper (backgroundBrush());
|
---|
99 | // mInfoStack->addTab (mDefStatText,
|
---|
100 | // VBoxGlobal::iconSet ("show_logs_16px.png"),
|
---|
101 | // QString::null);
|
---|
102 |
|
---|
103 | /* applying language settings */
|
---|
104 | languageChangeImp();
|
---|
105 |
|
---|
106 | /* show statistics page and make it focused */
|
---|
107 | connect (mInfoStack, SIGNAL (currentChanged (QWidget*)),
|
---|
108 | this, SLOT (onPageChanged (QWidget*)));
|
---|
109 | mInfoStack->showPage (mStatisticText);
|
---|
110 | }
|
---|
111 |
|
---|
112 |
|
---|
113 | void VBoxVMInformationDlg::destroy()
|
---|
114 | {
|
---|
115 | /* save dialog attributes for this vm */
|
---|
116 | QString dlgsize ("%1,%2,%3");
|
---|
117 | mSession.GetMachine().SetExtraData (VBoxDefs::GUI_InfoDlgState,
|
---|
118 | dlgsize.arg (mWidth).arg (mHeight).arg (isMaximized() ? "max" : "normal"));
|
---|
119 |
|
---|
120 | if (!mSession.isNull() && !mSession.GetMachine().isNull())
|
---|
121 | mSelfArray.erase (mSession.GetMachine().GetName());
|
---|
122 | }
|
---|
123 |
|
---|
124 |
|
---|
125 | void VBoxVMInformationDlg::setup (const CSession &aSession,
|
---|
126 | VBoxConsoleView *aConsole)
|
---|
127 | {
|
---|
128 | /* store related machine pointers */
|
---|
129 | mSession = aSession;
|
---|
130 | mConsole = aConsole;
|
---|
131 |
|
---|
132 | /* loading language constants */
|
---|
133 | languageChangeImp();
|
---|
134 |
|
---|
135 | /* details page update */
|
---|
136 | updateDetails();
|
---|
137 |
|
---|
138 | /* statistics page update */
|
---|
139 | processStatistics();
|
---|
140 | mStatTimer.start (5000);
|
---|
141 |
|
---|
142 | /* setup handlers */
|
---|
143 | connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
|
---|
144 | this, SLOT (updateDetails()));
|
---|
145 | connect (mConsole, SIGNAL (mediaChanged (VBoxDefs::DiskType)),
|
---|
146 | this, SLOT (updateDetails()));
|
---|
147 | connect (mConsole, SIGNAL (sharedFoldersChanged()),
|
---|
148 | this, SLOT (updateDetails()));
|
---|
149 |
|
---|
150 | connect (&mStatTimer, SIGNAL (timeout()), this, SLOT (processStatistics()));
|
---|
151 | connect (mConsole, SIGNAL (resizeHintDone()), this, SLOT (processStatistics()));
|
---|
152 |
|
---|
153 | /* preload dialog attributes for this vm */
|
---|
154 | QString dlgsize = mSession.GetMachine().GetExtraData (VBoxDefs::GUI_InfoDlgState);
|
---|
155 | if (dlgsize.isNull())
|
---|
156 | {
|
---|
157 | mWidth = 400;
|
---|
158 | mHeight = 450;
|
---|
159 | mMax = false;
|
---|
160 | }
|
---|
161 | else
|
---|
162 | {
|
---|
163 | QStringList list = QStringList::split (',', dlgsize);
|
---|
164 | mWidth = list [0].toInt(), mHeight = list [1].toInt();
|
---|
165 | mMax = list [2] == "max";
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | void VBoxVMInformationDlg::languageChangeImp()
|
---|
171 | {
|
---|
172 | /* Setup a dialog caption. */
|
---|
173 | if (!mSession.isNull() && !mSession.GetMachine().isNull())
|
---|
174 | setCaption (tr ("%1 - Session Information")
|
---|
175 | .arg (mSession.GetMachine().GetName()));
|
---|
176 |
|
---|
177 | /* Setup a tabwidget page names. */
|
---|
178 | mInfoStack->changeTab (mDetailsText, tr ("&Details"));
|
---|
179 | mInfoStack->changeTab (mStatisticText, tr ("&Runtime"));
|
---|
180 | // mInfoStack->changeTab (mDefStatText, tr ("De&fault Stat"));
|
---|
181 |
|
---|
182 | /* Clear counter names initially. */
|
---|
183 | mNamesMap.clear();
|
---|
184 |
|
---|
185 | /* HD statistics: */
|
---|
186 | mNamesMap ["/Devices/ATA0/Unit0/*DMA"] = tr ("DMA Transfers");
|
---|
187 | mNamesMap ["/Devices/ATA0/Unit0/*PIO"] = tr ("PIO Transfers");
|
---|
188 | mNamesMap ["/Devices/ATA0/Unit0/ReadBytes"] = tr ("Data Read");
|
---|
189 | mNamesMap ["/Devices/ATA0/Unit0/WrittenBytes"] = tr ("Data Written");
|
---|
190 |
|
---|
191 | mNamesMap ["/Devices/ATA0/Unit1/*DMA"] = tr ("DMA Transfers");
|
---|
192 | mNamesMap ["/Devices/ATA0/Unit1/*PIO"] = tr ("PIO Transfers");
|
---|
193 | mNamesMap ["/Devices/ATA0/Unit1/ReadBytes"] = tr ("Data Read");
|
---|
194 | mNamesMap ["/Devices/ATA0/Unit1/WrittenBytes"] = tr ("Data Written");
|
---|
195 |
|
---|
196 | mNamesMap ["/Devices/ATA1/Unit0/*DMA"] = tr ("DMA Transfers");
|
---|
197 | mNamesMap ["/Devices/ATA1/Unit0/*PIO"] = tr ("PIO Transfers");
|
---|
198 | mNamesMap ["/Devices/ATA1/Unit0/ReadBytes"] = tr ("Data Read");
|
---|
199 | mNamesMap ["/Devices/ATA1/Unit0/WrittenBytes"] = tr ("Data Written");
|
---|
200 |
|
---|
201 | mNamesMap ["/Devices/ATA1/Unit1/*DMA"] = tr ("DMA Transfers");
|
---|
202 | mNamesMap ["/Devices/ATA1/Unit1/*PIO"] = tr ("PIO Transfers");
|
---|
203 | mNamesMap ["/Devices/ATA1/Unit1/ReadBytes"] = tr ("Data Read");
|
---|
204 | mNamesMap ["/Devices/ATA1/Unit1/WrittenBytes"] = tr ("Data Written");
|
---|
205 |
|
---|
206 | mNamesMap ["/Devices/PCNet0/TransmitBytes"] = tr ("Data Transmitted");
|
---|
207 | mNamesMap ["/Devices/PCNet0/ReceiveBytes"] = tr ("Data Received");
|
---|
208 |
|
---|
209 | mNamesMap ["/Devices/PCNet1/TransmitBytes"] = tr ("Data Transmitted");
|
---|
210 | mNamesMap ["/Devices/PCNet1/ReceiveBytes"] = tr ("Data Received");
|
---|
211 |
|
---|
212 | mNamesMap ["/Devices/PCNet2/TransmitBytes"] = tr ("Data Transmitted");
|
---|
213 | mNamesMap ["/Devices/PCNet2/ReceiveBytes"] = tr ("Data Received");
|
---|
214 |
|
---|
215 | mNamesMap ["/Devices/PCNet3/TransmitBytes"] = tr ("Data Transmitted");
|
---|
216 | mNamesMap ["/Devices/PCNet3/ReceiveBytes"] = tr ("Data Received");
|
---|
217 |
|
---|
218 | /* Statistics page update. */
|
---|
219 | refreshStatistics();
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | QPushButton* VBoxVMInformationDlg::searchDefaultButton()
|
---|
224 | {
|
---|
225 | /* this mechanism is used for searching the default dialog button
|
---|
226 | * and similar the same mechanism in Qt::QDialog inner source */
|
---|
227 | QPushButton *button = 0;
|
---|
228 | QObjectList *list = queryList ("QPushButton");
|
---|
229 | QObjectListIt it (*list);
|
---|
230 | while ((button = (QPushButton*)it.current()) && !button->isDefault())
|
---|
231 | ++ it;
|
---|
232 | return button;
|
---|
233 | }
|
---|
234 |
|
---|
235 |
|
---|
236 | bool VBoxVMInformationDlg::eventFilter (QObject *aObject, QEvent *aEvent)
|
---|
237 | {
|
---|
238 | switch (aEvent->type())
|
---|
239 | {
|
---|
240 | /* auto-default button focus-in processor used to move the "default"
|
---|
241 | * button property into the currently focused button */
|
---|
242 | case QEvent::FocusIn:
|
---|
243 | {
|
---|
244 | if (aObject->inherits ("QPushButton") &&
|
---|
245 | aObject->parent() == centralWidget())
|
---|
246 | {
|
---|
247 | ((QPushButton*)aObject)->setDefault (aObject != mDefaultButton);
|
---|
248 | if (mDefaultButton)
|
---|
249 | mDefaultButton->setDefault (aObject == mDefaultButton);
|
---|
250 | }
|
---|
251 | break;
|
---|
252 | }
|
---|
253 | /* auto-default button focus-out processor used to remove the "default"
|
---|
254 | * button property from the previously focused button */
|
---|
255 | case QEvent::FocusOut:
|
---|
256 | {
|
---|
257 | if (aObject->inherits ("QPushButton") &&
|
---|
258 | aObject->parent() == centralWidget())
|
---|
259 | {
|
---|
260 | if (mDefaultButton)
|
---|
261 | mDefaultButton->setDefault (aObject != mDefaultButton);
|
---|
262 | ((QPushButton*)aObject)->setDefault (aObject == mDefaultButton);
|
---|
263 | }
|
---|
264 | break;
|
---|
265 | }
|
---|
266 | default:
|
---|
267 | break;
|
---|
268 | }
|
---|
269 | return QMainWindow::eventFilter (aObject, aEvent);
|
---|
270 | }
|
---|
271 |
|
---|
272 |
|
---|
273 | bool VBoxVMInformationDlg::event (QEvent *aEvent)
|
---|
274 | {
|
---|
275 | bool result = QMainWindow::event (aEvent);
|
---|
276 | switch (aEvent->type())
|
---|
277 | {
|
---|
278 | case QEvent::LanguageChange:
|
---|
279 | {
|
---|
280 | languageChangeImp();
|
---|
281 | break;
|
---|
282 | }
|
---|
283 | case QEvent::WindowStateChange:
|
---|
284 | {
|
---|
285 | if (mIsPolished)
|
---|
286 | mMax = isMaximized();
|
---|
287 | else if (mMax == isMaximized())
|
---|
288 | mIsPolished = true;
|
---|
289 | break;
|
---|
290 | }
|
---|
291 | default:
|
---|
292 | break;
|
---|
293 | }
|
---|
294 | return result;
|
---|
295 | }
|
---|
296 |
|
---|
297 |
|
---|
298 | void VBoxVMInformationDlg::keyPressEvent (QKeyEvent *aEvent)
|
---|
299 | {
|
---|
300 | if (aEvent->state() == 0 ||
|
---|
301 | (aEvent->state() & Keypad && aEvent->key() == Key_Enter))
|
---|
302 | {
|
---|
303 | switch (aEvent->key())
|
---|
304 | {
|
---|
305 | /* processing the return keypress for the auto-default button */
|
---|
306 | case Key_Enter:
|
---|
307 | case Key_Return:
|
---|
308 | {
|
---|
309 | QPushButton *currentDefault = searchDefaultButton();
|
---|
310 | if (currentDefault)
|
---|
311 | currentDefault->animateClick();
|
---|
312 | break;
|
---|
313 | }
|
---|
314 | /* processing the escape keypress as the close dialog action */
|
---|
315 | case Key_Escape:
|
---|
316 | {
|
---|
317 | close();
|
---|
318 | break;
|
---|
319 | }
|
---|
320 | }
|
---|
321 | }
|
---|
322 | else
|
---|
323 | aEvent->ignore();
|
---|
324 | }
|
---|
325 |
|
---|
326 |
|
---|
327 | void VBoxVMInformationDlg::showEvent (QShowEvent *aEvent)
|
---|
328 | {
|
---|
329 | QMainWindow::showEvent (aEvent);
|
---|
330 |
|
---|
331 | /* one may think that QWidget::polish() is the right place to do things
|
---|
332 | * below, but apparently, by the time when QWidget::polish() is called,
|
---|
333 | * the widget style & layout are not fully done, at least the minimum
|
---|
334 | * size hint is not properly calculated. Since this is sometimes necessary,
|
---|
335 | * we provide our own "polish" implementation. */
|
---|
336 |
|
---|
337 | if (mIsPolished)
|
---|
338 | return;
|
---|
339 |
|
---|
340 | /* load window size and state */
|
---|
341 | resize (mWidth, mHeight);
|
---|
342 | if (mMax)
|
---|
343 | QTimer::singleShot (0, this, SLOT (showMaximized()));
|
---|
344 | else
|
---|
345 | mIsPolished = true;
|
---|
346 |
|
---|
347 | VBoxGlobal::centerWidget (this, parentWidget());
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | void VBoxVMInformationDlg::resizeEvent (QResizeEvent*)
|
---|
352 | {
|
---|
353 | /* adjust the size-grip location for the current resize event */
|
---|
354 | mSizeGrip->move (centralWidget()->rect().bottomRight() -
|
---|
355 | QPoint (mSizeGrip->rect().width() - 1,
|
---|
356 | mSizeGrip->rect().height() - 1));
|
---|
357 |
|
---|
358 | /* store dialog size for this vm */
|
---|
359 | if (mIsPolished && !isMaximized())
|
---|
360 | {
|
---|
361 | mWidth = width();
|
---|
362 | mHeight = height();
|
---|
363 | }
|
---|
364 | }
|
---|
365 |
|
---|
366 |
|
---|
367 | void VBoxVMInformationDlg::updateDetails()
|
---|
368 | {
|
---|
369 | /* details page update */
|
---|
370 | mDetailsText->setText (
|
---|
371 | vboxGlobal().detailsReport (mSession.GetMachine(), false /* isNewVM */,
|
---|
372 | false /* withLinks */, false /* refresh */));
|
---|
373 | }
|
---|
374 |
|
---|
375 |
|
---|
376 | void VBoxVMInformationDlg::onPageChanged (QWidget *aPage)
|
---|
377 | {
|
---|
378 | /* focusing the browser on shown page */
|
---|
379 | aPage->setFocus();
|
---|
380 | }
|
---|
381 |
|
---|
382 |
|
---|
383 | void VBoxVMInformationDlg::processStatistics()
|
---|
384 | {
|
---|
385 | CMachineDebugger dbg = mSession.GetConsole().GetDebugger();
|
---|
386 | QString info;
|
---|
387 |
|
---|
388 | /* Look for all statistics for filtering purposes. */
|
---|
389 | // dbg.GetStats ("*", false, info);
|
---|
390 | // mDefStatText->setText (info);
|
---|
391 |
|
---|
392 | /* Process selected statistics: */
|
---|
393 | for (DataMapType::const_iterator it = mNamesMap.begin();
|
---|
394 | it != mNamesMap.end(); ++ it)
|
---|
395 | {
|
---|
396 | dbg.GetStats (it.key(), true, info);
|
---|
397 | mValuesMap [it.key()] = parseStatistics (info);
|
---|
398 | }
|
---|
399 |
|
---|
400 | /* Statistics page update. */
|
---|
401 | refreshStatistics();
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | QString VBoxVMInformationDlg::parseStatistics (const QString &aText)
|
---|
406 | {
|
---|
407 | /* Filters the statistic counters body. */
|
---|
408 | QRegExp query ("^.+<Statistics>\n(.+)\n</Statistics>.*$");
|
---|
409 | if (query.search (aText) == -1)
|
---|
410 | return QString::null;
|
---|
411 |
|
---|
412 | QStringList wholeList = QStringList::split ("\n", query.cap (1));
|
---|
413 |
|
---|
414 | ULONG64 summa = 0;
|
---|
415 | for (QStringList::Iterator lineIt = wholeList.begin();
|
---|
416 | lineIt != wholeList.end(); ++ lineIt)
|
---|
417 | {
|
---|
418 | QString text = *lineIt;
|
---|
419 | text.remove (1, 1);
|
---|
420 | text.remove (text.length() - 2, 2);
|
---|
421 |
|
---|
422 | /* Parse incoming counter and fill the counter-element values. */
|
---|
423 | CounterElementType counter;
|
---|
424 | counter.type = text.section (" ", 0, 0);
|
---|
425 | text = text.section (" ", 1);
|
---|
426 | QStringList list = QStringList::split ("\" ", text);
|
---|
427 | for (QStringList::Iterator it = list.begin(); it != list.end(); ++ it)
|
---|
428 | {
|
---|
429 | QString pair = *it;
|
---|
430 | QRegExp regExp ("^(.+)=\"([^\"]*)\"?$");
|
---|
431 | regExp.search (pair);
|
---|
432 | counter.list.insert (regExp.cap (1), regExp.cap (2));
|
---|
433 | }
|
---|
434 |
|
---|
435 | /* Fill the output with the necessary counter's value.
|
---|
436 | * Currently we are using "c" field of simple counter only. */
|
---|
437 | QString result = counter.list.contains ("c") ? counter.list ["c"] : "0";
|
---|
438 | summa += result.toULongLong();
|
---|
439 | }
|
---|
440 |
|
---|
441 | return QString::number (summa);
|
---|
442 | }
|
---|
443 |
|
---|
444 |
|
---|
445 | void VBoxVMInformationDlg::refreshStatistics()
|
---|
446 | {
|
---|
447 | if (mSession.isNull())
|
---|
448 | return;
|
---|
449 |
|
---|
450 | QString table = "<p><table border=0 cellspacing=0 cellpadding=0 width=100%>%1</table></p>";
|
---|
451 | QString hdrRow = "<tr><td align=left><img src='%1'></td><td colspan=3><b>%2</b></td></tr>";
|
---|
452 | QString bdyRow = "<tr><td></td><td><nobr>%1</nobr></td><td colspan=2><nobr>%2</nobr></td></tr>";
|
---|
453 | QString paragraph = "<tr><td colspan=4></td></tr>";
|
---|
454 | QString interline = "<tr><td colspan=4><font size=1> </font></td></tr>";
|
---|
455 | QString result;
|
---|
456 |
|
---|
457 | /* Screen & VT-X Runtime Parameters */
|
---|
458 | {
|
---|
459 | CConsole console = mSession.GetConsole();
|
---|
460 | ULONG bpp = console.GetDisplay().GetBitsPerPixel();
|
---|
461 | QString resolution = QString ("%1x%2")
|
---|
462 | .arg (console.GetDisplay().GetWidth())
|
---|
463 | .arg (console.GetDisplay().GetHeight());
|
---|
464 | if (bpp)
|
---|
465 | resolution += QString ("x%1").arg (bpp);
|
---|
466 | QString virt = console.GetDebugger().GetHWVirtExEnabled() ?
|
---|
467 | tr ("Enabled") : tr ("Disabled");
|
---|
468 |
|
---|
469 | result += hdrRow.arg ("state_running_16px.png").arg (tr ("Runtime Attributes"));
|
---|
470 | result += bdyRow.arg (tr ("Screen Resolution")).arg (resolution) +
|
---|
471 | bdyRow.arg (tr ("Hardware Virtualization")).arg (virt);
|
---|
472 | result += paragraph;
|
---|
473 | }
|
---|
474 |
|
---|
475 | /* Hard Disk Statistics. */
|
---|
476 | result += hdrRow.arg ("hd_16px.png").arg (tr ("IDE Hard Disk Statistics"));
|
---|
477 | result += formatHardDisk (tr ("Primary Master"), KDiskControllerType_IDE0, 0, 0, 1);
|
---|
478 | result += interline;
|
---|
479 | result += formatHardDisk (tr ("Primary Slave"), KDiskControllerType_IDE0, 1, 4, 5);
|
---|
480 | result += interline;
|
---|
481 | result += formatHardDisk (tr ("Secondary Slave"), KDiskControllerType_IDE1, 1, 12, 13);
|
---|
482 | result += paragraph;
|
---|
483 |
|
---|
484 | /* CD/DVD-ROM Statistics. */
|
---|
485 | result += hdrRow.arg ("cd_16px.png").arg (tr ("CD/DVD-ROM Statistics"));
|
---|
486 | result += formatHardDisk (QString::null /* tr ("Secondary Master") */,
|
---|
487 | KDiskControllerType_IDE1, 0, 8, 9);
|
---|
488 | result += paragraph;
|
---|
489 |
|
---|
490 | /* Network Adapters Statistics. */
|
---|
491 | result += hdrRow.arg ("nw_16px.png").arg (tr ("Network Adapter Statistics"));
|
---|
492 | result += formatAdapter (tr ("Adapter 1"), 0, 16, 17);
|
---|
493 | result += interline;
|
---|
494 | result += formatAdapter (tr ("Adapter 2"), 1, 18, 19);
|
---|
495 | result += interline;
|
---|
496 | result += formatAdapter (tr ("Adapter 3"), 2, 20, 21);
|
---|
497 | result += interline;
|
---|
498 | result += formatAdapter (tr ("Adapter 4"), 3, 22, 23);
|
---|
499 |
|
---|
500 | /* Show full composed page. */
|
---|
501 | mStatisticText->setText (table.arg (result));
|
---|
502 | }
|
---|
503 |
|
---|
504 |
|
---|
505 | QString VBoxVMInformationDlg::formatHardDisk (const QString &aName,
|
---|
506 | KDiskControllerType aType,
|
---|
507 | LONG aSlot, int aStart, int aFinish)
|
---|
508 | {
|
---|
509 | if (mSession.isNull())
|
---|
510 | return QString::null;
|
---|
511 |
|
---|
512 | QString header = "<tr><td></td><td colspan=3><nobr><u>%1</u></nobr></td></tr>";
|
---|
513 | CMachine machine = mSession.GetMachine();
|
---|
514 |
|
---|
515 | QString result = aName.isNull() ? QString::null : header.arg (aName);
|
---|
516 | CHardDisk hd = machine.GetHardDisk (aType, aSlot);
|
---|
517 | if (!hd.isNull() || (aType == KDiskControllerType_IDE1 && aSlot == 0))
|
---|
518 | {
|
---|
519 | result += composeArticle (QString::null, aStart, aFinish);
|
---|
520 | result += composeArticle ("B", aStart + 2, aFinish + 2);
|
---|
521 | }
|
---|
522 | else
|
---|
523 | result += composeArticle (tr ("Not attached"), -1, -1);
|
---|
524 | return result;
|
---|
525 | }
|
---|
526 |
|
---|
527 | QString VBoxVMInformationDlg::formatAdapter (const QString &aName,
|
---|
528 | ULONG aSlot,
|
---|
529 | int aStart, int aFinish)
|
---|
530 |
|
---|
531 | {
|
---|
532 | if (mSession.isNull())
|
---|
533 | return QString::null;
|
---|
534 |
|
---|
535 | QString header = "<tr><td></td><td colspan=3><nobr><u>%1</u></nobr></td></tr>";
|
---|
536 | CMachine machine = mSession.GetMachine();
|
---|
537 |
|
---|
538 | QString result = header.arg (aName);
|
---|
539 | CNetworkAdapter na = machine.GetNetworkAdapter (aSlot);
|
---|
540 | result += na.GetEnabled() ?
|
---|
541 | composeArticle ("B", aStart, aFinish) :
|
---|
542 | composeArticle (tr ("Disabled"), -1, -1);
|
---|
543 | return result;
|
---|
544 | }
|
---|
545 |
|
---|
546 |
|
---|
547 | QString VBoxVMInformationDlg::composeArticle (const QString &aUnits,
|
---|
548 | int aStart, int aFinish)
|
---|
549 | {
|
---|
550 | QString body = "<tr><td></td><td><nobr>%1</nobr></td><td align=right><nobr>%2%3</nobr></td><td width=100%></td></tr>";
|
---|
551 |
|
---|
552 | QString result;
|
---|
553 |
|
---|
554 | if (aStart == -1 && aFinish == -1)
|
---|
555 | result += body.arg (aUnits).arg (QString::null).arg (QString::null);
|
---|
556 | else for (int id = aStart; id <= aFinish; ++ id)
|
---|
557 | {
|
---|
558 | QString line = body;
|
---|
559 | if (mValuesMap.contains (mNamesMap.keys() [id]))
|
---|
560 | {
|
---|
561 | ULONG64 value = mValuesMap.values() [id].toULongLong();
|
---|
562 | line = line.arg (mNamesMap.values() [id])
|
---|
563 | .arg (QString ("%L1").arg (value));
|
---|
564 | line = aUnits.isNull() ?
|
---|
565 | line.arg (QString ("<img src=tpixel.png width=%1 height=1>")
|
---|
566 | .arg (QApplication::fontMetrics().width (" B"))) :
|
---|
567 | line.arg (QString (" %1").arg (aUnits));
|
---|
568 | }
|
---|
569 | result += line;
|
---|
570 | }
|
---|
571 |
|
---|
572 | return result;
|
---|
573 | }
|
---|
574 |
|
---|
575 |
|
---|
576 | /* Old code for two columns support */
|
---|
577 | #if 0
|
---|
578 | void VBoxVMInformationDlg::refreshStatistics()
|
---|
579 | {
|
---|
580 | QString table = "<p><table border=0 cellspacing=0 cellpadding=0 width=100%>%1</table></p>";
|
---|
581 | QString hdrRow = "<tr><td align=left><img src='%1'></td><td colspan=4><b>%2</b></td></tr>";
|
---|
582 | QString subRow = "<tr><td></td><td colspan=2><nobr><u>%1</u></nobr></td>"
|
---|
583 | "<td colspan=2><nobr><u>%2</u></nobr></td></tr>";
|
---|
584 | QString bdyRow = "<tr><td></td><td><nobr>%1</nobr></td><td width=50%><nobr>%2</nobr></td>"
|
---|
585 | "<td><nobr>%3</nobr></td><td width=50%><nobr>%4</nobr></td></tr>";
|
---|
586 | QString paragraph = "<tr><td colspan=5></td></tr>";
|
---|
587 | QString interline = "<tr><td colspan=5><font size=1> </font></td></tr>";
|
---|
588 | QString result;
|
---|
589 |
|
---|
590 | /* Screen & VT-X Runtime Parameters */
|
---|
591 | if (!mSession.isNull())
|
---|
592 | {
|
---|
593 | CConsole console = mSession.GetConsole();
|
---|
594 | ULONG bpp = console.GetDisplay().GetBitsPerPixel();
|
---|
595 | QString resolution = QString ("%1x%2")
|
---|
596 | .arg (console.GetDisplay().GetWidth())
|
---|
597 | .arg (console.GetDisplay().GetHeight());
|
---|
598 | if (bpp)
|
---|
599 | resolution += QString ("x%1").arg (bpp);
|
---|
600 | QString virt = console.GetDebugger().GetHWVirtExEnabled() ?
|
---|
601 | tr ("Enabled") : tr ("Disabled");
|
---|
602 |
|
---|
603 | result += hdrRow.arg ("state_running_16px.png").arg (tr ("Runtime Attributes"));
|
---|
604 | result += bdyRow.arg (tr ("Screen Resolution")) .arg (resolution)
|
---|
605 | .arg (tr ("Hardware Virtualization")).arg (virt);
|
---|
606 | result += paragraph;
|
---|
607 | }
|
---|
608 |
|
---|
609 | /* Hard Disk Statistics. */
|
---|
610 | result += hdrRow.arg ("hd_16px.png").arg (tr ("Hard Disks Statistics"));
|
---|
611 |
|
---|
612 | result += subRow.arg (tr ("Primary Master")).arg (tr ("Primary Slave"));
|
---|
613 | result += composeArticle (QString::null, 0, 1, 4, 5);
|
---|
614 | result += composeArticle ("B", 2, 3, 6, 7);
|
---|
615 | result += interline;
|
---|
616 |
|
---|
617 | result += subRow.arg (tr ("Secondary Master")).arg (tr ("Secondary Slave"));
|
---|
618 | result += composeArticle (QString::null, 8, 9, 12, 13);
|
---|
619 | result += composeArticle ("B", 10, 11, 14, 15);
|
---|
620 | result += paragraph;
|
---|
621 |
|
---|
622 | /* Network Adapters Statistics. Counters are currently missed. */
|
---|
623 | result += hdrRow.arg ("nw_16px.png").arg (tr ("Network Adapter Statistics"));
|
---|
624 | result += subRow.arg (tr ("Adapter 1")).arg (tr ("Adapter 2"));
|
---|
625 | result += composeArticle ("B", 16, 17, 18, 19);
|
---|
626 |
|
---|
627 | /* Show full composed page. */
|
---|
628 | mStatisticText->setText (table.arg (result));
|
---|
629 | }
|
---|
630 |
|
---|
631 |
|
---|
632 | QString VBoxVMInformationDlg::composeArticle (const QString &aUnits,
|
---|
633 | int aStart1, int aFinish1,
|
---|
634 | int aStart2, int aFinish2)
|
---|
635 | {
|
---|
636 | QString bdyRow = "<tr><td></td><td><nobr>%1</nobr></td><td width=50%><nobr>%2</nobr></td>"
|
---|
637 | "<td><nobr>%3</nobr></td><td width=50%><nobr>%4</nobr></td></tr>";
|
---|
638 |
|
---|
639 | QString result;
|
---|
640 |
|
---|
641 | int id1 = aStart1, id2 = aStart2;
|
---|
642 | while (id1 <= aFinish1 || id2 <= aFinish2)
|
---|
643 | {
|
---|
644 | QString line = bdyRow;
|
---|
645 | /* Processing first column */
|
---|
646 | if (id1 > aFinish1)
|
---|
647 | {
|
---|
648 | line = line.arg (QString::null).arg (QString::null)
|
---|
649 | .arg (QString::null).arg (QString::null);
|
---|
650 | }
|
---|
651 | else if (mValuesMap.contains (mNamesMap.keys() [id1]))
|
---|
652 | {
|
---|
653 | line = line.arg (mNamesMap.values() [id1]);
|
---|
654 | ULONG64 value = mValuesMap.values() [id1].toULongLong();
|
---|
655 | line = aUnits.isNull() ?
|
---|
656 | line.arg (QString ("%L1").arg (value)) :
|
---|
657 | line.arg (QString ("%L1 %2").arg (value).arg (aUnits));
|
---|
658 | }
|
---|
659 | /* Processing second column */
|
---|
660 | if (id2 > aFinish2)
|
---|
661 | {
|
---|
662 | line = line.arg (QString::null).arg (QString::null)
|
---|
663 | .arg (QString::null).arg (QString::null);
|
---|
664 | }
|
---|
665 | else if (mValuesMap.contains (mNamesMap.keys() [id2]))
|
---|
666 | {
|
---|
667 | line = line.arg (mNamesMap.values() [id2]);
|
---|
668 | ULONG64 value = mValuesMap.values() [id2].toULongLong();
|
---|
669 | line = aUnits.isNull() ?
|
---|
670 | line.arg (QString ("%L1").arg (value)) :
|
---|
671 | line.arg (QString ("%L1 %2").arg (value).arg (aUnits));
|
---|
672 | }
|
---|
673 | result += line;
|
---|
674 | ++ id1; ++ id2;
|
---|
675 | }
|
---|
676 |
|
---|
677 | return result;
|
---|
678 | }
|
---|
679 | #endif
|
---|
680 |
|
---|