* Renamed StatusAddOn to InterfacesAddOn.
* Made the interfaces list a more self-contained InterfacesListView object
  Now watch for network notifications, but does nothing yet with those.
* Small style changes (but still not compliant). 


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33212 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin
2009-09-20 23:03:44 +00:00
parent e58942cfd7
commit 47e4e5b32b
17 changed files with 454 additions and 303 deletions
@@ -193,19 +193,19 @@ EthernetSettingsView::_ShowConfiguration(Setting* setting)
fTypeMenuField->SetEnabled(setting != NULL);
if (setting) {
fIPTextControl->SetText(setting->GetIP());
fGatewayTextControl->SetText(setting->GetGateway());
fNetMaskTextControl->SetText(setting->GetNetmask());
fIPTextControl->SetText(setting->IP());
fGatewayTextControl->SetText(setting->Gateway());
fNetMaskTextControl->SetText(setting->Netmask());
BMenuItem* item;
if (setting->GetAutoConfigure() == true)
if (setting->AutoConfigured() == true)
item = fTypeMenuField->Menu()->FindItem("DHCP");
else
item = fTypeMenuField->Menu()->FindItem("Static");
if (item)
item->SetMarked(true);
enableControls = setting->GetAutoConfigure() == false;
enableControls = setting->AutoConfigured() == false;
if (setting->fNameservers.CountItems() >= 2) {
fSecondaryDNSTextControl->SetText(
@@ -219,7 +219,7 @@ EthernetSettingsView::_ShowConfiguration(Setting* setting)
}
//We don't want to enable loop
if (strcmp(fCurrentSettings->GetName(), "loop") == 0) {
if (strcmp(fCurrentSettings->Name(), "loop") == 0) {
_EnableTextControls(false);
fTypeMenuField->SetEnabled(false);
} else
@@ -268,8 +268,8 @@ EthernetSettingsView::_SaveConfiguration()
_ApplyControlsToConfiguration();
_SaveDNSConfiguration();
_SaveAdaptersConfiguration();
if (fCurrentSettings->GetAutoConfigure())
_TriggerAutoConfig(fCurrentSettings->GetName());
if (fCurrentSettings->AutoConfigured())
_TriggerAutoConfig(fCurrentSettings->Name());
}
@@ -305,7 +305,7 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
return;
FILE* fp = NULL;
if (fCurrentSettings->GetAutoConfigure())
if (fCurrentSettings->AutoConfigured())
return;
if (fp == NULL) {
@@ -317,11 +317,11 @@ EthernetSettingsView::_SaveAdaptersConfiguration()
}
}
fprintf(fp, "interface %s {\n\t\taddress {\n",fCurrentSettings->GetName());
fprintf(fp, "interface %s {\n\t\taddress {\n",fCurrentSettings->Name());
fprintf(fp, "\t\t\tfamily\tinet\n");
fprintf(fp, "\t\t\taddress\t%s\n",fCurrentSettings->GetIP());
fprintf(fp, "\t\t\tgateway\t%s\n",fCurrentSettings->GetGateway());
fprintf(fp, "\t\t\tmask\t%s\n",fCurrentSettings->GetNetmask());
fprintf(fp, "\t\t\taddress\t%s\n",fCurrentSettings->IP());
fprintf(fp, "\t\t\tgateway\t%s\n",fCurrentSettings->Gateway());
fprintf(fp, "\t\t\tmask\t%s\n",fCurrentSettings->Netmask());
fprintf(fp, "\t\t}\n}\n\n");
if (fp) {
@@ -445,7 +445,7 @@ EthernetSettingsView::MessageReceived(BMessage* message)
case kMsgChange:
fErrorMessage->SetText("");
//We don't want to enable loop
if (strcmp(fCurrentSettings->GetName(), "loop") == 0)
if (strcmp(fCurrentSettings->Name(), "loop") == 0)
fApplyButton->SetEnabled(false);
else
fApplyButton->SetEnabled(true);
@@ -13,32 +13,30 @@
*/
#include "NetworkStatusAddOn.h"
#include <net/if.h>
#include <sys/sockio.h>
#include "InterfacesAddOn.h"
#include "InterfacesListView.h"
#include "NetworkWindow.h"
#include <stdio.h>
#include <AutoDeleter.h>
#include <ScrollView.h>
#include <Alert.h>
#include "InterfaceStatusItem.h"
#include "NetworkWindow.h"
NetworkSetupAddOn*
get_nth_addon(image_id image, int index)
{
if (index == 0)
return new NetworkStatusAddOn(image);
return new InterfacesAddOn(image);
return NULL;
}
// #pragma mark -
NetworkStatusAddOn::NetworkStatusAddOn(image_id image)
InterfacesAddOn::InterfacesAddOn(image_id image)
:
NetworkSetupAddOn(image),
BBox(BRect(0, 0, 0, 0), NULL, B_FOLLOW_ALL, B_NAVIGABLE_JUMP, B_NO_BORDER)
@@ -46,20 +44,20 @@ NetworkStatusAddOn::NetworkStatusAddOn(image_id image)
}
NetworkStatusAddOn::~NetworkStatusAddOn()
InterfacesAddOn::~InterfacesAddOn()
{
}
const char*
NetworkStatusAddOn::Name()
InterfacesAddOn::Name()
{
return "Overview";
return "Interfaces";
}
BView*
NetworkStatusAddOn::CreateView(BRect *bounds)
InterfacesAddOn::CreateView(BRect *bounds)
{
float w, h;
BRect r = *bounds;
@@ -77,8 +75,7 @@ NetworkStatusAddOn::CreateView(BRect *bounds)
rlv.bottom -= 72;
rlv.InsetBy(2, 2);
rlv.right -= B_V_SCROLL_BAR_WIDTH;
fListview = new BListView(rlv, NULL, B_SINGLE_SELECTION_LIST,
B_FOLLOW_ALL_SIDES);
fListview = new InterfacesListView(rlv, "interfaces", B_FOLLOW_ALL_SIDES);
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
@@ -102,16 +99,13 @@ NetworkStatusAddOn::CreateView(BRect *bounds)
fOnOff->Hide();
AddChild(fOnOff);
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
_LookupDevices();
*bounds = Bounds();
return this;
}
void
NetworkStatusAddOn::AttachedToWindow()
InterfacesAddOn::AttachedToWindow()
{
fListview->SetTarget(this);
fConfigure->SetTarget(this);
@@ -121,19 +115,16 @@ NetworkStatusAddOn::AttachedToWindow()
void
NetworkStatusAddOn::MessageReceived(BMessage* msg)
InterfacesAddOn::MessageReceived(BMessage* msg)
{
int nr = fListview->CurrentSelection();
InterfaceStatusItem *item = NULL;
InterfaceListItem *item = NULL;
if(nr != -1) {
item = dynamic_cast<InterfaceStatusItem*>(fListview->ItemAt(nr));
item = dynamic_cast<InterfaceListItem*>(fListview->ItemAt(nr));
}
switch (msg->what) {
case INTERFACE_SELECTED_MSG: {
if (!item)
break;
fConfigure->SetEnabled(item != NULL);
fOnOff->SetEnabled(item != NULL);
if (item == NULL) {
@@ -167,40 +158,3 @@ NetworkStatusAddOn::MessageReceived(BMessage* msg)
BBox::MessageReceived(msg);
}
}
status_t
NetworkStatusAddOn::_LookupDevices()
{
// iterate over all interfaces and retrieve minimal status
ifconf config;
config.ifc_len = sizeof(config.ifc_value);
if (ioctl(fSocket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0)
return B_ERROR;
uint32 count = (uint32)config.ifc_value;
if (count == 0)
return B_ERROR;
void* buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL)
return B_ERROR;
MemoryDeleter deleter(buffer);
config.ifc_len = count * sizeof(struct ifreq);
config.ifc_buf = buffer;
if (ioctl(fSocket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
return B_ERROR;
ifreq* interface = (ifreq*)buffer;
fListview->MakeEmpty();
for (uint32 i = 0; i < count; i++) {
fListview->AddItem(new InterfaceStatusItem(interface->ifr_name, this));
// printf("Name = %s\n", interface->ifr_name);
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
+ interface->ifr_addr.sa_len);
}
return B_OK;
}
@@ -8,8 +8,8 @@
*/
#ifndef NETWORKSTATUSADDON_H
#define NETWORKSTATUSADDON_H
#ifndef INTERFACES_ADDON_H
#define INTERFACES_ADDON_H
#include <Box.h>
#include <ListView.h>
@@ -17,31 +17,28 @@
#include "NetworkSetupAddOn.h"
class NetworkStatusAddOn : public NetworkSetupAddOn, public BBox
class InterfacesAddOn : public NetworkSetupAddOn, public BBox
{
public:
NetworkStatusAddOn(image_id addon_image);
~NetworkStatusAddOn();
InterfacesAddOn(image_id addon_image);
~InterfacesAddOn();
const char* Name();
BView* CreateView(BRect *bounds);
enum {
INTERFACE_SELECTED_MSG = 'ifce',
CONFIGURE_INTERFACE_MSG = 'conf',
ONOFF_INTERFACE_MSG = 'onof'
};
enum {
INTERFACE_SELECTED_MSG = 'ifce',
CONFIGURE_INTERFACE_MSG = 'conf',
ONOFF_INTERFACE_MSG = 'onof'
};
void AttachedToWindow();
void MessageReceived(BMessage* msg);
private:
status_t _LookupDevices();
BListView* fListview;
BButton* fConfigure;
BButton* fOnOff;
int fSocket;
};
#endif /*NETWORKSTATUSADDON_H*/
#endif /*INTERFACES_ADDON_H*/
@@ -0,0 +1,329 @@
/*
* Copyright 2004-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Fredrik Modéen
*/
#include "InterfacesListView.h"
#include "Setting.h"
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <File.h>
#include <Resources.h>
#include <AutoDeleter.h>
#include <net_notifications.h>
class SocketOpener {
public:
SocketOpener()
{
fSocket = socket(AF_INET, SOCK_DGRAM, 0);
}
~SocketOpener()
{
close(fSocket);
}
status_t InitCheck()
{
return fSocket >= 0 ? B_OK : B_ERROR;
}
operator int() const
{
return fSocket;
}
private:
int fSocket;
};
// #pragma mark -
status_t
our_image(image_info& image)
{
int32 cookie = 0;
while (get_next_image_info(B_CURRENT_TEAM, &cookie, &image) == B_OK) {
if ((char *)our_image >= (char *)image.text
&& (char *)our_image <= (char *)image.text + image.text_size)
return B_OK;
}
return B_ERROR;
}
InterfaceListItem::InterfaceListItem(const char* name)
:
BListItem(0, false),
fEnabled(true),
fIcon(NULL),
fSetting(new Setting(name))
{
_InitIcon();
}
InterfaceListItem::~InterfaceListItem()
{
delete fIcon;
}
void InterfaceListItem::Update(BView* owner, const BFont* font)
{
BListItem::Update(owner,font);
font_height height;
font->GetHeight(&height);
// TODO: take into account icon height, if he's taller...
SetHeight((height.ascent+height.descent+height.leading) * 3.0 + 8);
}
void
InterfaceListItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
{
BListView* list = dynamic_cast<BListView*>(owner);
if (!list)
return;
font_height height;
BFont font;
owner->GetFont(&font);
font.GetHeight(&height);
float fntheight = height.ascent+height.descent+height.leading;
BRect bounds = list->ItemFrame(list->IndexOf(this));
rgb_color oldviewcolor = owner->ViewColor();
rgb_color oldlowcolor = owner->LowColor();
rgb_color oldcolor = owner->HighColor();
rgb_color color = oldviewcolor;
if ( IsSelected() )
color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT);
owner->SetViewColor( color );
owner->SetHighColor( color );
owner->SetLowColor( color );
owner->FillRect(bounds);
owner->SetViewColor( oldviewcolor);
owner->SetLowColor( oldlowcolor );
owner->SetHighColor( oldcolor );
BPoint iconPt = bounds.LeftTop() + BPoint(4,4);
BPoint namePt = iconPt + BPoint(32+8, fntheight);
BPoint driverPt = iconPt + BPoint(32+8, fntheight*2);
BPoint commentPt = iconPt + BPoint(32+8, fntheight*3);
drawing_mode mode = owner->DrawingMode();
if (fEnabled)
owner->SetDrawingMode(B_OP_OVER);
else {
owner->SetDrawingMode(B_OP_ALPHA);
owner->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
owner->SetHighColor(0, 0, 0, 32);
}
owner->DrawBitmapAsync(fIcon, iconPt);
if (!fEnabled)
owner->SetHighColor(tint_color(oldcolor, B_LIGHTEN_1_TINT));
owner->SetFont(be_bold_font);
owner->DrawString(Name(), namePt);
owner->SetFont(be_plain_font);
if (fEnabled) {
BString str("Enabled, IPv4 address: ");
str << fSetting->IP();
owner->DrawString(str.String(), driverPt);
if (fSetting->AutoConfigured())
owner->DrawString("DHCP enabled", commentPt);
else
owner->DrawString("DHCP disabled, use static IP address", commentPt);
} else
owner->DrawString("Disabled.", driverPt);
owner->SetHighColor(oldcolor);
owner->SetDrawingMode(mode);
}
void
InterfaceListItem::_InitIcon()
{
BBitmap* icon = NULL;
image_info info;
if (our_image(info) != B_OK)
return;
BFile file(info.name, B_READ_ONLY);
if (file.InitCheck() < B_OK)
return;
BResources resources(&file);
if (resources.InitCheck() < B_OK)
return;
size_t size;
const void *data = resources.LoadResource('ICON', Name(), &size);
if (!data)
data = resources.LoadResource('ICON', "generic_device", &size);
if (data) {
// Now build the bitmap
icon = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
icon->SetBits(data, size, 0, B_CMAP8);
}
fIcon = icon;
}
// #pragma mark -
InterfacesListView::InterfacesListView(BRect rect, const char* name, uint32 resizingMode)
: BListView(rect, name, B_SINGLE_SELECTION_LIST, resizingMode)
{
}
InterfacesListView::~InterfacesListView()
{
}
void
InterfacesListView::AttachedToWindow()
{
BListView::AttachedToWindow();
_InitList();
start_watching_network(
B_WATCH_NETWORK_INTERFACE_CHANGES | B_WATCH_NETWORK_LINK_CHANGES, this);
}
void
InterfacesListView::DetachedFromWindow()
{
BListView::DetachedFromWindow();
stop_watching_network(this);
// free all items, they will be retrieved again in AttachedToWindow()
for (int32 i = CountItems(); i-- > 0;) {
delete ItemAt(i);
}
MakeEmpty();
}
void
InterfacesListView::MessageReceived(BMessage* message)
{
switch (message->what) {
case B_NETWORK_MONITOR:
message->PrintToStream();
_UpdateList();
break;
default:
BListView::MessageReceived(message);
}
}
InterfaceListItem *
InterfacesListView::FindItem(const char* name)
{
for (int32 i = CountItems(); i-- > 0;) {
InterfaceListItem* item = dynamic_cast<InterfaceListItem*>(ItemAt(i));
if (item == NULL)
continue;
if (strcmp(item->Name(), name) == 0)
return item;
}
return NULL;
}
status_t
InterfacesListView::_InitList()
{
SocketOpener socket;
if (socket.InitCheck() != B_OK)
return B_ERROR;
// iterate over all interfaces and retrieve minimal status
ifconf config;
config.ifc_len = sizeof(config.ifc_value);
if (ioctl(socket, SIOCGIFCOUNT, &config, sizeof(struct ifconf)) < 0)
return B_ERROR;
uint32 count = (uint32)config.ifc_value;
if (count == 0)
return B_ERROR;
void* buffer = malloc(count * sizeof(struct ifreq));
if (buffer == NULL)
return B_ERROR;
MemoryDeleter deleter(buffer);
config.ifc_len = count * sizeof(struct ifreq);
config.ifc_buf = buffer;
if (ioctl(socket, SIOCGIFCONF, &config, sizeof(struct ifconf)) < 0)
return B_ERROR;
ifreq* interface = (ifreq*)buffer;
MakeEmpty();
for (uint32 i = 0; i < count; i++) {
AddItem(new InterfaceListItem(interface->ifr_name));
// printf("Name = %s\n", interface->ifr_name);
interface = (ifreq*)((addr_t)interface + IF_NAMESIZE
+ interface->ifr_addr.sa_len);
}
return B_OK;
}
status_t
InterfacesListView::_UpdateList()
{
// TODO
return B_OK;
}
@@ -0,0 +1,67 @@
/*
* Copyright 2004-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Fredrik Modéen
*/
#ifndef INTERFACES_LIST_VIEW_H
#define INTERFACES_LIST_VIEW_H
#include <String.h>
#include <ListView.h>
#include <ListItem.h>
#include <Bitmap.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
#include "Setting.h"
class InterfaceListItem : public BListItem {
public:
InterfaceListItem(const char* name);
~InterfaceListItem();
void DrawItem(BView* owner, BRect bounds, bool complete);
void Update(BView* owner, const BFont* font);
inline const char* Name() { return fSetting->Name(); }
inline bool Enabled() { return fEnabled; }
inline void SetEnabled(bool enable){ fEnabled = enable; }
inline Setting* GetSetting() { return fSetting; }
private:
void _InitIcon();
bool fEnabled;
BBitmap* fIcon;
Setting* fSetting;
};
class InterfacesListView : public BListView {
public:
InterfacesListView(BRect rect, const char* name,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP);
virtual ~InterfacesListView();
InterfaceListItem* FindItem(const char* name);
protected:
virtual void AttachedToWindow();
virtual void DetachedFromWindow();
virtual void MessageReceived(BMessage* message);
private:
status_t _InitList();
status_t _UpdateList();
};
#endif /*INTERFACES_LIST_VIEW_H*/
@@ -1,17 +1,17 @@
SubDir HAIKU_TOP src tests kits net preflet StatusAddOn ;
SubDir HAIKU_TOP src tests kits net preflet InterfacesAddOn ;
UseHeaders [ FDirName $(HAIKU_TOP) src tests kits net preflet ] ;
UseHeaders [ FDirName $(HAIKU_TOP) src servers net ] : true ;
UsePrivateHeaders shared ;
UsePrivateHeaders net shared ;
AddResources Overview :
AddResources Interfaces :
Icons.rdef
;
Addon Overview :
NetworkStatusAddOn.cpp
InterfaceStatusItem.cpp
Addon Interfaces :
InterfacesAddOn.cpp
InterfacesListView.cpp
Setting.cpp
NetworkWindow.cpp
EthernetSettingsView.cpp
@@ -24,7 +24,7 @@ NetworkWindow::NetworkWindow(Setting* setting)
fEthernetView = new EthernetSettingsView(setting);
GetLayout()->AddView(fEthernetView);
SetTitle(setting->GetName());
SetTitle(setting->Name());
}
@@ -22,11 +22,11 @@ class Setting {
void SetNetmask(BString ip) {fNetmask = ip; }
void SetAutoConfigure(bool t) {fAuto = t; }
const char* GetIP() {return fIP.String(); }
const char* GetGateway() {return fGateway.String(); }
const char* GetNetmask() {return fNetmask.String(); }
const char* GetName() {return fName.String(); }
bool GetAutoConfigure() {return fAuto; }
const char* IP() {return fIP.String(); }
const char* Gateway() {return fGateway.String(); }
const char* Netmask() {return fNetmask.String(); }
const char* Name() {return fName.String(); }
bool AutoConfigured() {return fAuto; }
BObjectList<BString> fNameservers;
void ReadConfiguration();
+1 -1
View File
@@ -8,7 +8,7 @@ SimpleTest NetworkSetup :
: be root $(TARGET_LIBSTDC++)
;
SubInclude HAIKU_TOP src tests kits net preflet StatusAddOn ;
SubInclude HAIKU_TOP src tests kits net preflet InterfacesAddOn ;
SubInclude HAIKU_TOP src tests kits net preflet ServicesAddOn ;
SubInclude HAIKU_TOP src tests kits net preflet DummyAddOn ;
SubInclude HAIKU_TOP src tests kits net preflet MultipleAddOns ;
@@ -15,8 +15,8 @@
// --------------------------------------------------------------
NetworkSetupWindow::NetworkSetupWindow(const char *title)
:
BWindow(BRect(100, 100, 600, 600), title, B_TITLED_WINDOW
, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
BWindow(BRect(100, 100, 600, 600), title, B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
{
BMenu *show_menu;
BMenu *profiles_menu;
@@ -250,7 +250,7 @@ NetworkSetupWindow::_BuildProfilesMenu(BMenu* menu, int32 msg_what)
menu->SetRadioMode(true);
BDirectory dir("/etc/network/profiles");
BDirectory dir("/boot/common/settings/network/profiles");
if (dir.InitCheck() == B_OK) {
BEntry entry;
@@ -1,148 +0,0 @@
/*
* Copyright 2004-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Fredrik Modéen
*/
#include "InterfaceStatusItem.h"
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include "NetworkSetupAddOn.h"
#include "Setting.h"
InterfaceStatusItem::InterfaceStatusItem(const char* name, NetworkStatusAddOn* addon)
:
BListItem(0, false),
fIcon(NULL),
fSetting(new Setting(name)),
fAddon(addon)
{
fEnabled = true;
_InitIcon();
}
InterfaceStatusItem::~InterfaceStatusItem()
{
delete fIcon;
}
void InterfaceStatusItem::Update(BView* owner, const BFont* font)
{
BListItem::Update(owner,font);
font_height height;
font->GetHeight(&height);
// TODO: take into account icon height, if he's taller...
SetHeight((height.ascent+height.descent+height.leading) * 3.0 + 8);
}
void
InterfaceStatusItem::DrawItem(BView* owner, BRect /*bounds*/, bool complete)
{
BListView* list = dynamic_cast<BListView*>(owner);
if (!list)
return;
font_height height;
BFont font;
owner->GetFont(&font);
font.GetHeight(&height);
float fntheight = height.ascent+height.descent+height.leading;
BRect bounds = list->ItemFrame(list->IndexOf(this));
rgb_color oldviewcolor = owner->ViewColor();
rgb_color oldlowcolor = owner->LowColor();
rgb_color oldcolor = owner->HighColor();
rgb_color color = oldviewcolor;
if ( IsSelected() )
color = tint_color(color, B_HIGHLIGHT_BACKGROUND_TINT);
owner->SetViewColor( color );
owner->SetHighColor( color );
owner->SetLowColor( color );
owner->FillRect(bounds);
owner->SetViewColor( oldviewcolor);
owner->SetLowColor( oldlowcolor );
owner->SetHighColor( oldcolor );
BPoint iconPt = bounds.LeftTop() + BPoint(4,4);
BPoint namePt = iconPt + BPoint(32+8, fntheight);
BPoint driverPt = iconPt + BPoint(32+8, fntheight*2);
BPoint commentPt = iconPt + BPoint(32+8, fntheight*3);
drawing_mode mode = owner->DrawingMode();
if (fEnabled)
owner->SetDrawingMode(B_OP_OVER);
else {
owner->SetDrawingMode(B_OP_ALPHA);
owner->SetBlendingMode(B_CONSTANT_ALPHA, B_ALPHA_OVERLAY);
owner->SetHighColor(0, 0, 0, 32);
}
owner->DrawBitmapAsync(fIcon, iconPt);
if (!fEnabled)
owner->SetHighColor(tint_color(oldcolor, B_LIGHTEN_2_TINT));
owner->SetFont(be_bold_font);
owner->DrawString(Name(), namePt);
owner->SetFont(be_plain_font);
if (fEnabled) {
BString str("Enabled, IPv4 address: ");
str << fSetting->GetIP();
owner->DrawString(str.String(), driverPt);
if (fSetting->GetAutoConfigure())
owner->DrawString("DHCP enabled", commentPt);
else
owner->DrawString("DHCP disabled, use static IP address", commentPt);
} else
owner->DrawString("Disabled.", driverPt);
owner->SetHighColor(oldcolor);
owner->SetDrawingMode(mode);
}
void
InterfaceStatusItem::_InitIcon()
{
BBitmap* icon = NULL;
BResources *resources = fAddon->Resources();
if (resources) {
size_t size;
const void *data = resources->LoadResource('ICON', Name(), &size);
if (!data)
data = resources->LoadResource('ICON', "generic_device", &size);
if (data) {
// Now build the bitmap
icon = new BBitmap(BRect(0, 0, 31, 31), B_CMAP8);
icon->SetBits(data, size, 0, B_CMAP8);
}
}
fIcon = icon;
}
@@ -1,48 +0,0 @@
/*
* Copyright 2004-2009 Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Philippe Houdoin
* Fredrik Modéen
*/
#ifndef INTERFACESTATUSITEM_H
#define INTERFACESTATUSITEM_H
#include <String.h>
#include <ListItem.h>
#include <Bitmap.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#include <net/if_types.h>
#include "NetworkStatusAddOn.h"
#include "Setting.h"
class InterfaceStatusItem : public BListItem
{
public:
InterfaceStatusItem(const char* name, NetworkStatusAddOn* addon);
~InterfaceStatusItem();
void DrawItem(BView* owner, BRect bounds, bool complete);
void Update(BView* owner, const BFont* font);
inline const char* Name() { return fSetting->GetName(); }
inline bool Enabled() { return fEnabled; }
inline void SetEnabled(bool enable){ fEnabled = enable; }
inline Setting* GetSetting() { return fSetting; }
private:
void _InitIcon();
bool fEnabled;
BBitmap* fIcon;
Setting* fSetting;
NetworkStatusAddOn* fAddon;
};
#endif /*INTERFACESTATUSITEM_H*/