xref: /haiku/src/preferences/repositories/RepoRow.cpp (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
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 <Catalog.h>
13 #include <ColumnTypes.h>
14 
15 #include "constants.h"
16 
17 
18 #undef B_TRANSLATION_CONTEXT
19 #define B_TRANSLATION_CONTEXT "RepoRow"
20 
21 
22 RepoRow::RepoRow(const char* repo_name, const char* repo_url, bool enabled)
23 	:
24 	BRow(),
25 	fName(repo_name),
26 	fUrl(repo_url),
27 	fEnabled(enabled),
28 	fTaskState(STATE_NOT_IN_QUEUE)
29 {
30 	SetField(new BStringField(""), kEnabledColumn);
31 	SetField(new BStringField(fName.String()), kNameColumn);
32 	SetField(new BStringField(fUrl.String()), kUrlColumn);
33 	if (enabled)
34 		SetEnabled(enabled);
35 }
36 
37 
38 void
39 RepoRow::SetName(const char* name)
40 {
41 	BStringField* field = (BStringField*)GetField(kNameColumn);
42 	field->SetString(name);
43 	fName.SetTo(name);
44 	Invalidate();
45 }
46 
47 
48 void
49 RepoRow::SetEnabled(bool enabled)
50 {
51 	fEnabled = enabled;
52 	RefreshEnabledField();
53 }
54 
55 
56 void
57 RepoRow::RefreshEnabledField()
58 {
59 	BStringField* field = (BStringField*)GetField(kEnabledColumn);
60 	if (fTaskState == STATE_NOT_IN_QUEUE)
61 		field->SetString(fEnabled ? B_TRANSLATE_COMMENT("Enabled",
62 			"Tag in the Status column") : "");
63 	else
64 		field->SetString(B_UTF8_ELLIPSIS);
65 	Invalidate();
66 }
67 
68 
69 void
70 RepoRow::SetTaskState(uint32 state)
71 {
72 	fTaskState = state;
73 	RefreshEnabledField();
74 }
75