The network status icons are now correctly read from the resources (I even

forgot to add them to the server before :-)).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20532 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2007-04-03 12:24:32 +00:00
parent 3eb30a22b2
commit d7e473d310
4 changed files with 90 additions and 47 deletions

View File

@ -7,7 +7,7 @@ UseLibraryHeaders icon ;
#UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ; #UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libkernelppp headers ] ;
#UseHeaders [ FDirName $(HAIKU_TOP) src tests kits net DialUpPreflet ] ; #UseHeaders [ FDirName $(HAIKU_TOP) src tests kits net DialUpPreflet ] ;
AddResources net_server : net_server.rdef ; AddResources net_server : net_server.rdef NetworkStatusIcons.rdef ;
Server net_server : Server net_server :
NetServer.cpp NetServer.cpp

View File

@ -986,7 +986,7 @@ NetServer::_UpdateReplicantStatus()
BMessage message(kStatusUpdate); BMessage message(kStatusUpdate);
for (StatusMap::iterator it = fStatusMap.begin(); for (StatusMap::iterator it = fStatusMap.begin();
it != fStatusMap.end(); ++it) { it != fStatusMap.end(); ++it) {
if (it->second > prevaling) if (it->second > prevaling)
prevaling = it->second; prevaling = it->second;

View File

@ -30,12 +30,12 @@
const char *kStatusReplicant = "NetStatusView"; const char *kStatusReplicant = "NetStatusView";
static const uint32 kShowConfiguration = 'shcf'; static const uint32 kShowConfiguration = 'shcf';
static const uint8 kStatusColors[kStatusCount][3] = { static const rgb_color kStatusColors[kStatusCount] = {
{ 0, 0, 0 }, // Unknown { 0, 0, 0 }, // Unknown
{ 255, 0, 0 }, // NoLink { 255, 0, 0 }, // NoLink
{ 0, 0, 255 }, // LinkNoConfig { 0, 0, 255 }, // LinkNoConfig
{ 0, 255, 0 }, // Connected { 0, 255, 0 }, // Connected
{ 255, 255, 0 }, // Preparing { 255, 255, 0 }, // Preparing
}; };
struct information_entry { struct information_entry {
@ -59,17 +59,36 @@ static const char *kStatusDescriptions[] = {
}; };
StatusReplicant::StatusReplicant() static status_t
: BView(BRect(0, 0, 15, 15), kStatusReplicant, B_FOLLOW_ALL, 0), our_image(image_info *image)
fPopUp("", false, false)
{ {
_Init(); 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;
}
// #pragma mark -
StatusReplicant::StatusReplicant()
: BView(BRect(0, 0, 15, 15), kStatusReplicant, B_FOLLOW_ALL, B_WILL_DRAW),
fPopUp("", false, false),
fStatus(kStatusUnknown)
{
_Init(false);
} }
StatusReplicant::StatusReplicant(BMessage *message) StatusReplicant::StatusReplicant(BMessage *message)
: BView(message), : BView(message),
fPopUp("", false, false) fPopUp("", false, false),
fStatus(kStatusUnknown)
{ {
_Init(); _Init();
} }
@ -136,6 +155,18 @@ StatusReplicant::MessageReceived(BMessage *message)
} }
void
StatusReplicant::Draw(BRect updateRect)
{
if (fBitmaps[fStatus] == NULL)
return;
SetDrawingMode(B_OP_ALPHA);
DrawBitmap(fBitmaps[fStatus]);
SetDrawingMode(B_OP_COPY);
}
void void
StatusReplicant::MouseDown(BPoint point) StatusReplicant::MouseDown(BPoint point)
{ {
@ -151,31 +182,42 @@ StatusReplicant::MouseDown(BPoint point)
void void
StatusReplicant::_Init() StatusReplicant::_Init(bool isReplicant)
{ {
// Load status bitmaps from resources // Load status bitmaps from resources
BResources* resources = BApplication::AppResources();
for (int i = 0; i < kStatusCount; i++) { for (int i = 0; i < kStatusCount; i++) {
fBitmaps[i] = NULL; fBitmaps[i] = NULL;
}
if (resources != NULL) { if (!isReplicant)
const void* data = NULL; return;
size_t size;
data = resources->LoadResource(B_VECTOR_ICON_TYPE,
kNetworkStatusNoDevice + i, &size);
if (data != NULL) {
BBitmap* icon = new BBitmap(Bounds(), B_RGB32);
if (icon->InitCheck() == B_OK
&& BIconUtils::GetVectorIcon((const uint8 *)data,
size, icon) == B_OK) {
fBitmaps[i] = icon;
} else
delete icon;
free((void*)data); 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;
for (int i = 0; i < kStatusCount; i++) {
const void* data = NULL;
size_t size;
data = resources.LoadResource(B_VECTOR_ICON_TYPE,
kNetworkStatusNoDevice + i, &size);
if (data != NULL) {
BBitmap* icon = new BBitmap(Bounds(), B_RGB32);
if (icon->InitCheck() == B_OK
&& BIconUtils::GetVectorIcon((const uint8 *)data,
size, icon) == B_OK) {
fBitmaps[i] = icon;
} else
delete icon;
} }
} }
} }
@ -306,15 +348,15 @@ StatusReplicant::_PrepareMenu(const InterfaceStatusList &status)
void void
StatusReplicant::_ChangeStatus(int newStatus) StatusReplicant::_ChangeStatus(int newStatus)
{ {
if (fBitmaps[newStatus]) { if (fStatus == newStatus)
return;
fStatus = newStatus;
if (fBitmaps[newStatus])
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
SetViewBitmap(fBitmaps[newStatus]); else
} else { SetViewColor(kStatusColors[newStatus]);
ClearViewBitmap();
SetViewColor(kStatusColors[newStatus][0],
kStatusColors[newStatus][1],
kStatusColors[newStatus][2]);
}
Invalidate(); Invalidate();
} }

View File

@ -31,25 +31,26 @@ class StatusReplicant : public BView {
virtual ~StatusReplicant(); virtual ~StatusReplicant();
static StatusReplicant *Instantiate(BMessage *archive); static StatusReplicant *Instantiate(BMessage *archive);
status_t Archive(BMessage *archive, bool deep) const; virtual status_t Archive(BMessage *archive, bool deep) const;
void AttachedToWindow(); virtual void AttachedToWindow();
void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual void Draw(BRect updateRect);
void MouseDown(BPoint point); virtual void MouseDown(BPoint point);
private: private:
typedef std::pair<std::string, int> InterfaceStatus; typedef std::pair<std::string, int> InterfaceStatus;
typedef std::vector<InterfaceStatus> InterfaceStatusList; typedef std::vector<InterfaceStatus> InterfaceStatusList;
void _Init(); void _Init(bool isReplicant = true);
void _UpdateFromMessage(BMessage *message); void _UpdateFromMessage(BMessage *message);
void _ShowConfiguration(BMessage *message); void _ShowConfiguration(BMessage *message);
void _PrepareMenu(const InterfaceStatusList &list); void _PrepareMenu(const InterfaceStatusList &list);
void _ChangeStatus(int newStatus); void _ChangeStatus(int newStatus);
BPopUpMenu fPopUp; BPopUpMenu fPopUp;
BBitmap *fBitmaps[kStatusCount]; BBitmap* fBitmaps[kStatusCount];
int32 fStatus;
}; };
#endif // _STATUS_REPLICANT_H #endif // _STATUS_REPLICANT_H