Changeset 67575 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jun 23, 2017 9:23:41 AM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 116329
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.cpp
r67452 r67575 23 23 # include <QCheckBox> 24 24 # include <QLabel> 25 # include <QPushButton> 25 26 # include <QRadioButton> 26 27 # include <QRegExpValidator> … … 29 30 30 31 /* GUI includes: */ 32 # include "QIDialogButtonBox.h" 31 33 # include "QILineEdit.h" 32 34 # include "QITabWidget.h" … … 42 44 43 45 44 UIHostNetworkDetailsDialog::UIHostNetworkDetailsDialog( QWidget *pParent /* = 0 */)46 UIHostNetworkDetailsDialog::UIHostNetworkDetailsDialog(EmbedTo enmEmbedding, QWidget *pParent /* = 0 */) 45 47 : QIWithRetranslateUI2<QWidget>(pParent) 48 , m_enmEmbedding(enmEmbedding) 46 49 , m_pTabWidget(0) 47 50 , m_pButtonAutomatic(0), m_pErrorPaneAutomatic(0) … … 51 54 , m_pLabelIPv6(0), m_pEditorIPv6(0), m_pErrorPaneIPv6(0) 52 55 , m_pLabelNMv6(0), m_pEditorNMv6(0), m_pErrorPaneNMv6(0) 56 , m_pButtonBoxInterface(0) 53 57 , m_pCheckBoxDHCP(0) 54 58 , m_pLabelDHCPAddress(0), m_pEditorDHCPAddress(0), m_pErrorPaneDHCPAddress(0) … … 56 60 , m_pLabelDHCPLowerAddress(0), m_pEditorDHCPLowerAddress(0), m_pErrorPaneDHCPLowerAddress(0) 57 61 , m_pLabelDHCPUpperAddress(0), m_pEditorDHCPUpperAddress(0), m_pErrorPaneDHCPUpperAddress(0) 62 , m_pButtonBoxServer(0) 58 63 { 59 64 /* Prepare: */ … … 102 107 m_pLabelNMv6->setText(tr("IPv6 Prefix &Length:")); 103 108 m_pEditorNMv6->setToolTip(tr("Holds the host IPv6 prefix length for this adapter if IPv6 is supported.")); 109 if (m_pButtonBoxInterface) 110 { 111 m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setText(tr("Reset")); 112 m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setText(tr("Apply")); 113 m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setShortcut(Qt::Key_Escape); 114 m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setShortcut(QString("Ctrl+Return")); 115 m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setStatusTip(tr("Reset changes in current interface details")); 116 m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setStatusTip(tr("Apply changes in current interface details")); 117 m_pButtonBoxInterface->button(QDialogButtonBox::Discard)-> 118 setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->shortcut().toString())); 119 m_pButtonBoxInterface->button(QDialogButtonBox::Apply)-> 120 setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->shortcut().toString())); 121 } 104 122 105 123 /* Translate 'DHCP server' tab content: */ … … 114 132 m_pLabelDHCPUpperAddress->setText(tr("&Upper Address Bound:")); 115 133 m_pEditorDHCPUpperAddress->setToolTip(tr("Holds the upper address bound offered by the DHCP server servicing the network associated with this host-only adapter.")); 134 if (m_pButtonBoxServer) 135 { 136 m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setText(tr("Reset")); 137 m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setText(tr("Apply")); 138 m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setShortcut(Qt::Key_Escape); 139 m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setShortcut(QString("Ctrl+Return")); 140 m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setStatusTip(tr("Reset changes in current DHCP server details")); 141 m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setStatusTip(tr("Apply changes in current DHCP server details")); 142 m_pButtonBoxServer->button(QDialogButtonBox::Discard)-> 143 setToolTip(tr("Reset Changes (%1)").arg(m_pButtonBoxServer->button(QDialogButtonBox::Discard)->shortcut().toString())); 144 m_pButtonBoxServer->button(QDialogButtonBox::Apply)-> 145 setToolTip(tr("Apply Changes (%1)").arg(m_pButtonBoxServer->button(QDialogButtonBox::Apply)->shortcut().toString())); 146 } 116 147 117 148 /* Retranslate validation: */ … … 124 155 loadDataForInterface(); 125 156 revalidate(); 126 notify();157 updateButtonStates(); 127 158 } 128 159 … … 132 163 loadDataForInterface(); 133 164 revalidate(); 134 notify();165 updateButtonStates(); 135 166 } 136 167 … … 139 170 m_newData.m_interface.m_strAddress = strText; 140 171 revalidate(m_pErrorPaneIPv4); 141 notify();172 updateButtonStates(); 142 173 } 143 174 … … 146 177 m_newData.m_interface.m_strMask = strText; 147 178 revalidate(m_pErrorPaneNMv4); 148 notify();179 updateButtonStates(); 149 180 } 150 181 … … 153 184 m_newData.m_interface.m_strAddress6 = strText; 154 185 revalidate(m_pErrorPaneIPv6); 155 notify();186 updateButtonStates(); 156 187 } 157 188 … … 160 191 m_newData.m_interface.m_strPrefixLength6 = strText; 161 192 revalidate(m_pErrorPaneNMv6); 162 notify();193 updateButtonStates(); 163 194 } 164 195 … … 168 199 loadDataForDHCPServer(); 169 200 revalidate(); 170 notify();201 updateButtonStates(); 171 202 } 172 203 … … 175 206 m_newData.m_dhcpserver.m_strAddress = strText; 176 207 revalidate(m_pErrorPaneDHCPAddress); 177 notify();208 updateButtonStates(); 178 209 } 179 210 … … 182 213 m_newData.m_dhcpserver.m_strMask = strText; 183 214 revalidate(m_pErrorPaneDHCPMask); 184 notify();215 updateButtonStates(); 185 216 } 186 217 … … 189 220 m_newData.m_dhcpserver.m_strLowerAddress = strText; 190 221 revalidate(m_pErrorPaneDHCPLowerAddress); 191 notify();222 updateButtonStates(); 192 223 } 193 224 … … 196 227 m_newData.m_dhcpserver.m_strUpperAddress = strText; 197 228 revalidate(m_pErrorPaneDHCPUpperAddress); 198 notify(); 229 updateButtonStates(); 230 } 231 232 void UIHostNetworkDetailsDialog::sltHandleButtonBoxClick(QAbstractButton *pButton) 233 { 234 /* Disable buttons first of all: */ 235 if (m_pButtonBoxInterface) 236 { 237 m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setEnabled(false); 238 m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setEnabled(false); 239 } 240 if (m_pButtonBoxServer) 241 { 242 m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setEnabled(false); 243 m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setEnabled(false); 244 } 245 246 /* Compare with known buttons: */ 247 if ( ( m_pButtonBoxInterface 248 && pButton == m_pButtonBoxInterface->button(QDialogButtonBox::Discard)) 249 || ( m_pButtonBoxServer 250 && pButton == m_pButtonBoxServer->button(QDialogButtonBox::Discard))) 251 emit sigDataChangeRejected(); 252 253 else 254 255 if ( ( m_pButtonBoxInterface 256 && pButton == m_pButtonBoxInterface->button(QDialogButtonBox::Apply)) 257 || ( m_pButtonBoxServer 258 && pButton == m_pButtonBoxServer->button(QDialogButtonBox::Apply))) 259 emit sigDataChangeAccepted(); 199 260 } 200 261 … … 206 267 /* Apply language settings: */ 207 268 retranslateUi(); 269 270 /* Update button states finally: */ 271 updateButtonStates(); 208 272 } 209 273 … … 508 572 pLayoutInterface->addItem(pSpacer2, 6, 0, 1, 3); 509 573 } 574 575 /* If parent embedded into stack: */ 576 if (m_enmEmbedding == EmbedTo_Stack) 577 { 578 /* Create button-box: */ 579 m_pButtonBoxInterface = new QIDialogButtonBox; 580 AssertPtrReturnVoid(m_pButtonBoxInterface); 581 /* Configure button-box: */ 582 m_pButtonBoxInterface->setStandardButtons(QDialogButtonBox::Discard | QDialogButtonBox::Apply); 583 connect(m_pButtonBoxInterface, &QIDialogButtonBox::clicked, this, &UIHostNetworkDetailsDialog::sltHandleButtonBoxClick); 584 585 /* Add into layout: */ 586 pLayoutInterface->addWidget(m_pButtonBoxInterface, 7, 0, 1, 3); 587 } 510 588 } 511 589 /* Add to tab-widget: */ … … 728 806 /* Add into layout: */ 729 807 pLayoutDHCPServer->addItem(pSpacer2, 5, 0, 1, 3); 808 } 809 810 /* If parent embedded into stack: */ 811 if (m_enmEmbedding == EmbedTo_Stack) 812 { 813 /* Create button-box: */ 814 m_pButtonBoxServer = new QIDialogButtonBox; 815 AssertPtrReturnVoid(m_pButtonBoxServer); 816 /* Configure button-box: */ 817 m_pButtonBoxServer->setStandardButtons(QDialogButtonBox::Discard | QDialogButtonBox::Apply); 818 connect(m_pButtonBoxServer, &QIDialogButtonBox::clicked, this, &UIHostNetworkDetailsDialog::sltHandleButtonBoxClick); 819 820 /* Add into layout: */ 821 pLayoutDHCPServer->addWidget(m_pButtonBoxServer, 6, 0, 1, 3); 730 822 } 731 823 } … … 922 1014 } 923 1015 924 void UIHostNetworkDetailsDialog:: notify()1016 void UIHostNetworkDetailsDialog::updateButtonStates() 925 1017 { 926 1018 // if (m_oldData != m_newData) … … 936 1028 // m_newData.m_dhcpserver.m_strUpperAddress.toUtf8().constData()); 937 1029 1030 /* Update 'Apply' / 'Reset' button states: */ 1031 if (m_pButtonBoxInterface) 1032 { 1033 m_pButtonBoxInterface->button(QDialogButtonBox::Discard)->setEnabled(m_oldData != m_newData); 1034 m_pButtonBoxInterface->button(QDialogButtonBox::Apply)->setEnabled(m_oldData != m_newData); 1035 } 1036 if (m_pButtonBoxServer) 1037 { 1038 m_pButtonBoxServer->button(QDialogButtonBox::Discard)->setEnabled(m_oldData != m_newData); 1039 m_pButtonBoxServer->button(QDialogButtonBox::Apply)->setEnabled(m_oldData != m_newData); 1040 } 1041 1042 /* Notify listeners as well: */ 938 1043 emit sigDataChanged(m_oldData != m_newData); 939 1044 } -
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkDetailsDialog.h
r67452 r67575 23 23 24 24 /* GUI includes: */ 25 #include "QIManagerDialog.h" 25 26 #include "QIWithRetranslateUI.h" 26 27 27 28 /* Forward declarations: */ 29 class QAbstractButton; 28 30 class QCheckBox; 29 31 class QLabel; 30 32 class QRadioButton; 33 class QIDialogButtonBox; 31 34 class QILineEdit; 32 35 class QITabWidget; … … 165 168 void sigDataChanged(bool fDiffers); 166 169 170 /** Notifies listeners about data change rejected and should be reseted. */ 171 void sigDataChangeRejected(); 172 /** Notifies listeners about data change accepted and should be applied. */ 173 void sigDataChangeAccepted(); 174 167 175 public: 168 176 169 177 /** Constructs host network details dialog for the passed @a pParent and @a data. */ 170 UIHostNetworkDetailsDialog( QWidget *pParent = 0);178 UIHostNetworkDetailsDialog(EmbedTo enmEmbedding, QWidget *pParent = 0); 171 179 172 180 /** Returns the host network data. */ … … 209 217 /** Handles DHCP server upper address text change. */ 210 218 void sltTextChangedUpperAddress(const QString &strText); 219 220 /** Handles button-box button click. */ 221 void sltHandleButtonBoxClick(QAbstractButton *pButton); 211 222 /** @} */ 212 223 … … 241 252 /** Retranslates validation for passed @a pWidget. */ 242 253 void retranslateValidation(QWidget *pWidget = 0); 243 /** Notifies listeners about data changed or not. */244 void notify();254 /** Updates button states. */ 255 void updateButtonStates(); 245 256 /** @} */ 246 257 247 258 /** @name General variables. 248 259 * @{ */ 260 /** Holds the parent widget embedding type. */ 261 const EmbedTo m_enmEmbedding; 262 249 263 /** Holds the old data copy. */ 250 264 UIDataHostNetwork m_oldData; … … 294 308 /** Holds the IPv6 network mask error pane. */ 295 309 QLabel *m_pErrorPaneNMv6; 310 311 /** Holds the interface button-box instance. */ 312 QIDialogButtonBox *m_pButtonBoxInterface; 296 313 /** @} */ 297 314 … … 328 345 /** Holds the DHCP upper address error pane. */ 329 346 QLabel *m_pErrorPaneDHCPUpperAddress; 347 348 /** Holds the server button-box instance. */ 349 QIDialogButtonBox *m_pButtonBoxServer; 330 350 /** @} */ 331 351 }; -
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.cpp
r67573 r67575 198 198 , m_pActionRemove(0) 199 199 , m_pActionDetails(0) 200 , m_pActionCommit(0)201 200 , m_pTreeWidget(0) 202 201 , m_pDetailsWidget(0) … … 230 229 m_pActionDetails->setToolTip(UIHostNetworkManager::tr("Open Host-only Network Details (%1)").arg(m_pActionDetails->shortcut().toString())); 231 230 m_pActionDetails->setStatusTip(UIHostNetworkManager::tr("Open pane with the selected host-only network details")); 232 }233 if (m_pActionCommit)234 {235 m_pActionCommit->setText(UIHostNetworkManager::tr("&Apply..."));236 m_pActionCommit->setToolTip(UIHostNetworkManager::tr("Apply Changes in Host-only Network Details (%1)").arg(m_pActionCommit->shortcut().toString()));237 m_pActionCommit->setStatusTip(UIHostNetworkManager::tr("Apply changes in host-only network details pane"));238 231 } 239 232 … … 276 269 } 277 270 278 void UIHostNetworkManagerWidget::sltAddHostNetwork() 279 { 280 /* Get host for further activities: */ 281 CHost comHost = vboxGlobal().host(); 282 283 /* Create interface: */ 284 CHostNetworkInterface comInterface; 285 CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface); 286 287 /* Show error message if necessary: */ 288 if (!comHost.isOk() || progress.isNull()) 289 msgCenter().cannotCreateHostNetworkInterface(comHost, this); 290 else 291 { 292 /* Show interface creation progress: */ 293 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 294 295 /* Show error message if necessary: */ 296 if (!progress.isOk() || progress.GetResultCode() != 0) 297 msgCenter().cannotCreateHostNetworkInterface(progress, this); 298 else 299 { 300 /* Get network name for further activities: */ 301 const QString strNetworkName = comInterface.GetNetworkName(); 302 303 /* Show error message if necessary: */ 304 if (!comInterface.isOk()) 305 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 306 else 307 { 308 /* Get VBox for further activities: */ 309 CVirtualBox comVBox = vboxGlobal().virtualBox(); 310 311 /* Find corresponding DHCP server (create if necessary): */ 312 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 313 if (!comVBox.isOk() || comServer.isNull()) 314 comServer = comVBox.CreateDHCPServer(strNetworkName); 315 316 /* Show error message if necessary: */ 317 if (!comVBox.isOk() || comServer.isNull()) 318 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 319 } 320 321 /* Add interface to the tree: */ 322 UIDataHostNetwork data; 323 loadHostNetwork(comInterface, data); 324 createItemForNetworkHost(data, true); 325 326 /* Adjust tree-widget: */ 327 sltAdjustTreeWidget(); 328 } 329 } 330 } 331 332 void UIHostNetworkManagerWidget::sltRemoveHostNetwork() 333 { 334 /* Get network item: */ 335 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 336 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 337 338 /* Get interface name: */ 339 const QString strInterfaceName(pItem->name()); 340 341 /* Confirm host network removal: */ 342 if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this)) 343 return; 344 345 /* Get host for further activities: */ 346 CHost comHost = vboxGlobal().host(); 347 348 /* Find corresponding interface: */ 349 const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName); 350 351 /* Show error message if necessary: */ 352 if (!comHost.isOk() || comInterface.isNull()) 353 msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this); 354 else 355 { 356 /* Get network name for further activities: */ 357 QString strNetworkName; 358 if (comInterface.isOk()) 359 strNetworkName = comInterface.GetNetworkName(); 360 /* Get interface id for further activities: */ 361 QString strInterfaceId; 362 if (comInterface.isOk()) 363 strInterfaceId = comInterface.GetId(); 364 365 /* Show error message if necessary: */ 366 if (!comInterface.isOk()) 367 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 368 else 369 { 370 /* Get VBox for further activities: */ 371 CVirtualBox comVBox = vboxGlobal().virtualBox(); 372 373 /* Find corresponding DHCP server: */ 374 const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 375 if (comVBox.isOk() && comServer.isNotNull()) 376 { 377 /* Remove server if any: */ 378 comVBox.RemoveDHCPServer(comServer); 379 380 /* Show error message if necessary: */ 381 if (!comVBox.isOk()) 382 msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this); 383 } 384 385 /* Remove interface finally: */ 386 CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId); 387 388 /* Show error message if necessary: */ 389 if (!comHost.isOk() || progress.isNull()) 390 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this); 391 else 392 { 393 /* Show interface removal progress: */ 394 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 395 396 /* Show error message if necessary: */ 397 if (!progress.isOk() || progress.GetResultCode() != 0) 398 return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this); 399 else 400 { 401 /* Remove interface from the tree: */ 402 delete pItem; 403 404 /* Adjust tree-widget: */ 405 sltAdjustTreeWidget(); 406 } 407 } 408 } 409 } 410 } 411 412 void UIHostNetworkManagerWidget::sltToggleHostNetworkDetailsVisibility(bool fVisible) 413 { 414 /* Show/hide details area and Apply button: */ 415 m_pDetailsWidget->setVisible(fVisible); 416 m_pActionCommit->setVisible(fVisible); 417 } 418 419 void UIHostNetworkManagerWidget::sltCommitHostNetworkDetailsChanges() 420 { 421 /* Disable button first of all: */ 422 m_pActionCommit->setEnabled(false); 423 271 void UIHostNetworkManagerWidget::sltResetHostNetworkDetailsChanges() 272 { 273 /* Just push the current item data there again: */ 274 sltHandleCurrentItemChange(); 275 } 276 277 void UIHostNetworkManagerWidget::sltApplyHostNetworkDetailsChanges() 278 { 424 279 /* Get network item: */ 425 280 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); … … 540 395 } 541 396 397 void UIHostNetworkManagerWidget::sltAddHostNetwork() 398 { 399 /* Get host for further activities: */ 400 CHost comHost = vboxGlobal().host(); 401 402 /* Create interface: */ 403 CHostNetworkInterface comInterface; 404 CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface); 405 406 /* Show error message if necessary: */ 407 if (!comHost.isOk() || progress.isNull()) 408 msgCenter().cannotCreateHostNetworkInterface(comHost, this); 409 else 410 { 411 /* Show interface creation progress: */ 412 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 413 414 /* Show error message if necessary: */ 415 if (!progress.isOk() || progress.GetResultCode() != 0) 416 msgCenter().cannotCreateHostNetworkInterface(progress, this); 417 else 418 { 419 /* Get network name for further activities: */ 420 const QString strNetworkName = comInterface.GetNetworkName(); 421 422 /* Show error message if necessary: */ 423 if (!comInterface.isOk()) 424 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 425 else 426 { 427 /* Get VBox for further activities: */ 428 CVirtualBox comVBox = vboxGlobal().virtualBox(); 429 430 /* Find corresponding DHCP server (create if necessary): */ 431 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 432 if (!comVBox.isOk() || comServer.isNull()) 433 comServer = comVBox.CreateDHCPServer(strNetworkName); 434 435 /* Show error message if necessary: */ 436 if (!comVBox.isOk() || comServer.isNull()) 437 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 438 } 439 440 /* Add interface to the tree: */ 441 UIDataHostNetwork data; 442 loadHostNetwork(comInterface, data); 443 createItemForNetworkHost(data, true); 444 445 /* Adjust tree-widget: */ 446 sltAdjustTreeWidget(); 447 } 448 } 449 } 450 451 void UIHostNetworkManagerWidget::sltRemoveHostNetwork() 452 { 453 /* Get network item: */ 454 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 455 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 456 457 /* Get interface name: */ 458 const QString strInterfaceName(pItem->name()); 459 460 /* Confirm host network removal: */ 461 if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this)) 462 return; 463 464 /* Get host for further activities: */ 465 CHost comHost = vboxGlobal().host(); 466 467 /* Find corresponding interface: */ 468 const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName); 469 470 /* Show error message if necessary: */ 471 if (!comHost.isOk() || comInterface.isNull()) 472 msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this); 473 else 474 { 475 /* Get network name for further activities: */ 476 QString strNetworkName; 477 if (comInterface.isOk()) 478 strNetworkName = comInterface.GetNetworkName(); 479 /* Get interface id for further activities: */ 480 QString strInterfaceId; 481 if (comInterface.isOk()) 482 strInterfaceId = comInterface.GetId(); 483 484 /* Show error message if necessary: */ 485 if (!comInterface.isOk()) 486 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 487 else 488 { 489 /* Get VBox for further activities: */ 490 CVirtualBox comVBox = vboxGlobal().virtualBox(); 491 492 /* Find corresponding DHCP server: */ 493 const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 494 if (comVBox.isOk() && comServer.isNotNull()) 495 { 496 /* Remove server if any: */ 497 comVBox.RemoveDHCPServer(comServer); 498 499 /* Show error message if necessary: */ 500 if (!comVBox.isOk()) 501 msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this); 502 } 503 504 /* Remove interface finally: */ 505 CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId); 506 507 /* Show error message if necessary: */ 508 if (!comHost.isOk() || progress.isNull()) 509 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this); 510 else 511 { 512 /* Show interface removal progress: */ 513 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 514 515 /* Show error message if necessary: */ 516 if (!progress.isOk() || progress.GetResultCode() != 0) 517 return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this); 518 else 519 { 520 /* Remove interface from the tree: */ 521 delete pItem; 522 523 /* Adjust tree-widget: */ 524 sltAdjustTreeWidget(); 525 } 526 } 527 } 528 } 529 } 530 531 void UIHostNetworkManagerWidget::sltToggleHostNetworkDetailsVisibility(bool fVisible) 532 { 533 /* Show/hide details area and Apply button: */ 534 m_pDetailsWidget->setVisible(fVisible); 535 /* Notify external lsiteners: */ 536 emit sigHostNetworkDetailsVisibilityChanged(fVisible); 537 } 538 542 539 void UIHostNetworkManagerWidget::sltAdjustTreeWidget() 543 540 { … … 658 655 if (m_pActionDetails) 659 656 m_pActionDetails->setEnabled(pItem); 660 if (m_pActionCommit)661 m_pActionCommit->setEnabled(false);662 657 663 658 /* If there is an item => update details data: */ … … 682 677 if (m_pActionDetails) 683 678 menu.addAction(m_pActionDetails); 684 if (m_pActionCommit)685 menu.addAction(m_pActionCommit);686 679 } 687 680 else … … 756 749 } 757 750 758 /* Create 'Apply' action: */759 m_pActionCommit = new QAction(this);760 AssertPtrReturnVoid(m_pActionCommit);761 {762 /* Configure 'Apply' action: */763 m_pActionCommit->setVisible(false);764 m_pActionCommit->setShortcut(QKeySequence("Ctrl+Return"));765 m_pActionCommit->setIcon(UIIconPool::iconSetFull(":/commit_host_iface_22px.png",766 ":/commit_host_iface_16px.png",767 ":/commit_host_iface_disabled_22px.png",768 ":/commit_host_iface_disabled_16px.png"));769 if (m_pActionDetails)770 connect(m_pActionDetails, &QAction::toggled, m_pActionCommit, &QAction::setVisible);771 connect(m_pActionCommit, &QAction::triggered, this, &UIHostNetworkManagerWidget::sltCommitHostNetworkDetailsChanges);772 }773 774 751 /* Prepare menu: */ 775 752 prepareMenu(); … … 789 766 if (m_pActionDetails) 790 767 m_pMenu->addAction(m_pActionDetails); 791 if (m_pActionCommit)792 m_pMenu->addAction(m_pActionCommit);793 768 } 794 769 } … … 832 807 if (m_pActionRemove) 833 808 m_pToolBar->addAction(m_pActionRemove); 834 if ((m_pActionAdd || m_pActionRemove) && (m_pActionDetails || m_pActionCommit))809 if ((m_pActionAdd || m_pActionRemove) && m_pActionDetails) 835 810 m_pToolBar->addSeparator(); 836 811 if (m_pActionDetails) 837 812 m_pToolBar->addAction(m_pActionDetails); 838 if (m_pActionCommit)839 m_pToolBar->addAction(m_pActionCommit);840 813 #ifdef VBOX_WS_MAC 841 814 /* Check whether we are embedded into a stack: */ … … 885 858 { 886 859 /* Create details-widget: */ 887 m_pDetailsWidget = new UIHostNetworkDetailsDialog ;860 m_pDetailsWidget = new UIHostNetworkDetailsDialog(m_enmEmbedding); 888 861 AssertPtrReturnVoid(m_pDetailsWidget); 889 862 { … … 891 864 m_pDetailsWidget->setVisible(false); 892 865 m_pDetailsWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); 893 if (m_pActionCommit) 894 connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChanged, 895 m_pActionCommit, &QAction::setEnabled); 866 connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChanged, 867 this, &UIHostNetworkManagerWidget::sigHostNetworkDetailsDataChanged); 868 connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChangeRejected, 869 this, &UIHostNetworkManagerWidget::sltResetHostNetworkDetailsChanges); 870 connect(m_pDetailsWidget, &UIHostNetworkDetailsDialog::sigDataChangeAccepted, 871 this, &UIHostNetworkManagerWidget::sltApplyHostNetworkDetailsChanges); 896 872 897 873 /* Add into layout: */ … … 1043 1019 } 1044 1020 1021 void UIHostNetworkManager::sltHandleButtonBoxClick(QAbstractButton *pButton) 1022 { 1023 /* Disable buttons first of all: */ 1024 buttonBox()->button(QDialogButtonBox::Reset)->setEnabled(false); 1025 buttonBox()->button(QDialogButtonBox::Save)->setEnabled(false); 1026 1027 /* Compare with known buttons: */ 1028 if (pButton == buttonBox()->button(QDialogButtonBox::Reset)) 1029 emit sigDataChangeRejected(); 1030 1031 else 1032 1033 if (pButton == buttonBox()->button(QDialogButtonBox::Save)) 1034 emit sigDataChangeAccepted(); 1035 } 1036 1045 1037 void UIHostNetworkManager::retranslateUi() 1046 1038 { 1047 1039 /* Translate window title: */ 1048 1040 setWindowTitle(tr("Host Network Manager")); 1041 1042 /* Translate buttons: */ 1043 buttonBox()->button(QDialogButtonBox::Reset)->setText(tr("Reset")); 1044 buttonBox()->button(QDialogButtonBox::Save)->setText(tr("Apply")); 1045 buttonBox()->button(QDialogButtonBox::Close)->setText(tr("Close")); 1046 buttonBox()->button(QDialogButtonBox::Reset)->setStatusTip(tr("Reset changes in current host network details")); 1047 buttonBox()->button(QDialogButtonBox::Save)->setStatusTip(tr("Apply changes in current host network details")); 1048 buttonBox()->button(QDialogButtonBox::Close)->setStatusTip(tr("Close dialog without saving")); 1049 buttonBox()->button(QDialogButtonBox::Reset)->setShortcut(QString("Ctrl+Backspace")); 1050 buttonBox()->button(QDialogButtonBox::Save)->setShortcut(QString("Ctrl+Return")); 1051 //buttonBox()->button(QDialogButtonBox::Close)->setShortcut(Qt::Key_Escape); /* done in base-class */ 1052 buttonBox()->button(QDialogButtonBox::Reset)-> 1053 setToolTip(tr("Reset Changes (%1)").arg(buttonBox()->button(QDialogButtonBox::Reset)->shortcut().toString())); 1054 buttonBox()->button(QDialogButtonBox::Save)-> 1055 setToolTip(tr("Apply Changes (%1)").arg(buttonBox()->button(QDialogButtonBox::Save)->shortcut().toString())); 1056 buttonBox()->button(QDialogButtonBox::Close)-> 1057 setToolTip(tr("Close Window (%1)").arg(buttonBox()->button(QDialogButtonBox::Close)->shortcut().toString())); 1049 1058 } 1050 1059 … … 1067 1076 setWidgetToolbar(pWidget->toolbar()); 1068 1077 #endif 1078 connect(this, &UIHostNetworkManager::sigDataChangeRejected, 1079 pWidget, &UIHostNetworkManagerWidget::sltResetHostNetworkDetailsChanges); 1080 connect(this, &UIHostNetworkManager::sigDataChangeAccepted, 1081 pWidget, &UIHostNetworkManagerWidget::sltApplyHostNetworkDetailsChanges); 1082 1069 1083 /* Add into layout: */ 1070 1084 centralWidget()->layout()->addWidget(pWidget); … … 1072 1086 } 1073 1087 1088 void UIHostNetworkManager::configureButtonBox() 1089 { 1090 /* Configure button-box: */ 1091 connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsVisibilityChanged, 1092 buttonBox()->button(QDialogButtonBox::Save), &QPushButton::setVisible); 1093 connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsVisibilityChanged, 1094 buttonBox()->button(QDialogButtonBox::Reset), &QPushButton::setVisible); 1095 connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsDataChanged, 1096 buttonBox()->button(QDialogButtonBox::Save), &QPushButton::setEnabled); 1097 connect(widget(), &UIHostNetworkManagerWidget::sigHostNetworkDetailsDataChanged, 1098 buttonBox()->button(QDialogButtonBox::Reset), &QPushButton::setEnabled); 1099 connect(buttonBox(), &QIDialogButtonBox::clicked, 1100 this, &UIHostNetworkManager::sltHandleButtonBoxClick); 1101 } 1102 1074 1103 void UIHostNetworkManager::finalize() 1075 1104 { -
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.h
r67573 r67575 43 43 Q_OBJECT; 44 44 45 signals: 46 47 /** Notifies listeners about host network details widget @a fVisible. */ 48 void sigHostNetworkDetailsVisibilityChanged(bool fVisible); 49 /** Notifies listeners about host network details data @a fDiffers. */ 50 void sigHostNetworkDetailsDataChanged(bool fDiffers); 51 45 52 public: 46 53 … … 68 75 /** Handles show @a pEvent. */ 69 76 virtual void showEvent(QShowEvent *pEvent) /* override */; 77 /** @} */ 78 79 public slots: 80 81 /** @name Menu/action stuff. 82 * @{ */ 83 /** Handles command to reset host network details changes. */ 84 void sltResetHostNetworkDetailsChanges(); 85 /** Handles command to apply host network details changes. */ 86 void sltApplyHostNetworkDetailsChanges(); 70 87 /** @} */ 71 88 … … 80 97 /** Handles command to make host network details @a fVisible. */ 81 98 void sltToggleHostNetworkDetailsVisibility(bool fVisible); 82 /** Handles command to commit host network details changes. */83 void sltCommitHostNetworkDetailsChanges();84 99 /** @} */ 85 100 … … 153 168 /** Holds the Details action instance. */ 154 169 QAction *m_pActionDetails; 155 /** Holds the Commit action instance. */156 QAction *m_pActionCommit;157 170 /** @} */ 158 171 … … 183 196 Q_OBJECT; 184 197 185 protected: 198 signals: 199 200 /** Notifies listeners about data change rejected and should be reseted. */ 201 void sigDataChangeRejected(); 202 /** Notifies listeners about data change accepted and should be applied. */ 203 void sigDataChangeAccepted(); 204 205 private slots: 206 207 /** @name Button-box stuff. 208 * @{ */ 209 /** Handles button-box button click. */ 210 void sltHandleButtonBoxClick(QAbstractButton *pButton); 211 /** @} */ 212 213 private: 186 214 187 215 /** Constructs Host Network Manager dialog. … … 201 229 /** Configures central-widget. */ 202 230 virtual void configureCentralWidget() /* override */; 231 /** Configures button-box. */ 232 virtual void configureButtonBox() /* override */; 203 233 /** Perform final preparations. */ 204 234 virtual void finalize() /* override */;
Note:
See TracChangeset
for help on using the changeset viewer.