VirtualBox

Changeset 33667 in vbox


Ignore:
Timestamp:
Nov 2, 2010 12:42:16 AM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
67287
Message:

FE/Qt: 5302: Reworking New VM wizard and New HD wizard for VBox config 4.0.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/wizards
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.cpp

    r33238 r33667  
    7474}
    7575
    76 QString UINewHDWzd::composeFullFileName(const QString &strFileName)
    77 {
    78     CVirtualBox vbox = vboxGlobal().virtualBox();
    79     QString strHomeFolder = vbox.GetHomeFolder();
    80     QString strDefaultFolder = vbox.GetHomeFolder();
    81 
     76void UINewHDWzd::setDefaultPath(const QString &strDefaultPath)
     77{
     78    m_strDefaultPath = strDefaultPath;
     79}
     80
     81QString UINewHDWzd::absoluteFilePath(const QString &strFileName)
     82{
     83    /* Wrap file-info around received file name: */
    8284    QFileInfo fi(strFileName);
    83     if (fi.fileName() == strFileName)
    84     {
    85         /* No path info at all, use strDefaultFolder */
    86         fi = QFileInfo(strDefaultFolder, strFileName);
    87     }
    88     else if (fi.isRelative())
    89     {
    90         /* Resolve relatively to strHomeFolder */
    91         fi = QFileInfo(strHomeFolder, strFileName);
    92     }
    93 
     85    /* If there is no path info at all or its relative: */
     86    if (fi.fileName() == strFileName || fi.isRelative())
     87    {
     88        /* Resolve path on the basis of m_strDefaultPath: */
     89        fi = QFileInfo(m_strDefaultPath, strFileName);
     90    }
     91    /* Return full absolute hard disk file path: */
    9492    return QDir::toNativeSeparators(fi.absoluteFilePath());
    9593}
     
    287285bool UINewHDWzdPage3::validatePage()
    288286{
    289     QString location = UINewHDWzd::composeFullFileName(m_strLocation);
     287    QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(m_strLocation);
    290288    if (QFileInfo(location).exists())
    291289    {
     
    310308void UINewHDWzdPage3::onSelectLocationButtonClicked()
    311309{
    312     /* Set the first parent directory that exists as the current */
    313     QFileInfo fullFilePath(UINewHDWzd::composeFullFileName(m_strLocation));
     310    /* Get parent wizard: */
     311    UINewHDWzd *pWizard = qobject_cast<UINewHDWzd*>(wizard());
     312
     313    /* Get current folder and filename: */
     314    QFileInfo fullFilePath(pWizard->absoluteFilePath(m_strLocation));
    314315    QDir folder = fullFilePath.path();
    315     QString fileName = fullFilePath.fileName();
    316 
     316    QString strFileName = fullFilePath.fileName();
     317
     318    /* Set the first parent foler that exists as the current: */
    317319    while (!folder.exists() && !folder.isRoot())
    318320        folder = QFileInfo(folder.absolutePath()).dir();
    319321
     322    /* But if it doesn't exists at all: */
    320323    if (!folder.exists() || folder.isRoot())
    321324    {
    322         CVirtualBox vbox = vboxGlobal().virtualBox();
    323         folder = vbox.GetHomeFolder();          // @todo machine folder?
    324         if (!folder.exists())
    325             folder = vbox.GetHomeFolder();
     325        /* Use recommended one folder: */
     326        QFileInfo defaultFilePath(pWizard->absoluteFilePath(strFileName));
     327        folder = defaultFilePath.path();
    326328    }
    327329
    328330    QString selected = QFileDialog::getSaveFileName(this, tr("Select a file for the new hard disk image file"),
    329                                                     folder.absoluteFilePath(fileName), tr("Hard disk images (*.vdi)"));
     331                                                    folder.absoluteFilePath(strFileName), tr("Hard disk images (*.vdi)"));
    330332
    331333    if (!selected.isEmpty())
     
    445447
    446448    QString type = field("type").toString();
    447     QString location = UINewHDWzd::composeFullFileName(field("location").toString());
     449    QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(field("location").toString());
    448450    QString sizeFormatted = VBoxGlobal::formatSize(field("currentSize").toULongLong());
    449451    QString sizeUnformatted = tr("%1 B").arg(field("currentSize").toULongLong());
     
    487489{
    488490    KMediumVariant variant = KMediumVariant_Standard;
    489     QString loc = field("location").toString();
     491    QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(field("location").toString());
    490492    qulonglong size = field("currentSize").toULongLong();
    491493    bool isFixed = field("fixed").toBool();
    492494
    493     AssertReturn(!loc.isNull(), false);
     495    AssertReturn(!location.isNull(), false);
    494496    AssertReturn(size > 0, false);
    495497
     
    498500    CProgress progress;
    499501
    500     CMedium hardDisk = vbox.CreateHardDisk(QString("VDI"), loc);
     502    CMedium hardDisk = vbox.CreateHardDisk(QString("VDI"), location);
    501503
    502504    if (!vbox.isOk())
    503505    {
    504         vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc, hardDisk, progress);
     506        vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress);
    505507        return false;
    506508    }
     
    513515    if (!hardDisk.isOk())
    514516    {
    515         vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc, hardDisk, progress);
     517        vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress);
    516518        return false;
    517519    }
     
    524526    if (!progress.isOk() || progress.GetResultCode() != 0)
    525527    {
    526         vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc, hardDisk, progress);
     528        vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress);
    527529        return false;
    528530    }
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.h

    r29131 r33667  
    4343    void setRecommendedSize(qulonglong uSize);
    4444
    45     static QString composeFullFileName(const QString &strFileName);
    46 
    47 protected:
    48 
    49     void retranslateUi();
     45    void setDefaultPath(const QString &strPath);
     46    QString absoluteFilePath(const QString &strFileName);
     47
     48protected:
     49
     50    void retranslateUi();
     51
     52private:
     53
     54    QString m_strDefaultPath;
    5055};
    5156
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp

    r33465 r33667  
    1717 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
    1818 */
     19
     20/* Global includes */
     21#include <QDir>
    1922
    2023/* Local includes */
     
    198201    registerField("name*", m_pNameEditor);
    199202    registerField("type*", m_pTypeSelector, "type", SIGNAL(osTypeChanged()));
     203    registerField("machineFolder", this, "machineFolder");
    200204
    201205    connect(m_pNameEditor, SIGNAL(textChanged(const QString&)),
     
    206210    /* Setup contents */
    207211    m_pTypeSelector->activateLayout();
    208 }
    209 
    210 void UINewVMWzdPage2::retranslateUi()
    211 {
    212     /* Translate uic generated strings */
    213     Ui::UINewVMWzdPage2::retranslateUi(this);
    214 
    215     /* Wizard page 2 title */
    216     setTitle(tr("VM Name and OS Type"));
    217 }
    218 
    219 void UINewVMWzdPage2::initializePage()
    220 {
    221     /* Fill and translate */
    222     retranslateUi();
    223 
    224     /* 'Name' field should have focus initially */
    225     m_pNameEditor->setFocus();
    226212}
    227213
     
    248234}
    249235
     236void UINewVMWzdPage2::retranslateUi()
     237{
     238    /* Translate uic generated strings */
     239    Ui::UINewVMWzdPage2::retranslateUi(this);
     240
     241    /* Wizard page 2 title */
     242    setTitle(tr("VM Name and OS Type"));
     243}
     244
     245void UINewVMWzdPage2::initializePage()
     246{
     247    /* Fill and translate */
     248    retranslateUi();
     249
     250    /* 'Name' field should have focus initially */
     251    m_pNameEditor->setFocus();
     252}
     253
     254void UINewVMWzdPage2::cleanupPage()
     255{
     256    cleanupMachineFolder();
     257}
     258
     259bool UINewVMWzdPage2::validatePage()
     260{
     261    return createMachineFolder();
     262}
     263
     264bool UINewVMWzdPage2::createMachineFolder()
     265{
     266    /* Cleanup old folder if present: */
     267    cleanupMachineFolder();
     268    /* Get VBox: */
     269    CVirtualBox vbox = vboxGlobal().virtualBox();
     270    /* Get default machines directory: */
     271    QString strDefaultMachinesFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
     272    /* Compose machine filename name: */
     273    QString strMachineFilename = vbox.ComposeMachineFilename(field("name").toString(), strDefaultMachinesFolder);
     274    QFileInfo fileInfo(strMachineFilename);
     275    /* Get machine directory: */
     276    QString strMachineFolder = fileInfo.absolutePath();
     277    /* Try to create this machine directory (and it's predecessors): */
     278    bool fMachineFolderCreated = QDir().mkpath(strMachineFolder);
     279    /* Initialize machine dir value: */
     280    if (fMachineFolderCreated)
     281        m_strMachineFolder = strMachineFolder;
     282    /* Return creation result: */
     283    return fMachineFolderCreated;
     284}
     285
     286bool UINewVMWzdPage2::cleanupMachineFolder()
     287{
     288    /* Return if machine folder was NOT set: */
     289    if (m_strMachineFolder.isEmpty())
     290        return false;
     291    /* Try to cleanup this machine directory (and it's predecessors): */
     292    bool fMachineFolderRemoved = QDir().rmpath(m_strMachineFolder);
     293    /* Reset machine dir value: */
     294    if (fMachineFolderRemoved)
     295        m_strMachineFolder = QString();
     296    /* Return cleanup result: */
     297    return fMachineFolderRemoved;
     298}
     299
     300QString UINewVMWzdPage2::machineFolder() const
     301{
     302    return m_strMachineFolder;
     303}
     304
     305void UINewVMWzdPage2::setMachineFolder(const QString &strMachineFolder)
     306{
     307    m_strMachineFolder = strMachineFolder;
     308}
     309
    250310UINewVMWzdPage3::UINewVMWzdPage3()
    251311{
     
    494554    dlg.setRecommendedName(field("name").toString());
    495555    dlg.setRecommendedSize(field("type").value<CGuestOSType>().GetRecommendedHDD());
     556    dlg.setDefaultPath(field("machineFolder").toString());
    496557
    497558    if (dlg.exec() == QDialog::Accepted)
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.h

    r29897 r33667  
    6666{
    6767    Q_OBJECT;
     68    Q_PROPERTY(QString machineFolder READ machineFolder WRITE setMachineFolder);
    6869
    6970public:
     
    8182
    8283    void initializePage();
     84    void cleanupPage();
     85
     86    bool validatePage();
     87
     88private:
     89
     90    bool createMachineFolder();
     91    bool cleanupMachineFolder();
     92
     93    QString machineFolder() const;
     94    void setMachineFolder(const QString &strMachineFolder);
     95    QString m_strMachineFolder;
    8396};
    8497
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