added small function to convert netmask to cidr; added customized overlay HVIF status icons to list view items thanks to NetworkStatus; code cleanup and reorganization
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40349 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -23,7 +23,6 @@
|
||||
#include <Alert.h>
|
||||
|
||||
|
||||
|
||||
NetworkSetupAddOn*
|
||||
get_nth_addon(image_id image, int index)
|
||||
{
|
||||
@@ -79,7 +78,7 @@ InterfacesAddOn::CreateView(BRect *bounds)
|
||||
fListview->SetSelectionMessage(new BMessage(INTERFACE_SELECTED_MSG));
|
||||
fListview->SetInvocationMessage(new BMessage(CONFIGURE_INTERFACE_MSG));
|
||||
AddChild(new BScrollView(NULL, fListview, B_FOLLOW_ALL_SIDES, B_WILL_DRAW
|
||||
| B_FRAME_EVENTS, false, true));
|
||||
| B_FRAME_EVENTS, false, true));
|
||||
|
||||
r.top = r.bottom - 60;
|
||||
fConfigure = new BButton(r, "configure", "Configure" B_UTF8_ELLIPSIS,
|
||||
@@ -93,8 +92,8 @@ InterfacesAddOn::CreateView(BRect *bounds)
|
||||
r.left += w + SMALL_MARGIN;
|
||||
|
||||
fOnOff = new BButton(r, "onoff", "Disable",
|
||||
new BMessage(ONOFF_INTERFACE_MSG),
|
||||
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT);
|
||||
new BMessage(ONOFF_INTERFACE_MSG),
|
||||
B_FOLLOW_BOTTOM | B_FOLLOW_LEFT);
|
||||
fOnOff->GetPreferredSize(&w, &h);
|
||||
fOnOff->ResizeToPreferred();
|
||||
fOnOff->Hide();
|
||||
|
||||
@@ -56,4 +56,18 @@ resource(1, "wifi") #'VICN' array {
|
||||
$"22040A000200021001178622040A020201031001178222040A01020002100117"
|
||||
$"8222040A0001041001178400040A03010400"
|
||||
};
|
||||
resource(2, "online") #'VICN' array {
|
||||
$"6E63696603050004016E020006023959B6382F60BA2F603B59B64B80504AE1D3"
|
||||
$"0056FF22FF05D005010204554FC96F4FC6CC4F4F554FC6CC4FC96F555BC6CC5B"
|
||||
$"C96F5B5B555BC96F5BC6CC020A0001001001178800040A02010000"
|
||||
};
|
||||
|
||||
resource(3, "warning") #'VICN' array {
|
||||
$"6E6369660205000200060238DB5A38CCBABACCBA3ADB5A4B8BE14AD7C900FFF3"
|
||||
$"75FFFFA406010A034F4F555B5B4F020A0001001001178802040A01010000"
|
||||
};
|
||||
|
||||
resource(4, "offline") #'VICN' array {
|
||||
$"6E6369660205000200060238DB5A38CCBABACCBA3ADB5A4BBBE14B07C900FF88"
|
||||
$"75FFFF0505010A044F4F4F5B5B5B5B4F020A0001001001178802040A01010000"
|
||||
};
|
||||
|
||||
@@ -52,6 +52,16 @@ our_image(image_info& image)
|
||||
}
|
||||
|
||||
|
||||
/* Takes the provided ip-style netmask and converts
|
||||
* it to an unsigned int, then counts the binary 1's
|
||||
*/
|
||||
int
|
||||
netmaskbitcount(const char* buf)
|
||||
{
|
||||
return(__builtin_popcount(inet_addr(buf)));
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
@@ -93,8 +103,9 @@ InterfaceListItem::Update(BView* owner, const BFont* font)
|
||||
void
|
||||
InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
{
|
||||
BListView* list = dynamic_cast<BListView*>(owner);
|
||||
BString interfaceState;
|
||||
BListView* list = dynamic_cast<BListView*>(owner);
|
||||
BBitmap* stateIcon(NULL);
|
||||
BString interfaceState;
|
||||
|
||||
if (!list)
|
||||
return;
|
||||
@@ -118,10 +129,16 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
|
||||
if (fSettings->IsDisabled()) {
|
||||
interfaceState << "disabled";
|
||||
} else if ( !fSettings->IP() && fSettings->AutoConfigure()) {
|
||||
stateIcon = fIconOffline;
|
||||
} else if (!fInterface.HasLink()) {
|
||||
interfaceState << "no link";
|
||||
stateIcon = fIconOffline;
|
||||
} else if (!fSettings->IP() && fSettings->AutoConfigure()) {
|
||||
interfaceState << "connecting" B_UTF8_ELLIPSIS;
|
||||
} else { /*if (fSettings->IsConnected()) {*/
|
||||
stateIcon = fIconPending;
|
||||
} else {
|
||||
interfaceState << "connected";
|
||||
stateIcon = fIconOnline;
|
||||
}
|
||||
|
||||
// Set the initial bounds of item contents
|
||||
@@ -148,6 +165,7 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
list->SetDrawingMode(B_OP_OVER);
|
||||
|
||||
list->DrawBitmapAsync(fIcon, iconPt);
|
||||
list->DrawBitmapAsync(stateIcon, iconPt);
|
||||
|
||||
if (fSettings->IsDisabled())
|
||||
list->SetHighColor(tint_color(black, B_LIGHTEN_1_TINT));
|
||||
@@ -163,6 +181,8 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||
if (!fSettings->IsDisabled()) {
|
||||
BString v4str("IPv4: ");
|
||||
v4str << fSettings->IP();
|
||||
v4str << " /";
|
||||
v4str << netmaskbitcount(fSettings->Netmask());
|
||||
v4str << " (";
|
||||
if (fSettings->AutoConfigure())
|
||||
v4str << "DHCP";
|
||||
@@ -184,10 +204,7 @@ InterfaceListItem::_Init()
|
||||
{
|
||||
fSettings = new Settings(Name());
|
||||
|
||||
// Init icon
|
||||
BBitmap* icon = NULL;
|
||||
|
||||
const char* mediaTypeName = NULL;
|
||||
const char* mediaTypeName = NULL;
|
||||
|
||||
int media = fInterface.Media();
|
||||
printf("%s media = 0x%x\n", Name(), media);
|
||||
@@ -208,40 +225,86 @@ InterfaceListItem::_Init()
|
||||
}
|
||||
}
|
||||
|
||||
_PopulateBitmaps(mediaTypeName);
|
||||
// Load the interface icons
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InterfaceListItem::_PopulateBitmaps(const char* mediaType) {
|
||||
|
||||
const uint8* HVIFInterfaceIcon;
|
||||
const uint8* HVIFOffline;
|
||||
const uint8* HVIFPending;
|
||||
const uint8* HVIFOnline;
|
||||
|
||||
BBitmap* interfaceBitmap = NULL;
|
||||
|
||||
/* Load interface icons */
|
||||
image_info info;
|
||||
if (our_image(info) != B_OK)
|
||||
return;
|
||||
|
||||
BFile file(info.name, B_READ_ONLY);
|
||||
if (file.InitCheck() < B_OK)
|
||||
BFile resourcesFile(info.name, B_READ_ONLY);
|
||||
if (resourcesFile.InitCheck() < B_OK)
|
||||
return;
|
||||
|
||||
BResources resources(&file);
|
||||
if (resources.InitCheck() < B_OK)
|
||||
BResources addonResources(&resourcesFile);
|
||||
|
||||
if (addonResources.InitCheck() < B_OK)
|
||||
return;
|
||||
|
||||
size_t size;
|
||||
size_t iconSize;
|
||||
|
||||
// Try specific interface icon?
|
||||
const uint8* rawIcon = (const uint8*)resources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, Name(), &size);
|
||||
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, Name(), &iconSize);
|
||||
|
||||
if (rawIcon == NULL && mediaTypeName != NULL)
|
||||
if (HVIFInterfaceIcon == NULL && mediaType != NULL)
|
||||
// Not found, try interface media type?
|
||||
rawIcon = (const uint8*)resources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, mediaTypeName, &size);
|
||||
if (rawIcon == NULL)
|
||||
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, mediaType, &iconSize);
|
||||
if (HVIFInterfaceIcon == NULL)
|
||||
// Not found, try default interface icon?
|
||||
rawIcon = (const uint8*)resources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, "ether", &size);
|
||||
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, "ether", &iconSize);
|
||||
|
||||
if (rawIcon) {
|
||||
if (HVIFInterfaceIcon) {
|
||||
// Now build the bitmap
|
||||
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||
if (BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK)
|
||||
fIcon = icon;
|
||||
interfaceBitmap = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||
if (BIconUtils::GetVectorIcon(HVIFInterfaceIcon,
|
||||
iconSize, interfaceBitmap) == B_OK)
|
||||
fIcon = interfaceBitmap;
|
||||
else
|
||||
delete icon;
|
||||
delete interfaceBitmap;
|
||||
}
|
||||
|
||||
// Load possible state icons
|
||||
HVIFOffline = (const uint8*)addonResources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, "offline", &iconSize);
|
||||
|
||||
if (HVIFOffline) {
|
||||
fIconOffline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||
BIconUtils::GetVectorIcon(HVIFOffline, iconSize, fIconOffline);
|
||||
}
|
||||
|
||||
HVIFPending = (const uint8*)addonResources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, "pending", &iconSize);
|
||||
|
||||
if (HVIFPending) {
|
||||
fIconOffline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||
BIconUtils::GetVectorIcon(HVIFPending, iconSize, fIconPending);
|
||||
}
|
||||
|
||||
HVIFOnline = (const uint8*)addonResources.LoadResource(
|
||||
B_VECTOR_ICON_TYPE, "online", &iconSize);
|
||||
|
||||
if (HVIFOnline) {
|
||||
fIconOnline = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||
BIconUtils::GetVectorIcon(HVIFOnline, iconSize, fIconOnline);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
/*
|
||||
* Copyright 2004-2009 Haiku Inc. All rights reserved.
|
||||
* Copyright 2004-2011 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Philippe Houdoin
|
||||
* Fredrik Modéen
|
||||
* Fredrik Modéen
|
||||
* Alexander von Gluck, [email protected]
|
||||
*/
|
||||
|
||||
|
||||
@@ -25,50 +26,64 @@
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
|
||||
int netmaskbitcount(const char* buf);
|
||||
|
||||
|
||||
class InterfaceListItem : public BListItem {
|
||||
public:
|
||||
InterfaceListItem(const char* name);
|
||||
~InterfaceListItem();
|
||||
InterfaceListItem(const char* name);
|
||||
~InterfaceListItem();
|
||||
|
||||
void DrawItem(BView* owner, BRect bounds, bool complete);
|
||||
void Update(BView* owner, const BFont* font);
|
||||
void DrawItem(BView* owner,
|
||||
BRect bounds, bool complete);
|
||||
void Update(BView* owner, const BFont* font);
|
||||
|
||||
inline const char* Name() { return fInterface.Name(); }
|
||||
inline bool IsDisabled() { return fSettings->IsDisabled(); }
|
||||
inline void SetDisabled(bool disable){ fSettings->SetDisabled(disable); }
|
||||
inline Settings* GetSettings() { return fSettings; }
|
||||
inline const char* Name() {return fInterface.Name();}
|
||||
inline bool IsDisabled() {
|
||||
return fSettings->IsDisabled();}
|
||||
inline void SetDisabled(bool disable) {
|
||||
fSettings->SetDisabled(disable);}
|
||||
inline Settings* GetSettings() {return fSettings;}
|
||||
|
||||
private:
|
||||
void _Init();
|
||||
void _Init();
|
||||
void _PopulateBitmaps(const char* mediaType);
|
||||
|
||||
BBitmap* fIcon;
|
||||
BNetworkInterface fInterface;
|
||||
Settings* fSettings;
|
||||
float fFirstlineOffset;
|
||||
float fSecondlineOffset;
|
||||
float fThirdlineOffset;
|
||||
float fStateWidth;
|
||||
BBitmap* fIcon;
|
||||
BBitmap* fIconOffline;
|
||||
BBitmap* fIconPending;
|
||||
BBitmap* fIconOnline;
|
||||
|
||||
BNetworkInterface fInterface;
|
||||
Settings* fSettings;
|
||||
float fFirstlineOffset;
|
||||
float fSecondlineOffset;
|
||||
float fThirdlineOffset;
|
||||
float fStateWidth;
|
||||
};
|
||||
|
||||
|
||||
class InterfacesListView : public BListView {
|
||||
public:
|
||||
InterfacesListView(BRect rect, const char* name,
|
||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||
virtual ~InterfacesListView();
|
||||
InterfacesListView(BRect rect, const char* name,
|
||||
uint32 resizingMode
|
||||
= B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||
|
||||
InterfaceListItem* FindItem(const char* name);
|
||||
virtual ~InterfacesListView();
|
||||
|
||||
InterfaceListItem* FindItem(const char* name);
|
||||
|
||||
protected:
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void AttachedToWindow();
|
||||
virtual void DetachedFromWindow();
|
||||
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
status_t _InitList();
|
||||
status_t _UpdateList();
|
||||
void _HandleNetworkMessage(BMessage* message);
|
||||
status_t _InitList();
|
||||
status_t _UpdateList();
|
||||
void _HandleNetworkMessage(BMessage* message);
|
||||
};
|
||||
|
||||
#endif /*INTERFACES_LIST_VIEW_H*/
|
||||
|
||||
Reference in New Issue
Block a user