Changeset 17784 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Mar 13, 2009 1:06:28 AM (16 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r17730 r17784 272 272 include/VBoxVMSettingsAudio.h \ 273 273 include/VBoxVMSettingsNetwork.h \ 274 include/VBoxVMSettingsNetworkDetails.h \ 274 275 include/VBoxVMSettingsSerial.h \ 275 276 include/VBoxVMSettingsParallel.h \ … … 352 353 src/VBoxVMSettingsAudio.cpp \ 353 354 src/VBoxVMSettingsNetwork.cpp \ 355 src/VBoxVMSettingsNetworkDetails.cpp \ 354 356 src/VBoxVMSettingsSerial.cpp \ 355 357 src/VBoxVMSettingsParallel.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/VBoxUI.pro
r17450 r17784 45 45 ui/VBoxVMSettingsHD.ui \ 46 46 ui/VBoxVMSettingsNetwork.ui \ 47 ui/VBoxVMSettingsNetworkDetails.ui \ 47 48 ui/VBoxVMSettingsParallel.ui \ 48 49 ui/VBoxVMSettingsSF.ui \ -
trunk/src/VBox/Frontends/VirtualBox/VirtualBox.qrc
r17726 r17784 334 334 <file alias="export_16px.png">images/export_16px.png</file> 335 335 <file alias="vmw_ovf_import.png">images/vmw_ovf_import.png</file> 336 <file alias="connect_16px.png">images/connect_16px.png</file> 337 <file alias="disconnect_16px.png">images/disconnect_16px.png</file> 336 338 </qresource> 337 339 </RCC> -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h
r17730 r17784 263 263 #if defined Q_WS_WIN 264 264 int confirmDeletingHostInterface (const QString &aName, QWidget *aParent = 0); 265 void cannotCreateHostInterface (const CHost &aHost, 266 QWidget *aParent = 0); 267 void cannotCreateHostInterface (const CProgress &aProgress, const QString &aName, 268 QWidget *aParent = 0); 265 void cannotCreateHostInterface (const CHost &aHost, QWidget *aParent = 0); 266 void cannotCreateHostInterface (const CProgress &aProgress, QWidget *aParent = 0); 269 267 void cannotRemoveHostInterface (const CHost &aHost, 270 268 const CHostNetworkInterface &aIface, -
trunk/src/VBox/Frontends/VirtualBox/include/VBoxVMSettingsNetwork.h
r17217 r17784 6 6 7 7 /* 8 * Copyright (C) 200 6-2008 Sun Microsystems, Inc.8 * Copyright (C) 2008 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 24 24 #define __VBoxVMSettingsNetwork_h__ 25 25 26 /* VBox Includes */ 27 #include "COMDefs.h" 26 28 #include "VBoxSettingsPage.h" 27 29 #include "VBoxVMSettingsNetwork.gen.h" 28 #include "COMDefs.h"29 30 30 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 31 class QTreeWidget; 32 class QTreeWidgetItem; 33 #endif 31 /* VBox Forwardes */ 32 class VBoxVMSettingsNetworkPage; 33 class VBoxVMSettingsNetworkDetails; 34 34 35 /* 36 * QWidget sub-class which represents one tab-page per each network adapter. 37 * It has generated UI part. 38 */ 39 class VBoxVMSettingsNetwork : public QIWithRetranslateUI<QWidget>, 35 class VBoxVMSettingsNetwork : public QIWithRetranslateUI <QWidget>, 40 36 public Ui::VBoxVMSettingsNetwork 41 37 { … … 44 40 public: 45 41 46 VBoxVMSettingsNetwork ();42 VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent); 47 43 48 44 void getFromAdapter (const CNetworkAdapter &aAdapter); 49 45 void putBackToAdapter(); 50 46 51 QString pageTitle() const;52 53 47 void setValidator (QIWidgetValidator *aValidator); 48 bool revalidate (QString &aWarning, QString &aTitle); 54 49 55 50 QWidget* setOrderAfter (QWidget *aAfter); 56 51 57 void setNetworksList (const QStringList &aList); 58 59 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 60 void setInterfaceName (const QString &); 61 QString interfaceName() const; 62 #endif 52 QString pageTitle() const; 53 QString currentName (KNetworkAttachmentType aType = KNetworkAttachmentType_Null) const; 63 54 64 55 protected: … … 68 59 private slots: 69 60 70 void adapterToggled (bool aOn); 71 void naTypeChanged (const QString &aString); 72 void genMACClicked(); 61 void updateCableConnectedState(); 62 void detailsClicked(); 73 63 74 64 private: 75 65 76 void prepareComboboxes(); 66 void populateComboboxes(); 67 KNetworkAttachmentType attachmentType() const; 77 68 78 void setTapEnabled (bool aEnabled); 79 void setTapVisible (bool aVisible); 80 69 VBoxVMSettingsNetworkPage *mParent; 70 VBoxVMSettingsNetworkDetails *mDetails; 81 71 CNetworkAdapter mAdapter; 82 72 QIWidgetValidator *mValidator; 83 84 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)85 QString mInterfaceName;86 #endif87 73 }; 88 74 89 90 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)91 /*92 * QGroupBox sub-class which represents network interface list.93 */94 class VBoxNIList : public QIWithRetranslateUI<QWidget>95 {96 Q_OBJECT;97 98 public:99 100 VBoxNIList (QWidget *aParent);101 102 bool isWrongInterface() const;103 void setCurrentInterface (const QString &aName);104 #if defined (Q_WS_WIN) && defined(VBOX_WITH_NETFLT)105 void updateInterfacesList(KNetworkAttachmentType enmAttachmentType);106 #endif107 signals:108 109 void listChanged();110 void currentInterfaceChanged (const QString &);111 112 private slots:113 114 void onCurrentItemChanged (QTreeWidgetItem *aCurrent, QTreeWidgetItem *aPrev = 0);115 void addHostInterface();116 void delHostInterface();117 118 protected:119 120 void retranslateUi();121 122 private:123 #if defined (Q_WS_WIN) && defined(VBOX_WITH_NETFLT)124 void populateInterfacesList(KNetworkAttachmentType enmAttachmentType);125 #else126 void populateInterfacesList();127 #endif128 QILabelSeparator *mLbTitle;129 QTreeWidget *mList;130 131 # if defined (Q_WS_WIN)132 QAction *mAddAction;133 QAction *mDelAction;134 # ifdef VBOX_WITH_NETFLT135 KNetworkAttachmentType mEnmAttachmentType;136 # endif137 # endif138 };139 #endif /* Q_WS_WIN || VBOX_WITH_NETFLT */140 141 142 /*143 * QWidget sub-class which represents network settings page itself.144 */145 75 class VBoxVMSettingsNetworkPage : public VBoxSettingsPage 146 76 { … … 151 81 VBoxVMSettingsNetworkPage(); 152 82 83 QStringList natList() const; 84 QStringList netList() const; 85 QStringList intList (KHostNetworkInterfaceType aType) const; 86 153 87 protected: 154 88 … … 156 90 void putBackTo(); 157 91 158 void setValidator (QIWidgetValidator *aVal );92 void setValidator (QIWidgetValidator *aValidator); 159 93 bool revalidate (QString &aWarning, QString &aTitle); 160 94 161 95 void retranslateUi(); 162 96 163 private slots:164 165 void updateNetworksList();166 #if defined (VBOX_WITH_NETFLT)167 void updateInterfaceList();168 #endif169 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)170 void onCurrentPageChanged (int);171 void onCurrentInterfaceChanged (const QString &);172 #endif173 174 97 private: 175 98 176 void populateNetworksList(); 177 178 /* Widgets */ 99 QIWidgetValidator *mValidator; 179 100 QTabWidget *mTwAdapters; 180 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)181 VBoxNIList *mNIList;182 #endif183 184 /* Widget Validator*/185 QIWidgetValidator *mValidator;186 187 /* Lists */188 QStringList mListNetworks;189 190 /* Flags */191 bool mLockNetworkListUpdate;192 101 }; 193 102 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp
r17737 r17784 1896 1896 * an additional symbolic network/interface name field, use 1897 1897 * this name instead */ 1898 if (type == KNetworkAttachmentType_Bridged) 1899 attType = attType.arg (tr ("host interface, %1", 1898 if (type == KNetworkAttachmentType_NAT) 1899 attType = attType.arg (tr ("NAT, '%1'", 1900 "details report (network)").arg (adapter.GetNATNetwork())); 1901 else if (type == KNetworkAttachmentType_Bridged) 1902 attType = attType.arg (tr ("Bridged network, %1", 1900 1903 "details report (network)").arg (adapter.GetHostInterface())); 1901 1904 else if (type == KNetworkAttachmentType_Internal) 1902 attType = attType.arg (tr (" internal network, '%1'",1905 attType = attType.arg (tr ("Internal network, '%1'", 1903 1906 "details report (network)").arg (adapter.GetInternalNetwork())); 1907 else if (type == KNetworkAttachmentType_HostOnly) 1908 attType = attType.arg (tr ("Host-only network, '%1'", 1909 "details report (network)").arg (adapter.GetHostInterface())); 1904 1910 else 1905 1911 attType = attType.arg (vboxGlobal().toString (type)); … … 2916 2922 tr ("NAT", "NetworkAttachmentType"); 2917 2923 mNetworkAttachmentTypes [KNetworkAttachmentType_Bridged] = 2918 tr ("Bridged Interface", "NetworkAttachmentType");2924 tr ("Bridged Network", "NetworkAttachmentType"); 2919 2925 mNetworkAttachmentTypes [KNetworkAttachmentType_Internal] = 2920 2926 tr ("Internal Network", "NetworkAttachmentType"); -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp
r17731 r17784 1337 1337 { 1338 1338 message (parent ? parent : mainWindowShown(), Error, 1339 tr ("Failed to create the host network interface."),1339 tr ("Failed to create the host-only network interface."), 1340 1340 formatErrorInfo (host)); 1341 1341 } 1342 1342 1343 1343 void VBoxProblemReporter::cannotCreateHostInterface ( 1344 const CProgress &progress, const QString &name,QWidget *parent)1344 const CProgress &progress, QWidget *parent) 1345 1345 { 1346 1346 message (parent ? parent : mainWindowShown(), Error, 1347 tr ("Failed to create the host network interface <b>%1</b>.") 1348 .arg (name), 1347 tr ("Failed to create the host-only network interface."), 1349 1348 formatErrorInfo (progress.GetErrorInfo())); 1350 1349 } -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMSettingsNetwork.cpp
r17737 r17784 6 6 7 7 /* 8 * Copyright (C) 200 6-2008 Sun Microsystems, Inc.8 * Copyright (C) 2008 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 21 21 */ 22 22 23 /* Common Includes */ 24 #include "VBoxVMSettingsNetwork.h" 23 /* VBox Includes */ 25 24 #include "QIWidgetValidator.h" 26 25 #include "VBoxGlobal.h" 27 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 28 #include "VBoxToolBar.h" 29 #include "VBoxSettingsUtils.h" 30 #include "VBoxProblemReporter.h" 31 #endif 32 33 /* Qt Includes */ 34 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT) 35 #include <QFileDialog> 36 #endif 37 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 38 #include <QTreeWidget> 39 #endif 40 41 /* Common Stuff */ 42 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 43 static QTreeWidgetItem* findItem (QTreeWidget *aList, 44 const QString &aMatch) 45 { 46 QList<QTreeWidgetItem*> list = 47 aList->findItems (aMatch, Qt::MatchExactly, 0); 48 return list.count() ? list [0] : 0; 49 } 50 #endif 51 26 #include "VBoxVMSettingsNetwork.h" 27 #include "VBoxVMSettingsNetworkDetails.h" 52 28 53 29 /* VBoxVMSettingsNetwork Stuff */ 54 VBoxVMSettingsNetwork::VBoxVMSettingsNetwork() 55 : QIWithRetranslateUI<QWidget> (0) 30 VBoxVMSettingsNetwork::VBoxVMSettingsNetwork (VBoxVMSettingsNetworkPage *aParent) 31 : QIWithRetranslateUI <QWidget> (0) 32 , mParent (aParent) 33 , mDetails (new VBoxVMSettingsNetworkDetails (this)) 56 34 , mValidator (0) 57 35 { … … 59 37 Ui::VBoxVMSettingsNetwork::setupUi (this); 60 38 61 /* Setup common validators */ 62 mLeMAC->setValidator (new QRegExpValidator 63 (QRegExp ("[0-9A-Fa-f][02468ACEace][0-9A-Fa-f]{10}"), this)); 64 65 /* Setup dialog for current platform */ 66 #if !defined (Q_WS_X11) || defined (VBOX_WITH_NETFLT) 67 setTapVisible (false); 68 #endif 39 /* Setup widgets */ 40 mTbDetails->setIcon (VBoxGlobal::iconSet ( 41 ":/global_settings_16px.png", ":/global_settings_disabled_16px.png")); 69 42 70 43 /* Applying language settings */ … … 75 48 * available on Mac OS X. Not sure why this happens but this seems to help 76 49 * against. */ 77 QList <QWidget*> list = findChildren<QWidget*>();50 QList <QWidget*> list = findChildren <QWidget*>(); 78 51 foreach (QWidget *w, list) 79 52 if (w->parent() == this) … … 86 59 mAdapter = aAdapter; 87 60 61 /* Load adapter state */ 88 62 mGbAdapter->setChecked (aAdapter.GetEnabled()); 89 63 90 int aPos = mCbAType->findText ( 91 vboxGlobal().toString (aAdapter.GetAdapterType())); 92 mCbAType->setCurrentIndex (aPos == -1 ? 0 : aPos); 93 94 int naPos = mCbNAType->findText ( 95 vboxGlobal().toString (aAdapter.GetAttachmentType())); 96 mCbNAType->setCurrentIndex (naPos == -1 ? 0 : naPos); 97 naTypeChanged (mCbNAType->currentText()); 98 99 mLeMAC->setText (aAdapter.GetMACAddress()); 100 101 mCbCable->setChecked (aAdapter.GetCableConnected()); 102 103 int inPos = mCbNetwork->findText (aAdapter.GetInternalNetwork()); 104 mCbNetwork->setCurrentIndex (inPos == -1 ? 0 : inPos); 105 106 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 107 mInterfaceName = aAdapter.GetHostInterface().isEmpty() ? 108 QString::null : aAdapter.GetHostInterface(); 109 #endif 110 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT) 111 mLeInterface_x11->setText (aAdapter.GetHostInterface()); 112 #endif 64 /* Load adapter type */ 65 int adapterPos = mCbAdapterType->findData (aAdapter.GetAdapterType()); 66 mCbAdapterType->setCurrentIndex (adapterPos == -1 ? 0 : adapterPos); 67 68 /* Load cable-connected status */ 69 mTbCable->setProperty ("EXT_Checked", QVariant (aAdapter.GetCableConnected())); 70 updateCableConnectedState(); 71 72 /* Load network attachment type */ 73 int attachmentPos = mCbAttachmentType->findData (aAdapter.GetAttachmentType()); 74 mCbAttachmentType->setCurrentIndex (attachmentPos == -1 ? 0 : attachmentPos); 75 76 /* Load details page */ 77 mDetails->getFromAdapter (aAdapter); 113 78 } 114 79 115 80 void VBoxVMSettingsNetwork::putBackToAdapter() 116 81 { 82 /* Save adapter state */ 117 83 mAdapter.SetEnabled (mGbAdapter->isChecked()); 118 84 119 mAdapter.SetAdapterType (vboxGlobal(). 120 toNetworkAdapterType (mCbAType->currentText())); 121 122 KNetworkAttachmentType type = 123 vboxGlobal().toNetworkAttachmentType (mCbNAType->currentText()); 124 switch (type) 85 /* Save adapter type */ 86 KNetworkAdapterType type = (KNetworkAdapterType) 87 mCbAdapterType->itemData (mCbAdapterType->currentIndex()).toInt(); 88 mAdapter.SetAdapterType (type); 89 90 /* Save cable-connected status */ 91 mAdapter.SetCableConnected (mTbCable->property ("EXT_Checked").toBool()); 92 93 /* Save network attachment type */ 94 switch (attachmentType()) 125 95 { 126 96 case KNetworkAttachmentType_Null: … … 140 110 break; 141 111 default: 142 AssertMsgFailed (("Invalid network attachment type: %d", type)); 143 break; 144 } 145 146 mAdapter.SetMACAddress (mLeMAC->text()); 147 148 mAdapter.SetCableConnected (mCbCable->isChecked()); 149 150 if (type == KNetworkAttachmentType_Bridged 151 #if defined (Q_WS_WIN) && defined (VBOX_WITH_NETFLT) 152 || type == KNetworkAttachmentType_HostOnly 153 #endif 154 ) 155 { 156 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 157 mAdapter.SetHostInterface (mInterfaceName); 158 #endif 159 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT) 160 QString iface = mLeInterface_x11->text(); 161 mAdapter.SetHostInterface (iface.isEmpty() ? QString::null : iface); 162 #endif 163 } 164 else if (type == KNetworkAttachmentType_Internal) 165 mAdapter.SetInternalNetwork (mCbNetwork->currentText()); 112 AssertMsgFailed (("Invalid network attachment type: (%d).", attachmentType())); 113 } 114 115 /* Save details page */ 116 mDetails->putBackToAdapter(); 117 } 118 119 void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator) 120 { 121 mValidator = aValidator; 122 123 connect (mGbAdapter, SIGNAL (toggled (bool)), 124 mValidator, SLOT (revalidate())); 125 connect (mCbAttachmentType, SIGNAL (activated (const QString&)), 126 mValidator, SLOT (revalidate())); 127 connect (mTbCable, SIGNAL (clicked (bool)), 128 this, SLOT (updateCableConnectedState())); 129 connect (mTbDetails, SIGNAL (clicked (bool)), 130 this, SLOT (detailsClicked())); 131 132 mValidator->revalidate(); 133 } 134 135 bool VBoxVMSettingsNetwork::revalidate (QString &aWarning, QString &aTitle) 136 { 137 bool valid = mGbAdapter->isChecked() ? 138 mDetails->revalidate (attachmentType(), aWarning) : true; 139 140 if (!valid) 141 aTitle += ": " + vboxGlobal().removeAccelMark (pageTitle()); 142 143 return valid; 144 } 145 146 QWidget* VBoxVMSettingsNetwork::setOrderAfter (QWidget *aAfter) 147 { 148 setTabOrder (aAfter, mGbAdapter); 149 setTabOrder (mGbAdapter, mCbAdapterType); 150 setTabOrder (mCbAdapterType, mTbCable); 151 setTabOrder (mTbCable, mCbAttachmentType); 152 return mCbAttachmentType; 166 153 } 167 154 168 155 QString VBoxVMSettingsNetwork::pageTitle() const 169 156 { 170 QString pageTitle;157 QString title; 171 158 if (!mAdapter.isNull()) 172 159 { 173 pageTitle = VBoxGlobal::tr ("Adapter %1", "network")160 title = VBoxGlobal::tr ("Adapter %1", "network") 174 161 .arg (QString ("&%1").arg (mAdapter.GetSlot() + 1)); 175 162 } 176 return pageTitle; 177 } 178 179 void VBoxVMSettingsNetwork::setValidator (QIWidgetValidator *aValidator) 180 { 181 mValidator = aValidator; 182 183 connect (mGbAdapter, SIGNAL (toggled (bool)), 184 this, SLOT (adapterToggled (bool))); 185 connect (mCbNAType, SIGNAL (activated (const QString&)), 186 this, SLOT (naTypeChanged (const QString&))); 187 connect (mCbNetwork, SIGNAL (activated (const QString&)), 188 mValidator, SLOT (revalidate())); 189 connect (mPbMAC, SIGNAL (clicked()), this, SLOT (genMACClicked())); 190 191 mValidator->revalidate(); 192 } 193 194 QWidget* VBoxVMSettingsNetwork::setOrderAfter (QWidget *aAfter) 195 { 196 setTabOrder (aAfter, mGbAdapter); 197 setTabOrder (mGbAdapter, mCbAType); 198 setTabOrder (mCbAType, mCbNAType); 199 setTabOrder (mCbNAType, mCbNetwork); 200 setTabOrder (mCbNetwork, mLeMAC); 201 setTabOrder (mLeMAC, mPbMAC); 202 setTabOrder (mPbMAC, mCbCable); 203 setTabOrder (mCbCable, mLeInterface_x11); 204 return mLeInterface_x11; 205 } 206 207 void VBoxVMSettingsNetwork::setNetworksList (const QStringList &aList) 208 { 209 QString curText = mCbNetwork->currentText(); 210 mCbNetwork->clear(); 211 mCbNetwork->clearEditText(); 212 mCbNetwork->insertItems (0, aList); 213 mCbNetwork->setCurrentIndex (mCbNetwork->findText (curText)); 214 if (mValidator) 215 mValidator->revalidate(); 216 } 217 218 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 219 void VBoxVMSettingsNetwork::setInterfaceName (const QString &aName) 220 { 221 mInterfaceName = aName; 222 if (mValidator) 223 mValidator->revalidate(); 224 } 225 226 QString VBoxVMSettingsNetwork::interfaceName() const 227 { 228 return mInterfaceName; 229 } 230 #endif 163 return title; 164 } 165 166 QString VBoxVMSettingsNetwork::currentName (KNetworkAttachmentType aType) const 167 { 168 return mDetails->currentName (aType); 169 } 231 170 232 171 void VBoxVMSettingsNetwork::retranslateUi() … … 235 174 Ui::VBoxVMSettingsNetwork::retranslateUi (this); 236 175 237 prepareComboboxes(); 238 } 239 240 void VBoxVMSettingsNetwork::adapterToggled (bool aOn) 241 { 242 if (!aOn) 243 { 244 mCbNAType->setCurrentIndex (0); 245 naTypeChanged (mCbNAType->currentText()); 246 } 247 if (mValidator) 248 mValidator->revalidate(); 249 } 250 251 void VBoxVMSettingsNetwork::naTypeChanged (const QString &aString) 252 { 253 bool enableIntNet = vboxGlobal().toNetworkAttachmentType (aString) == 254 KNetworkAttachmentType_Internal; 255 mLbNetwork->setEnabled (enableIntNet); 256 mCbNetwork->setEnabled (enableIntNet); 257 #if defined (Q_WS_X11) && !defined (VBOX_WITH_NETFLT) 258 bool enableHostIf = vboxGlobal().toNetworkAttachmentType (aString) == 259 KNetworkAttachmentType_Bridged; 260 setTapEnabled (enableHostIf); 261 #endif 262 if (mValidator) 263 mValidator->revalidate(); 264 } 265 266 void VBoxVMSettingsNetwork::genMACClicked() 267 { 268 mAdapter.SetMACAddress (QString::null); 269 mLeMAC->setText (mAdapter.GetMACAddress()); 270 } 271 272 void VBoxVMSettingsNetwork::prepareComboboxes() 273 { 274 /* Save the current selected value */ 275 int currentAdapter = mCbAType->currentIndex(); 276 /* Clear the driver box */ 277 mCbAType->clear(); 278 /* Refill them */ 279 mCbAType->insertItem (0, 176 /* Translate combo-boxes content */ 177 populateComboboxes(); 178 } 179 180 void VBoxVMSettingsNetwork::updateCableConnectedState() 181 { 182 if (sender()) 183 { 184 /* If click called with slot - toggle button's state */ 185 bool value = mTbCable->property ("EXT_Checked").toBool(); 186 mTbCable->setProperty ("EXT_Checked", QVariant (!value)); 187 } 188 189 /* Feat the icon relatively button state */ 190 mTbCable->setIcon (VBoxGlobal::iconSet (mTbCable-> 191 property ("EXT_Checked").toBool() ? ":/connect_16px.png" : 192 ":/disconnect_16px.png")); 193 } 194 195 void VBoxVMSettingsNetwork::detailsClicked() 196 { 197 /* Reload alternate list */ 198 KNetworkAttachmentType type = attachmentType(); 199 QStringList list; 200 switch (type) 201 { 202 case KNetworkAttachmentType_NAT: 203 list = mParent->natList(); 204 break; 205 case KNetworkAttachmentType_Bridged: 206 list = mParent->intList (KHostNetworkInterfaceType_Bridged); 207 break; 208 case KNetworkAttachmentType_Internal: 209 list = mParent->netList(); 210 break; 211 case KNetworkAttachmentType_HostOnly: 212 list = mParent->intList (KHostNetworkInterfaceType_HostOnly); 213 break; 214 default: 215 break; 216 } 217 mDetails->loadList (type, list); 218 mDetails->activateWindow(); 219 mDetails->exec(); 220 Assert (mValidator); 221 mValidator->revalidate(); 222 } 223 224 void VBoxVMSettingsNetwork::populateComboboxes() 225 { 226 /* Save the current selected adapter */ 227 int currentAdapter = mCbAdapterType->currentIndex(); 228 229 /* Clear the adapters combo-box */ 230 mCbAdapterType->clear(); 231 232 /* Populate adapters */ 233 mCbAdapterType->insertItem (0, 280 234 vboxGlobal().toString (KNetworkAdapterType_Am79C970A)); 281 mCbAType->setItemData (0, 282 mCbAType->itemText(0), Qt::ToolTipRole); 283 mCbAType->insertItem (1, 235 mCbAdapterType->setItemData (0, 236 KNetworkAdapterType_Am79C970A); 237 mCbAdapterType->setItemData (0, 238 mCbAdapterType->itemText (0), Qt::ToolTipRole); 239 mCbAdapterType->insertItem (1, 284 240 vboxGlobal().toString (KNetworkAdapterType_Am79C973)); 285 mCbAType->setItemData (1, 286 mCbAType->itemText(1), Qt::ToolTipRole); 241 mCbAdapterType->setItemData (1, 242 KNetworkAdapterType_Am79C973); 243 mCbAdapterType->setItemData (1, 244 mCbAdapterType->itemText (1), Qt::ToolTipRole); 287 245 #ifdef VBOX_WITH_E1000 288 mCbA Type->insertItem (2,246 mCbAdapterType->insertItem (2, 289 247 vboxGlobal().toString (KNetworkAdapterType_I82540EM)); 290 mCbAType->setItemData (2, 291 mCbAType->itemText(2), Qt::ToolTipRole); 292 mCbAType->insertItem (3, 248 mCbAdapterType->setItemData (2, 249 KNetworkAdapterType_I82540EM); 250 mCbAdapterType->setItemData (2, 251 mCbAdapterType->itemText (2), Qt::ToolTipRole); 252 mCbAdapterType->insertItem (3, 293 253 vboxGlobal().toString (KNetworkAdapterType_I82543GC)); 294 mCbAType->setItemData (3, 295 mCbAType->itemText(3), Qt::ToolTipRole); 296 #endif 254 mCbAdapterType->setItemData (3, 255 KNetworkAdapterType_I82543GC); 256 mCbAdapterType->setItemData (3, 257 mCbAdapterType->itemText (3), Qt::ToolTipRole); 258 #endif /* VBOX_WITH_E1000 */ 259 297 260 /* Set the old value */ 298 mCbAType->setCurrentIndex (currentAdapter); 299 300 /* Save the current selected value */ 301 int currentAttachment = mCbNAType->currentIndex(); 302 /* Clear the driver box */ 303 mCbNAType->clear(); 304 /* Refill them */ 305 mCbNAType->insertItem (0, 261 mCbAdapterType->setCurrentIndex (currentAdapter == -1 ? 262 0 : currentAdapter); 263 264 265 /* Save the current selected attachment type */ 266 int currentAttachment = mCbAttachmentType->currentIndex(); 267 268 /* Clear the attachments combo-box */ 269 mCbAttachmentType->clear(); 270 271 /* Populate attachments */ 272 mCbAttachmentType->insertItem (0, 306 273 vboxGlobal().toString (KNetworkAttachmentType_Null)); 307 mCbNAType->setItemData (0, 308 mCbNAType->itemText(0), Qt::ToolTipRole); 309 mCbNAType->insertItem (1, 274 mCbAttachmentType->setItemData (0, 275 KNetworkAttachmentType_Null); 276 mCbAttachmentType->setItemData (0, 277 mCbAttachmentType->itemText (0), Qt::ToolTipRole); 278 mCbAttachmentType->insertItem (1, 310 279 vboxGlobal().toString (KNetworkAttachmentType_NAT)); 311 mCbNAType->setItemData (1, 312 mCbNAType->itemText(1), Qt::ToolTipRole); 313 mCbNAType->insertItem (2, 280 mCbAttachmentType->setItemData (1, 281 KNetworkAttachmentType_NAT); 282 mCbAttachmentType->setItemData (1, 283 mCbAttachmentType->itemText (1), Qt::ToolTipRole); 284 mCbAttachmentType->insertItem (2, 314 285 vboxGlobal().toString (KNetworkAttachmentType_Bridged)); 315 mCbNAType->setItemData (2, 316 mCbNAType->itemText(2), Qt::ToolTipRole); 317 mCbNAType->insertItem (3, 286 mCbAttachmentType->setItemData (2, 287 KNetworkAttachmentType_Bridged); 288 mCbAttachmentType->setItemData (2, 289 mCbAttachmentType->itemText (2), Qt::ToolTipRole); 290 mCbAttachmentType->insertItem (3, 318 291 vboxGlobal().toString (KNetworkAttachmentType_Internal)); 319 mCbNAType->setItemData (3, 320 mCbNAType->itemText(3), Qt::ToolTipRole); 321 #if defined(RT_OS_LINUX) || defined (RT_OS_WINDOWS) 322 mCbNAType->insertItem (4, 292 mCbAttachmentType->setItemData (3, 293 KNetworkAttachmentType_Internal); 294 mCbAttachmentType->setItemData (3, 295 mCbAttachmentType->itemText (3), Qt::ToolTipRole); 296 #if defined (RT_OS_LINUX) || defined (RT_OS_WINDOWS) 297 mCbAttachmentType->insertItem (4, 323 298 vboxGlobal().toString (KNetworkAttachmentType_HostOnly)); 324 mCbNAType->setItemData (4, 325 mCbNAType->itemText(4), Qt::ToolTipRole); 326 #endif /* RT_OS_LINUX */ 299 mCbAttachmentType->setItemData (4, 300 KNetworkAttachmentType_HostOnly); 301 mCbAttachmentType->setItemData (4, 302 mCbAttachmentType->itemText (4), Qt::ToolTipRole); 303 #endif /* RT_OS_LINUX || RT_OS_WINDOWS */ 304 327 305 /* Set the old value */ 328 mCbNAType->setCurrentIndex (currentAttachment); 329 } 330 331 void VBoxVMSettingsNetwork::setTapEnabled (bool aEnabled) 332 { 333 mGbTap->setEnabled (aEnabled); 334 mLbInterface_x11->setEnabled (aEnabled); 335 mLeInterface_x11->setEnabled (aEnabled); 336 } 337 338 void VBoxVMSettingsNetwork::setTapVisible (bool aVisible) 339 { 340 mGbTap->setVisible (aVisible); 341 mLbInterface_x11->setVisible (aVisible); 342 mLeInterface_x11->setVisible (aVisible); 343 #ifdef Q_WS_MAC 344 /* Make sure the layout is recalculated (Important on the mac). */ 345 layout()->activate(); 346 #endif 347 } 348 349 /* VBoxNIList Stuff */ 350 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 351 class VBoxNIListItem : public QTreeWidgetItem 352 { 353 public: 354 355 enum { typeId = QTreeWidgetItem::UserType + 1 }; 356 357 VBoxNIListItem (QTreeWidget *aParent, const QString &aName, bool aWrong = false) 358 : QTreeWidgetItem (aParent, QStringList (aName), typeId) 359 , mWrong (aWrong) 360 { 361 init(); 362 } 363 364 VBoxNIListItem (const QString &aName, bool aWrong = false) 365 : QTreeWidgetItem (QStringList (aName), typeId) 366 , mWrong (aWrong) 367 { 368 init(); 369 } 370 371 void init() 372 { 373 /* Force the fake item's font to italic */ 374 if (mWrong) 375 { 376 QFont fnt = font (0); 377 fnt.setItalic (true); 378 setFont (0, fnt); 379 } 380 } 381 382 bool isWrong() { return mWrong; } 383 384 private: 385 386 bool mWrong; 387 }; 388 389 VBoxNIList::VBoxNIList (QWidget *aParent) 390 : QIWithRetranslateUI<QWidget> (aParent) 391 { 392 QVBoxLayout *mainLayout = new QVBoxLayout (this); 393 VBoxGlobal::setLayoutMargin (mainLayout, 0); 394 mLbTitle = new QILabelSeparator(); 395 mainLayout->addWidget (mLbTitle); 396 // mainLayout->addItem (new QSpacerItem (8, 16, QSizePolicy::Fixed, QSizePolicy::Minimum), 1, 0); 397 /* Creating List Widget */ 398 QHBoxLayout *layout = new QHBoxLayout (); 399 mainLayout->addLayout (layout); 400 mList = new QTreeWidget (this); 401 setFocusProxy (mList); 402 mLbTitle->setBuddy (mList); 403 mList->setColumnCount (1); 404 mList->header()->hide(); 405 mList->setContextMenuPolicy (Qt::ActionsContextMenu); 406 mList->setRootIsDecorated (false); 407 layout->addWidget (mList); 408 409 /* Prepare actions */ 410 # if defined (Q_WS_WIN) 411 mAddAction = new QAction (mList); 412 mDelAction = new QAction (mList); 413 mList->addAction (mAddAction); 414 mList->addAction (mDelAction); 415 mAddAction->setShortcut (QKeySequence ("Ins")); 416 mDelAction->setShortcut (QKeySequence ("Del")); 417 mAddAction->setIcon (VBoxGlobal::iconSet (":/add_host_iface_16px.png", 418 ":/add_host_iface_disabled_16px.png")); 419 mDelAction->setIcon (VBoxGlobal::iconSet (":/remove_host_iface_16px.png", 420 ":/remove_host_iface_disabled_16px.png")); 421 # endif /* Q_WS_WIN */ 422 423 # if defined (Q_WS_WIN) 424 /* Prepare toolbar */ 425 VBoxToolBar *toolBar = new VBoxToolBar (this); 426 toolBar->setUsesTextLabel (false); 427 toolBar->setIconSize (QSize (16, 16)); 428 toolBar->setOrientation (Qt::Vertical); 429 toolBar->addAction (mAddAction); 430 toolBar->addAction (mDelAction); 431 layout->addWidget (toolBar); 432 # endif /* Q_WS_WIN */ 433 434 /* Setup connections */ 435 connect (mList, SIGNAL (currentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *)), 436 this, SLOT (onCurrentItemChanged (QTreeWidgetItem *, QTreeWidgetItem *))); 437 # if defined (Q_WS_WIN) 438 connect (mAddAction, SIGNAL (triggered (bool)), 439 this, SLOT (addHostInterface())); 440 connect (mDelAction, SIGNAL (triggered (bool)), 441 this, SLOT (delHostInterface())); 442 # endif /* Q_WS_WIN */ 443 444 #if !defined(Q_WS_WIN) || !defined(VBOX_WITH_NETFLT) 445 /* Populating interface list */ 446 populateInterfacesList(); 447 #endif 448 449 /* Applying language settings */ 450 retranslateUi(); 451 } 452 453 bool VBoxNIList::isWrongInterface() const 454 { 455 return !mList->currentItem(); 456 } 457 458 void VBoxNIList::setCurrentInterface (const QString &aName) 459 { 460 /* Remove wrong item if present */ 461 for (int i = 0; i < mList->topLevelItemCount(); ++ i) 462 { 463 VBoxNIListItem *item = 464 mList->topLevelItem (i)->type() == VBoxNIListItem::typeId ? 465 static_cast<VBoxNIListItem*> (mList->topLevelItem (i)) : 0; 466 Assert (item); 467 if (item && item->isWrong()) 468 delete item; 469 } 470 471 if (aName.isEmpty()) 472 { 473 #ifdef VBOX_WITH_NETFLT 474 /* Always select the first item to have an initial value. */ 475 QTreeWidgetItem *item = mList->topLevelItem (0); 476 if (item) 477 { 478 item->setSelected (true); 479 mList->setCurrentItem (item); 480 onCurrentItemChanged (mList->currentItem()); 481 } 482 #else 483 /* Make sure no one of items selected in the list currently */ 484 mList->setCurrentItem (NULL); 485 mList->clearSelection(); 486 #endif 487 } 488 else 489 { 490 /* Search for the required item */ 491 QTreeWidgetItem *querryItem = findItem (mList, aName); 492 493 /* Create fake required item if real is not present */ 494 if (!querryItem) 495 querryItem = new VBoxNIListItem (mList, aName, true); 496 497 /* Set the required item to be the current */ 498 mList->setCurrentItem (querryItem); 499 } 500 } 501 502 void VBoxNIList::onCurrentItemChanged (QTreeWidgetItem *aCurrent, 503 QTreeWidgetItem *) 504 { 505 # if defined (Q_WS_WIN) 506 # if defined (VBOX_WITH_NETFLT) 507 if(mEnmAttachmentType == KNetworkAttachmentType_HostOnly) 508 # endif 509 { 510 VBoxNIListItem *item = aCurrent && 511 aCurrent->type() == VBoxNIListItem::typeId ? 512 static_cast<VBoxNIListItem*> (aCurrent) : 0; 513 mDelAction->setEnabled (item && !item->isWrong()); 514 } 515 # if defined (VBOX_WITH_NETFLT) 516 else 517 { 518 mDelAction->setEnabled (false); 519 } 520 # endif 521 # else 522 NOREF (aCurrent); 523 # endif 524 525 emit currentInterfaceChanged (mList->currentItem() ? 526 mList->currentItem()->text (0) : QString::null); 527 } 528 529 void VBoxNIList::addHostInterface() 530 { 531 # if defined (Q_WS_WIN) 532 /* Allow the started helper process to make itself the foreground window */ 533 AllowSetForegroundWindow (ASFW_ANY); 534 535 /* Search for the max available interface index */ 536 int ifaceNumber = 0; 537 QString ifaceName = tr ("VirtualBox Host Interface %1"); 538 QRegExp regExp (QString ("^") + ifaceName.arg ("([0-9]+)") + QString ("$")); 539 for (int index = 0; index < mList->topLevelItemCount(); ++ index) 540 { 541 QString iface = mList->topLevelItem (index)->text (0); 542 int pos = regExp.indexIn (iface); 543 if (pos != -1) 544 ifaceNumber = regExp.cap (1).toInt() > ifaceNumber ? 545 regExp.cap (1).toInt() : ifaceNumber; 546 } 547 548 /* Create interface */ 549 CHost host = vboxGlobal().virtualBox().GetHost(); 550 CHostNetworkInterface iFace; 551 CProgress progress = host.CreateHostOnlyNetworkInterface (iFace); 552 if (host.isOk()) 553 { 554 QString iName = iFace.GetName(); 555 556 vboxProblem().showModalProgressDialog (progress, iName, this); 557 /* Add&Select newly created interface */ 558 if (progress.GetResultCode() == 0) 559 new VBoxNIListItem (mList, iName); 560 else 561 vboxProblem().cannotCreateHostInterface (progress, iName, this); 562 } 563 else 564 vboxProblem().cannotCreateHostInterface (host, this); 565 566 emit listChanged(); 567 568 /* Allow the started helper process to make itself the foreground window */ 569 AllowSetForegroundWindow (ASFW_ANY); 570 # endif /* Q_WS_WIN */ 571 } 572 573 void VBoxNIList::delHostInterface() 574 { 575 Assert (mList->currentItem()); 576 577 # if defined (Q_WS_WIN) 578 /* Allow the started helper process to make itself the foreground window */ 579 AllowSetForegroundWindow (ASFW_ANY); 580 581 /* Check interface name */ 582 QString iName = mList->currentItem()->text (0); 583 if (iName.isEmpty()) 584 return; 585 586 /* Asking user about deleting selected network interface */ 587 int delNetIface = vboxProblem().message (this, VBoxProblemReporter::Question, 588 tr ("<p>Do you want to remove the selected host network interface " 589 "<nobr><b>%1</b>?</nobr></p>" 590 "<p><b>Note:</b> This interface may be in use by one or more " 591 "network adapters of this or another VM. After it is removed, these " 592 "adapters will no longer work until you correct their settings by " 593 "either choosing a different interface name or a different adapter " 594 "attachment type.</p>").arg (iName), 595 0, /* autoConfirmId */ 596 QIMessageBox::Ok | QIMessageBox::Default, 597 QIMessageBox::Cancel | QIMessageBox::Escape); 598 if (delNetIface == QIMessageBox::Cancel) 599 return; 600 601 CHost host = vboxGlobal().virtualBox().GetHost(); 602 CHostNetworkInterfaceVector interfaces = 603 host.GetNetworkInterfaces(); 604 CHostNetworkInterface iFace; 605 for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin(); 606 it != interfaces.end(); ++it) 607 if (it->GetName() == iName) 608 iFace = *it; 609 if (!iFace.isNull()) 610 { 611 /* Delete interface */ 612 CProgress progress = host.RemoveHostOnlyNetworkInterface (iFace.GetId(), iFace); 613 if (host.isOk()) 614 { 615 vboxProblem().showModalProgressDialog (progress, iName, this); 616 if (progress.GetResultCode() == 0) 617 delete findItem (mList, iName); 618 else 619 vboxProblem().cannotRemoveHostInterface (progress, iFace, this); 620 } 621 } 622 623 if (!host.isOk()) 624 vboxProblem().cannotRemoveHostInterface (host, iFace, this); 625 626 emit listChanged(); 627 # endif /* Q_WS_WIN */ 628 } 629 630 void VBoxNIList::retranslateUi() 631 { 632 mLbTitle->setText (tr ("Host &Interfaces")); 633 634 mList->setWhatsThis (tr ("Lists all available host interfaces.")); 635 636 # if defined (Q_WS_WIN) 637 mAddAction->setText (tr ("A&dd New Host Interface")); 638 mDelAction->setText (tr ("&Remove Selected Host Interface")); 639 mAddAction->setWhatsThis (tr ("Adds a new host interface.")); 640 mDelAction->setWhatsThis (tr ("Removes the selected host interface.")); 641 mAddAction->setToolTip (mAddAction->text().remove ('&') + 642 QString (" (%1)").arg (mAddAction->shortcut().toString())); 643 mDelAction->setToolTip (mDelAction->text().remove ('&') + 644 QString (" (%1)").arg (mDelAction->shortcut().toString())); 645 # endif /* Q_WS_WIN */ 646 } 647 648 #if defined(Q_WS_WIN) && defined(VBOX_WITH_NETFLT) 649 void VBoxNIList::updateInterfacesList(KNetworkAttachmentType enmAttachmentType) 650 { 651 bool bHostOnly = enmAttachmentType == KNetworkAttachmentType_HostOnly; 652 mEnmAttachmentType = enmAttachmentType; 653 mAddAction->setEnabled(bHostOnly); 654 mDelAction->setEnabled(bHostOnly); 655 populateInterfacesList(enmAttachmentType); 656 } 657 658 void VBoxNIList::populateInterfacesList(KNetworkAttachmentType enmAttachmentType) 659 #else 660 void VBoxNIList::populateInterfacesList() 661 #endif 662 { 663 /* Load current inner list */ 664 QList<QTreeWidgetItem*> itemsList; 665 CHostNetworkInterfaceVector interfaces = vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces(); 666 for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin(); 667 it != interfaces.end(); ++it) 668 { 669 #if defined(Q_WS_WIN) && defined(VBOX_WITH_NETFLT) 670 /* display real for not host-only and viceversa */ 671 if((enmAttachmentType == KNetworkAttachmentType_HostOnly) 672 == (it->GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)) 673 #endif 674 itemsList << new VBoxNIListItem (it->GetName()); 675 } 676 677 /* Save current list item name */ 678 QString currentListItemName = mList->currentItem() ? 679 mList->currentItem()->text (0) : QString::null; 680 681 /* Load current list items */ 682 mList->clear(); 683 if (!itemsList.isEmpty()) 684 mList->insertTopLevelItems (0, itemsList); 685 686 /* Select current list item */ 687 QTreeWidgetItem *item = findItem (mList, currentListItemName); 688 mList->setCurrentItem (item ? item : mList->topLevelItem (0)); 689 690 /* Update item's state */ 691 onCurrentItemChanged (mList->currentItem()); 692 } 693 #endif /* Q_WS_WIN || VBOX_WITH_NETFLT */ 694 306 mCbAttachmentType->setCurrentIndex (currentAttachment); 307 } 308 309 KNetworkAttachmentType VBoxVMSettingsNetwork::attachmentType() const 310 { 311 return (KNetworkAttachmentType) mCbAttachmentType->itemData ( 312 mCbAttachmentType->currentIndex()).toInt(); 313 } 695 314 696 315 /* VBoxVMSettingsNetworkPage Stuff */ 697 316 VBoxVMSettingsNetworkPage::VBoxVMSettingsNetworkPage() 698 317 : mValidator (0) 699 , mLockNetworkListUpdate (true) 700 { 701 QVBoxLayout * layout = new QVBoxLayout (this);702 layout->setContentsMargins (0, 5, 0, 5);318 { 319 /* Setup Main Layout */ 320 QVBoxLayout *mainLayout = new QVBoxLayout (this); 321 mainLayout->setContentsMargins (0, 5, 0, 5); 703 322 704 323 /* Creating Tab Widget */ 705 324 mTwAdapters = new QTabWidget (this); 706 layout->addWidget (mTwAdapters); 707 /* Prepare Networks Lists */ 708 populateNetworksList(); 709 710 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 711 /* Creating Interfaces List */ 712 mNIList = new VBoxNIList (this); 713 layout->addWidget (mNIList); 714 #else 715 // layout->addItem (new QSpacerItem (0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); 716 #endif 717 // layout->activate(); 325 mainLayout->addWidget (mTwAdapters); 326 } 327 328 QStringList VBoxVMSettingsNetworkPage::natList() const 329 { 330 QStringList list; 331 332 /* Load total NAT names list of all VMs */ 333 CVirtualBox vbox = vboxGlobal().virtualBox(); 334 ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount()); 335 CMachineVector vec = vbox.GetMachines(); 336 for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++ m) 337 { 338 if (m->GetAccessible()) 339 { 340 for (ulong slot = 0; slot < count; ++ slot) 341 { 342 QString name = m->GetNetworkAdapter (slot).GetNATNetwork(); 343 if (!name.isEmpty() && !list.contains (name)) 344 list << name; 345 } 346 } 347 } 348 349 /* Append NAT names list with names from all the pages */ 350 for (int index = 0; index < mTwAdapters->count(); ++ index) 351 { 352 VBoxVMSettingsNetwork *page = 353 qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (index)); 354 if (page) 355 { 356 QString name = page->currentName (KNetworkAttachmentType_NAT); 357 if (!name.isEmpty() && !list.contains (name)) 358 list << name; 359 } 360 } 361 362 return list; 363 } 364 365 QStringList VBoxVMSettingsNetworkPage::netList() const 366 { 367 QStringList list; 368 369 /* Load total network list of all VMs */ 370 CVirtualBox vbox = vboxGlobal().virtualBox(); 371 ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount()); 372 CMachineVector vec = vbox.GetMachines(); 373 for (CMachineVector::ConstIterator m = vec.begin(); m != vec.end(); ++ m) 374 { 375 if (m->GetAccessible()) 376 { 377 for (ulong slot = 0; slot < count; ++ slot) 378 { 379 QString name = m->GetNetworkAdapter (slot).GetInternalNetwork(); 380 if (!name.isEmpty() && !list.contains (name)) 381 list << name; 382 } 383 } 384 } 385 386 /* Append network list with names from all the pages */ 387 for (int index = 0; index < mTwAdapters->count(); ++ index) 388 { 389 VBoxVMSettingsNetwork *page = 390 qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (index)); 391 if (page) 392 { 393 QString name = page->currentName (KNetworkAttachmentType_Internal); 394 if (!name.isEmpty() && !list.contains (name)) 395 list << name; 396 } 397 } 398 399 return list; 400 } 401 402 QStringList VBoxVMSettingsNetworkPage::intList (KHostNetworkInterfaceType aType) const 403 { 404 QStringList list; 405 406 /* Load total interfaces list */ 407 CHostNetworkInterfaceVector interfaces = 408 vboxGlobal().virtualBox().GetHost().GetNetworkInterfaces(); 409 for (CHostNetworkInterfaceVector::ConstIterator it = interfaces.begin(); 410 it != interfaces.end(); ++ it) 411 { 412 if (it->GetInterfaceType() == aType) 413 list << it->GetName(); 414 } 415 416 return list; 718 417 } 719 418 720 419 void VBoxVMSettingsNetworkPage::getFrom (const CMachine &aMachine) 721 420 { 421 /* Setup tab order */ 722 422 Assert (mFirstWidget); 723 423 setTabOrder (mFirstWidget, mTwAdapters->focusProxy()); … … 733 433 734 434 /* Creating Adapter's page */ 735 VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork ();435 VBoxVMSettingsNetwork *page = new VBoxVMSettingsNetwork (this); 736 436 737 437 /* Loading Adapter's data into page */ 738 page->setNetworksList (mListNetworks);739 438 page->getFromAdapter (adapter); 740 439 … … 747 446 /* Setup tab order */ 748 447 lastFocusWidget = page->setOrderAfter (lastFocusWidget); 749 750 /* Setup connections */ 751 #if defined (VBOX_WITH_NETFLT) 752 connect (page->mCbNAType, SIGNAL (currentIndexChanged (int)), 753 this, SLOT (updateInterfaceList())); 754 #endif 755 connect (page->mCbNetwork, SIGNAL (editTextChanged (const QString&)), 756 this, SLOT (updateNetworksList())); 757 } 758 759 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 760 setTabOrder (lastFocusWidget, mNIList->focusProxy()); 761 connect (mTwAdapters, SIGNAL (currentChanged (int)), 762 this, SLOT (onCurrentPageChanged (int))); 763 connect (mNIList, SIGNAL (currentInterfaceChanged (const QString &)), 764 this, SLOT (onCurrentInterfaceChanged (const QString &))); 765 onCurrentPageChanged (mTwAdapters->currentIndex()); 766 #endif 448 } 767 449 768 450 /* Applying language settings */ … … 774 456 for (int i = 0; i < mTwAdapters->count(); ++ i) 775 457 { 776 VBoxVMSettingsNetwork *page = static_cast<VBoxVMSettingsNetwork*>777 (mTwAdapters->widget (i));778 if (page)779 458 VBoxVMSettingsNetwork *page = 459 qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i)); 460 Assert (page); 461 page->putBackToAdapter(); 780 462 } 781 463 } … … 784 466 { 785 467 mValidator = aVal; 786 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 787 connect (mNIList, SIGNAL (listChanged()), mValidator, SLOT (revalidate())); 788 #endif 789 } 790 791 bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning, 792 QString &aTitle) 468 } 469 470 bool VBoxVMSettingsNetworkPage::revalidate (QString &aWarning, QString &aTitle) 793 471 { 794 472 bool valid = true; … … 796 474 for (int i = 0; i < mTwAdapters->count(); ++ i) 797 475 { 798 VBoxVMSettingsNetwork *page = static_cast<VBoxVMSettingsNetwork*>799 (mTwAdapters->widget (i));476 VBoxVMSettingsNetwork *page = 477 qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i)); 800 478 Assert (page); 801 802 KNetworkAttachmentType type = 803 vboxGlobal().toNetworkAttachmentType (page->mCbNAType->currentText()); 804 805 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT) 806 if ((type == KNetworkAttachmentType_Bridged 807 #if defined (Q_WS_WIN) && defined (VBOX_WITH_NETFLT) 808 || type == KNetworkAttachmentType_HostOnly 809 #endif 810 ) && page->interfaceName().isNull()) 811 { 812 valid = false; 813 aWarning = tr ("No host network interface is selected"); 814 } else 815 #endif 816 if (type == KNetworkAttachmentType_Internal && 817 page->mCbNetwork->currentText().isEmpty()) 818 { 819 valid = false; 820 aWarning = tr ("Internal network name is not set"); 821 } 822 823 if (!valid) 824 { 825 aTitle += ": " + vboxGlobal().removeAccelMark (page->pageTitle()); 826 break; 827 } 479 valid = page->revalidate (aWarning, aTitle); 480 if (!valid) break; 828 481 } 829 482 … … 836 489 { 837 490 VBoxVMSettingsNetwork *page = 838 static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (i)); 491 qobject_cast <VBoxVMSettingsNetwork*> (mTwAdapters->widget (i)); 492 Assert (page); 839 493 mTwAdapters->setTabText (i, page->pageTitle()); 840 494 } 841 495 } 842 496 843 void VBoxVMSettingsNetworkPage::updateNetworksList()844 {845 /* Lock to prevent few simultaneously update */846 if (mLockNetworkListUpdate)847 return;848 mLockNetworkListUpdate = true;849 850 /* Compose latest list from current + new on all pages */851 QStringList curList (mListNetworks);852 for (int index = 0; index < mTwAdapters->count(); ++ index)853 {854 VBoxVMSettingsNetwork *page =855 static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));856 if (page)857 {858 QString curText = page->mCbNetwork->currentText();859 if (!curText.isEmpty() && !curList.contains (curText))860 curList << curText;861 }862 }863 864 /* Load latest list to all pages */865 for (int index = 0; index < mTwAdapters->count(); ++ index)866 {867 VBoxVMSettingsNetwork *page =868 static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (index));869 if (page)870 page->setNetworksList (curList);871 }872 873 /* Allow further Network List update */874 mLockNetworkListUpdate = false;875 }876 877 #if defined (VBOX_WITH_NETFLT)878 void VBoxVMSettingsNetworkPage::updateInterfaceList()879 {880 VBoxVMSettingsNetwork *page =881 static_cast <VBoxVMSettingsNetwork*> (mTwAdapters->currentWidget());882 KNetworkAttachmentType enmType = vboxGlobal().toNetworkAttachmentType (page->mCbNAType->currentText());883 884 bool isHostInterfaceAttached = enmType == KNetworkAttachmentType_Bridged;885 886 mNIList->setEnabled (isHostInterfaceAttached);887 # ifdef Q_WS_WIN888 if(!isHostInterfaceAttached)889 {890 mNIList->setEnabled (enmType == KNetworkAttachmentType_HostOnly);891 }892 mNIList->updateInterfacesList(enmType);893 # endif894 }895 #endif896 897 #if defined (Q_WS_WIN) || defined (VBOX_WITH_NETFLT)898 void VBoxVMSettingsNetworkPage::onCurrentPageChanged (int aIndex)899 {900 VBoxVMSettingsNetwork *page =901 static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->widget (aIndex));902 Assert (page);903 mNIList->setCurrentInterface (page->interfaceName());904 905 #if defined (VBOX_WITH_NETFLT)906 updateInterfaceList();907 #endif908 }909 910 void VBoxVMSettingsNetworkPage::onCurrentInterfaceChanged (const QString &aName)911 {912 VBoxVMSettingsNetwork *page =913 static_cast<VBoxVMSettingsNetwork*> (mTwAdapters->currentWidget());914 Assert (page);915 page->setInterfaceName (aName);916 }917 #endif918 919 void VBoxVMSettingsNetworkPage::populateNetworksList()920 {921 /* Clear inner list */922 mListNetworks.clear();923 924 /* Load internal network list */925 CVirtualBox vbox = vboxGlobal().virtualBox();926 ulong count = qMin ((ULONG) 4, vbox.GetSystemProperties().GetNetworkAdapterCount());927 CMachineVector vec = vbox.GetMachines();928 for (CMachineVector::ConstIterator m = vec.begin();929 m != vec.end(); ++ m)930 {931 if (m->GetAccessible())932 {933 for (ulong slot = 0; slot < count; ++ slot)934 {935 CNetworkAdapter adapter = m->GetNetworkAdapter (slot);936 if (adapter.GetAttachmentType() == KNetworkAttachmentType_Internal &&937 !mListNetworks.contains (adapter.GetInternalNetwork()))938 mListNetworks << adapter.GetInternalNetwork();939 }940 }941 }942 943 /* Allow further Network List update */944 mLockNetworkListUpdate = false;945 }946 -
trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsNetwork.ui
r17217 r17784 28 28 </property> 29 29 <layout class="QGridLayout" > 30 <item row="0" column="0" colspan=" 2" >30 <item row="0" column="0" colspan="3" > 31 31 <widget class="QCheckBox" name="mGbAdapter" > 32 32 <property name="whatsThis" > … … 75 75 <widget class="QLabel" name="mLbAType" > 76 76 <property name="text" > 77 <string>A &dapterType:</string>77 <string>Adapter &Type:</string> 78 78 </property> 79 79 <property name="alignment" > … … 81 81 </property> 82 82 <property name="buddy" > 83 <cstring>mCbA Type</cstring>83 <cstring>mCbAdapterType</cstring> 84 84 </property> 85 85 </widget> 86 86 </item> 87 87 <item row="0" column="1" > 88 <widget class="QComboBox" name="mCbA Type" >88 <widget class="QComboBox" name="mCbAdapterType" > 89 89 <property name="whatsThis" > 90 90 <string>Selects the type of the virtual network adapter. Depending on this value, VirtualBox will provide different network hardware to the virtual machine.</string> 91 </property> 92 </widget> 93 </item> 94 <item row="0" column="2" > 95 <widget class="QToolButton" name="mTbCable" > 96 <property name="whatsThis" > 97 <string>Indicates whether the virtual network cable is plugged in on machine startup or not.</string> 98 </property> 99 <property name="autoRaise" > 100 <bool>true</bool> 91 101 </property> 92 102 </widget> … … 101 111 </property> 102 112 <property name="buddy" > 103 <cstring>mCb NAType</cstring>113 <cstring>mCbAttachmentType</cstring> 104 114 </property> 105 115 </widget> 106 116 </item> 107 117 <item row="1" column="1" > 108 <widget class="QComboBox" name="mCb NAType" >118 <widget class="QComboBox" name="mCbAttachmentType" > 109 119 <property name="whatsThis" > 110 120 <string>Controls the way how this virtual adapter is attached to the real network of the Host OS.</string> … … 112 122 </widget> 113 123 </item> 114 <item row=" 2" column="0" >115 <widget class="Q Label" name="mLbNetwork" >116 <property name=" text" >117 <string> &Network Name:</string>124 <item row="1" column="2" > 125 <widget class="QToolButton" name="mTbDetails" > 126 <property name="whatsThis" > 127 <string>Open extended settings dialog for current attachment type.</string> 118 128 </property> 119 <property name="alignment" > 120 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> 121 </property> 122 <property name="buddy" > 123 <cstring>mCbNetwork</cstring> 124 </property> 125 </widget> 126 </item> 127 <item row="2" column="1" > 128 <widget class="QComboBox" name="mCbNetwork" > 129 <property name="whatsThis" > 130 <string>Displays the name of the internal network selected for this adapter.</string> 131 </property> 132 <property name="editable" > 129 <property name="autoRaise" > 133 130 <bool>true</bool> 134 </property>135 </widget>136 </item>137 <item row="3" column="0" >138 <widget class="QLabel" name="mLbMAC" >139 <property name="text" >140 <string>&MAC Address:</string>141 </property>142 <property name="alignment" >143 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>144 </property>145 <property name="buddy" >146 <cstring>mLeMAC</cstring>147 </property>148 </widget>149 </item>150 <item row="3" column="1" >151 <widget class="QLineEdit" name="mLeMAC" >152 <property name="sizePolicy" >153 <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >154 <horstretch>0</horstretch>155 <verstretch>0</verstretch>156 </sizepolicy>157 </property>158 <property name="whatsThis" >159 <string>Displays the MAC address of this adapter. It contains exactly 12 characters chosen from {0-9,A-F}. Note that the second character must be an even digit.</string>160 </property>161 </widget>162 </item>163 <item row="3" column="2" >164 <widget class="QPushButton" name="mPbMAC" >165 <property name="whatsThis" >166 <string>Generates a new random MAC address.</string>167 </property>168 <property name="text" >169 <string>&Generate</string>170 </property>171 </widget>172 </item>173 <item row="4" column="1" >174 <widget class="QCheckBox" name="mCbCable" >175 <property name="whatsThis" >176 <string>Indicates whether the virtual network cable is plugged in on machine startup or not.</string>177 </property>178 <property name="text" >179 <string>Ca&ble Connected</string>180 </property>181 </widget>182 </item>183 <item row="5" column="0" colspan="3" >184 <widget class="QILabelSeparator" name="mGbTap" >185 <property name="text" >186 <string>Host Interface Settings</string>187 </property>188 <property name="buddy" >189 <cstring>mLeInterface_x11</cstring>190 </property>191 </widget>192 </item>193 <item row="6" column="0" >194 <widget class="QLabel" name="mLbInterface_x11" >195 <property name="text" >196 <string>&Interface Name:</string>197 </property>198 <property name="alignment" >199 <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>200 </property>201 <property name="buddy" >202 <cstring>mLeInterface_x11</cstring>203 </property>204 </widget>205 </item>206 <item row="6" column="1" >207 <widget class="QLineEdit" name="mLeInterface_x11" >208 <property name="sizePolicy" >209 <sizepolicy vsizetype="Fixed" hsizetype="Preferred" >210 <horstretch>0</horstretch>211 <verstretch>0</verstretch>212 </sizepolicy>213 </property>214 <property name="whatsThis" >215 <string>Displays the TAP interface name.</string>216 131 </property> 217 132 </widget> … … 248 163 </layout> 249 164 </widget> 250 <customwidgets>251 <customwidget>252 <class>QILabelSeparator</class>253 <extends>QLabel</extends>254 <header>QILabelSeparator.h</header>255 </customwidget>256 </customwidgets>257 165 <resources/> 258 166 <connections>
Note:
See TracChangeset
for help on using the changeset viewer.