VirtualBox

Ignore:
Timestamp:
Aug 31, 2020 4:30:54 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9812: VM settings: Prepare cascade cleanup for Shared Folders details dialog.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSFDetails.cpp

    r85679 r85961  
    3232
    3333UIMachineSettingsSFDetails::UIMachineSettingsSFDetails(SFDialogType type,
    34                                                        bool fEnableSelector, /* for "permanent" checkbox */
     34                                                       bool fUsePermanent,
    3535                                                       const QStringList &usedNames,
    3636                                                       QWidget *pParent /* = 0 */)
    3737    : QIWithRetranslateUI2<QIDialog>(pParent)
    3838    , m_type(type)
    39     , m_fUsePermanent(fEnableSelector)
     39    , m_fUsePermanent(fUsePermanent)
    4040    , m_usedNames(usedNames)
    41     , m_pPathSelector(0)
    42     , m_pPermanentCheckBox(0)
    43     , m_pNameLineEdit(0)
     41    , m_pCache(0)
     42    , m_pLabelPath(0)
     43    , m_pSelectorPath(0)
     44    , m_pLabelName(0)
     45    , m_pEditorName(0)
     46    , m_pLabelAutoMountPoint(0)
     47    , m_pEditorAutoMountPoint(0)
    4448    , m_pReadonlyCheckBox(0)
    4549    , m_pAutoMountCheckBox(0)
    46     , m_pAutoMountPointLineEdit(0)
    47     , m_pPathLabel(0)
    48     , m_pNameLabel(0)
    49     , m_pAutoMountPointLabel(0)
     50    , m_pPermanentCheckBox(0)
    5051    , m_pButtonBox(0)
    5152{
    52     prepareWidgets();
    53 
    54     /* Setup widgets: */
    55     m_pPathSelector->setResetEnabled(false);
    56     m_pPathSelector->setHomeDir(QDir::homePath());
    57     m_pPermanentCheckBox->setHidden(!fEnableSelector);
    58 
    59     /* Setup connections: */
    60     connect(m_pPathSelector, static_cast<void(UIFilePathSelector::*)(int)>(&UIFilePathSelector::currentIndexChanged),
    61             this, &UIMachineSettingsSFDetails::sltSelectPath);
    62     connect(m_pPathSelector, &UIFilePathSelector::pathChanged, this, &UIMachineSettingsSFDetails::sltSelectPath);
    63     connect(m_pNameLineEdit, &QLineEdit::textChanged, this, &UIMachineSettingsSFDetails::sltValidate);
    64     if (fEnableSelector)
    65         connect(m_pPermanentCheckBox, &QCheckBox::toggled, this, &UIMachineSettingsSFDetails::sltValidate);
    66 
    67      /* Applying language settings: */
    68     retranslateUi();
    69 
    70     /* Validate the initial field values: */
    71     sltValidate();
    72 
    73     /* Adjust dialog size: */
    74     adjustSize();
    75 
    76 #ifdef VBOX_WS_MAC
    77     setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    78     setFixedSize(minimumSize());
    79 #endif /* VBOX_WS_MAC */
    80 }
    81 
    82 void UIMachineSettingsSFDetails::prepareWidgets()
    83 {
    84     if (objectName().isEmpty())
    85         setObjectName(QStringLiteral("UIMachineSettingsSFDetails"));
    86     resize(218, 196);
    87     QGridLayout *gridLayout = new QGridLayout(this);
    88     gridLayout->setObjectName(QStringLiteral("gridLayout"));
    89     m_pPathLabel = new QLabel;
    90     m_pPathLabel->setObjectName(QStringLiteral("m_pPathLabel"));
    91     m_pPathLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    92 
    93     gridLayout->addWidget(m_pPathLabel, 0, 0, 1, 1);
    94 
    95     m_pPathSelector = new UIFilePathSelector;
    96     m_pPathSelector->setObjectName(QStringLiteral("m_pPathSelector"));
    97     gridLayout->addWidget(m_pPathSelector, 0, 1, 1, 1);
    98 
    99     m_pNameLabel = new QLabel;
    100     m_pNameLabel->setObjectName(QStringLiteral("m_pNameLabel"));
    101     m_pNameLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    102     gridLayout->addWidget(m_pNameLabel, 1, 0, 1, 1);
    103 
    104     m_pNameLineEdit = new QLineEdit;
    105     m_pNameLineEdit->setObjectName(QStringLiteral("m_pNameLineEdit"));
    106     gridLayout->addWidget(m_pNameLineEdit, 1, 1, 1, 1);
    107 
    108     m_pReadonlyCheckBox = new QCheckBox;
    109     m_pReadonlyCheckBox->setObjectName(QStringLiteral("m_pReadonlyCheckBox"));
    110     gridLayout->addWidget(m_pReadonlyCheckBox, 2, 1, 1, 1);
    111 
    112     m_pAutoMountCheckBox = new QCheckBox;
    113     m_pAutoMountCheckBox->setObjectName(QStringLiteral("m_pAutoMountCheckBox"));
    114     gridLayout->addWidget(m_pAutoMountCheckBox, 3, 1, 1, 1);
    115 
    116     m_pAutoMountPointLabel = new QLabel;
    117     m_pAutoMountPointLabel->setObjectName(QStringLiteral("m_pAutoMountPointLabel"));
    118     m_pAutoMountPointLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
    119     gridLayout->addWidget(m_pAutoMountPointLabel, 4, 0, 1, 1);
    120 
    121     m_pAutoMountPointLineEdit = new QLineEdit;
    122     m_pAutoMountPointLineEdit->setObjectName(QStringLiteral("m_pAutoMountPointLineEdit"));
    123     gridLayout->addWidget(m_pAutoMountPointLineEdit, 4, 1, 1, 1);
    124 
    125     m_pPermanentCheckBox = new QCheckBox;
    126     m_pPermanentCheckBox->setObjectName(QStringLiteral("m_pPermanentCheckBox"));
    127     gridLayout->addWidget(m_pPermanentCheckBox, 5, 1, 1, 1);
    128 
    129     QSpacerItem *spacerItem = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
    130     gridLayout->addItem(spacerItem, 6, 1, 1, 1);
    131 
    132     m_pButtonBox = new QIDialogButtonBox;
    133     m_pButtonBox->setObjectName(QStringLiteral("m_pButtonBox"));
    134     m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Ok);
    135     gridLayout->addWidget(m_pButtonBox, 7, 0, 1, 2);
    136 
    137 
    138     QObject::connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIMachineSettingsSFDetails::accept);
    139     QObject::connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIMachineSettingsSFDetails::reject);
    140 }
    141 
     53    prepare();
     54}
    14255
    14356void UIMachineSettingsSFDetails::setPath(const QString &strPath)
    14457{
    145     m_pPathSelector->setPath(strPath);
     58    m_pSelectorPath->setPath(strPath);
    14659}
    14760
    14861QString UIMachineSettingsSFDetails::path() const
    14962{
    150     return m_pPathSelector->path();
     63    return m_pSelectorPath->path();
    15164}
    15265
    15366void UIMachineSettingsSFDetails::setName(const QString &strName)
    15467{
    155     m_pNameLineEdit->setText(strName);
     68    m_pEditorName->setText(strName);
    15669}
    15770
    15871QString UIMachineSettingsSFDetails::name() const
    15972{
    160     return m_pNameLineEdit->text();
     73    return m_pEditorName->text();
    16174}
    16275
     
    18396void UIMachineSettingsSFDetails::setAutoMountPoint(const QString &strAutoMountPoint)
    18497{
    185     m_pAutoMountPointLineEdit->setText(strAutoMountPoint);
     98    m_pEditorAutoMountPoint->setText(strAutoMountPoint);
    18699}
    187100
    188101QString UIMachineSettingsSFDetails::autoMountPoint() const
    189102{
    190     return m_pAutoMountPointLineEdit->text();
     103    return m_pEditorAutoMountPoint->text();
    191104}
    192105
     
    203116void UIMachineSettingsSFDetails::retranslateUi()
    204117{
    205     m_pPathLabel->setText(tr("Folder Path:"));
    206     m_pNameLabel->setText(tr("Folder Name:"));
    207     m_pNameLineEdit->setToolTip(tr("Holds the name of the shared folder (as it will be seen by the guest OS)."));
     118    m_pLabelPath->setText(tr("Folder Path:"));
     119    m_pLabelName->setText(tr("Folder Name:"));
     120    m_pEditorName->setToolTip(tr("Holds the name of the shared folder (as it will be seen by the guest OS)."));
    208121    m_pReadonlyCheckBox->setToolTip(tr("When checked, the guest OS will not be able to write to the specified shared folder."));
    209122    m_pReadonlyCheckBox->setText(tr("&Read-only"));
    210123    m_pAutoMountCheckBox->setToolTip(tr("When checked, the guest OS will try to automatically mount the shared folder on startup."));
    211124    m_pAutoMountCheckBox->setText(tr("&Auto-mount"));
    212     m_pAutoMountPointLabel->setText(tr("Mount point:"));
    213     m_pAutoMountPointLineEdit->setToolTip(tr("Where to automatically mount the folder in the guest.  A drive letter (e.g. 'G:') for Windows and OS/2 guests, path for the others.  If left empty the guest will pick something fitting."));
     125    m_pLabelAutoMountPoint->setText(tr("Mount point:"));
     126    m_pEditorAutoMountPoint->setToolTip(tr("Where to automatically mount the folder in the guest.  A drive letter (e.g. 'G:') for Windows and OS/2 guests, path for the others.  If left empty the guest will pick something fitting."));
    214127    m_pPermanentCheckBox->setToolTip(tr("When checked, this shared folder will be permanent."));
    215128    m_pPermanentCheckBox->setText(tr("&Make Permanent"));
     
    230143void UIMachineSettingsSFDetails::sltValidate()
    231144{
    232     m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_pPathSelector->path().isEmpty() &&
    233                                                          QDir(m_pPathSelector->path()).exists() &&
    234                                                          !m_pNameLineEdit->text().trimmed().isEmpty() &&
    235                                                          !m_pNameLineEdit->text().contains(" ") &&
    236                                                          !m_usedNames.contains(m_pNameLineEdit->text()));
     145    m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_pSelectorPath->path().isEmpty() &&
     146                                                         QDir(m_pSelectorPath->path()).exists() &&
     147                                                         !m_pEditorName->text().trimmed().isEmpty() &&
     148                                                         !m_pEditorName->text().contains(" ") &&
     149                                                         !m_usedNames.contains(m_pEditorName->text()));
    237150}
    238151
    239152void UIMachineSettingsSFDetails::sltSelectPath()
    240153{
    241     if (!m_pPathSelector->isPathSelected())
     154    if (!m_pSelectorPath->isPathSelected())
    242155        return;
    243156
    244     QString strFolderName(m_pPathSelector->path());
     157    QString strFolderName(m_pSelectorPath->path());
    245158#if defined (VBOX_WS_WIN) || defined (Q_OS_OS2)
    246159    if (strFolderName[0].isLetter() && strFolderName[1] == ':' && strFolderName[2] == 0)
     
    249162         * Append the trailing backslash to get a valid root path 'X:\': */
    250163        strFolderName += "\\";
    251         m_pPathSelector->setPath(strFolderName);
     164        m_pSelectorPath->setPath(strFolderName);
    252165    }
    253166#endif /* VBOX_WS_WIN || Q_OS_OS2 */
     
    256169    {
    257170        /* Processing non-root folder */
    258         m_pNameLineEdit->setText(folder.dirName().replace(' ', '_'));
     171        m_pEditorName->setText(folder.dirName().replace(' ', '_'));
    259172    }
    260173    else
     
    262175        /* Processing root folder: */
    263176#if defined (VBOX_WS_WIN) || defined (Q_OS_OS2)
    264         m_pNameLineEdit->setText(strFolderName.toUpper()[0] + "_DRIVE");
     177        m_pEditorName->setText(strFolderName.toUpper()[0] + "_DRIVE");
    265178#elif defined (VBOX_WS_X11)
    266         m_pNameLineEdit->setText("ROOT");
     179        m_pEditorName->setText("ROOT");
    267180#endif
    268181    }
     
    270183    sltValidate();
    271184}
     185
     186void UIMachineSettingsSFDetails::prepare()
     187{
     188    /* Prepare everything: */
     189    prepareWidgets();
     190    prepareConnections();
     191
     192    /* Apply language settings: */
     193    retranslateUi();
     194
     195    /* Validate the initial field values: */
     196    sltValidate();
     197
     198    /* Adjust dialog size: */
     199    adjustSize();
     200
     201#ifdef VBOX_WS_MAC
     202    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     203    setFixedSize(minimumSize());
     204#endif /* VBOX_WS_MAC */
     205}
     206
     207void UIMachineSettingsSFDetails::prepareWidgets()
     208{
     209    /* Prepare main layout: */
     210    QGridLayout *pLayoutMain = new QGridLayout(this);
     211    if (pLayoutMain)
     212    {
     213        pLayoutMain->setRowStretch(6, 1);
     214
     215        /* Prepare path label: */
     216        m_pLabelPath = new QLabel;
     217        if (m_pLabelPath)
     218        {
     219            m_pLabelPath->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
     220            pLayoutMain->addWidget(m_pLabelPath, 0, 0);
     221        }
     222        /* Prepare path selector: */
     223        m_pSelectorPath = new UIFilePathSelector;
     224        if (m_pSelectorPath)
     225        {
     226            m_pSelectorPath->setResetEnabled(false);
     227            m_pSelectorPath->setHomeDir(QDir::homePath());
     228
     229            pLayoutMain->addWidget(m_pSelectorPath, 0, 1);
     230        }
     231
     232        /* Prepare name label: */
     233        m_pLabelName = new QLabel;
     234        if (m_pLabelName)
     235        {
     236            m_pLabelName->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
     237            pLayoutMain->addWidget(m_pLabelName, 1, 0);
     238        }
     239        /* Prepare name editor: */
     240        m_pEditorName = new QLineEdit;
     241        if (m_pEditorName)
     242            pLayoutMain->addWidget(m_pEditorName, 1, 1);
     243
     244        /* Prepare auto-mount point: */
     245        m_pLabelAutoMountPoint = new QLabel;
     246        if (m_pLabelAutoMountPoint)
     247        {
     248            m_pLabelAutoMountPoint->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
     249            pLayoutMain->addWidget(m_pLabelAutoMountPoint, 2, 0);
     250        }
     251        /* Prepare auto-mount editor: */
     252        m_pEditorAutoMountPoint = new QLineEdit;
     253        if (m_pEditorAutoMountPoint)
     254            pLayoutMain->addWidget(m_pEditorAutoMountPoint, 2, 1);
     255
     256        /* Prepare read-only check-box: */
     257        m_pReadonlyCheckBox = new QCheckBox;
     258        if (m_pReadonlyCheckBox)
     259            pLayoutMain->addWidget(m_pReadonlyCheckBox, 3, 1);
     260        /* Prepare auto-mount check-box: */
     261        m_pAutoMountCheckBox = new QCheckBox;
     262        if (m_pAutoMountCheckBox)
     263            pLayoutMain->addWidget(m_pAutoMountCheckBox, 4, 1);
     264        /* Prepare permanent check-box: */
     265        m_pPermanentCheckBox = new QCheckBox;
     266        if (m_pPermanentCheckBox)
     267        {
     268            m_pPermanentCheckBox->setHidden(!m_fUsePermanent);
     269            pLayoutMain->addWidget(m_pPermanentCheckBox, 5, 1);
     270        }
     271
     272        /* Prepare button-box: */
     273        m_pButtonBox = new QIDialogButtonBox;
     274        if (m_pButtonBox)
     275        {
     276            m_pButtonBox->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
     277            pLayoutMain->addWidget(m_pButtonBox, 7, 0, 1, 2);
     278        }
     279    }
     280}
     281
     282void UIMachineSettingsSFDetails::prepareConnections()
     283{
     284    connect(m_pSelectorPath, static_cast<void(UIFilePathSelector::*)(int)>(&UIFilePathSelector::currentIndexChanged),
     285            this, &UIMachineSettingsSFDetails::sltSelectPath);
     286    connect(m_pSelectorPath, &UIFilePathSelector::pathChanged, this, &UIMachineSettingsSFDetails::sltSelectPath);
     287    connect(m_pEditorName, &QLineEdit::textChanged, this, &UIMachineSettingsSFDetails::sltValidate);
     288    if (m_fUsePermanent)
     289        connect(m_pPermanentCheckBox, &QCheckBox::toggled, this, &UIMachineSettingsSFDetails::sltValidate);
     290    connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UIMachineSettingsSFDetails::accept);
     291    connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UIMachineSettingsSFDetails::reject);
     292}
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsSFDetails.h

    r85645 r85961  
    4747
    4848    UIMachineSettingsSFDetails(SFDialogType type,
    49                                bool fEnableSelector, /* for "permanent" checkbox */
     49                               bool fUsePermanent,
    5050                               const QStringList &usedNames,
    5151                               QWidget *pParent = 0);
     
    8080private:
    8181
     82    /** Prepares all. */
     83    void prepare();
     84    /** Prepares widgets. */
    8285    void prepareWidgets();
     86    /** Prepares connections. */
     87    void prepareConnections();
    8388
    8489    SFDialogType  m_type;
     
    8994    /** @name Widgets
    9095      * @{ */
    91         UIFilePathSelector *m_pPathSelector;
    92         QCheckBox *m_pPermanentCheckBox;
    93         QLineEdit *m_pNameLineEdit;
    94         QCheckBox *m_pReadonlyCheckBox;
    95         QCheckBox *m_pAutoMountCheckBox;
    96         QLineEdit *m_pAutoMountPointLineEdit;
    97         QLabel *m_pPathLabel;
    98         QLabel *m_pNameLabel;
    99         QLabel *m_pAutoMountPointLabel;
    100         QIDialogButtonBox *m_pButtonBox;
     96        /** Holds the path label instance. */
     97        QLabel             *m_pLabelPath;
     98        /** Holds the path selector instance. */
     99        UIFilePathSelector *m_pSelectorPath;
     100        /** Holds the name label instance. */
     101        QLabel             *m_pLabelName;
     102        /** Holds the name editor instance. */
     103        QLineEdit          *m_pEditorName;
     104        /** Holds the auto-mount point label instance. */
     105        QLabel             *m_pLabelAutoMountPoint;
     106        /** Holds the auto-mount point editor instance. */
     107        QLineEdit          *m_pEditorAutoMountPoint;
     108        /** Holds the read-only check-box instance. */
     109        QCheckBox          *m_pReadonlyCheckBox;
     110        /** Holds the auto-mount check-box instance. */
     111        QCheckBox          *m_pAutoMountCheckBox;
     112        /** Holds the permanent check-box instance. */
     113        QCheckBox          *m_pPermanentCheckBox;
     114        /** Holds the button-box instance. */
     115        QIDialogButtonBox  *m_pButtonBox;
    101116    /** @} */
    102117};
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