File indexing completed on 2024-07-21 12:42:26

0001 /*
0002    SPDX-FileCopyrightText: 2021-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "retentioninfo.h"
0008 #include <QJsonObject>
0009 
0010 RetentionInfo::RetentionInfo() = default;
0011 
0012 bool RetentionInfo::isNotDefault() const
0013 {
0014     return mEnabled || mExcludePinned || mFilesOnly || mOverrideGlobal || (mMaxAge != -1);
0015 }
0016 
0017 void RetentionInfo::parseRetentionInfo(const QJsonObject &replyObject)
0018 {
0019     mEnabled = replyObject.value(QLatin1String("enabled")).toBool(false);
0020     mExcludePinned = replyObject.value(QLatin1String("excludePinned")).toBool(false);
0021     mFilesOnly = replyObject.value(QLatin1String("filesOnly")).toBool(false);
0022     mOverrideGlobal = replyObject.value(QLatin1String("overrideGlobal")).toBool(false);
0023     mMaxAge = replyObject.value(QLatin1String("maxAge")).toInt(-1);
0024 }
0025 
0026 bool RetentionInfo::enabled() const
0027 {
0028     return mEnabled;
0029 }
0030 
0031 void RetentionInfo::setEnabled(bool enabled)
0032 {
0033     mEnabled = enabled;
0034 }
0035 
0036 bool RetentionInfo::overrideGlobal() const
0037 {
0038     return mOverrideGlobal;
0039 }
0040 
0041 void RetentionInfo::setOverrideGlobal(bool overrideGlobal)
0042 {
0043     mOverrideGlobal = overrideGlobal;
0044 }
0045 
0046 bool RetentionInfo::excludePinned() const
0047 {
0048     return mExcludePinned;
0049 }
0050 
0051 void RetentionInfo::setExcludePinned(bool excludePinned)
0052 {
0053     mExcludePinned = excludePinned;
0054 }
0055 
0056 bool RetentionInfo::filesOnly() const
0057 {
0058     return mFilesOnly;
0059 }
0060 
0061 void RetentionInfo::setFilesOnly(bool filesOnly)
0062 {
0063     mFilesOnly = filesOnly;
0064 }
0065 
0066 int RetentionInfo::maxAge() const
0067 {
0068     return mMaxAge;
0069 }
0070 
0071 void RetentionInfo::setMaxAge(int maxAge)
0072 {
0073     mMaxAge = maxAge;
0074 }
0075 
0076 bool RetentionInfo::operator==(RetentionInfo other) const
0077 {
0078     return mMaxAge == other.maxAge() && mEnabled == other.enabled() && mOverrideGlobal == other.overrideGlobal() && mExcludePinned == other.excludePinned()
0079         && mFilesOnly == other.filesOnly();
0080 }
0081 
0082 bool RetentionInfo::operator!=(RetentionInfo other) const
0083 {
0084     return !RetentionInfo::operator==(other);
0085 }
0086 
0087 QJsonObject RetentionInfo::serialize(RetentionInfo retention)
0088 {
0089     QJsonObject obj;
0090     obj[QLatin1String("enabled")] = retention.enabled();
0091     obj[QLatin1String("overrideGlobal")] = retention.overrideGlobal();
0092     obj[QLatin1String("excludePinned")] = retention.excludePinned();
0093     obj[QLatin1String("filesOnly")] = retention.filesOnly();
0094     obj[QLatin1String("maxAge")] = retention.maxAge();
0095     return obj;
0096 }
0097 
0098 RetentionInfo RetentionInfo::deserialize(const QJsonObject &obj)
0099 {
0100     RetentionInfo info;
0101     info.setEnabled(obj[QLatin1String("enabled")].toBool());
0102     info.setOverrideGlobal(obj[QLatin1String("overrideGlobal")].toBool());
0103     info.setExcludePinned(obj[QLatin1String("excludePinned")].toBool());
0104     info.setFilesOnly(obj[QLatin1String("filesOnly")].toBool());
0105     info.setMaxAge(obj[QLatin1String("maxAge")].toInt(-1));
0106 
0107     return info;
0108 }
0109 
0110 QDebug operator<<(QDebug d, RetentionInfo t)
0111 {
0112     d << "Enabled " << t.enabled();
0113     d << "overrideGlobal " << t.overrideGlobal();
0114     d << "excludePinned " << t.excludePinned();
0115     d << "filesOnly " << t.filesOnly();
0116     d << "maxAge " << t.maxAge();
0117     return d;
0118 }