VirtualBox

Changeset 72199 in vbox for trunk/src


Ignore:
Timestamp:
May 14, 2018 12:57:36 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
122638
Message:

FE/Qt bugref:6769 Modifing the clone vm wizard so that it is now possible to provide a non default folder for the cloned vm

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.cpp

    r72182 r72199  
    240240        {
    241241            m_pNamePathSelector->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
     242            m_pNamePathSelector->setPath(vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder());
    242243            pMainLayout->addWidget(m_pNamePathSelector, 0, 1, 1, 2);
    243244        }
     
    349350}
    350351
    351 void UINameAndSystemEditor::setMachineFilePath(const QString &strPath)
     352void UINameAndSystemEditor::setMachineFolder(const QString &strPath)
    352353{
    353354    if (!m_pNamePathSelector)
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UINameAndSystemEditor.h

    r72182 r72199  
    7676
    7777    /** Forwards the machine name to UIVMNamePathSelector member instance. */
    78     void setMachineFilePath(const QString &strPath);
     78    void setMachineFolder(const QString &strPath);
    7979
    8080protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.cpp

    r72191 r72199  
    111111QString UIVMNamePathSelector::path() const
    112112{
    113     if (!m_pPath)
    114         return QString();
    115     return m_pPath->text();
     113    return m_strNonNativePath;
    116114}
    117115
    118116void UIVMNamePathSelector::setPath(const QString &path)
    119117{
    120     if (!m_pPath || m_pPath->text() == path)
     118    if (m_strNonNativePath == path)
    121119        return;
    122     QString nativePath(QDir::toNativeSeparators(path));
    123     m_pPath->setText(nativePath);
    124     m_pPath->setFixedWidthByText(nativePath);
    125     emit sigPathChanged(nativePath);
     120    m_strNonNativePath = path;
     121    if (m_pPath)
     122    {
     123        QString nativePath(QDir::toNativeSeparators(path));
     124        m_pPath->setText(nativePath);
     125        m_pPath->setFixedWidthByText(nativePath);
     126    }
     127    emit sigPathChanged(m_strNonNativePath);
    126128}
    127129
     
    131133        return QString();
    132134    return m_pName->text();
    133 
    134135}
    135136
     
    141142}
    142143
    143 
    144144void UIVMNamePathSelector::retranslateUi()
    145145{
    146146    if (m_strToolTipText.isEmpty())
     147    {
     148        setToolTip(tr("You have to enter a name for the virtual machine"));
    147149        return;
     150    }
    148151    QString strToolTip = "The Virtual Machine files will be saved under " + m_strToolTipText;
    149152    setToolTip(tr(qPrintable(strToolTip)));
     
    152155void UIVMNamePathSelector::sltOpenPathSelector()
    153156{
    154 
    155     QString strSelectedPath = QIFileDialog::getExistingDirectory(m_pPath->text(), this,
     157    QString strSelectedPath = QIFileDialog::getExistingDirectory(m_strNonNativePath, this,
    156158                                                                 QString("Select a parent folder for new Virtual Machine"));
    157159    if (!strSelectedPath.isEmpty())
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIVMNamePathSelector.h

    r72182 r72199  
    7676    /** Tooltip set is set by clients of this widget. */
    7777    QString       m_strToolTipText;
     78    /** Path string whose separators are not converted to native ones. */
     79    QString       m_strNonNativePath;
    7880};
    7981
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVM.cpp

    r69500 r72199  
    3131/* COM includes: */
    3232# include "CConsole.h"
     33# include "CSystemProperties.h"
    3334
    3435#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    5152bool UIWizardCloneVM::cloneVM()
    5253{
    53     /* Get clone name: */
     54    /* Get the clone name: */
    5455    QString strName = field("cloneName").toString();
     56    /* Get the clone path: */
     57    QString strPath = field("clonePath").toString();
     58    QString strSettingsFile = field("cloneFilePath").toString();
     59
    5560    /* Should we reinit mac status? */
    5661    bool fReinitMACs = field("reinitMACs").toBool();
     
    118123
    119124    /* Create a new machine object. */
    120     const QString &strSettingsFile = vbox.ComposeMachineFilename(strName, QString::null /**< @todo group support */, QString::null, QString::null);
    121125    CMachine cloneMachine = vbox.CreateMachine(strSettingsFile, strName, QVector<QString>(), QString::null, QString::null);
    122126    if (!vbox.isOk())
     
    175179void UIWizardCloneVM::prepare()
    176180{
     181    QString strDefaultMachineFolder = vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
    177182    /* Create corresponding pages: */
    178183    switch (mode())
     
    180185        case WizardMode_Basic:
    181186        {
    182             setPage(Page1, new UIWizardCloneVMPageBasic1(m_machine.GetName()));
     187            setPage(Page1, new UIWizardCloneVMPageBasic1(m_machine.GetName(), strDefaultMachineFolder));
    183188            setPage(Page2, new UIWizardCloneVMPageBasic2(m_snapshot.isNull()));
    184189            if (m_machine.GetSnapshotCount() > 0)
     
    189194        {
    190195            setPage(PageExpert, new UIWizardCloneVMPageExpert(m_machine.GetName(),
     196                                                              strDefaultMachineFolder,
    191197                                                              m_snapshot.isNull(),
    192198                                                              m_snapshot.isNull() ? false : m_snapshot.GetChildrenCount() > 0));
     
    202208    UIWizard::prepare();
    203209}
    204 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageBasic1.cpp

    r70805 r72199  
    2626
    2727/* GUI includes: */
     28# include "QIRichTextLabel.h"
     29# include "UIVMNamePathSelector.h"
     30# include "UIWizardCloneVM.h"
    2831# include "UIWizardCloneVMPageBasic1.h"
    29 # include "UIWizardCloneVM.h"
    30 # include "QIRichTextLabel.h"
     32# include "VBoxGlobal.h"
     33
     34/* COM includes: */
     35# include "CVirtualBox.h"
    3136
    3237#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    3338
    3439
    35 UIWizardCloneVMPage1::UIWizardCloneVMPage1(const QString &strOriginalName)
     40UIWizardCloneVMPage1::UIWizardCloneVMPage1(const QString &strOriginalName, const QString &strDefaultPath)
    3641    : m_strOriginalName(strOriginalName)
     42    , m_strDefaultPath(strDefaultPath)
    3743{
    3844}
     
    4046QString UIWizardCloneVMPage1::cloneName() const
    4147{
    42     return m_pNameEditor->text();
     48    return m_pNamePathSelector->name();
    4349}
    4450
    4551void UIWizardCloneVMPage1::setCloneName(const QString &strName)
    4652{
    47     m_pNameEditor->setText(strName);
     53    m_pNamePathSelector->setName(strName);
    4854}
     55
     56QString UIWizardCloneVMPage1::clonePath() const
     57{
     58    if (!m_pNamePathSelector)
     59        return QString();
     60    return m_pNamePathSelector->path();
     61}
     62
     63void UIWizardCloneVMPage1::setClonePath(const QString &strPath)
     64{
     65    m_pNamePathSelector->setPath(strPath);
     66}
     67
     68QString UIWizardCloneVMPage1::cloneFilePath() const
     69{
     70    return m_strCloneFilePath;
     71}
     72
     73void UIWizardCloneVMPage1::setCloneFilePath(const QString &path)
     74{
     75    if (m_strCloneFilePath == path)
     76        return;
     77    m_strCloneFilePath = path;
     78}
     79
    4980
    5081bool UIWizardCloneVMPage1::isReinitMACsChecked() const
     
    5384}
    5485
    55 UIWizardCloneVMPageBasic1::UIWizardCloneVMPageBasic1(const QString &strOriginalName)
    56     : UIWizardCloneVMPage1(strOriginalName)
     86void UIWizardCloneVMPage1::composeCloneFilePath()
     87{
     88    CVirtualBox vbox = vboxGlobal().virtualBox();
     89    setCloneFilePath(vbox.ComposeMachineFilename(m_pNamePathSelector->name(),
     90                                                 QString::null,
     91                                                 QString::null,
     92                                                 m_pNamePathSelector->path()));
     93    const QFileInfo fileInfo(m_strCloneFilePath);
     94    m_strCloneFolder = fileInfo.absolutePath();
     95    if (m_pNamePathSelector)
     96        m_pNamePathSelector->setToolTipText(m_strCloneFolder);
     97}
     98
     99UIWizardCloneVMPageBasic1::UIWizardCloneVMPageBasic1(const QString &strOriginalName, const QString &strDefaultPath)
     100    : UIWizardCloneVMPage1(strOriginalName, strDefaultPath)
    57101{
    58102    /* Create widgets: */
     
    60104    {
    61105        m_pLabel = new QIRichTextLabel(this);
    62         m_pNameEditor = new QLineEdit(this);
     106        if (m_pLabel)
    63107        {
    64             m_pNameEditor->setText(UIWizardCloneVM::tr("%1 Clone").arg(m_strOriginalName));
     108            pMainLayout->addWidget(m_pLabel);
    65109        }
     110
     111        m_pNamePathSelector = new UIVMNamePathSelector(this);
     112        if (m_pNamePathSelector)
     113        {
     114            pMainLayout->addWidget(m_pNamePathSelector);
     115            m_pNamePathSelector->setName(UIWizardCloneVM::tr("%1 Clone").arg(m_strOriginalName));
     116            m_pNamePathSelector->setPath(m_strDefaultPath);
     117        }
     118
    66119        m_pReinitMACsCheckBox = new QCheckBox(this);
    67         pMainLayout->addWidget(m_pLabel);
    68         pMainLayout->addWidget(m_pNameEditor);
    69         pMainLayout->addWidget(m_pReinitMACsCheckBox);
     120
     121        if (m_pReinitMACsCheckBox)
     122        {
     123            pMainLayout->addWidget(m_pReinitMACsCheckBox);
     124        }
    70125        pMainLayout->addStretch();
    71126    }
    72127
    73128    /* Setup connections: */
    74     connect(m_pNameEditor, &QLineEdit::textChanged, this, &UIWizardCloneVMPageBasic1::completeChanged);
     129    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigNameChanged, this, &UIWizardCloneVMPageBasic1::completeChanged);
     130    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigPathChanged, this, &UIWizardCloneVMPageBasic1::completeChanged);
     131
     132    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigNameChanged, this, &UIWizardCloneVMPageBasic1::sltNameChanged);
     133    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigPathChanged, this, &UIWizardCloneVMPageBasic1::sltPathChanged);
    75134
    76135    /* Register fields: */
    77136    registerField("cloneName", this, "cloneName");
     137    registerField("clonePath", this, "clonePath");
    78138    registerField("reinitMACs", this, "reinitMACs");
    79139}
     
    85145
    86146    /* Translate widgets: */
    87     m_pLabel->setText(UIWizardCloneVM::tr("<p>Please choose a name for the new virtual machine. "
     147    m_pLabel->setText(UIWizardCloneVM::tr("<p>Please choose a folder and a name for the new virtual machine. "
    88148                                          "The new machine will be a clone of the machine <b>%1</b>.</p>")
    89149                                          .arg(m_strOriginalName));
     
    100160bool UIWizardCloneVMPageBasic1::isComplete() const
    101161{
     162    if (!m_pNamePathSelector)
     163        return false;
     164
     165    QString path = m_pNamePathSelector->path();
     166    if (path.isEmpty())
     167        return false;
    102168    /* Make sure VM name feat the rules: */
    103     QString strName = m_pNameEditor->text().trimmed();
     169    QString strName = m_pNamePathSelector->name().trimmed();
    104170    return !strName.isEmpty() && strName != m_strOriginalName;
    105171}
    106172
     173void UIWizardCloneVMPageBasic1::sltNameChanged()
     174{
     175    composeCloneFilePath();
     176}
     177
     178void UIWizardCloneVMPageBasic1::sltPathChanged()
     179{
     180    composeCloneFilePath();
     181}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageBasic1.h

    r69500 r72199  
    2626class QCheckBox;
    2727class QIRichTextLabel;
     28class UIVMNamePathSelector;
    2829
    2930/* 1st page of the Clone Virtual Machine wizard (base part): */
     
    3233protected:
    3334
    34     /* Constructor: */
    35     UIWizardCloneVMPage1(const QString &strOriginalName);
     35    UIWizardCloneVMPage1(const QString &strOriginalName, const QString &strDefaultPath);
    3636
    37     /* Stuff for 'cloneName' field: */
    3837    QString cloneName() const;
    39     void setCloneName(const QString &strName);
     38    void    setCloneName(const QString &strName);
    4039
    41     /* Stuff for 'reinitMACs' field: */
     40    QString clonePath() const;
     41    void     setClonePath(const QString &strName);
     42
     43    QString cloneFilePath() const;
     44    void setCloneFilePath(const QString &path);
     45
    4246    bool isReinitMACsChecked() const;
     47    /** calls CVirtualBox::ComposeMachineFilename(...) and sets related member variables */
     48    void composeCloneFilePath();
    4349
    44     /* Variables: */
    45     QString m_strOriginalName;
     50    QString    m_strOriginalName;
     51    QString    m_strDefaultPath;
     52    /** Full, non-native path of the clone machines setting file. Generated by CVirtualBox::ComposeMachineFilename(...) */
     53    QString    m_strCloneFilePath;
     54    /** The full path of the folder where clone machine's settings file is located.
     55     * Generated from the m_strCloneFilePath by removing base file name */
     56    QString    m_strCloneFolder;
     57    QCheckBox *m_pReinitMACsCheckBox;
     58    UIVMNamePathSelector *m_pNamePathSelector;
    4659
    47     /* Widgets: */
    48     QLineEdit *m_pNameEditor;
    49     QCheckBox *m_pReinitMACsCheckBox;
    5060};
    5161
     
    5565    Q_OBJECT;
    5666    Q_PROPERTY(QString cloneName READ cloneName WRITE setCloneName);
     67    Q_PROPERTY(QString clonePath READ clonePath WRITE setClonePath);
     68    Q_PROPERTY(QString cloneFilePath READ cloneFilePath WRITE setCloneFilePath);
    5769    Q_PROPERTY(bool reinitMACs READ isReinitMACsChecked);
    5870
    5971public:
    6072
    61     /* Constructor: */
    62     UIWizardCloneVMPageBasic1(const QString &strOriginalName);
     73    UIWizardCloneVMPageBasic1(const QString &strOriginalName, const QString &strDefaultPath);
     74
     75private slots:
     76
     77    void sltNameChanged();
     78    void sltPathChanged();
    6379
    6480private:
    6581
    66     /* Translation stuff: */
    6782    void retranslateUi();
    68 
    69     /* Prepare stuff: */
    7083    void initializePage();
    7184
     
    7386    bool isComplete() const;
    7487
    75     /* Widgets: */
    7688    QIRichTextLabel *m_pLabel;
    7789};
    7890
    7991#endif // __UIWizardCloneVMPageBasic1_h__
    80 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageExpert.cpp

    r70805 r72199  
    2929
    3030/* Local includes: */
     31# include "UIVMNamePathSelector.h"
    3132# include "UIWizardCloneVMPageExpert.h"
    3233# include "UIWizardCloneVM.h"
     
    3536
    3637
    37 UIWizardCloneVMPageExpert::UIWizardCloneVMPageExpert(const QString &strOriginalName, bool fAdditionalInfo, bool fShowChildsOption)
    38     : UIWizardCloneVMPage1(strOriginalName)
     38UIWizardCloneVMPageExpert::UIWizardCloneVMPageExpert(const QString &strOriginalName, const QString &strDefaultPath, bool fAdditionalInfo, bool fShowChildsOption)
     39    : UIWizardCloneVMPage1(strOriginalName, strDefaultPath)
    3940    , UIWizardCloneVMPage2(fAdditionalInfo)
    4041    , UIWizardCloneVMPage3(fShowChildsOption)
     
    4748            QVBoxLayout *pNameCntLayout = new QVBoxLayout(m_pNameCnt);
    4849            {
    49                 m_pNameEditor = new QLineEdit(m_pNameCnt);
     50                m_pNamePathSelector = new UIVMNamePathSelector(m_pNameCnt);
    5051                {
    51                     m_pNameEditor->setText(UIWizardCloneVM::tr("%1 Clone").arg(m_strOriginalName));
     52                    m_pNamePathSelector->setName(UIWizardCloneVM::tr("%1 Clone").arg(m_strOriginalName));
    5253                }
    53                 pNameCntLayout->addWidget(m_pNameEditor);
     54                pNameCntLayout->addWidget(m_pNamePathSelector);
    5455            }
    5556        }
     
    101102
    102103    /* Setup connections: */
    103     connect(m_pNameEditor, &QLineEdit::textChanged,
     104    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigNameChanged,
    104105            this, &UIWizardCloneVMPageExpert::completeChanged);
     106    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigPathChanged,
     107            this, &UIWizardCloneVMPageExpert::completeChanged);
     108    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigNameChanged,
     109            this, &UIWizardCloneVMPageExpert::sltNameChanged);
     110    connect(m_pNamePathSelector, &UIVMNamePathSelector::sigPathChanged,
     111            this, &UIWizardCloneVMPageExpert::sltPathChanged);
    105112    connect(m_pButtonGroup, static_cast<void(QButtonGroup::*)(QAbstractButton*)>(&QButtonGroup::buttonClicked),
    106113            this, &UIWizardCloneVMPageExpert::sltButtonClicked);
     
    110117    /* Register fields: */
    111118    registerField("cloneName", this, "cloneName");
     119    registerField("clonePath", this, "clonePath");
    112120    registerField("reinitMACs", this, "reinitMACs");
    113121    registerField("linkedClone", this, "linkedClone");
    114122    registerField("cloneMode", this, "cloneMode");
     123    composeCloneFilePath();
    115124}
    116125
     
    144153bool UIWizardCloneVMPageExpert::isComplete() const
    145154{
     155    if (!m_pNamePathSelector)
     156        return false;
     157
     158    QString path = m_pNamePathSelector->path();
     159    if (path.isEmpty())
     160        return false;
    146161    /* Make sure VM name feat the rules: */
    147     QString strName = m_pNameEditor->text().trimmed();
     162    QString strName = m_pNamePathSelector->name().trimmed();
    148163    return !strName.isEmpty() && strName != m_strOriginalName;
    149164}
     
    168183}
    169184
     185void UIWizardCloneVMPageExpert::sltNameChanged()
     186{
     187    composeCloneFilePath();
     188}
     189
     190void UIWizardCloneVMPageExpert::sltPathChanged()
     191{
     192    composeCloneFilePath();
     193}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/clonevm/UIWizardCloneVMPageExpert.h

    r69500 r72199  
    3535    Q_OBJECT;
    3636    Q_PROPERTY(QString cloneName READ cloneName WRITE setCloneName);
     37    Q_PROPERTY(QString clonePath READ clonePath WRITE setClonePath);
    3738    Q_PROPERTY(bool reinitMACs READ isReinitMACsChecked);
    3839    Q_PROPERTY(bool linkedClone READ isLinkedClone);
     
    4243
    4344    /* Constructor: */
    44     UIWizardCloneVMPageExpert(const QString &strOriginalName, bool fAdditionalInfo, bool fShowChildsOption);
     45    UIWizardCloneVMPageExpert(const QString &strOriginalName, const QString &strDefaultPath,
     46                              bool fAdditionalInfo, bool fShowChildsOption);
    4547
    4648private slots:
     
    4850    /* Button click handler: */
    4951    void sltButtonClicked(QAbstractButton *pButton);
     52    void sltNameChanged();
     53    void sltPathChanged();
    5054
    5155private:
     
    6872
    6973#endif // __UIWizardCloneVMPageExpert_h__
    70 
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UIWizardNewVMPageBasic1.cpp

    r72191 r72199  
    236236
    237237    if (m_pNameAndSystemEditor)
    238         m_pNameAndSystemEditor->setMachineFilePath(m_strMachineFolder);
     238        m_pNameAndSystemEditor->setMachineFolder(m_strMachineFolder);
    239239}
    240240
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