xref: /haiku/src/apps/haikudepot/model/UserDetail.cpp (revision 3af8011358bd4c624a0979336d48dabb466171ed)
1 /*
2  * Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
3  *
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 #include "UserDetail.h"
7 
8 
9 // These are keys that are used to store this object's data into a BMessage
10 // instance.
11 
12 #define KEY_NICKNAME							"nickname"
13 #define KEY_AGREEMENT							"agreement"
14 #define KEY_IS_LATEST							"isLatest"
15 #define KEY_CODE								"code"
16 #define KEY_TIMESTAMP_AGREED					"timestampAgreed"
17 
18 
19 UserUsageConditionsAgreement::UserUsageConditionsAgreement(BMessage* from)
20 {
21 	from->FindUInt64(KEY_TIMESTAMP_AGREED, &fTimestampAgreed);
22 	from->FindString(KEY_CODE, &fCode);
23 	from->FindBool(KEY_IS_LATEST, &fIsLatest);
24 }
25 
26 
27 UserUsageConditionsAgreement::UserUsageConditionsAgreement()
28 	:
29 	fCode(),
30 	fTimestampAgreed(0),
31 	fIsLatest(false)
32 {
33 }
34 
35 
36 UserUsageConditionsAgreement::~UserUsageConditionsAgreement()
37 {
38 }
39 
40 
41 const BString&
42 UserUsageConditionsAgreement::Code() const
43 {
44 	return fCode;
45 }
46 
47 
48 const uint64
49 UserUsageConditionsAgreement::TimestampAgreed() const
50 {
51 	return fTimestampAgreed;
52 }
53 
54 
55 const bool
56 UserUsageConditionsAgreement::IsLatest() const
57 {
58 	return fIsLatest;
59 }
60 
61 
62 void
63 UserUsageConditionsAgreement::SetCode(const BString& value)
64 {
65 	fCode = value;
66 }
67 
68 
69 void
70 UserUsageConditionsAgreement::SetTimestampAgreed(uint64 value)
71 {
72 	fTimestampAgreed = value;
73 }
74 
75 
76 void
77 UserUsageConditionsAgreement::SetIsLatest(const bool value)
78 {
79 	fIsLatest = value;
80 }
81 
82 
83 UserUsageConditionsAgreement&
84 UserUsageConditionsAgreement::operator=(
85 	const UserUsageConditionsAgreement& other)
86 {
87 	fCode = other.fCode;
88 	fTimestampAgreed = other.fTimestampAgreed;
89 	fIsLatest = other.fIsLatest;
90 	return *this;
91 }
92 
93 
94 status_t
95 UserUsageConditionsAgreement::Archive(BMessage* into, bool deep) const
96 {
97 	status_t result = B_OK;
98 	if (result == B_OK)
99 		result = into->AddUInt64(KEY_TIMESTAMP_AGREED, fTimestampAgreed);
100 	if (result == B_OK)
101 		result = into->AddString(KEY_CODE, fCode);
102 	if (result == B_OK)
103 		result = into->AddBool(KEY_IS_LATEST, fIsLatest);
104 	return result;
105 }
106 
107 
108 UserDetail::UserDetail(BMessage* from)
109 {
110 	BMessage agreementMessage;
111 	if (from->FindMessage(KEY_AGREEMENT,
112 			&agreementMessage) == B_OK) {
113 		fAgreement = UserUsageConditionsAgreement(&agreementMessage);
114 	}
115 	from->FindString(KEY_NICKNAME, &fNickname);
116 }
117 
118 
119 UserDetail::UserDetail()
120 	:
121 	fNickname(),
122 	fAgreement()
123 {
124 }
125 
126 
127 UserDetail::~UserDetail()
128 {
129 }
130 
131 
132 const BString&
133 UserDetail::Nickname() const
134 {
135 	return fNickname;
136 }
137 
138 
139 const UserUsageConditionsAgreement&
140 UserDetail::Agreement() const
141 {
142 	return fAgreement;
143 }
144 
145 
146 void
147 UserDetail::SetNickname(const BString& value)
148 {
149 	fNickname = value;
150 }
151 
152 
153 void
154 UserDetail::SetAgreement(
155 	const UserUsageConditionsAgreement& value)
156 {
157 	fAgreement = value;
158 }
159 
160 
161 UserDetail&
162 UserDetail::operator=(const UserDetail& other)
163 {
164 	fNickname = other.fNickname;
165 	fAgreement = other.fAgreement;
166 	return *this;
167 }
168 
169 
170 status_t
171 UserDetail::Archive(BMessage* into, bool deep) const
172 {
173 	status_t result = B_OK;
174 	if (result == B_OK) {
175 		BMessage agreementMessage;
176 		result = fAgreement.Archive(&agreementMessage, true);
177 		if (result == B_OK)
178 			result = into->AddMessage(KEY_AGREEMENT, &agreementMessage);
179 	}
180 	if (result == B_OK)
181 		result = into->AddString(KEY_NICKNAME, fNickname);
182 	return result;
183 }
184