Changeset 33667 in vbox
- Timestamp:
- Nov 2, 2010 12:42:16 AM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 67287
- 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 74 74 } 75 75 76 QString UINewHDWzd::composeFullFileName(const QString &strFileName) 77 { 78 CVirtualBox vbox = vboxGlobal().virtualBox(); 79 QString strHomeFolder = vbox.GetHomeFolder(); 80 QString strDefaultFolder = vbox.GetHomeFolder(); 81 76 void UINewHDWzd::setDefaultPath(const QString &strDefaultPath) 77 { 78 m_strDefaultPath = strDefaultPath; 79 } 80 81 QString UINewHDWzd::absoluteFilePath(const QString &strFileName) 82 { 83 /* Wrap file-info around received file name: */ 82 84 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: */ 94 92 return QDir::toNativeSeparators(fi.absoluteFilePath()); 95 93 } … … 287 285 bool UINewHDWzdPage3::validatePage() 288 286 { 289 QString location = UINewHDWzd::composeFullFileName(m_strLocation);287 QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(m_strLocation); 290 288 if (QFileInfo(location).exists()) 291 289 { … … 310 308 void UINewHDWzdPage3::onSelectLocationButtonClicked() 311 309 { 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)); 314 315 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: */ 317 319 while (!folder.exists() && !folder.isRoot()) 318 320 folder = QFileInfo(folder.absolutePath()).dir(); 319 321 322 /* But if it doesn't exists at all: */ 320 323 if (!folder.exists() || folder.isRoot()) 321 324 { 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(); 326 328 } 327 329 328 330 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)")); 330 332 331 333 if (!selected.isEmpty()) … … 445 447 446 448 QString type = field("type").toString(); 447 QString location = UINewHDWzd::composeFullFileName(field("location").toString());449 QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(field("location").toString()); 448 450 QString sizeFormatted = VBoxGlobal::formatSize(field("currentSize").toULongLong()); 449 451 QString sizeUnformatted = tr("%1 B").arg(field("currentSize").toULongLong()); … … 487 489 { 488 490 KMediumVariant variant = KMediumVariant_Standard; 489 QString loc = field("location").toString();491 QString location = qobject_cast<UINewHDWzd*>(wizard())->absoluteFilePath(field("location").toString()); 490 492 qulonglong size = field("currentSize").toULongLong(); 491 493 bool isFixed = field("fixed").toBool(); 492 494 493 AssertReturn(!loc .isNull(), false);495 AssertReturn(!location.isNull(), false); 494 496 AssertReturn(size > 0, false); 495 497 … … 498 500 CProgress progress; 499 501 500 CMedium hardDisk = vbox.CreateHardDisk(QString("VDI"), loc );502 CMedium hardDisk = vbox.CreateHardDisk(QString("VDI"), location); 501 503 502 504 if (!vbox.isOk()) 503 505 { 504 vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc , hardDisk, progress);506 vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress); 505 507 return false; 506 508 } … … 513 515 if (!hardDisk.isOk()) 514 516 { 515 vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc , hardDisk, progress);517 vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress); 516 518 return false; 517 519 } … … 524 526 if (!progress.isOk() || progress.GetResultCode() != 0) 525 527 { 526 vboxProblem().cannotCreateHardDiskStorage(this, vbox, loc , hardDisk, progress);528 vboxProblem().cannotCreateHardDiskStorage(this, vbox, location, hardDisk, progress); 527 529 return false; 528 530 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.h
r29131 r33667 43 43 void setRecommendedSize(qulonglong uSize); 44 44 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 48 protected: 49 50 void retranslateUi(); 51 52 private: 53 54 QString m_strDefaultPath; 50 55 }; 51 56 -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp
r33465 r33667 17 17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 18 18 */ 19 20 /* Global includes */ 21 #include <QDir> 19 22 20 23 /* Local includes */ … … 198 201 registerField("name*", m_pNameEditor); 199 202 registerField("type*", m_pTypeSelector, "type", SIGNAL(osTypeChanged())); 203 registerField("machineFolder", this, "machineFolder"); 200 204 201 205 connect(m_pNameEditor, SIGNAL(textChanged(const QString&)), … … 206 210 /* Setup contents */ 207 211 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();226 212 } 227 213 … … 248 234 } 249 235 236 void 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 245 void UINewVMWzdPage2::initializePage() 246 { 247 /* Fill and translate */ 248 retranslateUi(); 249 250 /* 'Name' field should have focus initially */ 251 m_pNameEditor->setFocus(); 252 } 253 254 void UINewVMWzdPage2::cleanupPage() 255 { 256 cleanupMachineFolder(); 257 } 258 259 bool UINewVMWzdPage2::validatePage() 260 { 261 return createMachineFolder(); 262 } 263 264 bool 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 286 bool 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 300 QString UINewVMWzdPage2::machineFolder() const 301 { 302 return m_strMachineFolder; 303 } 304 305 void UINewVMWzdPage2::setMachineFolder(const QString &strMachineFolder) 306 { 307 m_strMachineFolder = strMachineFolder; 308 } 309 250 310 UINewVMWzdPage3::UINewVMWzdPage3() 251 311 { … … 494 554 dlg.setRecommendedName(field("name").toString()); 495 555 dlg.setRecommendedSize(field("type").value<CGuestOSType>().GetRecommendedHDD()); 556 dlg.setDefaultPath(field("machineFolder").toString()); 496 557 497 558 if (dlg.exec() == QDialog::Accepted) -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.h
r29897 r33667 66 66 { 67 67 Q_OBJECT; 68 Q_PROPERTY(QString machineFolder READ machineFolder WRITE setMachineFolder); 68 69 69 70 public: … … 81 82 82 83 void initializePage(); 84 void cleanupPage(); 85 86 bool validatePage(); 87 88 private: 89 90 bool createMachineFolder(); 91 bool cleanupMachineFolder(); 92 93 QString machineFolder() const; 94 void setMachineFolder(const QString &strMachineFolder); 95 QString m_strMachineFolder; 83 96 }; 84 97
Note:
See TracChangeset
for help on using the changeset viewer.