VirtualBox

Ignore:
Timestamp:
Feb 16, 2007 7:52:29 AM (18 years ago)
Author:
vboxsync
Message:

1758: Implement Shared Folders UI

Shared Folders Dialog now suitable for displaying three types of shared folders – global, machine and console under different root list-views items.

Location:
trunk/src/VBox/Frontends/VirtualBox/ui
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui

    r945 r946  
    183183</includes>
    184184<variables>
     185    <variable access="public">enum SFDialogType { WrongType = 0, GlobalType = 1, MachineType = 2, ConsoleType = 3 };</variable>
    185186    <variable access="private">bool mIsListViewChanged;</variable>
     187    <variable access="private">SFDialogType mDialogType;</variable>
    186188</variables>
    187189<slots>
     
    193195<functions>
    194196    <function access="private">init()</function>
     197    <function>setDialogType( VBoxSharedFoldersSettings::SFDialogType )</function>
     198    <function access="private" returnType="bool">isEditable( const QString &amp; )</function>
    195199    <function>getFromGlobal()</function>
    196200    <function>getFromMachine( const CMachine &amp; )</function>
    197201    <function>getFromConsole( const CConsole &amp; )</function>
    198     <function access="private">getFrom( const CSharedFolderEnumerator &amp; )</function>
     202    <function access="private">getFrom( const CSharedFolderEnumerator &amp;, QListViewItem* )</function>
    199203    <function>putBackToGlobal()</function>
    200204    <function>putBackToMachine( CMachine &amp; )</function>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h

    r945 r946  
    5050
    5151    VBoxRichListItem (FormatType aFormat, QListView *aParent,
    52                       const QString& aLabel1, const QString& aLabel2) :
    53         QListViewItem (aParent, aLabel1, aLabel2), mFormat (aFormat)
    54     {
    55         mTextList << aLabel1 << aLabel2;
     52                      const QString& aName, const QString& aNull,
     53                      const QString& aKey) :
     54        QListViewItem (aParent, aName, aNull, aKey), mFormat (aFormat)
     55    {
     56    }
     57
     58    VBoxRichListItem (FormatType aFormat, QListViewItem *aParent,
     59                      const QString& aName, const QString& aPath) :
     60        QListViewItem (aParent, aName, aPath), mFormat (aFormat)
     61    {
     62        mTextList << aName << aPath;
    5663    }
    5764
     
    7279    {
    7380        QString oneString = mTextList [aColumn];
     81        if (oneString.isEmpty())
     82            return;
    7483        int oldSize = listView()->fontMetrics().width (oneString);
    7584        int indentSize = listView()->fontMetrics().width ("...x");
     
    241250void VBoxSharedFoldersSettings::init()
    242251{
     252    mDialogType = WrongType;
    243253    new QIListViewSelectionPreserver (this, listView);
    244254    listView->setShowToolTips (false);
     
    257267}
    258268
     269void VBoxSharedFoldersSettings::setDialogType (
     270     VBoxSharedFoldersSettings::SFDialogType aType)
     271{
     272    mDialogType = aType;
     273}
     274
    259275
    260276void VBoxSharedFoldersSettings::getFromGlobal()
    261277{
    262     getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate());
     278    QString name = tr (" Global Shared Folders");
     279    QString key ("1");
     280    VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
     281                                                   listView, name, QString::null, key);
     282    getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate(), root);
    263283}
    264284
    265285void VBoxSharedFoldersSettings::getFromMachine (const CMachine &aMachine)
    266286{
    267     getFrom (aMachine.GetSharedFolders().Enumerate());
     287    QString name = tr (" Machine Shared Folders");
     288    QString key ("2");
     289    VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
     290                                                   listView, name, QString::null, key);
     291    getFrom (aMachine.GetSharedFolders().Enumerate(), root);
    268292}
    269293
    270294void VBoxSharedFoldersSettings::getFromConsole (const CConsole &aConsole)
    271295{
    272     getFrom (aConsole.GetSharedFolders().Enumerate());
    273 }
    274 
    275 void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn)
    276 {
     296    QString name = tr (" Transient Shared Folders");
     297    QString key ("3");
     298    VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd,
     299                                                   listView, name, QString::null, key);
     300    getFrom (aConsole.GetSharedFolders().Enumerate(), root);
     301}
     302
     303void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn,
     304                                         QListViewItem *aRoot)
     305{
     306    aRoot->setSelectable (false);
    277307    while (aEn.HasMore())
    278308    {
    279309        CSharedFolder sf = aEn.GetNext();
    280         new VBoxRichListItem (VBoxRichListItem::EllipsisFile, listView,
     310        new VBoxRichListItem (VBoxRichListItem::EllipsisFile, aRoot,
    281311                              sf.GetName(), sf.GetHostPath());
    282312    }
    283     listView->setCurrentItem (listView->firstChild());
    284     processCurrentChanged (listView->firstChild());
     313    listView->setOpen (aRoot, true);
     314    listView->setCurrentItem (aRoot->firstChild());
     315    processCurrentChanged (aRoot->firstChild());
    285316}
    286317
     
    311342    else return;
    312343
    313     /* saving all created list view items */
    314     QListViewItemIterator it (listView);
    315     while (it.current())
     344    /* saving all machine related list view items */
     345        Assert (mDialogType == 2);
     346    QListViewItem *root = listView->findItem (QString::number (mDialogType), 2);
     347    Assert (root);
     348    QListViewItem *iterator = root->firstChild();
     349    while (iterator)
    316350    {
    317351        VBoxRichListItem *item = 0;
    318         if (it.current()->rtti() == VBoxRichListItem::QIRichListItemId)
    319             item = static_cast<VBoxRichListItem*> (it.current());
     352        if (iterator->rtti() == VBoxRichListItem::QIRichListItemId)
     353            item = static_cast<VBoxRichListItem*> (iterator);
    320354        if (item)
    321355        {
     
    328362        else
    329363            AssertMsgFailed (("Incorrect listview item type\n"));
    330         ++it;
     364        iterator = iterator->nextSibling();
    331365    }
    332366}
     
    349383    /* Shared folder's name & path could not be empty */
    350384    Assert (!name.isEmpty() && !path.isEmpty());
    351 
     385    /* Searching root for the new listview item */
     386    QListViewItem *root = listView->findItem (QString::number (mDialogType), 2);
     387    Assert (root);
     388    /* Appending a new listview item to the root */
    352389    VBoxRichListItem *item = new VBoxRichListItem (VBoxRichListItem::EllipsisFile,
    353                                                    listView, name, path);
     390                                                   root, name, path);
    354391    listView->ensureItemVisible (item);
    355392    listView->setCurrentItem (item);
     
    375412    QString tip = tr ("<nobr>Name: %1</nobr><br><nobr>Path: %2</nobr>")
    376413                      .arg (item->getText (0)).arg (item->getText (1));
    377     QToolTip::add (listView->viewport(), listView->itemRect (aItem), tip);
     414    if (!item->getText (0).isEmpty() && !item->getText (1).isEmpty())
     415        QToolTip::add (listView->viewport(), listView->itemRect (aItem), tip);
     416    else
     417        QToolTip::remove (listView->viewport());
    378418}
    379419
     
    382422    if (aItem && listView->selectedItem() != aItem)
    383423        listView->setSelected (aItem, true);
    384     tbRemove->setEnabled (!!aItem);
     424    bool removeEnabled = aItem && aItem->parent();
     425    bool addEnabled = aItem &&
     426                      (isEditable (aItem->text (2)) ||
     427                       aItem->parent() && isEditable (aItem->parent()->text (2)));
     428    tbRemove->setEnabled (removeEnabled);
     429    tbAdd->setEnabled (addEnabled);
     430}
     431
     432bool VBoxSharedFoldersSettings::isEditable (const QString &aKey)
     433{
     434    /* mDialogType should be sutup already */
     435    Assert (mDialogType);
     436    /* simple item has no key information */
     437    if (aKey.isEmpty())
     438        return false;
     439    SFDialogType type = (SFDialogType)aKey.toInt();
     440    if (!type)
     441        AssertMsgFailed (("Incorrect listview item key value\n"));
     442    return type == mDialogType;
    385443}
    386444
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r925 r946  
    490490    QVBoxLayout* pageFoldersLayout = new QVBoxLayout (pageFolders, 0, 10, "pageFoldersLayout");
    491491    mSharedFolders = new VBoxSharedFoldersSettings (pageFolders, "sharedFolders");
     492    mSharedFolders->setDialogType (VBoxSharedFoldersSettings::MachineType);
    492493    pageFoldersLayout->addWidget (mSharedFolders);
    493494
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