1
/* $Id: UIConverterBackendGlobal.cpp $ */
4
* VBox frontends: Qt GUI ("VirtualBox"):
5
* UIConverterBackendGlobal implementation
9
* Copyright (C) 2012 Oracle Corporation
11
* This file is part of VirtualBox Open Source Edition (OSE), as
12
* available from http://www.virtualbox.org. This file is free software;
13
* you can redistribute it and/or modify it under the terms of the GNU
14
* General Public License (GPL) as published by the Free Software
15
* Foundation, in version 2 as it comes in the "COPYING" file of the
16
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21
#include <QApplication>
25
#include "UIConverterBackend.h"
26
#include "VBoxGlobal.h"
29
#include "CSystemProperties.h"
31
/* Determines if <Object of type X> can be converted to object of other type.
32
* These functions returns 'true' for all allowed conversions. */
33
template<> bool canConvert<StorageSlot>() { return true; }
34
template<> bool canConvert<DetailsElementType>() { return true; }
36
/* QString <= StorageSlot: */
37
template<> QString toString(const StorageSlot &storageSlot)
40
switch (storageSlot.bus)
44
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
45
int iMaxDevice = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(storageSlot.bus);
46
if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
48
AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
51
if (storageSlot.device < 0 || storageSlot.device > iMaxDevice)
53
AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
56
if (storageSlot.port == 0 && storageSlot.device == 0)
57
strResult = QApplication::translate("VBoxGlobal", "IDE Primary Master", "StorageSlot");
58
else if (storageSlot.port == 0 && storageSlot.device == 1)
59
strResult = QApplication::translate("VBoxGlobal", "IDE Primary Slave", "StorageSlot");
60
else if (storageSlot.port == 1 && storageSlot.device == 0)
61
strResult = QApplication::translate("VBoxGlobal", "IDE Secondary Master", "StorageSlot");
62
else if (storageSlot.port == 1 && storageSlot.device == 1)
63
strResult = QApplication::translate("VBoxGlobal", "IDE Secondary Slave", "StorageSlot");
66
case KStorageBus_SATA:
68
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
69
if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
71
AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
74
if (storageSlot.device != 0)
76
AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
79
strResult = QApplication::translate("VBoxGlobal", "SATA Port %1", "StorageSlot").arg(storageSlot.port);
82
case KStorageBus_SCSI:
84
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
85
if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
87
AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
90
if (storageSlot.device != 0)
92
AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
95
strResult = QApplication::translate("VBoxGlobal", "SCSI Port %1", "StorageSlot").arg(storageSlot.port);
100
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
101
if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
103
AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
106
if (storageSlot.device != 0)
108
AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
111
strResult = QApplication::translate("VBoxGlobal", "SAS Port %1", "StorageSlot").arg(storageSlot.port);
114
case KStorageBus_Floppy:
116
int iMaxDevice = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(storageSlot.bus);
117
if (storageSlot.port != 0)
119
AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
122
if (storageSlot.device < 0 || storageSlot.device > iMaxDevice)
124
AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
127
strResult = QApplication::translate("VBoxGlobal", "Floppy Device %1", "StorageSlot").arg(storageSlot.device);
132
AssertMsgFailed(("No text for bus=%d & port=% & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
139
/* StorageSlot <= QString: */
140
template<> StorageSlot fromString<StorageSlot>(const QString &strStorageSlot)
142
QHash<int, QString> list;
143
list[0] = QApplication::translate("VBoxGlobal", "IDE Primary Master", "StorageSlot");
144
list[1] = QApplication::translate("VBoxGlobal", "IDE Primary Slave", "StorageSlot");
145
list[2] = QApplication::translate("VBoxGlobal", "IDE Secondary Master", "StorageSlot");
146
list[3] = QApplication::translate("VBoxGlobal", "IDE Secondary Slave", "StorageSlot");
147
list[4] = QApplication::translate("VBoxGlobal", "SATA Port %1", "StorageSlot");
148
list[5] = QApplication::translate("VBoxGlobal", "SCSI Port %1", "StorageSlot");
149
list[6] = QApplication::translate("VBoxGlobal", "SAS Port %1", "StorageSlot");
150
list[7] = QApplication::translate("VBoxGlobal", "Floppy Device %1", "StorageSlot");
153
for (int i = 0; i < list.size(); ++i)
155
regExp = QRegExp(i >= 0 && i <= 3 ? list[i] : list[i].arg("(\\d+)"));
156
if (regExp.indexIn(strStorageSlot) != -1)
171
KStorageBus bus = KStorageBus_IDE;
172
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
173
int iMaxDevice = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(bus);
174
LONG iPort = index / iMaxPort;
175
LONG iDevice = index % iMaxPort;
176
if (iPort < 0 || iPort > iMaxPort)
178
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
181
if (iDevice < 0 || iDevice > iMaxDevice)
183
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
188
result.device = iDevice;
193
KStorageBus bus = KStorageBus_SATA;
194
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
195
LONG iPort = regExp.cap(1).toInt();
197
if (iPort < 0 || iPort > iMaxPort)
199
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
204
result.device = iDevice;
209
KStorageBus bus = KStorageBus_SCSI;
210
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
211
LONG iPort = regExp.cap(1).toInt();
213
if (iPort < 0 || iPort > iMaxPort)
215
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
220
result.device = iDevice;
225
KStorageBus bus = KStorageBus_SAS;
226
int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
227
LONG iPort = regExp.cap(1).toInt();
229
if (iPort < 0 || iPort > iMaxPort)
231
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
236
result.device = iDevice;
241
KStorageBus bus = KStorageBus_Floppy;
242
int iMaxDevice = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(bus);
244
LONG iDevice = regExp.cap(1).toInt();
245
if (iDevice < 0 || iDevice > iMaxDevice)
247
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
252
result.device = iDevice;
257
AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
264
/* QString <= DetailsElementType: */
265
template<> QString toString(const DetailsElementType &detailsElementType)
268
switch (detailsElementType)
270
case DetailsElementType_General: strResult = QApplication::translate("VBoxGlobal", "General", "DetailsElementType"); break;
271
case DetailsElementType_Preview: strResult = QApplication::translate("VBoxGlobal", "Preview", "DetailsElementType"); break;
272
case DetailsElementType_System: strResult = QApplication::translate("VBoxGlobal", "System", "DetailsElementType"); break;
273
case DetailsElementType_Display: strResult = QApplication::translate("VBoxGlobal", "Display", "DetailsElementType"); break;
274
case DetailsElementType_Storage: strResult = QApplication::translate("VBoxGlobal", "Storage", "DetailsElementType"); break;
275
case DetailsElementType_Audio: strResult = QApplication::translate("VBoxGlobal", "Audio", "DetailsElementType"); break;
276
case DetailsElementType_Network: strResult = QApplication::translate("VBoxGlobal", "Network", "DetailsElementType"); break;
277
case DetailsElementType_Serial: strResult = QApplication::translate("VBoxGlobal", "Serial ports", "DetailsElementType"); break;
278
#ifdef VBOX_WITH_PARALLEL_PORTS
279
case DetailsElementType_Parallel: strResult = QApplication::translate("VBoxGlobal", "Parallel ports", "DetailsElementType"); break;
280
#endif /* VBOX_WITH_PARALLEL_PORTS */
281
case DetailsElementType_USB: strResult = QApplication::translate("VBoxGlobal", "USB", "DetailsElementType"); break;
282
case DetailsElementType_SF: strResult = QApplication::translate("VBoxGlobal", "Shared folders", "DetailsElementType"); break;
283
case DetailsElementType_Description: strResult = QApplication::translate("VBoxGlobal", "Description", "DetailsElementType"); break;
286
AssertMsgFailed(("No text for details element type=%d", detailsElementType));
293
/* DetailsElementType <= QString: */
294
template<> DetailsElementType fromString<DetailsElementType>(const QString &strDetailsElementType)
296
QHash<QString, DetailsElementType> list;
297
list.insert(QApplication::translate("VBoxGlobal", "General", "DetailsElementType"), DetailsElementType_General);
298
list.insert(QApplication::translate("VBoxGlobal", "Preview", "DetailsElementType"), DetailsElementType_Preview);
299
list.insert(QApplication::translate("VBoxGlobal", "System", "DetailsElementType"), DetailsElementType_System);
300
list.insert(QApplication::translate("VBoxGlobal", "Display", "DetailsElementType"), DetailsElementType_Display);
301
list.insert(QApplication::translate("VBoxGlobal", "Storage", "DetailsElementType"), DetailsElementType_Storage);
302
list.insert(QApplication::translate("VBoxGlobal", "Audio", "DetailsElementType"), DetailsElementType_Audio);
303
list.insert(QApplication::translate("VBoxGlobal", "Network", "DetailsElementType"), DetailsElementType_Network);
304
list.insert(QApplication::translate("VBoxGlobal", "Serial ports", "DetailsElementType"), DetailsElementType_Serial);
305
#ifdef VBOX_WITH_PARALLEL_PORTS
306
list.insert(QApplication::translate("VBoxGlobal", "Parallel ports", "DetailsElementType"), DetailsElementType_Parallel);
307
#endif /* VBOX_WITH_PARALLEL_PORTS */
308
list.insert(QApplication::translate("VBoxGlobal", "USB", "DetailsElementType"), DetailsElementType_USB);
309
list.insert(QApplication::translate("VBoxGlobal", "Shared folders", "DetailsElementType"), DetailsElementType_SF);
310
list.insert(QApplication::translate("VBoxGlobal", "Description", "DetailsElementType"), DetailsElementType_Description);
311
if (!list.contains(strDetailsElementType))
313
AssertMsgFailed(("No value for '%s'", strDetailsElementType.toAscii().constData()));
315
return list.value(strDetailsElementType);
318
/* QString <= DetailsElementType: */
319
template<> QString toInternalString(const DetailsElementType &detailsElementType)
322
switch (detailsElementType)
324
case DetailsElementType_General: strResult = "general"; break;
325
case DetailsElementType_Preview: strResult = "preview"; break;
326
case DetailsElementType_System: strResult = "system"; break;
327
case DetailsElementType_Display: strResult = "display"; break;
328
case DetailsElementType_Storage: strResult = "storage"; break;
329
case DetailsElementType_Audio: strResult = "audio"; break;
330
case DetailsElementType_Network: strResult = "network"; break;
331
case DetailsElementType_Serial: strResult = "serialPorts"; break;
332
#ifdef VBOX_WITH_PARALLEL_PORTS
333
case DetailsElementType_Parallel: strResult = "parallelPorts"; break;
334
#endif /* VBOX_WITH_PARALLEL_PORTS */
335
case DetailsElementType_USB: strResult = "usb"; break;
336
case DetailsElementType_SF: strResult = "sharedFolders"; break;
337
case DetailsElementType_Description: strResult = "description"; break;
340
AssertMsgFailed(("No text for details element type=%d", detailsElementType));
347
/* DetailsElementType <= QString: */
348
template<> DetailsElementType fromInternalString<DetailsElementType>(const QString &strDetailsElementType)
350
QHash<QString, DetailsElementType> list;
351
list.insert("general", DetailsElementType_General);
352
list.insert("preview", DetailsElementType_Preview);
353
list.insert("system", DetailsElementType_System);
354
list.insert("display", DetailsElementType_Display);
355
list.insert("storage", DetailsElementType_Storage);
356
list.insert("audio", DetailsElementType_Audio);
357
list.insert("network", DetailsElementType_Network);
358
list.insert("serialPorts", DetailsElementType_Serial);
359
#ifdef VBOX_WITH_PARALLEL_PORTS
360
list.insert("parallelPorts", DetailsElementType_Parallel);
361
#endif /* VBOX_WITH_PARALLEL_PORTS */
362
list.insert("usb", DetailsElementType_USB);
363
list.insert("sharedFolders", DetailsElementType_SF);
364
list.insert("description", DetailsElementType_Description);
365
if (!list.contains(strDetailsElementType))
367
AssertMsgFailed(("No value for '%s'", strDetailsElementType.toAscii().constData()));
369
return list.value(strDetailsElementType);