Improvements. Still not beta.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7441 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval 2004-05-07 09:02:48 +00:00
parent f4e3a8d25f
commit 22b19ff048
10 changed files with 814 additions and 166 deletions

View File

@ -0,0 +1,558 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003-2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: ConfigurationWindow.cpp
// Author: Jérôme Duval
// Description: Devices Preferences
// Created : April 22, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// Includes ------------------------------------------------------------------------------------------ //
#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <ByteOrder.h>
#include <MenuItem.h>
#include <MenuField.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <Screen.h>
#include <stdio.h>
#include <ScrollView.h>
#include <String.h>
#include <StringView.h>
#include <TabView.h>
#include <TextView.h>
#include <Window.h>
#include <View.h>
#include "DevicesWindows.h"
#include "pcihdr.h"
#define CONFIGURATION_CHANGED 'cfch'
#define IRQ_CHANGED 'irch'
#define DMA_CHANGED 'irch'
class RangeConfItem : public BListItem
{
public:
RangeConfItem(uint32 lowAddress, uint32 highAddress);
~RangeConfItem();
virtual void DrawItem(BView *, BRect, bool = false);
static int Compare(const void *firstArg, const void *secondArg);
private:
uint32 fLowAddress, fHighAddress;
};
RangeConfItem::RangeConfItem(uint32 lowAddress, uint32 highAddress)
: BListItem(),
fLowAddress(lowAddress),
fHighAddress(highAddress)
{
}
RangeConfItem::~RangeConfItem()
{
}
/***********************************************************
* DrawItem
***********************************************************/
void
RangeConfItem::DrawItem(BView *owner, BRect itemRect, bool complete)
{
rgb_color kBlack = { 0,0,0,0 };
rgb_color kHighlight = { 156,154,156,0 };
if (IsSelected() || complete) {
rgb_color color;
if (IsSelected())
color = kHighlight;
else
color = owner->ViewColor();
owner->SetHighColor(color);
owner->SetLowColor(color);
owner->FillRect(itemRect);
owner->SetHighColor(kBlack);
} else {
owner->SetLowColor(owner->ViewColor());
}
BFont font = be_plain_font;
font_height finfo;
font.GetHeight(&finfo);
BPoint point = BPoint(itemRect.left + 4, itemRect.bottom - finfo.descent + 1);
owner->SetFont(be_plain_font);
owner->SetHighColor(kBlack);
owner->MovePenTo(point);
char string[20];
if (fLowAddress >= 0) {
sprintf(string, "0x%04lx", fLowAddress);
owner->DrawString(string);
}
point += BPoint(75, 0);
owner->MovePenTo(point);
owner->StrokeLine(point + BPoint(0,-3), point + BPoint(4,-3));
point += BPoint(15, 0);
owner->MovePenTo(point);
owner->SetFont(be_plain_font);
if (fHighAddress >= 0) {
sprintf(string, "0x%04lx", fHighAddress);
owner->DrawString(string);
}
}
int
RangeConfItem::Compare(const void *firstArg, const void *secondArg)
{
const RangeConfItem *item1 = *static_cast<const RangeConfItem * const *>(firstArg);
const RangeConfItem *item2 = *static_cast<const RangeConfItem * const *>(secondArg);
if (item1->fLowAddress < item2->fLowAddress) {
return -1;
} else if (item1->fLowAddress > item2->fLowAddress) {
return 1;
} else
return 0;
}
// -------------------------------------------------------------------------------------------------- //
// ConfigurationWindow - Constructor
ConfigurationWindow::ConfigurationWindow(BRect frame, DeviceItem *item)
: BWindow (frame, item->GetInfo()->GetName(), B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL ,
B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE|B_NOT_RESIZABLE),
fItem(item)
{
CenterWindowOnScreen(this);
fItem->SetWindow(this);
InitWindow();
Show();
}
// -------------------------------------------------------------------------------------------------- //
// ConfigurationWindow - Destructor
ConfigurationWindow::~ConfigurationWindow()
{
}
// -------------------------------------------------------------------------------------------------- //
// ConfigurationWindow::InitWindow -- Initialization Commands here
void
ConfigurationWindow::InitWindow(void)
{
DevicesInfo *devicesInfo = fItem->GetInfo();
BRect bRect = Bounds();
BBox *background = new BBox(bRect, "background", B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW, B_NO_BORDER);
AddChild(background);
BRect rtab = Bounds();
BRect rlist = Bounds();
rtab.top += 10;
rlist.top += 11;
rlist.left += 13;
rlist.right -= 13;
rlist.bottom -= 44;
// Create the TabView and Tabs
BTabView *tabView = new BTabView(rtab,"resource_usage_tabview");
tabView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rtab = tabView->Bounds();
rtab.InsetBy(5,5);
// Create the Views
BBox *resources = new BBox(rlist, "resources",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
BMenuItem *menuItem;
fConfigurationMenu = new BPopUpMenu("<empty>");
fConfigurationMenu->AddItem(menuItem = new BMenuItem("Current Configuration",
new BMessage(CONFIGURATION_CHANGED)));
menuItem->SetMarked(true);
fConfigurationMenu->AddItem(menuItem = new BMenuItem("Default Configuration",
new BMessage(CONFIGURATION_CHANGED)));
menuItem->SetEnabled(false);
fConfigurationMenu->AddItem(menuItem = new BMenuItem("Disable Device",
new BMessage(CONFIGURATION_CHANGED)));
menuItem->SetEnabled(false);
fConfigurationMenu->AddSeparatorItem();
fConfigurationMenu->AddItem(menuItem = new BMenuItem("Possible Configuration 0",
new BMessage(CONFIGURATION_CHANGED)));
BMenuField *configurationMenuField = new BMenuField(BRect(0,0,174 + (be_plain_font->Size() - 12) * 10,18), "configurationMenuField",
NULL, fConfigurationMenu, true);
resources->SetLabel(configurationMenuField);
fIRQMenu[0] = new BPopUpMenu("<empty>");
fIRQMenu[1] = new BPopUpMenu("<empty>");
fIRQMenu[2] = new BPopUpMenu("<empty>");
fDMAMenu[0] = new BPopUpMenu("<empty>");
fDMAMenu[1] = new BPopUpMenu("<empty>");
fDMAMenu[2] = new BPopUpMenu("<empty>");
BRect fieldRect;
fieldRect.top = 25;
fieldRect.left = 22;
fieldRect.right = fieldRect.left + 72;
fieldRect.bottom = fieldRect.top + 18;
BMenuField *field;
fIRQField[0] = field = new BMenuField(fieldRect, "IRQ1Field", "IRQs", fIRQMenu[0], true);
field->SetEnabled(false);
field->SetDivider(33);
resources->AddChild(field);
fieldRect.left = 25;
fieldRect.OffsetBy(71, 0);
fIRQField[1] = field = new BMenuField(fieldRect, "IRQ2Field", " and", fIRQMenu[1], true);
field->SetEnabled(false);
field->SetDivider(30);
resources->AddChild(field);
fieldRect.OffsetBy(71, 0);
fIRQField[2] = field = new BMenuField(fieldRect, "IRQ3Field", " and", fIRQMenu[2], true);
field->SetEnabled(false);
field->SetDivider(30);
resources->AddChild(field);
fieldRect.OffsetBy(-142, 23);
fieldRect.left = 14;
fDMAField[0] = field = new BMenuField(fieldRect, "DMA1Field", "DMAs", fDMAMenu[0], true);
field->SetEnabled(false);
field->SetDivider(41);
resources->AddChild(field);
fieldRect.left = 25;
fieldRect.OffsetBy(71, 0);
fDMAField[1] = field = new BMenuField(fieldRect, "DMA2Field", " and", fDMAMenu[1], true);
field->SetEnabled(false);
field->SetDivider(30);
resources->AddChild(field);
fieldRect.OffsetBy(71, 0);
fDMAField[2] = field = new BMenuField(fieldRect, "DMA3Field", " and", fDMAMenu[2], true);
field->SetEnabled(false);
field->SetDivider(30);
resources->AddChild(field);
fIRQMenu[0]->Superitem()->SetLabel("");
fIRQMenu[1]->Superitem()->SetLabel("");
fIRQMenu[2]->Superitem()->SetLabel("");
fDMAMenu[0]->Superitem()->SetLabel("");
fDMAMenu[1]->Superitem()->SetLabel("");
fDMAMenu[2]->Superitem()->SetLabel("");
BRect boxRect = resources->Bounds();
boxRect.top = 74;
boxRect.left += 13;
boxRect.right -= 11;
boxRect.bottom = boxRect.top + 141;
BBox *ioPortBox = new BBox(boxRect, "ioPort",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
ioPortBox->SetLabel(new BStringView(BRect(0,0,150,15), "ioPortLabel", " IO Port Ranges "));
resources->AddChild(ioPortBox);
boxRect.OffsetBy(0, 149);
boxRect.bottom = boxRect.top + 140;
BBox *memoryBox = new BBox(boxRect, "memory",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
memoryBox->SetLabel(new BStringView(BRect(0,0,150,15), "memoryLabel", " Memory Ranges "));
resources->AddChild(memoryBox);
ioListView = new BListView(BRect(14,22,164,127), "ioListView");
memoryListView = new BListView(BRect(14,22,164,127), "memoryListView");
BScrollView *ioScrollView = new BScrollView("ioScrollView", ioListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
ioPortBox->AddChild(ioScrollView);
BScrollView *memoryScrollView = new BScrollView("memoryScrollView", memoryListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
memoryBox->AddChild(memoryScrollView);
struct device_configuration *current = devicesInfo->GetCurrent();
resource_descriptor r;
{
int32 k = 0;
int32 num = count_resource_descriptors_of_type(current, B_IRQ_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_IRQ_RESOURCE,
&r, sizeof(resource_descriptor));
uint32 mask = r.d.m.mask;
int16 j = 0;
if (!mask)
continue;
for (;mask;mask>>=1,j++)
if (mask & 1) {
char value[50];
sprintf(value, "%d", j);
BMenuItem *item = new BMenuItem(value, new BMessage(IRQ_CHANGED));
fIRQMenu[k]->AddItem(item);
item->SetMarked(true);
fIRQField[k]->SetEnabled(true);
}
}
}
{
int32 k = 0;
int32 num = count_resource_descriptors_of_type(current, B_DMA_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_DMA_RESOURCE,
&r, sizeof(resource_descriptor));
uint32 mask = r.d.m.mask;
int16 j = 0;
if (!mask)
continue;
for (;mask;mask>>=1,j++)
if (mask & 1) {
char value[50];
sprintf(value, "%d", j);
BMenuItem *item = new BMenuItem(value, new BMessage(DMA_CHANGED));
fDMAMenu[k++]->AddItem(item);
item->SetMarked(true);
fDMAField[k]->SetEnabled(true);
}
}
}
{
int32 num = count_resource_descriptors_of_type(current, B_IO_PORT_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_IO_PORT_RESOURCE,
&r, sizeof(resource_descriptor));
ioListView->AddItem(new RangeConfItem(r.d.r.minbase,
r.d.r.minbase + r.d.r.len - 1));
}
ioListView->SortItems(&RangeConfItem::Compare);
}
{
int32 num = count_resource_descriptors_of_type(current, B_MEMORY_RESOURCE);
for (int32 i=0;i<num;i++) {
get_nth_resource_descriptor_of_type(current, i, B_MEMORY_RESOURCE,
&r, sizeof(resource_descriptor));
memoryListView->AddItem(new RangeConfItem(r.d.r.minbase,
r.d.r.minbase + r.d.r.len - 1));
}
memoryListView->SortItems(&RangeConfItem::Compare);
}
BBox *info = new BBox(rlist, "info",
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW, B_NO_BORDER);
BRect labelRect(1, 10, 122, 30);
BStringView *label = new BStringView(labelRect, "Card Name", "Card Name:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Device Name", "Device Name:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Logical Device Name", "Logical Device Name:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Bus Type", "Bus Type:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Device Type", "Device Type:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 36);
label = new BStringView(labelRect, "Vendor", "Vendor:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Card ID", "Card ID:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Current State", "Current State:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Resource Conflicts", "Resource Conflicts:");
label->SetAlignment(B_ALIGN_RIGHT);
info->AddChild(label);
BString cardName = "<Unknown>";
BString logicalDeviceName = "<Unknown>";
BString bus;
switch (devicesInfo->GetInfo()->bus) {
case B_ISA_BUS: bus = "ISA device"; break;
case B_PCI_BUS: bus = "PCI device"; break;
case B_PCMCIA_BUS: bus = "PCMCIA device"; break;
default: bus = "<Unknown>"; break;
}
BString deviceType1, deviceType2;
deviceType1 += devicesInfo->GetBaseString();
deviceType1 += " (";
deviceType1 += devicesInfo->GetSubTypeString();
deviceType1 += ")";
char typeString[255];
sprintf(typeString, "Base: %x Subtype: %x Interface: %x",
devicesInfo->GetInfo()->devtype.base,
devicesInfo->GetInfo()->devtype.subtype,
devicesInfo->GetInfo()->devtype.interface);
deviceType2 = typeString;
BString vendor;
BString vendorString = "<Unknown>";
BString cardID = "";
BString resourceConflicts = "None";
switch (devicesInfo->GetInfo()->bus) {
case B_ISA_BUS:
{
char string[255];
uint32 id = devicesInfo->GetInfo()->id[2];
sprintf(string, "%c%c%c Product: %x%x Revision: %x",
((uint8)(id >> 2) & 0x1f) + 'A' - 1,
((uint8)(id & 0x3) << 3) + ((uint8)(id >> 13) & 0x7) + 'A' - 1,
(uint8)(id >> 8) & 0x1f + 'A' - 1,
(uint8)(id >> 16) & 0xf,
(uint8)(id >> 20) & 0xf,
(uint8)((id >> 24) & 0xff));
vendor = string;
cardID = "0";
}
break;
case B_PCI_BUS:
{
for (uint32 i=0; i<PCI_VENTABLE_LEN; i++)
if (PciVenTable[i].VenId == devicesInfo->GetInfo()->id[0] & 0xffff) {
vendorString = PciVenTable[i].VenFull;
break;
}
char string[255];
sprintf(string, "%s (0x%04lx)", vendorString.String(), devicesInfo->GetInfo()->id[0] & 0xffff);
vendor = string;
sprintf(string, "%04lx", devicesInfo->GetInfo()->id[1] & 0xffff);
cardID = string;
}
break;
case B_PCMCIA_BUS: vendor = "XX"; break;
default: vendor = "<Unknown>"; break;
}
BString state = "Enabled";
if (!(devicesInfo->GetInfo()->flags & B_DEVICE_INFO_ENABLED))
switch (devicesInfo->GetInfo()->config_status) {
case B_DEV_RESOURCE_CONFLICT: state = "Disabled by System"; break;
case B_DEV_DISABLED_BY_USER: state = "Disabled by User"; break;
default: state = "Disabled for Unknown Reason"; break;
}
labelRect = BRect(127, 10, 400, 30);
label = new BStringView(labelRect, "Card Name", cardName.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Device Name", devicesInfo->GetName());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Logical Device Name", logicalDeviceName.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Bus Type", bus.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Device Type", deviceType1.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Device Type", deviceType2.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Vendor", vendor.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Card ID", cardID.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Current State", state.String());
info->AddChild(label);
labelRect.OffsetBy(0, 18);
label = new BStringView(labelRect, "Resource Conflicts", resourceConflicts.String());
info->AddChild(label);
BTab *tab = new BTab();
tabView->AddTab(resources, tab);
tab->SetLabel("Resources");
tab = new BTab();
tabView->AddTab(info, tab);
tab->SetLabel("Info");
background->AddChild(tabView);
ioListView->Select(0);
memoryListView->Select(0);
}
// -------------------------------------------------------------------------------------------------- //
// ConfigurationWindow::MessageReceived -- receives messages
void
ConfigurationWindow::MessageReceived (BMessage *message)
{
switch(message->what)
{
default:
BWindow::MessageReceived(message);
break;
}
}
// -------------------------------------------------------------------------------------------------- //
// ConfigurationWindow::QuitRequested -- Post a message to the app to quit
bool
ConfigurationWindow::QuitRequested()
{
fItem->SetWindow(NULL);
return true;
}
// ---------------------------------------------------------------------------------------------------------- //

View File

@ -1,21 +1,36 @@
/*
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003-2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: Devices.cpp
// Author: Sikosis, Jérôme Duval
// Description: Devices Preferences
// Created : March 04, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Devices by Sikosis
(C)2003 OBOS
*/
// Includes -------------------------------------------------------------------------------------------------- //
#include <Application.h>
#include <Window.h>
#include <View.h>
#include "Devices.h"
#include "DevicesWindows.h"
#define APP_SIGNATURE "application/x-vnd.OBOS.Devices" // Application Signature and Title
class Devices : public BApplication
{
public:
Devices();
virtual void MessageReceived(BMessage *message);
private:
};
// ---------------------------------------------------------------------------------------------------------- //
// Devices -- constructor

View File

@ -1,24 +0,0 @@
/*
Devices Header by Sikosis
(C)2003 OBOS
*/
#ifndef __DEVICES_H__
#define __DEVICES_H__
extern const char *APP_SIGNATURE;
class Devices : public BApplication
{
public:
Devices();
virtual void MessageReceived(BMessage *message);
private:
};
#endif

View File

@ -1,3 +1,18 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: DevicesInfo.cpp
// Author: Jérôme Duval
// Description: Devices Preferences
// Created : April 15, 2004
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#include <strings.h>
#include <GraphicsDefs.h>
#include <String.h>
@ -97,6 +112,8 @@ DevicesInfo::DevicesInfo(struct device_info *info,
fName = strdup((info->devtype.base < 13)
? ( (s && s->name) ? s->name : base_desc[info->devtype.base])
: "Unknown");
fBaseString = strdup((info->devtype.base < 13) ? base_desc[info->devtype.base] : "Unknown");
fSubTypeString = strdup((s && s->name) ? s->name : "Unknown");
}
@ -105,11 +122,15 @@ DevicesInfo::~DevicesInfo()
delete fInfo;
delete fCurrent;
delete fPossible;
delete fName;
delete fBaseString;
delete fSubTypeString;
}
DeviceItem::DeviceItem(DevicesInfo *info, const char* name)
: BListItem(),
fInfo(info)
fInfo(info),
fWindow(NULL)
{
fName = strdup(name);
}
@ -144,23 +165,29 @@ DeviceItem::DrawItem(BView *owner, BRect itemRect, bool complete)
owner->SetLowColor(owner->ViewColor());
}
BPoint point = itemRect.LeftTop() + BPoint(5, 10);
BFont font = be_plain_font;
font_height finfo;
font.GetHeight(&finfo);
BPoint point = BPoint(itemRect.left + 4, itemRect.bottom - finfo.descent + 1);
owner->SetHighColor(kBlack);
owner->SetFont(be_plain_font);
owner->SetFont(&font);
owner->MovePenTo(point);
owner->DrawString(fName);
point += BPoint(223, 0);
BString string = "enabled";
if (!(fInfo->GetInfo()->flags & B_DEVICE_INFO_ENABLED))
switch (fInfo->GetInfo()->config_status) {
case B_DEV_RESOURCE_CONFLICT: string = "disabled by system"; break;
case B_DEV_DISABLED_BY_USER: string = "disabled by user"; break;
default: string = "disabled for unknown reason"; break;
}
owner->MovePenTo(point);
owner->DrawString(string.String());
if(fInfo) {
point += BPoint(222, 0);
BString string = "enabled";
if (!(fInfo->GetInfo()->flags & B_DEVICE_INFO_ENABLED))
switch (fInfo->GetInfo()->config_status) {
case B_DEV_RESOURCE_CONFLICT: string = "disabled by system"; break;
case B_DEV_DISABLED_BY_USER: string = "disabled by user"; break;
default: string = "disabled for unknown reason"; break;
}
owner->MovePenTo(point);
owner->DrawString(string.String());
}
}

View File

@ -1,8 +1,24 @@
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: DevicesInfo.h
// Author: Jérôme Duval
// Description: Devices Preferences
// Created : April 15, 2004
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
#ifndef __DEVICESINFO_H__
#define __DEVICESINFO_H__
#include <drivers/config_manager.h>
#include <ListItem.h>
#include <Window.h>
class DevicesInfo
{
@ -13,12 +29,14 @@ class DevicesInfo
~DevicesInfo();
struct device_info * GetInfo() { return fInfo;}
char * GetName() const { return fName; }
char * GetBaseString() const { return fBaseString; }
char * GetSubTypeString() const { return fSubTypeString; }
struct device_configuration * GetCurrent() { return fCurrent;}
private:
struct device_info *fInfo;
struct device_configuration *fCurrent;
struct possible_device_configurations *fPossible;
char* fName;
char* fName, *fBaseString, *fSubTypeString;
};
class DeviceItem : public BListItem
@ -28,9 +46,12 @@ class DeviceItem : public BListItem
~DeviceItem();
DevicesInfo *GetInfo() { return fInfo; }
virtual void DrawItem(BView *, BRect, bool = false);
BWindow *GetWindow() { return fWindow; };
void SetWindow(BWindow *window) { fWindow = window; };
private:
DevicesInfo *fInfo;
char* fName;
BWindow *fWindow;
};
#endif

View File

@ -1,26 +1,26 @@
/*
Devices - DevicesWindow by Sikosis
(C)2003 OBOS
*/
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003-2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: DevicesWindow.cpp
// Author: Sikosis, Jérôme Duval
// Description: Devices Preferences
// Created : March 04, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// Includes -------------------------------------------------------------------------------------------------- //
#include <Alert.h>
#include <Application.h>
#include <Bitmap.h>
#include <Box.h>
#include <Button.h>
#include <ClassInfo.h>
#include <Directory.h>
#include <Entry.h>
#include <File.h>
#include <FilePanel.h>
#include <FindDirectory.h>
#include <Node.h>
#include <Path.h>
#include <MenuBar.h>
#include <Menu.h>
#include <MenuItem.h>
@ -28,16 +28,12 @@ Devices - DevicesWindow by Sikosis
#include <Path.h>
#include <Screen.h>
#include <ScrollView.h>
#include <Shape.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <String.h>
#include <StringView.h>
#include <Window.h>
#include <View.h>
#include "Devices.h"
#include "DevicesWindows.h"
#include "DevicesInfo.h"
@ -53,7 +49,7 @@ const uint32 SELECTION_CHANGED = 'slch';
// CenterWindowOnScreen -- Centers the BWindow to the Current Screen
static void CenterWindowOnScreen(BWindow* w)
void CenterWindowOnScreen(BWindow* w)
{
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
BPoint pt;
@ -131,8 +127,6 @@ DevicesWindow::~DevicesWindow()
// DevicesWindow::InitWindow -- Initialization Commands here
void DevicesWindow::InitWindow(void)
{
int LeftMargin = 16;
int RightMargin = 246;
BRect r;
r = Bounds(); // the whole view
@ -165,8 +159,8 @@ void DevicesWindow::InitWindow(void)
mniRemoveJumperedDevice->SetEnabled(false);
// Create the StringViews
stvDeviceName = new BStringView(BRect(LeftMargin, 16, 150, 40), "DeviceName", "Device Name");
stvCurrentState = new BStringView(BRect(RightMargin, 16, r.right-10, 40), "CurrentState", "Current State");
stvDeviceName = new BStringView(BRect(16, 16, 150, 40), "DeviceName", "Device Name");
stvCurrentState = new BStringView(BRect(248, 16, r.right-10, 40), "CurrentState", "Current State");
float fCurrentHeight = 279;
float fCurrentGap = 15;
@ -180,19 +174,20 @@ void DevicesWindow::InitWindow(void)
fCurrentHeight = fCurrentHeight + fCurrentGap;
// Create the OutlineView
BRect outlinerect(r.left+12,r.top+45,r.right-29,r.top+262);
BRect outlinerect(r.left+14,r.top+45,r.right-28,r.top+262);
BScrollView *outlinesv;
outline = new BOutlineListView(outlinerect,"devices_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM);
outline->AddItem(systemMenu = new BStringItem("System Devices"));
outline->AddItem(isaMenu = new BStringItem("ISA/Plug and Play Devices"));
outline->AddItem(pciMenu = new BStringItem("PCI Devices"));
outline->AddItem(jumperedMenu = new BStringItem("Jumpered Devices"));
outline = new BOutlineListView(outlinerect,"devices_list", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM);
outline->AddItem(systemMenu = new DeviceItem(NULL, "System Devices"));
outline->AddItem(isaMenu = new DeviceItem(NULL, "ISA/Plug and Play Devices"));
outline->AddItem(pciMenu = new DeviceItem(NULL, "PCI Devices"));
outline->AddItem(jumperedMenu = new DeviceItem(NULL, "Jumpered Devices"));
outline->SetSelectionMessage(new BMessage(SELECTION_CHANGED));
outline->SetInvocationMessage(new BMessage(BTN_CONFIGURE));
// Add ScrollView to Devices Window
outlinesv = new BScrollView("scroll_devices", outline, B_FOLLOW_LEFT|B_FOLLOW_TOP_BOTTOM, 0, false, true, B_FANCY_BORDER);
outlinesv = new BScrollView("scroll_devices", outline, B_FOLLOW_LEFT_RIGHT|B_FOLLOW_TOP_BOTTOM, 0, false, true, B_FANCY_BORDER);
// Setup the OutlineView
outline->AllAttached();
@ -211,11 +206,11 @@ void DevicesWindow::InitWindow(void)
// Create BBox (or Frame)
BBox *BottomFrame;
BRect BottomFrameRect(r.left+11,r.bottom-124,r.right-12,r.bottom-12);
BottomFrame = new BBox(BottomFrameRect, "BottomFrame", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER);
BottomFrame = new BBox(BottomFrameRect, "BottomFrame", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER);
// Create BButton - Configure
BRect ConfigureButtonRect(r.left+298,r.bottom-47,r.right-23,r.bottom-23);
btnConfigure = new BButton(ConfigureButtonRect,"btnConfigure","Configure", new BMessage(BTN_CONFIGURE), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
btnConfigure = new BButton(ConfigureButtonRect,"btnConfigure","Configure", new BMessage(BTN_CONFIGURE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW | B_NAVIGABLE);
btnConfigure->MakeDefault(true);
btnConfigure->SetEnabled(false);
@ -236,7 +231,10 @@ void DevicesWindow::InitWindow(void)
background->AddChild(BottomFrame);
// Set Window Limits
SetSizeLimits(396,396,400,BScreen().Frame().Height());
float xsize = 396 + (be_plain_font->Size()-10)*40;
if (xsize > 443)
xsize = 443;
SetSizeLimits(xsize,xsize,400,BScreen().Frame().Height());
}
// ---------------------------------------------------------------------------------------------------------- //
@ -318,6 +316,17 @@ DevicesWindow::MessageReceived (BMessage *message)
}
break;
case BTN_CONFIGURE:
{
DeviceItem *item = (DeviceItem *)outline->ItemAt(outline->CurrentSelection());
if (item && is_instance_of(item, DeviceItem) ) {
if (item->GetWindow()!=NULL)
item->GetWindow()->Activate();
else
new ConfigurationWindow(BRect(150,150,562,602), item);
}
}
break;
default:
BWindow::MessageReceived(message);
break;

View File

@ -1,19 +1,35 @@
/*
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003-2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: DevicesWindows.h
// Author: Sikosis, Jérôme Duval
// Description: Devices Preferences
// Created : March 04, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Devices Windows Header by Sikosis
(C)2003 OBOS
*/
#ifndef __DEVICESWINDOWS_H__
#define __DEVICESWINDOWS_H__
#include "Devices.h"
#include <ListView.h>
#include <Menu.h>
#include <PopUpMenu.h>
#include <Window.h>
#include "DevicesInfo.h"
#include "cm_wrapper.h"
#define MODEM_ADDED 'moad'
void CenterWindowOnScreen(BWindow* w);
class ResourceUsageWindow : public BWindow
{
public:
@ -23,8 +39,6 @@ class ResourceUsageWindow : public BWindow
private:
void InitWindow(BList &);
BTabView *tabView;
BTab *tab;
};
@ -39,6 +53,24 @@ class ModemWindow : public BWindow
BMessenger fMessenger;
};
class ConfigurationWindow : public BWindow
{
public:
ConfigurationWindow(BRect frame, DeviceItem *item);
~ConfigurationWindow();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
private:
void InitWindow(void);
DeviceItem *fItem;
BMenu *fConfigurationMenu;
BPopUpMenu *fIRQMenu[3];
BMenuField *fIRQField[3];
BPopUpMenu *fDMAMenu[3];
BMenuField *fDMAField[3];
BListView *ioListView, *memoryListView;
};
class DevicesWindow : public BWindow
{

View File

@ -2,7 +2,8 @@ SubDir OBOS_TOP src prefs devices ;
AddResources Devices : Devices.rdef ;
UsePrivateHeaders Devices ;
#UsePrivateHeaders Devices ;
UsePrivateHeaders [ FDirName kernel ] ;
Preference Devices :
Devices.cpp
@ -11,6 +12,7 @@ Preference Devices :
ModemWindow.cpp
cm_wrapper.c
DevicesInfo.cpp
ConfigurationWindow.cpp
;
LinkSharedOSLibs Devices : be ;

View File

@ -1,27 +1,33 @@
/*
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003-2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: ModemWindow.cpp
// Author: Sikosis, Jérôme Duval
// Description: Devices Preferences
// Created : August 23, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
ModemWindow
Author: Sikosis
(C)2003 OBOS - Released under the MIT License
*/
// Includes ------------------------------------------------------------------------------------------ //
#include <Application.h>
//#include <Application.h>
#include <Box.h>
#include <Button.h>
#include <MenuItem.h>
#include <MenuField.h>
#include <Path.h>
#include <PopUpMenu.h>
//#include <Path.h>
//#include <PopUpMenu.h>
#include <Screen.h>
#include <stdio.h>
#include <String.h>
//#include <stdio.h>
//#include <String.h>
#include <TextView.h>
#include <Window.h>
#include <View.h>
//#include <Window.h>
//#include <View.h>
#include "DevicesWindows.h"
@ -29,17 +35,6 @@ Author: Sikosis
const uint32 BTN_ADD = 'badd';
const uint32 BTN_CANCEL = 'bcnl';
// CenterWindowOnScreen -- Centers the BWindow to the Current Screen
static void CenterWindowOnScreen(BWindow* w)
{
BRect screenFrame = (BScreen(B_MAIN_SCREEN_ID).Frame());
BPoint pt;
pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2;
pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2;
if (screenFrame.Contains(pt))
w->MoveTo(pt);
}
// -------------------------------------------------------------------------------------------------- //
@ -58,12 +53,12 @@ ModemWindow::ModemWindow(BRect frame, BMessenger messenger)
// ModemWindow - Destructor
ModemWindow::~ModemWindow()
{
//exit(0);
}
// -------------------------------------------------------------------------------------------------- //
// ModemWindow::InitWindow -- Initialization Commands here
void ModemWindow::InitWindow(void)
void
ModemWindow::InitWindow(void)
{
BRect r;
r = Bounds();
@ -133,7 +128,8 @@ void ModemWindow::InitWindow(void)
// ModemWindow::MessageReceived -- receives messages
void ModemWindow::MessageReceived (BMessage *message)
void
ModemWindow::MessageReceived (BMessage *message)
{
switch(message->what)
{
@ -154,8 +150,3 @@ void ModemWindow::MessageReceived (BMessage *message)
}
}
// -------------------------------------------------------------------------------------------------- //

View File

@ -1,28 +1,27 @@
/*
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
//
// Copyright (c) 2003-2004, OpenBeOS
//
// This software is part of the OpenBeOS distribution and is covered
// by the OpenBeOS license.
//
//
// File: ResourceUsageWindow.cpp
// Author: Sikosis, Jérôme Duval
// Description: Devices Preferences
// Created : July 19, 2003
//
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
ResourceUsageWindow
Author: Sikosis
(C)2003 OBOS - Released under the MIT License
*/
// Includes ------------------------------------------------------------------------------------------ //
#include <Application.h>
#include <Box.h>
#include <List.h>
#include <ListView.h>
#include <Path.h>
#include <Screen.h>
#include <ScrollView.h>
#include <stdio.h>
#include <String.h>
#include <strings.h>
#include <TabView.h>
#include <Window.h>
#include <View.h>
#include "Devices.h"
#include "DevicesInfo.h"
#include "DevicesWindows.h"
@ -75,7 +74,11 @@ IRQDMAItem::DrawItem(BView *owner, BRect itemRect, bool complete)
owner->SetLowColor(owner->ViewColor());
}
BPoint point = itemRect.LeftTop() + BPoint(5, 10);
BFont font = be_plain_font;
font_height finfo;
font.GetHeight(&finfo);
BPoint point = BPoint(itemRect.left + 5, itemRect.bottom - finfo.descent + 1);
owner->SetHighColor(kBlack);
owner->SetFont(be_plain_font);
@ -141,7 +144,11 @@ RangeItem::DrawItem(BView *owner, BRect itemRect, bool complete)
owner->SetLowColor(owner->ViewColor());
}
BPoint point = itemRect.LeftTop() + BPoint(17, 10);
BFont font = be_plain_font;
font_height finfo;
font.GetHeight(&finfo);
BPoint point = BPoint(itemRect.left + 17, itemRect.bottom - finfo.descent + 1);
owner->SetFont(be_fixed_font);
owner->SetHighColor(kBlack);
owner->MovePenTo(point);
@ -172,19 +179,7 @@ RangeItem::Compare(const void *firstArg, const void *secondArg)
}
// -------------------------------------------------------------------------------------------------- //
// CenterWindowOnScreen -- Centers the BWindow to the Current Screen
static void CenterWindowOnScreen(BWindow* w)
{
BRect screenFrame = (BScreen().Frame());
BPoint pt;
pt.x = screenFrame.Width()/2 - w->Bounds().Width()/2;
pt.y = screenFrame.Height()/2 - w->Bounds().Height()/2;
if (screenFrame.Contains(pt))
w->MoveTo(pt);
}
// -------------------------------------------------------------------------------------------------- //
@ -219,21 +214,21 @@ void ResourceUsageWindow::InitWindow(BList &list)
rlist.bottom -= 47;
// Create the TabView and Tabs
tabView = new BTabView(rtab,"resource_usage_tabview");
BTabView *tabView = new BTabView(rtab,"resource_usage_tabview");
tabView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
rtab = tabView->Bounds();
rtab.InsetBy(5,5);
// Create the ListViews
BListView *IRQListView = new BListView(rlist, "IRQListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BListView *DMAListView = new BListView(rlist, "DMAListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BListView *IORangeListView = new BListView(rlist, "IORangeListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BListView *memoryListView = new BListView(rlist, "memoryListView", B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT | B_FOLLOW_TOP,
B_WILL_DRAW | B_NAVIGABLE);
BListView *IRQListView = new BListView(rlist, "IRQListView", B_SINGLE_SELECTION_LIST,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
BListView *DMAListView = new BListView(rlist, "DMAListView", B_SINGLE_SELECTION_LIST,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
BListView *IORangeListView = new BListView(rlist, "IORangeListView", B_SINGLE_SELECTION_LIST,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
BListView *memoryListView = new BListView(rlist, "memoryListView", B_SINGLE_SELECTION_LIST,
B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE);
BScrollView *IRQScrollView = new BScrollView("scroll_list1", IRQListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
@ -244,7 +239,7 @@ void ResourceUsageWindow::InitWindow(BList &list)
BScrollView *memoryScrollView = new BScrollView("scroll_list4", memoryListView, B_FOLLOW_LEFT|B_FOLLOW_TOP,
0, false, true, B_FANCY_BORDER);
tab = new BTab();
BTab *tab = new BTab();
tabView->AddTab(IRQScrollView, tab);
tab->SetLabel("IRQ");
tab = new BTab();
@ -329,13 +324,35 @@ void ResourceUsageWindow::InitWindow(BList &list)
get_nth_resource_descriptor_of_type(current, k, B_IO_PORT_RESOURCE,
&r, sizeof(resource_descriptor));
IORangeListView->AddItem(new RangeItem(r.d.r.minbase, r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetName()));
IORangeListView->AddItem(new RangeItem(r.d.r.minbase,
r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetName()));
}
}
IORangeListView->SortItems(&RangeItem::Compare);
}
{
for (int32 j=0; j<list.CountItems(); j++) {
DevicesInfo *deviceInfo = (DevicesInfo *)list.ItemAt(j);
struct device_configuration *current = deviceInfo->GetCurrent();
resource_descriptor r;
int32 num = count_resource_descriptors_of_type(current, B_MEMORY_RESOURCE);
for (int32 k=0;k<num;k++) {
get_nth_resource_descriptor_of_type(current, k, B_MEMORY_RESOURCE,
&r, sizeof(resource_descriptor));
memoryListView->AddItem(new RangeItem(r.d.r.minbase,
r.d.r.minbase + r.d.r.len - 1, deviceInfo->GetName()));
}
}
memoryListView->SortItems(&RangeItem::Compare);
}
BBox *background = new BBox(Bounds(), "background");
background->SetBorder(B_NO_BORDER);
AddChild(background);