File indexing completed on 2024-05-12 16:25:21
0001 /* 0002 SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "file.h" 0008 #include "utils.h" 0009 #include <QDateTime> 0010 #include <QJsonObject> 0011 0012 File::File() = default; 0013 0014 void File::parseFile(const QJsonObject &object, bool restApi) 0015 { 0016 const QJsonObject fields = restApi ? object : object.value(QLatin1String("fields")).toObject(); 0017 setUserId(fields.value(QLatin1String("userId")).toString()); 0018 0019 setDescription(fields.value(QLatin1String("description")).toString()); 0020 setFileName(fields.value(QLatin1String("name")).toString()); 0021 setMimeType(fields.value(QLatin1String("type")).toString()); 0022 setUrl(fields.value(QLatin1String("url")).toString()); 0023 setRid(fields.value(QLatin1String("rid")).toString()); 0024 setComplete(fields.value(QLatin1String("complete")).toBool()); 0025 setTypeGroup(fields.value(QLatin1String("typeGroup")).toString()); 0026 if (restApi) { 0027 setUploadedAt(Utils::parseIsoDate(QStringLiteral("uploadedAt"), fields)); 0028 } else { 0029 setUploadedAt(Utils::parseDate(QStringLiteral("uploadedAt"), fields)); 0030 } 0031 0032 const QJsonObject user = object.value(QLatin1String("user")).toObject(); 0033 setUserName(user.value(QLatin1String("username")).toString()); 0034 0035 setFileId(restApi ? object.value(QLatin1String("_id")).toString() : object.value(QLatin1String("id")).toString()); 0036 } 0037 0038 QString File::fileName() const 0039 { 0040 return mFileName; 0041 } 0042 0043 void File::setFileName(const QString &name) 0044 { 0045 mFileName = name; 0046 } 0047 0048 QString File::description() const 0049 { 0050 return mDescription; 0051 } 0052 0053 void File::setDescription(const QString &description) 0054 { 0055 mDescription = description; 0056 } 0057 0058 bool File::operator==(const File &other) const 0059 { 0060 return (description() == other.description()) && (fileName() == other.fileName()) && (url() == other.url()) && (userId() == other.userId()) 0061 && (mimeType() == other.mimeType()) && (uploadedAt() == other.uploadedAt()) && (fileId() == other.fileId()) && (rid() == other.rid()) 0062 && (userName() == other.userName()) && (complete() == other.complete()) && (typeGroup() == other.typeGroup()); 0063 } 0064 0065 QString File::userId() const 0066 { 0067 return mUserId; 0068 } 0069 0070 void File::setUserId(const QString &userId) 0071 { 0072 mUserId = userId; 0073 } 0074 0075 QString File::url() const 0076 { 0077 return mUrl; 0078 } 0079 0080 void File::setUrl(const QString &url) 0081 { 0082 mUrl = url; 0083 } 0084 0085 QString File::mimeType() const 0086 { 0087 return mMimeType; 0088 } 0089 0090 void File::setMimeType(const QString &mimeType) 0091 { 0092 mMimeType = mimeType; 0093 } 0094 0095 qint64 File::uploadedAt() const 0096 { 0097 return mUploadedAt; 0098 } 0099 0100 void File::setUploadedAt(qint64 uploadedAt) 0101 { 0102 mUploadedAt = uploadedAt; 0103 QLocale l; 0104 mUploadedDateTimeStr = l.toString(QDateTime::fromMSecsSinceEpoch(mUploadedAt), QLocale::LongFormat); 0105 } 0106 0107 QString File::fileId() const 0108 { 0109 return mFileId; 0110 } 0111 0112 void File::setFileId(const QString &fileId) 0113 { 0114 mFileId = fileId; 0115 } 0116 0117 QString File::rid() const 0118 { 0119 return mRid; 0120 } 0121 0122 void File::setRid(const QString &rid) 0123 { 0124 mRid = rid; 0125 } 0126 0127 QString File::userName() const 0128 { 0129 return mUserName; 0130 } 0131 0132 void File::setUserName(const QString &userName) 0133 { 0134 mUserName = userName; 0135 } 0136 0137 QString File::uploadedDateTimeStr() const 0138 { 0139 return mUploadedDateTimeStr; 0140 } 0141 0142 bool File::complete() const 0143 { 0144 return mComplete; 0145 } 0146 0147 void File::setComplete(bool complete) 0148 { 0149 mComplete = complete; 0150 } 0151 0152 QString File::typeGroup() const 0153 { 0154 return mTypeGroup; 0155 } 0156 0157 void File::setTypeGroup(const QString &typeGroup) 0158 { 0159 mTypeGroup = typeGroup; 0160 } 0161 0162 QDebug operator<<(QDebug d, const File &t) 0163 { 0164 d.space() << "Name:" << t.fileName(); 0165 d.space() << "Description:" << t.description(); 0166 d.space() << "Url:" << t.url(); 0167 d.space() << "UserId:" << t.userId(); 0168 d.space() << "Mimetype:" << t.mimeType(); 0169 d.space() << "Uploaded time:" << t.uploadedAt(); 0170 d.space() << "File Id:" << t.fileId(); 0171 d.space() << "Rid:" << t.rid(); 0172 d.space() << "Username:" << t.userName(); 0173 d.space() << "Complete:" << t.complete(); 0174 d.space() << "TypeGroup:" << t.typeGroup(); 0175 return d; 0176 } 0177 0178 #include "moc_file.cpp"