VirtualBox

Changeset 72177 in vbox


Ignore:
Timestamp:
May 9, 2018 3:57:09 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122600
Message:

FE/Qt: bugref: 6769 Adding a path/name selector widget to our new vm wizards.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
10 edited

Legend:

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

    r72174 r72177  
    554554        {
    555555            /* Configure widget: */
    556             m_pNameAndSystemEditor->nameEditor()->setValidator(new QRegExpValidator(QRegExp(".+"), this));
     556            m_pNameAndSystemEditor->setNameFieldValidator(".+");
    557557        }
    558558    }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.cpp

    r72174 r72177  
    3131# include "UIFilePathSelector.h"
    3232# include "UINameAndSystemEditor.h"
     33# include "UIVMNamePathSelector.h"
    3334
    3435/* COM includes: */
     
    5051    , m_fSupportsHWVirtEx(false)
    5152    , m_fSupportsLongMode(false)
    52     , m_pLabelName(0)
    5353    , m_pLabelFamily(0)
    5454    , m_pLabelType(0)
    5555    , m_pIconType(0)
    56     , m_pEditorName(0)
    57     , m_pEditorLocation(0)
     56    , m_pNamePathLabel(0)
     57    , m_pNamePathSelector(0)
    5858    , m_pComboFamily(0)
    5959    , m_pComboType(0)
     
    6565QString UINameAndSystemEditor::name() const
    6666{
    67     if (!m_fChooseLocation)
    68         return m_pEditorName->text();
    69     else
    70         return m_pEditorLocation->path();
     67    if (!m_pNamePathSelector)
     68        return QString();
     69    return m_pNamePathSelector->name();
     70}
     71
     72QString UINameAndSystemEditor::path() const
     73{
     74    if (!m_pNamePathSelector)
     75        return vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
     76    return m_pNamePathSelector->path();
    7177}
    7278
    7379void UINameAndSystemEditor::setName(const QString &strName)
    7480{
    75     if (!m_fChooseLocation)
    76         m_pEditorName->setText(strName);
    77     else
    78         m_pEditorLocation->setPath(strName);
     81    if (!m_pNamePathSelector)
     82        return;
     83    m_pNamePathSelector->setName(strName);
    7984}
    8085
     
    112117void UINameAndSystemEditor::retranslateUi()
    113118{
    114     m_pLabelName->setText(tr("N&ame:"));
    115119    m_pLabelFamily->setText(tr("&Type:"));
    116120    m_pLabelType->setText(tr("&Version:"));
    117     if (!m_fChooseLocation)
    118         m_pEditorName->setWhatsThis(tr("Holds the name of the virtual machine."));
    119     else
    120         m_pEditorLocation->setWhatsThis(tr("Holds the location of the virtual machine."));
     121    m_pNamePathLabel->setText(tr("Path/Name:"));
     122
    121123    m_pComboFamily->setWhatsThis(tr("Selects the operating system family that "
    122124                                    "you plan to install into this virtual machine."));
     
    227229        pMainLayout->setContentsMargins(0, 0, 0, 0);
    228230
    229         /* Create VM name label: */
    230         m_pLabelName = new QLabel;
    231         if (m_pLabelName)
    232         {
    233             /* Configure VM name label: */
    234             m_pLabelName->setAlignment(Qt::AlignRight);
    235             m_pLabelName->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
    236             /* Add VM name label into main-layout: */
    237             pMainLayout->addWidget(m_pLabelName, 0, 0);
    238         }
    239 
    240         if (!m_fChooseLocation)
    241         {
    242             /* Create VM name editor: */
    243             m_pEditorName = new QLineEdit;
    244             if (m_pEditorName)
    245             {
    246                 /* Configure VM name editor: */
    247                 m_pEditorName->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    248                 m_pLabelName->setBuddy(m_pEditorName);
    249                 /* Add VM name editor into main-layout: */
    250                 pMainLayout->addWidget(m_pEditorName, 0, 1, 1, 2);
    251             }
    252         }
    253         else
    254         {
    255             /* Create VM location editor: */
    256             m_pEditorLocation = new UIFilePathSelector;
    257             if (m_pEditorLocation)
    258             {
    259                 /* Configure advanced VM name editor: */
    260                 m_pEditorLocation->setResetEnabled(false);
    261                 m_pEditorLocation->setMode(UIFilePathSelector::Mode_File_Save);
    262                 m_pEditorLocation->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    263                 m_pEditorLocation->setHomeDir(vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder());
    264                 m_pLabelName->setBuddy(m_pEditorLocation);
    265                 /* Add advanced VM name editor into main-layout: */
    266                 pMainLayout->addWidget(m_pEditorLocation, 0, 1, 1, 2);
    267             }
     231        m_pNamePathLabel = new QLabel;
     232        if (m_pNamePathLabel)
     233        {
     234            m_pNamePathLabel->setAlignment(Qt::AlignRight);
     235            m_pNamePathLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
     236            pMainLayout->addWidget(m_pNamePathLabel, 0, 0, 1, 1);
     237        }
     238        m_pNamePathSelector = new UIVMNamePathSelector;
     239        if (m_pNamePathSelector)
     240        {
     241            m_pNamePathSelector->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     242            pMainLayout->addWidget(m_pNamePathSelector, 0, 1, 1, 2);
    268243        }
    269244
     
    325300                pLayoutIcon->addWidget(m_pIconType);
    326301            }
    327 
    328302            /* Add stretch to sub-layout: */
    329303            pLayoutIcon->addStretch();
     
    358332{
    359333    /* Prepare connections: */
    360     if (!m_fChooseLocation)
    361         connect(m_pEditorName, &QLineEdit::textChanged,
    362                 this, &UINameAndSystemEditor::sigNameChanged);
    363     else
    364         connect(m_pEditorLocation, &UIFilePathSelector::pathChanged,
    365                 this, &UINameAndSystemEditor::sigNameChanged);
     334    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigNameChanged,
     335            this, &UINameAndSystemEditor::sigNameChanged);
    366336    connect(m_pComboFamily, static_cast<void(QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
    367337            this, &UINameAndSystemEditor::sltFamilyChanged);
     
    369339            this, &UINameAndSystemEditor::sltTypeChanged);
    370340}
     341
     342void UINameAndSystemEditor::setNameFieldValidator(const QString &strValidatorString)
     343{
     344    if (!m_pNamePathSelector)
     345        return;
     346    m_pNamePathSelector->setNameFieldValidator(strValidatorString);
     347}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.h

    r72174 r72177  
    3636class QString;
    3737class UIFilePathSelector;
     38class UIVMNamePathSelector;
    3839
    3940/** QWidget subclass providing complex editor for basic VM parameters. */
     
    5859    UINameAndSystemEditor(QWidget *pParent, bool fChooseLocation = false);
    5960
    60     /** Returns the VM name editor. */
    61     QLineEdit *nameEditor() const { return m_pEditorName; }
    62     /** Returns the VM location editor. */
    63     UIFilePathSelector *locationEditor() const { return m_pEditorLocation; }
    64 
    6561    /** Returns the VM name. */
    6662    QString name() const;
     63    /** Returns path string selected by the user. */
     64    QString path() const;
     65
    6766    /** Defines the VM @a strName. */
    6867    void setName(const QString &strName);
     
    7271    /** Defines the VM OS @a enmType. */
    7372    void setType(const CGuestOSType &enmType);
     73
     74    void setNameFieldValidator(const QString &strValidatorString);
    7475
    7576protected:
     
    113114    bool                    m_fSupportsLongMode;
    114115
    115     /** Holds the VM name label instance. */
    116     QLabel                 *m_pLabelName;
    117116    /** Holds the VM OS family label instance. */
    118117    QLabel                 *m_pLabelFamily;
     
    121120    /** Holds the VM OS type icon instance. */
    122121    QLabel                 *m_pIconType;
    123     /** Holds the VM name editor instance. */
    124     QLineEdit              *m_pEditorName;
    125     /** Holds the VM location editor instance. */
    126     UIFilePathSelector     *m_pEditorLocation;
     122
     123    QLabel                 *m_pNamePathLabel;
     124    UIVMNamePathSelector   *m_pNamePathSelector;
    127125    /** Holds the VM OS family combo instance. */
    128126    QComboBox              *m_pComboFamily;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.cpp

    r72174 r72177  
    2323# include <QDir>
    2424# include <QHBoxLayout>
     25# include <QRegExpValidator>
    2526
    2627/* GUI includes: */
     28# include "QIFileDialog.h"
    2729# include "QILineEdit.h"
    2830# include "QILabel.h"
     31# include "QIToolButton.h"
     32# include "UIIconPool.h"
    2933# include "UIVMNamePathSelector.h"
    3034# include "VBoxGlobal.h"
     
    3539#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3640
    37 
    38 
    3941UIVMNamePathSelector::UIVMNamePathSelector(QWidget *pParent /* = 0 */)
    4042    : QIWithRetranslateUI<QWidget>(pParent)
     
    4345    , m_pName(0)
    4446    , m_pSeparator(0)
     47    ,m_pFileDialogButton(0)
    4548{
    4649    prepareWidgets();
     50    retranslateUi();
    4751}
    4852
     
    5256    CVirtualBox vbox = vboxGlobal().virtualBox();
    5357    /* Get default machine folder: */
    54     /*const QString strDefaultMachineFolder = */return vbox.GetSystemProperties().GetDefaultMachineFolder();
     58    return vbox.GetSystemProperties().GetDefaultMachineFolder();
    5559
    5660}
     
    6569    m_pMainLayout->setSpacing(0);
    6670    setLayout(m_pMainLayout);
     71
     72    m_pFileDialogButton = new QIToolButton(this);
     73    if (m_pFileDialogButton)
     74    {
     75        m_pMainLayout->addWidget(m_pFileDialogButton);
     76        m_pFileDialogButton->setIcon(UIIconPool::iconSet(QString(":/sf_add_16px.png")));
     77        connect(m_pFileDialogButton, &QIToolButton::clicked, this, &UIVMNamePathSelector::sltOpenPathSelector);
     78    }
    6779
    6880    m_pPath = new QILineEdit;
     
    8496    {
    8597        m_pMainLayout->addWidget(m_pName);
     98        connect(m_pName, &QILineEdit::textChanged,
     99                this, &UIVMNamePathSelector::sigNameChanged);
     100
    86101    }
    87102
     
    121136void UIVMNamePathSelector::retranslateUi()
    122137{
     138    setToolTip(tr("The Virtual Machine files will be saved under ..."));
    123139}
     140
     141void UIVMNamePathSelector::sltOpenPathSelector()
     142{
     143
     144    QString strSelectedPath = QIFileDialog::getExistingDirectory(m_pPath->text(), this,
     145                                                                 QString("Select a parent folder for new Virtual Machine"));
     146    if (!strSelectedPath.isEmpty())
     147    {
     148        m_pPath->setText(strSelectedPath);
     149    }
     150}
     151
     152void UIVMNamePathSelector::setNameFieldValidator(const QString &strValidatorString)
     153{
     154    if (!m_pName)
     155        return;
     156    m_pName->setValidator(new QRegExpValidator(QRegExp(strValidatorString), this));
     157}
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.h

    r72174 r72177  
    2929class QILabel;
    3030class QILineEdit;
    31 
     31class QIToolButton;
    3232
    3333class SHARED_LIBRARY_STUFF UIVMNamePathSelector : public QIWithRetranslateUI<QWidget>
     
    3636
    3737signals:
     38
     39    void sigNameChanged(const QString &strName);
    3840
    3941public:
     
    4850    QString name() const;
    4951    void    setName(const QString &name);
     52    void    setNameFieldValidator(const QString &strValidatorString);
    5053
    5154protected:
     
    5558private slots:
    5659
     60    void sltOpenPathSelector();
    5761
    5862private:
     
    6165    QString      defaultMachineFolder() const;
    6266
    63     QHBoxLayout *m_pMainLayout;
    64     QILineEdit  *m_pPath;
    65     QILineEdit  *m_pName;
    66     QILabel     *m_pSeparator;
     67    QHBoxLayout  *m_pMainLayout;
     68    QILineEdit   *m_pPath;
     69    QILineEdit   *m_pName;
     70    QILabel      *m_pSeparator;
     71    QIToolButton *m_pFileDialogButton;
     72
    6773};
    6874
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVM.cpp

    r71027 r72177  
    106106        if (!m_strGroup.isEmpty())
    107107            groups << m_strGroup;
    108         m_machine = vbox.CreateMachine(QString() /* no file-path for now */,
     108        m_machine = vbox.CreateMachine(field("machineFilePath").toString(),
    109109                                       field("name").toString(),
    110110                                       groups, strTypeId, QString());
     
    397397    return strControllerName;
    398398}
    399 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.cpp

    r72174 r72177  
    217217bool UIWizardNewVMPage1::createMachineFolder()
    218218{
     219    if (!m_pNameAndSystemEditor)
     220        return false;
    219221    /* Cleanup previosly created folder if any: */
    220222    if (machineFolderCreated() && !cleanupMachineFolder())
     
    227229    CVirtualBox vbox = vboxGlobal().virtualBox();
    228230    /* Get default machine folder: */
    229     const QString strDefaultMachineFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
     231    //const QString strMachineFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
     232
    230233    /* Compose machine filename: */
    231     const QString strMachineFilePath = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(),
    232                                                                    m_strGroup,
    233                                                                    QString(),
    234                                                                    strDefaultMachineFolder);
     234    m_strMachineFilePath = vbox.ComposeMachineFilename(m_pNameAndSystemEditor->name(),
     235                                                       m_strGroup,
     236                                                       QString(),
     237                                                       m_pNameAndSystemEditor->path());
    235238    /* Compose machine folder/basename: */
    236     const QFileInfo fileInfo(strMachineFilePath);
    237     const QString strMachineFolder = fileInfo.absolutePath();
    238     const QString strMachineBaseName = fileInfo.completeBaseName();
     239    const QFileInfo fileInfo(m_strMachineFilePath);
     240    m_strMachineFolder = fileInfo.absolutePath();
     241    m_strMachineBaseName = fileInfo.completeBaseName();
    239242
    240243    /* Make sure that folder doesn't exists: */
    241     if (QDir(strMachineFolder).exists())
     244    if (QDir(m_strMachineFolder).exists())
    242245    {
    243         msgCenter().cannotRewriteMachineFolder(strMachineFolder, thisImp());
     246        msgCenter().cannotRewriteMachineFolder(m_strMachineFolder, thisImp());
    244247        return false;
    245248    }
    246249
    247250    /* Try to create new folder (and it's predecessors): */
    248     bool fMachineFolderCreated = QDir().mkpath(strMachineFolder);
     251    bool fMachineFolderCreated = QDir().mkpath(m_strMachineFolder);
    249252    if (!fMachineFolderCreated)
    250253    {
    251         msgCenter().cannotCreateMachineFolder(strMachineFolder, thisImp());
     254        msgCenter().cannotCreateMachineFolder(m_strMachineFolder, thisImp());
    252255        return false;
    253256    }
    254 
    255     /* Initialize fields: */
    256     m_strMachineFolder = strMachineFolder;
    257     m_strMachineBaseName = strMachineBaseName;
    258257    return true;
    259258}
     
    293292    registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
    294293    registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
     294    registerField("machineFilePath", this, "machineFilePath");
    295295    registerField("machineFolder", this, "machineFolder");
    296296    registerField("machineBaseName", this, "machineBaseName");
     
    315315
    316316    /* Translate widgets: */
    317     m_pLabel->setText(UIWizardNewVM::tr("Please choose a descriptive name for the new virtual machine "
     317    m_pLabel->setText(UIWizardNewVM::tr("Please choose a descriptive name and destination folder for the new virtual machine "
    318318                                        "and select the type of operating system you intend to install on it. "
    319319                                        "The name you choose will be used throughout VirtualBox "
     
    340340    return createMachineFolder();
    341341}
    342 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.h

    r72174 r72177  
    4343    bool cleanupMachineFolder();
    4444
     45    QString machineFilePath() const { return m_strMachineFilePath; }
     46    void setMachineFilePath(const QString &strMachineFilePath) { m_strMachineFilePath = strMachineFilePath; }
     47
    4548    /** Returns the machine folder value. */
    4649    QString machineFolder() const { return m_strMachineFolder; }
     
    5356    void setMachineBaseName(const QString &strMachineBaseName) { m_strMachineBaseName = strMachineBaseName; }
    5457
    55     /** Holds the machine folder value. */
     58    /** Full path (including the file name) of the machine's configuration file. */
     59    QString m_strMachineFilePath;
     60    /** Path of the folder hosting the machine's configuration file. Generated from m_strMachineFilePath. */
    5661    QString m_strMachineFolder;
    57     /** Holds the machine base-name value. */
     62    /** Base name of the machine is generated from the m_strMachineFilePath. */
    5863    QString m_strMachineBaseName;
    5964
    60     /* Widgets: */
     65    /** Provides a path selector and a line edit field for path and name entry. */
    6166    UINameAndSystemEditor *m_pNameAndSystemEditor;
    6267
    63     /* Variables: */
     68    /** Variables: */
    6469    QString m_strGroup;
    6570    bool m_fSupportsHWVirtEx;
     
    7176{
    7277    Q_OBJECT;
     78    Q_PROPERTY(QString machineFilePath READ machineFilePath WRITE setMachineFilePath);
    7379    Q_PROPERTY(QString machineFolder READ machineFolder WRITE setMachineFolder);
    7480    Q_PROPERTY(QString machineBaseName READ machineBaseName WRITE setMachineBaseName);
     
    107113
    108114#endif // __UIWizardNewVMPageBasic1_h__
    109 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.cpp

    r71948 r72177  
    160160    registerField("name*", m_pNameAndSystemEditor, "name", SIGNAL(sigNameChanged(const QString &)));
    161161    registerField("type", m_pNameAndSystemEditor, "type", SIGNAL(sigOsTypeChanged()));
     162    registerField("machineFilePath", this, "machineFilePath");
    162163    registerField("machineFolder", this, "machineFolder");
    163164    registerField("machineBaseName", this, "machineBaseName");
     
    304305    return fResult;
    305306}
    306 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageExpert.h

    r71027 r72177  
    3636    Q_PROPERTY(QString machineFolder READ machineFolder WRITE setMachineFolder);
    3737    Q_PROPERTY(QString machineBaseName READ machineBaseName WRITE setMachineBaseName);
     38    Q_PROPERTY(QString machineFilePath READ machineFilePath WRITE setMachineFilePath);
    3839    Q_PROPERTY(CMedium virtualDisk READ virtualDisk WRITE setVirtualDisk);
    3940    Q_PROPERTY(QString virtualDiskId READ virtualDiskId WRITE setVirtualDiskId);
     
    8485
    8586#endif // __UIWizardNewVMPageExpert_h__
    86 
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette