- Timestamp:
- Aug 1, 2021 9:04:40 AM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/medium
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.cpp
r82968 r90453 5 5 6 6 /* 7 * Copyright (C) 2008-202 0Oracle Corporation7 * Copyright (C) 2008-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 18 18 /* Qt includes */ 19 #include <QCheckBox>20 #include <QDialogButtonBox>21 #include <QDir>22 #include <QGridLayout>23 #include <QLabel>24 #include <QPushButton>19 #include <QCheckBox> 20 #include <QDialogButtonBox> 21 #include <QDir> 22 #include <QGridLayout> 23 #include <QLabel> 24 #include <QPushButton> 25 25 26 26 /* GUI includes */ 27 #include "UICommon.h" 27 28 #include "UIFDCreationDialog.h" 28 29 #include "UIFilePathSelector.h" 29 30 #include "UIMedium.h" 30 31 #include "UIMessageCenter.h" 31 #include "UI Common.h"32 #include "UINotificationCenter.h" 32 33 33 34 /* COM includes: */ … … 38 39 39 40 UIFDCreationDialog::UIFDCreationDialog(QWidget *pParent, 40 const QString &strDefaultFolder, 41 const QString &strMachineName /* = QString() */) 42 : QIWithRetranslateUI<QDialog>(pParent) 43 , m_pFilePathselector(0) 44 , m_pPathLabel(0) 45 , m_pSizeLabel(0) 46 , m_pSizeCombo(0) 47 , m_pButtonBox(0) 48 , m_pFormatCheckBox(0) 41 const QString &strDefaultFolder, 42 const QString &strMachineName /* = QString() */) 43 : QIWithRetranslateUI<QDialog>(pParent) 49 44 , m_strDefaultFolder(strDefaultFolder) 50 45 , m_strMachineName(strMachineName) 51 { 52 46 , m_pLabelPath(0) 47 , m_pFilePathSelector(0) 48 , m_pSizeLabel(0) 49 , m_pComboSize(0) 50 , m_pCheckBoxFormat(0) 51 , m_pButtonBox(0) 52 { 53 53 prepare(); 54 /* Adjust dialog size: */ 55 adjustSize(); 54 } 55 56 QUuid UIFDCreationDialog::mediumID() const 57 { 58 return m_uMediumID; 59 } 60 61 void UIFDCreationDialog::accept() 62 { 63 /* Make Ok button disabled first of all: */ 64 m_pButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false); 65 66 /* Acquire medium path & formats: */ 67 const QString strMediumLocation = m_pFilePathSelector->path(); 68 const QVector<CMediumFormat> mediumFormats = UIMediumDefs::getFormatsForDeviceType(KDeviceType_Floppy); 69 /* Make sure we have both path and formats selected: */ 70 if (strMediumLocation.isEmpty() || mediumFormats.isEmpty()) 71 return; 72 73 /* Get VBox for further activities: */ 74 CVirtualBox comVBox = uiCommon().virtualBox(); 75 76 /* Create medium: */ 77 CMedium comMedium = comVBox.CreateMedium(mediumFormats[0].GetName(), strMediumLocation, 78 KAccessMode_ReadWrite, KDeviceType_Floppy); 79 if (!comVBox.isOk()) 80 { 81 msgCenter().cannotCreateMediumStorage(comVBox, strMediumLocation, this); 82 return; 83 } 84 85 /* Compose medium storage variants: */ 86 QVector<KMediumVariant> variants(1, KMediumVariant_Fixed); 87 /* Decide if disk formatting is required: */ 88 if (m_pCheckBoxFormat && m_pCheckBoxFormat->checkState() == Qt::Checked) 89 variants.push_back(KMediumVariant_Formatted); 90 91 /* Create medium storage, asynchronously: */ 92 UINotificationProgressMediumCreate *pNotification = 93 new UINotificationProgressMediumCreate(comMedium, m_pComboSize->currentData().toLongLong(), variants); 94 connect(pNotification, &UINotificationProgressMediumCreate::sigMediumCreated, 95 &uiCommon(), &UICommon::sltHandleMediumCreated); 96 connect(pNotification, &UINotificationProgressMediumCreate::sigMediumCreated, 97 this, &UIFDCreationDialog::sltHandleMediumCreated); 98 notificationCenter().append(pNotification); 99 } 100 101 void UIFDCreationDialog::retranslateUi() 102 { 103 if (m_strMachineName.isEmpty()) 104 setWindowTitle(QString("%1").arg(tr("Floppy Disk Creator"))); 105 else 106 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Floppy Disk Creator"))); 107 if (m_pLabelPath) 108 m_pLabelPath->setText(tr("File Path:")); 109 if (m_pSizeLabel) 110 m_pSizeLabel->setText(tr("Size:")); 111 if (m_pButtonBox) 112 m_pButtonBox->button(QDialogButtonBox::Ok)->setText("Create"); 113 if (m_pCheckBoxFormat) 114 m_pCheckBoxFormat->setText(tr("Format disk as FAT12")); 115 if (m_pComboSize) 116 { 117 //m_pComboSize->setItemText(FDSize_2_88M, tr("2.88M")); 118 m_pComboSize->setItemText(FDSize_1_44M, tr("1.44M")); 119 m_pComboSize->setItemText(FDSize_1_2M, tr("1.2M")); 120 m_pComboSize->setItemText(FDSize_720K, tr("720K")); 121 m_pComboSize->setItemText(FDSize_360K, tr("360K")); 122 } 123 } 124 125 void UIFDCreationDialog::sltHandleMediumCreated(const CMedium &comMedium) 126 { 127 /* Store the ID of the newly created medium: */ 128 m_uMediumID = comMedium.GetId(); 129 130 /* Close the dialog now: */ 131 QDialog::accept(); 132 } 133 134 void UIFDCreationDialog::prepare() 135 { 136 #ifndef VBOX_WS_MAC 137 setWindowIcon(QIcon(":/fd_add_32px.png")); 138 #endif 139 140 setWindowModality(Qt::WindowModal); 141 setSizeGripEnabled(false); 142 143 /* Prepare main layout: */ 144 QGridLayout *pLayoutMain = new QGridLayout(this); 145 if (pLayoutMain) 146 { 147 /* Prepare path label: */ 148 m_pLabelPath = new QLabel(this); 149 if (m_pLabelPath) 150 { 151 m_pLabelPath->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 152 pLayoutMain->addWidget(m_pLabelPath, 0, 0); 153 } 154 /* Prepare file path selector: */ 155 m_pFilePathSelector = new UIFilePathSelector(this); 156 if (m_pFilePathSelector) 157 { 158 m_pFilePathSelector->setMode(UIFilePathSelector::Mode_File_Save); 159 const QString strFilePath = getDefaultFilePath(); 160 m_pFilePathSelector->setDefaultPath(strFilePath); 161 m_pFilePathSelector->setPath(strFilePath); 162 163 pLayoutMain->addWidget(m_pFilePathSelector, 0, 1, 1, 3); 164 } 165 166 /* Prepare size label: */ 167 m_pSizeLabel = new QLabel(this); 168 if (m_pSizeLabel) 169 { 170 m_pSizeLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 171 pLayoutMain->addWidget(m_pSizeLabel, 1, 0); 172 } 173 /* Prepare size combo: */ 174 m_pComboSize = new QComboBox(this); 175 if (m_pComboSize) 176 { 177 //m_pComboSize->insertItem(FDSize_2_88M, "2.88M", 2949120); 178 m_pComboSize->insertItem(FDSize_1_44M, "1.44M", 1474560); 179 m_pComboSize->insertItem(FDSize_1_2M, "1.2M", 1228800); 180 m_pComboSize->insertItem(FDSize_720K, "720K", 737280); 181 m_pComboSize->insertItem(FDSize_360K, "360K", 368640); 182 m_pComboSize->setCurrentIndex(FDSize_1_44M); 183 184 pLayoutMain->addWidget(m_pComboSize, 1, 1); 185 } 186 187 /* Prepare format check-box: */ 188 m_pCheckBoxFormat = new QCheckBox; 189 if (m_pCheckBoxFormat) 190 { 191 m_pCheckBoxFormat->setCheckState(Qt::Checked); 192 pLayoutMain->addWidget(m_pCheckBoxFormat, 2, 1, 1, 2); 193 } 194 195 /* Prepare button-box: */ 196 m_pButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); 197 if (m_pButtonBox) 198 { 199 connect(m_pButtonBox, &QDialogButtonBox::accepted, this, &UIFDCreationDialog::accept); 200 connect(m_pButtonBox, &QDialogButtonBox::rejected, this, &UIFDCreationDialog::reject); 201 202 pLayoutMain->addWidget(m_pButtonBox, 3, 0, 1, 3); 203 } 204 } 205 206 /* Apply language settings: */ 207 retranslateUi(); 56 208 57 209 #ifdef VBOX_WS_MAC … … 59 211 setFixedSize(minimumSize()); 60 212 #endif /* VBOX_WS_MAC */ 61 } 62 63 void UIFDCreationDialog::retranslateUi() 64 { 65 if (m_strMachineName.isEmpty()) 66 setWindowTitle(QString("%1").arg(tr("Floppy Disk Creator"))); 67 else 68 setWindowTitle(QString("%1 - %2").arg(m_strMachineName).arg(tr("Floppy Disk Creator"))); 69 if (m_pPathLabel) 70 m_pPathLabel->setText(tr("File Path:")); 71 if (m_pSizeLabel) 72 m_pSizeLabel->setText(tr("Size:")); 73 if (m_pButtonBox) 74 m_pButtonBox->button(QDialogButtonBox::Ok)->setText("Create"); 75 if (m_pFormatCheckBox) 76 m_pFormatCheckBox->setText(tr("Format disk as FAT12")); 77 if (m_pSizeCombo) 78 { 79 //m_pSizeCombo->setItemText(FDSize_2_88M, tr("2.88M")); 80 m_pSizeCombo->setItemText(FDSize_1_44M, tr("1.44M")); 81 m_pSizeCombo->setItemText(FDSize_1_2M, tr("1.2M")); 82 m_pSizeCombo->setItemText(FDSize_720K, tr("720K")); 83 m_pSizeCombo->setItemText(FDSize_360K, tr("360K")); 84 } 85 } 86 87 void UIFDCreationDialog::prepare() 88 { 89 90 #ifndef VBOX_WS_MAC 91 setWindowIcon(QIcon(":/fd_add_32px.png")); 92 #endif 93 94 setWindowModality(Qt::WindowModal); 95 setSizeGripEnabled(false); 96 97 QGridLayout *pMainLayout = new QGridLayout; 98 if (!pMainLayout) 99 return; 100 setLayout(pMainLayout); 101 102 m_pPathLabel = new QLabel; 103 if (m_pPathLabel) 104 { 105 pMainLayout->addWidget(m_pPathLabel, 0, 0, 1, 1); 106 m_pPathLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 107 } 108 109 m_pFilePathselector = new UIFilePathSelector; 110 if (m_pFilePathselector) 111 { 112 pMainLayout->addWidget(m_pFilePathselector, 0, 1, 1, 2); 113 m_pFilePathselector->setMode(UIFilePathSelector::Mode_File_Save); 114 QString strFolder = getDefaultFolder(); 115 m_pFilePathselector->setDefaultPath(strFolder); 116 m_pFilePathselector->setPath(strFolder); 117 } 118 119 m_pSizeLabel = new QLabel; 120 if (m_pSizeLabel) 121 { 122 pMainLayout->addWidget(m_pSizeLabel, 1, 0, 1, 1); 123 m_pSizeLabel->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); 124 } 125 126 m_pSizeCombo = new QComboBox; 127 if (m_pSizeCombo) 128 { 129 pMainLayout->addWidget(m_pSizeCombo, 1, 1, 1, 1); 130 //m_pSizeCombo->insertItem(FDSize_2_88M, "2.88M", 2949120); 131 m_pSizeCombo->insertItem(FDSize_1_44M, "1.44M", 1474560); 132 m_pSizeCombo->insertItem(FDSize_1_2M, "1.2M", 1228800); 133 m_pSizeCombo->insertItem(FDSize_720K, "720K", 737280); 134 m_pSizeCombo->insertItem(FDSize_360K, "360K", 368640); 135 m_pSizeCombo->setCurrentIndex(FDSize_1_44M); 136 137 } 138 139 m_pFormatCheckBox = new QCheckBox; 140 if (m_pFormatCheckBox) 141 { 142 pMainLayout->addWidget(m_pFormatCheckBox, 2, 1, 1, 1); 143 m_pFormatCheckBox->setCheckState(Qt::Checked); 144 } 145 146 m_pButtonBox = 147 new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal, this); 148 if (m_pButtonBox) 149 { 150 pMainLayout->addWidget(m_pButtonBox, 3, 0, 1, 3); 151 connect(m_pButtonBox, &QDialogButtonBox::accepted, this, &UIFDCreationDialog::accept); 152 connect(m_pButtonBox, &QDialogButtonBox::rejected, this, &UIFDCreationDialog::reject); 153 } 154 retranslateUi(); 155 } 156 157 QString UIFDCreationDialog::getDefaultFolder() const 158 { 159 QString strPreferredExtension = UIMediumDefs::getPreferredExtensionForMedium(KDeviceType_Floppy); 160 161 QString strInitialPath = m_strDefaultFolder; 162 if (strInitialPath.isEmpty()) 163 strInitialPath = uiCommon().virtualBox().GetSystemProperties().GetDefaultMachineFolder(); 164 165 if (strInitialPath.isEmpty()) 166 return strInitialPath; 167 168 QString strDiskname = !(m_strMachineName.isEmpty()) ? m_strMachineName : "NewFloppyDisk"; 213 214 /* Adjust dialog size: */ 215 adjustSize(); 216 } 217 218 QString UIFDCreationDialog::getDefaultFilePath() const 219 { 220 /* Prepare default file-path on the basis of passerd default folder: */ 221 QString strDefaultFilePath = m_strDefaultFolder; 222 223 /* Make sure it's not empty if possible: */ 224 if (strDefaultFilePath.isEmpty()) 225 strDefaultFilePath = uiCommon().virtualBox().GetSystemProperties().GetDefaultMachineFolder(); 226 if (strDefaultFilePath.isEmpty()) 227 return strDefaultFilePath; 228 229 /* Append file-path with disc name, generate unique file-name if necessary: */ 230 QString strDiskname = !m_strMachineName.isEmpty() ? m_strMachineName : "NewFloppyDisk"; 169 231 strDiskname = UICommon::findUniqueFileName(m_strDefaultFolder, strDiskname); 170 232 171 strInitialPath = QDir(strInitialPath).absoluteFilePath(strDiskname + "." + strPreferredExtension); 172 return strInitialPath; 173 } 174 175 void UIFDCreationDialog::accept() 176 { 177 QVector<CMediumFormat> mediumFormats = UIMediumDefs::getFormatsForDeviceType(KDeviceType_Floppy); 178 179 if (m_pFilePathselector->path().isEmpty() || mediumFormats.isEmpty()) 180 return; 181 182 CVirtualBox vbox = uiCommon().virtualBox(); 183 QString strMediumLocation = m_pFilePathselector->path(); 184 185 CMedium newMedium = vbox.CreateMedium(mediumFormats[0].GetName(), strMediumLocation, 186 KAccessMode_ReadWrite, KDeviceType_Floppy); 187 if (!vbox.isOk()) 188 { 189 msgCenter().cannotCreateMediumStorage(vbox, strMediumLocation, this); 190 return; 191 } 192 193 QVector<KMediumVariant> variants(1, KMediumVariant_Fixed); 194 /* Decide if formatting the disk is required: */ 195 if (m_pFormatCheckBox && m_pFormatCheckBox->checkState() == Qt::Checked) 196 variants.push_back(KMediumVariant_Formatted); 197 CProgress progress = newMedium.CreateBaseStorage(m_pSizeCombo->currentData().toLongLong(), variants); 198 199 if (!newMedium.isOk()) 200 { 201 msgCenter().cannotCreateMediumStorage(newMedium, strMediumLocation, this); 202 return; 203 } 204 /* Show creation progress: */ 205 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this); 206 if (progress.GetCanceled()) 207 return; 208 209 if (!progress.isOk() || progress.GetResultCode() != 0) 210 { 211 msgCenter().cannotCreateHardDiskStorage(progress, strMediumLocation, this); 212 return; 213 } 214 /* Store the id of the newly create medium: */ 215 m_uMediumID = newMedium.GetId(); 216 217 /* Notify UICommon about the new medium: */ 218 uiCommon().createMedium(UIMedium(newMedium, UIMediumDeviceType_Floppy, KMediumState_Created)); 219 220 /* After a successful creation and initilization of the floppy disk we call base class accept 221 effectively closing this dialog: */ 222 QDialog::accept(); 223 } 224 225 QUuid UIFDCreationDialog::mediumID() const 226 { 227 return m_uMediumID; 228 } 233 /* Append file-path with preferred extension finally: */ 234 const QString strPreferredExtension = UIMediumDefs::getPreferredExtensionForMedium(KDeviceType_Floppy); 235 strDefaultFilePath = QDir(strDefaultFilePath).absoluteFilePath(strDiskname + "." + strPreferredExtension); 236 237 /* Return default file-path: */ 238 return strDefaultFilePath; 239 } -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.h
r82968 r90453 5 5 6 6 /* 7 * Copyright (C) 2008-202 0Oracle Corporation7 * Copyright (C) 2008-2021 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 35 35 class QLabel; 36 36 class UIFilePathSelector; 37 class CMedium; 37 38 38 /* A QDialog extension to get necessary setting from the user for floppy disk creation */39 /* A QDialog extension to get necessary setting from the user for floppy disk creation. */ 39 40 class SHARED_LIBRARY_STUFF UIFDCreationDialog : public QIWithRetranslateUI<QDialog> 40 41 41 { 42 42 Q_OBJECT; 43 43 44 45 44 public: 46 45 46 /** Constructs the floppy disc creation dialog passing @a pParent to the base-class. 47 * @param strDefaultFolder Brings the default folder. 48 * @param strMachineName Brings the machine name. */ 47 49 UIFDCreationDialog(QWidget *pParent, 48 50 const QString &strDefaultFolder, 49 51 const QString &strMachineName = QString()); 50 52 53 /** Return the medium ID. */ 54 QUuid mediumID() const; 51 55 52 virtual void accept() /* override */; 53 /* Return the mediumID */ 54 QUuid mediumID() const; 56 public slots: 57 58 /** Creates the floppy disc image, asynchronously. */ 59 virtual void accept() /* override final */; 55 60 56 61 protected: 57 62 58 void retranslateUi(); 63 /** Handles translation event. */ 64 virtual void retranslateUi() /* override final */; 59 65 60 66 private slots: 61 67 68 /** Handles signal about @a comMedium was created. */ 69 void sltHandleMediumCreated(const CMedium &comMedium); 62 70 63 71 private: 72 73 /** Floppy disc sizes. */ 64 74 enum FDSize 65 75 { … … 70 80 FDSize_360K 71 81 }; 72 void prepare();73 QString getDefaultFolder() const;74 82 75 UIFilePathSelector *m_pFilePathselector; 76 QLabel *m_pPathLabel; 83 /** Prepares all. */ 84 void prepare(); 85 86 /** Returns default file-path. */ 87 QString getDefaultFilePath() const; 88 89 /** Holds the default folder. */ 90 QString m_strDefaultFolder; 91 /** Holds the machine name. */ 92 QString m_strMachineName; 93 94 /** Holds the path label instance. */ 95 QLabel *m_pLabelPath; 96 /** Holds the file path selector instance. */ 97 UIFilePathSelector *m_pFilePathSelector; 98 /** Holds the size label instance. */ 77 99 QLabel *m_pSizeLabel; 78 QComboBox *m_pSizeCombo; 100 /** Holds the size combo instance. */ 101 QComboBox *m_pComboSize; 102 /** Holds the format check-box instance. */ 103 QCheckBox *m_pCheckBoxFormat; 104 /** holds the button-box instance. */ 79 105 QDialogButtonBox *m_pButtonBox; 80 QCheckBox *m_pFormatCheckBox; 81 QString m_strDefaultFolder; 82 QString m_strMachineName; 83 QUuid m_uMediumID; 106 107 /** Holds the created medium ID. */ 108 QUuid m_uMediumID; 84 109 }; 85 110
Note:
See TracChangeset
for help on using the changeset viewer.