File indexing completed on 2024-12-08 12:15:06

0001 /*
0002     This file is part of KDE.
0003 
0004     SPDX-FileCopyrightText: 2011 Laszlo Papp <djszapi@archlinux.us>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "achievement.h"
0010 
0011 using namespace Attica;
0012 
0013 Achievement::Type Achievement::stringToAchievementType(const QString &achievementTypeString)
0014 {
0015     if (achievementTypeString == QLatin1String("flowing")) {
0016         return Achievement::FlowingAchievement;
0017     } else if (achievementTypeString == QLatin1String("stepped")) {
0018         return Achievement::SteppedAchievement;
0019     } else if (achievementTypeString == QLatin1String("namedsteps")) {
0020         return Achievement::NamedstepsAchievement;
0021     } else if (achievementTypeString == QLatin1String("set")) {
0022         return Achievement::SetAchievement;
0023     }
0024 
0025     Q_ASSERT(false);
0026     return Achievement::FlowingAchievement;
0027 }
0028 
0029 QString Achievement::achievementTypeToString(const Achievement::Type type)
0030 {
0031     switch (type) {
0032     case Achievement::FlowingAchievement:
0033         return QStringLiteral("flowing");
0034     case Achievement::SteppedAchievement:
0035         return QStringLiteral("stepped");
0036     case Achievement::NamedstepsAchievement:
0037         return QStringLiteral("namedsteps");
0038     case Achievement::SetAchievement:
0039         return QStringLiteral("set");
0040     }
0041 
0042     Q_ASSERT(false);
0043     return QString();
0044 }
0045 
0046 Achievement::Visibility Achievement::stringToAchievementVisibility(const QString &achievementVisibilityString)
0047 {
0048     if (achievementVisibilityString == QLatin1String("visible")) {
0049         return Achievement::VisibleAchievement;
0050     } else if (achievementVisibilityString == QLatin1String("dependents")) {
0051         return Achievement::DependentsAchievement;
0052     } else if (achievementVisibilityString == QLatin1String("secret")) {
0053         return Achievement::SecretAchievement;
0054     }
0055 
0056     Q_ASSERT(false);
0057     return Achievement::VisibleAchievement;
0058 }
0059 
0060 QString Achievement::achievementVisibilityToString(const Achievement::Visibility visibility)
0061 {
0062     switch (visibility) {
0063     case Achievement::VisibleAchievement:
0064         return QStringLiteral("visible");
0065     case Achievement::DependentsAchievement:
0066         return QStringLiteral("dependents");
0067     case Achievement::SecretAchievement:
0068         return QStringLiteral("secret");
0069     }
0070 
0071     Q_ASSERT(false);
0072     return QString();
0073 }
0074 
0075 class Q_DECL_HIDDEN Achievement::Private : public QSharedData
0076 {
0077 public:
0078     QString m_id;
0079     QString m_contentId;
0080     QString m_name;
0081     QString m_description;
0082     QString m_explanation;
0083     int m_points;
0084     QUrl m_image;
0085     QStringList m_dependencies;
0086     Achievement::Visibility m_visibility;
0087     Achievement::Type m_type;
0088     QStringList m_options;
0089     int m_steps;
0090     QVariant m_progress;
0091 
0092     Private()
0093         : m_points(0)
0094         , m_steps(0)
0095     {
0096     }
0097 };
0098 
0099 Achievement::Achievement()
0100     : d(new Private)
0101 {
0102 }
0103 
0104 Achievement::Achievement(const Achievement &other)
0105     : d(other.d)
0106 {
0107 }
0108 
0109 Achievement &Achievement::operator=(const Attica::Achievement &other)
0110 {
0111     d = other.d;
0112     return *this;
0113 }
0114 
0115 Achievement::~Achievement()
0116 {
0117 }
0118 
0119 void Achievement::setId(const QString &id)
0120 {
0121     d->m_id = id;
0122 }
0123 
0124 QString Achievement::id() const
0125 {
0126     return d->m_id;
0127 }
0128 
0129 void Achievement::setContentId(const QString &contentId)
0130 {
0131     d->m_contentId = contentId;
0132 }
0133 
0134 QString Achievement::contentId() const
0135 {
0136     return d->m_contentId;
0137 }
0138 
0139 void Achievement::setName(const QString &name)
0140 {
0141     d->m_name = name;
0142 }
0143 
0144 QString Achievement::name() const
0145 {
0146     return d->m_name;
0147 }
0148 
0149 void Achievement::setDescription(const QString &description)
0150 {
0151     d->m_description = description;
0152 }
0153 
0154 QString Achievement::description() const
0155 {
0156     return d->m_description;
0157 }
0158 
0159 void Achievement::setExplanation(const QString &explanation)
0160 {
0161     d->m_explanation = explanation;
0162 }
0163 
0164 QString Achievement::explanation() const
0165 {
0166     return d->m_explanation;
0167 }
0168 
0169 void Achievement::setPoints(const int points)
0170 {
0171     d->m_points = points;
0172 }
0173 
0174 int Achievement::points() const
0175 {
0176     return d->m_points;
0177 }
0178 
0179 void Achievement::setImage(const QUrl &image)
0180 {
0181     d->m_image = image;
0182 }
0183 
0184 QUrl Achievement::image() const
0185 {
0186     return d->m_image;
0187 }
0188 
0189 void Achievement::setDependencies(const QStringList &dependencies)
0190 {
0191     d->m_dependencies = dependencies;
0192 }
0193 
0194 void Achievement::addDependency(const QString &dependency)
0195 {
0196     d->m_dependencies.append(dependency);
0197 }
0198 
0199 void Achievement::removeDependency(const QString &dependency)
0200 {
0201     d->m_dependencies.removeOne(dependency);
0202 }
0203 
0204 QStringList Achievement::dependencies() const
0205 {
0206     return d->m_dependencies;
0207 }
0208 
0209 void Achievement::setVisibility(Achievement::Visibility visibility)
0210 {
0211     d->m_visibility = visibility;
0212 }
0213 
0214 Achievement::Visibility Achievement::visibility() const
0215 {
0216     return d->m_visibility;
0217 }
0218 
0219 void Achievement::setType(Achievement::Type type)
0220 {
0221     d->m_type = type;
0222 }
0223 
0224 Achievement::Type Achievement::type() const
0225 {
0226     return d->m_type;
0227 }
0228 
0229 void Achievement::setOptions(const QStringList &options)
0230 {
0231     d->m_options = options;
0232 }
0233 
0234 void Achievement::addOption(const QString &option)
0235 {
0236     d->m_options.append(option);
0237 }
0238 
0239 void Achievement::removeOption(const QString &option)
0240 {
0241     d->m_options.removeOne(option);
0242 }
0243 
0244 QStringList Achievement::options() const
0245 {
0246     return d->m_options;
0247 }
0248 
0249 void Achievement::setSteps(const int steps)
0250 {
0251     d->m_steps = steps;
0252 }
0253 
0254 int Achievement::steps() const
0255 {
0256     return d->m_steps;
0257 }
0258 
0259 void Achievement::setProgress(const QVariant &progress)
0260 {
0261     d->m_progress = progress;
0262 }
0263 
0264 QVariant Achievement::progress() const
0265 {
0266     return d->m_progress;
0267 }
0268 
0269 bool Achievement::isValid() const
0270 {
0271     return !(d->m_id.isEmpty());
0272 }