Changeset 946 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Feb 16, 2007 7:52:29 AM (18 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/ui
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui
r945 r946 183 183 </includes> 184 184 <variables> 185 <variable access="public">enum SFDialogType { WrongType = 0, GlobalType = 1, MachineType = 2, ConsoleType = 3 };</variable> 185 186 <variable access="private">bool mIsListViewChanged;</variable> 187 <variable access="private">SFDialogType mDialogType;</variable> 186 188 </variables> 187 189 <slots> … … 193 195 <functions> 194 196 <function access="private">init()</function> 197 <function>setDialogType( VBoxSharedFoldersSettings::SFDialogType )</function> 198 <function access="private" returnType="bool">isEditable( const QString & )</function> 195 199 <function>getFromGlobal()</function> 196 200 <function>getFromMachine( const CMachine & )</function> 197 201 <function>getFromConsole( const CConsole & )</function> 198 <function access="private">getFrom( const CSharedFolderEnumerator & )</function>202 <function access="private">getFrom( const CSharedFolderEnumerator &, QListViewItem* )</function> 199 203 <function>putBackToGlobal()</function> 200 204 <function>putBackToMachine( CMachine & )</function> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h
r945 r946 50 50 51 51 VBoxRichListItem (FormatType aFormat, QListView *aParent, 52 const QString& aLabel1, const QString& aLabel2) : 53 QListViewItem (aParent, aLabel1, aLabel2), mFormat (aFormat) 54 { 55 mTextList << aLabel1 << aLabel2; 52 const QString& aName, const QString& aNull, 53 const QString& aKey) : 54 QListViewItem (aParent, aName, aNull, aKey), mFormat (aFormat) 55 { 56 } 57 58 VBoxRichListItem (FormatType aFormat, QListViewItem *aParent, 59 const QString& aName, const QString& aPath) : 60 QListViewItem (aParent, aName, aPath), mFormat (aFormat) 61 { 62 mTextList << aName << aPath; 56 63 } 57 64 … … 72 79 { 73 80 QString oneString = mTextList [aColumn]; 81 if (oneString.isEmpty()) 82 return; 74 83 int oldSize = listView()->fontMetrics().width (oneString); 75 84 int indentSize = listView()->fontMetrics().width ("...x"); … … 241 250 void VBoxSharedFoldersSettings::init() 242 251 { 252 mDialogType = WrongType; 243 253 new QIListViewSelectionPreserver (this, listView); 244 254 listView->setShowToolTips (false); … … 257 267 } 258 268 269 void VBoxSharedFoldersSettings::setDialogType ( 270 VBoxSharedFoldersSettings::SFDialogType aType) 271 { 272 mDialogType = aType; 273 } 274 259 275 260 276 void VBoxSharedFoldersSettings::getFromGlobal() 261 277 { 262 getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate()); 278 QString name = tr (" Global Shared Folders"); 279 QString key ("1"); 280 VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd, 281 listView, name, QString::null, key); 282 getFrom (vboxGlobal().virtualBox().GetSharedFolders().Enumerate(), root); 263 283 } 264 284 265 285 void VBoxSharedFoldersSettings::getFromMachine (const CMachine &aMachine) 266 286 { 267 getFrom (aMachine.GetSharedFolders().Enumerate()); 287 QString name = tr (" Machine Shared Folders"); 288 QString key ("2"); 289 VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd, 290 listView, name, QString::null, key); 291 getFrom (aMachine.GetSharedFolders().Enumerate(), root); 268 292 } 269 293 270 294 void VBoxSharedFoldersSettings::getFromConsole (const CConsole &aConsole) 271 295 { 272 getFrom (aConsole.GetSharedFolders().Enumerate()); 273 } 274 275 void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn) 276 { 296 QString name = tr (" Transient Shared Folders"); 297 QString key ("3"); 298 VBoxRichListItem *root = new VBoxRichListItem (VBoxRichListItem::EllipsisEnd, 299 listView, name, QString::null, key); 300 getFrom (aConsole.GetSharedFolders().Enumerate(), root); 301 } 302 303 void VBoxSharedFoldersSettings::getFrom (const CSharedFolderEnumerator &aEn, 304 QListViewItem *aRoot) 305 { 306 aRoot->setSelectable (false); 277 307 while (aEn.HasMore()) 278 308 { 279 309 CSharedFolder sf = aEn.GetNext(); 280 new VBoxRichListItem (VBoxRichListItem::EllipsisFile, listView,310 new VBoxRichListItem (VBoxRichListItem::EllipsisFile, aRoot, 281 311 sf.GetName(), sf.GetHostPath()); 282 312 } 283 listView->setCurrentItem (listView->firstChild()); 284 processCurrentChanged (listView->firstChild()); 313 listView->setOpen (aRoot, true); 314 listView->setCurrentItem (aRoot->firstChild()); 315 processCurrentChanged (aRoot->firstChild()); 285 316 } 286 317 … … 311 342 else return; 312 343 313 /* saving all created list view items */ 314 QListViewItemIterator it (listView); 315 while (it.current()) 344 /* saving all machine related list view items */ 345 Assert (mDialogType == 2); 346 QListViewItem *root = listView->findItem (QString::number (mDialogType), 2); 347 Assert (root); 348 QListViewItem *iterator = root->firstChild(); 349 while (iterator) 316 350 { 317 351 VBoxRichListItem *item = 0; 318 if (it .current()->rtti() == VBoxRichListItem::QIRichListItemId)319 item = static_cast<VBoxRichListItem*> (it .current());352 if (iterator->rtti() == VBoxRichListItem::QIRichListItemId) 353 item = static_cast<VBoxRichListItem*> (iterator); 320 354 if (item) 321 355 { … … 328 362 else 329 363 AssertMsgFailed (("Incorrect listview item type\n")); 330 ++it;364 iterator = iterator->nextSibling(); 331 365 } 332 366 } … … 349 383 /* Shared folder's name & path could not be empty */ 350 384 Assert (!name.isEmpty() && !path.isEmpty()); 351 385 /* Searching root for the new listview item */ 386 QListViewItem *root = listView->findItem (QString::number (mDialogType), 2); 387 Assert (root); 388 /* Appending a new listview item to the root */ 352 389 VBoxRichListItem *item = new VBoxRichListItem (VBoxRichListItem::EllipsisFile, 353 listView, name, path);390 root, name, path); 354 391 listView->ensureItemVisible (item); 355 392 listView->setCurrentItem (item); … … 375 412 QString tip = tr ("<nobr>Name: %1</nobr><br><nobr>Path: %2</nobr>") 376 413 .arg (item->getText (0)).arg (item->getText (1)); 377 QToolTip::add (listView->viewport(), listView->itemRect (aItem), tip); 414 if (!item->getText (0).isEmpty() && !item->getText (1).isEmpty()) 415 QToolTip::add (listView->viewport(), listView->itemRect (aItem), tip); 416 else 417 QToolTip::remove (listView->viewport()); 378 418 } 379 419 … … 382 422 if (aItem && listView->selectedItem() != aItem) 383 423 listView->setSelected (aItem, true); 384 tbRemove->setEnabled (!!aItem); 424 bool removeEnabled = aItem && aItem->parent(); 425 bool addEnabled = aItem && 426 (isEditable (aItem->text (2)) || 427 aItem->parent() && isEditable (aItem->parent()->text (2))); 428 tbRemove->setEnabled (removeEnabled); 429 tbAdd->setEnabled (addEnabled); 430 } 431 432 bool VBoxSharedFoldersSettings::isEditable (const QString &aKey) 433 { 434 /* mDialogType should be sutup already */ 435 Assert (mDialogType); 436 /* simple item has no key information */ 437 if (aKey.isEmpty()) 438 return false; 439 SFDialogType type = (SFDialogType)aKey.toInt(); 440 if (!type) 441 AssertMsgFailed (("Incorrect listview item key value\n")); 442 return type == mDialogType; 385 443 } 386 444 -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h
r925 r946 490 490 QVBoxLayout* pageFoldersLayout = new QVBoxLayout (pageFolders, 0, 10, "pageFoldersLayout"); 491 491 mSharedFolders = new VBoxSharedFoldersSettings (pageFolders, "sharedFolders"); 492 mSharedFolders->setDialogType (VBoxSharedFoldersSettings::MachineType); 492 493 pageFoldersLayout->addWidget (mSharedFolders); 493 494
Note:
See TracChangeset
for help on using the changeset viewer.