VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/usb/UIUSBTools.cpp

Last change on this file was 105165, checked in by vboxsync, 3 months ago

FE/Qt: OSE fixing part 2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.6 KB
Line 
1/* $Id: UIUSBTools.cpp 105165 2024-07-05 15:23:48Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIUSBTools namespace implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QApplication>
30#include <QVector>
31
32/* GUI includes: */
33#include "UIConverter.h"
34#include "UIUSBTools.h"
35
36/* COM includes: */
37#include "CHostUSBDevice.h"
38#include "CHostVideoInputDevice.h"
39#include "CUSBDevice.h"
40#include "CUSBDeviceFilter.h"
41
42/* VirtualBox interface declarations: */
43#include <VBox/com/VirtualBox.h>
44
45
46QString UIUSBTools::usbDetails(const CUSBDevice &comDevice)
47{
48 QString strDetails;
49 if (comDevice.isNull())
50 strDetails = QApplication::translate("UIUSBTools", "Unknown device", "USB device details");
51 else
52 {
53 QVector<QString> devInfoVector = comDevice.GetDeviceInfo();
54 QString strManufacturer;
55 QString strProduct;
56
57 if (devInfoVector.size() >= 1)
58 strManufacturer = devInfoVector[0].trimmed();
59 if (devInfoVector.size() >= 2)
60 strProduct = devInfoVector[1].trimmed();
61
62 if (strManufacturer.isEmpty() && strProduct.isEmpty())
63 {
64 strDetails =
65 QApplication::translate("UIUSBTools", "Unknown device %1:%2", "USB device details")
66 .arg(QString::number(comDevice.GetVendorId(), 16).toUpper().rightJustified(4, '0'))
67 .arg(QString::number(comDevice.GetProductId(), 16).toUpper().rightJustified(4, '0'));
68 }
69 else
70 {
71 if (strProduct.toUpper().startsWith(strManufacturer.toUpper()))
72 strDetails = strProduct;
73 else
74 strDetails = strManufacturer + " " + strProduct;
75 }
76 ushort iRev = comDevice.GetRevision();
77 if (iRev != 0)
78 {
79 strDetails += " [";
80 strDetails += QString::number(iRev, 16).toUpper().rightJustified(4, '0');
81 strDetails += "]";
82 }
83 }
84
85 return strDetails.trimmed();
86}
87
88QString UIUSBTools::usbToolTip(const CUSBDevice &comDevice)
89{
90 QString strTip =
91 QApplication::translate("UIUSBTools", "<nobr>Vendor ID: %1</nobr><br>"
92 "<nobr>Product ID: %2</nobr><br>"
93 "<nobr>Revision: %3</nobr>", "USB device tooltip")
94 .arg(QString::number(comDevice.GetVendorId(), 16).toUpper().rightJustified(4, '0'))
95 .arg(QString::number(comDevice.GetProductId(), 16).toUpper().rightJustified(4, '0'))
96 .arg(QString::number(comDevice.GetRevision(), 16).toUpper().rightJustified(4, '0'));
97
98 const QString strSerial = comDevice.GetSerialNumber();
99 if (!strSerial.isEmpty())
100 strTip += QApplication::translate("UIUSBTools",
101 "<br><nobr>Serial No. %1</nobr>",
102 "USB device tooltip").arg(strSerial);
103
104 /* Add the state field if it's a host USB device: */
105 CHostUSBDevice hostDev(comDevice);
106 if (!hostDev.isNull())
107 {
108 strTip += QString(QApplication::translate("UIUSBTools",
109 "<br><nobr>State: %1</nobr>",
110 "USB device tooltip"))
111 .arg(gpConverter->toString(hostDev.GetState()));
112 }
113
114 return strTip;
115}
116
117QString UIUSBTools::usbToolTip(const CUSBDeviceFilter &comFilter)
118{
119 QString strTip;
120
121 const QString strVendorId = comFilter.GetVendorId();
122 if (!strVendorId.isEmpty())
123 strTip += QApplication::translate("UIUSBTools",
124 "<nobr>Vendor ID: %1</nobr>",
125 "USB filter tooltip").arg(strVendorId);
126
127 const QString strProductId = comFilter.GetProductId();
128 if (!strProductId.isEmpty())
129 strTip += strTip.isEmpty() ? "" : "<br/>" + QApplication::translate("UIUSBTools",
130 "<nobr>Product ID: %2</nobr>",
131 "USB filter tooltip").arg(strProductId);
132
133 const QString strRevision = comFilter.GetRevision();
134 if (!strRevision.isEmpty())
135 strTip += strTip.isEmpty() ? "" : "<br/>" + QApplication::translate("UIUSBTools",
136 "<nobr>Revision: %3</nobr>",
137 "USB filter tooltip").arg(strRevision);
138
139 const QString strProduct = comFilter.GetProduct();
140 if (!strProduct.isEmpty())
141 strTip += strTip.isEmpty() ? "" : "<br/>" + QApplication::translate("UIUSBTools",
142 "<nobr>Product: %4</nobr>",
143 "USB filter tooltip").arg(strProduct);
144
145 const QString strManufacturer = comFilter.GetManufacturer();
146 if (!strManufacturer.isEmpty())
147 strTip += strTip.isEmpty() ? "" : "<br/>" + QApplication::translate("UIUSBTools",
148 "<nobr>Manufacturer: %5</nobr>",
149 "USB filter tooltip").arg(strManufacturer);
150
151 const QString strSerial = comFilter.GetSerialNumber();
152 if (!strSerial.isEmpty())
153 strTip += strTip.isEmpty() ? "" : "<br/>" + QApplication::translate("UIUSBTools",
154 "<nobr>Serial No.: %1</nobr>",
155 "USB filter tooltip").arg(strSerial);
156
157 const QString strPort = comFilter.GetPort();
158 if (!strPort.isEmpty())
159 strTip += strTip.isEmpty() ? "" : "<br/>" + QApplication::translate("UIUSBTools",
160 "<nobr>Port: %1</nobr>",
161 "USB filter tooltip").arg(strPort);
162
163 /* Add the state field if it's a host USB device: */
164 CHostUSBDevice hostDev(comFilter);
165 if (!hostDev.isNull())
166 {
167 strTip += strTip.isEmpty() ? "":"<br/>" + QApplication::translate("UIUSBTools",
168 "<nobr>State: %1</nobr>",
169 "USB filter tooltip")
170 .arg(gpConverter->toString(hostDev.GetState()));
171 }
172
173 return strTip;
174}
175
176QString UIUSBTools::usbToolTip(const CHostVideoInputDevice &comWebcam)
177{
178 QStringList records;
179
180 const QString strName = comWebcam.GetName();
181 if (!strName.isEmpty())
182 records << strName;
183
184 const QString strPath = comWebcam.GetPath();
185 if (!strPath.isEmpty())
186 records << strPath;
187
188 return records.join("<br>");
189}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette