Changeset 253 in vbox for trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h
- Timestamp:
- Jan 23, 2007 6:28:49 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h
r132 r253 44 44 QString aLabel8 = QString::null) : 45 45 QListViewItem (parent, aLabel1, aLabel2, aLabel3, aLabel4, aLabel5, 46 aLabel6, aLabel7, aLabel8), mName (aLabel1) {} 46 aLabel6, aLabel7, aLabel8), 47 mName (aLabel1), mStatus (VBoxMedia::Unknown) {} 47 48 48 49 DiskImageItem (QListView *parent, QString aLabel1, … … 55 56 QString aLabel8 = QString::null) : 56 57 QListViewItem (parent, aLabel1, aLabel2, aLabel3, aLabel4, aLabel5, 57 aLabel6, aLabel7, aLabel8), mName (aLabel1) {} 58 aLabel6, aLabel7, aLabel8), 59 mName (aLabel1), mStatus (VBoxMedia::Unknown) {} 58 60 59 61 QString getName() { return mName; } … … 86 88 void setMachineId (QString aMachineId) { mMachineId = aMachineId; } 87 89 const QString &getMachineId() { return mMachineId; } 90 91 92 void setStatus (VBoxMedia::Status aStatus) { mStatus = aStatus; } 93 VBoxMedia::Status getStatus() { return mStatus; } 88 94 89 95 … … 106 112 int compare (QListViewItem *aItem, int aColumn, bool aAscending) const 107 113 { 108 if (aItem->rtti() == 1002)109 return aAscending ? 1 : -1;110 111 114 ULONG64 thisValue = vboxGlobal().parseSize ( text (aColumn)); 112 115 ULONG64 thatValue = vboxGlobal().parseSize (aItem->text (aColumn)); … … 127 130 QListViewItem::nextSibling()->rtti() == 1001) ? 128 131 static_cast<DiskImageItem*> (QListViewItem::nextSibling()) : 0; 132 } 133 134 void paintCell (QPainter *aPainter, const QColorGroup &aColorGroup, 135 int aColumn, int aWidth, int aSlign) 136 { 137 QColorGroup cGroup (aColorGroup); 138 if (mStatus == VBoxMedia::Unknown) 139 cGroup.setColor (QColorGroup::Text, cGroup.mid()); 140 QListViewItem::paintCell (aPainter, cGroup, aColumn, aWidth, aSlign); 129 141 } 130 142 … … 144 156 145 157 QString mToolTip; 146 }; 147 148 149 class ProgressBarItem : public QListViewItem, public QProgressBar 150 { 151 public: 152 153 ProgressBarItem (QListView *aParent, ULONG aTotalSteps) : 154 QListViewItem (aParent) 155 { 156 setFrameShadow (Sunken); 157 setFrameShape (Panel); 158 setSelectable (false); 159 setProgress (0, aTotalSteps); 160 setPercentageVisible (false); 161 } 162 163 void paintCell (QPainter *p, const QColorGroup &cg, 164 int column, int width, int align) 165 { 166 setMaximumWidth (100); 167 setFixedHeight (QListViewItem::height()); 168 QListViewItem::paintCell (p, cg, column, width, align); 169 if (column == 0) 170 { 171 drawContents (p); 172 drawFrame (p); 173 } 174 } 175 176 void increaseProgress() { setProgress (progress() + 1); } 177 178 int rtti() const { return 1002; } 179 180 int compare (QListViewItem *aItem, int /*aColumn*/, bool aAscending) const 181 { 182 if (aItem->rtti() == 1001) 183 return aAscending ? -1 : 1; 184 else 185 return 0; 186 } 158 159 VBoxMedia::Status mStatus; 187 160 }; 188 161 … … 206 179 /// @todo refreshAll() may be slow, so it may be better to analyze 207 180 // event details and update only what is changed */ 208 connect (&vboxGlobal(), SIGNAL (machineDataChanged (const VBoxMachineDataChangeEvent &)),209 mModelessDialog, SLOT (refreshAll()));181 //connect (&vboxGlobal(), SIGNAL (machineDataChanged (const VBoxMachineDataChangeEvent &)), 182 // mModelessDialog, SLOT (refreshAll())); 210 183 connect (&vboxGlobal(), SIGNAL (machineRegistered (const VBoxMachineRegisteredEvent &)), 211 184 mModelessDialog, SLOT (refreshAll())); … … 223 196 ~WindowMinimized); 224 197 mModelessDialog->setActiveWindow(); 225 226 198 } 227 199 … … 233 205 mToBeRefreshed = false; 234 206 mInLoop = false; 235 236 mHdsProgress = 0;237 mCdsProgress = 0;238 mFdsProgress = 0;239 207 240 208 defaultButton = searchDefaultButton(); … … 273 241 274 242 /* setup image list views */ 275 276 hdsView->setShowSortIndicator (true);277 cdsView->setShowSortIndicator (true);278 fdsView->setShowSortIndicator (true);279 280 243 hdsView->setColumnAlignment (1, Qt::AlignRight); 281 244 hdsView->setColumnAlignment (2, Qt::AlignRight); … … 290 253 cdsView->header()->setStretchEnabled (false); 291 254 cdsView->header()->setStretchEnabled (true, 0); 255 292 256 293 257 /* setup list-view's item tooltip */ … … 302 266 this, SLOT (mouseOnItem(QListViewItem*))); 303 267 304 /* setup dnd handlers */305 hdsView->viewport()->setAcceptDrops (true);306 cdsView->viewport()->setAcceptDrops (true);307 fdsView->viewport()->setAcceptDrops (true);308 connect (hdsView, SIGNAL (dropped (QDropEvent *)),309 this, SLOT (addDroppedImages (QDropEvent*)));310 connect (cdsView, SIGNAL (dropped (QDropEvent*)),311 this, SLOT (addDroppedImages (QDropEvent*)));312 connect (fdsView, SIGNAL (dropped (QDropEvent*)),313 this, SLOT (addDroppedImages (QDropEvent*)));314 268 315 269 /* status-bar currently disabled */ 316 270 statusBar()->setHidden (true); 271 317 272 318 273 /* context menu composing */ … … 435 390 fdsPane1 = createInfoString (tr ("Location"), fdsContainer, 0, -1); 436 391 fdsPane2 = createInfoString (tr ("Attached to"), fdsContainer, 1, -1); 392 393 394 /* enumeration progressbar creation */ 395 mProgressText = new QLabel (tr ("Checking accessibility"), centralWidget()); 396 mProgressText->setHidden (true); 397 buttonLayout->insertWidget (2, mProgressText); 398 mProgressBar = new QProgressBar (centralWidget()); 399 mProgressBar->setHidden (true); 400 mProgressBar->setFrameShadow (QFrame::Sunken); 401 mProgressBar->setFrameShape (QFrame::Panel); 402 mProgressBar->setPercentageVisible (false); 403 mProgressBar->setMaximumWidth (100); 404 buttonLayout->insertWidget (3, mProgressBar); 405 406 if (!vboxGlobal().isInEnumeratingProcess()) loadListViews(); 407 } 408 409 410 void VBoxDiskImageManagerDlg::loadListViews() 411 { 412 /* load hd list */ 413 CHardDiskEnumerator hdEnum = vbox.GetHardDisks().Enumerate(); 414 while (hdEnum.HasMore()) 415 { 416 CHardDisk hd = hdEnum.GetNext(); 417 DiskImageItem *item = createHdItem (hdsView, 0, hd, VBoxMedia::Unknown); 418 createHdChildren (item, hd, VBoxMedia::Unknown); 419 } 420 421 /* load cd list */ 422 CDVDImageEnumerator cdEnum = vbox.GetDVDImages().Enumerate(); 423 while (cdEnum.HasMore()) 424 { 425 CDVDImage cd = cdEnum.GetNext(); 426 DiskImageItem *item = createCdItem (cdsView, 0, cd, VBoxMedia::Unknown); 427 } 428 429 /* load fd list */ 430 CFloppyImageEnumerator fdEnum = vbox.GetFloppyImages().Enumerate(); 431 while (fdEnum.HasMore()) 432 { 433 CFloppyImage fd = fdEnum.GetNext(); 434 DiskImageItem *item = createFdItem (fdsView, 0, fd, VBoxMedia::Unknown); 435 } 437 436 } 438 437 … … 504 503 case 1001: 505 504 tip = static_cast<DiskImageItem*> (aItem)->getToolTip(); 506 break;507 case 1002:508 tip = tr ("Enumeration in progress...", "Media accessibility check");509 505 break; 510 506 default: … … 624 620 QDragEnterEvent *dragEnterEvent = 625 621 static_cast<QDragEnterEvent*>(aEvent); 626 dragEnterEvent->accept(); 622 dragEnterEvent->acceptAction(); 623 return true; 624 } 625 break; 626 } 627 case QEvent::Drop: 628 { 629 if (aObject == currentList) 630 { 631 QDropEvent *dropEvent = 632 static_cast<QDropEvent*>(aEvent); 633 QStringList *droppedList = new QStringList(); 634 QUriDrag::decodeLocalFiles (dropEvent, *droppedList); 635 QCustomEvent *updateEvent = new QCustomEvent (1001); 636 updateEvent->setData (droppedList); 637 QApplication::postEvent (currentList, updateEvent); 638 dropEvent->acceptAction(); 639 return true; 640 } 641 break; 642 } 643 case 1001: /* QCustomEvent 1001 - DnD Update Event */ 644 { 645 if (aObject == currentList) 646 { 647 QCustomEvent *updateEvent = 648 static_cast<QCustomEvent*>(aEvent); 649 addDroppedImages ((QStringList*) updateEvent->data()); 650 return true; 627 651 } 628 652 break; … … 655 679 656 680 657 void VBoxDiskImageManagerDlg::addDroppedImages (Q DropEvent *aEvent)681 void VBoxDiskImageManagerDlg::addDroppedImages (QStringList *aDroppedList) 658 682 { 659 683 QListView *currentList = getCurrentListView(); 660 684 661 QStringList droppedList; 662 QUriDrag::decodeLocalFiles (aEvent, droppedList); 663 664 for (QStringList::Iterator it = droppedList.begin(); 665 it != droppedList.end(); ++it) 685 DiskImageItem *item = 0; 686 for (QStringList::Iterator it = (*aDroppedList).begin(); 687 it != (*aDroppedList).end(); ++it) 666 688 { 667 689 // Checking dropped media type … … 680 702 } 681 703 // If media type has been determined - attach this device 682 if (type) 683 addDroppedImage (*it, type); 684 } 685 686 refreshAll(); 687 } 688 689 690 void VBoxDiskImageManagerDlg::addDroppedImage (QString aSource, VBoxDefs::DiskType aDiskType) 704 if (type) item = addImageToList (*it, type); 705 } 706 delete aDroppedList; 707 setCurrentItem (currentList, item); 708 } 709 710 711 DiskImageItem* VBoxDiskImageManagerDlg::addImageToList (QString aSource, VBoxDefs::DiskType aDiskType) 691 712 { 692 713 if (aSource.isEmpty()) 693 return; 694 714 return 0; 715 716 DiskImageItem *item = 0; 695 717 QUuid uuid; 696 718 switch (aDiskType) … … 703 725 CHardDisk hardDisk = CUnknown (vdi); 704 726 vbox.RegisterHardDisk (hardDisk); 727 if (vbox.isOk()) 728 { 729 VBoxMedia::Status status = hardDisk.GetAccessible() ? 730 VBoxMedia::Ok : VBoxMedia::Inaccessible; 731 item = createHdItem (hdsView, 0, hardDisk, status); 732 /* synchronize modeless dialog if present */ 733 if (mModelessDialog && mModelessDialog != this) 734 mModelessDialog->createHdItem (mModelessDialog->hdsView, 735 0, hardDisk, status); 736 } 705 737 } 706 738 break; … … 710 742 CDVDImage dvdImage = vbox.OpenDVDImage (aSource, uuid); 711 743 if (vbox.isOk()) 744 { 712 745 vbox.RegisterDVDImage (dvdImage); 746 if (vbox.isOk()) 747 { 748 VBoxMedia::Status status = dvdImage.GetAccessible() ? 749 VBoxMedia::Ok : VBoxMedia::Inaccessible; 750 item = createCdItem (cdsView, 0, dvdImage, status); 751 /* synchronize modeless dialog if present */ 752 if (mModelessDialog && mModelessDialog != this) 753 mModelessDialog->createCdItem (mModelessDialog->cdsView, 754 0, dvdImage, status); 755 } 756 } 713 757 break; 714 758 } … … 717 761 CFloppyImage floppyImage = vbox.OpenFloppyImage (aSource, uuid); 718 762 if (vbox.isOk()) 763 { 719 764 vbox.RegisterFloppyImage (floppyImage); 765 if (vbox.isOk()) 766 { 767 VBoxMedia::Status status = floppyImage.GetAccessible() ? 768 VBoxMedia::Ok : VBoxMedia::Inaccessible; 769 item = createFdItem (fdsView, 0, floppyImage, status); 770 /* synchronize modeless dialog if present */ 771 if (mModelessDialog && mModelessDialog != this) 772 mModelessDialog->createFdItem (mModelessDialog->fdsView, 773 0, floppyImage, status); 774 } 775 } 720 776 break; 721 777 } … … 725 781 } 726 782 } 783 return item; 727 784 } 728 785 … … 838 895 839 896 840 QString VBoxDiskImageManagerDlg::composeHdToolTip (CHardDisk &aHd) 897 QString VBoxDiskImageManagerDlg::composeHdToolTip (CHardDisk &aHd, 898 VBoxMedia::Status aStatus) 841 899 { 842 900 CVirtualBox vbox = vboxGlobal().virtualBox(); 843 bool accessible = aHd.GetAccessible();844 901 QUuid machineId = aHd.GetMachineId(); 845 902 … … 867 924 /* compose tool-tip information */ 868 925 QString tip; 869 if (!accessible) 870 { 871 tip = tr ("<nobr><b>%1</b></nobr><br>%2") 872 .arg (location) 873 .arg (aHd.GetLastAccessError()); 874 } 875 else 876 { 877 tip = tr ("<nobr><b>%1</b></nobr><br>" 878 "<nobr>Disk type: %2</nobr><br>" 879 "<nobr>Storage type: %3</nobr>") 880 .arg (location) 881 .arg (hardDiskType) 882 .arg (storageType); 883 884 if (!usage.isNull()) 885 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (usage); 886 if (!snapshotName.isNull()) 887 tip += tr ("<br><nobr>Snapshot: %5</nobr>").arg (snapshotName); 926 switch (aStatus) 927 { 928 case VBoxMedia::Unknown: 929 { 930 tip = tr ("<nobr><b>%1</b></nobr><br>" 931 "Checking accessibility...", "HDD") 932 .arg (location); 933 break; 934 } 935 case VBoxMedia::Ok: 936 { 937 tip = tr ("<nobr><b>%1</b></nobr><br>" 938 "<nobr>Disk type: %2</nobr><br>" 939 "<nobr>Storage type: %3</nobr>") 940 .arg (location) 941 .arg (hardDiskType) 942 .arg (storageType); 943 944 if (!usage.isNull()) 945 tip += tr ("<br><nobr>Attached to: %1</nobr>", "HDD") 946 .arg (usage); 947 if (!snapshotName.isNull()) 948 tip += tr ("<br><nobr>Snapshot: %5</nobr>", "HDD") 949 .arg (snapshotName); 950 break; 951 } 952 case VBoxMedia::Error: 953 { 954 /// @todo (r=dmik) paass a complete VBoxMedia instance here 955 // to get the result of blabla.GetAccessible() call form CUnknown 956 tip = tr ("<nobr><b>%1</b></nobr><br>" 957 "Error checking media accessibility", "HDD") 958 .arg (location); 959 break; 960 } 961 case VBoxMedia::Inaccessible: 962 { 963 tip = tr ("<nobr><b>%1</b></nobr><br>%2", "HDD") 964 .arg (location) 965 .arg (aHd.GetLastAccessError()); 966 break; 967 } 968 default: 969 AssertFailed(); 888 970 } 889 971 return tip; 890 972 } 891 973 892 QString VBoxDiskImageManagerDlg::composeCdToolTip (CDVDImage &aCd )893 { 894 bool accessible = aCd.GetAccessible(); 974 QString VBoxDiskImageManagerDlg::composeCdToolTip (CDVDImage &aCd, 975 VBoxMedia::Status aStatus) 976 { 895 977 QString src = aCd.GetFilePath(); 896 978 QFileInfo fi (src); … … 901 983 /* compose tool-tip information */ 902 984 QString tip; 903 if (!accessible) 904 { 905 /// @todo (r=dmik) correct this when GetLastAccessError() is 906 // implemented for IFloppyImage/IDVDImage 907 tip = tr ("<nobr><b>%1</b></nobr><br>%2") 908 .arg (location) 909 .arg (tr ("The image file is not accessible", 910 "CD/DVD/Floppy")); 911 } 912 else 913 { 914 tip = tr ("<nobr><b>%1</b></nobr>") 915 .arg (location); 916 917 if (!usage.isNull()) 918 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (usage); 985 switch (aStatus) 986 { 987 case VBoxMedia::Unknown: 988 { 989 tip = tr ("<nobr><b>%1</b></nobr><br>" 990 "Checking accessibility...", "CD/DVD/Floppy") 991 .arg (location); 992 break; 993 } 994 case VBoxMedia::Ok: 995 { 996 tip = tr ("<nobr><b>%1</b></nobr>", "CD/DVD/Floppy") 997 .arg (location); 998 999 if (!usage.isNull()) 1000 tip += tr ("<br><nobr>Attached to: %1</nobr>", 1001 "CD/DVD/Floppy") 1002 .arg (usage); 1003 break; 1004 } 1005 case VBoxMedia::Error: 1006 { 1007 /// @todo (r=dmik) paass a complete VBoxMedia instance here 1008 // to get the result of blabla.GetAccessible() call form CUnknown 1009 tip = tr ("<nobr><b>%1</b></nobr><br>" 1010 "Error checking media accessibility", "CD/DVD/Floppy") 1011 .arg (location); 1012 break; 1013 } 1014 case VBoxMedia::Inaccessible: 1015 { 1016 /// @todo (r=dmik) correct this when GetLastAccessError() is 1017 // implemented for IDVDImage 1018 tip = tr ("<nobr><b>%1</b></nobr><br>%2") 1019 .arg (location) 1020 .arg (tr ("The image file is not accessible", 1021 "CD/DVD/Floppy")); 1022 break; 1023 } 1024 default: 1025 AssertFailed(); 919 1026 } 920 1027 return tip; 921 1028 } 922 1029 923 QString VBoxDiskImageManagerDlg::composeFdToolTip (CFloppyImage &aFd )924 { 925 bool accessible = aFd.GetAccessible(); 1030 QString VBoxDiskImageManagerDlg::composeFdToolTip (CFloppyImage &aFd, 1031 VBoxMedia::Status aStatus) 1032 { 926 1033 QString src = aFd.GetFilePath(); 927 1034 QFileInfo fi (src); … … 931 1038 932 1039 /* compose tool-tip information */ 1040 /* compose tool-tip information */ 933 1041 QString tip; 934 if (!accessible) 935 { 936 /// @todo (r=dmik) correct this when GetLastAccessError() is 937 // implemented for IFloppyImage/IDVDImage 938 tip = tr ("<nobr><b>%1</b></nobr><br>%2") 939 .arg (location) 940 .arg (tr ("The image file is not accessible", 941 "CD/DVD/Floppy")); 942 } 943 else 944 { 945 tip = tr ("<nobr><b>%1</b></nobr>") 1042 switch (aStatus) 1043 { 1044 case VBoxMedia::Unknown: 1045 { 1046 tip = tr ("<nobr><b>%1</b></nobr><br>" 1047 "Checking accessibility...", "CD/DVD/Floppy") 946 1048 .arg (location); 947 948 if (!usage.isNull()) 949 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (usage); 1049 break; 1050 } 1051 case VBoxMedia::Ok: 1052 { 1053 tip = tr ("<nobr><b>%1</b></nobr>", "CD/DVD/Floppy") 1054 .arg (location); 1055 1056 if (!usage.isNull()) 1057 tip += tr ("<br><nobr>Attached to: %1</nobr>", 1058 "CD/DVD/Floppy") 1059 .arg (usage); 1060 break; 1061 } 1062 case VBoxMedia::Error: 1063 { 1064 /// @todo (r=dmik) paass a complete VBoxMedia instance here 1065 // to get the result of blabla.GetAccessible() call form CUnknown 1066 tip = tr ("<nobr><b>%1</b></nobr><br>" 1067 "Error checking media accessibility", "CD/DVD/Floppy") 1068 .arg (location); 1069 break; 1070 } 1071 case VBoxMedia::Inaccessible: 1072 { 1073 /// @todo (r=dmik) correct this when GetLastAccessError() is 1074 // implemented for IDVDImage 1075 tip = tr ("<nobr><b>%1</b></nobr><br>%2") 1076 .arg (location) 1077 .arg (tr ("The image file is not accessible", 1078 "CD/DVD/Floppy")); 1079 break; 1080 } 1081 default: 1082 AssertFailed(); 950 1083 } 951 1084 return tip; … … 955 1088 DiskImageItem* VBoxDiskImageManagerDlg::createHdItem (QListView *aList, 956 1089 DiskImageItem *aRoot, 957 CHardDisk &aHd) 1090 CHardDisk &aHd, 1091 VBoxMedia::Status aStatus) 958 1092 { 959 1093 DiskImageItem *item = 0; … … 962 1096 QString src = aHd.GetLocation(); 963 1097 QUuid machineId = aHd.GetMachineId(); 964 bool accessible = aHd.GetAccessible();965 1098 966 1099 QString usage; … … 969 1102 QString storageType = vboxGlobal().toString (aHd.GetStorageType()); 970 1103 QString hardDiskType = vboxGlobal().hardDiskTypeString (aHd); 971 QString virtualSize = a ccessible?972 vboxGlobal().formatSize ( aHd.GetSize() * _1M) : QString ("--");973 QString actualSize = a ccessible?1104 QString virtualSize = aStatus == VBoxMedia::Ok ? 1105 vboxGlobal().formatSize ((ULONG64)aHd.GetSize() * _1M) : QString ("--"); 1106 QString actualSize = aStatus == VBoxMedia::Ok ? 974 1107 vboxGlobal().formatSize (aHd.GetActualSize()) : QString ("--"); 975 1108 QString snapshotName; … … 983 1116 QFileInfo fi (src); 984 1117 985 item = createImageNode ( 986 aList, aRoot, 987 fi.fileName(), 988 virtualSize, 989 actualSize 990 ); 1118 item = createImageNode (aList, aRoot, 1119 fi.fileName(), 1120 virtualSize, 1121 actualSize); 991 1122 item->setPath (aHd.GetStorageType() == CEnums::ISCSIHardDisk ? src : 992 1123 QDir::convertSeparators (fi.absFilePath())); … … 999 1130 item->setUuid (uuid); 1000 1131 item->setMachineId (machineId); 1001 item->setToolTip (composeHdToolTip (aHd)); 1132 item->setToolTip (composeHdToolTip (aHd, aStatus)); 1133 item->setStatus (aStatus); 1002 1134 1003 1135 return item; … … 1007 1139 DiskImageItem* VBoxDiskImageManagerDlg::createCdItem (QListView *aList, 1008 1140 DiskImageItem *aRoot, 1009 CDVDImage &aCd) 1141 CDVDImage &aCd, 1142 VBoxMedia::Status aStatus) 1010 1143 { 1011 1144 DiskImageItem *item = 0; … … 1014 1147 QString src = aCd.GetFilePath(); 1015 1148 QString usage = getDVDImageUsage (uuid); 1016 bool accessible = aCd.GetAccessible(); 1017 1018 QString size = accessible ? 1149 1150 QString size = aStatus == VBoxMedia::Ok ? 1019 1151 vboxGlobal().formatSize (aCd.GetSize()) : QString ("--"); 1020 1152 QFileInfo fi (src); … … 1027 1159 item->setActualSize (size); 1028 1160 item->setUuid (uuid); 1029 item->setToolTip (composeCdToolTip (aCd)); 1161 item->setToolTip (composeCdToolTip (aCd, aStatus)); 1162 item->setStatus (aStatus); 1030 1163 1031 1164 return item; … … 1035 1168 DiskImageItem* VBoxDiskImageManagerDlg::createFdItem (QListView *aList, 1036 1169 DiskImageItem *aRoot, 1037 CFloppyImage &aFd) 1170 CFloppyImage &aFd, 1171 VBoxMedia::Status aStatus) 1038 1172 { 1039 1173 DiskImageItem *item = 0; … … 1042 1176 QString src = aFd.GetFilePath(); 1043 1177 QString usage = getFloppyImageUsage (uuid); 1044 bool accessible = aFd.GetAccessible(); 1045 1046 QString size = accessible ? 1178 1179 QString size = aStatus == VBoxMedia::Ok ? 1047 1180 vboxGlobal().formatSize (aFd.GetSize()) : QString ("--"); 1048 1181 QFileInfo fi (src); … … 1055 1188 item->setActualSize (size); 1056 1189 item->setUuid (uuid); 1057 item->setToolTip (composeFdToolTip (aFd)); 1190 item->setToolTip (composeFdToolTip (aFd, aStatus)); 1191 item->setStatus (aStatus); 1058 1192 1059 1193 return item; … … 1062 1196 1063 1197 void VBoxDiskImageManagerDlg::createHdChildren (DiskImageItem *aRoot, 1064 CHardDisk &aHd) 1198 CHardDisk &aHd, 1199 VBoxMedia::Status aStatus) 1065 1200 { 1066 1201 CHardDiskEnumerator enumerator = aHd.GetChildren().Enumerate(); … … 1068 1203 { 1069 1204 CHardDisk subHd = enumerator.GetNext(); 1070 DiskImageItem *subItem = createHdItem (0, aRoot, subHd); 1071 createHdChildren (subItem, subHd); 1072 } 1073 } 1074 1075 1076 void VBoxDiskImageManagerDlg::insertMedia (const VBoxMedia &aMedia) 1077 { 1078 /* ignore non-interesting aMedia */ 1205 DiskImageItem *subItem = createHdItem (0, aRoot, subHd, aStatus); 1206 createHdChildren (subItem, subHd, aStatus); 1207 } 1208 } 1209 1210 1211 DiskImageItem* VBoxDiskImageManagerDlg::searchItem (QListView *aList, QUuid aId) 1212 { 1213 DiskImageItem *item = 0, *iterator = 0; 1214 if (aList->firstChild() && aList->firstChild()->rtti() == 1001) 1215 iterator = static_cast<DiskImageItem*>(aList->firstChild()); 1216 while (iterator) 1217 { 1218 if (iterator->getUuid() == aId) 1219 item = iterator; 1220 iterator = iterator->nextSibling(); 1221 } 1222 return item; 1223 } 1224 1225 1226 void VBoxDiskImageManagerDlg::updateMedia (const VBoxMedia &aMedia) 1227 { 1228 /* ignore non-updated aMedia */ 1079 1229 if (!(type & aMedia.type)) 1080 1230 return; 1081 1231 1232 /* search for updated listview item */ 1082 1233 DiskImageItem *item = 0; 1083 1084 1234 switch (aMedia.type) 1085 1235 { 1086 1236 case VBoxDefs::HD: 1087 1237 { 1088 refreshList (hdsView, mHdsProgress);1089 1238 CHardDisk hd = aMedia.disk; 1090 item = createHdItem (hdsView, 0, hd);1091 createHdChildren (item, hd);1092 hdsView->adjustColumn (1);1093 hdsView->adjustColumn (2);1239 item = searchItem (hdsView, hd.GetId()); 1240 delete item; 1241 item = createHdItem (hdsView, 0, hd, aMedia.status); 1242 createHdChildren (item, hd, aMedia.status); 1094 1243 break; 1095 1244 } 1096 1245 case VBoxDefs::CD: 1097 1246 { 1098 refreshList (cdsView, mCdsProgress);1099 1247 CDVDImage cd = aMedia.disk; 1100 item = createCdItem (cdsView, 0, cd); 1101 cdsView->adjustColumn (1); 1248 item = searchItem (cdsView, cd.GetId()); 1249 delete item; 1250 item = createCdItem (cdsView, 0, cd, aMedia.status); 1102 1251 break; 1103 1252 } 1104 1253 case VBoxDefs::FD: 1105 1254 { 1106 refreshList (fdsView, mFdsProgress);1107 1255 CFloppyImage fd = aMedia.disk; 1108 item = createFdItem (fdsView, 0, fd); 1109 fdsView->adjustColumn (1); 1256 item = searchItem (fdsView, fd.GetId()); 1257 delete item; 1258 item = createFdItem (fdsView, 0, fd, aMedia.status); 1110 1259 break; 1111 1260 } … … 1121 1270 else if (aMedia.status == VBoxMedia::Error) 1122 1271 item->setPixmap (0, pxErroneous); 1272 1273 mProgressBar->setProgress (mProgressBar->progress() + 1); 1123 1274 } 1124 1275 … … 1160 1311 1161 1312 VBoxMediaList::const_iterator it; 1313 prepareToRefresh(); 1162 1314 for (it = list.begin(); it != list.end(); ++ it) 1163 insertMedia (*it); 1164 1165 if (!mediaList) 1315 updateMedia (*it); 1316 1317 if (mediaList) 1318 { 1319 mediaEnumerated (*mediaList); 1320 } 1321 else 1166 1322 { 1167 1323 /* only start enumerating media if we haven't been supplied with a list 1168 1324 * (it's ok if the enumeration has been already started, nothing will 1169 1325 * happen) */ 1170 refreshAll();1326 vboxGlobal().startEnumeratingMedia(); 1171 1327 } 1172 1328 } … … 1176 1332 { 1177 1333 if (!mToBeRefreshed) return; 1178 1179 insertMedia (aMedia);1334 updateMedia (aMedia); 1335 processCurrentChanged(); 1180 1336 } 1181 1337 … … 1185 1341 if (!mToBeRefreshed) return; 1186 1342 1187 delete mHdsProgress, delete mCdsProgress, delete mFdsProgress; 1188 mHdsProgress = 0, mCdsProgress = 0, mFdsProgress = 0; 1189 1190 cdsView->setCurrentItem (cdsView->firstChild()); 1191 fdsView->setCurrentItem (fdsView->firstChild()); 1192 hdsView->setCurrentItem (hdsView->firstChild()); 1193 cdsView->setSelected (cdsView->currentItem(), true); 1194 fdsView->setSelected (fdsView->currentItem(), true); 1195 hdsView->setSelected (hdsView->currentItem(), true); 1196 processCurrentChanged(); 1343 mProgressBar->setHidden (true); 1344 mProgressText->setHidden (true); 1197 1345 1198 1346 imRefreshAction->setEnabled (true); … … 1226 1374 1227 1375 1228 void VBoxDiskImageManagerDlg:: refreshAll()1376 void VBoxDiskImageManagerDlg::prepareToRefresh() 1229 1377 { 1230 1378 if (mToBeRefreshed) return; … … 1238 1386 fdsPane1->clear(), fdsPane2->clear(); 1239 1387 1388 /* prepare progressbar */ 1389 if (mProgressBar) 1390 { 1391 int totalSteps = 0; 1392 if (type & VBoxDefs::HD) 1393 totalSteps += vbox.GetHardDisks().GetCount(); 1394 if (type & VBoxDefs::CD) 1395 totalSteps += vbox.GetDVDImages().GetCount(); 1396 if (type & VBoxDefs::FD) 1397 totalSteps += vbox.GetFloppyImages().GetCount(); 1398 mProgressBar->setProgress (0, totalSteps); 1399 mProgressBar->setHidden (false); 1400 mProgressText->setHidden (false); 1401 } 1402 1240 1403 imRefreshAction->setEnabled (false); 1241 1404 setCursor (QCursor (BusyCursor)); 1242 1405 } 1406 1407 1408 void VBoxDiskImageManagerDlg::refreshAll() 1409 { 1410 if (mToBeRefreshed) return; 1411 prepareToRefresh(); 1412 /* lists clearing */ 1413 hdsView->clear(), cdsView->clear(), fdsView->clear(); 1414 /* load all lists */ 1415 loadListViews(); 1243 1416 /* start enumerating media */ 1244 1417 vboxGlobal().startEnumeratingMedia(); 1245 }1246 1247 void VBoxDiskImageManagerDlg::refreshList (QListView *aView, ProgressBarItem *&aItem)1248 {1249 if (!aItem)1250 {1251 aView->clear();1252 ULONG iCount = 0;1253 if (aView == hdsView)1254 iCount = vbox.GetHardDisks().GetCount();1255 else if (aView == cdsView)1256 iCount = vbox.GetDVDImages().GetCount();1257 else if (aView == fdsView)1258 iCount = vbox.GetFloppyImages().GetCount();1259 aItem = new ProgressBarItem (aView, iCount);1260 }1261 aItem->increaseProgress();1262 1418 } 1263 1419 … … 1323 1479 1324 1480 1325 void VBoxDiskImageManagerDlg::setCurrentItem (QListView *aListView, DiskImageItem *aItem) 1326 { 1481 void VBoxDiskImageManagerDlg::setCurrentItem (QListView *aListView, QListViewItem *aItem) 1482 { 1483 aListView->setFocus(); 1327 1484 if (aItem) 1328 1485 { 1329 1486 aListView->setCurrentItem (aItem); 1330 1487 aListView->setSelected (aListView->currentItem(), true); 1488 /* it is strange repeat but it works */ 1331 1489 aListView->adjustColumn (1); 1332 1490 aListView->adjustColumn (2); 1333 }1334 aListView->setFocus();1491 aListView->adjustColumn (1); 1492 } 1335 1493 processCurrentChanged (aListView->currentItem()); 1336 1494 } … … 1341 1499 QListView *currentList = getCurrentListView(); 1342 1500 currentList->setFocus(); 1501 1502 QListViewItem *itemToSelect = 1503 !currentList->isSelected (currentList->currentItem()) ? 1504 currentList->firstChild() : currentList->currentItem(); 1505 setCurrentItem (currentList, itemToSelect); 1343 1506 1344 1507 /* tab stop setup */ … … 1360 1523 setTabOrder (buttonHelp, buttonOk); 1361 1524 setTabOrder (buttonOk, twImages); 1362 1363 processCurrentChanged (currentList->selectedItem());1364 1525 } 1365 1526 … … 1440 1601 { 1441 1602 CHardDisk hd = dlg.hardDisk(); 1442 DiskImageItem *createdItem = createHdItem (hdsView, 0, hd); 1603 VBoxMedia::Status status = hd.GetAccessible() ? 1604 VBoxMedia::Ok : VBoxMedia::Inaccessible; 1605 DiskImageItem *createdItem = createHdItem (hdsView, 0, hd, status); 1443 1606 setCurrentItem (hdsView, createdItem); 1444 1607 /* synchronize modeless dialog if present */ 1445 1608 if (mModelessDialog && mModelessDialog != this) 1446 mModelessDialog->createHdItem (mModelessDialog->hdsView, 0, hd); 1609 mModelessDialog->createHdItem (mModelessDialog->hdsView, 1610 0, hd, status); 1447 1611 } 1448 1612 } … … 1457 1621 1458 1622 QString dir; 1459 if (item )1623 if (item && item->getStatus() == VBoxMedia::Ok) 1460 1624 dir = item->getPath().stripWhiteSpace(); 1461 1625 … … 1490 1654 title); 1491 1655 1492 DiskImageItem *createdItem = 0; 1493 if (src) 1494 { 1495 QUuid uuid; 1496 if (currentList == hdsView) 1497 { 1498 CVirtualDiskImage vdi = vbox.OpenVirtualDiskImage (src); 1499 if (vbox.isOk()) 1500 { 1501 /// @todo (dmik) later, change wrappers so that converting 1502 // to CUnknown is not necessary for cross-assignments 1503 CHardDisk hardDisk = CUnknown (vdi); 1504 vbox.RegisterHardDisk (hardDisk); 1505 if (vbox.isOk()) 1506 { 1507 createdItem = createHdItem (hdsView, 0, hardDisk); 1508 /* synchronize modeless dialog if present */ 1509 if (mModelessDialog && mModelessDialog != this) 1510 mModelessDialog->createHdItem (mModelessDialog->hdsView, 0, hardDisk); 1511 } 1512 } 1513 } 1514 else 1515 if (currentList == cdsView) 1516 { 1517 CDVDImage dvdImage = vbox.OpenDVDImage (src, uuid); 1518 if (vbox.isOk()) 1519 { 1520 vbox.RegisterDVDImage (dvdImage); 1521 if (vbox.isOk()) 1522 { 1523 createdItem = createCdItem (cdsView, 0, dvdImage); 1524 /* synchronize modeless dialog if present */ 1525 if (mModelessDialog && mModelessDialog != this) 1526 mModelessDialog->createCdItem (mModelessDialog->cdsView, 0, dvdImage); 1527 } 1528 } 1529 } 1530 else 1531 if (currentList == fdsView) 1532 { 1533 CFloppyImage floppyImage = vbox.OpenFloppyImage (src, uuid); 1534 if (vbox.isOk()) 1535 { 1536 vbox.RegisterFloppyImage (floppyImage); 1537 if (vbox.isOk()) 1538 { 1539 createdItem = createFdItem (fdsView, 0, floppyImage); 1540 /* synchronize modeless dialog if present */ 1541 if (mModelessDialog && mModelessDialog != this) 1542 mModelessDialog->createFdItem (mModelessDialog->fdsView, 0, floppyImage); 1543 } 1544 } 1545 } 1546 1547 if (!vbox.isOk()) 1548 { 1549 vboxProblem().cannotRegisterMedia (this, vbox, type, src); 1550 } 1551 } 1552 /* set current item */ 1656 DiskImageItem *createdItem = addImageToList (src, type); 1553 1657 setCurrentItem (currentList, createdItem); 1658 1659 if (!vbox.isOk()) 1660 { 1661 vboxProblem().cannotRegisterMedia (this, vbox, type, src); 1662 } 1554 1663 } 1555 1664 … … 1573 1682 int deleteImage; 1574 1683 if (vbox.GetHardDisk (uuid).GetStorageType() == CEnums::VirtualDiskImage && 1575 vbox.GetHardDisk (uuid).GetAccessible())1684 item->getStatus() == VBoxMedia::Ok) 1576 1685 { 1577 1686 deleteImage = vboxProblem().confirmHardDiskImageDeletion (this, src); … … 1613 1722 { 1614 1723 delete item; 1615 setCurrentItem (currentList, (DiskImageItem*)currentList->currentItem());1724 setCurrentItem (currentList, currentList->currentItem()); 1616 1725 /* synchronize modeless dialog if present */ 1617 1726 if (mModelessDialog && mModelessDialog != this) … … 1825 1934 accept(); 1826 1935 } 1827 1828 1829 void VBoxDiskImageManagerDlg::uploadCurrentList (QStringList &aNames,1830 QStringList &aKeys,1831 const QUuid &aMachineId)1832 {1833 QListView *currentList = getCurrentListView();1834 DiskImageItem *item = 0;1835 if (currentList->firstChild() &&1836 currentList->firstChild()->rtti() == 1001)1837 item = static_cast<DiskImageItem*> (currentList->firstChild());1838 Assert (item);1839 1840 do {1841 if (QUuid (item->getMachineId()).isNull() ||1842 QUuid (item->getMachineId()) == aMachineId)1843 {1844 aNames << QString ("%1 (%2)")1845 .arg (item->getName().stripWhiteSpace())1846 .arg (item->getPath().stripWhiteSpace());1847 aKeys << item->getUuid();1848 }1849 item = item->nextSibling();1850 } while (item);1851 }
Note:
See TracChangeset
for help on using the changeset viewer.