Changeset 72869 in vbox for trunk/src/VBox
- Timestamp:
- Jul 4, 2018 11:31:55 AM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 123414
- 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 539 539 540 540 #endif /* !___UIMessageCenter_h___ */ 541 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIFDCreationDialog.cpp
r72815 r72869 21 21 22 22 /* 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 */ 26 30 # include "UIFDCreationDialog.h" 27 31 # include "UIFilePathSelector.h" 32 # include "UIMessageCenter.h" 28 33 # include "VBoxGlobal.h" 34 35 /* COM includes: */ 36 # include "CSystemProperties.h" 37 # include "CMedium.h" 38 # include "CMediumFormat.h" 29 39 30 40 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ … … 38 48 , m_strMachineName(strMachineName) 39 49 , m_strMachineSettingsFilePath(strMachineSettingsFilePath) 50 , m_pPathLabel(0) 51 , m_pSizeLabel(0) 52 , m_pSizeCombo(0) 53 , m_pButtonBox(0) 40 54 { 41 55 … … 52 66 void UIFDCreationDialog::retranslateUi() 53 67 { 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 } 55 83 } 56 84 57 85 void UIFDCreationDialog::prepare() 58 86 { 87 88 #ifndef VBOX_WS_MAC 89 setWindowIcon(QIcon(":/vm_settings_16px.png")); 90 #endif 91 59 92 setWindowModality(Qt::WindowModal); 60 61 QVBoxLayout *pMainLayout = new QVBoxLayout; 93 setSizeGripEnabled(false); 94 95 96 QGridLayout *pMainLayout = new QGridLayout; 62 97 if (!pMainLayout) 63 98 return; 64 99 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 } 65 107 66 108 m_pFilePathselector = new UIFilePathSelector; 67 109 if (m_pFilePathselector) 68 110 { 69 pMainLayout->addWidget(m_pFilePathselector );111 pMainLayout->addWidget(m_pFilePathselector, 0, 1, 1, 2); 70 112 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 149 QString 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 164 void 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 27 27 28 28 /* Forward declarations: */ 29 class QDialogButtonBox; 30 class QLabel; 31 class QComboBox; 29 32 class UIFilePathSelector; 30 33 … … 40 43 UIFDCreationDialog(QWidget *pParent = 0, 41 44 const QString &strMachineName = QString(), 42 const QString &strMachineSettingsFilePath = QString() 43 ); 45 const QString &strMachineSettingsFilePath = QString()); 46 47 virtual void accept() /* override */; 44 48 45 49 protected: … … 51 55 52 56 private: 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; 56 67 UIFilePathSelector *m_pFilePathselector; 57 68 QString m_strMachineName; 58 69 QString m_strMachineSettingsFilePath; 70 QLabel *m_pPathLabel; 71 QLabel *m_pSizeLabel; 72 QComboBox *m_pSizeCombo; 73 QDialogButtonBox *m_pButtonBox; 59 74 }; 60 75 -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumDefs.cpp
r72822 r72869 22 22 /* GUI includes: */ 23 23 # include "UIMediumDefs.h" 24 # include "VBoxGlobal.h" 25 26 /* COM includes: */ 27 # include "CMediumFormat.h" 28 # include "CSystemProperties.h" 24 29 25 30 /* COM includes: */ … … 104 109 return MediumBackends(comVBox, KDeviceType_Floppy); 105 110 } 111 112 QString 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 134 QVector<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 73 73 /** Returns which floppy disk formats are currently supported by @a comVBox. */ 74 74 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); 75 79 } 76 80 /* Using this namespace globally: */ -
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumSelector.cpp
r72815 r72869 481 481 { 482 482 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; 506 489 } 507 490
Note:
See TracChangeset
for help on using the changeset viewer.