From e267a9eb47c4486b7057fe4cbf2f18345a5240bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 19 Feb 2015 17:35:49 +0000 Subject: [PATCH] Network: show interface addresses in list item. * No family prefix yet. --- src/preferences/network/InterfaceListItem.cpp | 55 +++++++------------ src/preferences/network/InterfaceListItem.h | 5 +- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/preferences/network/InterfaceListItem.cpp b/src/preferences/network/InterfaceListItem.cpp index f7d55927c5..d6ac0bdc84 100644 --- a/src/preferences/network/InterfaceListItem.cpp +++ b/src/preferences/network/InterfaceListItem.cpp @@ -78,19 +78,11 @@ InterfaceListItem::DrawItem(BView* owner, BRect bounds, bool complete) const char* stateText = _StateText(); // Set the initial bounds of item contents - BPoint iconPoint = bounds.LeftTop(); - BPoint namePoint = bounds.LeftTop(); - BPoint line2Point = bounds.LeftTop(); - BPoint line3Point = bounds.LeftTop(); - BPoint statePoint = bounds.RightTop(); - - iconPoint += BPoint(4, 4); - statePoint += BPoint(0, fFirstlineOffset); - namePoint += BPoint(ICON_SIZE + 12, fFirstlineOffset); - line2Point += BPoint(ICON_SIZE + 12, fSecondlineOffset); - line3Point += BPoint(ICON_SIZE + 12, fThirdlineOffset); - - statePoint -= BPoint(be_plain_font->StringWidth(stateText) + 4.0f, 0); + BPoint iconPoint = bounds.LeftTop() + BPoint(4, 4); + BPoint statePoint = bounds.RightTop() + BPoint(0, fFirstLineOffset) + - BPoint(be_plain_font->StringWidth(stateText) + 4.0f, 0); + BPoint namePoint = bounds.LeftTop() + + BPoint(ICON_SIZE + 12, fFirstLineOffset); if (fDisabled) { list->SetDrawingMode(B_OP_ALPHA); @@ -126,26 +118,15 @@ InterfaceListItem::DrawItem(BView* owner, BRect bounds, bool complete) list->SetFont(be_plain_font); list->DrawString(stateText, statePoint); -// TODO! -/* if (!disabled) { - // Render IPv4 Address - BString ipv4Str(B_TRANSLATE_COMMENT("IP:", "IPv4 address label")); - if (fSettings->IPAddr(AF_INET).IsEmpty()) - ipv4Str << " " << B_TRANSLATE("None"); - else - ipv4Str << " " << BString(fSettings->IP(AF_INET)); + BPoint linePoint = bounds.LeftTop() + BPoint(ICON_SIZE + 12, + fFirstLineOffset + fLineOffset); - list->DrawString(ipv4Str, line2Point); + for (size_t line = 0; line < sizeof(fAddress) / sizeof(fAddress[0]); + line++) { + list->DrawString(fAddress[line], linePoint); + linePoint.y += fLineOffset; } - // Render IPv6 Address (if present) - if (!disabled && !fSettings->IPAddr(AF_INET6).IsEmpty()) { - BString ipv6Str(B_TRANSLATE_COMMENT("IPv6:", "IPv6 address label")); - ipv6Str << " " << BString(fSettings->IP(AF_INET6)); - - list->DrawString(ipv6Str, line3Point); - } -*/ owner->PopState(); } @@ -160,9 +141,8 @@ InterfaceListItem::Update(BView* owner, const BFont* font) float lineHeight = ceilf(height.ascent) + ceilf(height.descent) + ceilf(height.leading); - fFirstlineOffset = 2 + ceilf(height.ascent + height.leading / 2); - fSecondlineOffset = fFirstlineOffset + lineHeight; - fThirdlineOffset = fFirstlineOffset + (lineHeight * 2); + fFirstLineOffset = 2 + ceilf(height.ascent + height.leading / 2); + fLineOffset = lineHeight; _UpdateState(); @@ -272,14 +252,21 @@ InterfaceListItem::_UpdateState() fConnecting = (fInterface.Flags() & IFF_CONFIGURING) != 0; int32 count = fInterface.CountAddresses(); + int lastFamily = -1; size_t addressIndex = 0; for (int32 index = 0; index < count; index++) { if (addressIndex >= sizeof(fAddress) / sizeof(fAddress[0])) break; BNetworkInterfaceAddress address; - if (fInterface.GetAddressAt(index, address) == B_OK) + if (fInterface.GetAddressAt(index, address) == B_OK) { + if (address.Address().IsEmpty() + || lastFamily == address.Address().Family()) + continue; + fAddress[addressIndex++] = address.Address().ToString(); + lastFamily = address.Address().Family(); + } } } diff --git a/src/preferences/network/InterfaceListItem.h b/src/preferences/network/InterfaceListItem.h index e989411e89..ac8e6e060c 100644 --- a/src/preferences/network/InterfaceListItem.h +++ b/src/preferences/network/InterfaceListItem.h @@ -46,9 +46,8 @@ private: BNetworkInterface fInterface; // Hardware Interface - float fFirstlineOffset; - float fSecondlineOffset; - float fThirdlineOffset; + float fFirstLineOffset; + float fLineOffset; BString fDeviceName; bool fDisabled;