File indexing completed on 2024-11-24 04:16:55

0001 /*
0002   SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #include "translator.h"
0007 
0008 Translator::Translator() = default;
0009 
0010 Translator::~Translator() = default;
0011 
0012 void Translator::parse(const QJsonObject &obj, bool remote)
0013 {
0014     mUrl = obj[QLatin1String("url")].toString();
0015     mModelName = obj[QLatin1String("modelName")].toString();
0016     mShortName = obj[QLatin1String("shortName")].toString();
0017     mCheckSum = obj[QLatin1String("checksum")].toString();
0018     mRepository = obj[QLatin1String("repository")].toString();
0019     mType = obj[QLatin1String("type")].toString();
0020     mSource = obj[QLatin1String("src")].toString();
0021     mTarget = obj[QLatin1String("trg")].toString();
0022     mVersion = obj[QLatin1String("version")].toInt(-1);
0023     mApi = obj[QLatin1String("API")].toInt(-1);
0024     mRemote = remote;
0025 }
0026 
0027 QString Translator::shortName() const
0028 {
0029     return mShortName;
0030 }
0031 
0032 bool Translator::operator==(const Translator &other) const
0033 {
0034     return mShortName == other.mShortName && mModelName == other.mModelName && mSource == other.mSource && mTarget == other.mTarget
0035         && mCheckSum == other.mCheckSum && mRepository == other.mRepository && mUrl == other.mUrl && mType == other.mType && mVersion == other.mVersion
0036         && mApi == other.mApi && mRemote == other.mRemote;
0037 }
0038 
0039 bool Translator::remote() const
0040 {
0041     return mRemote;
0042 }
0043 
0044 void Translator::setRemote(bool newRemote)
0045 {
0046     mRemote = newRemote;
0047 }
0048 
0049 void Translator::setShortName(const QString &newShortName)
0050 {
0051     mShortName = newShortName;
0052 }
0053 
0054 QString Translator::modelName() const
0055 {
0056     return mModelName;
0057 }
0058 
0059 void Translator::setModelName(const QString &newModelName)
0060 {
0061     mModelName = newModelName;
0062 }
0063 
0064 QString Translator::source() const
0065 {
0066     return mSource;
0067 }
0068 
0069 void Translator::setSource(const QString &newSource)
0070 {
0071     mSource = newSource;
0072 }
0073 
0074 QString Translator::checkSum() const
0075 {
0076     return mCheckSum;
0077 }
0078 
0079 void Translator::setCheckSum(const QString &newCheckSum)
0080 {
0081     mCheckSum = newCheckSum;
0082 }
0083 
0084 QString Translator::target() const
0085 {
0086     return mTarget;
0087 }
0088 
0089 void Translator::setTarget(const QString &newTarget)
0090 {
0091     mTarget = newTarget;
0092 }
0093 
0094 int Translator::version() const
0095 {
0096     return mVersion;
0097 }
0098 
0099 void Translator::setVersion(int newVersion)
0100 {
0101     mVersion = newVersion;
0102 }
0103 
0104 int Translator::api() const
0105 {
0106     return mApi;
0107 }
0108 
0109 void Translator::setApi(int newApi)
0110 {
0111     mApi = newApi;
0112 }
0113 
0114 QString Translator::url() const
0115 {
0116     return mUrl;
0117 }
0118 
0119 void Translator::setUrl(const QString &newUrl)
0120 {
0121     mUrl = newUrl;
0122 }
0123 
0124 QString Translator::repository() const
0125 {
0126     return mRepository;
0127 }
0128 
0129 void Translator::setRepository(const QString &newRepository)
0130 {
0131     mRepository = newRepository;
0132 }
0133 
0134 QString Translator::type() const
0135 {
0136     return mType;
0137 }
0138 
0139 void Translator::setType(const QString &newType)
0140 {
0141     mType = newType;
0142 }
0143 
0144 bool Translator::isValid() const
0145 {
0146     if (mRemote) {
0147         return !mUrl.isEmpty() && !mTarget.isEmpty() && !mSource.isEmpty();
0148     } else {
0149         return !mTarget.isEmpty() && !mSource.isEmpty();
0150     }
0151 }
0152 
0153 QDebug operator<<(QDebug d, const Translator &t)
0154 {
0155     d << "mShortName " << t.shortName();
0156     d << "mModelName " << t.modelName();
0157     d << "mSource " << t.source();
0158     d << "mTarget " << t.target();
0159     d << "mCheckSum " << t.checkSum();
0160     d << "mRepository " << t.repository();
0161     d << "mUrl " << t.url();
0162     d << "mType " << t.type();
0163     d << "mVersion " << t.version();
0164     d << "mApi " << t.api();
0165     d << "mRemote " << t.remote();
0166     return d;
0167 }