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