File indexing completed on 2024-12-08 04:33:08
0001 /* 0002 SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "bannerinfo.h" 0008 0009 #include <KLocalizedString> 0010 #include <QJsonArray> 0011 #include <QJsonObject> 0012 0013 BannerInfo::BannerInfo() = default; 0014 0015 BannerInfo::~BannerInfo() = default; 0016 0017 bool BannerInfo::isValid() const 0018 { 0019 return !mText.isEmpty() && !mIdentifier.isEmpty() && !mTitle.isEmpty(); 0020 } 0021 0022 void BannerInfo::parseBannerInfo(const QJsonObject &object) 0023 { 0024 QStringList lst; 0025 const QJsonArray array = object[QLatin1String("textArguments")].toArray(); 0026 lst.reserve(array.count()); 0027 for (const QJsonValue ¤t : array) { 0028 lst.append(current.toString()); 0029 } 0030 mTextArguments = lst; 0031 mText = object[QLatin1String("text")].toString(); 0032 mTitle = object[QLatin1String("title")].toString(); 0033 mLink = object[QLatin1String("link")].toString(); 0034 mIdentifier = object[QLatin1String("id")].toString(); 0035 mPriority = object[QLatin1String("priority")].toInt(-1); 0036 mRead = object[QLatin1String("read")].toBool(false); 0037 // if (mPriority != -1) { 0038 // qWarning() << " priority != -1 " << object; 0039 // } 0040 } 0041 0042 QString BannerInfo::defaultText(const BannerInfo &info) 0043 { 0044 QString str{info.text()}; 0045 if (str == QLatin1String("New_version_available_(s)")) { 0046 str = i18n("New version available %1", info.textArguments().at(0)); 0047 } 0048 return str; 0049 } 0050 0051 bool BannerInfo::operator==(const BannerInfo &other) const 0052 { 0053 return mText == other.text() && mTitle == other.title() && mLink == other.link() && mRead == other.read() && mRead == other.read() 0054 && mTextArguments == other.textArguments() && mIdentifier == other.identifier() && mPriority == other.priority(); 0055 } 0056 0057 const QString &BannerInfo::text() const 0058 { 0059 return mText; 0060 } 0061 0062 void BannerInfo::setText(const QString &newText) 0063 { 0064 mText = newText; 0065 } 0066 0067 const QString &BannerInfo::title() const 0068 { 0069 return mTitle; 0070 } 0071 0072 void BannerInfo::setTitle(const QString &newTitle) 0073 { 0074 mTitle = newTitle; 0075 } 0076 0077 const QString &BannerInfo::link() const 0078 { 0079 return mLink; 0080 } 0081 0082 void BannerInfo::setLink(const QString &newLink) 0083 { 0084 mLink = newLink; 0085 } 0086 0087 bool BannerInfo::read() const 0088 { 0089 return mRead; 0090 } 0091 0092 void BannerInfo::setRead(bool newRead) 0093 { 0094 mRead = newRead; 0095 } 0096 0097 const QStringList &BannerInfo::textArguments() const 0098 { 0099 return mTextArguments; 0100 } 0101 0102 void BannerInfo::setTextArguments(const QStringList &newTextArguments) 0103 { 0104 mTextArguments = newTextArguments; 0105 } 0106 0107 const QString &BannerInfo::identifier() const 0108 { 0109 return mIdentifier; 0110 } 0111 0112 void BannerInfo::setIdentifier(const QString &newIdentifier) 0113 { 0114 mIdentifier = newIdentifier; 0115 } 0116 0117 int BannerInfo::priority() const 0118 { 0119 return mPriority; 0120 } 0121 0122 void BannerInfo::setPriority(int newPriority) 0123 { 0124 mPriority = newPriority; 0125 } 0126 0127 QDebug operator<<(QDebug d, const BannerInfo &t) 0128 { 0129 d.space() << "mText" << t.text(); 0130 d.space() << "mTitle" << t.title(); 0131 d.space() << "mLink" << t.link(); 0132 d.space() << "mRead" << t.read(); 0133 d.space() << "mTextArguments" << t.textArguments(); 0134 d.space() << "mIdentifier" << t.identifier(); 0135 d.space() << "mPriority" << t.priority(); 0136 return d; 0137 }