101339a54SAndrew Lindesay/*
201339a54SAndrew Lindesay * Copyright 2019, Andrew Lindesay <apl@lindesay.co.nz>.
301339a54SAndrew Lindesay *
401339a54SAndrew Lindesay * All rights reserved. Distributed under the terms of the MIT License.
501339a54SAndrew Lindesay */
601339a54SAndrew Lindesay#include "UserUsageConditions.h"
701339a54SAndrew Lindesay
8d2d4866dSAndrew Lindesay#include <stdio.h>
901339a54SAndrew Lindesay
1001339a54SAndrew Lindesay// These are keys that are used to store this object's data into a BMessage
1101339a54SAndrew Lindesay// instance.
1201339a54SAndrew Lindesay
1301339a54SAndrew Lindesay#define KEY_COPY_MARKDOWN	"copyMarkdown"
1401339a54SAndrew Lindesay#define KEY_CODE			"code"
1501339a54SAndrew Lindesay#define KEY_MINIMUM_AGE		"minimumAge"
1601339a54SAndrew Lindesay
1701339a54SAndrew Lindesay
1801339a54SAndrew LindesayUserUsageConditions::UserUsageConditions(BMessage* from)
1901339a54SAndrew Lindesay	:
2001339a54SAndrew Lindesay	fCode(""),
2101339a54SAndrew Lindesay	fCopyMarkdown(""),
2201339a54SAndrew Lindesay	fMinimumAge(0)
2301339a54SAndrew Lindesay{
2401339a54SAndrew Lindesay	int16 minimumAge;
2501339a54SAndrew Lindesay
2601339a54SAndrew Lindesay	if (from->FindInt16(KEY_MINIMUM_AGE, &minimumAge) != B_OK)
2701339a54SAndrew Lindesay		printf("expected key [%s] in the message data\n", KEY_MINIMUM_AGE);
2801339a54SAndrew Lindesay	fMinimumAge = (uint8) minimumAge;
2901339a54SAndrew Lindesay
3001339a54SAndrew Lindesay	if (from->FindString(KEY_CODE, &fCode) != B_OK)
3101339a54SAndrew Lindesay		printf("expected key [%s] in the message data\n", KEY_CODE);
3201339a54SAndrew Lindesay
3301339a54SAndrew Lindesay	if (from->FindString(KEY_COPY_MARKDOWN, &fCopyMarkdown) != B_OK)
3401339a54SAndrew Lindesay		printf("expected key [%s] in the message data\n", KEY_COPY_MARKDOWN);
3501339a54SAndrew Lindesay}
3601339a54SAndrew Lindesay
3701339a54SAndrew Lindesay
3801339a54SAndrew LindesayUserUsageConditions::UserUsageConditions()
3901339a54SAndrew Lindesay	:
4001339a54SAndrew Lindesay	fCode(""),
4101339a54SAndrew Lindesay	fCopyMarkdown(""),
4201339a54SAndrew Lindesay	fMinimumAge(0)
4301339a54SAndrew Lindesay{
4401339a54SAndrew Lindesay}
4501339a54SAndrew Lindesay
4601339a54SAndrew Lindesay
4701339a54SAndrew LindesayUserUsageConditions::~UserUsageConditions()
4801339a54SAndrew Lindesay{
4901339a54SAndrew Lindesay}
5001339a54SAndrew Lindesay
5101339a54SAndrew Lindesay
5201339a54SAndrew Lindesayconst BString&
5301339a54SAndrew LindesayUserUsageConditions::Code() const
5401339a54SAndrew Lindesay{
5501339a54SAndrew Lindesay	return fCode;
5601339a54SAndrew Lindesay}
5701339a54SAndrew Lindesay
5801339a54SAndrew Lindesay
5901339a54SAndrew Lindesayconst uint8
6001339a54SAndrew LindesayUserUsageConditions::MinimumAge() const
6101339a54SAndrew Lindesay{
6201339a54SAndrew Lindesay	return fMinimumAge;
6301339a54SAndrew Lindesay}
6401339a54SAndrew Lindesay
6501339a54SAndrew Lindesay
6601339a54SAndrew Lindesayconst BString&
6701339a54SAndrew LindesayUserUsageConditions::CopyMarkdown() const
6801339a54SAndrew Lindesay{
6901339a54SAndrew Lindesay	return fCopyMarkdown;
7001339a54SAndrew Lindesay}
7101339a54SAndrew Lindesay
7201339a54SAndrew Lindesay
7301339a54SAndrew Lindesayvoid
7401339a54SAndrew LindesayUserUsageConditions::SetCode(const BString& code)
7501339a54SAndrew Lindesay{
7601339a54SAndrew Lindesay	fCode = code;
7701339a54SAndrew Lindesay}
7801339a54SAndrew Lindesay
7901339a54SAndrew Lindesay
8001339a54SAndrew Lindesayvoid
8101339a54SAndrew LindesayUserUsageConditions::SetMinimumAge(uint8 age)
8201339a54SAndrew Lindesay{
8301339a54SAndrew Lindesay	fMinimumAge = age;
8401339a54SAndrew Lindesay}
8501339a54SAndrew Lindesay
8601339a54SAndrew Lindesay
8701339a54SAndrew Lindesayvoid
8801339a54SAndrew LindesayUserUsageConditions::SetCopyMarkdown(const BString& copyMarkdown)
8901339a54SAndrew Lindesay{
9001339a54SAndrew Lindesay	fCopyMarkdown = copyMarkdown;
9101339a54SAndrew Lindesay}
9201339a54SAndrew Lindesay
9301339a54SAndrew Lindesay
9401339a54SAndrew Lindesaystatus_t
9501339a54SAndrew LindesayUserUsageConditions::Archive(BMessage* into, bool deep) const
9601339a54SAndrew Lindesay{
9701339a54SAndrew Lindesay	into->AddInt16(KEY_MINIMUM_AGE, (int16) fMinimumAge);
9801339a54SAndrew Lindesay	into->AddString(KEY_CODE, fCode);
9901339a54SAndrew Lindesay	into->AddString(KEY_COPY_MARKDOWN, fCopyMarkdown);
10001339a54SAndrew Lindesay	return B_OK;
10101339a54SAndrew Lindesay}