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 18UserUsageConditions::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 37UserUsageConditions::UserUsageConditions() 38 : 39 fCode(""), 40 fCopyMarkdown(""), 41 fMinimumAge(0) 42{ 43} 44 45 46UserUsageConditions::~UserUsageConditions() 47{ 48} 49 50 51const BString& 52UserUsageConditions::Code() const 53{ 54 return fCode; 55} 56 57 58const uint8 59UserUsageConditions::MinimumAge() const 60{ 61 return fMinimumAge; 62} 63 64 65const BString& 66UserUsageConditions::CopyMarkdown() const 67{ 68 return fCopyMarkdown; 69} 70 71 72void 73UserUsageConditions::SetCode(const BString& code) 74{ 75 fCode = code; 76} 77 78 79void 80UserUsageConditions::SetMinimumAge(uint8 age) 81{ 82 fMinimumAge = age; 83} 84 85 86void 87UserUsageConditions::SetCopyMarkdown(const BString& copyMarkdown) 88{ 89 fCopyMarkdown = copyMarkdown; 90} 91 92 93status_t 94UserUsageConditions::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}