VirtualBox

Ignore:
Timestamp:
Jan 29, 2024 9:08:47 AM (12 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10501. Some cleaning.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/activity/overview/UIVMActivityOverviewWidget.cpp

    r103019 r103101  
    232232public:
    233233
    234     UIActivityOverviewItem(const QUuid &uid, const QString &strVMName, bool fIsCloudVM = false);
     234    UIActivityOverviewItem(const QUuid &uid, const QString &strVMName);
    235235
    236236    UIActivityOverviewItem();
    237237    ~UIActivityOverviewItem();
    238238    bool operator==(const UIActivityOverviewItem& other) const;
    239     bool isWithGuestAdditions();
    240     void resetDebugger();
    241239
    242240    QUuid         m_VMuid;
    243241    QString       m_strVMName;
    244     bool          m_fIsCloudVM;
    245 
    246     KMachineState m_enmMachineState;
    247242
    248243    quint64  m_uCPUGuestLoad;
    249     quint64  m_uCPUVMMLoad;
    250 
    251244    quint64  m_uTotalRAM;
    252245    quint64  m_uFreeRAM;
    253246    quint64  m_uUsedRAM;
    254247    float    m_fRAMUsagePercentage;
    255 
    256     quint64 m_uNetworkDownRate;
    257     quint64 m_uNetworkUpRate;
    258     quint64 m_uNetworkDownTotal;
    259     quint64 m_uNetworkUpTotal;
     248    quint64  m_uNetworkDownRate;
     249    quint64  m_uNetworkUpRate;
     250    quint64  m_uNetworkDownTotal;
     251    quint64  m_uNetworkUpTotal;
    260252
    261253    quint64 m_uDiskWriteRate;
     
    264256    quint64 m_uDiskReadTotal;
    265257
     258
     259    /** The strings of each column for the item. We update this during performance query
     260      * instead of model's data function to know the string length earlier. */
     261    QMap<int, QString> m_columnData;
     262
     263private:
     264
     265    void setupPerformanceCollector();
     266};
     267
     268Q_DECLARE_METATYPE(UIActivityOverviewItem);
     269
     270/** Each instance of UIVMActivityOverviewItem corresponds to a running vm whose stats are displayed.
     271  * they are owned my the model. */
     272/*********************************************************************************************************************************
     273 *   Class UIVMActivityOverviewItem definition.                                                                           *
     274 *********************************************************************************************************************************/
     275class UIActivityOverviewItemLocal : public UIActivityOverviewItem
     276{
     277
     278public:
     279
     280    UIActivityOverviewItemLocal(const QUuid &uid, const QString &strVMName);
     281
     282    UIActivityOverviewItemLocal();
     283    ~UIActivityOverviewItemLocal();
     284
     285    bool isWithGuestAdditions();
     286    void resetDebugger();
     287
     288    KMachineState m_enmMachineState;
     289    quint64  m_uCPUVMMLoad;
     290
    266291    quint64 m_uVMExitRate;
    267292    quint64 m_uVMExitTotal;
     
    270295    CMachineDebugger m_comDebugger;
    271296    CGuest   m_comGuest;
    272     /** The strings of each column for the item. We update this during performance query
    273       * instead of model's data function to know the string length earlier. */
    274     QMap<int, QString> m_columnData;
    275 
    276 private:
    277 
    278     void setupPerformanceCollector();
    279297};
    280298
    281 Q_DECLARE_METATYPE(UIActivityOverviewItem);
     299
     300/*********************************************************************************************************************************
     301*   Class UIVMActivityOverviewItem implementation.                                                                               *
     302*********************************************************************************************************************************/
     303UIActivityOverviewItemLocal::UIActivityOverviewItemLocal(const QUuid &uid, const QString &strVMName)
     304    : UIActivityOverviewItem(uid, strVMName)
     305    , m_uCPUVMMLoad(0)
     306    , m_uVMExitRate(0)
     307    , m_uVMExitTotal(0)
     308{
     309    if (m_enmMachineState == KMachineState_Running)
     310        resetDebugger();
     311}
     312
     313UIActivityOverviewItemLocal::UIActivityOverviewItemLocal()
     314    : m_uCPUVMMLoad(0)
     315    , m_uVMExitRate(0)
     316    , m_uVMExitTotal(0)
     317{
     318}
     319
     320UIActivityOverviewItemLocal::~UIActivityOverviewItemLocal()
     321{
     322    if (!m_comSession.isNull())
     323        m_comSession.UnlockMachine();
     324}
     325
     326bool UIActivityOverviewItemLocal::isWithGuestAdditions()
     327{
     328    if (m_comGuest.isNull())
     329        return false;
     330    return m_comGuest.GetAdditionsStatus(m_comGuest.GetAdditionsRunLevel());
     331}
     332
     333void UIActivityOverviewItemLocal::resetDebugger()
     334{
     335    m_comSession = uiCommon().openSession(m_VMuid, KLockType_Shared);
     336    if (!m_comSession.isNull())
     337    {
     338        CConsole comConsole = m_comSession.GetConsole();
     339        if (!comConsole.isNull())
     340        {
     341            m_comGuest = comConsole.GetGuest();
     342            m_comDebugger = comConsole.GetDebugger();
     343        }
     344    }
     345}
    282346
    283347
     
    346410    void sltMachineRegistered(const QUuid &uId, bool fRegistered);
    347411    void sltTimeout();
    348     void sltCloudUpdateTimeout();
    349412
    350413private:
     
    357420    void removeItem(const QUuid& uMachineId);
    358421    void getHostRAMStats();
    359     QVector<CCloudClient> obtainCloudClientList();
    360     QVector<CCloudMachine> obtainCloudMachineList();
    361 
    362     QVector<UIActivityOverviewItem> m_itemList;
     422
     423    QVector<UIActivityOverviewItemLocal> m_itemList;
    363424    QMap<int, QString> m_columnTitles;
    364425    QTimer *m_pTimer;
    365     QTimer *m_pCloudUpdateTimer;
    366426    /** @name The following are used during UIPerformanceCollector::QueryMetricsData(..)
    367427     * @{ */
     
    793853*   Class UIVMActivityOverviewItem implementation.                                                                               *
    794854*********************************************************************************************************************************/
    795 UIActivityOverviewItem::UIActivityOverviewItem(const QUuid &uid, const QString &strVMName, bool fIsCloudVM /* = false */)
     855UIActivityOverviewItem::UIActivityOverviewItem(const QUuid &uid, const QString &strVMName)
    796856    : m_VMuid(uid)
    797857    , m_strVMName(strVMName)
    798     , m_fIsCloudVM(fIsCloudVM)
    799858    , m_uCPUGuestLoad(0)
    800     , m_uCPUVMMLoad(0)
    801859    , m_uTotalRAM(0)
    802860    , m_uFreeRAM(0)
     
    811869    , m_uDiskWriteTotal(0)
    812870    , m_uDiskReadTotal(0)
    813     , m_uVMExitRate(0)
    814     , m_uVMExitTotal(0)
    815 {
    816     if (m_enmMachineState == KMachineState_Running)
    817         resetDebugger();
     871{
    818872}
    819873
    820874UIActivityOverviewItem::UIActivityOverviewItem()
    821875    : m_VMuid(QUuid())
    822     , m_fIsCloudVM(false)
    823876    , m_uCPUGuestLoad(0)
    824     , m_uCPUVMMLoad(0)
    825877    , m_uTotalRAM(0)
    826878    , m_uUsedRAM(0)
     
    834886    , m_uDiskWriteTotal(0)
    835887    , m_uDiskReadTotal(0)
    836     , m_uVMExitRate(0)
    837     , m_uVMExitTotal(0)
    838 {
    839 }
    840 
    841 void UIActivityOverviewItem::resetDebugger()
    842 {
    843     m_comSession = uiCommon().openSession(m_VMuid, KLockType_Shared);
    844     if (!m_comSession.isNull())
    845     {
    846         CConsole comConsole = m_comSession.GetConsole();
    847         if (!comConsole.isNull())
    848         {
    849             m_comGuest = comConsole.GetGuest();
    850             m_comDebugger = comConsole.GetDebugger();
    851         }
    852     }
    853 }
     888{
     889}
     890
    854891
    855892UIActivityOverviewItem::~UIActivityOverviewItem()
    856893{
    857     if (!m_comSession.isNull())
    858         m_comSession.UnlockMachine();
    859894}
    860895
     
    864899        return true;
    865900    return false;
    866 }
    867 
    868 bool UIActivityOverviewItem::isWithGuestAdditions()
    869 {
    870     if (m_comGuest.isNull())
    871         return false;
    872     return m_comGuest.GetAdditionsStatus(m_comGuest.GetAdditionsRunLevel());
    873901}
    874902
     
    967995    :QAbstractTableModel(parent)
    968996    , m_pTimer(new QTimer(this))
    969     , m_pCloudUpdateTimer(new QTimer(this))
    970997{
    971998    initialize();
     
    9871014        m_pTimer->start(1000);
    9881015    }
    989 
    990     if (m_pCloudUpdateTimer)
    991     {
    992         connect(m_pCloudUpdateTimer, &QTimer::timeout, this, &UIActivityOverviewModel::sltCloudUpdateTimeout);
    993         m_pCloudUpdateTimer->start(10 * 1000);
    994     }
    9951016}
    9961017
     
    10151036        else
    10161037            m_pTimer->stop();
    1017     }
    1018     if (m_pCloudUpdateTimer)
    1019     {
    1020         if (fShouldUpdate)
    1021             m_pCloudUpdateTimer->start();
    1022         else
    1023             m_pCloudUpdateTimer->stop();
    10241038    }
    10251039}
     
    12721286    emit sigDataUpdate();
    12731287    emit sigHostStatsUpdate(m_hostStats);
    1274 }
    1275 
    1276 QVector<CCloudMachine> UIActivityOverviewModel::obtainCloudMachineList()
    1277 {
    1278     QVector<CCloudMachine> cloudMachineList;
    1279     QVector<CCloudClient> cloudClientList = obtainCloudClientList();
    1280     foreach (const CCloudClient &comClient, cloudClientList)
    1281     {
    1282         cloudMachineList << comClient.GetCloudMachineList();
    1283     }
    1284     return cloudMachineList;
    1285 }
    1286 
    1287 QVector<CCloudClient> UIActivityOverviewModel::obtainCloudClientList()
    1288 {
    1289     QVector<CCloudClient> comCloudClients;
    1290     /* Acquire Cloud Profile Manager restrictions: */
    1291     const QStringList restrictions = gEDataManager->cloudProfileManagerRestrictions();
    1292 
    1293     foreach (CCloudProvider comCloudProvider, listCloudProviders())
    1294     {
    1295         /* Skip if we have nothing to populate: */
    1296         if (comCloudProvider.isNull())
    1297             continue;
    1298 
    1299         /* Acquire provider id: */
    1300         QUuid uProviderId;
    1301         if (!cloudProviderId(comCloudProvider, uProviderId))
    1302             continue;
    1303 
    1304         /* Acquire provider short name: */
    1305         QString strProviderShortName;
    1306         if (!cloudProviderShortName(comCloudProvider, strProviderShortName))
    1307             continue;
    1308 
    1309         /* Make sure this provider isn't restricted: */
    1310         const QString strProviderPath = QString("/%1").arg(strProviderShortName);
    1311         if (restrictions.contains(strProviderPath))
    1312             continue;
    1313 
    1314         /* Acquire list of profiles: */
    1315         const QVector<CCloudProfile> profiles = listCloudProfiles(comCloudProvider);
    1316         if (profiles.isEmpty())
    1317             continue;
    1318 
    1319         foreach (CCloudProfile comCloudProfile, profiles)
    1320         {
    1321             /* Skip if we have nothing to populate: */
    1322             if (comCloudProfile.isNull())
    1323                 continue;
    1324 
    1325             /* Acquire profile name: */
    1326             QString strProfileName;
    1327             if (!cloudProfileName(comCloudProfile, strProfileName))
    1328                 continue;
    1329 
    1330             /* Make sure this profile isn't restricted: */
    1331             const QString strProfilePath = QString("/%1/%2").arg(strProviderShortName, strProfileName);
    1332             if (restrictions.contains(strProfilePath))
    1333                 continue;
    1334 
    1335 
    1336             QString strErrorMessage;
    1337             /* Create read cloud machine list task: */
    1338             const UICloudEntityKey cloudProfileKey = UICloudEntityKey(strProviderShortName, strProfileName);
    1339             CCloudClient comCloudClient = cloudClientByName(cloudProfileKey.m_strProviderShortName,
    1340                                                             cloudProfileKey.m_strProfileName,
    1341                                                             strErrorMessage);
    1342             if (strErrorMessage.isEmpty() && comCloudClient.isOk())
    1343                 comCloudClients << comCloudClient;
    1344         }
    1345     }
    1346     return comCloudClients;
    1347 }
    1348 
    1349 void UIActivityOverviewModel::sltCloudUpdateTimeout()
    1350 {
    1351     /* Update the m_items list: This is necessary as we dont have add/remove/change events for cloud machines: */
    1352     QVector<CCloudMachine> cloudMachines = obtainCloudMachineList();
    1353     foreach (const CCloudMachine &comMachine, cloudMachines)
    1354     {
    1355         if (!comMachine.isOk())
    1356             continue;
    1357         UIActivityOverviewItem cloudVMItem(comMachine.GetId(), comMachine.GetName(), true /* cloud vm*/);
    1358         if (m_itemList.contains(cloudVMItem))
    1359             continue;
    1360         m_itemList << cloudVMItem;
    1361     }
    13621288}
    13631289
     
    14691395void UIActivityOverviewModel::addItem(const QUuid& uMachineId, const QString& strMachineName, KMachineState enmState)
    14701396{
    1471     UIActivityOverviewItem newItem(uMachineId, strMachineName);
     1397    UIActivityOverviewItemLocal newItem(uMachineId, strMachineName);
    14721398    newItem.m_enmMachineState = enmState;
    14731399    m_itemList.append(newItem);
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