Changeset 66720 in vbox
- Timestamp:
- Apr 28, 2017 2:30:01 PM (8 years ago)
- svn:sync-xref-src-repo-rev:
- 115122
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.cpp
r66718 r66720 29 29 # include "QITreeWidget.h" 30 30 # include "UIIconPool.h" 31 # include "UIMessageCenter.h"32 31 # include "UIHostNetworkDetailsDialog.h" 33 32 # include "UIHostNetworkManager.h" 33 # include "UIMessageCenter.h" 34 34 # include "UIToolBar.h" 35 35 # ifdef VBOX_WS_MAC … … 195 195 , m_pMenu(0) 196 196 , m_pActionAdd(0) 197 , m_pActionRemove(0) 197 198 , m_pActionEdit(0) 198 , m_pActionRemove(0)199 199 , m_pTreeWidget(0) 200 200 , m_pButtonBox(0) … … 245 245 m_pActionAdd->setStatusTip(tr("Creates new host-only network.")); 246 246 } 247 if (m_pActionRemove) 248 { 249 m_pActionRemove->setText(tr("&Remove...")); 250 m_pActionRemove->setToolTip(tr("Remove Host-only Network (%1)").arg(m_pActionRemove->shortcut().toString())); 251 m_pActionRemove->setStatusTip(tr("Removes selected host-only network.")); 252 } 247 253 if (m_pActionEdit) 248 254 { … … 250 256 m_pActionEdit->setToolTip(tr("Modify Host-only Network (%1)").arg(m_pActionEdit->shortcut().toString())); 251 257 m_pActionEdit->setStatusTip(tr("Modifies selected host-only network.")); 252 }253 if (m_pActionRemove)254 {255 m_pActionRemove->setText(tr("&Remove..."));256 m_pActionRemove->setToolTip(tr("Remove Host-only Network (%1)").arg(m_pActionRemove->shortcut().toString()));257 m_pActionRemove->setStatusTip(tr("Removes selected host-only network."));258 258 } 259 259 … … 346 346 /* Adjust tree-widget: */ 347 347 sltAdjustTreeWidget(); 348 } 349 } 350 } 351 352 void UIHostNetworkManager::sltRemoveHostNetwork() 353 { 354 /* Get network item: */ 355 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem()); 356 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n")); 357 358 /* Get interface name: */ 359 const QString strInterfaceName(pItem->name()); 360 361 /* Confirm host network removal: */ 362 if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this)) 363 return; 364 365 /* Get host for further activities: */ 366 CHost comHost = vboxGlobal().host(); 367 368 /* Find corresponding interface: */ 369 const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName); 370 371 /* Show error message if necessary: */ 372 if (!comHost.isOk() || comInterface.isNull()) 373 msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this); 374 else 375 { 376 /* Get network name for further activities: */ 377 QString strNetworkName; 378 if (comInterface.isOk()) 379 strNetworkName = comInterface.GetNetworkName(); 380 /* Get interface id for further activities: */ 381 QString strInterfaceId; 382 if (comInterface.isOk()) 383 strInterfaceId = comInterface.GetId(); 384 385 /* Show error message if necessary: */ 386 if (!comInterface.isOk()) 387 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this); 388 else 389 { 390 /* Get VBox for further activities: */ 391 CVirtualBox comVBox = vboxGlobal().virtualBox(); 392 393 /* Find corresponding DHCP server: */ 394 const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName); 395 if (comVBox.isOk() && comServer.isNotNull()) 396 { 397 /* Remove server if any: */ 398 comVBox.RemoveDHCPServer(comServer); 399 400 /* Show error message if necessary: */ 401 if (!comVBox.isOk()) 402 msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this); 403 } 404 405 /* Remove interface finally: */ 406 CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId); 407 408 /* Show error message if necessary: */ 409 if (!comHost.isOk() || progress.isNull()) 410 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this); 411 else 412 { 413 /* Show interface removal progress: */ 414 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0); 415 416 /* Show error message if necessary: */ 417 if (!progress.isOk() || progress.GetResultCode() != 0) 418 return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this); 419 else 420 { 421 /* Remove interface from the tree: */ 422 delete pItem; 423 424 /* Adjust tree-widget: */ 425 sltAdjustTreeWidget(); 426 } 427 } 348 428 } 349 429 } … … 445 525 } 446 526 447 void UIHostNetworkManager::sltRemoveHostNetwork()448 {449 /* Get network item: */450 UIItemHostNetwork *pItem = static_cast<UIItemHostNetwork*>(m_pTreeWidget->currentItem());451 AssertMsgReturnVoid(pItem, ("Current item must not be null!\n"));452 453 /* Get interface name: */454 const QString strInterfaceName(pItem->name());455 456 /* Confirm host network removal: */457 if (!msgCenter().confirmHostOnlyInterfaceRemoval(strInterfaceName, this))458 return;459 460 /* Get host for further activities: */461 CHost comHost = vboxGlobal().host();462 463 /* Find corresponding interface: */464 const CHostNetworkInterface &comInterface = comHost.FindHostNetworkInterfaceByName(strInterfaceName);465 466 /* Show error message if necessary: */467 if (!comHost.isOk() || comInterface.isNull())468 msgCenter().cannotFindHostNetworkInterface(comHost, strInterfaceName, this);469 else470 {471 /* Get network name for further activities: */472 QString strNetworkName;473 if (comInterface.isOk())474 strNetworkName = comInterface.GetNetworkName();475 /* Get interface id for further activities: */476 QString strInterfaceId;477 if (comInterface.isOk())478 strInterfaceId = comInterface.GetId();479 480 /* Show error message if necessary: */481 if (!comInterface.isOk())482 msgCenter().cannotAcquireHostNetworkInterfaceParameter(comInterface, this);483 else484 {485 /* Get VBox for further activities: */486 CVirtualBox comVBox = vboxGlobal().virtualBox();487 488 /* Find corresponding DHCP server: */489 const CDHCPServer &comServer = comVBox.FindDHCPServerByNetworkName(strNetworkName);490 if (comVBox.isOk() && comServer.isNotNull())491 {492 /* Remove server if any: */493 comVBox.RemoveDHCPServer(comServer);494 495 /* Show error message if necessary: */496 if (!comVBox.isOk())497 msgCenter().cannotRemoveDHCPServer(comVBox, strInterfaceName, this);498 }499 500 /* Remove interface finally: */501 CProgress progress = comHost.RemoveHostOnlyNetworkInterface(strInterfaceId);502 503 /* Show error message if necessary: */504 if (!comHost.isOk() || progress.isNull())505 msgCenter().cannotRemoveHostNetworkInterface(comHost, strInterfaceName, this);506 else507 {508 /* Show interface removal progress: */509 msgCenter().showModalProgressDialog(progress, tr("Networking"), ":/progress_network_interface_90px.png", this, 0);510 511 /* Show error message if necessary: */512 if (!progress.isOk() || progress.GetResultCode() != 0)513 return msgCenter().cannotRemoveHostNetworkInterface(progress, strInterfaceName, this);514 else515 {516 /* Remove interface from the tree: */517 delete pItem;518 519 /* Adjust tree-widget: */520 sltAdjustTreeWidget();521 }522 }523 }524 }525 }526 527 527 void UIHostNetworkManager::sltAdjustTreeWidget() 528 528 { … … 633 633 if (m_pTreeWidget->itemAt(pos)) 634 634 { 635 menu.addAction(m_pActionRemove); 635 636 menu.addAction(m_pActionEdit); 636 menu.addAction(m_pActionRemove);637 637 } 638 638 else … … 695 695 } 696 696 697 /* Create 'Remove' action: */ 698 m_pActionRemove = new QAction(this); 699 AssertPtrReturnVoid(m_pActionRemove); 700 { 701 /* Configure 'Remove' action: */ 702 m_pActionRemove->setShortcut(QKeySequence("Del")); 703 m_pActionRemove->setIcon(UIIconPool::iconSetFull(":/remove_host_iface_22px.png", 704 ":/remove_host_iface_16px.png", 705 ":/remove_host_iface_disabled_22px.png", 706 ":/remove_host_iface_disabled_16px.png")); 707 connect(m_pActionRemove, SIGNAL(triggered()), this, SLOT(sltRemoveHostNetwork())); 708 } 709 697 710 /* Create 'Edit' action: */ 698 711 m_pActionEdit = new QAction(this); … … 708 721 } 709 722 710 /* Create 'Remove' action: */711 m_pActionRemove = new QAction(this);712 AssertPtrReturnVoid(m_pActionRemove);713 {714 /* Configure 'Remove' action: */715 m_pActionRemove->setShortcut(QKeySequence("Del"));716 m_pActionRemove->setIcon(UIIconPool::iconSetFull(":/remove_host_iface_22px.png",717 ":/remove_host_iface_16px.png",718 ":/remove_host_iface_disabled_22px.png",719 ":/remove_host_iface_disabled_16px.png"));720 connect(m_pActionRemove, SIGNAL(triggered()), this, SLOT(sltRemoveHostNetwork()));721 }722 723 723 /* Prepare menu-bar: */ 724 724 prepareMenuBar(); … … 733 733 /* Configure 'File' menu: */ 734 734 m_pMenu->addAction(m_pActionAdd); 735 m_pMenu->addAction(m_pActionRemove); 735 736 m_pMenu->addAction(m_pActionEdit); 736 m_pMenu->addAction(m_pActionRemove);737 737 } 738 738 … … 780 780 if (m_pActionAdd) 781 781 m_pToolBar->addAction(m_pActionAdd); 782 if (m_pActionRemove) 783 m_pToolBar->addAction(m_pActionRemove); 782 784 if (m_pActionEdit) 783 785 m_pToolBar->addAction(m_pActionEdit); 784 if (m_pActionRemove)785 m_pToolBar->addAction(m_pActionRemove);786 786 /* Integrate tool-bar into dialog: */ 787 787 QVBoxLayout *pMainLayout = qobject_cast<QVBoxLayout*>(centralWidget()->layout()); -
trunk/src/VBox/Frontends/VirtualBox/src/hostnetwork/UIHostNetworkManager.h
r66696 r66720 73 73 /** Handles command to add host network. */ 74 74 void sltAddHostNetwork(); 75 /** Handles command to remove host network. */ 76 void sltRemoveHostNetwork(); 75 77 /** Handles command to edit host network. */ 76 78 void sltEditHostNetwork(); 77 /** Handles command to remove host network. */78 void sltRemoveHostNetwork();79 79 /** @} */ 80 80 … … 152 152 /** Holds the Add action instance. */ 153 153 QAction *m_pActionAdd; 154 /** Holds the Remove action instance. */ 155 QAction *m_pActionRemove; 154 156 /** Holds the Edit action instance. */ 155 157 QAction *m_pActionEdit; 156 /** Holds the Remove action instance. */157 QAction *m_pActionRemove;158 158 /** @} */ 159 159
Note:
See TracChangeset
for help on using the changeset viewer.