Changeset 59 in vbox for trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h
- Timestamp:
- Jan 16, 2007 12:49:17 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxDiskImageManagerDlg.ui.h
r1 r59 106 106 int compare (QListViewItem *aItem, int aColumn, bool aAscending) const 107 107 { 108 if (aItem->rtti() == 1002) 109 return aAscending ? 1 : -1; 110 108 111 ULONG64 thisValue = vboxGlobal().parseSize ( text (aColumn)); 109 112 ULONG64 thatValue = vboxGlobal().parseSize (aItem->text (aColumn)); 110 113 if (thisValue && thatValue) 111 return thisValue > thatValue ? 1 : -1; 114 { 115 if (thisValue == thatValue) 116 return 0; 117 else 118 return thisValue > thatValue ? 1 : -1; 119 } 112 120 else 113 121 return QListViewItem::compare (aItem, aColumn, aAscending); … … 136 144 137 145 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 } 138 187 }; 139 188 … … 163 212 connect (&vboxGlobal(), SIGNAL (snapshotChanged (const VBoxSnapshotEvent &)), 164 213 mModelessDialog, SLOT (refreshAll())); 165 214 166 215 /* listen also to the machine state change because hard disks of running 167 216 * VMs are inaccessible by the current design */ … … 184 233 mToBeRefreshed = false; 185 234 mInLoop = false; 235 236 mHdsProgress = 0; 237 mCdsProgress = 0; 238 mFdsProgress = 0; 186 239 187 240 defaultButton = searchDefaultButton(); … … 221 274 /* setup image list views */ 222 275 276 hdsView->setShowSortIndicator (true); 277 cdsView->setShowSortIndicator (true); 278 fdsView->setShowSortIndicator (true); 279 223 280 hdsView->setColumnAlignment (1, Qt::AlignRight); 224 281 hdsView->setColumnAlignment (2, Qt::AlignRight); … … 234 291 cdsView->header()->setStretchEnabled (true, 0); 235 292 293 /* setup list-view's item tooltip */ 294 hdsView->setShowToolTips (false); 295 cdsView->setShowToolTips (false); 296 fdsView->setShowToolTips (false); 236 297 connect (hdsView, SIGNAL (onItem (QListViewItem*)), 237 298 this, SLOT (mouseOnItem(QListViewItem*))); … … 240 301 connect (fdsView, SIGNAL (onItem (QListViewItem*)), 241 302 this, SLOT (mouseOnItem(QListViewItem*))); 242 hdsView->setShowToolTips (false); 243 cdsView->setShowToolTips (false); 244 fdsView->setShowToolTips (false); 303 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*))); 245 314 246 315 /* status-bar currently disabled */ … … 424 493 425 494 VBoxGlobal::centerWidget (this, parentWidget()); 426 427 updateNotice (getCurrentListView());428 495 } 429 496 … … 432 499 { 433 500 QListView *currentList = getCurrentListView(); 434 DiskImageItem *item = 0; 435 if (aItem->rtti() == 1001) 436 item = static_cast<DiskImageItem*> (aItem); 437 Assert (item); 438 439 QToolTip::add (currentList->viewport(), currentList->itemRect(item), item->getToolTip()); 501 QString tip; 502 switch (aItem->rtti()) 503 { 504 case 1001: 505 tip = static_cast<DiskImageItem*> (aItem)->getToolTip(); 506 break; 507 case 1002: 508 tip = tr ("Enumeration in progress...", "Media accessibility check"); 509 break; 510 default: 511 Assert (0); 512 } 513 QToolTip::add (currentList->viewport(), currentList->itemRect (aItem), tip); 440 514 } 441 515 … … 445 519 sizeGrip->move (centralWidget()->rect().bottomRight() - 446 520 QPoint(sizeGrip->rect().width() - 1, sizeGrip->rect().height() - 1)); 447 448 updateNotice (getCurrentListView());449 521 } 450 522 … … 546 618 switch (aEvent->type()) 547 619 { 548 /* Dragged object(s) has entered list-view area */549 620 case QEvent::DragEnter: 550 621 { … … 557 628 break; 558 629 } 559 /* Dragged object(s) was dropped on list-view area */560 case QEvent::Drop:561 {562 if (aObject == currentList)563 {564 QDropEvent *dropEvent = static_cast<QDropEvent*>(aEvent);565 566 QStringList droppedList;567 QUriDrag::decodeLocalFiles (dropEvent, droppedList);568 569 for (QStringList::Iterator it = droppedList.begin();570 it != droppedList.end(); ++it)571 {572 /* Checking dropped media type */573 VBoxDefs::DiskType type = VBoxDefs::InvalidType;574 if ((*it).endsWith ("iso", false))575 {576 if (currentList == cdsView) type = VBoxDefs::CD;577 }578 else if ((*it).endsWith ("img", false))579 {580 if (currentList == fdsView) type = VBoxDefs::FD;581 }582 else if ((*it).endsWith ("vdi", false))583 {584 if (currentList == hdsView) type = VBoxDefs::HD;585 }586 /* If media type has been determined - attach this device */587 if (type)588 addDroppedImage(*it, type);589 }590 dropEvent->accept();591 refreshAll();592 }593 break;594 }595 630 case QEvent::FocusIn: 596 631 { … … 617 652 } 618 653 return QMainWindow::eventFilter (aObject, aEvent); 654 } 655 656 657 void VBoxDiskImageManagerDlg::addDroppedImages (QDropEvent *aEvent) 658 { 659 QListView *currentList = getCurrentListView(); 660 661 QStringList droppedList; 662 QUriDrag::decodeLocalFiles (aEvent, droppedList); 663 664 for (QStringList::Iterator it = droppedList.begin(); 665 it != droppedList.end(); ++it) 666 { 667 // Checking dropped media type 668 VBoxDefs::DiskType type = VBoxDefs::InvalidType; 669 if ((*it).endsWith ("iso", false)) 670 { 671 if (currentList == cdsView) type = VBoxDefs::CD; 672 } 673 else if ((*it).endsWith ("img", false)) 674 { 675 if (currentList == fdsView) type = VBoxDefs::FD; 676 } 677 else if ((*it).endsWith ("vdi", false)) 678 { 679 if (currentList == hdsView) type = VBoxDefs::HD; 680 } 681 // If media type has been determined - attach this device 682 if (type) 683 addDroppedImage (*it, type); 684 } 685 686 refreshAll(); 619 687 } 620 688 … … 695 763 QString VBoxDiskImageManagerDlg::getDVDImageUsage (const QUuid &aId) 696 764 { 765 CVirtualBox vbox = vboxGlobal().virtualBox(); 766 697 767 QStringList permMachines = 698 768 QStringList::split (' ', vbox.GetDVDImageUsage (aId, CEnums::PermanentUsage)); … … 731 801 QString VBoxDiskImageManagerDlg::getFloppyImageUsage (const QUuid &aId) 732 802 { 803 CVirtualBox vbox = vboxGlobal().virtualBox(); 804 733 805 QStringList permMachines = 734 806 QStringList::split (' ', vbox.GetFloppyImageUsage (aId, CEnums::PermanentUsage)); … … 763 835 764 836 return usage; 837 } 838 839 840 QString VBoxDiskImageManagerDlg::composeHdToolTip (CHardDisk &aHd) 841 { 842 CVirtualBox vbox = vboxGlobal().virtualBox(); 843 bool accessible = aHd.GetAccessible(); 844 QUuid machineId = aHd.GetMachineId(); 845 846 QString src = aHd.GetLocation(); 847 QFileInfo fi (src); 848 QString location = aHd.GetStorageType() == CEnums::ISCSIHardDisk ? src : 849 QDir::convertSeparators (fi.absFilePath()); 850 851 QString storageType = vboxGlobal().toString (aHd.GetStorageType()); 852 QString hardDiskType = vboxGlobal().hardDiskTypeString (aHd); 853 854 QString usage; 855 if (!machineId.isNull()) 856 usage = vbox.GetMachine (machineId).GetName(); 857 858 QString snapshotName; 859 if (!machineId.isNull() && !aHd.GetSnapshotId().isNull()) 860 { 861 CSnapshot snapshot = vbox.GetMachine (machineId). 862 GetSnapshot (aHd.GetSnapshotId()); 863 if (!snapshot.isNull()) 864 snapshotName = snapshot.GetName(); 865 } 866 867 /* compose tool-tip information */ 868 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); 888 } 889 return tip; 890 } 891 892 QString VBoxDiskImageManagerDlg::composeCdToolTip (CDVDImage &aCd) 893 { 894 bool accessible = aCd.GetAccessible(); 895 QString src = aCd.GetFilePath(); 896 QFileInfo fi (src); 897 QString location = QDir::convertSeparators (fi.absFilePath ()); 898 QUuid uuid = aCd.GetId(); 899 QString usage = getDVDImageUsage (uuid); 900 901 /* compose tool-tip information */ 902 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); 919 } 920 return tip; 921 } 922 923 QString VBoxDiskImageManagerDlg::composeFdToolTip (CFloppyImage &aFd) 924 { 925 bool accessible = aFd.GetAccessible(); 926 QString src = aFd.GetFilePath(); 927 QFileInfo fi (src); 928 QString location = QDir::convertSeparators (fi.absFilePath ()); 929 QUuid uuid = aFd.GetId(); 930 QString usage = getFloppyImageUsage (uuid); 931 932 /* compose tool-tip information */ 933 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>") 946 .arg (location); 947 948 if (!usage.isNull()) 949 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (usage); 950 } 951 return tip; 765 952 } 766 953 … … 812 999 item->setUuid (uuid); 813 1000 item->setMachineId (machineId); 814 815 /* compose tool-tip information */ 816 if (!accessible) 817 { 818 item->setToolTip (tr ("<nobr><b>%1</b></nobr><br>%2") 819 .arg (item->getPath()) 820 .arg (aHd.GetLastAccessError())); 821 } 822 else 823 { 824 QString tip = tr ("<nobr><b>%1</b></nobr><br>" 825 "<nobr>Disk type: %2</nobr><br>" 826 "<nobr>Storage type: %3</nobr>") 827 .arg (item->getPath()) 828 .arg (item->getDiskType()) 829 .arg (item->getStorageType()); 830 831 QString str = item->getUsage(); 832 if (!str.isNull()) 833 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (str); 834 835 str = item->getSnapshotName(); 836 if (!str.isNull()) 837 tip += tr ("<br><nobr>Snapshot: %5</nobr>").arg (str); 838 839 item->setToolTip (tip); 840 } 1001 item->setToolTip (composeHdToolTip (aHd)); 841 1002 842 1003 return item; … … 866 1027 item->setActualSize (size); 867 1028 item->setUuid (uuid); 868 869 /* compose tool-tip information */ 870 if (!accessible) 871 { 872 /// @todo (r=dmik) correct this when GetLastAccessError() is 873 // implemented for IFloppyImage/IDVDImage 874 item->setToolTip (tr ("<nobr><b>%1</b></nobr><br>%2") 875 .arg (item->getPath()) 876 .arg (tr ("The image file is not accessible", 877 "CD/DVD/Floppy"))); 878 } 879 else 880 { 881 QString tip = tr ("<nobr><b>%1</b></nobr>") 882 .arg (item->getPath()); 883 884 QString str = item->getUsage(); 885 if (!str.isNull()) 886 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (str); 887 888 item->setToolTip (tip); 889 } 1029 item->setToolTip (composeCdToolTip (aCd)); 890 1030 891 1031 return item; … … 915 1055 item->setActualSize (size); 916 1056 item->setUuid (uuid); 917 918 /* compose tool-tip information */ 919 if (!accessible) 920 { 921 /// @todo (r=dmik) correct this when GetLastAccessError() is 922 // implemented for IFloppyImage/IDVDImage 923 item->setToolTip (tr ("<nobr><b>%1</b></nobr><br>%2") 924 .arg (item->getPath()) 925 .arg (tr ("The image file is not accessible", 926 "CD/DVD/Floppy"))); 927 } 928 else 929 { 930 QString tip = tr ("<nobr><b>%1</b></nobr>") 931 .arg (item->getPath()); 932 933 QString str = item->getUsage(); 934 if (!str.isNull()) 935 tip += tr ("<br><nobr>Attached to: %1</nobr>").arg (str); 936 937 item->setToolTip (tip); 938 } 1057 item->setToolTip (composeFdToolTip (aFd)); 939 1058 940 1059 return item; … … 967 1086 case VBoxDefs::HD: 968 1087 { 1088 refreshList (hdsView, mHdsProgress); 969 1089 CHardDisk hd = aMedia.disk; 970 1090 item = createHdItem (hdsView, 0, hd); … … 976 1096 case VBoxDefs::CD: 977 1097 { 1098 refreshList (cdsView, mCdsProgress); 978 1099 CDVDImage cd = aMedia.disk; 979 1100 item = createCdItem (cdsView, 0, cd); … … 983 1104 case VBoxDefs::FD: 984 1105 { 1106 refreshList (fdsView, mFdsProgress); 985 1107 CFloppyImage fd = aMedia.disk; 986 1108 item = createFdItem (fdsView, 0, fd); … … 1051 1173 1052 1174 1053 void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &) 1054 { 1055 /* This function is unnecessary since media devices enumeration 1056 performs on full VBoxMediaList completion */ 1175 void VBoxDiskImageManagerDlg::mediaEnumerated (const VBoxMedia &aMedia) 1176 { 1177 if (!mToBeRefreshed) return; 1178 1179 insertMedia (aMedia); 1057 1180 } 1058 1181 … … 1062 1185 if (!mToBeRefreshed) return; 1063 1186 1064 hdsView->clear(); 1065 cdsView->clear(); 1066 fdsView->clear(); 1067 1068 VBoxMediaList::const_iterator it; 1069 for (it = aList.begin(); it != aList.end(); ++ it) 1070 insertMedia (*it); 1071 1072 removeNotice (hdsView), removeNotice (cdsView), removeNotice (fdsView); 1187 delete mHdsProgress, delete mCdsProgress, delete mFdsProgress; 1188 mHdsProgress = 0, mCdsProgress = 0, mFdsProgress = 0; 1073 1189 1074 1190 cdsView->setCurrentItem (cdsView->firstChild()); 1075 1191 fdsView->setCurrentItem (fdsView->firstChild()); 1076 1192 hdsView->setCurrentItem (hdsView->firstChild()); 1077 cdsView->setSelected (cdsView-> firstChild(), true);1078 fdsView->setSelected (fdsView-> firstChild(), true);1079 hdsView->setSelected (hdsView-> firstChild(), true);1193 cdsView->setSelected (cdsView->currentItem(), true); 1194 fdsView->setSelected (fdsView->currentItem(), true); 1195 hdsView->setSelected (hdsView->currentItem(), true); 1080 1196 processCurrentChanged(); 1081 1197 … … 1110 1226 1111 1227 1112 void VBoxDiskImageManagerDlg::createNotice (QListView *aListView)1113 {1114 QString warning = tr ("...enumerating media...");1115 QLabel *notice = new QLabel (warning, aListView->viewport(), "notice");1116 notice->setFrameShape (QFrame::Box);1117 notice->setMargin (10);1118 notice->adjustSize();1119 aListView->setEnabled (false);1120 }1121 1122 1123 void VBoxDiskImageManagerDlg::updateNotice (QListView *aListView)1124 {1125 QLabel *notice = (QLabel*)aListView->child ("notice");1126 if (notice)1127 notice->move ((((QListView*)notice->parent())->width() - notice->width())/2,1128 (((QListView*)notice->parent())->height() - notice->height())/2);1129 }1130 1131 1132 void VBoxDiskImageManagerDlg::removeNotice (QListView *aListView)1133 {1134 QLabel *notice = (QLabel*)aListView->child ("notice");1135 if (notice) delete notice;1136 aListView->setEnabled (true);1137 }1138 1139 1140 1228 void VBoxDiskImageManagerDlg::refreshAll() 1141 1229 { … … 1143 1231 mToBeRefreshed = true; 1144 1232 1145 hdsView->clear(), cdsView->clear(), fdsView->clear(); 1146 createNotice (hdsView), createNotice (cdsView), createNotice (fdsView); 1233 /* info panel clearing */ 1234 hdsPane1->clear(); 1235 hdsPane2->clear(), hdsPane3->clear(); 1236 hdsPane4->clear(), hdsPane5->clear(); 1237 cdsPane1->clear(), cdsPane2->clear(); 1238 fdsPane1->clear(), fdsPane2->clear(); 1239 1147 1240 imRefreshAction->setEnabled (false); 1148 1241 setCursor (QCursor (BusyCursor)); … … 1150 1243 /* start enumerating media */ 1151 1244 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(); 1152 1262 } 1153 1263 … … 1231 1341 QListView *currentList = getCurrentListView(); 1232 1342 currentList->setFocus(); 1233 updateNotice (currentList);1234 1343 1235 1344 /* tab stop setup */ … … 1260 1369 static_cast<DiskImageItem*> (aItem) : 0; 1261 1370 1262 bool modifyEnabled = item && item->getUsage().isNull(); 1371 bool modifyEnabled = item && item->getUsage().isNull() && 1372 !item->firstChild() && !item->getPath().isNull(); 1263 1373 bool releaseEnabled = item && !item->getUsage().isNull() && 1264 1374 checkImage (item) &&
Note:
See TracChangeset
for help on using the changeset viewer.