xref: /haiku/src/apps/devices/Device.cpp (revision 1c09002cbee8e797a0f8bbfc5678dfadd39ee1a7)
1 /*
2  * Copyright 2008-2009 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Pieter Panman
7  */
8 
9 
10 #include "Device.h"
11 
12 #include <iostream>
13 
14 #include <Catalog.h>
15 
16 #undef B_TRANSLATE_CONTEXT
17 #define B_TRANSLATE_CONTEXT "Device"
18 
19 // This list comes from the pciid list, except for the last one
20 const char* kCategoryString[] = {
21 	B_TRANSLATE("Unclassified device"), 				// 0x00
22 	B_TRANSLATE("Mass storage controller"),				// 0x01
23 	B_TRANSLATE("Network controller"),					// 0x02
24 	B_TRANSLATE("Display controller"), 					// 0x03
25 	B_TRANSLATE("Multimedia controller"), 				// 0x04
26 	B_TRANSLATE("Memory controller"),  					// 0x05
27 	B_TRANSLATE("Bridge"), 								// 0x06
28 	B_TRANSLATE("Communication controller"),  			// 0x07
29 	B_TRANSLATE("Generic system peripheral"),  			// 0x08
30 	B_TRANSLATE("Input device controller"),  			// 0x09
31 	B_TRANSLATE("Docking station"),  					// 0x0a
32 	B_TRANSLATE("Processor"),  							// 0x0b
33 	B_TRANSLATE("Serial bus controller"),  				// 0x0c
34 	B_TRANSLATE("Wireless controller"),  				// 0x0d
35 	B_TRANSLATE("Intelligent controller"),  			// 0x0e
36 	B_TRANSLATE("Satellite communications controller"), // 0x0f
37 	B_TRANSLATE("Encryption controller"),  				// 0x10
38 	B_TRANSLATE("Signal processing controller"),		// 0x11
39 	B_TRANSLATE("Computer"),							// 0x12 (added later)
40 	B_TRANSLATE("ACPI controller")						// 0x13 (added later)
41 };
42 
43 // This list is only used to translate Device properties
44 static const char* kTranslateMarkString[] = {
45 	B_TRANSLATE_MARK("unknown"),
46 	B_TRANSLATE_MARK("Device"),
47 	B_TRANSLATE_MARK("Computer"),
48 	B_TRANSLATE_MARK("ACPI bus"),
49 	B_TRANSLATE_MARK("PCI bus"),
50 	B_TRANSLATE_MARK("ISA bus"),
51 	B_TRANSLATE_MARK("Unknown device")
52 };
53 
54 
55 Device::Device(Device* physicalParent, BusType busType, Category category,
56 			const BString& name, const BString& manufacturer,
57 			const BString& driverUsed, const BString& devPathsPublished)
58 	:
59 	BStringItem(name.String()),
60 	fBusType(busType),
61 	fCategory(category),
62 	fPhysicalParent(physicalParent)
63 {
64 	SetAttribute(B_TRANSLATE("Device name"), B_TRANSLATE(name));
65 	SetAttribute(B_TRANSLATE("Manufacturer"), B_TRANSLATE(manufacturer));
66 	SetAttribute(B_TRANSLATE("Driver used"), B_TRANSLATE(driverUsed));
67 	SetAttribute(B_TRANSLATE("Device paths"), B_TRANSLATE(devPathsPublished));
68 }
69 
70 
71 Device::~Device()
72 {
73 }
74 
75 
76 void
77 Device::SetAttribute(const BString& name, const BString& value)
78 {
79 	if (name == B_TRANSLATE("Device name")) {
80 		SetText(value.String());
81 	}
82 	fAttributeMap[name] = value;
83 }
84 
85 
86 Attributes
87 Device::GetBasicAttributes()
88 {
89 	Attributes attributes;
90 	attributes.push_back(Attribute(B_TRANSLATE("Device name:"), GetName()));
91 	attributes.push_back(Attribute(B_TRANSLATE("Manufacturer:"),
92 		GetManufacturer()));
93 	return attributes;
94 }
95 
96 
97 Attributes
98 Device::GetBusAttributes()
99 {
100 	Attributes attributes;
101 	attributes.push_back(Attribute("None", ""));
102 	return attributes;
103 }
104 
105 
106 Attributes
107 Device::GetAllAttributes()
108 {
109 	Attributes attributes;
110 	AttributeMapIterator iter;
111 	for (iter = fAttributeMap.begin(); iter != fAttributeMap.end(); iter++) {
112 		attributes.push_back(Attribute(iter->first, iter->second));
113 	}
114 	return attributes;
115 }
116 
117 
118 BString
119 Device::GetBasicStrings()
120 {
121 	BString str(B_TRANSLATE("Device Name\t\t\t\t: %Name%\n"
122 							"Manufacturer\t\t\t: %Manufacturer%\n"
123 							"Driver used\t\t\t\t: %DriverUsed%\n"
124 							"Device paths\t: %DevicePaths%"));
125 
126 	str.ReplaceFirst("%Name%", GetName());
127 	str.ReplaceFirst("%Manufacturer%", GetManufacturer());
128 	str.ReplaceFirst("%DriverUsed%", GetDriverUsed());
129 	str.ReplaceFirst("%DevicePaths%", GetDevPathsPublished());
130 
131 	return str;
132 }
133 
134 BString
135 Device::GetBusStrings()
136 {
137 	return B_TRANSLATE("None");
138 }
139 
140 
141 BString
142 Device::GetBusTabName()
143 {
144 	return B_TRANSLATE("Bus Information");
145 }
146 
147 
148 BString
149 Device::GetAllStrings()
150 {
151 	BString str;
152 	AttributeMapIterator iter;
153 	for (iter = fAttributeMap.begin(); iter != fAttributeMap.end(); iter++) {
154 		str << iter->first << " : " << iter->second << "\n";
155 	}
156 	return str;
157 }
158