Network: fixed top item creation, sort entries.
* Need a way to access the NetworkWindow object from a static method in order to sort all entries correctly, though.
This commit is contained in:
@@ -92,6 +92,8 @@ public:
|
|||||||
BNetworkSettings& settings);
|
BNetworkSettings& settings);
|
||||||
~BNetworkInterfaceListItem();
|
~BNetworkInterfaceListItem();
|
||||||
|
|
||||||
|
const char* Label() const;
|
||||||
|
|
||||||
virtual void DrawItem(BView* owner,
|
virtual void DrawItem(BView* owner,
|
||||||
BRect bounds, bool complete);
|
BRect bounds, bool complete);
|
||||||
virtual void Update(BView* owner, const BFont* font);
|
virtual void Update(BView* owner, const BFont* font);
|
||||||
|
|||||||
@@ -106,6 +106,13 @@ BNetworkInterfaceListItem::~BNetworkInterfaceListItem()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const char*
|
||||||
|
BNetworkInterfaceListItem::Label() const
|
||||||
|
{
|
||||||
|
return fLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BNetworkInterfaceListItem::DrawItem(BView* owner, BRect bounds, bool complete)
|
BNetworkInterfaceListItem::DrawItem(BView* owner, BRect bounds, bool complete)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <PathMonitor.h>
|
#include <PathMonitor.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <ScrollView.h>
|
#include <ScrollView.h>
|
||||||
|
#include <StringItem.h>
|
||||||
#include <SymLink.h>
|
#include <SymLink.h>
|
||||||
|
|
||||||
#define ENABLE_PROFILES 0
|
#define ENABLE_PROFILES 0
|
||||||
@@ -62,7 +63,10 @@ static const uint32 kMsgItemSelected = 'ItSl';
|
|||||||
NetworkWindow::NetworkWindow()
|
NetworkWindow::NetworkWindow()
|
||||||
:
|
:
|
||||||
BWindow(BRect(100, 100, 400, 400), B_TRANSLATE("Network"), B_TITLED_WINDOW,
|
BWindow(BRect(100, 100, 400, 400), B_TRANSLATE("Network"), B_TITLED_WINDOW,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS)
|
B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS),
|
||||||
|
fServicesItem(NULL),
|
||||||
|
fDialUpItem(NULL),
|
||||||
|
fOtherItem(NULL)
|
||||||
{
|
{
|
||||||
// Profiles section
|
// Profiles section
|
||||||
#if ENABLE_PROFILES
|
#if ENABLE_PROFILES
|
||||||
@@ -362,9 +366,10 @@ NetworkWindow::_ScanAddOns()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
fSettingsMap[item->ListItem()] = item;
|
fSettingsMap[item->ListItem()] = item;
|
||||||
// TODO: sort
|
|
||||||
fListView->AddUnder(item->ListItem(), interfaceItem);
|
fListView->AddUnder(item->ListItem(), interfaceItem);
|
||||||
}
|
}
|
||||||
|
fListView->SortItemsUnder(interfaceItem, true,
|
||||||
|
NetworkWindow::_CompareListItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic items
|
// Generic items
|
||||||
@@ -375,12 +380,18 @@ NetworkWindow::_ScanAddOns()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
fSettingsMap[item->ListItem()] = item;
|
fSettingsMap[item->ListItem()] = item;
|
||||||
// TODO: sort
|
|
||||||
fListView->AddUnder(item->ListItem(),
|
fListView->AddUnder(item->ListItem(),
|
||||||
_ListItemFor(item->Type()));
|
_ListItemFor(item->Type()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_SortItemsUnder(fServicesItem);
|
||||||
|
_SortItemsUnder(fDialUpItem);
|
||||||
|
_SortItemsUnder(fOtherItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fListView->SortItemsUnder(NULL, true,
|
||||||
|
NetworkWindow::_CompareTopLevelListItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -395,28 +406,31 @@ NetworkWindow::_SettingsItemFor(BListItem* item)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
NetworkWindow::_SortItemsUnder(BListItem* item)
|
||||||
|
{
|
||||||
|
if (item != NULL)
|
||||||
|
fListView->SortItemsUnder(item, true, NetworkWindow::_CompareListItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BListItem*
|
BListItem*
|
||||||
NetworkWindow::_ListItemFor(BNetworkSettingsType type)
|
NetworkWindow::_ListItemFor(BNetworkSettingsType type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case B_NETWORK_SETTINGS_TYPE_SERVICE:
|
case B_NETWORK_SETTINGS_TYPE_SERVICE:
|
||||||
if (fServicesItem == NULL) {
|
if (fServicesItem == NULL)
|
||||||
fServicesItem = new BStringItem(B_TRANSLATE("Services"));
|
fServicesItem = _CreateItem(B_TRANSLATE("Services"));
|
||||||
fServicesItem->SetExpanded(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return fServicesItem;
|
return fServicesItem;
|
||||||
|
|
||||||
case B_NETWORK_SETTINGS_TYPE_DIAL_UP:
|
case B_NETWORK_SETTINGS_TYPE_DIAL_UP:
|
||||||
if (fDialUpItem == NULL)
|
if (fDialUpItem == NULL)
|
||||||
fDialUpItem = new BStringItem(B_TRANSLATE("Dial Up"));
|
fDialUpItem = _CreateItem(B_TRANSLATE("Dial Up"));
|
||||||
|
|
||||||
return fDialUpItem;
|
return fDialUpItem;
|
||||||
|
|
||||||
case B_NETWORK_SETTINGS_TYPE_OTHER:
|
case B_NETWORK_SETTINGS_TYPE_OTHER:
|
||||||
if (fOtherItem == NULL)
|
if (fOtherItem == NULL)
|
||||||
fOtherItem = new BStringItem(B_TRANSLATE("Other"));
|
fOtherItem = _CreateItem(B_TRANSLATE("Other"));
|
||||||
|
|
||||||
return fOtherItem;
|
return fOtherItem;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -425,6 +439,16 @@ NetworkWindow::_ListItemFor(BNetworkSettingsType type)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BListItem*
|
||||||
|
NetworkWindow::_CreateItem(const char* label)
|
||||||
|
{
|
||||||
|
BListItem* item = new BStringItem(label);
|
||||||
|
item->SetExpanded(true);
|
||||||
|
fListView->AddItem(item);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
NetworkWindow::_SelectItem(BListItem* listItem)
|
NetworkWindow::_SelectItem(BListItem* listItem)
|
||||||
{
|
{
|
||||||
@@ -508,3 +532,67 @@ NetworkWindow::_IsReplicantInstalled()
|
|||||||
BDeskbar deskbar;
|
BDeskbar deskbar;
|
||||||
return deskbar.HasItem("NetworkStatus");
|
return deskbar.HasItem("NetworkStatus");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ const char*
|
||||||
|
NetworkWindow::_ItemName(const BListItem* item)
|
||||||
|
{
|
||||||
|
if (const BNetworkInterfaceListItem* listItem = dynamic_cast<
|
||||||
|
const BNetworkInterfaceListItem*>(item))
|
||||||
|
return listItem->Label();
|
||||||
|
|
||||||
|
if (const BStringItem* stringItem = dynamic_cast<const BStringItem*>(item))
|
||||||
|
return stringItem->Text();
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ int
|
||||||
|
NetworkWindow::_CompareTopLevelListItems(const BListItem* a, const BListItem* b)
|
||||||
|
{
|
||||||
|
if (a == b)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (const InterfaceListItem* itemA
|
||||||
|
= dynamic_cast<const InterfaceListItem*>(a)) {
|
||||||
|
if (const InterfaceListItem* itemB
|
||||||
|
= dynamic_cast<const InterfaceListItem*>(b)) {
|
||||||
|
return strcasecmp(itemA->Name(), itemB->Name());
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
} else if (dynamic_cast<const InterfaceListItem*>(b) != NULL)
|
||||||
|
return 1;
|
||||||
|
/*
|
||||||
|
if (a == fDialUpItem)
|
||||||
|
return -1;
|
||||||
|
if (b == fDialUpItem)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (a == fServicesItem)
|
||||||
|
return -1;
|
||||||
|
if (b == fServicesItem)
|
||||||
|
return 1;
|
||||||
|
*/
|
||||||
|
return _CompareListItems(a, b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*static*/ int
|
||||||
|
NetworkWindow::_CompareListItems(const BListItem* a, const BListItem* b)
|
||||||
|
{
|
||||||
|
if (a == b)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
const char* nameA = _ItemName(a);
|
||||||
|
const char* nameB = _ItemName(b);
|
||||||
|
|
||||||
|
if (nameA != NULL && nameB != NULL)
|
||||||
|
return strcasecmp(nameA, nameB);
|
||||||
|
if (nameA != NULL)
|
||||||
|
return 1;
|
||||||
|
if (nameB != NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return (addr_t)a > (addr_t)b ? 1 : -1;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,7 +43,9 @@ private:
|
|||||||
void _ScanAddOns();
|
void _ScanAddOns();
|
||||||
BNetworkSettingsItem*
|
BNetworkSettingsItem*
|
||||||
_SettingsItemFor(BListItem* item);
|
_SettingsItemFor(BListItem* item);
|
||||||
|
void _SortItemsUnder(BListItem* item);
|
||||||
BListItem* _ListItemFor(BNetworkSettingsType type);
|
BListItem* _ListItemFor(BNetworkSettingsType type);
|
||||||
|
BListItem* _CreateItem(const char* label);
|
||||||
void _SelectItem(BListItem* listItem);
|
void _SelectItem(BListItem* listItem);
|
||||||
void _BroadcastSettingsUpdate(uint32 type);
|
void _BroadcastSettingsUpdate(uint32 type);
|
||||||
void _BroadcastConfigurationUpdate(
|
void _BroadcastConfigurationUpdate(
|
||||||
@@ -52,6 +54,12 @@ private:
|
|||||||
bool _IsReplicantInstalled();
|
bool _IsReplicantInstalled();
|
||||||
void _ShowReplicant(bool show);
|
void _ShowReplicant(bool show);
|
||||||
|
|
||||||
|
static const char* _ItemName(const BListItem* item);
|
||||||
|
static int _CompareTopLevelListItems(const BListItem* a,
|
||||||
|
const BListItem* b);
|
||||||
|
static int _CompareListItems(const BListItem* a,
|
||||||
|
const BListItem* b);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
typedef BObjectList<BNetworkSettingsAddOn> AddOnList;
|
typedef BObjectList<BNetworkSettingsAddOn> AddOnList;
|
||||||
typedef BObjectList<BNetworkSettingsItem> ItemList;
|
typedef BObjectList<BNetworkSettingsItem> ItemList;
|
||||||
|
|||||||
Reference in New Issue
Block a user