VirtualBox

Changeset 42563 in vbox


Ignore:
Timestamp:
Aug 3, 2012 1:42:21 AM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: 6234: Support for VM groups: Items sorting functionality.

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

Legend:

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

    r42542 r42563  
    432432    {
    433433#if defined(Q_WS_MAC)
    434         setText(QApplication::translate("UIActionPool", "Create Alias on Desktop"));
    435         setStatusTip(QApplication::translate("UIActionPool", "Creates an Alias file to the VirtualBox Machine Definition file on your Desktop."));
     434        setText(QApplication::translate("UIActionPool", "Create alias on desktop"));
     435        setStatusTip(QApplication::translate("UIActionPool", "Creates an alias file to the VirtualBox Machine Definition file on your desktop."));
    436436#else
    437         setText(QApplication::translate("UIActionPool", "Create Shortcut on Desktop"));
    438         setStatusTip(QApplication::translate("UIActionPool", "Creates an Shortcut file to the VirtualBox Machine Definition file on your Desktop."));
     437        setText(QApplication::translate("UIActionPool", "Create shortcut on desktop"));
     438        setStatusTip(QApplication::translate("UIActionPool", "Creates an shortcut file to the VirtualBox Machine Definition file on your desktop."));
    439439#endif
    440440        setShortcut(gSS->keySequence(UISelectorShortcuts::CreateVMAliasShortcut));
     
    458458    void retranslateUi()
    459459    {
    460         setText(QApplication::translate("UIActionPool", "Sort List"));
    461         setStatusTip(QApplication::translate("UIActionPool", "Sort the VM list alphabetically (Shift for descending order)"));
    462         setShortcut(gSS->keySequence(UISelectorShortcuts::ResortVMList));
     460        setText(QApplication::translate("UIActionPool", "Sort group"));
     461        setStatusTip(QApplication::translate("UIActionPool", "Sort the items of the selected group alphabetically"));
     462        setShortcut(gSS->keySequence(UISelectorShortcuts::SortGroup));
    463463    }
    464464};
     
    823823};
    824824
    825 class UIActionSimpleMachineSort : public UIActionSimple
    826 {
    827     Q_OBJECT;
    828 
    829 public:
    830 
    831     UIActionSimpleMachineSort(QObject *pParent)
     825class UIActionSimpleCommonSortParent : public UIActionSimple
     826{
     827    Q_OBJECT;
     828
     829public:
     830
     831    UIActionSimpleCommonSortParent(QObject *pParent)
    832832        : UIActionSimple(pParent/*, ":/settings_16px.png", ":/settings_dis_16px.png"*/)
    833833    {
     
    839839    void retranslateUi()
    840840    {
    841         setText(QApplication::translate("UIActionPool", "Sort List"));
    842         setStatusTip(QApplication::translate("UIActionPool", "Sort the VM list alphabetically (Shift for descending order)"));
    843         setShortcut(gSS->keySequence(UISelectorShortcuts::ResortVMList));
     841        setText(QApplication::translate("UIActionPool", "Sort parent group"));
     842        setStatusTip(QApplication::translate("UIActionPool", "Sort the parent group of the first selected item alphabetically"));
     843        setShortcut(gSS->keySequence(UISelectorShortcuts::SortParentGroup));
    844844    }
    845845};
     
    977977    m_pool[UIActionIndexSelector_Simple_Machine_ShowInFileManager] = new UIActionSimpleMachineShowInFileManager(this);
    978978    m_pool[UIActionIndexSelector_Simple_Machine_CreateShortcut] = new UIActionSimpleMachineCreateShortcut(this);
    979     m_pool[UIActionIndexSelector_Simple_Machine_Sort] = new UIActionSimpleMachineSort(this);
     979
     980    /* Common actions: */
     981    m_pool[UIActionIndexSelector_Simple_Common_SortParent] = new UIActionSimpleCommonSortParent(this);
    980982
    981983    /* 'Machine/Close' actions: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UIActionPoolSelector.h

    r42542 r42563  
    6363    UIActionIndexSelector_Simple_Machine_ShowInFileManager,
    6464    UIActionIndexSelector_Simple_Machine_CreateShortcut,
    65     UIActionIndexSelector_Simple_Machine_Sort,
     65
     66    /* Common menu action: */
     67    UIActionIndexSelector_Simple_Common_SortParent,
    6668
    6769    /* 'Machine/Close' menu actions: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorShortcuts.cpp

    r42542 r42563  
    4949    m_Shortcuts[ShowVMInFileManagerShortcut] = UIKeySequence("ShowVMInFileManager");
    5050    m_Shortcuts[CreateVMAliasShortcut]       = UIKeySequence("CreateVMAlias");
    51     m_Shortcuts[ResortVMList]                = UIKeySequence("ResortVMList");
     51    m_Shortcuts[SortParentGroup]             = UIKeySequence("SortParentGroup");
     52    m_Shortcuts[SortGroup]                   = UIKeySequence("SortGroup");
    5253    m_Shortcuts[HelpShortcut]                = UIKeySequence("Help",                QKeySequence::HelpContents);
    5354    m_Shortcuts[WebShortcut]                 = UIKeySequence("Web");
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorShortcuts.h

    r42542 r42563  
    5151        ShowVMInFileManagerShortcut,
    5252        CreateVMAliasShortcut,
    53         ResortVMList,
     53        SortParentGroup,
     54        SortGroup,
    5455        HelpShortcut,
    5556        WebShortcut,
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r42560 r42563  
    11161116    pMenu->addAction(m_pActionGroupCreateShortcut);
    11171117    pMenu->addSeparator();
    1118 //    m_pActionGroupSort = gActionPool->action(UIActionIndexSelector_Simple_Group_Sort);
    1119 //    pMenu->addAction(m_pActionGroupSort);
     1118    m_pActionGroupSortParent = gActionPool->action(UIActionIndexSelector_Simple_Common_SortParent);
     1119    pMenu->addAction(m_pActionGroupSortParent);
     1120    m_pActionGroupSort = gActionPool->action(UIActionIndexSelector_Simple_Group_Sort);
     1121    pMenu->addAction(m_pActionGroupSort);
    11201122
    11211123    /* Remember action list: */
     
    11251127                   << m_pActionGroupReset << m_pActionGroupRefresh
    11261128                   << m_pActionGroupLogDialog << m_pActionGroupShowInFileManager
    1127                    << m_pActionGroupCreateShortcut /* << m_pActionGroupSort */;
     1129                   << m_pActionGroupCreateShortcut << m_pActionGroupSort;
    11281130}
    11291131
     
    11681170    pMenu->addAction(m_pActionMachineCreateShortcut);
    11691171    pMenu->addSeparator();
    1170 //    m_pActionMachineSort = gActionPool->action(UIActionIndexSelector_Simple_Machine_Sort);
    1171 //    pMenu->addAction(m_pActionMachineSort);
     1172    m_pActionMachineSortParent = gActionPool->action(UIActionIndexSelector_Simple_Common_SortParent);
     1173    pMenu->addAction(m_pActionMachineSortParent);
    11721174
    11731175    /* Remember action list: */
     
    11791181                     << m_pActionMachineReset << m_pActionMachineRefresh
    11801182                     << m_pActionMachineLogDialog << m_pActionMachineShowInFileManager
    1181                      << m_pActionMachineCreateShortcut /* << m_pActionMachineSort */;
     1183                     << m_pActionMachineCreateShortcut;
    11821184}
    11831185
     
    15221524    m_pActionGroupShowInFileManager->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_ShowInFileManager, items));
    15231525    m_pActionGroupCreateShortcut->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_CreateShortcut, items));
    1524 //    m_pActionGroupSort->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Sort, items));
     1526    m_pActionGroupSortParent->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Common_SortParent, items));
     1527    m_pActionGroupSort->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Group_Sort, items));
    15251528
    15261529    /* Enable/disable machine actions: */
     
    15371540    m_pActionMachineShowInFileManager->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_ShowInFileManager, items));
    15381541    m_pActionMachineCreateShortcut->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_CreateShortcut, items));
    1539 //    m_pActionMachineSort->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Machine_Sort, items));
     1542    m_pActionMachineSortParent->setEnabled(isActionEnabled(UIActionIndexSelector_Simple_Common_SortParent, items));
    15401543
    15411544    /* Enable/disable machine-close actions: */
     
    17581761        case UIActionIndexSelector_Simple_Group_ShowInFileManager:
    17591762        case UIActionIndexSelector_Simple_Machine_ShowInFileManager:
    1760 //        case UIActionIndexSelector_Simple_Group_Sort:
    1761 //        case UIActionIndexSelector_Simple_Machine_Sort:
    1762 //        {
    1763 //            /* Make sure all items are accessible: */
    1764 //            return isItemsAccessible(items);
    1765 //        }
     1763        case UIActionIndexSelector_Simple_Common_SortParent:
     1764        case UIActionIndexSelector_Simple_Group_Sort:
     1765        {
     1766            /* Make sure all items are accessible: */
     1767            return items.size() > 0 && isItemsAccessible(items);
     1768        }
    17661769        case UIActionIndexSelector_Simple_Group_CreateShortcut:
    17671770        case UIActionIndexSelector_Simple_Machine_CreateShortcut:
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h

    r42560 r42563  
    190190    UIAction *m_pActionGroupShowInFileManager;
    191191    UIAction *m_pActionGroupCreateShortcut;
    192 //    UIAction *m_pActionGroupSort;
     192    UIAction *m_pActionGroupSortParent;
     193    UIAction *m_pActionGroupSort;
    193194
    194195    /* 'Machine' menu action pointers: */
     
    210211    UIAction *m_pActionMachineShowInFileManager;
    211212    UIAction *m_pActionMachineCreateShortcut;
    212 //    UIAction *m_pActionMachineSort;
     213    UIAction *m_pActionMachineSortParent;
    213214
    214215    /* 'Machine / Close' menu action pointers: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItem.h

    r42558 r42563  
    8686    virtual void addItem(UIGChooserItem *pItem, int iPosition) = 0;
    8787    virtual void removeItem(UIGChooserItem *pItem) = 0;
     88    virtual void setItems(const QList<UIGChooserItem*> &items, UIGChooserItemType type) = 0;
    8889    virtual QList<UIGChooserItem*> items(UIGChooserItemType type = UIGChooserItemType_Any) const = 0;
    8990    virtual bool hasItems(UIGChooserItemType type = UIGChooserItemType_Any) const = 0;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.cpp

    r42558 r42563  
    475475}
    476476
     477void UIGChooserItemGroup::setItems(const QList<UIGChooserItem*> &items, UIGChooserItemType type)
     478{
     479    /* Check item type: */
     480    switch (type)
     481    {
     482        case UIGChooserItemType_Group: m_groupItems = items; break;
     483        case UIGChooserItemType_Machine: m_machineItems = items; break;
     484        default: AssertMsgFailed(("Invalid item type!")); break;
     485    }
     486}
     487
    477488QList<UIGChooserItem*> UIGChooserItemGroup::items(UIGChooserItemType type /* = UIGChooserItemType_Any */) const
    478489{
     
    513524        case UIGChooserItemType_Group:
    514525        {
    515             while (!m_groupItems.isEmpty()) { delete m_groupItems.last(); }
     526            while (!m_groupItems.isEmpty()) { delete m_groupItems.takeLast(); }
     527            AssertMsg(m_groupItems.isEmpty(), ("Group items cleanup failed!"));
    516528            break;
    517529        }
    518530        case UIGChooserItemType_Machine:
    519531        {
    520             while (!m_machineItems.isEmpty()) { delete m_machineItems.last(); }
     532            while (!m_machineItems.isEmpty()) { delete m_machineItems.takeLast(); }
     533            AssertMsg(m_machineItems.isEmpty(), ("Machine items cleanup failed!"));
    521534            break;
    522535        }
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemGroup.h

    r42558 r42563  
    117117    void addItem(UIGChooserItem *pItem, int iPosition);
    118118    void removeItem(UIGChooserItem *pItem);
     119    void setItems(const QList<UIGChooserItem*> &items, UIGChooserItemType type);
    119120    QList<UIGChooserItem*> items(UIGChooserItemType type = UIGChooserItemType_Any) const;
    120121    bool hasItems(UIGChooserItemType type = UIGChooserItemType_Any) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.cpp

    r42559 r42563  
    233233
    234234void UIGChooserItemMachine::removeItem(UIGChooserItem*)
     235{
     236    AssertMsgFailed(("Machine graphics item do NOT support children!"));
     237}
     238
     239void UIGChooserItemMachine::setItems(const QList<UIGChooserItem*>&, UIGChooserItemType)
    235240{
    236241    AssertMsgFailed(("Machine graphics item do NOT support children!"));
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserItemMachine.h

    r42558 r42563  
    9898    void addItem(UIGChooserItem *pItem, int iPosition);
    9999    void removeItem(UIGChooserItem *pItem);
     100    void setItems(const QList<UIGChooserItem*> &items, UIGChooserItemType type);
    100101    QList<UIGChooserItem*> items(UIGChooserItemType type) const;
    101102    bool hasItems(UIGChooserItemType type) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r42547 r42563  
    769769}
    770770
     771void UIGChooserModel::sltSortParentGroup()
     772{
     773    if (!selectionList().isEmpty())
     774        sortItems(selectionList().first()->parentItem());
     775}
     776
     777void UIGChooserModel::sltSortGroup()
     778{
     779    if (singleGroupSelected())
     780        sortItems(selectionList().first());
     781}
     782
    771783QVariant UIGChooserModel::data(int iKey) const
    772784{
     
    814826    m_pContextMenuGroup->addAction(gActionPool->action(UIActionIndexSelector_Simple_Group_ShowInFileManager));
    815827    m_pContextMenuGroup->addAction(gActionPool->action(UIActionIndexSelector_Simple_Group_CreateShortcut));
    816 //    m_pContextMenuGroup->addSeparator();
    817 //    m_pContextMenuGroup->addAction(gActionPool->action(UIActionIndexSelector_Simple_Group_Sort));
     828    m_pContextMenuGroup->addSeparator();
     829    m_pContextMenuGroup->addAction(gActionPool->action(UIActionIndexSelector_Simple_Common_SortParent));
     830    m_pContextMenuGroup->addAction(gActionPool->action(UIActionIndexSelector_Simple_Group_Sort));
    818831
    819832    /* Context menu for machine(s): */
     
    835848    m_pContextMenuMachine->addAction(gActionPool->action(UIActionIndexSelector_Simple_Machine_ShowInFileManager));
    836849    m_pContextMenuMachine->addAction(gActionPool->action(UIActionIndexSelector_Simple_Machine_CreateShortcut));
    837 //    m_pContextMenuMachine->addSeparator();
    838 //    m_pContextMenuMachine->addAction(gActionPool->action(UIActionIndexSelector_Simple_Machine_Sort));
     850    m_pContextMenuMachine->addSeparator();
     851    m_pContextMenuMachine->addAction(gActionPool->action(UIActionIndexSelector_Simple_Common_SortParent));
    839852
    840853    connect(m_pContextMenuRoot, SIGNAL(hovered(QAction*)), this, SLOT(sltActionHovered(QAction*)));
     
    850863    connect(gActionPool->action(UIActionIndexSelector_Simple_Machine_RemoveDialog), SIGNAL(triggered()),
    851864            this, SLOT(sltRemoveCurrentlySelectedMachine()));
     865    connect(gActionPool->action(UIActionIndexSelector_Simple_Common_SortParent), SIGNAL(triggered()),
     866            this, SLOT(sltSortParentGroup()));
     867    connect(gActionPool->action(UIActionIndexSelector_Simple_Group_Sort), SIGNAL(triggered()),
     868            this, SLOT(sltSortGroup()));
    852869}
    853870
     
    16061623}
    16071624
     1625void UIGChooserModel::sortItems(UIGChooserItem *pParent, bool fRecursively /* = false */)
     1626{
     1627    /* Sort group items: */
     1628    QMap<QString, UIGChooserItem*> sorter;
     1629    foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Group))
     1630    {
     1631        sorter.insert(pItem->name().toLower(), pItem);
     1632        if (fRecursively)
     1633            sortItems(pItem, fRecursively);
     1634    }
     1635    pParent->setItems(sorter.values(), UIGChooserItemType_Group);
     1636
     1637    /* Sort machine items: */
     1638    sorter.clear();
     1639    foreach (UIGChooserItem *pItem, pParent->items(UIGChooserItemType_Machine))
     1640        sorter.insert(pItem->name().toLower(), pItem);
     1641    pParent->setItems(sorter.values(), UIGChooserItemType_Machine);
     1642
     1643    /* Update model: */
     1644    updateNavigation();
     1645    updateLayout();
     1646}
     1647
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.h

    r42547 r42563  
    177177    void sltSlidingComplete();
    178178
     179    /* Handlers: Sorting stuff: */
     180    void sltSortParentGroup();
     181    void sltSortGroup();
     182
    179183private:
    180184
     
    257261    void removeMachineItems(const QStringList &names, QList<UIGChooserItem*> &selectedItems);
    258262    void unregisterMachines(const QStringList &names);
     263
     264    /* Helper: Sorting stuff: */
     265    void sortItems(UIGChooserItem *pParent, bool fRecursively = false);
    259266
    260267    /* Variables: */
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