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>
|
#include <Alert.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NetworkSetupAddOn*
|
NetworkSetupAddOn*
|
||||||
get_nth_addon(image_id image, int index)
|
get_nth_addon(image_id image, int index)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,4 +56,18 @@ resource(1, "wifi") #'VICN' array {
|
|||||||
$"22040A000200021001178622040A020201031001178222040A01020002100117"
|
$"22040A000200021001178622040A020201031001178222040A01020002100117"
|
||||||
$"8222040A0001041001178400040A03010400"
|
$"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 -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
@@ -94,6 +104,7 @@ void
|
|||||||
InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
||||||
{
|
{
|
||||||
BListView* list = dynamic_cast<BListView*>(owner);
|
BListView* list = dynamic_cast<BListView*>(owner);
|
||||||
|
BBitmap* stateIcon(NULL);
|
||||||
BString interfaceState;
|
BString interfaceState;
|
||||||
|
|
||||||
if (!list)
|
if (!list)
|
||||||
@@ -118,10 +129,16 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
|||||||
|
|
||||||
if (fSettings->IsDisabled()) {
|
if (fSettings->IsDisabled()) {
|
||||||
interfaceState << "disabled";
|
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;
|
interfaceState << "connecting" B_UTF8_ELLIPSIS;
|
||||||
} else { /*if (fSettings->IsConnected()) {*/
|
stateIcon = fIconPending;
|
||||||
|
} else {
|
||||||
interfaceState << "connected";
|
interfaceState << "connected";
|
||||||
|
stateIcon = fIconOnline;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the initial bounds of item contents
|
// 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->SetDrawingMode(B_OP_OVER);
|
||||||
|
|
||||||
list->DrawBitmapAsync(fIcon, iconPt);
|
list->DrawBitmapAsync(fIcon, iconPt);
|
||||||
|
list->DrawBitmapAsync(stateIcon, iconPt);
|
||||||
|
|
||||||
if (fSettings->IsDisabled())
|
if (fSettings->IsDisabled())
|
||||||
list->SetHighColor(tint_color(black, B_LIGHTEN_1_TINT));
|
list->SetHighColor(tint_color(black, B_LIGHTEN_1_TINT));
|
||||||
@@ -163,6 +181,8 @@ InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
|
|||||||
if (!fSettings->IsDisabled()) {
|
if (!fSettings->IsDisabled()) {
|
||||||
BString v4str("IPv4: ");
|
BString v4str("IPv4: ");
|
||||||
v4str << fSettings->IP();
|
v4str << fSettings->IP();
|
||||||
|
v4str << " /";
|
||||||
|
v4str << netmaskbitcount(fSettings->Netmask());
|
||||||
v4str << " (";
|
v4str << " (";
|
||||||
if (fSettings->AutoConfigure())
|
if (fSettings->AutoConfigure())
|
||||||
v4str << "DHCP";
|
v4str << "DHCP";
|
||||||
@@ -184,9 +204,6 @@ InterfaceListItem::_Init()
|
|||||||
{
|
{
|
||||||
fSettings = new Settings(Name());
|
fSettings = new Settings(Name());
|
||||||
|
|
||||||
// Init icon
|
|
||||||
BBitmap* icon = NULL;
|
|
||||||
|
|
||||||
const char* mediaTypeName = NULL;
|
const char* mediaTypeName = NULL;
|
||||||
|
|
||||||
int media = fInterface.Media();
|
int media = fInterface.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;
|
image_info info;
|
||||||
if (our_image(info) != B_OK)
|
if (our_image(info) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BFile file(info.name, B_READ_ONLY);
|
BFile resourcesFile(info.name, B_READ_ONLY);
|
||||||
if (file.InitCheck() < B_OK)
|
if (resourcesFile.InitCheck() < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BResources resources(&file);
|
BResources addonResources(&resourcesFile);
|
||||||
if (resources.InitCheck() < B_OK)
|
|
||||||
|
if (addonResources.InitCheck() < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
size_t size;
|
size_t iconSize;
|
||||||
|
|
||||||
// Try specific interface icon?
|
// Try specific interface icon?
|
||||||
const uint8* rawIcon = (const uint8*)resources.LoadResource(
|
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource(
|
||||||
B_VECTOR_ICON_TYPE, Name(), &size);
|
B_VECTOR_ICON_TYPE, Name(), &iconSize);
|
||||||
|
|
||||||
if (rawIcon == NULL && mediaTypeName != NULL)
|
if (HVIFInterfaceIcon == NULL && mediaType != NULL)
|
||||||
// Not found, try interface media type?
|
// Not found, try interface media type?
|
||||||
rawIcon = (const uint8*)resources.LoadResource(
|
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource(
|
||||||
B_VECTOR_ICON_TYPE, mediaTypeName, &size);
|
B_VECTOR_ICON_TYPE, mediaType, &iconSize);
|
||||||
if (rawIcon == NULL)
|
if (HVIFInterfaceIcon == NULL)
|
||||||
// Not found, try default interface icon?
|
// Not found, try default interface icon?
|
||||||
rawIcon = (const uint8*)resources.LoadResource(
|
HVIFInterfaceIcon = (const uint8*)addonResources.LoadResource(
|
||||||
B_VECTOR_ICON_TYPE, "ether", &size);
|
B_VECTOR_ICON_TYPE, "ether", &iconSize);
|
||||||
|
|
||||||
if (rawIcon) {
|
if (HVIFInterfaceIcon) {
|
||||||
// Now build the bitmap
|
// Now build the bitmap
|
||||||
icon = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
interfaceBitmap = new BBitmap(BRect(0, 0, 31, 31), 0, B_RGBA32);
|
||||||
if (BIconUtils::GetVectorIcon(rawIcon, size, icon) == B_OK)
|
if (BIconUtils::GetVectorIcon(HVIFInterfaceIcon,
|
||||||
fIcon = icon;
|
iconSize, interfaceBitmap) == B_OK)
|
||||||
|
fIcon = interfaceBitmap;
|
||||||
else
|
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.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Philippe Houdoin
|
* Philippe Houdoin
|
||||||
* Fredrik Modéen
|
* Fredrik Modéen
|
||||||
|
* Alexander von Gluck, [email protected]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -25,23 +26,35 @@
|
|||||||
|
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
|
||||||
|
|
||||||
|
int netmaskbitcount(const char* buf);
|
||||||
|
|
||||||
|
|
||||||
class InterfaceListItem : public BListItem {
|
class InterfaceListItem : public BListItem {
|
||||||
public:
|
public:
|
||||||
InterfaceListItem(const char* name);
|
InterfaceListItem(const char* name);
|
||||||
~InterfaceListItem();
|
~InterfaceListItem();
|
||||||
|
|
||||||
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 fInterface.Name(); }
|
inline const char* Name() {return fInterface.Name();}
|
||||||
inline bool IsDisabled() { return fSettings->IsDisabled(); }
|
inline bool IsDisabled() {
|
||||||
inline void SetDisabled(bool disable){ fSettings->SetDisabled(disable); }
|
return fSettings->IsDisabled();}
|
||||||
inline Settings* GetSettings() { return fSettings; }
|
inline void SetDisabled(bool disable) {
|
||||||
|
fSettings->SetDisabled(disable);}
|
||||||
|
inline Settings* GetSettings() {return fSettings;}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init();
|
void _Init();
|
||||||
|
void _PopulateBitmaps(const char* mediaType);
|
||||||
|
|
||||||
BBitmap* fIcon;
|
BBitmap* fIcon;
|
||||||
|
BBitmap* fIconOffline;
|
||||||
|
BBitmap* fIconPending;
|
||||||
|
BBitmap* fIconOnline;
|
||||||
|
|
||||||
BNetworkInterface fInterface;
|
BNetworkInterface fInterface;
|
||||||
Settings* fSettings;
|
Settings* fSettings;
|
||||||
float fFirstlineOffset;
|
float fFirstlineOffset;
|
||||||
@@ -54,7 +67,9 @@ private:
|
|||||||
class InterfacesListView : public BListView {
|
class InterfacesListView : public BListView {
|
||||||
public:
|
public:
|
||||||
InterfacesListView(BRect rect, const char* name,
|
InterfacesListView(BRect rect, const char* name,
|
||||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
uint32 resizingMode
|
||||||
|
= B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||||
|
|
||||||
virtual ~InterfacesListView();
|
virtual ~InterfacesListView();
|
||||||
|
|
||||||
InterfaceListItem* FindItem(const char* name);
|
InterfaceListItem* FindItem(const char* name);
|
||||||
|
|||||||
Reference in New Issue
Block a user