VirtualBox

Changeset 65682 in vbox for trunk


Ignore:
Timestamp:
Feb 8, 2017 2:47:56 PM (8 years ago)
Author:
vboxsync
Message:

FE/Qt: Global preferences: Extension page: Integrate settings caching.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/settings/global
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.cpp

    r65678 r65682  
    4545
    4646    /* Extension package item constructor: */
    47     UIExtensionPackageItem(QITreeWidget *pParent, const UISettingsCacheGlobalExtensionItem &data)
     47    UIExtensionPackageItem(QITreeWidget *pParent, const UIDataSettingsGlobalExtensionItem &data)
    4848        : QITreeWidgetItem(pParent)
    4949        , m_data(data)
     
    9494private:
    9595
    96     UISettingsCacheGlobalExtensionItem m_data;
     96    UIDataSettingsGlobalExtensionItem m_data;
    9797};
    9898
     
    242242    UISettingsPageGlobal::fetchData(data);
    243243
    244     /* Load to cache: */
     244    /* Clear cache initially: */
     245    m_cache.clear();
     246
     247    /* Prepare old data: */
     248    UIDataSettingsGlobalExtension oldData;
     249
     250    /* Gather old data: */
    245251    const CExtPackManager &manager = vboxGlobal().virtualBox().GetExtensionPackManager();
    246252    const CExtPackVector &packages = manager.GetInstalledExtPacks();
    247253    for (int i = 0; i < packages.size(); ++i)
    248         m_cache.m_items << fetchData(packages[i]);
     254        oldData.m_items << fetchData(packages[i]);
     255
     256    /* Cache old data: */
     257    m_cache.cacheInitialData(oldData);
    249258
    250259    /* Upload properties & settings to data: */
     
    254263void UIGlobalSettingsExtension::getFromCache()
    255264{
    256     /* Fetch from cache: */
    257     for (int i = 0; i < m_cache.m_items.size(); ++i)
    258         new UIExtensionPackageItem(m_pPackagesTree, m_cache.m_items[i]);
     265    /* Get old/new data from cache: */
     266    m_data = m_cache.base();
     267
     268    /* Load old data from cache: */
     269    for (int i = 0; i < m_data.m_items.size(); ++i)
     270        new UIExtensionPackageItem(m_pPackagesTree, m_data.m_items[i]);
    259271    /* If at least one item present: */
    260272    if (m_pPackagesTree->topLevelItemCount())
     
    366378        {
    367379            /* Remove it from the cache. */
    368             for (int i = 0; i < m_cache.m_items.size(); i++)
    369                 if (!strExtPackName.compare(m_cache.m_items[i].m_strName, Qt::CaseInsensitive))
     380            for (int i = 0; i < m_data.m_items.size(); i++)
     381                if (!strExtPackName.compare(m_data.m_items[i].m_strName, Qt::CaseInsensitive))
    370382                {
    371                     m_cache.m_items.removeAt(i);
     383                    m_data.m_items.removeAt(i);
    372384                    break;
    373385                }
     
    390402            if (package.isOk())
    391403            {
    392                 m_cache.m_items << fetchData(package);
    393 
    394                 UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pPackagesTree, m_cache.m_items.last());
     404                m_data.m_items << fetchData(package);
     405
     406                UIExtensionPackageItem *pItem = new UIExtensionPackageItem(m_pPackagesTree, m_data.m_items.last());
    395407                m_pPackagesTree->setCurrentItem(pItem);
    396408                m_pPackagesTree->sortByColumn(1, Qt::AscendingOrder);
     
    433445                {
    434446                    /* Remove selected package from cache: */
    435                     for (int i = 0; i < m_cache.m_items.size(); ++i)
     447                    for (int i = 0; i < m_data.m_items.size(); ++i)
    436448                    {
    437                         if (!strSelectedPackageName.compare(m_cache.m_items[i].m_strName, Qt::CaseInsensitive))
     449                        if (!strSelectedPackageName.compare(m_data.m_items[i].m_strName, Qt::CaseInsensitive))
    438450                        {
    439                             m_cache.m_items.removeAt(i);
     451                            m_data.m_items.removeAt(i);
    440452                            break;
    441453                        }
     
    453465}
    454466
    455 UISettingsCacheGlobalExtensionItem UIGlobalSettingsExtension::fetchData(const CExtPack &package) const
    456 {
    457     UISettingsCacheGlobalExtensionItem item;
     467UIDataSettingsGlobalExtensionItem UIGlobalSettingsExtension::fetchData(const CExtPack &package) const
     468{
     469    UIDataSettingsGlobalExtensionItem item;
    458470    item.m_strName = package.GetName();
    459471    item.m_strDescription = package.GetDescription();
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsExtension.h

    r65678 r65682  
    2424
    2525
    26 /** Global settings: Extension page item cache structure. */
    27 struct UISettingsCacheGlobalExtensionItem
     26/** Global settings: Extension page item data structure. */
     27struct UIDataSettingsGlobalExtensionItem
    2828{
     29    /** Constructs data. */
     30    UIDataSettingsGlobalExtensionItem()
     31        : m_strName(QString())
     32        , m_strDescription(QString())
     33        , m_strVersion(QString())
     34        , m_uRevision(0)
     35        , m_fIsUsable(false)
     36        , m_strWhyUnusable(QString())
     37    {}
     38
     39    /** Returns whether the @a other passed data is equal to this one. */
     40    bool equal(const UIDataSettingsGlobalExtensionItem &other) const
     41    {
     42        return true
     43               && (m_strName == other.m_strName)
     44               && (m_strDescription == other.m_strDescription)
     45               && (m_strVersion == other.m_strVersion)
     46               && (m_uRevision == other.m_uRevision)
     47               && (m_fIsUsable == other.m_fIsUsable)
     48               && (m_strWhyUnusable == other.m_strWhyUnusable)
     49               ;
     50    }
     51
     52    /** Returns whether the @a other passed data is equal to this one. */
     53    bool operator==(const UIDataSettingsGlobalExtensionItem &other) const { return equal(other); }
     54    /** Returns whether the @a other passed data is different from this one. */
     55    bool operator!=(const UIDataSettingsGlobalExtensionItem &other) const { return !equal(other); }
     56
    2957    /** Holds the extension item name. */
    3058    QString m_strName;
     
    4270
    4371
    44 /** Global settings: Extension page cache structure. */
    45 struct UISettingsCacheGlobalExtension
     72/** Global settings: Extension page data structure. */
     73struct UIDataSettingsGlobalExtension
    4674{
     75    /** Constructs data. */
     76    UIDataSettingsGlobalExtension()
     77        : m_items(QList<UIDataSettingsGlobalExtensionItem>())
     78    {}
     79
     80    /** Returns whether the @a other passed data is equal to this one. */
     81    bool equal(const UIDataSettingsGlobalExtension &other) const
     82    {
     83        return true
     84               && (m_items == other.m_items)
     85               ;
     86    }
     87
     88    /** Returns whether the @a other passed data is equal to this one. */
     89    bool operator==(const UIDataSettingsGlobalExtension &other) const { return equal(other); }
     90    /** Returns whether the @a other passed data is different from this one. */
     91    bool operator!=(const UIDataSettingsGlobalExtension &other) const { return !equal(other); }
     92
    4793    /** Holds the extension items. */
    48     QList<UISettingsCacheGlobalExtensionItem> m_items;
     94    QList<UIDataSettingsGlobalExtensionItem> m_items;
    4995};
     96typedef UISettingsCache<UIDataSettingsGlobalExtension> UISettingsCacheGlobalExtension;
    5097
    5198
     
    96143private:
    97144
    98     /* Prepare UISettingsCacheGlobalExtensionItem basing on CExtPack: */
    99     UISettingsCacheGlobalExtensionItem fetchData(const CExtPack &package) const;
     145    /* Prepare UIDataSettingsGlobalExtensionItem basing on CExtPack: */
     146    UIDataSettingsGlobalExtensionItem fetchData(const CExtPack &package) const;
    100147
    101148    /* Variables: Actions: */
     
    105152    /* Cache: */
    106153    UISettingsCacheGlobalExtension m_cache;
     154    UIDataSettingsGlobalExtension m_data;
    107155};
    108156
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