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