VirtualBox

Changeset 72869 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 4, 2018 11:31:55 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
123414
Message:

FE/Qt: bugref:9083 Adding a create floppy dialog to the UIMediumSelector. fix take

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h

    r72347 r72869  
    539539
    540540#endif /* !___UIMessageCenter_h___ */
    541 
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.cpp

    r72815 r72869  
    2121
    2222/* Qt includes */
    23 # include<QVBoxLayout>
    24 
    25 /* Other includes */
     23# include<QDialogButtonBox>
     24# include<QDir>
     25# include<QGridLayout>
     26# include<QLabel>
     27# include<QPushButton>
     28
     29/* GUI includes */
    2630# include "UIFDCreationDialog.h"
    2731# include "UIFilePathSelector.h"
     32# include "UIMessageCenter.h"
    2833# include "VBoxGlobal.h"
     34
     35/* COM includes: */
     36# include "CSystemProperties.h"
     37# include "CMedium.h"
     38# include "CMediumFormat.h"
    2939
    3040#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
     
    3848    , m_strMachineName(strMachineName)
    3949    , m_strMachineSettingsFilePath(strMachineSettingsFilePath)
     50    , m_pPathLabel(0)
     51    , m_pSizeLabel(0)
     52    , m_pSizeCombo(0)
     53    , m_pButtonBox(0)
    4054{
    4155
     
    5266void UIFDCreationDialog::retranslateUi()
    5367{
    54 
     68    setWindowTitle(QApplication::translate("UIMediumManager", "Create a Floppy Disk"));
     69    if (m_pPathLabel)
     70        m_pPathLabel->setText(QApplication::translate("UIMediumManager", "File Path:"));
     71    if (m_pSizeLabel)
     72        m_pSizeLabel->setText(QApplication::translate("UIMediumManager", "Size:"));
     73    if (m_pButtonBox)
     74        m_pButtonBox->button(QDialogButtonBox::Ok)->setText("Create");
     75    if (m_pSizeCombo)
     76    {
     77        m_pSizeCombo->setItemText(FDSize_2_88M, QApplication::translate("UIMediumManager", "2.88M"));
     78        m_pSizeCombo->setItemText(FDSize_1_44M, QApplication::translate("UIMediumManager", "1.44M"));
     79        m_pSizeCombo->setItemText(FDSize_1_2M, QApplication::translate("UIMediumManager", "1.2M"));
     80        m_pSizeCombo->setItemText(FDSize_720K, QApplication::translate("UIMediumManager", "720K"));
     81        m_pSizeCombo->setItemText(FDSize_360K, QApplication::translate("UIMediumManager", "360K"));
     82    }
    5583}
    5684
    5785void UIFDCreationDialog::prepare()
    5886{
     87
     88#ifndef VBOX_WS_MAC
     89    setWindowIcon(QIcon(":/vm_settings_16px.png"));
     90#endif
     91
    5992    setWindowModality(Qt::WindowModal);
    60 
    61     QVBoxLayout *pMainLayout = new QVBoxLayout;
     93    setSizeGripEnabled(false);
     94
     95
     96    QGridLayout *pMainLayout = new QGridLayout;
    6297    if (!pMainLayout)
    6398        return;
    6499    setLayout(pMainLayout);
     100
     101    m_pPathLabel = new QLabel;
     102    if (m_pPathLabel)
     103    {
     104        pMainLayout->addWidget(m_pPathLabel, 0, 0, 1, 1);
     105        m_pPathLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
     106    }
    65107
    66108    m_pFilePathselector = new UIFilePathSelector;
    67109    if (m_pFilePathselector)
    68110    {
    69         pMainLayout->addWidget(m_pFilePathselector);
     111        pMainLayout->addWidget(m_pFilePathselector, 0, 1, 1, 2);
    70112        m_pFilePathselector->setMode(UIFilePathSelector::Mode_File_Save);
    71     }
    72 }
     113        QString strFolder = getDefaultFolder();
     114        m_pFilePathselector->setDefaultPath(strFolder);
     115        m_pFilePathselector->setPath(strFolder);
     116    }
     117
     118    m_pSizeLabel = new QLabel;
     119    if (m_pSizeLabel)
     120    {
     121        pMainLayout->addWidget(m_pSizeLabel, 1, 0, 1, 1);
     122        m_pSizeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
     123    }
     124
     125    m_pSizeCombo = new QComboBox;
     126    if (m_pSizeCombo)
     127    {
     128        pMainLayout->addWidget(m_pSizeCombo, 1, 1, 1, 2);
     129        m_pSizeCombo->insertItem(FDSize_2_88M, "2.88M", 2949120);
     130        m_pSizeCombo->insertItem(FDSize_1_44M, "1.44M", 1474560);
     131        m_pSizeCombo->insertItem(FDSize_1_2M, "1.2M", 1228800);
     132        m_pSizeCombo->insertItem(FDSize_720K, "720K", 737280);
     133        m_pSizeCombo->insertItem(FDSize_360K, "360K", 368640);
     134        m_pSizeCombo->setCurrentIndex(FDSize_1_44M);
     135
     136    }
     137
     138    m_pButtonBox =
     139        new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this);
     140    if (m_pButtonBox)
     141    {
     142        pMainLayout->addWidget(m_pButtonBox, 2, 0, 1, 3);
     143        connect(m_pButtonBox, &QDialogButtonBox::accepted, this, &UIFDCreationDialog::accept);
     144        connect(m_pButtonBox, &QDialogButtonBox::rejected, this, &UIFDCreationDialog::reject);
     145    }
     146    retranslateUi();
     147}
     148
     149QString UIFDCreationDialog::getDefaultFolder() const
     150{
     151    QString strPreferredExtension = UIMediumDefs::getPreferredExtensionForMedium(KDeviceType_Floppy);
     152
     153    QString strInitialPath = QFileInfo(m_strMachineSettingsFilePath).absolutePath();
     154    if (strInitialPath.isEmpty())
     155        strInitialPath = vboxGlobal().virtualBox().GetSystemProperties().GetDefaultMachineFolder();
     156
     157    if (strInitialPath.isEmpty())
     158        return strInitialPath;
     159
     160    strInitialPath = QDir(strInitialPath).absoluteFilePath(m_strMachineName + "." + strPreferredExtension);
     161    return strInitialPath;
     162}
     163
     164void UIFDCreationDialog::accept()
     165{
     166    QVector<CMediumFormat>  mediumFormats = UIMediumDefs::getFormatsForDeviceType(KDeviceType_Floppy);
     167
     168    if (m_pFilePathselector->path().isEmpty() || mediumFormats.isEmpty())
     169        return;
     170
     171    CVirtualBox vbox = vboxGlobal().virtualBox();
     172
     173    CMedium newMedium = vbox.CreateMedium(mediumFormats[0].GetName(), m_pFilePathselector->path(),
     174                                          KAccessMode_ReadWrite, KDeviceType_Floppy);
     175    if (!vbox.isOk())
     176    {
     177        msgCenter().cannotCreateMediumStorage(vbox, m_pFilePathselector->path(), this);
     178        return;
     179    }
     180    QVector<KMediumVariant> variants(1, KMediumVariant_Fixed);
     181    CProgress progress = newMedium.CreateBaseStorage(m_pSizeCombo->currentData().toLongLong(), variants);
     182
     183    if (!newMedium.isOk())
     184    {
     185        msgCenter().cannotCreateMediumStorage(newMedium, m_pFilePathselector->path(), this);
     186        return;
     187    }
     188    /* Show creation progress: */
     189    msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this);
     190    if (progress.GetCanceled())
     191        return;
     192
     193    if (!progress.isOk() || progress.GetResultCode() != 0)
     194    {
     195        msgCenter().cannotCreateHardDiskStorage(progress, m_pFilePathselector->path(), this);
     196        return;
     197    }
     198
     199    /* After a successful creation and initilization of the floppy disk we call base class accept
     200       effectively closing this dialog: */
     201    QDialog::accept();
     202}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.h

    r72815 r72869  
    2727
    2828/* Forward declarations: */
     29class QDialogButtonBox;
     30class QLabel;
     31class QComboBox;
    2932class UIFilePathSelector;
    3033
     
    4043    UIFDCreationDialog(QWidget *pParent = 0,
    4144                       const QString &strMachineName = QString(),
    42                        const QString &strMachineSettingsFilePath = QString()
    43                        );
     45                       const QString &strMachineSettingsFilePath = QString());
     46
     47    virtual void accept() /* override */;
    4448
    4549protected:
     
    5155
    5256private:
    53 
    54     void prepare();
    55 
     57    enum FDSize
     58    {
     59        FDSize_2_88M,
     60        FDSize_1_44M,
     61        FDSize_1_2M,
     62        FDSize_720K,
     63        FDSize_360K
     64    };
     65    void                prepare();
     66    QString             getDefaultFolder() const;
    5667    UIFilePathSelector *m_pFilePathselector;
    5768    QString             m_strMachineName;
    5869    QString             m_strMachineSettingsFilePath;
     70    QLabel             *m_pPathLabel;
     71    QLabel             *m_pSizeLabel;
     72    QComboBox          *m_pSizeCombo;
     73    QDialogButtonBox   *m_pButtonBox;
    5974};
    6075
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp

    r72822 r72869  
    2222/* GUI includes: */
    2323# include "UIMediumDefs.h"
     24# include "VBoxGlobal.h"
     25
     26/* COM includes: */
     27# include "CMediumFormat.h"
     28# include "CSystemProperties.h"
    2429
    2530/* COM includes: */
     
    104109    return MediumBackends(comVBox, KDeviceType_Floppy);
    105110}
     111
     112QString UIMediumDefs::getPreferredExtensionForMedium(KDeviceType enmDeviceType)
     113{
     114    CSystemProperties comSystemProperties = vboxGlobal().virtualBox().GetSystemProperties();
     115    QVector<CMediumFormat> mediumFormats = comSystemProperties.GetMediumFormats();
     116    for (int i = 0; i < mediumFormats.size(); ++i)
     117    {
     118        /* File extensions */
     119        QVector <QString> fileExtensions;
     120        QVector <KDeviceType> deviceTypes;
     121
     122        mediumFormats[i].DescribeFileExtensions(fileExtensions, deviceTypes);
     123        if (fileExtensions.size() != deviceTypes.size())
     124            continue;
     125        for (int a = 0; a < fileExtensions.size(); ++a)
     126        {
     127            if (deviceTypes[a] == enmDeviceType)
     128                return fileExtensions[a];
     129        }
     130    }
     131    return QString();
     132}
     133
     134QVector<CMediumFormat> UIMediumDefs::getFormatsForDeviceType(KDeviceType enmDeviceType)
     135{
     136    CSystemProperties comSystemProperties = vboxGlobal().virtualBox().GetSystemProperties();
     137    QVector<CMediumFormat> mediumFormats = comSystemProperties.GetMediumFormats();
     138    QVector<CMediumFormat> formatList;
     139    for (int i = 0; i < mediumFormats.size(); ++i)
     140    {
     141        /* File extensions */
     142        QVector <QString> fileExtensions;
     143        QVector <KDeviceType> deviceTypes;
     144
     145        mediumFormats[i].DescribeFileExtensions(fileExtensions, deviceTypes);
     146        if (deviceTypes.contains(enmDeviceType))
     147            formatList.push_back(mediumFormats[i]);
     148    }
     149    return formatList;
     150}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.h

    r72822 r72869  
    7373    /** Returns which floppy disk formats are currently supported by @a comVBox. */
    7474    QList<QPair<QString, QString> > FloppyBackends(const CVirtualBox &comVBox);
     75
     76    /** Returns the first file extension of the list of file extension support for the @a enmDeviceType. */
     77   QString getPreferredExtensionForMedium(KDeviceType enmDeviceType);
     78   QVector<CMediumFormat>  getFormatsForDeviceType(KDeviceType enmDeviceType);
    7579}
    7680/* Using this namespace globally: */
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp

    r72815 r72869  
    481481{
    482482
    483     UIFDCreationDialog *pDialog = new UIFDCreationDialog(this, m_strMachineSettingsFilePath, m_strMachineName);
    484     pDialog->exec();
    485 
    486     // QVector<CMediumFormat>  mediumFormats = vboxGlobal().getFormatsForDeviceType(UIMediumDefs::mediumTypeToGlobal(m_enmMediumType));
    487     // if (mediumFormats.isEmpty())
    488     //     return;
    489     // QString strMachineFolder = QFileInfo(m_strMachineSettingsFilePath).absolutePath();
    490     // QString strMediumPath =vboxGlobal().getNewMediumPath(m_enmMediumType, this,
    491     //                                             strMachineFolder, m_strMachineName);
    492     // if (strMediumPath.isEmpty())
    493     //     return;
    494     // //
    495     // CVirtualBox vbox = vboxGlobal().virtualBox();
    496 
    497     // CMedium newMedium = vbox.CreateMedium(mediumFormats[0].GetName(), strMediumPath,
    498     //                                       KAccessMode_ReadWrite, UIMediumDefs::mediumTypeToGlobal(m_enmMediumType));
    499     // if (!vbox.isOk())
    500     // {
    501     //     msgCenter().cannotCreateHardDiskStorage(vbox, strMediumPath, this);
    502     //     return;
    503     // }
    504 
    505 
     483    UIFDCreationDialog *pDialog = new UIFDCreationDialog(this, m_strMachineName, m_strMachineSettingsFilePath);
     484    if (pDialog->exec())
     485    {
     486        sltHandleRefresh();
     487    }
     488    delete pDialog;
    506489}
    507490
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