VirtualBox

Changeset 48826 in vbox for trunk


Ignore:
Timestamp:
Oct 2, 2013 5:43:12 PM (11 years ago)
Author:
vboxsync
Message:

FE/Qt: 6936: Crash in worker enumeration thread: Moving static translation stuff to UIConverter framework.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackend.h

    r48523 r48826  
    5858
    5959/* Declare global canConvert specializations: */
     60template<> bool canConvert<SizeSuffix>();
    6061template<> bool canConvert<StorageSlot>();
    6162template<> bool canConvert<RuntimeMenuType>();
     
    9192
    9293/* Declare global conversion specializations: */
     94template<> QString toString(const SizeSuffix &sizeSuffix);
     95template<> SizeSuffix fromString<SizeSuffix>(const QString &strSizeSuffix);
    9396template<> QString toString(const StorageSlot &storageSlot);
    9497template<> StorageSlot fromString<StorageSlot>(const QString &strStorageSlot);
  • trunk/src/VBox/Frontends/VirtualBox/src/converter/UIConverterBackendGlobal.cpp

    r47595 r48826  
    3131/* Determines if <Object of type X> can be converted to object of other type.
    3232 * These functions returns 'true' for all allowed conversions. */
     33template<> bool canConvert<SizeSuffix>() { return true; }
    3334template<> bool canConvert<StorageSlot>() { return true; }
    3435template<> bool canConvert<RuntimeMenuType>() { return true; }
     
    3940template<> bool canConvert<IndicatorType>() { return true; }
    4041template<> bool canConvert<MachineCloseAction>() { return true; }
     42
     43/* QString <= SizeSuffix: */
     44template<> QString toString(const SizeSuffix &sizeSuffix)
     45{
     46    QString strResult;
     47    switch (sizeSuffix)
     48    {
     49        case SizeSuffix_Byte:     strResult = QApplication::translate("VBoxGlobal", "B", "size suffix Bytes"); break;
     50        case SizeSuffix_KiloByte: strResult = QApplication::translate("VBoxGlobal", "KB", "size suffix KBytes=1024 Bytes"); break;
     51        case SizeSuffix_MegaByte: strResult = QApplication::translate("VBoxGlobal", "MB", "size suffix MBytes=1024 KBytes"); break;
     52        case SizeSuffix_GigaByte: strResult = QApplication::translate("VBoxGlobal", "GB", "size suffix GBytes=1024 MBytes"); break;
     53        case SizeSuffix_TeraByte: strResult = QApplication::translate("VBoxGlobal", "TB", "size suffix TBytes=1024 GBytes"); break;
     54        case SizeSuffix_PetaByte: strResult = QApplication::translate("VBoxGlobal", "PB", "size suffix PBytes=1024 TBytes"); break;
     55        default:
     56        {
     57            AssertMsgFailed(("No text for size suffix=%d", sizeSuffix));
     58            break;
     59        }
     60    }
     61    return strResult;
     62}
     63
     64/* SizeSuffix <= QString: */
     65template<> SizeSuffix fromString<SizeSuffix>(const QString &strSizeSuffix)
     66{
     67    QHash<QString, SizeSuffix> list;
     68    list.insert(QApplication::translate("VBoxGlobal", "B", "size suffix Bytes"),               SizeSuffix_Byte);
     69    list.insert(QApplication::translate("VBoxGlobal", "KB", "size suffix KBytes=1024 Bytes"),  SizeSuffix_KiloByte);
     70    list.insert(QApplication::translate("VBoxGlobal", "MB", "size suffix MBytes=1024 KBytes"), SizeSuffix_MegaByte);
     71    list.insert(QApplication::translate("VBoxGlobal", "GB", "size suffix GBytes=1024 MBytes"), SizeSuffix_GigaByte);
     72    list.insert(QApplication::translate("VBoxGlobal", "TB", "size suffix TBytes=1024 GBytes"), SizeSuffix_TeraByte);
     73    list.insert(QApplication::translate("VBoxGlobal", "PB", "size suffix PBytes=1024 TBytes"), SizeSuffix_PetaByte);
     74    if (!list.contains(strSizeSuffix))
     75    {
     76        AssertMsgFailed(("No value for '%s'", strSizeSuffix.toAscii().constData()));
     77    }
     78    return list.value(strSizeSuffix);
     79}
    4180
    4281/* QString <= StorageSlot: */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDefs.h

    r48301 r48826  
    228228Q_DECLARE_METATYPE(StorageSlot);
    229229
     230/* Common UI size suffixes: */
     231enum SizeSuffix
     232{
     233    SizeSuffix_Byte = 0,
     234    SizeSuffix_KiloByte,
     235    SizeSuffix_MegaByte,
     236    SizeSuffix_GigaByte,
     237    SizeSuffix_TeraByte,
     238    SizeSuffix_PetaByte,
     239    SizeSuffix_Max
     240};
     241
    230242/* Runtime UI menu types: */
    231243enum RuntimeMenuType
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r48685 r48826  
    25972597                                FormatSize aMode /* = FormatSize_Round */)
    25982598{
    2599     static QString Suffixes [7];
    2600     Suffixes[0] = tr ("B", "size suffix Bytes");
    2601     Suffixes[1] = tr ("KB", "size suffix KBytes=1024 Bytes");
    2602     Suffixes[2] = tr ("MB", "size suffix MBytes=1024 KBytes");
    2603     Suffixes[3] = tr ("GB", "size suffix GBytes=1024 MBytes");
    2604     Suffixes[4] = tr ("TB", "size suffix TBytes=1024 GBytes");
    2605     Suffixes[5] = tr ("PB", "size suffix PBytes=1024 TBytes");
    2606     Suffixes[6] = (const char *)NULL;
    2607     AssertCompile(6 < RT_ELEMENTS (Suffixes));
    2608 
    26092599    quint64 denom = 0;
    26102600    int suffix = 0;
     
    26672657            ++ intg;
    26682658            /* check if we've got 1024 XB after rounding and scale down if so */
    2669             if (intg == 1024 && Suffixes [suffix + 1] != NULL)
     2659            if (intg == 1024 && suffix + 1 < (int)SizeSuffix_Max)
    26702660            {
    26712661                intg /= 1024;
     
    26822672    }
    26832673
    2684     return QString ("%1 %2").arg (number).arg (Suffixes [suffix]);
     2674    return QString ("%1 %2").arg (number).arg (gpConverter->toString(static_cast<SizeSuffix>(suffix)));
    26852675}
    26862676
Note: See TracChangeset for help on using the changeset viewer.

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