- Timestamp:
- Dec 14, 2020 6:09:21 PM (4 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/networkmanager
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.cpp
r87088 r87089 24 24 /* GUI includes: */ 25 25 #include "QIDialogButtonBox.h" 26 #include "QITabWidget.h" 26 27 #include "QITreeWidget.h" 27 28 #include "UIActionPoolManager.h" … … 58 59 59 60 60 /** Host Network Manager: Tree-widget item. */61 /** Network Manager: Host Network tree-widget item. */ 61 62 class UIItemHostNetwork : public QITreeWidgetItem, public UIDataHostNetwork 62 63 { … … 196 197 , m_fShowToolbar(fShowToolbar) 197 198 , m_pToolBar(0) 198 , m_pTreeWidget(0) 199 , m_pDetailsWidget(0) 199 , m_pTabWidget(0) 200 , m_pTabHostNetwork(0) 201 , m_pLayoutHostNetwork(0) 202 , m_pTreeWidgetHostNetwork(0) 203 , m_pDetailsWidgetHostNetwork(0) 200 204 { 201 205 prepare(); … … 221 225 #endif 222 226 223 /* Translate tree-widget: */ 224 if (m_pTreeWidget) 227 /* Translate tab-widget: */ 228 if (m_pTabWidget) 229 m_pTabWidget->setTabText(0, UINetworkManager::tr("Host-only Networks")); 230 231 /* Translate host network tree-widget: */ 232 if (m_pTreeWidgetHostNetwork) 225 233 { 226 234 const QStringList fields = QStringList() … … 229 237 << UINetworkManager::tr("IPv6 Address/Mask") 230 238 << UINetworkManager::tr("DHCP Server"); 231 m_pTreeWidget ->setHeaderLabels(fields);239 m_pTreeWidgetHostNetwork->setHeaderLabels(fields); 232 240 } 233 241 } … … 238 246 QIWithRetranslateUI<QWidget>::resizeEvent(pEvent); 239 247 240 /* Adjust tree-widget : */241 sltAdjustTreeWidget ();248 /* Adjust tree-widgets: */ 249 sltAdjustTreeWidgets(); 242 250 } 243 251 … … 247 255 QIWithRetranslateUI<QWidget>::showEvent(pEvent); 248 256 249 /* Adjust tree-widget: */ 250 sltAdjustTreeWidget(); 251 } 252 253 void UINetworkManagerWidget::sltResetHostNetworkDetailsChanges() 254 { 257 /* Adjust tree-widgets: */ 258 sltAdjustTreeWidgets(); 259 } 260 261 void UINetworkManagerWidget::sltResetDetailsChanges() 262 { 263 /* Check tab-widget: */ 264 AssertMsgReturnVoid(m_pTabWidget, ("This action should not be allowed!\n")); 265 255 266 /* Just push current item data to details-widget again: */ 256 sltHandleCurrentItemChange(); 257 } 258 259 void UINetworkManagerWidget::sltApplyHostNetworkDetailsChanges() 260 { 261 /* Check tree-widget: */ 262 AssertMsgReturnVoid(m_pTreeWidget, ("Tree-widget isn't created!\n")); 263 264 /* Get network item: */ 265 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 266 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 267 268 /* Check details-widget: */ 269 AssertMsgReturnVoid(m_pDetailsWidget, ("Details-widget isn't created!\n")); 270 271 /* Get item data: */ 272 UIDataHostNetwork oldData = *pItem; 273 UIDataHostNetwork newData = m_pDetailsWidget->data(); 274 267 switch (m_pTabWidget->currentIndex()) 268 { 269 case 0: 270 { 271 sltHandleCurrentItemChangeHostNetwork(); 272 break; 273 } 274 default: 275 break; 276 } 277 } 278 279 void UINetworkManagerWidget::sltApplyDetailsChanges() 280 { 281 /* Check tab-widget: */ 282 AssertMsgReturnVoid(m_pTabWidget, ("This action should not be allowed!\n")); 283 284 /* Apply details-widget data changes: */ 285 switch (m_pTabWidget->currentIndex()) 286 { 287 case 0: 288 { 289 sltApplyDetailsChangesHostNetwork(); 290 break; 291 } 292 default: 293 break; 294 } 295 } 296 297 void UINetworkManagerWidget::sltCreateHostNetwork() 298 { 275 299 /* Get host for further activities: */ 276 300 CHost comHost = uiCommon().host(); 277 301 278 /* Find corresponding interface: */ 279 CHostNetworkInterface comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName); 302 /* Create interface: */ 303 CHostNetworkInterface comInterface; 304 CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface); 280 305 281 306 /* Show error message if necessary: */ 282 if (!comHost.isOk() || comInterface.isNull())283 msgCenter().cannot FindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this);307 if (!comHost.isOk() || progress.isNull()) 308 msgCenter().cannotCreateHostNetworkInterface(comHost, this); 284 309 else 285 310 { 286 /* Save automatic interface configuration: */ 287 if (newData.m_interface.m_fDHCPEnabled) 288 { 289 if ( comInterface.isOk() 290 && !oldData.m_interface.m_fDHCPEnabled) 291 comInterface.EnableDynamicIPConfig(); 292 } 293 /* Save manual interface configuration: */ 294 else 295 { 296 /* Save IPv4 interface configuration: */ 297 if ( comInterface.isOk() 298 && ( oldData.m_interface.m_fDHCPEnabled 299 || newData.m_interface.m_strAddress != oldData.m_interface.m_strAddress 300 || newData.m_interface.m_strMask != oldData.m_interface.m_strMask)) 301 comInterface.EnableStaticIPConfig(newData.m_interface.m_strAddress, newData.m_interface.m_strMask); 302 /* Save IPv6 interface configuration: */ 303 if ( comInterface.isOk() 304 && newData.m_interface.m_fSupportedIPv6 305 && ( oldData.m_interface.m_fDHCPEnabled 306 || newData.m_interface.m_strAddress6 != oldData.m_interface.m_strAddress6 307 || newData.m_interface.m_strPrefixLength6 != oldData.m_interface.m_strPrefixLength6)) 308 comInterface.EnableStaticIPConfigV6(newData.m_interface.m_strAddress6, newData.m_interface.m_strPrefixLength6.toULong()); 309 } 311 /* Show interface creation progress: */ 312 msgCenter().showModalProgressDialog(progress, UINetworkManager::tr("Adding network ..."), ":/progress_network_interface_90px.png", this, 0); 310 313 311 314 /* Show error message if necessary: */ 312 if (! comInterface.isOk())313 msgCenter().cannot SaveHostNetworkInterfaceParameter(comInterface, this);315 if (!progress.isOk() || progress.GetResultCode() != 0) 316 msgCenter().cannotCreateHostNetworkInterface(progress, this); 314 317 else 315 318 { … … 333 336 if (!comVBox.isOk() || comServer.isNull()) 334 337 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 335 else336 {337 /* Save whether DHCP server is enabled: */338 if ( comServer.isOk()339 && newData.m_dhcpserver.m_fEnabled != oldData.m_dhcpserver.m_fEnabled)340 comServer.SetEnabled(newData.m_dhcpserver.m_fEnabled);341 /* Save DHCP server configuration: */342 if ( comServer.isOk()343 && newData.m_dhcpserver.m_fEnabled344 && ( newData.m_dhcpserver.m_strAddress != oldData.m_dhcpserver.m_strAddress345 || newData.m_dhcpserver.m_strMask != oldData.m_dhcpserver.m_strMask346 || newData.m_dhcpserver.m_strLowerAddress != oldData.m_dhcpserver.m_strLowerAddress347 || newData.m_dhcpserver.m_strUpperAddress != oldData.m_dhcpserver.m_strUpperAddress))348 comServer.SetConfiguration(newData.m_dhcpserver.m_strAddress, newData.m_dhcpserver.m_strMask,349 newData.m_dhcpserver.m_strLowerAddress, newData.m_dhcpserver.m_strUpperAddress);350 351 /* Show error message if necessary: */352 if (!comServer.isOk())353 msgCenter().cannotSaveDHCPServerParameter(comServer, this);354 }355 }356 }357 358 /* Find corresponding interface again (if necessary): */359 if (!comInterface.isOk())360 {361 comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName);362 363 /* Show error message if necessary: */364 if (!comHost.isOk() || comInterface.isNull())365 msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this);366 }367 368 /* If interface is Ok now: */369 if (comInterface.isNotNull() && comInterface.isOk())370 {371 /* Update interface in the tree: */372 UIDataHostNetwork data;373 loadHostNetwork(comInterface, data);374 updateItemForNetworkHost(data, true, pItem);375 376 /* Make sure current item fetched: */377 sltHandleCurrentItemChange();378 379 /* Adjust tree-widget: */380 sltAdjustTreeWidget();381 }382 }383 }384 385 void UINetworkManagerWidget::sltCreateHostNetwork()386 {387 /* Get host for further activities: */388 CHost comHost = uiCommon().host();389 390 /* Create interface: */391 CHostNetworkInterface comInterface;392 CProgress progress = comHost.CreateHostOnlyNetworkInterface(comInterface);393 394 /* Show error message if necessary: */395 if (!comHost.isOk() || progress.isNull())396 msgCenter().cannotCreateHostNetworkInterface(comHost, this);397 else398 {399 /* Show interface creation progress: */400 msgCenter().showModalProgressDialog(progress, UINetworkManager::tr("Adding network ..."), ":/progress_network_interface_90px.png", this, 0);401 402 /* Show error message if necessary: */403 if (!progress.isOk() || progress.GetResultCode() != 0)404 msgCenter().cannotCreateHostNetworkInterface(progress, this);405 else406 {407 /* Get network name for further activities: */408 const QString strNetworkName = comInterface.GetNetworkName();409 410 /* Show error message if necessary: */411 if (!comInterface.isOk())412 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);413 else414 {415 /* Get VBox for further activities: */416 CVirtualBox comVBox = uiCommon().virtualBox();417 418 /* Find corresponding DHCP server (create if necessary): */419 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);420 if (!comVBox.isOk() || comServer.isNull())421 comServer = comVBox.CreateDHCPServer(strNetworkName);422 423 /* Show error message if necessary: */424 if (!comVBox.isOk() || comServer.isNull())425 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this);426 338 } 427 339 … … 431 343 createItemForNetworkHost(data, true); 432 344 433 /* Adjust tree-widget : */434 sltAdjustTreeWidget ();345 /* Adjust tree-widgets: */ 346 sltAdjustTreeWidgets(); 435 347 } 436 348 } … … 439 351 void UINetworkManagerWidget::sltRemoveHostNetwork() 440 352 { 441 /* Check tree-widget: */442 AssertMsgReturnVoid(m_pTreeWidget , ("Tree-widget isn't created!\n"));353 /* Check host network tree-widget: */ 354 AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n")); 443 355 444 356 /* Get network item: */ 445 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget ->currentItem());357 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidgetHostNetwork->currentItem()); 446 358 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 447 359 … … 512 424 delete pItem; 513 425 514 /* Adjust tree-widget : */515 sltAdjustTreeWidget ();426 /* Adjust tree-widgets: */ 427 sltAdjustTreeWidgets(); 516 428 } 517 429 } … … 520 432 } 521 433 522 void UINetworkManagerWidget::sltToggle HostNetworkDetailsVisibility(bool fVisible)434 void UINetworkManagerWidget::sltToggleDetailsVisibilityHostNetwork(bool fVisible) 523 435 { 524 436 /* Save the setting: */ 525 437 gEDataManager->setHostNetworkManagerDetailsExpanded(fVisible); 526 438 /* Show/hide details area and Apply button: */ 527 if (m_pDetailsWidget )528 m_pDetailsWidget ->setVisible(fVisible);439 if (m_pDetailsWidgetHostNetwork) 440 m_pDetailsWidgetHostNetwork->setVisible(fVisible); 529 441 /* Notify external listeners: */ 530 emit sig HostNetworkDetailsVisibilityChanged(fVisible);442 emit sigDetailsVisibilityChangedHostNetwork(fVisible); 531 443 } 532 444 … … 537 449 } 538 450 539 void UINetworkManagerWidget::sltAdjustTreeWidget ()540 { 541 /* Check tree-widget: */542 if (m_pTreeWidget )451 void UINetworkManagerWidget::sltAdjustTreeWidgets() 452 { 453 /* Check host network tree-widget: */ 454 if (m_pTreeWidgetHostNetwork) 543 455 { 544 456 /* Get the tree-widget abstract interface: */ 545 QAbstractItemView *pItemView = m_pTreeWidget ;457 QAbstractItemView *pItemView = m_pTreeWidgetHostNetwork; 546 458 /* Get the tree-widget header-view: */ 547 QHeaderView *pItemHeader = m_pTreeWidget ->header();459 QHeaderView *pItemHeader = m_pTreeWidgetHostNetwork->header(); 548 460 549 461 /* Calculate the total tree-widget width: */ 550 const int iTotal = m_pTreeWidget ->viewport()->width();462 const int iTotal = m_pTreeWidgetHostNetwork->viewport()->width(); 551 463 /* Look for a minimum width hints for non-important columns: */ 552 464 const int iMinWidth1 = qMax(pItemView->sizeHintForColumn(Column_IPv4), pItemHeader->sectionSizeHint(Column_IPv4)); … … 558 470 const int iWidth3 = iMinWidth3 < iTotal / Column_Max ? iMinWidth3 : iTotal / Column_Max; 559 471 /* Apply the proposal: */ 560 m_pTreeWidget ->setColumnWidth(Column_IPv4, iWidth1);561 m_pTreeWidget ->setColumnWidth(Column_IPv6, iWidth2);562 m_pTreeWidget ->setColumnWidth(Column_DHCP, iWidth3);563 m_pTreeWidget ->setColumnWidth(Column_Name, iTotal - iWidth1 - iWidth2 - iWidth3);564 } 565 } 566 567 void UINetworkManagerWidget::sltHandleItemChange (QTreeWidgetItem *pItem)472 m_pTreeWidgetHostNetwork->setColumnWidth(Column_IPv4, iWidth1); 473 m_pTreeWidgetHostNetwork->setColumnWidth(Column_IPv6, iWidth2); 474 m_pTreeWidgetHostNetwork->setColumnWidth(Column_DHCP, iWidth3); 475 m_pTreeWidgetHostNetwork->setColumnWidth(Column_Name, iTotal - iWidth1 - iWidth2 - iWidth3); 476 } 477 } 478 479 void UINetworkManagerWidget::sltHandleItemChangeHostNetwork(QTreeWidgetItem *pItem) 568 480 { 569 481 /* Get network item: */ … … 639 551 640 552 /* Make sure current item fetched: */ 641 sltHandleCurrentItemChange ();642 643 /* Adjust tree-widget : */644 sltAdjustTreeWidget ();553 sltHandleCurrentItemChangeHostNetwork(); 554 555 /* Adjust tree-widgets: */ 556 sltAdjustTreeWidgets(); 645 557 } 646 558 } … … 649 561 } 650 562 651 void UINetworkManagerWidget::sltHandleCurrentItemChange ()652 { 653 /* Check tree-widget: */654 AssertMsgReturnVoid(m_pTreeWidget , ("Tree-widget isn't created!\n"));563 void UINetworkManagerWidget::sltHandleCurrentItemChangeHostNetwork() 564 { 565 /* Check host network tree-widget: */ 566 AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n")); 655 567 656 568 /* Get network item: */ 657 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget ->currentItem());569 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidgetHostNetwork->currentItem()); 658 570 659 571 /* Update actions availability: */ … … 661 573 m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setEnabled(pItem); 662 574 663 /* Check details-widget: */664 AssertMsgReturnVoid(m_pDetailsWidget , ("Details-widget isn't created!\n"));575 /* Check host network details-widget: */ 576 AssertMsgReturnVoid(m_pDetailsWidgetHostNetwork, ("Host network details-widget isn't created!\n")); 665 577 666 578 /* If there is an item => update details data: */ 667 579 if (pItem) 668 m_pDetailsWidget ->setData(*pItem);580 m_pDetailsWidgetHostNetwork->setData(*pItem); 669 581 else 670 582 { 671 583 /* Otherwise => clear details and close the area: */ 672 m_pDetailsWidget ->setData(UIDataHostNetwork());673 sltToggle HostNetworkDetailsVisibility(false);674 } 675 } 676 677 void UINetworkManagerWidget::sltHandleContextMenuRequest (const QPoint &position)678 { 679 /* Check tree-widget: */680 AssertMsgReturnVoid(m_pTreeWidget , ("Tree-widget isn't created!\n"));584 m_pDetailsWidgetHostNetwork->setData(UIDataHostNetwork()); 585 sltToggleDetailsVisibilityHostNetwork(false); 586 } 587 } 588 589 void UINetworkManagerWidget::sltHandleContextMenuRequestHostNetwork(const QPoint &position) 590 { 591 /* Check host network tree-widget: */ 592 AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n")); 681 593 682 594 /* Compose temporary context-menu: */ 683 595 QMenu menu; 684 if (m_pTreeWidget ->itemAt(position))596 if (m_pTreeWidgetHostNetwork->itemAt(position)) 685 597 { 686 598 menu.addAction(m_pActionPool->action(UIActionIndexMN_M_Network_S_Remove)); … … 693 605 } 694 606 /* And show it: */ 695 menu.exec(m_pTreeWidget->mapToGlobal(position)); 607 menu.exec(m_pTreeWidgetHostNetwork->mapToGlobal(position)); 608 } 609 610 void UINetworkManagerWidget::sltApplyDetailsChangesHostNetwork() 611 { 612 /* Check host network tree-widget: */ 613 AssertMsgReturnVoid(m_pTreeWidgetHostNetwork, ("Host network tree-widget isn't created!\n")); 614 615 /* Get host network item: */ 616 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidgetHostNetwork->currentItem()); 617 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 618 619 /* Check host network details-widget: */ 620 AssertMsgReturnVoid(m_pDetailsWidgetHostNetwork, ("Host network details-widget isn't created!\n")); 621 622 /* Get item data: */ 623 UIDataHostNetwork oldData = *pItem; 624 UIDataHostNetwork newData = m_pDetailsWidgetHostNetwork->data(); 625 626 /* Get host for further activities: */ 627 CHost comHost = uiCommon().host(); 628 629 /* Find corresponding interface: */ 630 CHostNetworkInterface comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName); 631 632 /* Show error message if necessary: */ 633 if (!comHost.isOk() || comInterface.isNull()) 634 msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this); 635 else 636 { 637 /* Save automatic interface configuration: */ 638 if (newData.m_interface.m_fDHCPEnabled) 639 { 640 if ( comInterface.isOk() 641 && !oldData.m_interface.m_fDHCPEnabled) 642 comInterface.EnableDynamicIPConfig(); 643 } 644 /* Save manual interface configuration: */ 645 else 646 { 647 /* Save IPv4 interface configuration: */ 648 if ( comInterface.isOk() 649 && ( oldData.m_interface.m_fDHCPEnabled 650 || newData.m_interface.m_strAddress != oldData.m_interface.m_strAddress 651 || newData.m_interface.m_strMask != oldData.m_interface.m_strMask)) 652 comInterface.EnableStaticIPConfig(newData.m_interface.m_strAddress, newData.m_interface.m_strMask); 653 /* Save IPv6 interface configuration: */ 654 if ( comInterface.isOk() 655 && newData.m_interface.m_fSupportedIPv6 656 && ( oldData.m_interface.m_fDHCPEnabled 657 || newData.m_interface.m_strAddress6 != oldData.m_interface.m_strAddress6 658 || newData.m_interface.m_strPrefixLength6 != oldData.m_interface.m_strPrefixLength6)) 659 comInterface.EnableStaticIPConfigV6(newData.m_interface.m_strAddress6, newData.m_interface.m_strPrefixLength6.toULong()); 660 } 661 662 /* Show error message if necessary: */ 663 if (!comInterface.isOk()) 664 msgCenter().cannotSaveHostNetworkInterfaceParameter(comInterface, this); 665 else 666 { 667 /* Get network name for further activities: */ 668 const QString strNetworkName = comInterface.GetNetworkName(); 669 670 /* Show error message if necessary: */ 671 if (!comInterface.isOk()) 672 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 673 else 674 { 675 /* Get VBox for further activities: */ 676 CVirtualBox comVBox = uiCommon().virtualBox(); 677 678 /* Find corresponding DHCP server (create if necessary): */ 679 CDHCPServer comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 680 if (!comVBox.isOk() || comServer.isNull()) 681 comServer = comVBox.CreateDHCPServer(strNetworkName); 682 683 /* Show error message if necessary: */ 684 if (!comVBox.isOk() || comServer.isNull()) 685 msgCenter().cannotCreateDHCPServer(comVBox, strNetworkName, this); 686 else 687 { 688 /* Save whether DHCP server is enabled: */ 689 if ( comServer.isOk() 690 && newData.m_dhcpserver.m_fEnabled != oldData.m_dhcpserver.m_fEnabled) 691 comServer.SetEnabled(newData.m_dhcpserver.m_fEnabled); 692 /* Save DHCP server configuration: */ 693 if ( comServer.isOk() 694 && newData.m_dhcpserver.m_fEnabled 695 && ( newData.m_dhcpserver.m_strAddress != oldData.m_dhcpserver.m_strAddress 696 || newData.m_dhcpserver.m_strMask != oldData.m_dhcpserver.m_strMask 697 || newData.m_dhcpserver.m_strLowerAddress != oldData.m_dhcpserver.m_strLowerAddress 698 || newData.m_dhcpserver.m_strUpperAddress != oldData.m_dhcpserver.m_strUpperAddress)) 699 comServer.SetConfiguration(newData.m_dhcpserver.m_strAddress, newData.m_dhcpserver.m_strMask, 700 newData.m_dhcpserver.m_strLowerAddress, newData.m_dhcpserver.m_strUpperAddress); 701 702 /* Show error message if necessary: */ 703 if (!comServer.isOk()) 704 msgCenter().cannotSaveDHCPServerParameter(comServer, this); 705 } 706 } 707 } 708 709 /* Find corresponding interface again (if necessary): */ 710 if (!comInterface.isOk()) 711 { 712 comInterface = comHost.FindHostNetworkInterfaceByName(oldData.m_interface.m_strName); 713 714 /* Show error message if necessary: */ 715 if (!comHost.isOk() || comInterface.isNull()) 716 msgCenter().cannotFindHostNetworkInterface(comHost, oldData.m_interface.m_strName, this); 717 } 718 719 /* If interface is Ok now: */ 720 if (comInterface.isNotNull() && comInterface.isOk()) 721 { 722 /* Update interface in the tree: */ 723 UIDataHostNetwork data; 724 loadHostNetwork(comInterface, data); 725 updateItemForNetworkHost(data, true, pItem); 726 727 /* Make sure current item fetched: */ 728 sltHandleCurrentItemChangeHostNetwork(); 729 730 /* Adjust tree-widgets: */ 731 sltAdjustTreeWidgets(); 732 } 733 } 696 734 } 697 735 … … 711 749 retranslateUi(); 712 750 713 /* Load hostnetworks: */751 /* Load networks: */ 714 752 loadHostNetworks(); 715 753 } … … 729 767 this, &UINetworkManagerWidget::sltRemoveHostNetwork); 730 768 connect(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details), &QAction::toggled, 731 this, &UINetworkManagerWidget::sltToggle HostNetworkDetailsVisibility);769 this, &UINetworkManagerWidget::sltToggleDetailsVisibilityHostNetwork); 732 770 connect(m_pActionPool->action(UIActionIndexMN_M_Network_S_Refresh), &QAction::triggered, 733 771 this, &UINetworkManagerWidget::sltRefreshHostNetworks); … … 751 789 if (m_fShowToolbar) 752 790 prepareToolBar(); 753 /* Prepare tree-widget: */ 754 prepareTreeWidget(); 755 /* Prepare details-widget: */ 756 prepareDetailsWidget(); 791 /* Prepare tab-widget: */ 792 prepareTabWidget(); 757 793 } 758 794 } … … 791 827 } 792 828 793 void UINetworkManagerWidget::prepareTreeWidget() 794 { 795 /* Prepare tree-widget: */ 796 m_pTreeWidget = new QITreeWidget(this); 797 if (m_pTreeWidget) 798 { 799 m_pTreeWidget->setRootIsDecorated(false); 800 m_pTreeWidget->setAlternatingRowColors(true); 801 m_pTreeWidget->setContextMenuPolicy(Qt::CustomContextMenu); 802 m_pTreeWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 803 m_pTreeWidget->setColumnCount(Column_Max); 804 m_pTreeWidget->setSortingEnabled(true); 805 m_pTreeWidget->sortByColumn(Column_Name, Qt::AscendingOrder); 806 m_pTreeWidget->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); 807 connect(m_pTreeWidget, &QITreeWidget::currentItemChanged, 808 this, &UINetworkManagerWidget::sltHandleCurrentItemChange); 809 connect(m_pTreeWidget, &QITreeWidget::customContextMenuRequested, 810 this, &UINetworkManagerWidget::sltHandleContextMenuRequest); 811 connect(m_pTreeWidget, &QITreeWidget::itemChanged, 812 this, &UINetworkManagerWidget::sltHandleItemChange); 813 connect(m_pTreeWidget, &QITreeWidget::itemDoubleClicked, 829 void UINetworkManagerWidget::prepareTabWidget() 830 { 831 /* Create tab-widget: */ 832 m_pTabWidget = new QITabWidget(this); 833 if (m_pTabWidget) 834 { 835 prepareTabHostNetwork(); 836 837 /* Add into layout: */ 838 layout()->addWidget(m_pTabWidget); 839 } 840 } 841 842 void UINetworkManagerWidget::prepareTabHostNetwork() 843 { 844 /* Prepare host network tab: */ 845 m_pTabHostNetwork = new QWidget(m_pTabWidget); 846 if (m_pTabHostNetwork) 847 { 848 /* Prepare host network layout: */ 849 m_pLayoutHostNetwork = new QVBoxLayout(m_pTabHostNetwork); 850 if (m_pLayoutHostNetwork) 851 { 852 prepareTreeWidgetHostNetwork(); 853 prepareDetailsWidgetHostNetwork(); 854 } 855 856 /* Add into tab-widget: */ 857 m_pTabWidget->addTab(m_pTabHostNetwork, QString()); 858 } 859 } 860 861 void UINetworkManagerWidget::prepareTreeWidgetHostNetwork() 862 { 863 /* Prepare host network tree-widget: */ 864 m_pTreeWidgetHostNetwork = new QITreeWidget(m_pTabHostNetwork); 865 if (m_pTreeWidgetHostNetwork) 866 { 867 m_pTreeWidgetHostNetwork->setRootIsDecorated(false); 868 m_pTreeWidgetHostNetwork->setAlternatingRowColors(true); 869 m_pTreeWidgetHostNetwork->setContextMenuPolicy(Qt::CustomContextMenu); 870 m_pTreeWidgetHostNetwork->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 871 m_pTreeWidgetHostNetwork->setColumnCount(Column_Max); 872 m_pTreeWidgetHostNetwork->setSortingEnabled(true); 873 m_pTreeWidgetHostNetwork->sortByColumn(Column_Name, Qt::AscendingOrder); 874 m_pTreeWidgetHostNetwork->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding); 875 connect(m_pTreeWidgetHostNetwork, &QITreeWidget::currentItemChanged, 876 this, &UINetworkManagerWidget::sltHandleCurrentItemChangeHostNetwork); 877 connect(m_pTreeWidgetHostNetwork, &QITreeWidget::customContextMenuRequested, 878 this, &UINetworkManagerWidget::sltHandleContextMenuRequestHostNetwork); 879 connect(m_pTreeWidgetHostNetwork, &QITreeWidget::itemChanged, 880 this, &UINetworkManagerWidget::sltHandleItemChangeHostNetwork); 881 connect(m_pTreeWidgetHostNetwork, &QITreeWidget::itemDoubleClicked, 814 882 m_pActionPool->action(UIActionIndexMN_M_Network_T_Details), &QAction::setChecked); 815 883 816 884 /* Add into layout: */ 817 layout()->addWidget(m_pTreeWidget);818 } 819 } 820 821 void UINetworkManagerWidget::prepareDetailsWidget ()822 { 823 /* Prepare details-widget: */824 m_pDetailsWidget = new UINetworkDetailsWidget(m_enmEmbedding, this);825 if (m_pDetailsWidget )826 { 827 m_pDetailsWidget ->setVisible(false);828 m_pDetailsWidget ->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);829 connect(m_pDetailsWidget , &UINetworkDetailsWidget::sigDataChanged,830 this, &UINetworkManagerWidget::sig HostNetworkDetailsDataChanged);831 connect(m_pDetailsWidget , &UINetworkDetailsWidget::sigDataChangeRejected,832 this, &UINetworkManagerWidget::slt ResetHostNetworkDetailsChanges);833 connect(m_pDetailsWidget , &UINetworkDetailsWidget::sigDataChangeAccepted,834 this, &UINetworkManagerWidget::sltApply HostNetworkDetailsChanges);885 m_pLayoutHostNetwork->addWidget(m_pTreeWidgetHostNetwork); 886 } 887 } 888 889 void UINetworkManagerWidget::prepareDetailsWidgetHostNetwork() 890 { 891 /* Prepare host network details-widget: */ 892 m_pDetailsWidgetHostNetwork = new UINetworkDetailsWidget(m_enmEmbedding, m_pTabHostNetwork); 893 if (m_pDetailsWidgetHostNetwork) 894 { 895 m_pDetailsWidgetHostNetwork->setVisible(false); 896 m_pDetailsWidgetHostNetwork->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); 897 connect(m_pDetailsWidgetHostNetwork, &UINetworkDetailsWidget::sigDataChanged, 898 this, &UINetworkManagerWidget::sigDetailsDataChangedHostNetwork); 899 connect(m_pDetailsWidgetHostNetwork, &UINetworkDetailsWidget::sigDataChangeRejected, 900 this, &UINetworkManagerWidget::sltHandleCurrentItemChangeHostNetwork); 901 connect(m_pDetailsWidgetHostNetwork, &UINetworkDetailsWidget::sigDataChangeAccepted, 902 this, &UINetworkManagerWidget::sltApplyDetailsChangesHostNetwork); 835 903 836 904 /* Add into layout: */ 837 layout()->addWidget(m_pDetailsWidget);905 m_pLayoutHostNetwork->addWidget(m_pDetailsWidgetHostNetwork); 838 906 } 839 907 } … … 845 913 { 846 914 m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->setChecked(gEDataManager->hostNetworkManagerDetailsExpanded()); 847 sltToggle HostNetworkDetailsVisibility(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->isChecked());915 sltToggleDetailsVisibilityHostNetwork(m_pActionPool->action(UIActionIndexMN_M_Network_T_Details)->isChecked()); 848 916 } 849 917 } … … 851 919 void UINetworkManagerWidget::loadHostNetworks() 852 920 { 853 /* Check tree-widget: */854 if (!m_pTreeWidget )921 /* Check host network tree-widget: */ 922 if (!m_pTreeWidgetHostNetwork) 855 923 return; 856 924 857 925 /* Clear tree first of all: */ 858 m_pTreeWidget ->clear();926 m_pTreeWidgetHostNetwork->clear(); 859 927 860 928 /* Get host for further activities: */ … … 879 947 880 948 /* Choose the 1st item as current initially: */ 881 m_pTreeWidget ->setCurrentItem(m_pTreeWidget->topLevelItem(0));882 sltHandleCurrentItemChange ();883 884 /* Adjust tree-widget : */885 sltAdjustTreeWidget ();949 m_pTreeWidgetHostNetwork->setCurrentItem(m_pTreeWidgetHostNetwork->topLevelItem(0)); 950 sltHandleCurrentItemChangeHostNetwork(); 951 952 /* Adjust tree-widgets: */ 953 sltAdjustTreeWidgets(); 886 954 } 887 955 } … … 955 1023 pItem->updateFields(); 956 1024 /* Add item to the tree: */ 957 m_pTreeWidget ->addTopLevelItem(pItem);1025 m_pTreeWidgetHostNetwork->addTopLevelItem(pItem); 958 1026 /* And choose it as current if necessary: */ 959 1027 if (fChooseItem) 960 m_pTreeWidget ->setCurrentItem(pItem);1028 m_pTreeWidgetHostNetwork->setCurrentItem(pItem); 961 1029 } 962 1030 } … … 972 1040 /* And choose it as current if necessary: */ 973 1041 if (fChooseItem) 974 m_pTreeWidget ->setCurrentItem(pItem);1042 m_pTreeWidgetHostNetwork->setCurrentItem(pItem); 975 1043 } 976 1044 } … … 1019 1087 { 1020 1088 /* Translate window title: */ 1021 setWindowTitle(tr(" HostNetwork Manager"));1089 setWindowTitle(tr("Network Manager")); 1022 1090 1023 1091 /* Translate buttons: */ … … 1026 1094 button(ButtonType_Close)->setText(tr("Close")); 1027 1095 button(ButtonType_Help)->setText(tr("Help")); 1028 button(ButtonType_Reset)->setStatusTip(tr("Reset changes in current hostnetwork details"));1029 button(ButtonType_Apply)->setStatusTip(tr("Apply changes in current hostnetwork details"));1096 button(ButtonType_Reset)->setStatusTip(tr("Reset changes in current network details")); 1097 button(ButtonType_Apply)->setStatusTip(tr("Apply changes in current network details")); 1030 1098 button(ButtonType_Close)->setStatusTip(tr("Close dialog without saving")); 1031 1099 button(ButtonType_Help)->setStatusTip(tr("Show dialog help")); … … 1058 1126 #endif 1059 1127 connect(this, &UINetworkManager::sigDataChangeRejected, 1060 pWidget, &UINetworkManagerWidget::sltReset HostNetworkDetailsChanges);1128 pWidget, &UINetworkManagerWidget::sltResetDetailsChanges); 1061 1129 connect(this, &UINetworkManager::sigDataChangeAccepted, 1062 pWidget, &UINetworkManagerWidget::sltApply HostNetworkDetailsChanges);1130 pWidget, &UINetworkManagerWidget::sltApplyDetailsChanges); 1063 1131 1064 1132 /* Add into layout: */ … … 1070 1138 { 1071 1139 /* Configure button-box: */ 1072 connect(widget(), &UINetworkManagerWidget::sig HostNetworkDetailsVisibilityChanged,1140 connect(widget(), &UINetworkManagerWidget::sigDetailsVisibilityChangedHostNetwork, 1073 1141 button(ButtonType_Apply), &QPushButton::setVisible); 1074 connect(widget(), &UINetworkManagerWidget::sig HostNetworkDetailsVisibilityChanged,1142 connect(widget(), &UINetworkManagerWidget::sigDetailsVisibilityChangedHostNetwork, 1075 1143 button(ButtonType_Reset), &QPushButton::setVisible); 1076 connect(widget(), &UINetworkManagerWidget::sig HostNetworkDetailsDataChanged,1144 connect(widget(), &UINetworkManagerWidget::sigDetailsDataChangedHostNetwork, 1077 1145 button(ButtonType_Apply), &QPushButton::setEnabled); 1078 connect(widget(), &UINetworkManagerWidget::sig HostNetworkDetailsDataChanged,1146 connect(widget(), &UINetworkManagerWidget::sigDetailsDataChangedHostNetwork, 1079 1147 button(ButtonType_Reset), &QPushButton::setEnabled); 1080 1148 connect(buttonBox(), &QIDialogButtonBox::clicked, -
trunk/src/VBox/Frontends/VirtualBox/src/networkmanager/UINetworkManager.h
r87088 r87089 33 33 class QAbstractButton; 34 34 class QTreeWidgetItem; 35 class QVBoxLayout; 35 36 class QIDialogButtonBox; 37 class QITabWidget; 36 38 class QITreeWidget; 37 39 class UIActionPool; … … 42 44 43 45 44 /** QWidget extension providing GUI with the pane to control hostnetwork related functionality. */46 /** QWidget extension providing GUI with the pane to control network related functionality. */ 45 47 class UINetworkManagerWidget : public QIWithRetranslateUI<QWidget> 46 48 { … … 49 51 signals: 50 52 51 /** Notifies listeners about hostnetwork details-widget @a fVisible. */52 void sig HostNetworkDetailsVisibilityChanged(bool fVisible);53 /** Notifies listeners about hostnetwork details data @a fDiffers. */54 void sig HostNetworkDetailsDataChanged(bool fDiffers);53 /** Notifies listeners about network details-widget @a fVisible. */ 54 void sigDetailsVisibilityChangedHostNetwork(bool fVisible); 55 /** Notifies listeners about network details data @a fDiffers. */ 56 void sigDetailsDataChangedHostNetwork(bool fDiffers); 55 57 56 58 public: 57 59 58 /** Constructs HostNetwork Manager widget.60 /** Constructs Network Manager widget. 59 61 * @param enmEmbedding Brings the type of widget embedding. 60 62 * @param pActionPool Brings the action-pool reference. … … 89 91 /** @name Details-widget stuff. 90 92 * @{ */ 91 /** Handles command to reset host networkdetails changes. */92 void sltReset HostNetworkDetailsChanges();93 /** Handles command to apply host networkdetails changes. */94 void sltApply HostNetworkDetailsChanges();93 /** Handles command to reset details changes. */ 94 void sltResetDetailsChanges(); 95 /** Handles command to apply details changes. */ 96 void sltApplyDetailsChanges(); 95 97 /** @} */ 96 98 … … 104 106 void sltRemoveHostNetwork(); 105 107 /** Handles command to make host network details @a fVisible. */ 106 void sltToggle HostNetworkDetailsVisibility(bool fVisible);108 void sltToggleDetailsVisibilityHostNetwork(bool fVisible); 107 109 /** Handles command to refresh host networks. */ 108 110 void sltRefreshHostNetworks(); … … 112 114 * @{ */ 113 115 /** Handles command to adjust tree-widget. */ 114 void sltAdjustTreeWidget(); 115 116 /** Handles tree-widget @a pItem change. */ 117 void sltHandleItemChange(QTreeWidgetItem *pItem); 118 /** Handles tree-widget current item change. */ 119 void sltHandleCurrentItemChange(); 120 /** Handles context menu request for tree-widget @a position. */ 121 void sltHandleContextMenuRequest(const QPoint &position); 116 void sltAdjustTreeWidgets(); 117 118 /** Handles host network tree-widget @a pItem change. */ 119 void sltHandleItemChangeHostNetwork(QTreeWidgetItem *pItem); 120 /** Handles host network tree-widget current item change. */ 121 void sltHandleCurrentItemChangeHostNetwork(); 122 /** Handles host network context-menu request for tree-widget @a position. */ 123 void sltHandleContextMenuRequestHostNetwork(const QPoint &position); 124 125 /** Handles command to apply host network details changes. */ 126 void sltApplyDetailsChangesHostNetwork(); 122 127 /** @} */ 123 128 … … 134 139 /** Prepares toolbar. */ 135 140 void prepareToolBar(); 136 /** Prepares tree-widget. */ 137 void prepareTreeWidget(); 138 /** Prepares details-widget. */ 139 void prepareDetailsWidget(); 141 /** Prepares tab-widget. */ 142 void prepareTabWidget(); 143 /** Prepares host network tab. */ 144 void prepareTabHostNetwork(); 145 /** Prepares host network tree-widget. */ 146 void prepareTreeWidgetHostNetwork(); 147 /** Prepares host network details-widget. */ 148 void prepareDetailsWidgetHostNetwork(); 140 149 /** Load settings: */ 141 150 void loadSettings(); … … 176 185 /** @name Splitter variables. 177 186 * @{ */ 178 /** Holds the tree-widget instance. */ 179 QITreeWidget *m_pTreeWidget; 180 /** Holds the details-widget instance. */ 181 UINetworkDetailsWidget *m_pDetailsWidget; 187 /** Holds the tab-widget instance. */ 188 QITabWidget *m_pTabWidget; 189 190 /** Holds the host network tab. */ 191 QWidget *m_pTabHostNetwork; 192 /** Holds the host network layout. */ 193 QVBoxLayout *m_pLayoutHostNetwork; 194 /** Holds the host network tree-widget instance. */ 195 QITreeWidget *m_pTreeWidgetHostNetwork; 196 /** Holds the host network details-widget instance. */ 197 UINetworkDetailsWidget *m_pDetailsWidgetHostNetwork; 182 198 /** @} */ 183 199 };
Note:
See TracChangeset
for help on using the changeset viewer.