UIMachineSettingsUSB.cpp revision d34409ad02ea0d28e08a6c4b089a412fdb3b4c9c
/* $Id$ */
/** @file
* VBox Qt GUI - UIMachineSettingsUSB class implementation.
*/
/*
* Copyright (C) 2006-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* 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.
*/
/* Qt includes: */
#include <QHeaderView>
#include <QHelpEvent>
#include <QToolTip>
/* GUI includes: */
#include "QIWidgetValidator.h"
#include "UIIconPool.h"
#include "VBoxGlobal.h"
#include "UIMessageCenter.h"
#include "UIToolBar.h"
#include "UIMachineSettingsUSB.h"
#include "UIMachineSettingsUSBFilterDetails.h"
#include "UIConverter.h"
/* COM includes: */
#include "CConsole.h"
#include "CUSBController.h"
#include "CUSBDeviceFilters.h"
#include "CUSBDevice.h"
#include "CUSBDeviceFilter.h"
#include "CHostUSBDevice.h"
#include "CHostUSBDeviceFilter.h"
#include "CExtPackManager.h"
#include "CExtPack.h"
/**
* USB popup menu class.
* This class provides the list of USB devices attached to the host.
*/
class VBoxUSBMenu : public QMenu
{
public:
/* Constructor: */
{
}
/* Returns USB device related to passed action: */
{
return m_usbDeviceMap[pAction];
}
/* Console setter: */
{
}
private slots:
/* Prepare menu appearance: */
void processAboutToShow()
{
clear();
if (fIsUSBEmpty)
{
pAction->setEnabled(false);
}
else
{
{
pAction->setCheckable(true);
/* Check if created item was already attached to this session: */
{
}
}
}
}
private:
/* Event handler: */
{
/* We provide dynamic tooltips for the usb devices: */
{
if (pAction)
{
{
return true;
}
}
}
/* Call to base-class: */
}
};
: m_pToolBar(0)
, mMupAction(0), mMdnAction(0)
, mUSBDevicesMenu(0)
{
/* Apply UI decorations */
/* Prepare actions */
":/usb_new_disabled_16px.png"));
":/usb_add_disabled_16px.png"));
":/usb_filter_edit_disabled_16px.png"));
":/usb_remove_disabled_16px.png"));
":/usb_moveup_disabled_16px.png"));
":/usb_movedown_disabled_16px.png"));
/* Prepare tool-bar: */
/* Setup connections */
this, SLOT (usbAdapterToggled (bool)));
this, SLOT (edtClicked()));
mUSBDevicesMenu = new VBoxUSBMenu (this);
this, SLOT (newClicked()));
this, SLOT (addClicked()));
this, SLOT (edtClicked()));
this, SLOT (delClicked()));
this, SLOT (mupClicked()));
this, SLOT (mdnClicked()));
/* Setup dialog */
/* Prepare validation: */
/* Applying language settings */
#ifndef VBOX_WITH_EHCI
#endif /* VBOX_WITH_EHCI */
}
bool UIMachineSettingsUSB::isUSBEnabled() const
{
}
/* Load data to cache from corresponding external object(s),
* this task COULD be performed in other than GUI thread: */
{
/* Fetch data to properties & settings or machine: */
/* Clear cache initially: */
/* Prepare USB data: */
/* Gather USB values: */
usbData.m_USBControllerType = m_machine.GetUSBControllerCountByType(KUSBControllerType_XHCI) > 0 ? KUSBControllerType_XHCI :
/* Check if controller is valid: */
{
/* For each USB filter: */
{
/* Prepare USB filter data: */
/* Check if filter is valid: */
{
}
/* Cache USB filter data: */
}
}
/* Cache USB data: */
/* Upload properties & settings or machine to data: */
}
/* Load data to corresponding widgets from cache,
* this task SHOULD be performed in GUI thread only: */
void UIMachineSettingsUSB::getFromCache()
{
/* Clear list initially: */
mTwFilters->clear();
/* Get USB data from cache: */
/* Load USB data to page: */
switch (usbData.m_USBControllerType)
{
default:
}
/* For each USB filter => load it to the page: */
/* Choose first filter as current: */
/* Update page: */
/* Polish page finally: */
polishPage();
/* Revalidate: */
revalidate();
}
/* Save data from corresponding widgets to cache,
* this task SHOULD be performed in GUI thread only: */
void UIMachineSettingsUSB::putToCache()
{
/* Prepare USB data: */
/* Is USB controller enabled? */
/* Of which type? */
if (!usbData.m_fUSBEnabled)
else
{
}
/* Update USB cache: */
/* For each USB filter => recache USB filter data: */
}
/* Save data from cache to corresponding external object(s),
* this task COULD be performed in other than GUI thread: */
{
/* Fetch data to properties & settings or machine: */
/* Check if USB data really changed: */
if (m_cache.wasChanged())
{
/* Check if controller is valid: */
{
/* Get USB data from cache: */
/* Store USB data: */
if (isMachineOffline())
{
/* Removing USB controllers: */
if (!usbData.m_fUSBEnabled)
{
if (cXhciCtls)
if (cEhciCtls)
if (cOhciCtls)
}
else
{
switch (usbData.m_USBControllerType)
{
case KUSBControllerType_OHCI:
{
if (cEhciCtls)
if (cXhciCtls)
if (!cOhciCtls)
break;
}
case KUSBControllerType_EHCI:
{
if (cXhciCtls)
if (!cOhciCtls)
if (!cEhciCtls)
break;
}
case KUSBControllerType_XHCI:
{
if (cEhciCtls)
if (cOhciCtls)
if (!cXhciCtls)
break;
}
default:
break;
}
}
}
/* Store USB filters data: */
if (isMachineInValidMode())
{
/* For each USB filter data set: */
int iOperationPosition = 0;
{
/* Check if USB filter data really changed: */
if (usbFilterCache.wasChanged())
{
/* If filter was removed or updated: */
{
if (usbFilterCache.wasRemoved())
}
/* If filter was created or updated: */
{
/* Get USB filter data from cache: */
/* Store USB filter data: */
}
}
/* Advance operation position: */
}
}
}
}
/* Upload properties & settings or machine to data: */
}
{
/* Pass by default: */
bool fPass = true;
#ifdef VBOX_WITH_EXTPACK
/* USB 2.0 Extension Pack presence test: */
{
/* Prepare message: */
"However, this requires the <b>%1</b> to be installed. "
"Please install the Extension Pack from the VirtualBox download site "
"or disable USB 2.0 to be able to start the machine.")
/* Serialize message: */
}
#endif /* VBOX_WITH_EXTPACK */
/* Return result: */
return fPass;
}
{
}
void UIMachineSettingsUSB::retranslateUi()
{
/* Translate uic generated strings */
"initially set to empty strings. Note "
"that such a filter will match any "
"attached USB device."));
"set to the values of the selected USB "
"device attached to the host PC."));
}
{
if (fEnabled)
{
/* If there is no chosen item but there is something to choose => choose it: */
}
/* Update current item: */
}
{
/* Get selected items: */
/* Deselect all selected items first: */
/* If tree-widget is NOT enabled => we should NOT select anything: */
if (!mTwFilters->isEnabled())
return;
/* Select item if requested: */
if (aItem)
aItem->setSelected(true);
/* Update corresponding action states: */
}
void UIMachineSettingsUSB::newClicked()
{
/* Search for the max available filter index: */
int iMaxFilterIndex = 0;
while (*iterator)
{
if (pos != -1)
++iterator;
}
/* Prepare new USB filter data: */
usbFilterData.m_fActive = true;
usbFilterData.m_fHostUSBDevice = false;
/* Add new USB filter data: */
/* Revalidate: */
revalidate();
}
void UIMachineSettingsUSB::addClicked()
{
}
{
/* Get USB device: */
return;
/* Prepare new USB filter data: */
usbFilterData.m_fActive = true;
usbFilterData.m_fHostUSBDevice = false;
/* The port property depends on the host computer rather than on the USB
* device itself; for this reason only a few people will want to use it
* in the filter since the same device plugged into a different socket
* will not match the filter in this case. */
#if 0
#endif
/* Add new USB filter data: */
/* Revalidate: */
revalidate();
}
void UIMachineSettingsUSB::edtClicked()
{
/* Get current USB filter item: */
/* Configure USB filter details dialog: */
else
/* Run USB filter details dialog: */
{
usbFilterData.m_strName = dlgFilterDetails.mLeName->text().isEmpty() ? QString::null : dlgFilterDetails.mLeName->text();
usbFilterData.m_strVendorId = dlgFilterDetails.mLeVendorID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeVendorID->text();
usbFilterData.m_strProductId = dlgFilterDetails.mLeProductID->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProductID->text();
usbFilterData.m_strRevision = dlgFilterDetails.mLeRevision->text().isEmpty() ? QString::null : dlgFilterDetails.mLeRevision->text();
usbFilterData.m_strManufacturer = dlgFilterDetails.mLeManufacturer->text().isEmpty() ? QString::null : dlgFilterDetails.mLeManufacturer->text();
usbFilterData.m_strProduct = dlgFilterDetails.mLeProduct->text().isEmpty() ? QString::null : dlgFilterDetails.mLeProduct->text();
usbFilterData.m_strSerialNumber = dlgFilterDetails.mLeSerialNo->text().isEmpty() ? QString::null : dlgFilterDetails.mLeSerialNo->text();
usbFilterData.m_strPort = dlgFilterDetails.mLePort->text().isEmpty() ? QString::null : dlgFilterDetails.mLePort->text();
{
default: AssertMsgFailed(("Invalid combo box index"));
}
}
}
void UIMachineSettingsUSB::delClicked()
{
/* Get current USB filter item: */
/* Delete corresponding items: */
delete pItem;
/* Update current item: */
/* Revalidate: */
revalidate();
}
void UIMachineSettingsUSB::mupClicked()
{
}
void UIMachineSettingsUSB::mdnClicked()
{
}
{
if (mTwFilters->isEnabled())
{
menu.addSeparator();
menu.addSeparator();
menu.addSeparator();
}
}
{
/* Check changed USB filter item: */
/* Delete corresponding items: */
}
{
/* Prepare validation: */
}
void UIMachineSettingsUSB::addUSBFilter(const UIDataSettingsMachineUSBFilter &usbFilterData, bool fIsNew)
{
/* Append internal list with data: */
/* Append tree-widget with item: */
/* Select this item if its new: */
if (fIsNew)
}
/* static */
{
/* Prepare tool-tip: */
if (!strVendorId.isEmpty())
if (!strProductId.isEmpty())
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product ID: %2</nobr>", "USB filter tooltip").arg(strProductId);
if (!strRevision.isEmpty())
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Revision: %3</nobr>", "USB filter tooltip").arg(strRevision);
if (!strProduct.isEmpty())
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Product: %4</nobr>", "USB filter tooltip").arg(strProduct);
if (!strManufacturer.isEmpty())
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip").arg(strManufacturer);
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Serial No.: %1</nobr>", "USB filter tooltip").arg(strSerial);
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>Port: %1</nobr>", "USB filter tooltip").arg(strPort);
/* Add the state field if it's a host USB device: */
{
strToolTip += strToolTip.isEmpty() ? "":"<br/>" + tr("<nobr>State: %1</nobr>", "USB filter tooltip")
}
return strToolTip;
}
void UIMachineSettingsUSB::polishPage()
{
}
#include "UIMachineSettingsUSB.moc"