xref: /haiku/src/preferences/repositories/RepoRow.cpp (revision 6aff37d1c79e20748c683ae224bd629f88a5b0be)
1 /*
2  * Copyright 2017 Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Brian Hill
7  */
8 
9 
10 #include "RepoRow.h"
11 
12 #include <ColumnTypes.h>
13 
14 #include "constants.h"
15 
16 
17 RepoRow::RepoRow(const char* repo_name, const char* repo_url, bool enabled)
18 	:
19 	BRow(),
20 	fName(repo_name),
21 	fUrl(repo_url),
22 	fEnabled(enabled),
23 	fTaskState(STATE_NOT_IN_QUEUE)
24 {
25 	SetField(new BStringField(""), kEnabledColumn);
26 	SetField(new BStringField(fName.String()), kNameColumn);
27 	SetField(new BStringField(fUrl.String()), kUrlColumn);
28 	if (enabled)
29 		SetEnabled(enabled);
30 }
31 
32 
33 void
34 RepoRow::SetName(const char* name)
35 {
36 	BStringField* field = (BStringField*)GetField(kNameColumn);
37 	field->SetString(name);
38 	fName.SetTo(name);
39 	Invalidate();
40 }
41 
42 
43 void
44 RepoRow::SetEnabled(bool enabled)
45 {
46 	fEnabled = enabled;
47 	RefreshEnabledField();
48 }
49 
50 
51 void
52 RepoRow::RefreshEnabledField()
53 {
54 	BStringField* field = (BStringField*)GetField(kEnabledColumn);
55 	if (fTaskState == STATE_NOT_IN_QUEUE)
56 		field->SetString(fEnabled ? B_TRANSLATE("Enabled") : "");
57 	else
58 		field->SetString(B_UTF8_ELLIPSIS);
59 	Invalidate();
60 }
61 
62 
63 void
64 RepoRow::SetTaskState(uint32 state)
65 {
66 	fTaskState = state;
67 	RefreshEnabledField();
68 }
69