1 /*
2 * Copyright 2019-2020, Andrew Lindesay <apl@lindesay.co.nz>.
3 *
4 * All rights reserved. Distributed under the terms of the MIT License.
5 */
6 #include "UserUsageConditions.h"
7
8 #include "Logger.h"
9
10 // These are keys that are used to store this object's data into a BMessage
11 // instance.
12
13 #define KEY_COPY_MARKDOWN "copyMarkdown"
14 #define KEY_CODE "code"
15 #define KEY_MINIMUM_AGE "minimumAge"
16
17
UserUsageConditions(BMessage * from)18 UserUsageConditions::UserUsageConditions(BMessage* from)
19 :
20 fCode(""),
21 fCopyMarkdown(""),
22 fMinimumAge(0)
23 {
24 int16 minimumAge;
25
26 if (from->FindInt16(KEY_MINIMUM_AGE, &minimumAge) != B_OK)
27 HDERROR("expected key [%s] in the message data", KEY_MINIMUM_AGE);
28 fMinimumAge = (uint8) minimumAge;
29
30 if (from->FindString(KEY_CODE, &fCode) != B_OK)
31 HDERROR("expected key [%s] in the message data", KEY_CODE);
32 if (from->FindString(KEY_COPY_MARKDOWN, &fCopyMarkdown) != B_OK)
33 HDERROR("expected key [%s] in the message data", KEY_COPY_MARKDOWN);
34 }
35
36
UserUsageConditions()37 UserUsageConditions::UserUsageConditions()
38 :
39 fCode(""),
40 fCopyMarkdown(""),
41 fMinimumAge(0)
42 {
43 }
44
45
~UserUsageConditions()46 UserUsageConditions::~UserUsageConditions()
47 {
48 }
49
50
51 const BString&
Code() const52 UserUsageConditions::Code() const
53 {
54 return fCode;
55 }
56
57
58 const uint8
MinimumAge() const59 UserUsageConditions::MinimumAge() const
60 {
61 return fMinimumAge;
62 }
63
64
65 const BString&
CopyMarkdown() const66 UserUsageConditions::CopyMarkdown() const
67 {
68 return fCopyMarkdown;
69 }
70
71
72 void
SetCode(const BString & code)73 UserUsageConditions::SetCode(const BString& code)
74 {
75 fCode = code;
76 }
77
78
79 void
SetMinimumAge(uint8 age)80 UserUsageConditions::SetMinimumAge(uint8 age)
81 {
82 fMinimumAge = age;
83 }
84
85
86 void
SetCopyMarkdown(const BString & copyMarkdown)87 UserUsageConditions::SetCopyMarkdown(const BString& copyMarkdown)
88 {
89 fCopyMarkdown = copyMarkdown;
90 }
91
92
93 status_t
Archive(BMessage * into,bool deep) const94 UserUsageConditions::Archive(BMessage* into, bool deep) const
95 {
96 into->AddInt16(KEY_MINIMUM_AGE, (int16) fMinimumAge);
97 into->AddString(KEY_CODE, fCode);
98 into->AddString(KEY_COPY_MARKDOWN, fCopyMarkdown);
99 return B_OK;
100 }