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