Changeset 10742 in vbox for trunk/src/VBox/Frontends/VirtualBox4
- Timestamp:
- Jul 18, 2008 10:12:28 AM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 3 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/Makefile.kmk
r10728 r10742 484 484 include/VBoxVMSettingsUSBFilterDetails.h \ 485 485 include/VBoxVMSettingsSF.h \ 486 include/VBoxVMSettingsSFDetails.h \ 486 487 include/VBoxVMSettingsVRDP.h \ 487 488 include/VBoxGLSettingsGeneral.h \ … … 558 559 src/VBoxVMSettingsUSBFilterDetails.cpp \ 559 560 src/VBoxVMSettingsSF.cpp \ 561 src/VBoxVMSettingsSFDetails.cpp \ 560 562 src/VBoxVMSettingsVRDP.cpp \ 561 563 src/VBoxGLSettingsGeneral.cpp \ -
trunk/src/VBox/Frontends/VirtualBox4/VBoxUI.pro
r10728 r10742 47 47 ui/VBoxVMSettingsParallel.ui \ 48 48 ui/VBoxVMSettingsSF.ui \ 49 ui/VBoxVMSettingsSFDetails.ui \ 49 50 ui/VBoxVMSettingsSerial.ui \ 50 51 ui/VBoxVMSettingsUSB.ui \ -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxVMSettingsSF.h
r10167 r10742 27 27 #include "VBoxVMSettingsSF.gen.h" 28 28 29 #include <QDialog>30 31 29 class SFTreeViewItem; 32 class QIDialogButtonBox;33 34 class QLineEdit;35 class QPushButton;36 class QCheckBox;37 30 38 31 enum SFDialogType … … 118 111 }; 119 112 120 class VBoxAddSFDialog : public QIWithRetranslateUI<QDialog>121 {122 Q_OBJECT;123 124 public:125 126 enum DialogType127 {128 AddDialogType,129 EditDialogType130 };131 132 VBoxAddSFDialog (VBoxVMSettingsSF *aParent,133 VBoxAddSFDialog::DialogType aType,134 bool aEnableSelector /* for "permanent" checkbox */,135 const SFoldersNameList &aUsedNames);136 ~VBoxAddSFDialog() {}137 138 QString getPath();139 QString getName();140 bool getPermanent();141 bool getWritable();142 143 void setPath (const QString &aPath);144 void setName (const QString &aName);145 void setPermanent (bool aPermanent);146 void setWritable (bool aWritable);147 148 protected:149 150 void retranslateUi();151 152 private slots:153 154 void validate();155 void showFileDialog();156 157 private:158 159 void showEvent (QShowEvent *aEvent);160 161 VBoxAddSFDialog::DialogType mType;162 QIDialogButtonBox *mButtonBox;163 QLabel *mLbPath;164 QLineEdit *mLePath;165 QToolButton *mTbPath;166 QLabel *mLbName;167 QLineEdit *mLeName;168 QCheckBox *mCbPermanent;169 QCheckBox *mCbReadonly;170 SFoldersNameList mUsedNames;171 };172 173 113 #endif // __VBoxVMSettingsSF_h__ 174 114 -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxVMSettingsSF.cpp
r10232 r10742 22 22 23 23 #include "VBoxVMSettingsSF.h" 24 #include "VBoxVMSettingsSFDetails.h" 24 25 #include "VBoxGlobal.h" 25 26 #include "VBoxProblemReporter.h" 26 27 #include "VBoxUtils.h" 27 #include "QIDialogButtonBox.h"28 28 #include "VBoxToolBar.h" 29 29 30 #include <QLineEdit> 31 #include <QToolButton> 32 #include <QPushButton> 33 #include <QDir> 30 /* Qt includes */ 34 31 #include <QHeaderView> 35 32 #include <QTimer> 36 #include <QLabel>37 33 38 34 class SFTreeViewItem : public QTreeWidgetItem … … 371 367 { 372 368 /* Invoke Add-Box Dialog */ 373 VBoxAddSFDialog dlg (this, VBoxAddSFDialog::AddDialogType, 374 mDialogType & ConsoleType, usedList (true)); 375 if (dlg.exec() != QDialog::Accepted) 376 return; 377 378 QString name = dlg.getName(); 379 QString path = dlg.getPath(); 380 bool isPermanent = dlg.getPermanent(); 381 /* Shared folder's name & path could not be empty */ 382 Assert (!name.isEmpty() && !path.isEmpty()); 383 /* Searching root for the new listview item */ 384 SFTreeViewItem *root = searchRoot (isPermanent); 385 Assert (root); 386 /* Appending a new listview item to the root */ 387 QStringList fields; 388 fields << name /* name */ << path /* path */ 389 << (dlg.getWritable() ? mTrFull : mTrReadOnly /* writable? */) 390 << "edited" /* mark item as edited */; 391 SFTreeViewItem *item = new SFTreeViewItem (root, fields, 392 SFTreeViewItem::EllipsisFile); 393 mTreeView->sortItems (0, Qt::AscendingOrder); 394 mTreeView->scrollToItem (item); 395 mTreeView->setCurrentItem (item); 396 processCurrentChanged (item); 397 mTreeView->setFocus(); 398 adjustList(); 399 400 mIsListViewChanged = true; 369 VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::AddType, 370 mDialogType & ConsoleType, 371 usedList (true), 372 this); 373 if (dlg.exec() == QDialog::Accepted) 374 { 375 QString name = dlg.name(); 376 QString path = dlg.path(); 377 bool isPermanent = dlg.isPermanent(); 378 /* Shared folder's name & path could not be empty */ 379 Assert (!name.isEmpty() && !path.isEmpty()); 380 /* Searching root for the new listview item */ 381 SFTreeViewItem *root = searchRoot (isPermanent); 382 Assert (root); 383 /* Appending a new listview item to the root */ 384 QStringList fields; 385 fields << name /* name */ << path /* path */ 386 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */) 387 << "edited" /* mark item as edited */; 388 SFTreeViewItem *item = new SFTreeViewItem (root, fields, 389 SFTreeViewItem::EllipsisFile); 390 mTreeView->sortItems (0, Qt::AscendingOrder); 391 mTreeView->scrollToItem (item); 392 mTreeView->setCurrentItem (item); 393 processCurrentChanged (item); 394 mTreeView->setFocus(); 395 adjustList(); 396 397 mIsListViewChanged = true; 398 } 401 399 } 402 400 … … 413 411 414 412 /* Invoke Edit-Box Dialog */ 415 VBoxAddSFDialog dlg (this, VBoxAddSFDialog::EditDialogType, 416 mDialogType & ConsoleType, usedList (false)); 413 VBoxVMSettingsSFDetails dlg (VBoxVMSettingsSFDetails::EditType, 414 mDialogType & ConsoleType, 415 usedList (false), 416 this); 417 417 dlg.setPath (item->getText (1)); 418 418 dlg.setName (item->getText (0)); 419 419 dlg.setPermanent ((SFDialogType)item->parent()->text (1).toInt() 420 420 != ConsoleType); 421 dlg.setWrit able (item->getText (2) == mTrFull);422 if (dlg.exec() != QDialog::Accepted)423 return;424 425 QString name = dlg.getName();426 QString path = dlg.getPath();427 bool isPermanent = dlg.getPermanent();428 /* Shared folder's name & path could not be empty */429 Assert (!name.isEmpty() && !path.isEmpty());430 /* Searching new root for the selected listview item */431 SFTreeViewItem *root = searchRoot (isPermanent);432 Assert (root);433 /* Updating an edited listview item */434 QStringList fields;435 fields << name /* name */ << path /* path */436 << (dlg.getWritable() ? mTrFull : mTrReadOnly /* writable? */)437 << "edited" /* mark item as edited */;438 item->updateText (fields);439 mTreeView->sortItems (0, Qt::AscendingOrder);440 if (item->parent() != root)441 {442 /* Move the selected item into new location */443 item->parent()->takeChild (item->parent()->indexOfChild (item));444 root->insertChild (root->childCount(),item);445 mTreeView->scrollToItem (item);446 mTreeView->setCurrentItem(item);447 processCurrentChanged (item);448 mTreeView->setFocus();449 }450 adjustList(); 451 452 mIsListViewChanged = true;421 dlg.setWriteable (item->getText (2) == mTrFull); 422 if (dlg.exec() == QDialog::Accepted) 423 { 424 QString name = dlg.name(); 425 QString path = dlg.path(); 426 bool isPermanent = dlg.isPermanent(); 427 /* Shared folder's name & path could not be empty */ 428 Assert (!name.isEmpty() && !path.isEmpty()); 429 /* Searching new root for the selected listview item */ 430 SFTreeViewItem *root = searchRoot (isPermanent); 431 Assert (root); 432 /* Updating an edited listview item */ 433 QStringList fields; 434 fields << name /* name */ << path /* path */ 435 << (dlg.isWriteable() ? mTrFull : mTrReadOnly /* writable? */) 436 << "edited" /* mark item as edited */; 437 item->updateText (fields); 438 mTreeView->sortItems (0, Qt::AscendingOrder); 439 if (item->parent() != root) 440 { 441 /* Move the selected item into new location */ 442 item->parent()->takeChild (item->parent()->indexOfChild (item)); 443 root->insertChild (root->childCount(), item); 444 mTreeView->scrollToItem (item); 445 mTreeView->setCurrentItem (item); 446 processCurrentChanged (item); 447 mTreeView->setFocus(); 448 } 449 adjustList(); 450 451 mIsListViewChanged = true; 452 } 453 453 } 454 454 … … 727 727 } 728 728 729 730 VBoxAddSFDialog::VBoxAddSFDialog (VBoxVMSettingsSF *aParent,731 VBoxAddSFDialog::DialogType aType,732 bool aEnableSelector,733 const SFoldersNameList &aUsedNames)734 : QIWithRetranslateUI<QDialog> (aParent)735 , mType(aType), mLePath (0), mLeName (0), mCbPermanent (0), mCbReadonly (0)736 , mUsedNames (aUsedNames)737 {738 setModal (true);739 740 QVBoxLayout *mainLayout = new QVBoxLayout (this);741 742 /* Setup Input layout */743 QGridLayout *inputLayout = new QGridLayout ();744 mainLayout->addLayout (inputLayout);745 mLbPath = new QLabel (this);746 mLePath = new QLineEdit (this);747 mTbPath = new QToolButton (this);748 mTbPath->setAutoRaise (true);749 mLbName = new QLabel (this);750 mLeName = new QLineEdit (this);751 mTbPath->setIcon (VBoxGlobal::iconSet (":/select_file_16px.png",752 ":/select_file_dis_16px.png"));753 mTbPath->setFocusPolicy (Qt::TabFocus);754 connect (mLePath, SIGNAL (textChanged (const QString &)),755 this, SLOT (validate()));756 connect (mLeName, SIGNAL (textChanged (const QString &)),757 this, SLOT (validate()));758 connect (mTbPath, SIGNAL (clicked()), this, SLOT (showFileDialog()));759 mCbReadonly = new QCheckBox (this);760 mCbReadonly->setChecked (false);761 762 inputLayout->addWidget (mLbPath, 0, 0);763 inputLayout->addWidget (mLePath, 0, 1);764 inputLayout->addWidget (mTbPath, 0, 2);765 inputLayout->addWidget (mLbName, 1, 0);766 inputLayout->addWidget (mLeName, 1, 1, 1, 2);767 inputLayout->addWidget (mCbReadonly, 2, 0, 1, 3);768 769 if (aEnableSelector)770 {771 mCbPermanent = new QCheckBox (this);772 mCbPermanent->setChecked (true);773 inputLayout->addWidget (mCbPermanent, 3, 0, 1, 3);774 connect (mCbPermanent, SIGNAL (toggled (bool)),775 this, SLOT (validate()));776 }777 778 /* Setup Button layout */779 mButtonBox = new QIDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel);780 mButtonBox->setCenterButtons (true);781 connect (mButtonBox, SIGNAL (accepted()), this, SLOT (accept()));782 connect (mButtonBox, SIGNAL (rejected()), this, SLOT (reject()));783 mainLayout->addWidget (mButtonBox);784 785 /* Validate fields */786 validate();787 788 retranslateUi();789 }790 791 QString VBoxAddSFDialog::getPath()792 {793 return mLePath->text();794 }795 QString VBoxAddSFDialog::getName()796 {797 return mLeName->text();798 }799 bool VBoxAddSFDialog::getPermanent()800 {801 return mCbPermanent ? mCbPermanent->isChecked() : true;802 }803 bool VBoxAddSFDialog::getWritable()804 {805 return !mCbReadonly->isChecked();806 }807 808 void VBoxAddSFDialog::setPath (const QString &aPath)809 {810 mLePath->setText (aPath);811 }812 void VBoxAddSFDialog::setName (const QString &aName)813 {814 mLeName->setText (aName);815 }816 void VBoxAddSFDialog::setPermanent (bool aPermanent)817 {818 if (mCbPermanent)819 {820 mCbPermanent->setChecked (aPermanent);821 mCbPermanent->setEnabled (!aPermanent);822 }823 }824 void VBoxAddSFDialog::setWritable (bool aWritable)825 {826 mCbReadonly->setChecked (!aWritable);827 }828 829 void VBoxAddSFDialog::retranslateUi()830 {831 switch (mType)832 {833 case AddDialogType:834 setWindowTitle (tr ("Add Share"));835 break;836 case EditDialogType:837 setWindowTitle (tr ("Edit Share"));838 break;839 default:840 AssertMsgFailed (("Incorrect SF Dialog type\n"));841 }842 843 mLbPath->setText (tr ("Folder Path"));844 mLePath->setWhatsThis (tr ("Displays the path to an existing folder "845 "on the host PC."));846 847 mLbName->setText (tr ("Folder Name"));848 mLeName->setWhatsThis (tr ("Displays the name of the shared folder "849 "(as it will be seen by the guest OS)."));850 851 mTbPath->setWhatsThis (tr ("Opens the dialog to select a folder."));852 853 mCbReadonly->setText (tr ("&Read-only"));854 mCbReadonly->setWhatsThis (tr ("When checked, the guest OS will not "855 "be able to write to the specified "856 "shared folder."));857 858 if (mCbPermanent)859 mCbPermanent->setText (tr ("&Make Permanent"));860 }861 862 void VBoxAddSFDialog::validate()863 {864 int dlgType = static_cast<VBoxVMSettingsSF*>865 (parent())->dialogType();866 SFDialogType resultType =867 mCbPermanent && !mCbPermanent->isChecked() ? ConsoleType :868 dlgType & MachineType ? MachineType : GlobalType;869 SFolderName pair = qMakePair (mLeName->text(), resultType);870 871 mButtonBox->button (QDialogButtonBox::Ok)->setEnabled (!mLePath->text().isEmpty() &&872 !mLeName->text().trimmed().isEmpty() &&873 !mLeName->text().contains(" ") &&874 !mUsedNames.contains (pair));875 }876 877 void VBoxAddSFDialog::showFileDialog()878 {879 QString folderName = vboxGlobal()880 .getExistingDirectory (mLePath->text().isEmpty() ? QDir::homePath() : mLePath->text(),881 this,882 tr ("Select a folder to share"));883 if (folderName.isNull())884 return;885 886 QDir folder (folderName);887 mLePath->setText (QDir::toNativeSeparators (folder.absolutePath()));888 if (!folder.isRoot())889 /* processing non-root folder */890 mLeName->setText (folder.dirName());891 else892 {893 /* processing root folder */894 #if defined (Q_OS_WIN) || defined (Q_OS_OS2)895 mLeName->setText (folderName.toUpper()[0] + "_DRIVE");896 #elif defined (Q_OS_UNIX)897 mLeName->setText ("ROOT");898 #endif899 }900 }901 902 void VBoxAddSFDialog::showEvent (QShowEvent *aEvent)903 {904 setFixedHeight (height());905 QDialog::showEvent (aEvent);906 }907
Note:
See TracChangeset
for help on using the changeset viewer.