Index: /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.cpp	(revision 33666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.cpp	(revision 33667)
@@ -74,22 +74,20 @@
 }
 
-QString UINewHDWzd::composeFullFileName(const QString &strFileName)
-{
-    CVirtualBox vbox = vboxGlobal().virtualBox();
-    QString strHomeFolder = vbox.GetHomeFolder();
-    QString strDefaultFolder = vbox.GetHomeFolder();
-
+void UINewHDWzd::setDefaultPath(const QString &strDefaultPath)
+{
+    m_strDefaultPath = strDefaultPath;
+}
+
+QString UINewHDWzd::absoluteFilePath(const QString &strFileName)
+{
+    /* Wrap file-info around received file name: */
     QFileInfo fi(strFileName);
-    if (fi.fileName() == strFileName)
-    {
-        /* No path info at all, use strDefaultFolder */
-        fi = QFileInfo(strDefaultFolder, strFileName);
-    }
-    else if (fi.isRelative())
-    {
-        /* Resolve relatively to strHomeFolder */
-        fi = QFileInfo(strHomeFolder, strFileName);
-    }
-
+    /* If there is no path info at all or its relative: */
+    if (fi.fileName() == strFileName || fi.isRelative())
+    {
+        /* Resolve path on the basis of m_strDefaultPath: */
+        fi = QFileInfo(m_strDefaultPath, strFileName);
+    }
+    /* Return full absolute hard disk file path: */
     return QDir::toNativeSeparators(fi.absoluteFilePath());
 }
@@ -287,5 +285,5 @@
 bool UINewHDWzdPage3::validatePage()
 {
-    QString location = UINewHDWzd::composeFullFileName(m_strLocation);
+    QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(m_strLocation);
     if (QFileInfo(location).exists())
     {
@@ -310,22 +308,26 @@
 void UINewHDWzdPage3::onSelectLocationButtonClicked()
 {
-    /* Set the first parent directory that exists as the current */
-    QFileInfo fullFilePath(UINewHDWzd::composeFullFileName(m_strLocation));
+    /* Get parent wizard: */
+    UINewHDWzd *pWizard = qobject_cast<UINewHDWzd*>(wizard());
+
+    /* Get current folder and filename: */
+    QFileInfo fullFilePath(pWizard->absoluteFilePath(m_strLocation));
     QDir folder = fullFilePath.path();
-    QString fileName = fullFilePath.fileName();
-
+    QString strFileName = fullFilePath.fileName();
+
+    /* Set the first parent foler that exists as the current: */
     while (!folder.exists() && !folder.isRoot())
         folder = QFileInfo(folder.absolutePath()).dir();
 
+    /* But if it doesn't exists at all: */
     if (!folder.exists() || folder.isRoot())
     {
-        CVirtualBox vbox = vboxGlobal().virtualBox();
-        folder = vbox.GetHomeFolder();          // @todo machine folder?
-        if (!folder.exists())
-            folder = vbox.GetHomeFolder();
+        /* Use recommended one folder: */
+        QFileInfo defaultFilePath(pWizard->absoluteFilePath(strFileName));
+        folder = defaultFilePath.path();
     }
 
     QString selected = QFileDialog::getSaveFileName(this, tr("Select a file for the new hard disk image file"),
-                                                    folder.absoluteFilePath(fileName), tr("Hard disk images (*.vdi)"));
+                                                    folder.absoluteFilePath(strFileName), tr("Hard disk images (*.vdi)"));
 
     if (!selected.isEmpty())
@@ -445,5 +447,5 @@
 
     QString type = field("type").toString();
-    QString location = UINewHDWzd::composeFullFileName(field("location").toString());
+    QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(field("location").toString());
     QString sizeFormatted = VBoxGlobal::formatSize(field("currentSize").toULongLong());
     QString sizeUnformatted = tr("%1 B").arg(field("currentSize").toULongLong());
@@ -487,9 +489,9 @@
 {
     KMediumVariant variant = KMediumVariant_Standard;
-    QString loc = field("location").toString();
+    QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(field("location").toString());
     qulonglong size = field("currentSize").toULongLong();
     bool isFixed = field("fixed").toBool();
 
-    AssertReturn(!loc.isNull(), false);
+    AssertReturn(!location.isNull(), false);
     AssertReturn(size > 0, false);
 
@@ -498,9 +500,9 @@
     CProgress progress;
 
-    CMedium hardDisk = vbox.CreateHardDisk(QString("VDI"), loc);
+    CMedium hardDisk = vbox.CreateHardDisk(QString("VDI"), location);
 
     if (!vbox.isOk())
     {
-        vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc, hardDisk, progress);
+        vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress);
         return false;
     }
@@ -513,5 +515,5 @@
     if (!hardDisk.isOk())
     {
-        vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc, hardDisk, progress);
+        vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress);
         return false;
     }
@@ -524,5 +526,5 @@
     if (!progress.isOk() || progress.GetResultCode() != 0)
     {
-        vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc, hardDisk, progress);
+        vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress);
         return false;
     }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.h	(revision 33666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.h	(revision 33667)
@@ -43,9 +43,14 @@
     void setRecommendedSize(qulonglong uSize);
 
-    static QString composeFullFileName(const QString &strFileName);
-
-protected:
-
-    void retranslateUi();
+    void setDefaultPath(const QString &strPath);
+    QString absoluteFilePath(const QString &strFileName);
+
+protected:
+
+    void retranslateUi();
+
+private:
+
+    QString m_strDefaultPath;
 };
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp	(revision 33666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp	(revision 33667)
@@ -17,4 +17,7 @@
  * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
  */
+
+/* Global includes */
+#include <QDir>
 
 /* Local includes */
@@ -198,4 +201,5 @@
     registerField("name*", m_pNameEditor);
     registerField("type*", m_pTypeSelector, "type", SIGNAL(osTypeChanged()));
+    registerField("machineFolder", this, "machineFolder");
 
     connect(m_pNameEditor, SIGNAL(textChanged(const QString&)),
@@ -206,22 +210,4 @@
     /* Setup contents */
     m_pTypeSelector->activateLayout();
-}
-
-void UINewVMWzdPage2::retranslateUi()
-{
-    /* Translate uic generated strings */
-    Ui::UINewVMWzdPage2::retranslateUi(this);
-
-    /* Wizard page 2 title */
-    setTitle(tr("VM Name and OS Type"));
-}
-
-void UINewVMWzdPage2::initializePage()
-{
-    /* Fill and translate */
-    retranslateUi();
-
-    /* 'Name' field should have focus initially */
-    m_pNameEditor->setFocus();
 }
 
@@ -248,4 +234,78 @@
 }
 
+void UINewVMWzdPage2::retranslateUi()
+{
+    /* Translate uic generated strings */
+    Ui::UINewVMWzdPage2::retranslateUi(this);
+
+    /* Wizard page 2 title */
+    setTitle(tr("VM Name and OS Type"));
+}
+
+void UINewVMWzdPage2::initializePage()
+{
+    /* Fill and translate */
+    retranslateUi();
+
+    /* 'Name' field should have focus initially */
+    m_pNameEditor->setFocus();
+}
+
+void UINewVMWzdPage2::cleanupPage()
+{
+    cleanupMachineFolder();
+}
+
+bool UINewVMWzdPage2::validatePage()
+{
+    return createMachineFolder();
+}
+
+bool UINewVMWzdPage2::createMachineFolder()
+{
+    /* Cleanup old folder if present: */
+    cleanupMachineFolder();
+    /* Get VBox: */
+    CVirtualBox vbox = vboxGlobal().virtualBox();
+    /* Get default machines directory: */
+    QString strDefaultMachinesFolder = vbox.GetSystemProperties().GetDefaultMachineFolder();
+    /* Compose machine filename name: */
+    QString strMachineFilename = vbox.ComposeMachineFilename(field("name").toString(), strDefaultMachinesFolder);
+    QFileInfo fileInfo(strMachineFilename);
+    /* Get machine directory: */
+    QString strMachineFolder = fileInfo.absolutePath();
+    /* Try to create this machine directory (and it's predecessors): */
+    bool fMachineFolderCreated = QDir().mkpath(strMachineFolder);
+    /* Initialize machine dir value: */
+    if (fMachineFolderCreated)
+        m_strMachineFolder = strMachineFolder;
+    /* Return creation result: */
+    return fMachineFolderCreated;
+}
+
+bool UINewVMWzdPage2::cleanupMachineFolder()
+{
+    /* Return if machine folder was NOT set: */
+    if (m_strMachineFolder.isEmpty())
+        return false;
+    /* Try to cleanup this machine directory (and it's predecessors): */
+    bool fMachineFolderRemoved = QDir().rmpath(m_strMachineFolder);
+    /* Reset machine dir value: */
+    if (fMachineFolderRemoved)
+        m_strMachineFolder = QString();
+    /* Return cleanup result: */
+    return fMachineFolderRemoved;
+}
+
+QString UINewVMWzdPage2::machineFolder() const
+{
+    return m_strMachineFolder;
+}
+
+void UINewVMWzdPage2::setMachineFolder(const QString &strMachineFolder)
+{
+    m_strMachineFolder = strMachineFolder;
+}
+
 UINewVMWzdPage3::UINewVMWzdPage3()
 {
@@ -494,4 +554,5 @@
     dlg.setRecommendedName(field("name").toString());
     dlg.setRecommendedSize(field("type").value<CGuestOSType>().GetRecommendedHDD());
+    dlg.setDefaultPath(field("machineFolder").toString());
 
     if (dlg.exec() == QDialog::Accepted)
Index: /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.h	(revision 33666)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.h	(revision 33667)
@@ -66,4 +66,5 @@
 {
     Q_OBJECT;
+    Q_PROPERTY(QString machineFolder READ machineFolder WRITE setMachineFolder);
 
 public:
@@ -81,4 +82,16 @@
 
     void initializePage();
+    void cleanupPage();
+
+    bool validatePage();
+
+private:
+
+    bool createMachineFolder();
+    bool cleanupMachineFolder();
+
+    QString machineFolder() const;
+    void setMachineFolder(const QString &strMachineFolder);
+    QString m_strMachineFolder;
 };
 
