Changeset 8093 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Apr 17, 2008 12:34:17 PM (17 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h
r8071 r8093 215 215 } 216 216 217 KStorageBus toStorageBusType (const QString &s) const 218 { 219 QStringVector::const_iterator it = 220 qFind (storageBuses.begin(), storageBuses.end(), s); 221 AssertMsg (it != storageBuses.end(), ("No value for {%s}", s.latin1())); 217 /** 218 * Returns a string representation of the given KStorageBus enum value. 219 * Complementary to #toStorageBusType (const QString &) const. 220 */ 221 QString toString (KStorageBus aBus) const 222 { 223 AssertMsg (!storageBuses [aBus].isNull(), ("No text for %d", aBus)); 224 return storageBuses [aBus]; 225 } 226 227 /** 228 * Returns a KStorageBus enum value corresponding to the given string 229 * representation. Complementary to #toString (KStorageBus) const. 230 */ 231 KStorageBus toStorageBusType (const QString &aBus) const 232 { 233 QStringVector::const_iterator it = 234 qFind (storageBuses.begin(), storageBuses.end(), aBus); 235 AssertMsg (it != storageBuses.end(), ("No value for {%s}", aBus.latin1())); 222 236 return KStorageBus (it - storageBuses.begin()); 223 237 } 224 238 225 QString toString (KStorageBus t) const 226 { 227 AssertMsg (!storageBuses [t].isNull(), ("No text for %d", t)); 228 return storageBuses [t]; 229 } 230 231 LONG toStorageChannelType (KStorageBus t, const QString &c) const; 232 QString toString (KStorageBus t, LONG c) const; 233 234 LONG toStorageDeviceType (KStorageBus t, const QString &c) const; 235 QString toString (KStorageBus t, LONG c, LONG d) const; 239 QString toString (KStorageBus aBus, LONG aChannel) const; 240 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const; 241 242 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const; 243 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const; 244 245 QString toFullString (KStorageBus aBus, LONG aChannel, LONG aDevice) const; 236 246 237 247 QString toString (KHardDiskType t) const -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r8071 r8093 738 738 , deviceTypes (KDeviceType_COUNT) 739 739 , storageBuses (KStorageBus_COUNT) 740 , storageBusDevices ( 4)741 , storageBusChannels ( 3)740 , storageBusDevices (3) 741 , storageBusChannels (2) 742 742 , diskTypes (KHardDiskType_COUNT) 743 743 , diskStorageTypes (KHardDiskStorageType_COUNT) … … 960 960 } 961 961 962 LONG VBoxGlobal::toStorageDeviceType (KStorageBus t, const QString &c) const 963 { 964 LONG device; 965 switch (t) 962 /** 963 * Returns a string representation of the given channel number on the given 964 * storage bus. Complementary to #toStorageChannel (KStorageBus, const 965 * QString &) const. 966 */ 967 QString VBoxGlobal::toString (KStorageBus aBus, LONG aChannel) const 968 { 969 Assert (storageBusChannels.count() == 2); 970 QString channel; 971 972 switch (aBus) 966 973 { 967 974 case KStorageBus_IDE: 968 975 { 976 if (aChannel == 0 || aChannel == 1) 977 { 978 channel = storageBusChannels [aChannel]; 979 break; 980 } 981 982 AssertMsgFailedBreakVoid (("Invalid channel %d\n", aChannel)); 983 } 984 case KStorageBus_SATA: 985 { 986 AssertMsgBreakVoid (aChannel == 0, ("Invalid channel %d\n", aChannel)); 987 988 /* null string since the SATA channel is alwayz zero so far */ 989 break; 990 } 991 default: 992 AssertFailedBreakVoid(); 993 } 994 995 return channel; 996 } 997 998 /** 999 * Returns a channel number on the given storage bus corresponding to the given 1000 * string representation. Complementary to #toString (KStorageBus, LONG) const. 1001 */ 1002 LONG VBoxGlobal::toStorageChannel (KStorageBus aBus, const QString &aChannel) const 1003 { 1004 LONG channel = 0; 1005 1006 switch (aBus) 1007 { 1008 case KStorageBus_IDE: 1009 { 969 1010 QStringVector::const_iterator it = 970 qFind (storageBusDevices.begin(), storageBusDevices.end(), c); 971 AssertMsg (it != storageBusDevices.end(), ("No value for {%s}", c.latin1())); 1011 qFind (storageBusChannels.begin(), storageBusChannels.end(), 1012 aChannel); 1013 AssertMsgBreakVoid (it != storageBusChannels.end(), 1014 ("No value for {%s}\n", aChannel.latin1())); 1015 channel = (LONG) (it - storageBusChannels.begin()); 1016 break; 1017 } 1018 case KStorageBus_SATA: 1019 { 1020 AssertMsgBreakVoid (aChannel.isEmpty(), 1021 ("Invalid channel {%s}\n", aChannel.latin1())); 1022 /* always zero so far for SATA */ 1023 break; 1024 } 1025 default: 1026 AssertFailedBreakVoid(); 1027 } 1028 1029 return channel; 1030 } 1031 1032 /** 1033 * Returns a string representation of the given device number of the given 1034 * channel on the given storage bus. Complementary to #toStorageDevice 1035 * (KStorageBus, LONG, const QString &) const. 1036 */ 1037 QString VBoxGlobal::toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const 1038 { 1039 NOREF (aChannel); 1040 1041 Assert (storageBusDevices.count() == 3); 1042 QString device; 1043 1044 switch (aBus) 1045 { 1046 case KStorageBus_IDE: 1047 { 1048 if (aDevice == 0 || aDevice == 1) 1049 { 1050 device = storageBusDevices [aDevice]; 1051 break; 1052 } 1053 1054 AssertMsgFailedBreakVoid (("Invalid device %d\n", aDevice)); 1055 } 1056 case KStorageBus_SATA: 1057 { 1058 device = storageBusDevices [2].arg (aDevice); 1059 break; 1060 } 1061 default: 1062 AssertFailedBreakVoid(); 1063 } 1064 1065 return device; 1066 } 1067 1068 /** 1069 * Returns a device number of the given channel on the given storage bus 1070 * corresponding to the given string representation. Complementary to #toString 1071 * (KStorageBus, LONG, LONG) const. 1072 */ 1073 LONG VBoxGlobal::toStorageDevice (KStorageBus aBus, LONG aChannel, 1074 const QString &aDevice) const 1075 { 1076 NOREF (aChannel); 1077 1078 LONG device = 0; 1079 1080 switch (aBus) 1081 { 1082 case KStorageBus_IDE: 1083 { 1084 QStringVector::const_iterator it = 1085 qFind (storageBusDevices.begin(), storageBusDevices.end(), 1086 aDevice); 1087 AssertMsg (it != storageBusDevices.end(), 1088 ("No value for {%s}", aDevice.latin1())); 972 1089 device = (LONG) (it - storageBusDevices.begin()); 973 1090 break; 974 1091 } 975 default: 976 { 977 device = 0; 978 break; 979 } 980 } 981 return device; 982 } 983 984 QString VBoxGlobal::toString (KStorageBus t, LONG c, LONG d) const 985 { 986 Assert (storageBusDevices.count() == 4); 987 QString dev; 988 989 NOREF(c); 990 switch (t) 991 { 992 case KStorageBus_IDE: 993 { 994 if (d == 0 || d == 1) 1092 case KStorageBus_SATA: 1093 { 1094 /// @todo use regexp to properly extract the %1 text 1095 QString tpl = storageBusDevices [2].arg (""); 1096 if (aDevice.startsWith (tpl)) 995 1097 { 996 dev = storageBusDevices [d];1098 device = aDevice.right (aDevice.length() - tpl.length()).toLong(); 997 1099 break; 998 1100 } 1101 1102 AssertMsgFailedBreakVoid (("Invalid device {%s}\n", aDevice.latin1())); 1103 } 1104 default: 1105 AssertFailedBreakVoid(); 1106 } 1107 1108 return device; 1109 } 1110 1111 /** 1112 * Returns a full string representation of the given device of the given channel 1113 * on the given storage bus. Complementary to #toStorageParams (KStorageBus, 1114 * LONG, LONG) const. 1115 */ 1116 QString VBoxGlobal::toFullString (KStorageBus aBus, LONG aChannel, 1117 LONG aDevice) const 1118 { 1119 QString device; 1120 1121 switch (aBus) 1122 { 1123 case KStorageBus_IDE: 1124 { 1125 device = QString ("%1 %2 %3") 1126 .arg (vboxGlobal().toString (aBus)) 1127 .arg (vboxGlobal().toString (aBus, aChannel)) 1128 .arg (vboxGlobal().toString (aBus, aChannel, aDevice)); 1129 break; 999 1130 } 1000 1131 case KStorageBus_SATA: 1001 1132 { 1002 dev = storageBusDevices [3].arg (d); 1133 /* we only have one SATA channel so far which is always zero */ 1134 device = QString ("%1 %2") 1135 .arg (vboxGlobal().toString (aBus)) 1136 .arg (vboxGlobal().toString (aBus, aChannel, aDevice)); 1003 1137 break; 1004 1138 } 1005 1139 default: 1006 dev = storageBusDevices [2].arg (d); 1007 } 1008 return dev; 1009 } 1010 1011 LONG VBoxGlobal::toStorageChannelType (KStorageBus t, const QString &c) const 1012 { 1013 LONG channel; 1014 switch (t) 1015 { 1016 case KStorageBus_IDE: 1017 { 1018 QStringVector::const_iterator it = 1019 qFind (storageBusChannels.begin(), storageBusChannels.end(), c); 1020 AssertMsg (it != storageBusChannels.end(), ("No value for {%s}", c.latin1())); 1021 channel = (LONG) (it - storageBusChannels.begin()); 1022 break; 1023 } 1024 default: 1025 { 1026 channel = 0; 1027 break; 1028 } 1029 } 1030 return channel; 1031 } 1032 1033 QString VBoxGlobal::toString (KStorageBus t, LONG c) const 1034 { 1035 Assert (storageBusChannels.count() == 3); 1036 QString dev; 1037 switch (t) 1038 { 1039 case KStorageBus_IDE: 1040 { 1041 if (c == 0 || c == 1) 1042 { 1043 dev = storageBusChannels [c]; 1044 break; 1045 } 1046 } 1047 default: 1048 dev = storageBusChannels [2].arg (c); 1049 } 1050 return dev; 1140 AssertFailedBreakVoid(); 1141 } 1142 1143 return device; 1051 1144 } 1052 1145 … … 1439 1532 { 1440 1533 QString src = root.GetLocation(); 1534 KStorageBus bus = hda.GetBus(); 1535 LONG channel = hda.GetChannel(); 1536 LONG device = hda.GetDevice(); 1441 1537 hardDisks += QString (sSectionItemTpl) 1442 .arg (QString ("%1 %2") 1443 .arg (toString (hda.GetBus(), hda.GetChannel())) 1444 .arg (toString (hda.GetBus(), hda.GetChannel(), 1445 hda.GetDevice()))) 1538 .arg (toFullString (bus, channel, device)) 1446 1539 .arg (QString ("%1 [<nobr>%2</nobr>]") 1447 1540 .arg (prepareFileNameForHTML (src)) … … 2344 2437 tr ("SATA", "StorageBus"); 2345 2438 2346 Assert (storageBusChannels.count() == 3);2439 Assert (storageBusChannels.count() == 2); 2347 2440 storageBusChannels [0] = 2348 2441 tr ("Primary", "StorageBusChannel"); 2349 2442 storageBusChannels [1] = 2350 2443 tr ("Secondary", "StorageBusChannel"); 2351 storageBusChannels [2] = 2352 tr ("Channel %1", "StorageBusChannel"); 2353 2354 Assert (storageBusDevices.count() == 4); 2444 2445 Assert (storageBusDevices.count() == 3); 2355 2446 storageBusDevices [0] = tr ("Master", "StorageBusDevice"); 2356 2447 storageBusDevices [1] = tr ("Slave", "StorageBusDevice"); 2357 storageBusDevices [2] = tr ("Device %1", "StorageBusDevice"); 2358 storageBusDevices [3] = tr ("Port %1", "StorageBusDevice"); 2448 storageBusDevices [2] = tr ("Port %1", "StorageBusDevice"); 2359 2449 2360 2450 diskTypes [KHardDiskType_Normal] = -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxHardDiskSettings.ui
r8075 r8093 1 1 <!DOCTYPE UI><UI version="3.3" stdsetdef="1"> 2 2 <class>VBoxHardDiskSettings</class> 3 <comment> 4 :mode=html:tabSize=4:indentSize=4:noTabs=true: 5 :folding=explicit:collapseFolds=1: 6 7 VBox GUI: Hard Disk Settings UI (Qt Designer). 8 9 Copyright (C) 2008 innotek GmbH 10 11 This file is part of VirtualBox Open Source Edition (OSE), as 12 available from http://www.virtualbox.org. This file is free software; 13 you can redistribute it and/or modify it under the terms of the GNU 14 General Public License (GPL) as published by the Free Software 15 Foundation, in version 2 as it comes in the "COPYING" file of the 16 VirtualBox OSE distribution. VirtualBox OSE is distributed in the 17 hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 18 </comment> 3 19 <widget class="QWidget"> 4 20 <property name="name"> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxHardDiskSettings.ui.h
r8075 r8093 6 6 7 7 /* 8 * Copyright (C) 200 6-2007innotek GmbH8 * Copyright (C) 2008 innotek GmbH 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 28 28 class HDSlotItem; 29 29 30 /** Combines the string and the numeric representation of the hard disk slot. */ 31 struct HDSlot 32 { 33 HDSlot() : bus (KStorageBus_Null), channel (0), device (0) {} 34 HDSlot (const QString &aStr, KStorageBus aBus, LONG aChannel, LONG aDevice) 35 : str (aStr), bus (aBus), channel (aChannel), device (aDevice) {} 36 37 QString str; 38 KStorageBus bus; 39 LONG channel; 40 LONG device; 41 }; 42 30 43 /** 31 44 * QObject class reimplementation to use for making selected IDE & SATA … … 47 60 } 48 61 49 Q StringListlist (HDSlotItem *aForSubscriber);62 QValueList <HDSlot> list (HDSlotItem *aForSubscriber); 50 63 51 64 int totalCount() { return mIDEList.size() + mSATAList.size(); } … … 95 108 void makeIDEList() 96 109 { 97 QString device ("%1 %2 %3");98 99 110 mIDEList.clear(); 100 111 101 112 /* IDE Primary Master */ 102 mIDEList << device.arg (vboxGlobal().toString (KStorageBus_IDE)) 103 .arg (vboxGlobal().toString (KStorageBus_IDE, 0)) 104 .arg (vboxGlobal().toString (KStorageBus_IDE, 0, 0)); 105 113 mIDEList << HDSlot (vboxGlobal().toFullString (KStorageBus_IDE, 0, 0), 114 KStorageBus_IDE, 0, 0); 106 115 /* IDE Primary Slave */ 107 mIDEList << device.arg (vboxGlobal().toString (KStorageBus_IDE)) 108 .arg (vboxGlobal().toString (KStorageBus_IDE, 0)) 109 .arg (vboxGlobal().toString (KStorageBus_IDE, 0, 1)); 110 116 mIDEList << HDSlot (vboxGlobal().toFullString (KStorageBus_IDE, 0, 1), 117 KStorageBus_IDE, 0, 1); 111 118 /* IDE Secondary Slave */ 112 mIDEList << device.arg (vboxGlobal().toString (KStorageBus_IDE)) 113 .arg (vboxGlobal().toString (KStorageBus_IDE, 1)) 114 .arg (vboxGlobal().toString (KStorageBus_IDE, 1, 1)); 119 mIDEList << HDSlot (vboxGlobal().toFullString (KStorageBus_IDE, 1, 1), 120 KStorageBus_IDE, 1, 1); 115 121 116 122 emit listChanged(); … … 119 125 void makeSATAList() 120 126 { 121 QString device ("%1 %2");122 123 127 mSATAList.clear(); 124 128 125 129 for (int i = 0; i < mSataPortsCount; ++ i) 126 mSATAList << device.arg (vboxGlobal().toString (KStorageBus_SATA))127 .arg (vboxGlobal().toString (KStorageBus_SATA, 0, i));130 mSATAList << HDSlot (vboxGlobal().toFullString (KStorageBus_SATA, 0, i), 131 KStorageBus_SATA, 0, i); 128 132 129 133 emit listChanged(); … … 131 135 132 136 int mSataPortsCount; 133 Q StringListmIDEList;134 Q StringListmSATAList;137 QValueList <HDSlot> mIDEList; 138 QValueList <HDSlot> mSATAList; 135 139 QPtrVector<HDSlotItem> mSubscribersList; 136 140 }; … … 166 170 } 167 171 172 KStorageBus currentBus() const 173 { 174 AssertReturn (currentItem() >= 0 && (size_t) currentItem() < mHDSlots.size(), 175 KStorageBus_Null); 176 return mHDSlots [currentItem()].bus; 177 } 178 179 LONG currentChannel() const 180 { 181 AssertReturn (currentItem() >= 0 && (size_t) currentItem() < mHDSlots.size(), 182 0); 183 return mHDSlots [currentItem()].channel; 184 } 185 186 LONG currentDevice() const 187 { 188 AssertReturn (currentItem() >= 0 && (size_t) currentItem() < mHDSlots.size(), 189 0); 190 return mHDSlots [currentItem()].device; 191 } 192 168 193 private slots: 169 194 170 195 void refresh() 171 196 { 172 QString current Item= currentText();173 QStringList newList (mUniq->list (this));197 QString current = currentText(); 198 mHDSlots = mUniq->list (this); 174 199 clear(); 175 insertStringList (newList); 176 if (newList.contains (currentItem)) 177 setCurrentText (currentItem); 200 201 bool setCurrent = false; 202 203 for (QValueList <HDSlot>::const_iterator it = mHDSlots.begin(); 204 it != mHDSlots.end(); ++ it) 205 { 206 insertItem ((*it).str); 207 if (!setCurrent) 208 setCurrent = (*it).str == current; 209 } 210 211 if (setCurrent) 212 setCurrentText (current); 178 213 } 179 214 … … 192 227 193 228 HDSlotUniquizer *mUniq; 229 230 QValueList <HDSlot> mHDSlots; 194 231 }; 195 232 … … 222 259 }; 223 260 224 Q StringListHDSlotUniquizer::list (HDSlotItem *aSubscriber)225 { 226 Q StringListlist = mIDEList + mSATAList;261 QValueList <HDSlot> HDSlotUniquizer::list (HDSlotItem *aSubscriber) 262 { 263 QValueList <HDSlot> list = mIDEList + mSATAList; 227 264 228 265 /* Compose exclude list */ … … 233 270 234 271 /* Filter the list */ 235 Q StringList::Iterator it = list.begin();272 QValueList <HDSlot>::Iterator it = list.begin(); 236 273 while (it != list.end()) 237 274 { 238 if (excludeList.contains ( *it))275 if (excludeList.contains ((*it).str)) 239 276 it = list.remove (it); 240 277 else … … 293 330 } 294 331 295 KStorageBus getBus() const 296 { 297 QStringList list = QStringList::split (' ', text (0)); 298 return vboxGlobal().toStorageBusType (list [0]); 299 } 300 301 LONG getChannel() const 302 { 303 QStringList list = QStringList::split (' ', text (0)); 304 return vboxGlobal().toStorageChannelType (getBus(), list [1]); 305 } 306 307 LONG getDevice() const 308 { 309 QStringList list = QStringList::split (' ', text (0)); 310 switch (getBus()) 311 { 312 case KStorageBus_IDE: 313 { 314 return vboxGlobal() 315 .toStorageDeviceType (KStorageBus_IDE, list [2]); 316 } 317 default: 318 { 319 return list [2].toLong(); 320 } 321 } 332 KStorageBus bus() const 333 { 334 return static_cast <HDSlotItem *> (mVector [0])->currentBus(); 335 } 336 337 LONG channel() const 338 { 339 return static_cast <HDSlotItem *> (mVector [0])->currentChannel(); 340 } 341 342 LONG device() const 343 { 344 return static_cast <HDSlotItem *> (mVector [0])->currentDevice(); 322 345 } 323 346 … … 349 372 void setAttachment (const CHardDiskAttachment &aHda) 350 373 { 351 QString device; 352 switch (aHda.GetBus()) 353 { 354 case KStorageBus_IDE: 355 { 356 device = QString ("%1 %2 %3") 357 .arg (vboxGlobal().toString (KStorageBus_IDE)) 358 .arg (vboxGlobal().toString (KStorageBus_IDE, 359 aHda.GetChannel())) 360 .arg (vboxGlobal().toString (KStorageBus_IDE, 361 aHda.GetChannel(), 362 aHda.GetDevice())); 363 break; 364 } 365 case KStorageBus_SATA: 366 { 367 device = QString ("%1 %2") 368 .arg (vboxGlobal().toString (KStorageBus_SATA)) 369 .arg (vboxGlobal().toString (KStorageBus_SATA, 370 0, aHda.GetDevice())); 371 break; 372 } 373 default: 374 break; 375 } 374 QString device = vboxGlobal() 375 .toFullString (aHda.GetBus(), aHda.GetChannel(), aHda.GetDevice()); 376 376 377 377 if (mVector [0]->listBox()->findItem (device, Qt::ExactMatch)) 378 378 mVector [0]->setCurrentText (device); 379 379 380 static_cast<VBoxMediaComboBox*> (mVector [1])-> 380 381 setCurrentItem (aHda.GetHardDisk().GetId()); 382 381 383 mVector [0]->setHidden (true); 382 384 mVector [1]->setHidden (true); … … 547 549 { 548 550 mMachine.AttachHardDisk (item->getId(), 549 item-> getBus(), item->getChannel(), item->getDevice());551 item->bus(), item->channel(), item->device()); 550 552 if (!mMachine.isOk()) 551 553 vboxProblem().cannotAttachHardDisk (this, mMachine, item->getId(), 552 item-> getBus(), item->getChannel(), item->getDevice());554 item->bus(), item->channel(), item->device()); 553 555 item = item->nextSibling(); 554 556 } … … 658 660 while (sataItem) 659 661 { 660 if (sataItem-> getBus() == KStorageBus_SATA)662 if (sataItem->bus() == KStorageBus_SATA) 661 663 break; 662 664 sataItem = sataItem->nextSibling(); … … 684 686 HDListItem *curIt = it; 685 687 it = it->nextSibling(); 686 if (curIt-> getBus() == KStorageBus_SATA)688 if (curIt->bus() == KStorageBus_SATA) 687 689 { 688 690 if (curIt == mLvHD->currentItem())
Note:
See TracChangeset
for help on using the changeset viewer.