File indexing completed on 2024-05-12 05:04:16

0001 // SPDX-FileCopyrightText: 2023 Shubham Arora <shubhamarora@protonmail.com>
0002 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0003 
0004 #include "tag.h"
0005 
0006 using namespace Qt::Literals::StringLiterals;
0007 
0008 Tag::Tag(QJsonObject obj)
0009 {
0010     fromJson(obj);
0011 }
0012 
0013 void Tag::fromJson(QJsonObject obj)
0014 {
0015     m_name = obj["name"_L1].toString();
0016     m_url = QUrl(obj["url"_L1].toString());
0017     m_following = obj["following"_L1].toBool();
0018     const auto historyArray = obj["history"_L1].toArray();
0019     for (const QJsonValue &historyValue : historyArray) {
0020         QJsonObject historyObj = historyValue.toObject();
0021         QString day = historyObj["day"_L1].toString();
0022         QString uses = historyObj["uses"_L1].toString();
0023         QString accounts = historyObj["accounts"_L1].toString();
0024         History history(day, uses, accounts);
0025         m_history.append(history);
0026     }
0027 }
0028 
0029 History::History(const QString &day, const QString &uses, const QString &accounts)
0030     : m_day(day)
0031     , m_uses(uses)
0032     , m_accounts(accounts)
0033 {
0034 }
0035 
0036 QList<History> Tag::history() const
0037 {
0038     return m_history;
0039 }
0040 
0041 QUrl Tag::url() const
0042 {
0043     return m_url;
0044 }
0045 
0046 QString Tag::name() const
0047 {
0048     return m_name;
0049 }
0050 
0051 #include "moc_tag.cpp"