VirtualBox

Ignore:
Timestamp:
Jul 24, 2007 9:12:30 AM (17 years ago)
Author:
vboxsync
Message:

2130: Improve Shared Folders UI:

Shared Folders Dialog improvements done:

  1. Dialog made modal (all the title buttons made like in non-modal VDM).
  2. [Help]....[Ok][Cancel] dialog's button configuration.
  3. Permanent shared folder could be created during VM session runtime (through the discussed check-box).
  4. Edit action opens on list-view's item double-click.

Note: Also all the GUI_ constants from the different *.cpp files moved into VBoxDefs.cpp

File:
1 edited

Legend:

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

    r2981 r3802  
    154154public:
    155155
    156     enum DialogType { AddDType, EditDType };
    157 
    158     VBoxAddSFDialog (QWidget *aParent, VBoxAddSFDialog::DialogType aType) :
     156    enum DialogType { AddDialogType, EditDialogType };
     157
     158    VBoxAddSFDialog (QWidget *aParent, VBoxAddSFDialog::DialogType aType,
     159                     bool aEnableSelector /* for "permanent" checkbox */) :
    159160        QDialog (aParent, "VBoxAddSFDialog", true /* modal */),
    160         mLePath (0), mLeName (0)
     161        mLePath (0), mLeName (0), mCbPermanent (0)
    161162    {
    162163        switch (aType)
    163164        {
    164             case AddDType:
     165            case AddDialogType:
    165166                setCaption (tr ("Add Share"));
    166167                break;
    167             case EditDType:
     168            case EditDialogType:
    168169                setCaption (tr ("Edit Share"));
    169170                break;
     
    174175
    175176        /* Setup Input layout */
    176         QGridLayout *inputLayout = new QGridLayout (mainLayout, 2, 3, 10, "inputLayout");
     177        QGridLayout *inputLayout = new QGridLayout (mainLayout, 3, 3, 10, "inputLayout");
    177178        QLabel *lbPath = new QLabel (tr ("Folder Path"), this);
    178179        mLePath = new QLineEdit (this);
     
    199200        inputLayout->addMultiCellWidget (mLeName, 1, 1, 1, 2);
    200201
     202        if (aEnableSelector)
     203        {
     204            mCbPermanent = new QCheckBox ("&Make Permanent", this);
     205            mCbPermanent->setChecked (true);
     206            inputLayout->addMultiCellWidget (mCbPermanent, 2, 2, 0, 2);
     207        }
     208
    201209        /* Setup Button layout */
    202210        QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout");
     
    219227    QString getPath() { return mLePath->text(); }
    220228    QString getName() { return mLeName->text(); }
     229    bool getPermanent()
     230    {
     231        return mCbPermanent ? mCbPermanent->isChecked() : true;
     232    }
    221233
    222234    void setPath (const QString &aPath) { mLePath->setText (aPath); }
    223235    void setName (const QString &aName) { mLeName->setText (aName); }
     236    void setPermanent (bool aPermanent)
     237    {
     238        if (mCbPermanent)
     239        {
     240            mCbPermanent->setChecked (aPermanent);
     241            mCbPermanent->setEnabled (!aPermanent);
     242        }
     243    }
    224244
    225245private slots:
     
    272292    QLineEdit *mLePath;
    273293    QLineEdit *mLeName;
     294    QCheckBox *mCbPermanent;
    274295};
    275296
     
    301322}
    302323
    303 void VBoxSharedFoldersSettings::setDialogType (
    304      VBoxSharedFoldersSettings::SFDialogType aType)
     324void VBoxSharedFoldersSettings::setDialogType (int aType)
    305325{
    306326    mDialogType = aType;
     
    456476
    457477    /* This function is only available for MachineType dialog */
    458     Assert (mDialogType == MachineType);
     478    Assert (mDialogType & MachineType);
    459479    /* Searching for MachineType item's root */
    460480    QListViewItem *root = listView->findItem (QString::number (MachineType), 2);
     
    470490
    471491    /* This function is only available for ConsoleType dialog */
    472     Assert (mDialogType == ConsoleType);
     492    Assert (mDialogType & ConsoleType);
    473493    /* Searching for ConsoleType item's root */
    474494    QListViewItem *root = listView->findItem (QString::number (ConsoleType), 2);
     
    507527
    508528
     529QListViewItem* VBoxSharedFoldersSettings::searchRoot (bool aIsPermanent)
     530{
     531    if (!aIsPermanent)
     532        return listView->findItem (QString::number (ConsoleType), 2);
     533    else if (mDialogType & MachineType)
     534        return listView->findItem (QString::number (MachineType), 2);
     535    else
     536        return listView->findItem (QString::number (GlobalType), 2);
     537}
     538
    509539void VBoxSharedFoldersSettings::tbAddPressed()
    510540{
    511541    /* Invoke Add-Box Dialog */
    512     VBoxAddSFDialog dlg (this, VBoxAddSFDialog::AddDType);
     542    VBoxAddSFDialog dlg (this, VBoxAddSFDialog::AddDialogType,
     543                         mDialogType & ConsoleType);
    513544    if (dlg.exec() != QDialog::Accepted)
    514545        return;
    515546    QString name = dlg.getName();
    516547    QString path = dlg.getPath();
     548    bool isPermanent = dlg.getPermanent();
    517549    /* Shared folder's name & path could not be empty */
    518550    Assert (!name.isEmpty() && !path.isEmpty());
    519551    /* Searching root for the new listview item */
    520     QListViewItem *root = listView->findItem (QString::number (mDialogType), 2);
     552    QListViewItem *root = searchRoot (isPermanent);
    521553    Assert (root);
    522554    /* Appending a new listview item to the root */
    523     VBoxRichListItem *item = new VBoxRichListItem (VBoxRichListItem::EllipsisFile,
    524                                                    root, name, path);
     555    VBoxRichListItem *item = new VBoxRichListItem (
     556        VBoxRichListItem::EllipsisFile, root, name, path);
     557    /* Make the created item selected */
    525558    listView->ensureItemVisible (item);
    526559    listView->setCurrentItem (item);
    527560    processCurrentChanged (item);
    528561    listView->setFocus();
     562
    529563    mIsListViewChanged = true;
    530564}
     
    534568    /* Check selected item */
    535569    QListViewItem *selectedItem = listView->selectedItem();
    536     VBoxRichListItem *item = 0;
    537     if (selectedItem->rtti() == VBoxRichListItem::QIRichListItemId)
    538         item = static_cast<VBoxRichListItem*> (selectedItem);
     570    VBoxRichListItem *item =
     571        selectedItem->rtti() == VBoxRichListItem::QIRichListItemId ?
     572        static_cast<VBoxRichListItem*> (selectedItem) : 0;
    539573    Assert (item);
    540     /* Invoke Add-Box Dialog */
    541     VBoxAddSFDialog dlg (this, VBoxAddSFDialog::EditDType);
     574    Assert (item->parent());
     575    /* Invoke Edit-Box Dialog */
     576    VBoxAddSFDialog dlg (this, VBoxAddSFDialog::EditDialogType,
     577                         mDialogType & ConsoleType);
    542578    dlg.setPath (item->getText (1));
    543579    dlg.setName (item->getText (0));
     580    dlg.setPermanent ((SFDialogType)item->parent()->text (2).toInt()
     581                      != ConsoleType);
    544582    if (dlg.exec() != QDialog::Accepted)
    545583        return;
    546584    QString name = dlg.getName();
    547585    QString path = dlg.getPath();
     586    bool isPermanent = dlg.getPermanent();
    548587    /* Shared folder's name & path could not be empty */
    549588    Assert (!name.isEmpty() && !path.isEmpty());
     589    /* Searching new root for the selected listview item */
     590    QListViewItem *root = searchRoot (isPermanent);
     591    Assert (root);
    550592    /* Updating an edited listview item */
    551593    item->updateText (1, path);
    552594    item->updateText (0, name);
     595    if (item->parent() != root)
     596    {
     597        /* Move the selected item into new location */
     598        item->parent()->takeItem (item);
     599        root->insertItem (item);
     600
     601        /* Make the created item selected */
     602        listView->ensureItemVisible (item);
     603        listView->setCurrentItem (item);
     604        processCurrentChanged (item);
     605        listView->setFocus();
     606    }
     607
    553608    mIsListViewChanged = true;
    554609}
     
    591646}
    592647
     648void VBoxSharedFoldersSettings::processDoubleClick (QListViewItem *aItem)
     649{
     650    bool editEnabled = aItem && aItem->parent() &&
     651        isEditable (aItem->parent()->text (2));
     652    if (editEnabled)
     653        tbEditPressed();
     654}
     655
    593656bool VBoxSharedFoldersSettings::isEditable (const QString &aKey)
    594657{
     
    601664    if (!type)
    602665        AssertMsgFailed (("Incorrect listview item key value\n"));
    603     return type == mDialogType;
     666    return mDialogType & type;
    604667}
    605668
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