1/*
2 This file is part of KDE.
3
4 SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#include "achievement.h"
10
11using namespace Attica;
12
13Achievement::Type Achievement::stringToAchievementType(const QString &achievementTypeString)
14{
15 if (achievementTypeString == QLatin1String("flowing")) {
16 return Achievement::FlowingAchievement;
17 } else if (achievementTypeString == QLatin1String("stepped")) {
18 return Achievement::SteppedAchievement;
19 } else if (achievementTypeString == QLatin1String("namedsteps")) {
20 return Achievement::NamedstepsAchievement;
21 } else if (achievementTypeString == QLatin1String("set")) {
22 return Achievement::SetAchievement;
23 }
24
25 Q_ASSERT(false);
26 return Achievement::FlowingAchievement;
27}
28
29QString Achievement::achievementTypeToString(const Achievement::Type type)
30{
31 switch (type) {
32 case Achievement::FlowingAchievement:
33 return QStringLiteral("flowing");
34 case Achievement::SteppedAchievement:
35 return QStringLiteral("stepped");
36 case Achievement::NamedstepsAchievement:
37 return QStringLiteral("namedsteps");
38 case Achievement::SetAchievement:
39 return QStringLiteral("set");
40 }
41
42 Q_ASSERT(false);
43 return QString();
44}
45
46Achievement::Visibility Achievement::stringToAchievementVisibility(const QString &achievementVisibilityString)
47{
48 if (achievementVisibilityString == QLatin1String("visible")) {
49 return Achievement::VisibleAchievement;
50 } else if (achievementVisibilityString == QLatin1String("dependents")) {
51 return Achievement::DependentsAchievement;
52 } else if (achievementVisibilityString == QLatin1String("secret")) {
53 return Achievement::SecretAchievement;
54 }
55
56 Q_ASSERT(false);
57 return Achievement::VisibleAchievement;
58}
59
60QString Achievement::achievementVisibilityToString(const Achievement::Visibility visibility)
61{
62 switch (visibility) {
63 case Achievement::VisibleAchievement:
64 return QStringLiteral("visible");
65 case Achievement::DependentsAchievement:
66 return QStringLiteral("dependents");
67 case Achievement::SecretAchievement:
68 return QStringLiteral("secret");
69 }
70
71 Q_ASSERT(false);
72 return QString();
73}
74
75class Q_DECL_HIDDEN Achievement::Private : public QSharedData
76{
77public:
78 QString m_id;
79 QString m_contentId;
80 QString m_name;
81 QString m_description;
82 QString m_explanation;
83 int m_points;
84 QUrl m_image;
85 QStringList m_dependencies;
86 Achievement::Visibility m_visibility;
87 Achievement::Type m_type;
88 QStringList m_options;
89 int m_steps;
90 QVariant m_progress;
91
92 Private()
93 : m_points(0)
94 , m_steps(0)
95 {
96 }
97};
98
99Achievement::Achievement()
100 : d(new Private)
101{
102}
103
104Achievement::Achievement(const Achievement &other)
105 : d(other.d)
106{
107}
108
109Achievement &Achievement::operator=(const Attica::Achievement &other)
110{
111 d = other.d;
112 return *this;
113}
114
115Achievement::~Achievement()
116{
117}
118
119void Achievement::setId(const QString &id)
120{
121 d->m_id = id;
122}
123
124QString Achievement::id() const
125{
126 return d->m_id;
127}
128
129void Achievement::setContentId(const QString &contentId)
130{
131 d->m_contentId = contentId;
132}
133
134QString Achievement::contentId() const
135{
136 return d->m_contentId;
137}
138
139void Achievement::setName(const QString &name)
140{
141 d->m_name = name;
142}
143
144QString Achievement::name() const
145{
146 return d->m_name;
147}
148
149void Achievement::setDescription(const QString &description)
150{
151 d->m_description = description;
152}
153
154QString Achievement::description() const
155{
156 return d->m_description;
157}
158
159void Achievement::setExplanation(const QString &explanation)
160{
161 d->m_explanation = explanation;
162}
163
164QString Achievement::explanation() const
165{
166 return d->m_explanation;
167}
168
169void Achievement::setPoints(const int points)
170{
171 d->m_points = points;
172}
173
174int Achievement::points() const
175{
176 return d->m_points;
177}
178
179void Achievement::setImage(const QUrl &image)
180{
181 d->m_image = image;
182}
183
184QUrl Achievement::image() const
185{
186 return d->m_image;
187}
188
189void Achievement::setDependencies(const QStringList &dependencies)
190{
191 d->m_dependencies = dependencies;
192}
193
194void Achievement::addDependency(const QString &dependency)
195{
196 d->m_dependencies.append(t: dependency);
197}
198
199void Achievement::removeDependency(const QString &dependency)
200{
201 d->m_dependencies.removeOne(t: dependency);
202}
203
204QStringList Achievement::dependencies() const
205{
206 return d->m_dependencies;
207}
208
209void Achievement::setVisibility(Achievement::Visibility visibility)
210{
211 d->m_visibility = visibility;
212}
213
214Achievement::Visibility Achievement::visibility() const
215{
216 return d->m_visibility;
217}
218
219void Achievement::setType(Achievement::Type type)
220{
221 d->m_type = type;
222}
223
224Achievement::Type Achievement::type() const
225{
226 return d->m_type;
227}
228
229void Achievement::setOptions(const QStringList &options)
230{
231 d->m_options = options;
232}
233
234void Achievement::addOption(const QString &option)
235{
236 d->m_options.append(t: option);
237}
238
239void Achievement::removeOption(const QString &option)
240{
241 d->m_options.removeOne(t: option);
242}
243
244QStringList Achievement::options() const
245{
246 return d->m_options;
247}
248
249void Achievement::setSteps(const int steps)
250{
251 d->m_steps = steps;
252}
253
254int Achievement::steps() const
255{
256 return d->m_steps;
257}
258
259void Achievement::setProgress(const QVariant &progress)
260{
261 d->m_progress = progress;
262}
263
264QVariant Achievement::progress() const
265{
266 return d->m_progress;
267}
268
269bool Achievement::isValid() const
270{
271 return !(d->m_id.isEmpty());
272}
273

source code of attica/src/achievement.cpp