Implemented interfaces monitoring and disabled state introduced last week.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -80,9 +80,8 @@ our_image(image_info& image)
|
|||||||
InterfaceListItem::InterfaceListItem(const char* name)
|
InterfaceListItem::InterfaceListItem(const char* name)
|
||||||
:
|
:
|
||||||
BListItem(0, false),
|
BListItem(0, false),
|
||||||
fEnabled(true),
|
|
||||||
fIcon(NULL),
|
fIcon(NULL),
|
||||||
fSetting(new Setting(name))
|
fSettings(new Setting(name))
|
||||||
{
|
{
|
||||||
_InitIcon();
|
_InitIcon();
|
||||||
}
|
}
|
||||||
@@ -143,7 +142,7 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
|||||||
BPoint commentPt = iconPt + BPoint(32+8, fntheight*3);
|
BPoint commentPt = iconPt + BPoint(32+8, fntheight*3);
|
||||||
|
|
||||||
drawing_mode mode = owner->DrawingMode();
|
drawing_mode mode = owner->DrawingMode();
|
||||||
if (fEnabled)
|
if (fSettings->Enabled())
|
||||||
owner->SetDrawingMode(B_OP_OVER);
|
owner->SetDrawingMode(B_OP_OVER);
|
||||||
else {
|
else {
|
||||||
owner->SetDrawingMode(B_OP_ALPHA);
|
owner->SetDrawingMode(B_OP_ALPHA);
|
||||||
@@ -153,23 +152,21 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
|||||||
|
|
||||||
owner->DrawBitmapAsync(fIcon, iconPt);
|
owner->DrawBitmapAsync(fIcon, iconPt);
|
||||||
|
|
||||||
if (!fEnabled)
|
if (!fSettings->Enabled())
|
||||||
owner->SetHighColor(tint_color(oldcolor, B_LIGHTEN_1_TINT));
|
owner->SetHighColor(tint_color(oldcolor, B_LIGHTEN_1_TINT));
|
||||||
|
|
||||||
owner->SetFont(be_bold_font);
|
owner->SetFont(be_bold_font);
|
||||||
owner->DrawString(Name(), namePt);
|
owner->DrawString(Name(), namePt);
|
||||||
owner->SetFont(be_plain_font);
|
owner->SetFont(be_plain_font);
|
||||||
|
|
||||||
if (fEnabled) {
|
if (fSettings->Enabled()) {
|
||||||
BString str("Enabled, IPv4 address: ");
|
BString str("Enabled, IPv4 address: ");
|
||||||
str << fSetting->IP();
|
str << fSettings->IP();
|
||||||
owner->DrawString(str.String(), driverPt);
|
owner->DrawString(str.String(), driverPt);
|
||||||
if (fSetting->AutoConfigured())
|
if (fSettings->AutoConfigured())
|
||||||
owner->DrawString("DHCP enabled", commentPt);
|
owner->DrawString("DHCP enabled", commentPt);
|
||||||
else
|
else
|
||||||
owner->DrawString("DHCP disabled, use static IP address", commentPt);
|
owner->DrawString("DHCP disabled, use static IP address", commentPt);
|
||||||
|
|
||||||
|
|
||||||
} else
|
} else
|
||||||
owner->DrawString("Disabled.", driverPt);
|
owner->DrawString("Disabled.", driverPt);
|
||||||
|
|
||||||
@@ -184,7 +181,7 @@ InterfaceListItem::_InitIcon()
|
|||||||
BBitmap* icon = NULL;
|
BBitmap* icon = NULL;
|
||||||
|
|
||||||
const char* mediaTypeName = "";
|
const char* mediaTypeName = "";
|
||||||
int media = fSetting->Media();
|
int media = fSettings->Media();
|
||||||
printf("%s media = 0x%x\n", Name(), media);
|
printf("%s media = 0x%x\n", Name(), media);
|
||||||
switch (IFM_TYPE(media)) {
|
switch (IFM_TYPE(media)) {
|
||||||
case IFM_ETHER:
|
case IFM_ETHER:
|
||||||
@@ -273,8 +270,7 @@ InterfacesListView::MessageReceived(BMessage* message)
|
|||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case B_NETWORK_MONITOR:
|
case B_NETWORK_MONITOR:
|
||||||
message->PrintToStream();
|
_HandleNetworkMessage(message);
|
||||||
_UpdateList();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -331,10 +327,10 @@ InterfacesListView::_InitList()
|
|||||||
MakeEmpty();
|
MakeEmpty();
|
||||||
|
|
||||||
for (uint32 i = 0; i < count; i++) {
|
for (uint32 i = 0; i < count; i++) {
|
||||||
// if (strcmp(interface->ifr_name, "loop") != 0) {
|
if (strcmp(interface->ifr_name, "loop") != 0) {
|
||||||
AddItem(new InterfaceListItem(interface->ifr_name));
|
AddItem(new InterfaceListItem(interface->ifr_name));
|
||||||
// printf("Name = %s\n", interface->ifr_name);
|
// printf("Name = %s\n", interface->ifr_name);
|
||||||
// }
|
}
|
||||||
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
|
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
|
||||||
+ interface->ifr_addr.sa_len);
|
+ interface->ifr_addr.sa_len);
|
||||||
}
|
}
|
||||||
@@ -349,3 +345,44 @@ InterfacesListView::_UpdateList()
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
InterfacesListView::_HandleNetworkMessage(BMessage* message)
|
||||||
|
{
|
||||||
|
const char* name;
|
||||||
|
int32 opcode;
|
||||||
|
|
||||||
|
message->PrintToStream();
|
||||||
|
|
||||||
|
if (message->FindInt32("opcode", &opcode) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (message->FindString("interface", &name) != B_OK
|
||||||
|
&& message->FindString("device", &name) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
InterfaceListItem* item = FindItem(name);
|
||||||
|
if (!item)
|
||||||
|
printf("InterfaceListItem %s not found!\n", name);
|
||||||
|
|
||||||
|
switch (opcode) {
|
||||||
|
case B_NETWORK_INTERFACE_CHANGED:
|
||||||
|
case B_NETWORK_DEVICE_LINK_CHANGED:
|
||||||
|
if (item)
|
||||||
|
InvalidateItem(IndexOf(item));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_NETWORK_INTERFACE_ADDED:
|
||||||
|
if (item)
|
||||||
|
InvalidateItem(IndexOf(item));
|
||||||
|
else
|
||||||
|
AddItem(new InterfaceListItem(name));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_NETWORK_INTERFACE_REMOVED:
|
||||||
|
if (item) {
|
||||||
|
RemoveItem(item);
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,17 +31,16 @@ public:
|
|||||||
void DrawItem(BView* owner, BRect bounds, bool complete);
|
void DrawItem(BView* owner, BRect bounds, bool complete);
|
||||||
void Update(BView* owner, const BFont* font);
|
void Update(BView* owner, const BFont* font);
|
||||||
|
|
||||||
inline const char* Name() { return fSetting->Name(); }
|
inline const char* Name() { return fSettings->Name(); }
|
||||||
inline bool Enabled() { return fEnabled; }
|
inline bool Enabled() { return fSettings->Enabled(); }
|
||||||
inline void SetEnabled(bool enable){ fEnabled = enable; }
|
inline void SetEnabled(bool enable){ fSettings->Enable(enable); }
|
||||||
inline Setting* GetSetting() { return fSetting; }
|
inline Setting* GetSetting() { return fSettings; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _InitIcon();
|
void _InitIcon();
|
||||||
|
|
||||||
bool fEnabled;
|
|
||||||
BBitmap* fIcon;
|
BBitmap* fIcon;
|
||||||
Setting* fSetting;
|
Setting* fSettings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -62,6 +61,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
status_t _InitList();
|
status_t _InitList();
|
||||||
status_t _UpdateList();
|
status_t _UpdateList();
|
||||||
|
void _HandleNetworkMessage(BMessage* message);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /*INTERFACES_LIST_VIEW_H*/
|
#endif /*INTERFACES_LIST_VIEW_H*/
|
||||||
|
|||||||
@@ -34,7 +34,8 @@
|
|||||||
|
|
||||||
Setting::Setting(const char *name)
|
Setting::Setting(const char *name)
|
||||||
:
|
:
|
||||||
fAuto(true)
|
fAuto(true),
|
||||||
|
fEnabled(false)
|
||||||
{
|
{
|
||||||
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
fName = name;
|
fName = name;
|
||||||
@@ -149,6 +150,7 @@ Setting::ReadConfiguration()
|
|||||||
flags = request.ifr_flags;
|
flags = request.ifr_flags;
|
||||||
|
|
||||||
fAuto = (flags & IFF_AUTO_CONFIGURED) != 0;
|
fAuto = (flags & IFF_AUTO_CONFIGURED) != 0;
|
||||||
|
fEnabled = (flags & IFF_UP) != 0;
|
||||||
|
|
||||||
if (ioctl(fSocket, SIOCGIFMEDIA, &request, sizeof(struct ifreq)) == 0)
|
if (ioctl(fSocket, SIOCGIFMEDIA, &request, sizeof(struct ifreq)) == 0)
|
||||||
fMedia = request.ifr_media;
|
fMedia = request.ifr_media;
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ class Setting {
|
|||||||
void SetGateway(BString ip) {fGateway = ip; }
|
void SetGateway(BString ip) {fGateway = ip; }
|
||||||
void SetNetmask(BString ip) {fNetmask = ip; }
|
void SetNetmask(BString ip) {fNetmask = ip; }
|
||||||
void SetAutoConfigure(bool t) {fAuto = t; }
|
void SetAutoConfigure(bool t) {fAuto = t; }
|
||||||
|
void Enable(bool enable) { fEnabled = enable; }
|
||||||
|
|
||||||
const char* IP() {return fIP.String(); }
|
const char* IP() {return fIP.String(); }
|
||||||
const char* Gateway() {return fGateway.String(); }
|
const char* Gateway() {return fGateway.String(); }
|
||||||
const char* Netmask() {return fNetmask.String(); }
|
const char* Netmask() {return fNetmask.String(); }
|
||||||
const char* Name() {return fName.String(); }
|
const char* Name() {return fName.String(); }
|
||||||
bool AutoConfigured() {return fAuto; }
|
bool AutoConfigured() {return fAuto; }
|
||||||
|
bool Enabled() { return fEnabled; }
|
||||||
int Media() { return fMedia; }
|
int Media() { return fMedia; }
|
||||||
BObjectList<BString> fNameservers;
|
BObjectList<BString> fNameservers;
|
||||||
void ReadConfiguration();
|
void ReadConfiguration();
|
||||||
@@ -41,6 +43,7 @@ class Setting {
|
|||||||
BString fNetmask;
|
BString fNetmask;
|
||||||
BString fName;
|
BString fName;
|
||||||
bool fAuto;
|
bool fAuto;
|
||||||
|
bool fEnabled;
|
||||||
int fMedia;
|
int fMedia;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user