2 * Copyright 2003-2008 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
10 #include "HEventList.h"
14 #include <ColumnTypes.h>
17 #include <MediaFiles.h>
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "HEventList"
26 HEventRow::HEventRow(const char* name
, const char* path
)
31 SetField(new BStringField(name
), kEventColumn
);
36 HEventRow::~HEventRow()
42 HEventRow::SetPath(const char* _path
)
46 SetField(new BStringField(_path
? path
.Leaf() : B_TRANSLATE("<none>")),
52 HEventRow::Remove(const char* type
)
54 BMediaFiles().RemoveItem(type
, Name());
58 HEventList::HEventList(const char* name
)
60 BColumnListView(name
, B_NAVIGABLE
, B_PLAIN_BORDER
, true),
63 AddColumn(new BStringColumn(B_TRANSLATE("Event"), 180, 50, 500,
64 B_TRUNCATE_MIDDLE
), kEventColumn
);
65 AddColumn(new BStringColumn(B_TRANSLATE("Sound"), 130, 50, 500,
66 B_TRUNCATE_END
), kSoundColumn
);
70 HEventList::~HEventList()
78 HEventList::SetType(const char* type
)
82 mfiles
.RewindRefs(type
);
88 while (mfiles
.GetNextRef(&name
,&ref
) == B_OK
) {
90 if (path
.InitCheck() != B_OK
|| ref
.name
== NULL
91 || strcmp(ref
.name
, "") == 0)
92 AddRow(new HEventRow(name
.String(), NULL
));
94 AddRow(new HEventRow(name
.String(), path
.Path()));
97 ResizeAllColumnsToPreferred();
102 HEventList::RemoveAll()
105 while ((row
= RowAt((int32
)0, NULL
)) != NULL
) {
113 HEventList::SelectionChanged()
115 BColumnListView::SelectionChanged();
117 HEventRow
* row
= (HEventRow
*)CurrentSelection();
120 BMediaFiles().GetRefFor(fType
, row
->Name(), &ref
);
123 if (path
.InitCheck() == B_OK
|| ref
.name
== NULL
124 || strcmp(ref
.name
, "") == 0) {
125 row
->SetPath(path
.Path());
128 printf("name %s\n", ref
.name
);
129 BMediaFiles().RemoveRefFor(fType
, row
->Name(), ref
);
130 BAlert
* alert
= new BAlert("alert",
131 B_TRANSLATE("No such file or directory"), B_TRANSLATE("OK"));
132 alert
->SetFlags(alert
->Flags() | B_CLOSE_ON_ESCAPE
);
136 BMessage
msg(M_EVENT_CHANGED
);
137 msg
.AddString("name", row
->Name());
138 msg
.AddString("path", row
->Path());
139 Window()->PostMessage(&msg
);
145 HEventList::SetPath(const char* path
)
147 HEventRow
* row
= (HEventRow
*)CurrentSelection();
152 BMediaFiles().SetRefFor(fType
, row
->Name(), ref
);