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