network preflet: Make InterfaceListItem dumber
* Allows us to use InterfaceListItem for non-physical interface things (like a VPN connection)
This commit is contained in:
parent
476da4a52f
commit
6516aed58b
@ -24,6 +24,7 @@ enum BNetworkSettingsType {
|
||||
B_NETWORK_SETTINGS_TYPE_INTERFACE = 'intf',
|
||||
B_NETWORK_SETTINGS_TYPE_SERVICE = 'serv',
|
||||
B_NETWORK_SETTINGS_TYPE_DIAL_UP = 'dial',
|
||||
B_NETWORK_SETTINGS_TYPE_VPN = 'vpnc',
|
||||
B_NETWORK_SETTINGS_TYPE_OTHER = 'othr'
|
||||
};
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
#include <Catalog.h>
|
||||
#include <ControlLook.h>
|
||||
#include <IconUtils.h>
|
||||
#include <NetworkDevice.h>
|
||||
#include <OutlineListView.h>
|
||||
#include <Resources.h>
|
||||
#include <String.h>
|
||||
@ -32,9 +31,11 @@
|
||||
#define B_TRANSLATION_CONTEXT "InterfaceListItem"
|
||||
|
||||
|
||||
InterfaceListItem::InterfaceListItem(const char* name)
|
||||
InterfaceListItem::InterfaceListItem(const char* name,
|
||||
BNetworkInterfaceType type)
|
||||
:
|
||||
BListItem(0, false),
|
||||
fType(type),
|
||||
fIcon(NULL),
|
||||
fFirstLineOffset(0),
|
||||
fLineOffset(0),
|
||||
@ -166,16 +167,15 @@ InterfaceListItem::ConfigurationUpdated(const BMessage& message)
|
||||
void
|
||||
InterfaceListItem::_Init()
|
||||
{
|
||||
const char* mediaTypeName = NULL;
|
||||
|
||||
BNetworkDevice device(Name());
|
||||
if (device.IsWireless())
|
||||
mediaTypeName = "wifi";
|
||||
else if (device.IsEthernet())
|
||||
mediaTypeName = "ether";
|
||||
|
||||
_PopulateBitmaps(mediaTypeName);
|
||||
// Load the interface icons
|
||||
switch(fType) {
|
||||
default:
|
||||
case B_NETWORK_INTERFACE_TYPE_WIFI:
|
||||
_PopulateBitmaps("wifi");
|
||||
break;
|
||||
case B_NETWORK_INTERFACE_TYPE_ETHERNET:
|
||||
_PopulateBitmaps("ether");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -257,13 +257,19 @@ InterfaceListItem::_UpdateState()
|
||||
fHasLink = fInterface.HasLink();
|
||||
fConnecting = (fInterface.Flags() & IFF_CONFIGURING) != 0;
|
||||
|
||||
BNetworkDevice device(Name());
|
||||
if (device.IsWireless())
|
||||
fSubtitle = B_TRANSLATE("Wireless device");
|
||||
else if (device.IsEthernet())
|
||||
fSubtitle = B_TRANSLATE("Ethernet device");
|
||||
else
|
||||
fSubtitle = "";
|
||||
switch (fType) {
|
||||
case B_NETWORK_INTERFACE_TYPE_WIFI:
|
||||
fSubtitle = B_TRANSLATE("Wireless device");
|
||||
break;
|
||||
case B_NETWORK_INTERFACE_TYPE_ETHERNET:
|
||||
fSubtitle = B_TRANSLATE("Ethernet device");
|
||||
break;
|
||||
case B_NETWORK_INTERFACE_TYPE_VPN:
|
||||
fSubtitle = B_TRANSLATE("VPN connection");
|
||||
break;
|
||||
default:
|
||||
fSubtitle = "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,13 +17,22 @@
|
||||
#include <NetworkSettingsAddOn.h>
|
||||
|
||||
|
||||
enum BNetworkInterfaceType {
|
||||
B_NETWORK_INTERFACE_TYPE_WIFI = 'wifi',
|
||||
B_NETWORK_INTERFACE_TYPE_ETHERNET = 'ethr',
|
||||
B_NETWORK_INTERFACE_TYPE_VPN = 'nvpn',
|
||||
B_NETWORK_INTERFACE_TYPE_OTHER = 'othe',
|
||||
};
|
||||
|
||||
|
||||
class BBitmap;
|
||||
|
||||
|
||||
class InterfaceListItem : public BListItem,
|
||||
public BNetworkKit::BNetworkConfigurationListener {
|
||||
public:
|
||||
InterfaceListItem(const char* name);
|
||||
InterfaceListItem(const char* name,
|
||||
BNetworkInterfaceType type);
|
||||
~InterfaceListItem();
|
||||
|
||||
void DrawItem(BView* owner,
|
||||
@ -42,6 +51,8 @@ private:
|
||||
const char* _StateText() const;
|
||||
|
||||
private:
|
||||
BNetworkInterfaceType fType;
|
||||
|
||||
BBitmap* fIcon;
|
||||
BBitmap* fIconOffline;
|
||||
BBitmap* fIconPending;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <Deskbar.h>
|
||||
#include <Directory.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <NetworkDevice.h>
|
||||
#include <NetworkInterface.h>
|
||||
#include <NetworkNotifications.h>
|
||||
#include <NetworkRoster.h>
|
||||
@ -94,6 +95,7 @@ NetworkWindow::NetworkWindow()
|
||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
|
||||
fServicesItem(NULL),
|
||||
fDialUpItem(NULL),
|
||||
fVPNItem(NULL),
|
||||
fOtherItem(NULL)
|
||||
{
|
||||
// Profiles section
|
||||
@ -336,7 +338,15 @@ NetworkWindow::_ScanInterfaces()
|
||||
if ((interface.Flags() & IFF_LOOPBACK) != 0)
|
||||
continue;
|
||||
|
||||
InterfaceListItem* item = new InterfaceListItem(interface.Name());
|
||||
BNetworkDevice device(interface.Name());
|
||||
BNetworkInterfaceType type = B_NETWORK_INTERFACE_TYPE_OTHER;
|
||||
|
||||
if (device.IsWireless())
|
||||
type = B_NETWORK_INTERFACE_TYPE_WIFI;
|
||||
else if (device.IsEthernet())
|
||||
type = B_NETWORK_INTERFACE_TYPE_ETHERNET;
|
||||
|
||||
InterfaceListItem* item = new InterfaceListItem(interface.Name(), type);
|
||||
item->SetExpanded(true);
|
||||
|
||||
fInterfaceItemMap.insert(std::pair<BString, InterfaceListItem*>(
|
||||
@ -440,6 +450,7 @@ NetworkWindow::_ScanAddOns()
|
||||
|
||||
_SortItemsUnder(fServicesItem);
|
||||
_SortItemsUnder(fDialUpItem);
|
||||
_SortItemsUnder(fVPNItem);
|
||||
_SortItemsUnder(fOtherItem);
|
||||
}
|
||||
|
||||
@ -481,6 +492,11 @@ NetworkWindow::_ListItemFor(BNetworkSettingsType type)
|
||||
fDialUpItem = _CreateItem(B_TRANSLATE("Dial Up"));
|
||||
return fDialUpItem;
|
||||
|
||||
case B_NETWORK_SETTINGS_TYPE_VPN:
|
||||
if (fVPNItem == NULL)
|
||||
fVPNItem = _CreateItem(B_TRANSLATE("VPN"));
|
||||
return fVPNItem;
|
||||
|
||||
case B_NETWORK_SETTINGS_TYPE_OTHER:
|
||||
if (fOtherItem == NULL)
|
||||
fOtherItem = _CreateItem(B_TRANSLATE("Other"));
|
||||
|
@ -78,6 +78,7 @@ private:
|
||||
ItemMap fInterfaceItemMap;
|
||||
BListItem* fServicesItem;
|
||||
BListItem* fDialUpItem;
|
||||
BListItem* fVPNItem;
|
||||
BListItem* fOtherItem;
|
||||
|
||||
SettingsMap fSettingsMap;
|
||||
|
Loading…
Reference in New Issue
Block a user