File indexing completed on 2024-04-28 04:43:01
0001 /* 0002 * Copyright (C) 2014 Vishesh Handa <me@vhanda.in> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Lesser General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Lesser General Public 0015 * License along with this library; if not, write to the Free Software 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0017 * 0018 */ 0019 0020 #include "tvseasondb.h" 0021 #include "tvepisodedblist.h" 0022 #include "configuration.h" 0023 0024 #include <QJsonArray> 0025 #include <QJsonObject> 0026 #include <QDebug> 0027 0028 using namespace TmdbQt; 0029 0030 class TmdbQt::TvSeasonDbPrivate : public QSharedData 0031 { 0032 public: 0033 TvSeasonDbPrivate(const Configuration &config) 0034 : m_configuration(config) 0035 , m_id(-1) 0036 , m_seasonNumber(-1) 0037 {} 0038 0039 Configuration m_configuration; 0040 0041 int m_id; 0042 int m_seasonNumber; 0043 0044 QString m_name; 0045 QString m_overview; 0046 0047 QDate m_airDate; 0048 QString m_posterPath; 0049 0050 TvEpisodeDbList m_episodes; 0051 }; 0052 0053 TvSeasonDb::TvSeasonDb(const Configuration& config) 0054 : d(new TvSeasonDbPrivate(config)) 0055 { 0056 } 0057 0058 TvSeasonDb::TvSeasonDb(const TvSeasonDb& other) 0059 : d(other.d) 0060 { 0061 } 0062 0063 TvSeasonDb::~TvSeasonDb() 0064 { 0065 } 0066 0067 TvSeasonDb &TvSeasonDb::operator=(const TvSeasonDb& other) 0068 { 0069 d = other.d; 0070 return *this; 0071 } 0072 0073 QDate TvSeasonDb::airDate() const 0074 { 0075 return d->m_airDate; 0076 } 0077 0078 int TvSeasonDb::id() const 0079 { 0080 return d->m_id; 0081 } 0082 0083 QString TvSeasonDb::name() const 0084 { 0085 return d->m_name; 0086 } 0087 0088 QString TvSeasonDb::overview() const 0089 { 0090 return d->m_overview; 0091 } 0092 0093 QString TvSeasonDb::posterPath() const 0094 { 0095 return d->m_posterPath; 0096 } 0097 0098 int TvSeasonDb::seasonNumber() const 0099 { 0100 return d->m_seasonNumber; 0101 } 0102 0103 QUrl TvSeasonDb::posterUrl(const QString& size) const 0104 { 0105 QUrl url = d->m_configuration.imageBaseUrl(); 0106 if (url.isEmpty()) 0107 qWarning() << "No image base URL, did you wait for the initialized() signal before starting jobs?"; 0108 url.setPath(url.path() + size + d->m_posterPath); 0109 return url; 0110 } 0111 0112 TvEpisodeDbList TvSeasonDb::episodes() const 0113 { 0114 return d->m_episodes; 0115 } 0116 0117 void TvSeasonDb::load(const QJsonObject& json) 0118 { 0119 d->m_id = json.value(QStringLiteral("id")).toInt(); 0120 d->m_seasonNumber = json.value(QStringLiteral("season_number")).toInt(); 0121 d->m_name = json.value(QStringLiteral("name")).toString(); 0122 d->m_overview = json.value(QStringLiteral("overview")).toString(); 0123 0124 const QString airDate = json.value(QStringLiteral("air_date")).toString(); 0125 d->m_airDate = QDate::fromString(airDate, Qt::ISODate); 0126 d->m_posterPath = json.value(QStringLiteral("poster_path")).toString(); 0127 0128 QJsonArray arr = json.value(QStringLiteral("episodes")).toArray(); 0129 d->m_episodes.load(arr, d->m_configuration); 0130 } 0131 0132