Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.cpp	(revision 35547)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.cpp	(revision 35548)
@@ -257,28 +257,5 @@
         const CHostNetworkInterface &iface = interfaces[iNetworkIndex];
         if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
-        {
-            /* Initialization: */
-            CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
-            if (dhcp.isNull()) vboxGlobal().virtualBox().CreateDHCPServer(iface.GetNetworkName());
-            dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
-            AssertMsg(!dhcp.isNull(), ("DHCP Server creation failed!\n"));
-            UIHostNetworkData data;
-            /* Host-only interface settings */
-            data.m_interface.m_strName = iface.GetName();
-            data.m_interface.m_fDhcpClientEnabled = iface.GetDhcpEnabled();
-            data.m_interface.m_strInterfaceAddress = iface.GetIPAddress();
-            data.m_interface.m_strInterfaceMask = iface.GetNetworkMask();
-            data.m_interface.m_fIpv6Supported = iface.GetIPV6Supported();
-            data.m_interface.m_strInterfaceAddress6 = iface.GetIPV6Address();
-            data.m_interface.m_strInterfaceMaskLength6 = QString::number(iface.GetIPV6NetworkMaskPrefixLength());
-            /* DHCP server settings: */
-            data.m_dhcpserver.m_fDhcpServerEnabled = dhcp.GetEnabled();
-            data.m_dhcpserver.m_strDhcpServerAddress = dhcp.GetIPAddress();
-            data.m_dhcpserver.m_strDhcpServerMask = dhcp.GetNetworkMask();
-            data.m_dhcpserver.m_strDhcpLowerAddress = dhcp.GetLowerIP();
-            data.m_dhcpserver.m_strDhcpUpperAddress = dhcp.GetUpperIP();
-            /* Cache: */
-            m_cache.m_items << data;
-        }
+            appendCacheItem(iface);
     }
 
@@ -293,10 +270,6 @@
     /* Fetch from cache: */
     for (int iNetworkIndex = 0; iNetworkIndex < m_cache.m_items.size(); ++iNetworkIndex)
-    {
-        const UIHostNetworkData &data = m_cache.m_items[iNetworkIndex];
-        UIHostInterfaceItem *pItem = new UIHostInterfaceItem;
-        pItem->fetchNetworkData(data);
-        m_pInterfacesTree->addTopLevelItem(pItem);
-    }
+        appendListItem(m_cache.m_items[iNetworkIndex]);
+    /* Set first list item as current: */
     m_pInterfacesTree->setCurrentItem(m_pInterfacesTree->topLevelItem(0));
     sltUpdateCurrentItem();
@@ -307,6 +280,7 @@
 void UIGlobalSettingsNetwork::putToCache()
 {
+    /* Eraze cache: */
+    m_cache.m_items.clear();
     /* Upload to cache: */
-    m_cache.m_items.clear();
     for (int iNetworkIndex = 0; iNetworkIndex < m_pInterfacesTree->topLevelItemCount(); ++iNetworkIndex)
     {
@@ -329,92 +303,54 @@
     UISettingsPageGlobal::fetchData(data);
 
-    /* Save from cache: */
+    /* Prepare useful variables: */
     CVirtualBox vbox = vboxGlobal().virtualBox();
     CHost host = vbox.GetHost();
-    const CHostNetworkInterfaceVector &interfaces = host.GetNetworkInterfaces();
-    /* Remove all the old interfaces first: */
-    for (int iNetworkIndex = 0; iNetworkIndex < interfaces.size() && !failed(); ++iNetworkIndex)
-    {
-        /* Get iterated interface: */
-        const CHostNetworkInterface &iface = interfaces[iNetworkIndex];
-        if (iface.GetInterfaceType() == KHostNetworkInterfaceType_HostOnly)
-        {
-            /* Search for this interface's dhcp sserver: */
-            CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
-            /* Delete it if its present: */
-            if (!dhcp.isNull())
-                vbox.RemoveDHCPServer(dhcp);
-            /* Delete interface finally: */
-            CProgress progress = host.RemoveHostOnlyNetworkInterface(iface.GetId());
-            if (host.isOk())
+
+    /* Update all the host-only interfaces: */
+    for (int iNetworkIndex = 0; iNetworkIndex < m_cache.m_items.size(); ++iNetworkIndex)
+    {
+        /* Get iterated data: */
+        const UIHostNetworkData &data = m_cache.m_items[iNetworkIndex];
+        /* Find corresponding interface: */
+        CHostNetworkInterface iface = host.FindHostNetworkInterfaceByName(data.m_interface.m_strName);
+        if (!iface.isNull())
+        {
+            /* Host-only interface configuring: */
+            if (data.m_interface.m_fDhcpClientEnabled)
             {
-                progress.WaitForCompletion(-1);
-                if (progress.GetResultCode() != 0)
-                {
-                    /* Mark the page as failed: */
-                    setFailed(true);
-                    /* Show error message: */
-                    vboxProblem().cannotRemoveHostInterface(progress, iface);
-                }
+                iface.EnableDynamicIpConfig();
             }
             else
             {
-                /* Mark the page as failed: */
-                setFailed(true);
-                /* Show error message: */
-                vboxProblem().cannotRemoveHostInterface(host, iface);
+                AssertMsg(data.m_interface.m_strInterfaceAddress.isEmpty() ||
+                          QHostAddress(data.m_interface.m_strInterfaceAddress).protocol() == QAbstractSocket::IPv4Protocol,
+                          ("Interface IPv4 address must be empty or IPv4-valid!\n"));
+                AssertMsg(data.m_interface.m_strInterfaceMask.isEmpty() ||
+                          QHostAddress(data.m_interface.m_strInterfaceMask).protocol() == QAbstractSocket::IPv4Protocol,
+                          ("Interface IPv4 network mask must be empty or IPv4-valid!\n"));
+                iface.EnableStaticIpConfig(data.m_interface.m_strInterfaceAddress, data.m_interface.m_strInterfaceMask);
+                if (iface.GetIPV6Supported())
+                {
+                    AssertMsg(data.m_interface.m_strInterfaceAddress6.isEmpty() ||
+                              QHostAddress(data.m_interface.m_strInterfaceAddress6).protocol() == QAbstractSocket::IPv6Protocol,
+                              ("Interface IPv6 address must be empty or IPv6-valid!\n"));
+                    iface.EnableStaticIpConfigV6(data.m_interface.m_strInterfaceAddress6, data.m_interface.m_strInterfaceMaskLength6.toULong());
+                }
             }
-        }
-    }
-    /* Add all the new interfaces finally: */
-    for (int iNetworkIndex = 0; iNetworkIndex < m_cache.m_items.size() && !failed(); ++iNetworkIndex)
-    {
-        /* Get iterated data: */
-        const UIHostNetworkData &data = m_cache.m_items[iNetworkIndex];
-        CHostNetworkInterface iface;
-        /* Create interface: */
-        CProgress progress = host.CreateHostOnlyNetworkInterface(iface);
-        if (host.isOk())
-        {
-            progress.WaitForCompletion(-1);
-            if (progress.GetResultCode() == 0)
+
+            /* Find corresponding DHCP server: */
+            CDHCPServer dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
+            if (!dhcp.isNull())
             {
-                /* Create DHCP server: */
-                CDHCPServer dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
-                if (dhcp.isNull()) vbox.CreateDHCPServer(iface.GetNetworkName());
-                dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
-                AssertMsg(!dhcp.isNull(), ("DHCP Server creation failed!\n"));
-                /* Host-only Interface configuring: */
-                if (data.m_interface.m_fDhcpClientEnabled)
-                {
-                    iface.EnableDynamicIpConfig();
-                }
-                else
-                {
-                    AssertMsg(data.m_interface.m_strInterfaceAddress.isEmpty() ||
-                              QHostAddress(data.m_interface.m_strInterfaceAddress).protocol() == QAbstractSocket::IPv4Protocol,
-                              ("Interface IPv4 address must be empty or IPv4-valid!\n"));
-                    AssertMsg(data.m_interface.m_strInterfaceMask.isEmpty() ||
-                              QHostAddress(data.m_interface.m_strInterfaceMask).protocol() == QAbstractSocket::IPv4Protocol,
-                              ("Interface IPv4 network mask must be empty or IPv4-valid!\n"));
-                    iface.EnableStaticIpConfig(data.m_interface.m_strInterfaceAddress, data.m_interface.m_strInterfaceMask);
-                    if (iface.GetIPV6Supported())
-                    {
-                        AssertMsg(data.m_interface.m_strInterfaceAddress6.isEmpty() ||
-                                  QHostAddress(data.m_interface.m_strInterfaceAddress6).protocol() == QAbstractSocket::IPv6Protocol,
-                                  ("Interface IPv6 address must be empty or IPv6-valid!\n"));
-                        iface.EnableStaticIpConfigV6(data.m_interface.m_strInterfaceAddress6, data.m_interface.m_strInterfaceMaskLength6.toULong());
-                    }
-                }
-                /* DHCP Server configuring: */
+                /* DHCP server configuring: */
                 dhcp.SetEnabled(data.m_dhcpserver.m_fDhcpServerEnabled);
-//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpServerAddress).protocol() == QAbstractSocket::IPv4Protocol,
-//                          ("DHCP Server IPv4 address must be IPv4-valid!\n"));
-//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpServerMask).protocol() == QAbstractSocket::IPv4Protocol,
-//                          ("DHCP Server IPv4 network mask must be IPv4-valid!\n"));
-//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpLowerAddress).protocol() == QAbstractSocket::IPv4Protocol,
-//                          ("DHCP Server IPv4 lower bound must be IPv4-valid!\n"));
-//                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpUpperAddress).protocol() == QAbstractSocket::IPv4Protocol,
-//                          ("DHCP Server IPv4 upper bound must be IPv4-valid!\n"));
+                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpServerAddress).protocol() == QAbstractSocket::IPv4Protocol,
+                          ("DHCP server IPv4 address must be IPv4-valid!\n"));
+                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpServerMask).protocol() == QAbstractSocket::IPv4Protocol,
+                          ("DHCP server IPv4 network mask must be IPv4-valid!\n"));
+                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpLowerAddress).protocol() == QAbstractSocket::IPv4Protocol,
+                          ("DHCP server IPv4 lower bound must be IPv4-valid!\n"));
+                AssertMsg(QHostAddress(data.m_dhcpserver.m_strDhcpUpperAddress).protocol() == QAbstractSocket::IPv4Protocol,
+                          ("DHCP server IPv4 upper bound must be IPv4-valid!\n"));
                 if (QHostAddress(data.m_dhcpserver.m_strDhcpServerAddress).protocol() == QAbstractSocket::IPv4Protocol &&
                     QHostAddress(data.m_dhcpserver.m_strDhcpServerMask).protocol() == QAbstractSocket::IPv4Protocol &&
@@ -424,18 +360,4 @@
                                           data.m_dhcpserver.m_strDhcpLowerAddress, data.m_dhcpserver.m_strDhcpUpperAddress);
             }
-            else
-            {
-                /* Mark the page as failed: */
-                setFailed(true);
-                /* Show error message: */
-                vboxProblem().cannotCreateHostInterface(progress);
-            }
-        }
-        else
-        {
-            /* Mark the page as failed: */
-            setFailed(true);
-            /* Show error message: */
-            vboxProblem().cannotCreateHostInterface(host);
         }
     }
@@ -487,23 +409,36 @@
 void UIGlobalSettingsNetwork::sltAddInterface()
 {
-    /* Creating interface item: */
-    UIHostInterfaceItem *pItem = new UIHostInterfaceItem;
-    /* Fill item's data: */
-    UIHostNetworkData data;
-    /* Interface data: */
-    // TODO: Make unique name!
-    data.m_interface.m_strName = tr("New Host-Only Interface");
-    data.m_interface.m_fDhcpClientEnabled = true;
-    data.m_interface.m_fIpv6Supported = false;
-    /* DHCP data: */
-    data.m_dhcpserver.m_fDhcpServerEnabled = false;
-    /* Fetch item with data: */
-    pItem->fetchNetworkData(data);
-    /* Add new top-level item: */
-    m_pInterfacesTree->addTopLevelItem(pItem);
-    m_pInterfacesTree->sortItems(0, Qt::AscendingOrder);
-    m_pInterfacesTree->setCurrentItem(pItem);
-    /* Mark dialog as edited: */
-    m_fChanged = true;
+    /* Prepare useful variables: */
+    CVirtualBox vbox = vboxGlobal().virtualBox();
+    CHost host = vbox.GetHost();
+
+    /* Create new host-only interface: */
+    CHostNetworkInterface iface;
+    CProgress progress = host.CreateHostOnlyNetworkInterface(iface);
+    if (host.isOk())
+    {
+        vboxProblem().showModalProgressDialog(progress, tr("Creating host-only interface..."),
+                                              ":/nw_32px.png", this, true, 0);
+        if (progress.GetResultCode() == 0)
+        {
+            /* Create DHCP server: */
+            CDHCPServer dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
+            if (dhcp.isNull())
+            {
+                vbox.CreateDHCPServer(iface.GetNetworkName());
+                dhcp = vbox.FindDHCPServerByNetworkName(iface.GetNetworkName());
+            }
+            AssertMsg(!dhcp.isNull(), ("DHCP server creation failed!\n"));
+
+            /* Append cache with new item: */
+            appendCacheItem(iface);
+            /* Append list with new item: */
+            appendListItem(m_cache.m_items.last());
+        }
+        else
+            vboxProblem().cannotCreateHostInterface(progress);
+    }
+    else
+        vboxProblem().cannotRemoveHostInterface(host, iface);
 }
 
@@ -519,8 +454,35 @@
     if (vboxProblem().confirmDeletingHostInterface(strInterfaceName, this) == QIMessageBox::Cancel)
         return;
-    /* Removing interface: */
-    delete pItem;
-    /* Mark dialog as edited: */
-    m_fChanged = true;
+
+    /* Prepare useful variables: */
+    CVirtualBox vbox = vboxGlobal().virtualBox();
+    CHost host = vbox.GetHost();
+
+    /* Find corresponding interface: */
+    const CHostNetworkInterface &iface = host.FindHostNetworkInterfaceByName(strInterfaceName);
+
+    /* Remove DHCP server first: */
+    CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
+    if (!dhcp.isNull())
+        vbox.RemoveDHCPServer(dhcp);
+
+    /* Remove interface finally: */
+    CProgress progress = host.RemoveHostOnlyNetworkInterface(iface.GetId());
+    if (host.isOk())
+    {
+        vboxProblem().showModalProgressDialog(progress, tr("Removing host-only interface..."),
+                                              ":/nw_32px.png", this, true, 0);
+        if (progress.GetResultCode() == 0)
+        {
+            /* Remove list item: */
+            removeListItem(pItem);
+            /* Remove cache item: */
+            removeCacheItem(strInterfaceName);
+        }
+        else
+            vboxProblem().cannotRemoveHostInterface(progress, iface);
+    }
+    else
+        vboxProblem().cannotRemoveHostInterface(host, iface);
 }
 
@@ -538,9 +500,8 @@
         details.putBackToItem();
         pItem->updateInfo();
-    }
-    sltUpdateCurrentItem();
-    m_pValidator->revalidate();
-    /* Mark dialog as edited: */
-    m_fChanged = true;
+        sltUpdateCurrentItem();
+        m_pValidator->revalidate();
+        m_fChanged = true;
+    }
 }
 
@@ -570,6 +531,68 @@
         menu.addAction(m_pAddAction);
     }
-
     menu.exec(m_pInterfacesTree->mapToGlobal(pos));
 }
 
+void UIGlobalSettingsNetwork::appendCacheItem(const CHostNetworkInterface &iface)
+{
+    /* Get DHCP server (create if necessary): */
+    CDHCPServer dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
+    if (dhcp.isNull())
+    {
+        vboxGlobal().virtualBox().CreateDHCPServer(iface.GetNetworkName());
+        dhcp = vboxGlobal().virtualBox().FindDHCPServerByNetworkName(iface.GetNetworkName());
+    }
+    AssertMsg(!dhcp.isNull(), ("DHCP server creation failed!\n"));
+
+    /* Prepare cache item: */
+    UIHostNetworkData data;
+
+    /* Host-only interface settings */
+    data.m_interface.m_strName = iface.GetName();
+    data.m_interface.m_fDhcpClientEnabled = iface.GetDhcpEnabled();
+    data.m_interface.m_strInterfaceAddress = iface.GetIPAddress();
+    data.m_interface.m_strInterfaceMask = iface.GetNetworkMask();
+    data.m_interface.m_fIpv6Supported = iface.GetIPV6Supported();
+    data.m_interface.m_strInterfaceAddress6 = iface.GetIPV6Address();
+    data.m_interface.m_strInterfaceMaskLength6 = QString::number(iface.GetIPV6NetworkMaskPrefixLength());
+
+    /* DHCP server settings: */
+    data.m_dhcpserver.m_fDhcpServerEnabled = dhcp.GetEnabled();
+    data.m_dhcpserver.m_strDhcpServerAddress = dhcp.GetIPAddress();
+    data.m_dhcpserver.m_strDhcpServerMask = dhcp.GetNetworkMask();
+    data.m_dhcpserver.m_strDhcpLowerAddress = dhcp.GetLowerIP();
+    data.m_dhcpserver.m_strDhcpUpperAddress = dhcp.GetUpperIP();
+
+    /* Append cache item: */
+    m_cache.m_items << data;
+}
+
+void UIGlobalSettingsNetwork::removeCacheItem(const QString &strInterfaceName)
+{
+    /* Search for invalidated cache item: */
+    for (int iNetworkIndex = 0; iNetworkIndex < m_cache.m_items.size(); ++iNetworkIndex)
+    {
+        /* Get iterated data: */
+        const UIHostNetworkData &data = m_cache.m_items[iNetworkIndex];
+        if (data.m_interface.m_strName == strInterfaceName)
+        {
+            m_cache.m_items.removeAll(data);
+            break;
+        }
+    }
+}
+
+void UIGlobalSettingsNetwork::appendListItem(const UIHostNetworkData &data)
+{
+    /* Add new item to the list: */
+    UIHostInterfaceItem *pItem = new UIHostInterfaceItem;
+    pItem->fetchNetworkData(data);
+    m_pInterfacesTree->addTopLevelItem(pItem);
+}
+
+void UIGlobalSettingsNetwork::removeListItem(UIHostInterfaceItem *pItem)
+{
+    /* Delete passed item: */
+    delete pItem;
+}
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h	(revision 35547)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsNetwork.h	(revision 35548)
@@ -35,4 +35,14 @@
     QString m_strInterfaceAddress6;
     QString m_strInterfaceMaskLength6;
+    bool operator==(const UIHostInterfaceData &other) const
+    {
+        return m_strName == other.m_strName &&
+               m_fDhcpClientEnabled == other.m_fDhcpClientEnabled &&
+               m_strInterfaceAddress == other.m_strInterfaceAddress &&
+               m_strInterfaceMask == other.m_strInterfaceMask &&
+               m_fIpv6Supported == other.m_fIpv6Supported &&
+               m_strInterfaceAddress6 == other.m_strInterfaceAddress6 &&
+               m_strInterfaceMaskLength6 == other.m_strInterfaceMaskLength6;
+    }
 };
 
@@ -46,4 +56,12 @@
     QString m_strDhcpLowerAddress;
     QString m_strDhcpUpperAddress;
+    bool operator==(const UIDHCPServerData &other) const
+    {
+        return m_fDhcpServerEnabled == other.m_fDhcpServerEnabled &&
+               m_strDhcpServerAddress == other.m_strDhcpServerAddress &&
+               m_strDhcpServerMask == other.m_strDhcpServerMask &&
+               m_strDhcpLowerAddress == other.m_strDhcpLowerAddress &&
+               m_strDhcpUpperAddress == other.m_strDhcpUpperAddress;
+    }
 };
 
@@ -53,4 +71,9 @@
     UIHostInterfaceData m_interface;
     UIDHCPServerData m_dhcpserver;
+    bool operator==(const UIHostNetworkData &other) const
+    {
+        return m_interface == other.m_interface &&
+               m_dhcpserver == other.m_dhcpserver;
+    }
 };
 
@@ -161,4 +184,10 @@
 private:
 
+    /* Helper members: */
+    void appendCacheItem(const CHostNetworkInterface &iface);
+    void removeCacheItem(const QString &strInterfaceName);
+    void appendListItem(const UIHostNetworkData &data);
+    void removeListItem(UIHostInterfaceItem *pItem);
+
     /* Validator: */
     QIWidgetValidator *m_pValidator;
