/**
*
* VBox frontends: Qt GUI ("VirtualBox"):
* "VirtualBox Information Dialog" dialog UI include (Qt Designer)
*/
/*
* Copyright (C) 2006 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/
VBoxVMInformationDlg::InfoDlgMap VBoxVMInformationDlg::mSelfArray = InfoDlgMap();
void VBoxVMInformationDlg::createInformationDlg (const CSession &aSession,
VBoxConsoleView *aConsole)
{
CMachine machine = aSession.GetMachine();
if (mSelfArray.find (machine.GetName()) == mSelfArray.end())
{
/* creating new information dialog if there is no one existing */
mSelfArray [machine.GetName()] = new VBoxVMInformationDlg (
aConsole,
"VBoxVMInformationDlg", WType_TopLevel | WDestructiveClose);
/* read new machine data for this information dialog */
mSelfArray [machine.GetName()]->setup (aSession, aConsole);
}
VBoxVMInformationDlg *info = mSelfArray [machine.GetName()];
info->show();
info->raise();
info->setWindowState (info->windowState() & ~WindowMinimized);
info->setActiveWindow();
}
void VBoxVMInformationDlg::init()
{
/* dialog initially is not polished */
mIsPolished = false;
/* search the default button */
mDefaultButton = searchDefaultButton();
qApp->installEventFilter (this);
/* setup a dialog icon */
setIcon (QPixmap::fromMimeSource ("description_16px.png"));
/* statusbar initially disabled */
statusBar()->setHidden (true);
/* setup size grip */
mSizeGrip = new QSizeGrip (centralWidget(), "mSizeGrip");
mSizeGrip->resize (mSizeGrip->sizeHint());
mSizeGrip->stackUnder (mCloseButton);
/* logs list creation */
mInfoStack = new QTabWidget (mInfoFrame, "mInfoStack");
mInfoStack->setMargin (10);
QVBoxLayout *infoFrameLayout = new QVBoxLayout (mInfoFrame);
infoFrameLayout->addWidget (mInfoStack);
/* details view creation */
mDetailsText = new QTextBrowser();
mDetailsText->setFrameShape (QFrame::NoFrame);
mDetailsText->setPaper (backgroundBrush());
mInfoStack->addTab (mDetailsText,
VBoxGlobal::iconSet ("settings_16px.png"),
QString::null);
/* statistic view creation */
mStatisticText = new QTextBrowser();
mStatisticText->setFrameShape (QFrame::NoFrame);
mStatisticText->setPaper (backgroundBrush());
mInfoStack->addTab (mStatisticText,
VBoxGlobal::iconSet ("state_running_16px.png"),
QString::null);
/* full list of statistics counters to get total info */
// mDefStatText = new QTextBrowser();
// mDefStatText->setFrameShape (QFrame::NoFrame);
// mDefStatText->setPaper (backgroundBrush());
// mInfoStack->addTab (mDefStatText,
// VBoxGlobal::iconSet ("show_logs_16px.png"),
// QString::null);
/* show statistics page and make it focused */
connect (mInfoStack, SIGNAL (currentChanged (QWidget*)),
this, SLOT (onPageChanged (QWidget*)));
mInfoStack->showPage (mStatisticText);
}
void VBoxVMInformationDlg::destroy()
{
/* save dialog attributes for this vm */
QString dlgsize ("%1,%2,%3");
mSession.GetMachine().SetExtraData (VBoxDefs::GUI_InfoDlgState,
dlgsize.arg (mWidth).arg (mHeight).arg (isMaximized() ? "max" : "normal"));
if (!mSession.isNull() && !mSession.GetMachine().isNull())
mSelfArray.erase (mSession.GetMachine().GetName());
}
void VBoxVMInformationDlg::setup (const CSession &aSession,
VBoxConsoleView *aConsole)
{
/* store related machine pointers */
mSession = aSession;
mConsole = aConsole;
/* loading language constants */
languageChangeImp();
/* details page update */
updateDetails();
/* statistics page update */
processStatistics();
mStatTimer.start (5000);
/* setup handlers */
connect (&vboxGlobal(), SIGNAL (mediaEnumFinished (const VBoxMediaList &)),
this, SLOT (updateDetails()));
connect (mConsole, SIGNAL (mediaChanged (VBoxDefs::DiskType)),
this, SLOT (updateDetails()));
connect (mConsole, SIGNAL (sharedFoldersChanged()),
this, SLOT (updateDetails()));
connect (&mStatTimer, SIGNAL (timeout()), this, SLOT (processStatistics()));
connect (mConsole, SIGNAL (resizeHintDone()), this, SLOT (processStatistics()));
/* preload dialog attributes for this vm */
QString dlgsize = mSession.GetMachine().GetExtraData (VBoxDefs::GUI_InfoDlgState);
if (dlgsize.isNull())
{
mWidth = 400;
mHeight = 450;
mMax = false;
}
else
{
QStringList list = QStringList::split (',', dlgsize);
mWidth = list [0].toInt(), mHeight = list [1].toInt();
mMax = list [2] == "max";
}
}
void VBoxVMInformationDlg::languageChangeImp()
{
AssertReturnVoid (!mSession.isNull());
CMachine machine = mSession.GetMachine();
AssertReturnVoid (!machine.isNull());
/* Setup a dialog caption. */
setCaption (tr ("%1 - Session Information").arg (machine.GetName()));
/* Setup a tabwidget page names. */
mInfoStack->changeTab (mDetailsText, tr ("&Details"));
mInfoStack->changeTab (mStatisticText, tr ("&Runtime"));
// mInfoStack->changeTab (mDefStatText, tr ("De&fault Stat"));
/* Clear counter names initially. */
mNamesMap.clear();
/* HD statistics: */
mNamesMap ["/Devices/ATA0/Unit0/*DMA"] = tr ("DMA Transfers");
mNamesMap ["/Devices/ATA0/Unit0/*PIO"] = tr ("PIO Transfers");
mNamesMap ["/Devices/ATA0/Unit0/ReadBytes"] = tr ("Data Read");
mNamesMap ["/Devices/ATA0/Unit0/WrittenBytes"] = tr ("Data Written");
mNamesMap ["/Devices/ATA0/Unit1/*DMA"] = tr ("DMA Transfers");
mNamesMap ["/Devices/ATA0/Unit1/*PIO"] = tr ("PIO Transfers");
mNamesMap ["/Devices/ATA0/Unit1/ReadBytes"] = tr ("Data Read");
mNamesMap ["/Devices/ATA0/Unit1/WrittenBytes"] = tr ("Data Written");
mNamesMap ["/Devices/ATA1/Unit0/*DMA"] = tr ("DMA Transfers");
mNamesMap ["/Devices/ATA1/Unit0/*PIO"] = tr ("PIO Transfers");
mNamesMap ["/Devices/ATA1/Unit0/ReadBytes"] = tr ("Data Read");
mNamesMap ["/Devices/ATA1/Unit0/WrittenBytes"] = tr ("Data Written");
mNamesMap ["/Devices/ATA1/Unit1/*DMA"] = tr ("DMA Transfers");
mNamesMap ["/Devices/ATA1/Unit1/*PIO"] = tr ("PIO Transfers");
mNamesMap ["/Devices/ATA1/Unit1/ReadBytes"] = tr ("Data Read");
mNamesMap ["/Devices/ATA1/Unit1/WrittenBytes"] = tr ("Data Written");
for (int i = 0; i < 4; i++)
{
CNetworkAdapter na = machine.GetNetworkAdapter (i);
KNetworkAdapterType ty = na.GetAdapterType();
const char *name;
switch (ty)
{
case KNetworkAdapterType_I82540EM:
name = "E1k";
break;
default:
name = "PCNet";
break;
}
mNamesMap [QString("/Devices/%1%2/TransmitBytes")
.arg(name) .arg(i)] = tr ("Data Transmitted");
mNamesMap [QString("/Devices/%1%2/ReceiveBytes")
.arg(name) .arg(i)] = tr ("Data Received");
}
/* Statistics page update. */
refreshStatistics();
}
QPushButton* VBoxVMInformationDlg::searchDefaultButton()
{
/* this mechanism is used for searching the default dialog button
* and similar the same mechanism in Qt::QDialog inner source */
QPushButton *button = 0;
QObjectList *list = queryList ("QPushButton");
QObjectListIt it (*list);
while ((button = (QPushButton*)it.current()) && !button->isDefault())
++ it;
return button;
}
bool VBoxVMInformationDlg::eventFilter (QObject *aObject, QEvent *aEvent)
{
switch (aEvent->type())
{
/* auto-default button focus-in processor used to move the "default"
* button property into the currently focused button */
case QEvent::FocusIn:
{
if (aObject->inherits ("QPushButton") &&
aObject->parent() == centralWidget())
{
((QPushButton*)aObject)->setDefault (aObject != mDefaultButton);
if (mDefaultButton)
mDefaultButton->setDefault (aObject == mDefaultButton);
}
break;
}
/* auto-default button focus-out processor used to remove the "default"
* button property from the previously focused button */
case QEvent::FocusOut:
{
if (aObject->inherits ("QPushButton") &&
aObject->parent() == centralWidget())
{
if (mDefaultButton)
mDefaultButton->setDefault (aObject != mDefaultButton);
((QPushButton*)aObject)->setDefault (aObject == mDefaultButton);
}
break;
}
default:
break;
}
return QMainWindow::eventFilter (aObject, aEvent);
}
bool VBoxVMInformationDlg::event (QEvent *aEvent)
{
bool result = QMainWindow::event (aEvent);
switch (aEvent->type())
{
case QEvent::LanguageChange:
{
if (!mSession.isNull())
languageChangeImp();
break;
}
case QEvent::WindowStateChange:
{
if (mIsPolished)
mMax = isMaximized();
else if (mMax == isMaximized())
mIsPolished = true;
break;
}
default:
break;
}
return result;
}
void VBoxVMInformationDlg::keyPressEvent (QKeyEvent *aEvent)
{
if (aEvent->state() == 0 ||
(aEvent->state() & Keypad && aEvent->key() == Key_Enter))
{
switch (aEvent->key())
{
/* processing the return keypress for the auto-default button */
case Key_Enter:
case Key_Return:
{
QPushButton *currentDefault = searchDefaultButton();
if (currentDefault)
currentDefault->animateClick();
break;
}
/* processing the escape keypress as the close dialog action */
case Key_Escape:
{
close();
break;
}
}
}
else
aEvent->ignore();
}
void VBoxVMInformationDlg::showEvent (QShowEvent *aEvent)
{
QMainWindow::showEvent (aEvent);
/* one may think that QWidget::polish() is the right place to do things
* below, but apparently, by the time when QWidget::polish() is called,
* the widget style & layout are not fully done, at least the minimum
* size hint is not properly calculated. Since this is sometimes necessary,
* we provide our own "polish" implementation. */
if (mIsPolished)
return;
/* load window size and state */
resize (mWidth, mHeight);
if (mMax)
QTimer::singleShot (0, this, SLOT (showMaximized()));
else
mIsPolished = true;
VBoxGlobal::centerWidget (this, parentWidget());
}
void VBoxVMInformationDlg::resizeEvent (QResizeEvent*)
{
/* adjust the size-grip location for the current resize event */
mSizeGrip->move (centralWidget()->rect().bottomRight() -
QPoint (mSizeGrip->rect().width() - 1,
mSizeGrip->rect().height() - 1));
/* store dialog size for this vm */
if (mIsPolished && !isMaximized())
{
mWidth = width();
mHeight = height();
}
}
void VBoxVMInformationDlg::updateDetails()
{
/* details page update */
mDetailsText->setText (
vboxGlobal().detailsReport (mSession.GetMachine(), false /* isNewVM */,
false /* withLinks */, false /* refresh */));
}
void VBoxVMInformationDlg::onPageChanged (QWidget *aPage)
{
/* focusing the browser on shown page */
aPage->setFocus();
}
void VBoxVMInformationDlg::processStatistics()
{
CMachineDebugger dbg = mSession.GetConsole().GetDebugger();
QString info;
/* Look for all statistics for filtering purposes. */
// dbg.GetStats ("*", false, info);
// mDefStatText->setText (info);
/* Process selected statistics: */
for (DataMapType::const_iterator it = mNamesMap.begin();
it != mNamesMap.end(); ++ it)
{
dbg.GetStats (it.key(), true, info);
mValuesMap [it.key()] = parseStatistics (info);
}
/* Statistics page update. */
refreshStatistics();
}
QString VBoxVMInformationDlg::parseStatistics (const QString &aText)
{
/* Filters the statistic counters body. */
QRegExp query ("^.+