Changeset 50706 in vbox
- Timestamp:
- Mar 5, 2014 2:31:40 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
r50704 r50706 74 74 { refresh(); } 75 75 76 /** Removes UIMedium wrapped by <i>this</i> item. */ 77 virtual bool remove() = 0; 78 76 79 /** Refreshes item fully. */ 77 80 void refreshAll() … … 147 150 /** UIMedium wrapped by <i>this</i> item. */ 148 151 UIMedium m_medium; 152 }; 153 154 155 /** UIMediumItem extension representing hard-disk item. */ 156 class UIMediumItemHD : public UIMediumItem 157 { 158 public: 159 160 /** Constructor for top-level item. */ 161 UIMediumItemHD(const UIMedium &medium, QTreeWidget *pParent) 162 : UIMediumItem(medium, pParent) 163 {} 164 165 /** Constructor for child item. */ 166 UIMediumItemHD(const UIMedium &medium, UIMediumItem *pParent) 167 : UIMediumItem(medium, pParent) 168 {} 169 170 private: 171 172 /** Removes UIMedium wrapped by <i>this</i> item. */ 173 bool remove() 174 { 175 /* Confirm medium removal: */ 176 if (!msgCenter().confirmMediumRemoval(medium(), treeWidget())) 177 return false; 178 179 /* Remember some of hard-disk attributes: */ 180 CMedium hardDisk = medium().medium(); 181 QString strMediumID = id(); 182 183 /* Propose to remove medium storage: */ 184 if (!maybeRemoveStorage()) 185 return false; 186 187 /* Close hard-disk: */ 188 hardDisk.Close(); 189 if (!hardDisk.isOk()) 190 { 191 msgCenter().cannotCloseMedium(medium(), hardDisk, treeWidget()); 192 return false; 193 } 194 195 /* Remove UIMedium finally: */ 196 vboxGlobal().deleteMedium(strMediumID); 197 198 /* True by default: */ 199 return true; 200 } 201 202 /** Proposes user to remove CMedium storage wrapped by <i>this</i> item. */ 203 bool maybeRemoveStorage() 204 { 205 /* Remember some of hard-disk attributes: */ 206 CMedium hardDisk = medium().medium(); 207 QString strLocation = location(); 208 209 /* We don't want to try to delete inaccessible storage as it will most likely fail. 210 * Note that UIMessageCenter::confirmMediumRemoval() is aware of that and 211 * will give a corresponding hint. Therefore, once the code is changed below, 212 * the hint should be re-checked for validity. */ 213 bool fDeleteStorage = false; 214 qulonglong uCapability = 0; 215 QVector<KMediumFormatCapabilities> capabilities = hardDisk.GetMediumFormat().GetCapabilities(); 216 foreach (KMediumFormatCapabilities capability, capabilities) 217 uCapability |= capability; 218 if (state() != KMediumState_Inaccessible && uCapability & MediumFormatCapabilities_File) 219 { 220 int rc = msgCenter().confirmDeleteHardDiskStorage(strLocation, treeWidget()); 221 if (rc == AlertButton_Cancel) 222 return false; 223 fDeleteStorage = rc == AlertButton_Choice1; 224 } 225 226 /* If user wish to delete storage: */ 227 if (fDeleteStorage) 228 { 229 /* Prepare delete storage progress: */ 230 CProgress progress = hardDisk.DeleteStorage(); 231 if (!hardDisk.isOk()) 232 { 233 msgCenter().cannotDeleteHardDiskStorage(hardDisk, strLocation, treeWidget()); 234 return false; 235 } 236 /* Show delete storage progress: */ 237 msgCenter().showModalProgressDialog(progress, UIMediumManager::tr("Removing medium..."), 238 ":/progress_media_delete_90px.png", treeWidget()); 239 if (!progress.isOk() || progress.GetResultCode() != 0) 240 { 241 msgCenter().cannotDeleteHardDiskStorage(progress, strLocation, treeWidget()); 242 return false; 243 } 244 } 245 246 /* True by default: */ 247 return true; 248 } 249 }; 250 251 /** UIMediumItem extension representing optical-disk item. */ 252 class UIMediumItemCD : public UIMediumItem 253 { 254 public: 255 256 /** Constructor for top-level item. */ 257 UIMediumItemCD(const UIMedium &medium, QTreeWidget *pParent) 258 : UIMediumItem(medium, pParent) 259 {} 260 261 private: 262 263 /** Removes UIMedium wrapped by <i>this</i> item. */ 264 bool remove() 265 { 266 /* Confirm medium removal: */ 267 if (!msgCenter().confirmMediumRemoval(medium(), treeWidget())) 268 return false; 269 270 /* Remember some of optical-disk attributes: */ 271 CMedium image = medium().medium(); 272 QString strMediumID = id(); 273 274 /* Close optical-disk: */ 275 image.Close(); 276 if (!image.isOk()) 277 { 278 msgCenter().cannotCloseMedium(medium(), image, treeWidget()); 279 return false; 280 } 281 282 /* Remove UIMedium finally: */ 283 vboxGlobal().deleteMedium(strMediumID); 284 285 /* True by default: */ 286 return true; 287 } 288 }; 289 290 /** UIMediumItem extension representing floppy-disk item. */ 291 class UIMediumItemFD : public UIMediumItem 292 { 293 public: 294 295 /** Constructor for top-level item. */ 296 UIMediumItemFD(const UIMedium &medium, QTreeWidget *pParent) 297 : UIMediumItem(medium, pParent) 298 {} 299 300 private: 301 302 /** Removes UIMedium wrapped by <i>this</i> item. */ 303 bool remove() 304 { 305 /* Confirm medium removal: */ 306 if (!msgCenter().confirmMediumRemoval(medium(), treeWidget())) 307 return false; 308 309 /* Remember some of floppy-disk attributes: */ 310 CMedium image = medium().medium(); 311 QString strMediumID = id(); 312 313 /* Close floppy-disk: */ 314 image.Close(); 315 if (!image.isOk()) 316 { 317 msgCenter().cannotCloseMedium(medium(), image, treeWidget()); 318 return false; 319 } 320 321 /* Remove UIMedium finally: */ 322 vboxGlobal().deleteMedium(strMediumID); 323 324 /* True by default: */ 325 return true; 326 } 149 327 }; 150 328 … … 413 591 AssertReturnVoid(!pMediumItem->id().isNull()); 414 592 415 /* Remember ID/type as they may get lost after the closure/deletion: */ 416 QString strMediumID = pMediumItem->id(); 417 AssertReturnVoid(!strMediumID.isNull()); 418 UIMediumType type = pMediumItem->mediumType(); 419 420 /* Confirm medium removal: */ 421 if (!msgCenter().confirmMediumRemoval(pMediumItem->medium(), this)) 422 return; 423 424 /* Prepare result: */ 425 COMResult result; 426 switch (type) 427 { 428 case UIMediumType_HardDisk: 429 { 430 /* We don't want to try to delete inaccessible storage as it will most likely fail. 431 * Note that UIMessageCenter::confirmMediumRemoval() is aware of that and 432 * will give a corresponding hint. Therefore, once the code is changed below, 433 * the hint should be re-checked for validity. */ 434 bool fDeleteStorage = false; 435 qulonglong uCapability = 0; 436 QVector<KMediumFormatCapabilities> capabilities = pMediumItem->medium().medium().GetMediumFormat().GetCapabilities(); 437 foreach (KMediumFormatCapabilities capability, capabilities) 438 uCapability |= capability; 439 if (pMediumItem->state() != KMediumState_Inaccessible && 440 uCapability & MediumFormatCapabilities_File) 441 { 442 int rc = msgCenter().confirmDeleteHardDiskStorage(pMediumItem->location(), this); 443 if (rc == AlertButton_Cancel) 444 return; 445 fDeleteStorage = rc == AlertButton_Choice1; 446 } 447 448 /* Get hard-disk: */ 449 CMedium hardDisk = pMediumItem->medium().medium(); 450 451 if (fDeleteStorage) 452 { 453 /* Remember hard-disk attributes: */ 454 QString strLocation = hardDisk.GetLocation(); 455 /* Prepare delete storage progress: */ 456 CProgress progress = hardDisk.DeleteStorage(); 457 if (hardDisk.isOk()) 458 { 459 /* Show delete storage progress: */ 460 msgCenter().showModalProgressDialog(progress, windowTitle(), ":/progress_media_delete_90px.png", this); 461 if (!progress.isOk() || progress.GetResultCode() != 0) 462 { 463 msgCenter().cannotDeleteHardDiskStorage(progress, strLocation, this); 464 return; 465 } 466 } 467 else 468 { 469 msgCenter().cannotDeleteHardDiskStorage(hardDisk, strLocation, this); 470 return; 471 } 472 } 473 474 /* Close hard-disk: */ 475 hardDisk.Close(); 476 result = hardDisk; 477 break; 478 } 479 case UIMediumType_DVD: 480 { 481 /* Get optical-disk: */ 482 CMedium image = pMediumItem->medium().medium(); 483 /* Close optical-disk: */ 484 image.Close(); 485 result = image; 486 break; 487 } 488 case UIMediumType_Floppy: 489 { 490 /* Get floppy-disk: */ 491 CMedium image = pMediumItem->medium().medium(); 492 /* Close floppy-disk: */ 493 image.Close(); 494 result = image; 495 break; 496 } 497 default: AssertFailedReturnVoid(); 498 } 499 500 /* Verify result: */ 501 if (result.isOk()) 502 vboxGlobal().deleteMedium(strMediumID); 503 else 504 msgCenter().cannotCloseMedium(pMediumItem->medium(), result, this); 593 /* Remove current medium-item: */ 594 pMediumItem->remove(); 505 595 } 506 596 … … 1381 1471 case UIMediumType_DVD: 1382 1472 { 1383 pMediumItem = new UIMediumItem (medium, mTwCD);1473 pMediumItem = new UIMediumItemCD(medium, mTwCD); 1384 1474 LogRel2(("UIMediumManager: Optical medium-item with ID={%s} created.\n", medium.id().toAscii().constData())); 1385 1475 AssertPtrReturnVoid(pMediumItem); … … 1394 1484 case UIMediumType_Floppy: 1395 1485 { 1396 pMediumItem = new UIMediumItem (medium, mTwFD);1486 pMediumItem = new UIMediumItemFD(medium, mTwFD); 1397 1487 LogRel2(("UIMediumManager: Floppy medium-item with ID={%s} created.\n", medium.id().toAscii().constData())); 1398 1488 AssertPtrReturnVoid(pMediumItem); … … 1764 1854 if (pParentMediumItem) 1765 1855 { 1766 pMediumItem = new UIMediumItem (medium, pParentMediumItem);1856 pMediumItem = new UIMediumItemHD(medium, pParentMediumItem); 1767 1857 LogRel2(("UIMediumManager: Child hard-drive medium-item with ID={%s} created.\n", medium.id().toAscii().constData())); 1768 1858 } … … 1771 1861 if (!pMediumItem) 1772 1862 { 1773 pMediumItem = new UIMediumItem (medium, pTree);1863 pMediumItem = new UIMediumItemHD(medium, pTree); 1774 1864 LogRel2(("UIMediumManager: Root hard-drive medium-item with ID={%s} created.\n", medium.id().toAscii().constData())); 1775 1865 }
Note:
See TracChangeset
for help on using the changeset viewer.