VirtualBox

Changeset 82931 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jan 30, 2020 2:48:06 PM (5 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9653: VirtualBox Manager: Rework UIVirtualMachineItem to cache everything, including NLS tags which previously were generated on-the-fly; This required a bit of NLS related changes as well.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/manager
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItem.cpp

    r82879 r82931  
    1717
    1818/* Qt includes: */
    19 #include <QApplication>
    2019#include <QFileInfo>
    2120#include <QIcon>
     
    6160}
    6261
    63 QString UIVirtualMachineItem::machineStateName() const
    64 {
    65     return   m_fAccessible
    66            ? gpConverter->toString(m_enmMachineState)
    67            : QApplication::translate("UIVMListView", "Inaccessible");
    68 }
    69 
    70 QString UIVirtualMachineItem::sessionStateName() const
    71 {
    72     return   m_fAccessible
    73            ? gpConverter->toString(m_enmSessionState)
    74            : QApplication::translate("UIVMListView", "Inaccessible");
    75 }
    76 
    77 QIcon UIVirtualMachineItem::machineStateIcon() const
    78 {
    79     return   m_fAccessible
    80            ? gpConverter->toIcon(m_enmMachineState)
    81            : gpConverter->toIcon(KMachineState_Aborted);
    82 }
    83 
    84 QString UIVirtualMachineItem::toolTipText() const
    85 {
    86     QString strToolTip;
    87 
    88     const QString strDateTime = (m_lastStateChange.date() == QDate::currentDate())
    89                               ? m_lastStateChange.time().toString(Qt::LocalDate)
    90                               : m_lastStateChange.toString(Qt::LocalDate);
    91 
    92     if (m_fAccessible)
    93     {
    94         strToolTip = QString("<b>%1</b>").arg(m_strName);
    95         if (!m_strSnapshotName.isNull())
    96             strToolTip += QString(" (%1)").arg(m_strSnapshotName);
    97         strToolTip = QApplication::translate("UIVMListView",
    98                                              "<nobr>%1<br></nobr>"
    99                                              "<nobr>%2 since %3</nobr><br>"
    100                                              "<nobr>Session %4</nobr>",
    101                                              "VM tooltip (name, last state change, session state)")
    102                                              .arg(strToolTip)
    103                                              .arg(gpConverter->toString(m_enmMachineState))
    104                                              .arg(strDateTime)
    105                                              .arg(gpConverter->toString(m_enmSessionState).toLower());
    106     }
    107     else
    108     {
    109         strToolTip = QApplication::translate("UIVMListView",
    110                                              "<nobr><b>%1</b><br></nobr>"
    111                                              "<nobr>Inaccessible since %2</nobr>",
    112                                              "Inaccessible VM tooltip (name, last state change)")
    113                                              .arg(m_strSettingsFile)
    114                                              .arg(strDateTime);
    115     }
    116 
    117     return strToolTip;
    118 }
    119 
    12062void UIVirtualMachineItem::recache()
    12163{
     
    14486        /* Determine VM states: */
    14587        m_enmMachineState = m_comMachine.GetState();
     88        m_strMachineStateName = gpConverter->toString(m_enmMachineState);
     89        m_machineStateIcon = gpConverter->toIcon(m_enmMachineState);
    14690        m_enmSessionState = m_comMachine.GetSessionState();
     91        m_strSessionStateName = gpConverter->toString(m_enmSessionState);
    14792
    14893        /* Determine configuration access level: */
     
    191136        /* Reset VM states: */
    192137        m_enmMachineState = KMachineState_Null;
     138        m_machineStateIcon = gpConverter->toIcon(KMachineState_Aborted);
    193139        m_enmSessionState = KSessionState_Null;
    194140
     
    205151    /* Recache item pixmap: */
    206152    recachePixmap();
     153
     154    /* Retranslate finally: */
     155    retranslateUi();
    207156}
    208157
     
    228177bool UIVirtualMachineItem::canSwitchTo() const
    229178{
    230     return const_cast <CMachine &>(m_comMachine).CanShowConsoleWindow();
     179    return const_cast <CMachine&>(m_comMachine).CanShowConsoleWindow();
    231180}
    232181
     
    354303}
    355304
     305void UIVirtualMachineItem::retranslateUi()
     306{
     307    /* This is used in tool-tip generation: */
     308    const QString strDateTime = (m_lastStateChange.date() == QDate::currentDate())
     309                              ? m_lastStateChange.time().toString(Qt::LocalDate)
     310                              : m_lastStateChange.toString(Qt::LocalDate);
     311
     312    /* If machine is accessible: */
     313    if (m_fAccessible)
     314    {
     315        /* Update tool-tip: */
     316        m_strToolTipText = QString("<b>%1</b>").arg(m_strName);
     317        if (!m_strSnapshotName.isNull())
     318            m_strToolTipText += QString(" (%1)").arg(m_strSnapshotName);
     319        m_strToolTipText = tr("<nobr>%1<br></nobr>"
     320                              "<nobr>%2 since %3</nobr><br>"
     321                              "<nobr>Session %4</nobr>",
     322                              "VM tooltip (name, last state change, session state)")
     323                              .arg(m_strToolTipText)
     324                              .arg(gpConverter->toString(m_enmMachineState))
     325                              .arg(strDateTime)
     326                              .arg(gpConverter->toString(m_enmSessionState).toLower());
     327    }
     328    /* Otherwise: */
     329    else
     330    {
     331        /* Update tool-tip: */
     332        m_strToolTipText = tr("<nobr><b>%1</b><br></nobr>"
     333                              "<nobr>Inaccessible since %2</nobr>",
     334                              "Inaccessible VM tooltip (name, last state change)")
     335                              .arg(m_strSettingsFile)
     336                              .arg(strDateTime);
     337
     338        /* We have our own translation for Null states: */
     339        m_strMachineStateName = tr("Inaccessible");
     340        m_strSessionStateName = tr("Inaccessible");
     341    }
     342}
     343
    356344
    357345/*********************************************************************************************************************************
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualMachineItem.h

    r82878 r82931  
    2424/* Qt includes: */
    2525#include <QDateTime>
     26#include <QIcon>
    2627#include <QMimeData>
    2728#include <QPixmap>
    2829
    2930/* GUI includes: */
     31#include "QIWithRetranslateUI.h"
    3032#include "UISettingsDefs.h"
    3133
     
    3840using namespace UISettingsDefs;
    3941
    40 /** Virtual Machine item interface.
    41   * A wrapper caching data about local VM. */
    42 class UIVirtualMachineItem
     42/** Virtual Machine item interface. A wrapper caching VM data. */
     43class UIVirtualMachineItem : public QIWithRetranslateUI3<QObject>
    4344{
     45    Q_OBJECT;
     46
    4447public:
    4548
     
    5558    /** @} */
    5659
     60    /** @name VM access attributes.
     61      * @{ */
     62        /** Returns whether VM was accessible. */
     63        bool accessible() const { return m_fAccessible; }
     64        /** Returns the last cached access error. */
     65        const CVirtualBoxErrorInfo &accessError() const { return m_comAccessError; }
     66    /** @} */
     67
    5768    /** @name Basic attributes.
    5869      * @{ */
     
    6172        /** Returns cached machine settings file name. */
    6273        QString settingsFile() const { return m_strSettingsFile; }
    63     /** @} */
    64 
    65     /** @name VM access attributes.
    66       * @{ */
    67         /** Returns whether VM was accessible. */
    68         bool accessible() const { return m_fAccessible; }
    69         /** Returns the last cached access error. */
    70         const CVirtualBoxErrorInfo &accessError() const { return m_comAccessError; }
    71     /** @} */
    72 
    73     /** @name Advanced attributes.
    74       * @{ */
    7574        /** Returns cached machine name. */
    7675        QString name() const { return m_strName; }
     
    9695        /** Returns cached machine state. */
    9796        KMachineState machineState() const { return m_enmMachineState; }
     97        /** Returns cached machine state name. */
     98        QString machineStateName() const { return m_strMachineStateName; }
     99        /** Returns cached machine state icon. */
     100        QIcon machineStateIcon() const { return m_machineStateIcon; }
     101
    98102        /** Returns cached session state. */
    99103        KSessionState sessionState() const { return m_enmSessionState; }
    100         /** Returns cached machine state name. */
    101         QString machineStateName() const;
    102104        /** Returns cached session state name. */
    103         QString sessionStateName() const;
    104         /** Returns cached machine state icon. */
    105         QIcon machineStateIcon() const;
     105        QString sessionStateName() const { return m_strSessionStateName; }
     106
    106107        /** Returns cached configuration access level. */
    107108        ConfigurationAccessLevel configurationAccessLevel() const { return m_enmConfigurationAccessLevel; }
     
    111112      * @{ */
    112113        /** Returns cached machine tool-tip. */
    113         QString toolTipText() const;
     114        QString toolTipText() const { return m_strToolTipText; }
    114115    /** @} */
    115116
     
    157158    /** @} */
    158159
     160protected:
     161
     162    /** @name Event handling.
     163      * @{ */
     164        /** Handles translation event. */
     165        virtual void retranslateUi() /* override */;
     166    /** @} */
     167
    159168private:
    160169
     
    163172        /** Holds cached machine object reference. */
    164173        CMachine  m_comMachine;
    165     /** @} */
    166 
    167     /** @name Basic attributes.
    168       * @{ */
    169         /** Holds cached machine id. */
    170         QUuid    m_uId;
    171         /** Holds cached machine settings file name. */
    172         QString  m_strSettingsFile;
    173174    /** @} */
    174175
     
    181182    /** @} */
    182183
    183     /** @name Advanced attributes.
    184       * @{ */
     184    /** @name Basic attributes.
     185      * @{ */
     186        /** Holds cached machine id. */
     187        QUuid        m_uId;
     188        /** Holds cached machine settings file name. */
     189        QString      m_strSettingsFile;
    185190        /** Holds cached machine name. */
    186191        QString      m_strName;
     
    209214        /** Holds cached machine state. */
    210215        KMachineState             m_enmMachineState;
     216        /** Holds cached machine state name. */
     217        QString                   m_strMachineStateName;
     218        /** Holds cached machine state name. */
     219        QIcon                     m_machineStateIcon;
     220
    211221        /** Holds cached session state. */
    212222        KSessionState             m_enmSessionState;
     223        /** Holds cached session state name. */
     224        QString                   m_strSessionStateName;
     225
    213226        /** Holds configuration access level. */
    214227        ConfigurationAccessLevel  m_enmConfigurationAccessLevel;
     228    /** @} */
     229
     230    /** @name Visual attributes.
     231      * @{ */
     232        /** Holds cached machine tool-tip. */
     233        QString  m_strToolTipText;
    215234    /** @} */
    216235
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