VirtualBox

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.

File:
1 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/*********************************************************************************************************************************
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