xref: /haiku/src/apps/devices/PropertyList.cpp (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 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 "PropertyList.h"
11 
12 #include <Catalog.h>
13 #include <ColumnTypes.h>
14 
15 #undef B_TRANSLATION_CONTEXT
16 #define B_TRANSLATION_CONTEXT "PropertyList"
17 
18 
19 PropertyRow::PropertyRow(const char* name, const char* value)
20 	: BRow(),
21 	fName(name), fValue(value)
22 {
23 	SetField(new BStringField(name), kNameColumn);
24 	SetField(new BStringField(value), kValueColumn);
25 }
26 
27 
28 PropertyRow::~PropertyRow()
29 {
30 }
31 
32 
33 void
34 PropertyRow::SetName(const char* name)
35 {
36 	fName = name;
37 	SetField(new BStringField(name), kNameColumn);
38 }
39 
40 
41 void
42 PropertyRow::SetValue(const char* value)
43 {
44 	fValue = value;
45 	SetField(new BStringField(value), kValueColumn);
46 }
47 
48 
49 PropertyList::PropertyList(const char* name)
50 	: BColumnListView(BRect(0.0, 0.0, 1.0, 1.0), name, B_FOLLOW_ALL, 0,
51 		B_NO_BORDER, true)
52 {
53 	BStringColumn* nameColumn;
54 	AddColumn(nameColumn = new BStringColumn(B_TRANSLATE("Name"), 150, 50, 500,
55 			B_TRUNCATE_MIDDLE),
56 		kNameColumn);
57 	AddColumn(new BStringColumn(B_TRANSLATE("Value"), 150, 50, 500,
58 		B_TRUNCATE_END), kValueColumn);
59 	SetSortColumn(nameColumn, false, true);
60 }
61 
62 
63 PropertyList::~PropertyList()
64 {
65 	RemoveAll();
66 }
67 
68 
69 void
70 PropertyList::AddAttributes(const Attributes& attributes)
71 {
72 	RemoveAll();
73 	for (unsigned int i = 0; i < attributes.size(); i++) {
74 		AddRow(new PropertyRow(attributes[i].fName, attributes[i].fValue));
75 	}
76 }
77 
78 
79 void
80 PropertyList::RemoveAll()
81 {
82 	BRow *row;
83 	while ((row = RowAt((int32)0, NULL))!=NULL) {
84 		RemoveRow(row);
85 		delete row;
86 	}
87 }
88 
89 
90 void
91 PropertyList::SelectionChanged()
92 {
93 }
94