- Timestamp:
- Aug 7, 2007 1:23:00 PM (17 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/ui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui
r3927 r4062 243 243 <function access="private">init()</function> 244 244 <function>setDialogType( int )</function> 245 <function returnType="int">dialogType() {return mDialogType;}</function> 245 246 <function access="private">removeSharedFolder( const QString &, const QString &, VBoxSharedFoldersSettings::SFDialogType )</function> 246 247 <function access="private">createSharedFolder( const QString &, const QString &, VBoxSharedFoldersSettings::SFDialogType )</function> -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h
r3927 r4062 34 34 35 35 36 typedef QPair<QString, VBoxSharedFoldersSettings::SFDialogType> SFolderName; 37 typedef QValueList<SFolderName> SFoldersNameList; 38 39 36 40 class VBoxRichListItem : public QListViewItem 37 41 { … … 57 61 58 62 VBoxRichListItem (FormatType aFormat, QListViewItem *aParent, 59 const QString& aName, const QString& aPath) : 60 QListViewItem (aParent, aName, aPath), mFormat (aFormat) 61 { 62 mTextList << aName << aPath; 63 const QString& aName, const QString& aPath, 64 const QString& aEdited) : 65 QListViewItem (aParent, aName, aPath, aEdited), mFormat (aFormat) 66 { 67 mTextList << aName << aPath << aEdited; 63 68 } 64 69 65 70 int rtti() const { return QIRichListItemId; } 71 72 VBoxRichListItem* nextSibling() const 73 { 74 QListViewItem *item = QListViewItem::nextSibling(); 75 return item && item->rtti() == QIRichListItemId ? 76 static_cast<VBoxRichListItem*> (item) : 0; 77 } 66 78 67 79 QString getText (int aIndex) … … 156 168 enum DialogType { AddDialogType, EditDialogType }; 157 169 158 VBoxAddSFDialog (QWidget *aParent, VBoxAddSFDialog::DialogType aType, 159 bool aEnableSelector /* for "permanent" checkbox */) : 160 QDialog (aParent, "VBoxAddSFDialog", true /* modal */), 161 mLePath (0), mLeName (0), mCbPermanent (0) 170 VBoxAddSFDialog (VBoxSharedFoldersSettings *aParent, 171 VBoxAddSFDialog::DialogType aType, 172 bool aEnableSelector /* for "permanent" checkbox */, 173 const SFoldersNameList &aUsedNames) 174 : QDialog (aParent, "VBoxAddSFDialog", true /* modal */) 175 , mLePath (0), mLeName (0), mCbPermanent (0) 176 , mUsedNames (aUsedNames) 162 177 { 163 178 switch (aType) … … 205 220 mCbPermanent->setChecked (true); 206 221 inputLayout->addMultiCellWidget (mCbPermanent, 2, 2, 0, 2); 222 connect (mCbPermanent, SIGNAL (toggled (bool)), 223 this, SLOT (validate())); 207 224 } 208 225 209 226 /* Setup Button layout */ 210 227 QHBoxLayout *buttonLayout = new QHBoxLayout (mainLayout, 10, "buttonLayout"); 211 mBtOk = new QPushButton (tr (" OK"), this, "btOk");228 mBtOk = new QPushButton (tr ("&OK"), this, "btOk"); 212 229 QSpacerItem *spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); 213 230 QPushButton *btCancel = new QPushButton (tr ("Cancel"), this, "btCancel"); … … 247 264 void validate() 248 265 { 249 mBtOk->setEnabled (!mLePath->text().isEmpty() && !mLeName->text().isEmpty()); 266 VBoxSharedFoldersSettings::SFDialogType dlgType = 267 (VBoxSharedFoldersSettings::SFDialogType) 268 static_cast<VBoxSharedFoldersSettings*> (parent())->dialogType(); 269 VBoxSharedFoldersSettings::SFDialogType resultType = 270 mCbPermanent && !mCbPermanent->isChecked() ? 271 VBoxSharedFoldersSettings::ConsoleType : 272 dlgType & VBoxSharedFoldersSettings::MachineType ? 273 VBoxSharedFoldersSettings::MachineType : 274 VBoxSharedFoldersSettings::GlobalType; 275 SFolderName pair = qMakePair (mLeName->text(), resultType); 276 277 mBtOk->setEnabled (!mLePath->text().isEmpty() && 278 !mLeName->text().isEmpty() && 279 !mUsedNames.contains (pair)); 250 280 } 251 281 … … 293 323 QLineEdit *mLeName; 294 324 QCheckBox *mCbPermanent; 325 SFoldersNameList mUsedNames; 295 326 }; 296 327 … … 299 330 { 300 331 mDialogType = WrongType; 332 listView->setSorting (-1); 301 333 new QIListViewSelectionPreserver (this, listView); 302 334 listView->setShowToolTips (false); … … 442 474 CSharedFolder sf = aEn.GetNext(); 443 475 new VBoxRichListItem (VBoxRichListItem::EllipsisFile, aRoot, 444 sf.GetName(), sf.GetHostPath() );476 sf.GetName(), sf.GetHostPath(), "not edited"); 445 477 } 446 478 listView->setOpen (aRoot, true); … … 501 533 SFDialogType type = (SFDialogType)aRoot->text (2).toInt(); 502 534 503 /* deleting all existing folders if the list */535 /* deleting all changed folders of the list */ 504 536 while (aEn.HasMore()) 505 537 { 506 538 CSharedFolder sf = aEn.GetNext(); 539 540 /* Search for this root's items */ 541 QListViewItem *firstItem = aRoot->firstChild(); 542 VBoxRichListItem *item = firstItem && 543 firstItem->rtti() == VBoxRichListItem::QIRichListItemId ? 544 static_cast<VBoxRichListItem*> (firstItem) : 0; 545 while (item) 546 { 547 if (item->getText (0) == sf.GetName() && 548 item->getText (1) == sf.GetHostPath() && 549 item->getText (2) == "not edited") 550 break; 551 item = item->nextSibling(); 552 } 553 if (item) 554 continue; 507 555 removeSharedFolder (sf.GetName(), sf.GetHostPath(), type); 508 556 } … … 515 563 if (iterator->rtti() == VBoxRichListItem::QIRichListItemId) 516 564 item = static_cast<VBoxRichListItem*> (iterator); 517 if (item && !item->getText (0).isNull() && !item->getText (1).isNull()) 565 if (item && !item->getText (0).isNull() && !item->getText (1).isNull() 566 && item->getText (2) == "edited") 518 567 createSharedFolder (item->getText (0), item->getText (1), type); 519 else520 AssertMsgFailed (("Incorrect listview item type\n"));521 568 iterator = iterator->nextSibling(); 522 569 } … … 536 583 void VBoxSharedFoldersSettings::tbAddPressed() 537 584 { 585 /* Make the used names list: */ 586 SFoldersNameList usedList; 587 QListViewItemIterator it (listView); 588 while (*it) 589 { 590 if ((*it)->parent() && (*it)->rtti() == VBoxRichListItem::QIRichListItemId) 591 { 592 VBoxRichListItem *item = static_cast<VBoxRichListItem*> (*it); 593 SFDialogType type = (SFDialogType)item->parent()->text (2).toInt(); 594 usedList << qMakePair (item->getText (0), type); 595 } 596 ++ it; 597 } 598 538 599 /* Invoke Add-Box Dialog */ 539 600 VBoxAddSFDialog dlg (this, VBoxAddSFDialog::AddDialogType, 540 mDialogType & ConsoleType );601 mDialogType & ConsoleType, usedList); 541 602 if (dlg.exec() != QDialog::Accepted) 542 603 return; … … 551 612 /* Appending a new listview item to the root */ 552 613 VBoxRichListItem *item = new VBoxRichListItem ( 553 VBoxRichListItem::EllipsisFile, root, name, path );614 VBoxRichListItem::EllipsisFile, root, name, path, "edited"); 554 615 /* Make the created item selected */ 555 616 listView->ensureItemVisible (item); … … 563 624 void VBoxSharedFoldersSettings::tbEditPressed() 564 625 { 626 /* Make the used names list: */ 627 SFoldersNameList usedList; 628 QListViewItemIterator it (listView); 629 while (*it) 630 { 631 if ((*it)->parent() && !(*it)->isSelected() && 632 (*it)->rtti() == VBoxRichListItem::QIRichListItemId) 633 { 634 VBoxRichListItem *item = static_cast<VBoxRichListItem*> (*it); 635 SFDialogType type = (SFDialogType)item->parent()->text (2).toInt(); 636 usedList << qMakePair (item->getText (0), type); 637 } 638 ++ it; 639 } 640 565 641 /* Check selected item */ 566 642 QListViewItem *selectedItem = listView->selectedItem(); … … 572 648 /* Invoke Edit-Box Dialog */ 573 649 VBoxAddSFDialog dlg (this, VBoxAddSFDialog::EditDialogType, 574 mDialogType & ConsoleType );650 mDialogType & ConsoleType, usedList); 575 651 dlg.setPath (item->getText (1)); 576 652 dlg.setName (item->getText (0)); … … 588 664 Assert (root); 589 665 /* Updating an edited listview item */ 666 item->updateText (2, "edited"); 590 667 item->updateText (1, path); 591 668 item->updateText (0, name); … … 653 730 bool VBoxSharedFoldersSettings::isEditable (const QString &aKey) 654 731 { 655 /* mDialogType should be s utup already */732 /* mDialogType should be setup already */ 656 733 Assert (mDialogType); 657 /* simple item has no key information */ 658 if (aKey.isEmpty()) 659 return false; 734 660 735 SFDialogType type = (SFDialogType)aKey.toInt(); 661 if (!type) 662 AssertMsgFailed (("Incorrect listview item key value\n")); 736 if (!type) return false; 663 737 return mDialogType & type; 664 738 }
Note:
See TracChangeset
for help on using the changeset viewer.