コード例 #1
0
ファイル: InterfacesListView.cpp プロジェクト: mylegacy/haiku
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;
}
コード例 #2
0
ファイル: InterfacesListView.cpp プロジェクト: mylegacy/haiku
status_t
InterfacesListView::SaveItems()
{
	// Grab each fSettings instance and write it's settings
	for (int32 i = CountItems(); i-- > 0;) {
		InterfaceListItem* item = dynamic_cast<InterfaceListItem*>(ItemAt(i));
		if (item == NULL)
			continue;

		if (strcmp(item->Name(), "loop") == 0)
			continue;

		NetworkSettings* ns = item->GetSettings();
		// TODO : SetConfiguration doesn't use the interface settings file
		ns->SetConfiguration();
	}

	return B_OK;
}
コード例 #3
0
ファイル: NetworkWindow.cpp プロジェクト: kodybrown/haiku
void
NetworkWindow::_ScanInterfaces()
{
	// Try existing devices first
	BNetworkRoster& roster = BNetworkRoster::Default();
	BNetworkInterface interface;
	uint32 cookie = 0;

	while (roster.GetNextInterface(&cookie, interface) == B_OK) {
		if ((interface.Flags() & IFF_LOOPBACK) != 0)
			continue;

		InterfaceListItem* item = new InterfaceListItem(interface.Name());
		item->SetExpanded(true);

		fInterfaceItemMap.insert(std::pair<BString, InterfaceListItem*>(
			BString(interface.Name()), item));
		fListView->AddItem(item);
	}

	// TODO: Then consider those from the settings (for example, for USB)
}
コード例 #4
0
ファイル: NetworkWindow.cpp プロジェクト: kodybrown/haiku
void
NetworkWindow::_SelectItem(BListItem* listItem)
{
	while (fAddOnShellView->CountChildren() > 0)
		fAddOnShellView->ChildAt(0)->RemoveSelf();

	BView* nextView = NULL;

	BNetworkSettingsItem* item = _SettingsItemFor(listItem);
	if (item != NULL) {
		nextView = item->View();
	} else {
		InterfaceListItem* item = dynamic_cast<InterfaceListItem*>(
			listItem);
		if (item != NULL) {
			fInterfaceView->SetTo(item->Name());
			nextView = fInterfaceView;
		}
	}

	if (nextView != NULL)
		fAddOnShellView->AddChild(nextView);
}
コード例 #5
0
ファイル: InterfacesListView.cpp プロジェクト: mylegacy/haiku
void
InterfacesListView::MouseDown(BPoint where)
{
	int32 buttons = 0;
	Window()->CurrentMessage()->FindInt32("buttons", &buttons);

	if ((B_SECONDARY_MOUSE_BUTTON & buttons) == 0) {
		// If not secondary mouse button do the default
		BListView::MouseDown(where);
		return;
	}

	InterfaceListItem* item = FindItem(where);
	if (item == NULL)
		return;

	// Remove all items from the menu
	for (int32 i = fContextMenu->CountItems(); i >= 0; --i) {
		BMenuItem* menuItem = fContextMenu->RemoveItem(i);
		delete menuItem;
	}

	// Now add the ones we want
	if (item->GetSettings()->IsDisabled()) {
		fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Enable"),
			new BMessage(kMsgInterfaceToggle)));
	} else {
		fContextMenu->AddItem(new BMenuItem(
			B_TRANSLATE("Configure" B_UTF8_ELLIPSIS),
				new BMessage(kMsgInterfaceConfigure)));
		if (item->GetSettings()->AutoConfigure(AF_INET)
			|| item->GetSettings()->AutoConfigure(AF_INET6)) {
			fContextMenu->AddItem(new BMenuItem(
				B_TRANSLATE("Renegotiate Address"),
					new BMessage(kMsgInterfaceRenegotiate)));
		}
		fContextMenu->AddItem(new BSeparatorItem());
		fContextMenu->AddItem(new BMenuItem(B_TRANSLATE("Disable"),
			new BMessage(kMsgInterfaceToggle)));
	}

	fContextMenu->ResizeToPreferred();
	BMenuItem* selected = fContextMenu->Go(ConvertToScreen(where));
	if (selected == NULL)
		return;

	switch (selected->Message()->what) {
		case kMsgInterfaceConfigure:
		{
			InterfaceWindow* win = new InterfaceWindow(item->GetSettings());
			win->MoveTo(ConvertToScreen(where));
			win->Show();
			break;
		}

		case kMsgInterfaceToggle:
			item->SetDisabled(!item->IsDisabled());
			Invalidate();
			break;

		case kMsgInterfaceRenegotiate:
			item->GetSettings()->RenegotiateAddresses();
			break;
	}
}