VirtualBox

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


Ignore:
Timestamp:
Aug 27, 2012 5:35:33 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: 6234: Support for VM groups: Save VM groups order on-the-fly in parallel thread (extra-data).

Location:
trunk/src/VBox/Frontends/VirtualBox/src/selector
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r42945 r43005  
    14511451    connect(m_pChooser, SIGNAL(sigToggleStarted()), m_pDetails, SIGNAL(sigToggleStarted()));
    14521452    connect(m_pChooser, SIGNAL(sigToggleFinished()), m_pDetails, SIGNAL(sigToggleFinished()));
    1453     connect(m_pChooser, SIGNAL(sigGroupSavingStarted()), this, SLOT(sltGroupSavingUpdate()));
    1454     connect(m_pChooser, SIGNAL(sigGroupSavingFinished()), this, SLOT(sltGroupSavingUpdate()));
     1453    connect(m_pChooser, SIGNAL(sigGroupSavingStateChanged()), this, SLOT(sltGroupSavingUpdate()));
    14551454
    14561455    /* Tool-bar connections: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooser.cpp

    r42882 r43005  
    126126    connect(m_pChooserModel, SIGNAL(sigToggleStarted()), this, SIGNAL(sigToggleStarted()));
    127127    connect(m_pChooserModel, SIGNAL(sigToggleFinished()), this, SIGNAL(sigToggleFinished()));
    128     connect(m_pChooserModel, SIGNAL(sigGroupSavingStarted()), this, SIGNAL(sigGroupSavingStarted()));
    129     connect(m_pChooserModel, SIGNAL(sigGroupSavingFinished()), this, SIGNAL(sigGroupSavingFinished()));
     128    connect(m_pChooserModel, SIGNAL(sigGroupSavingStateChanged()), this, SIGNAL(sigGroupSavingStateChanged()));
    130129    connect(m_pChooserModel, SIGNAL(sigFocusChanged(UIGChooserItem*)), m_pChooserView, SLOT(sltFocusChanged(UIGChooserItem*)));
    131130
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooser.h

    r42734 r43005  
    5050    void sigToggleFinished();
    5151
    52     /* Notifiers: Group saving stuff: */
    53     void sigGroupSavingStarted();
    54     void sigGroupSavingFinished();
     52    /* Notifier: Group saving stuff: */
     53    void sigGroupSavingStateChanged();
    5554
    5655public:
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r42998 r43005  
    553553bool UIGChooserModel::isGroupSavingInProgress() const
    554554{
    555     return UIGroupsSavingThread::instance();
     555    return UIGroupDefinitionSaveThread::instance() ||
     556           UIGroupOrderSaveThread::instance();
    556557}
    557558
     
    977978void UIGChooserModel::sltGroupSavingStart()
    978979{
    979     saveGroupTree();
    980 }
    981 
    982 void UIGChooserModel::sltGroupSavingComplete()
    983 {
    984     makeSureGroupSavingIsFinished();
    985     emit sigGroupSavingFinished();
     980    saveGroupDefinitions();
     981    saveGroupOrders();
     982}
     983
     984void UIGChooserModel::sltGroupDefinitionsSaveComplete()
     985{
     986    makeSureGroupDefinitionsSaveIsFinished();
     987    emit sigGroupSavingStateChanged();
     988}
     989
     990void UIGChooserModel::sltGroupOrdersSaveComplete()
     991{
     992    makeSureGroupOrdersSaveIsFinished();
     993    emit sigGroupSavingStateChanged();
    986994}
    987995
     
    11101118void UIGChooserModel::cleanupGroupTree()
    11111119{
    1112     makeSureGroupSavingIsFinished();
    1113     saveGroupsOrder();
     1120    makeSureGroupDefinitionsSaveIsFinished();
     1121    makeSureGroupOrdersSaveIsFinished();
    11141122}
    11151123
     
    14711479}
    14721480
    1473 void UIGChooserModel::saveGroupTree()
    1474 {
    1475     /* Make sure there is no group saving activity: */
    1476     if (UIGroupsSavingThread::instance())
     1481void UIGChooserModel::saveGroupDefinitions()
     1482{
     1483    /* Make sure there is no group save activity: */
     1484    if (UIGroupDefinitionSaveThread::instance())
    14771485        return;
    14781486
    14791487    /* Prepare full group map: */
    14801488    QMap<QString, QStringList> groups;
    1481     gatherGroupTree(groups, mainRoot());
     1489    gatherGroupDefinitions(groups, mainRoot());
    14821490
    14831491    /* Save information in other thread: */
    1484     UIGroupsSavingThread::prepare();
    1485     emit sigGroupSavingStarted();
    1486     UIGroupsSavingThread::instance()->configure(this, m_groups, groups);
    1487     UIGroupsSavingThread::instance()->start();
     1492    UIGroupDefinitionSaveThread::prepare();
     1493    emit sigGroupSavingStateChanged();
     1494    UIGroupDefinitionSaveThread::instance()->configure(this, m_groups, groups);
     1495    UIGroupDefinitionSaveThread::instance()->start();
    14881496    m_groups = groups;
    14891497}
    14901498
    1491 void UIGChooserModel::saveGroupsOrder()
    1492 {
    1493     /* Clear all the extra-data records related to group-definitions: */
    1494     const QVector<QString> extraDataKeys = vboxGlobal().virtualBox().GetExtraDataKeys();
    1495     foreach (const QString &strKey, extraDataKeys)
    1496         if (strKey.startsWith(UIDefs::GUI_GroupDefinitions))
    1497             vboxGlobal().virtualBox().SetExtraData(strKey, QString());
    1498     /* Save order starting from the root-item: */
    1499     saveGroupsOrder(mainRoot());
    1500 }
    1501 
    1502 void UIGChooserModel::saveGroupsOrder(UIGChooserItem *pParentItem)
    1503 {
    1504     /* Prepare extra-data key for current group: */
    1505     QString strExtraDataKey = UIDefs::GUI_GroupDefinitions + fullName(pParentItem);
    1506     /* Gather item order: */
    1507     QStringList order;
    1508     foreach (UIGChooserItem *pItem, pParentItem->items(UIGChooserItemType_Group))
    1509     {
    1510         saveGroupsOrder(pItem);
    1511         QString strGroupDescriptor(pItem->toGroupItem()->opened() ? "go" : "gc");
    1512         order << QString("%1=%2").arg(strGroupDescriptor, pItem->name());
    1513     }
    1514     foreach (UIGChooserItem *pItem, pParentItem->items(UIGChooserItemType_Machine))
    1515         order << QString("m=%1").arg(pItem->toMachineItem()->id());
    1516     vboxGlobal().virtualBox().SetExtraDataStringList(strExtraDataKey, order);
    1517 }
    1518 
    1519 void UIGChooserModel::gatherGroupTree(QMap<QString, QStringList> &groups,
    1520                                       UIGChooserItem *pParentGroup)
     1499void UIGChooserModel::saveGroupOrders()
     1500{
     1501    /* Make sure there is no group save activity: */
     1502    if (UIGroupOrderSaveThread::instance())
     1503        return;
     1504
     1505    /* Prepare full group map: */
     1506    QMap<QString, QStringList> groups;
     1507    gatherGroupOrders(groups, mainRoot());
     1508
     1509    /* Save information in other thread: */
     1510    UIGroupOrderSaveThread::prepare();
     1511    emit sigGroupSavingStateChanged();
     1512    UIGroupOrderSaveThread::instance()->configure(this, groups);
     1513    UIGroupOrderSaveThread::instance()->start();
     1514}
     1515
     1516void UIGChooserModel::gatherGroupDefinitions(QMap<QString, QStringList> &groups,
     1517                                             UIGChooserItem *pParentGroup)
    15211518{
    15221519    /* Iterate over all the machine items: */
     
    15271524    /* Iterate over all the group items: */
    15281525    foreach (UIGChooserItem *pItem, pParentGroup->items(UIGChooserItemType_Group))
    1529         gatherGroupTree(groups, pItem);
     1526        gatherGroupDefinitions(groups, pItem);
     1527}
     1528
     1529void UIGChooserModel::gatherGroupOrders(QMap<QString, QStringList> &groups,
     1530                                        UIGChooserItem *pParentItem)
     1531{
     1532    /* Prepare extra-data key for current group: */
     1533    QString strExtraDataKey = UIDefs::GUI_GroupDefinitions + fullName(pParentItem);
     1534    /* Iterate over all the group items: */
     1535    foreach (UIGChooserItem *pItem, pParentItem->items(UIGChooserItemType_Group))
     1536    {
     1537        QString strGroupDescriptor(pItem->toGroupItem()->opened() ? "go" : "gc");
     1538        groups[strExtraDataKey] << QString("%1=%2").arg(strGroupDescriptor, pItem->name());
     1539        gatherGroupOrders(groups, pItem);
     1540    }
     1541    /* Iterate over all the machine items: */
     1542    foreach (UIGChooserItem *pItem, pParentItem->items(UIGChooserItemType_Machine))
     1543        groups[strExtraDataKey] << QString("m=%1").arg(pItem->toMachineItem()->id());
    15301544}
    15311545
     
    19011915}
    19021916
    1903 void UIGChooserModel::makeSureGroupSavingIsFinished()
    1904 {
    1905     /* Nothing to do if thread is null: */
    1906     if (!UIGroupsSavingThread::instance())
    1907         return;
    1908 
    1909     /* Cleanup thread otherwise: */
    1910     UIGroupsSavingThread::cleanup();
     1917void UIGChooserModel::makeSureGroupDefinitionsSaveIsFinished()
     1918{
     1919    /* Cleanup if necessary: */
     1920    if (UIGroupDefinitionSaveThread::instance())
     1921        UIGroupDefinitionSaveThread::cleanup();
     1922}
     1923
     1924void UIGChooserModel::makeSureGroupOrdersSaveIsFinished()
     1925{
     1926    /* Cleanup if necessary: */
     1927    if (UIGroupOrderSaveThread::instance())
     1928        UIGroupOrderSaveThread::cleanup();
    19111929}
    19121930
     
    19301948
    19311949/* static */
    1932 UIGroupsSavingThread* UIGroupsSavingThread::m_spInstance = 0;
     1950UIGroupDefinitionSaveThread* UIGroupDefinitionSaveThread::m_spInstance = 0;
    19331951
    19341952/* static */
    1935 UIGroupsSavingThread* UIGroupsSavingThread::instance()
     1953UIGroupDefinitionSaveThread* UIGroupDefinitionSaveThread::instance()
    19361954{
    19371955    return m_spInstance;
     
    19391957
    19401958/* static */
    1941 void UIGroupsSavingThread::prepare()
     1959void UIGroupDefinitionSaveThread::prepare()
    19421960{
    19431961    /* Make sure instance not prepared: */
     
    19461964
    19471965    /* Crate instance: */
    1948     new UIGroupsSavingThread;
     1966    new UIGroupDefinitionSaveThread;
    19491967}
    19501968
    19511969/* static */
    1952 void UIGroupsSavingThread::cleanup()
     1970void UIGroupDefinitionSaveThread::cleanup()
    19531971{
    19541972    /* Make sure instance prepared: */
     
    19601978}
    19611979
    1962 void UIGroupsSavingThread::configure(QObject *pParent,
    1963                                      const QMap<QString, QStringList> &oldLists,
    1964                                      const QMap<QString, QStringList> &newLists)
     1980void UIGroupDefinitionSaveThread::configure(QObject *pParent,
     1981                                            const QMap<QString, QStringList> &oldLists,
     1982                                            const QMap<QString, QStringList> &newLists)
    19651983{
    19661984    m_oldLists = oldLists;
    19671985    m_newLists = newLists;
    1968     connect(this, SIGNAL(sigComplete()), pParent, SLOT(sltGroupSavingComplete()));
    1969 }
    1970 
    1971 void UIGroupsSavingThread::sltHandleError(UIGroupsSavingError errorType, const CMachine &machine)
     1986    connect(this, SIGNAL(sigComplete()), pParent, SLOT(sltGroupDefinitionsSaveComplete()));
     1987}
     1988
     1989void UIGroupDefinitionSaveThread::sltHandleError(UIGroupsSavingError errorType, const CMachine &machine)
    19721990{
    19731991    switch (errorType)
     
    19882006}
    19892007
    1990 UIGroupsSavingThread::UIGroupsSavingThread()
     2008UIGroupDefinitionSaveThread::UIGroupDefinitionSaveThread()
    19912009{
    19922010    /* Assign instance: */
     
    19992017}
    20002018
    2001 UIGroupsSavingThread::~UIGroupsSavingThread()
     2019UIGroupDefinitionSaveThread::~UIGroupDefinitionSaveThread()
    20022020{
    20032021    /* Wait: */
     
    20082026}
    20092027
    2010 void UIGroupsSavingThread::run()
     2028void UIGroupDefinitionSaveThread::run()
    20112029{
    20122030    /* Lock other thread mutex: */
     
    20852103}
    20862104
     2105/* static */
     2106UIGroupOrderSaveThread* UIGroupOrderSaveThread::m_spInstance = 0;
     2107
     2108/* static */
     2109UIGroupOrderSaveThread* UIGroupOrderSaveThread::instance()
     2110{
     2111    return m_spInstance;
     2112}
     2113
     2114/* static */
     2115void UIGroupOrderSaveThread::prepare()
     2116{
     2117    /* Make sure instance not prepared: */
     2118    if (m_spInstance)
     2119        return;
     2120
     2121    /* Crate instance: */
     2122    new UIGroupOrderSaveThread;
     2123}
     2124
     2125/* static */
     2126void UIGroupOrderSaveThread::cleanup()
     2127{
     2128    /* Make sure instance prepared: */
     2129    if (!m_spInstance)
     2130        return;
     2131
     2132    /* Crate instance: */
     2133    delete m_spInstance;
     2134}
     2135
     2136void UIGroupOrderSaveThread::configure(QObject *pParent,
     2137                                       const QMap<QString, QStringList> &groups)
     2138{
     2139    m_groups = groups;
     2140    connect(this, SIGNAL(sigComplete()), pParent, SLOT(sltGroupOrdersSaveComplete()));
     2141}
     2142
     2143UIGroupOrderSaveThread::UIGroupOrderSaveThread()
     2144{
     2145    /* Assign instance: */
     2146    m_spInstance = this;
     2147}
     2148
     2149UIGroupOrderSaveThread::~UIGroupOrderSaveThread()
     2150{
     2151    /* Wait: */
     2152    wait();
     2153
     2154    /* Erase instance: */
     2155    m_spInstance = 0;
     2156}
     2157
     2158void UIGroupOrderSaveThread::run()
     2159{
     2160    /* COM prepare: */
     2161    COMBase::InitializeCOM(false);
     2162
     2163    /* Clear all the extra-data records related to group-definitions: */
     2164    const QVector<QString> extraDataKeys = vboxGlobal().virtualBox().GetExtraDataKeys();
     2165    foreach (const QString &strKey, extraDataKeys)
     2166        if (strKey.startsWith(UIDefs::GUI_GroupDefinitions))
     2167            vboxGlobal().virtualBox().SetExtraData(strKey, QString());
     2168
     2169    /* For every particular group definition: */
     2170    foreach (const QString &strId, m_groups.keys())
     2171        vboxGlobal().virtualBox().SetExtraDataStringList(strId, m_groups[strId]);
     2172
     2173    /* Notify listeners about completeness: */
     2174    emit sigComplete();
     2175
     2176    /* COM cleanup: */
     2177    COMBase::CleanupCOM();
     2178}
     2179
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r42998 r43005  
    8585    /* Notifiers: Group saving stuff: */
    8686    void sigStartGroupSaving();
    87     void sigGroupSavingStarted();
    88     void sigGroupSavingFinished();
     87    void sigGroupSavingStateChanged();
    8988
    9089public:
     
    213212    /* Handlers: Group saving stuff: */
    214213    void sltGroupSavingStart();
    215     void sltGroupSavingComplete();
     214    void sltGroupDefinitionsSaveComplete();
     215    void sltGroupOrdersSaveComplete();
    216216
    217217    /* Handler: Lookup stuff: */
     
    266266    void createMachineItem(const CMachine &machine, UIGChooserItem *pParentItem);
    267267
    268     /* Helpers: Saving: */
    269     void saveGroupTree();
    270     void saveGroupsOrder();
    271     void saveGroupsOrder(UIGChooserItem *pParentItem);
    272     void gatherGroupTree(QMap<QString, QStringList> &groups, UIGChooserItem *pParentGroup);
     268    /* Helpers: Group saving stuff: */
     269    void saveGroupDefinitions();
     270    void saveGroupOrders();
     271    void gatherGroupDefinitions(QMap<QString, QStringList> &groups, UIGChooserItem *pParentGroup);
     272    void gatherGroupOrders(QMap<QString, QStringList> &groups, UIGChooserItem *pParentItem);
    273273    QString fullName(UIGChooserItem *pItem);
    274274
     
    307307    void sortItems(UIGChooserItem *pParent, bool fRecursively = false);
    308308
    309     /* Helper: Group saving stuff: */
    310     void makeSureGroupSavingIsFinished();
     309    /* Helpers: Group saving stuff: */
     310    void makeSureGroupDefinitionsSaveIsFinished();
     311    void makeSureGroupOrdersSaveIsFinished();
    311312
    312313    /* Helper: Lookup stuff: */
     
    339340};
    340341
    341 /* Represents group-saving error types: */
     342/* Represents group definitions save error types: */
    342343enum UIGroupsSavingError
    343344{
     
    348349Q_DECLARE_METATYPE(UIGroupsSavingError);
    349350
    350 /* Allows to save group settings asynchronously: */
    351 class UIGroupsSavingThread : public QThread
     351/* Allows to save group definitions asynchronously: */
     352class UIGroupDefinitionSaveThread : public QThread
    352353{
    353354    Q_OBJECT;
     
    364365
    365366    /* Singleton stuff: */
    366     static UIGroupsSavingThread* instance();
     367    static UIGroupDefinitionSaveThread* instance();
    367368    static void prepare();
    368369    static void cleanup();
     
    381382
    382383    /* Constructor/destructor: */
    383     UIGroupsSavingThread();
    384     ~UIGroupsSavingThread();
     384    UIGroupDefinitionSaveThread();
     385    ~UIGroupDefinitionSaveThread();
    385386
    386387    /* Worker thread stuff: */
     
    388389
    389390    /* Variables: */
    390     static UIGroupsSavingThread *m_spInstance;
     391    static UIGroupDefinitionSaveThread *m_spInstance;
    391392    QMap<QString, QStringList> m_oldLists;
    392393    QMap<QString, QStringList> m_newLists;
     
    395396};
    396397
     398/* Allows to save group order asynchronously: */
     399class UIGroupOrderSaveThread : public QThread
     400{
     401    Q_OBJECT;
     402
     403signals:
     404
     405    /* Notifier: Complete stuff: */
     406    void sigComplete();
     407
     408public:
     409
     410    /* Singleton stuff: */
     411    static UIGroupOrderSaveThread* instance();
     412    static void prepare();
     413    static void cleanup();
     414
     415    /* API: Configuring stuff: */
     416    void configure(QObject *pParent, const QMap<QString, QStringList> &groups);
     417
     418private:
     419
     420    /* Constructor/destructor: */
     421    UIGroupOrderSaveThread();
     422    ~UIGroupOrderSaveThread();
     423
     424    /* Worker thread stuff: */
     425    void run();
     426
     427    /* Variables: */
     428    static UIGroupOrderSaveThread *m_spInstance;
     429    QMap<QString, QStringList> m_groups;
     430};
     431
    397432#endif /* __UIGChooserModel_h__ */
    398433
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