~ubuntu-branches/ubuntu/trusty/virtualbox/trusty-proposed

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendGlobal.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer
  • Date: 2013-03-07 16:38:36 UTC
  • mfrom: (1.1.13) (3.1.20 experimental)
  • Revision ID: package-import@ubuntu.com-20130307163836-p93jpbgx39tp3gb4
Tags: 4.2.8-dfsg-0ubuntu1
* New upstream release. (Closes: #691148)
  - Fixes compatibility with kernel 3.8. (Closes: #700823; LP: #1101867)
* Switch to my @debian.org email address.
* Move package to contrib as virtualbox 4.2 needs a non-free compiler to
  build the BIOS.
* Build-depend on libdevmapper-dev.
* Refresh patches.
  - Drop 36-fix-ftbfs-xserver-112.patch, cve-2012-3221.patch,
    CVE-2013-0420.patch 37-kcompat-3.6.patch and 38-kcompat-3.7.patch.
* Drop all virtualbox-ose transitional packages.
* Drop the virtualbox-fuse package as vdfuse fails to build with
  virtualbox 4.2.
* Update install files and VBox.sh.
* Bump required kbuild version to 0.1.9998svn2577.
* Fix path to VBoxCreateUSBNode.sh in virtualbox.postinst. (Closes: #700479)
* Add an init script to virtuabox-guest-x11 which loads the vboxvideo
  kernel module. The X Server 1.13 doesn't load it anymore. (Closes: #686994)
* Update man pages. (Closes: #680053)
* Add 36-python-multiarch.patch from Rico Tzschichholz to fix detection of
  python in multiarch paths using pkg-config.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: UIConverterBackendGlobal.cpp $ */
 
2
/** @file
 
3
 *
 
4
 * VBox frontends: Qt GUI ("VirtualBox"):
 
5
 * UIConverterBackendGlobal implementation
 
6
 */
 
7
 
 
8
/*
 
9
 * Copyright (C) 2012 Oracle Corporation
 
10
 *
 
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.
 
18
 */
 
19
 
 
20
/* Qt includes: */
 
21
#include <QApplication>
 
22
#include <QHash>
 
23
 
 
24
/* GUI includes: */
 
25
#include "UIConverterBackend.h"
 
26
#include "VBoxGlobal.h"
 
27
 
 
28
/* COM includes: */
 
29
#include "CSystemProperties.h"
 
30
 
 
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; }
 
35
 
 
36
/* QString <= StorageSlot: */
 
37
template<> QString toString(const StorageSlot &storageSlot)
 
38
{
 
39
    QString strResult;
 
40
    switch (storageSlot.bus)
 
41
    {
 
42
        case KStorageBus_IDE:
 
43
        {
 
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)
 
47
            {
 
48
                AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
 
49
                break;
 
50
            }
 
51
            if (storageSlot.device < 0 || storageSlot.device > iMaxDevice)
 
52
            {
 
53
                AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
 
54
                break;
 
55
            }
 
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");
 
64
            break;
 
65
        }
 
66
        case KStorageBus_SATA:
 
67
        {
 
68
            int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
 
69
            if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
 
70
            {
 
71
                AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
 
72
                break;
 
73
            }
 
74
            if (storageSlot.device != 0)
 
75
            {
 
76
                AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
 
77
                break;
 
78
            }
 
79
            strResult = QApplication::translate("VBoxGlobal", "SATA Port %1", "StorageSlot").arg(storageSlot.port);
 
80
            break;
 
81
        }
 
82
        case KStorageBus_SCSI:
 
83
        {
 
84
            int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
 
85
            if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
 
86
            {
 
87
                AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
 
88
                break;
 
89
            }
 
90
            if (storageSlot.device != 0)
 
91
            {
 
92
                AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
 
93
                break;
 
94
            }
 
95
            strResult = QApplication::translate("VBoxGlobal", "SCSI Port %1", "StorageSlot").arg(storageSlot.port);
 
96
            break;
 
97
        }
 
98
        case KStorageBus_SAS:
 
99
        {
 
100
            int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(storageSlot.bus);
 
101
            if (storageSlot.port < 0 || storageSlot.port > iMaxPort)
 
102
            {
 
103
                AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
 
104
                break;
 
105
            }
 
106
            if (storageSlot.device != 0)
 
107
            {
 
108
                AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
 
109
                break;
 
110
            }
 
111
            strResult = QApplication::translate("VBoxGlobal", "SAS Port %1", "StorageSlot").arg(storageSlot.port);
 
112
            break;
 
113
        }
 
114
        case KStorageBus_Floppy:
 
115
        {
 
116
            int iMaxDevice = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(storageSlot.bus);
 
117
            if (storageSlot.port != 0)
 
118
            {
 
119
                AssertMsgFailed(("No text for bus=%d & port=%d", storageSlot.bus, storageSlot.port));
 
120
                break;
 
121
            }
 
122
            if (storageSlot.device < 0 || storageSlot.device > iMaxDevice)
 
123
            {
 
124
                AssertMsgFailed(("No text for bus=%d & port=%d & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
 
125
                break;
 
126
            }
 
127
            strResult = QApplication::translate("VBoxGlobal", "Floppy Device %1", "StorageSlot").arg(storageSlot.device);
 
128
            break;
 
129
        }
 
130
        default:
 
131
        {
 
132
            AssertMsgFailed(("No text for bus=%d & port=% & device=%d", storageSlot.bus, storageSlot.port, storageSlot.device));
 
133
            break;
 
134
        }
 
135
    }
 
136
    return strResult;
 
137
}
 
138
 
 
139
/* StorageSlot <= QString: */
 
140
template<> StorageSlot fromString<StorageSlot>(const QString &strStorageSlot)
 
141
{
 
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");
 
151
    int index = -1;
 
152
    QRegExp regExp;
 
153
    for (int i = 0; i < list.size(); ++i)
 
154
    {
 
155
        regExp = QRegExp(i >= 0 && i <= 3 ? list[i] : list[i].arg("(\\d+)"));
 
156
        if (regExp.indexIn(strStorageSlot) != -1)
 
157
        {
 
158
            index = i;
 
159
            break;
 
160
        }
 
161
    }
 
162
 
 
163
    StorageSlot result;
 
164
    switch (index)
 
165
    {
 
166
        case 0:
 
167
        case 1:
 
168
        case 2:
 
169
        case 3:
 
170
        {
 
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)
 
177
            {
 
178
                AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
179
                break;
 
180
            }
 
181
            if (iDevice < 0 || iDevice > iMaxDevice)
 
182
            {
 
183
                AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
184
                break;
 
185
            }
 
186
            result.bus = bus;
 
187
            result.port = iPort;
 
188
            result.device = iDevice;
 
189
            break;
 
190
        }
 
191
        case 4:
 
192
        {
 
193
            KStorageBus bus = KStorageBus_SATA;
 
194
            int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
 
195
            LONG iPort = regExp.cap(1).toInt();
 
196
            LONG iDevice = 0;
 
197
            if (iPort < 0 || iPort > iMaxPort)
 
198
            {
 
199
                AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
200
                break;
 
201
            }
 
202
            result.bus = bus;
 
203
            result.port = iPort;
 
204
            result.device = iDevice;
 
205
            break;
 
206
        }
 
207
        case 5:
 
208
        {
 
209
            KStorageBus bus = KStorageBus_SCSI;
 
210
            int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
 
211
            LONG iPort = regExp.cap(1).toInt();
 
212
            LONG iDevice = 0;
 
213
            if (iPort < 0 || iPort > iMaxPort)
 
214
            {
 
215
                AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
216
                break;
 
217
            }
 
218
            result.bus = bus;
 
219
            result.port = iPort;
 
220
            result.device = iDevice;
 
221
            break;
 
222
        }
 
223
        case 6:
 
224
        {
 
225
            KStorageBus bus = KStorageBus_SAS;
 
226
            int iMaxPort = vboxGlobal().virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus(bus);
 
227
            LONG iPort = regExp.cap(1).toInt();
 
228
            LONG iDevice = 0;
 
229
            if (iPort < 0 || iPort > iMaxPort)
 
230
            {
 
231
                AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
232
                break;
 
233
            }
 
234
            result.bus = bus;
 
235
            result.port = iPort;
 
236
            result.device = iDevice;
 
237
            break;
 
238
        }
 
239
        case 7:
 
240
        {
 
241
            KStorageBus bus = KStorageBus_Floppy;
 
242
            int iMaxDevice = vboxGlobal().virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus(bus);
 
243
            LONG iPort = 0;
 
244
            LONG iDevice = regExp.cap(1).toInt();
 
245
            if (iDevice < 0 || iDevice > iMaxDevice)
 
246
            {
 
247
                AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
248
                break;
 
249
            }
 
250
            result.bus = bus;
 
251
            result.port = iPort;
 
252
            result.device = iDevice;
 
253
            break;
 
254
        }
 
255
        default:
 
256
        {
 
257
            AssertMsgFailed(("No storage slot for text='%s'", strStorageSlot.toAscii().constData()));
 
258
            break;
 
259
        }
 
260
    }
 
261
    return result;
 
262
}
 
263
 
 
264
/* QString <= DetailsElementType: */
 
265
template<> QString toString(const DetailsElementType &detailsElementType)
 
266
{
 
267
    QString strResult;
 
268
    switch (detailsElementType)
 
269
    {
 
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;
 
284
        default:
 
285
        {
 
286
            AssertMsgFailed(("No text for details element type=%d", detailsElementType));
 
287
            break;
 
288
        }
 
289
    }
 
290
    return strResult;
 
291
}
 
292
 
 
293
/* DetailsElementType <= QString: */
 
294
template<> DetailsElementType fromString<DetailsElementType>(const QString &strDetailsElementType)
 
295
{
 
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))
 
312
    {
 
313
        AssertMsgFailed(("No value for '%s'", strDetailsElementType.toAscii().constData()));
 
314
    }
 
315
    return list.value(strDetailsElementType);
 
316
}
 
317
 
 
318
/* QString <= DetailsElementType: */
 
319
template<> QString toInternalString(const DetailsElementType &detailsElementType)
 
320
{
 
321
    QString strResult;
 
322
    switch (detailsElementType)
 
323
    {
 
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;
 
338
        default:
 
339
        {
 
340
            AssertMsgFailed(("No text for details element type=%d", detailsElementType));
 
341
            break;
 
342
        }
 
343
    }
 
344
    return strResult;
 
345
}
 
346
 
 
347
/* DetailsElementType <= QString: */
 
348
template<> DetailsElementType fromInternalString<DetailsElementType>(const QString &strDetailsElementType)
 
349
{
 
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))
 
366
    {
 
367
        AssertMsgFailed(("No value for '%s'", strDetailsElementType.toAscii().constData()));
 
368
    }
 
369
    return list.value(strDetailsElementType);
 
370
}
 
371