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 "tvepisodedb.h"
0021 #include "configuration.h"
0022 
0023 #include <QDebug>
0024 #include <QJsonArray>
0025 #include <QJsonObject>
0026 
0027 using namespace TmdbQt;
0028 
0029 class TmdbQt::TvEpisodeDbPrivate : public QSharedData
0030 {
0031 public:
0032     TvEpisodeDbPrivate(const Configuration &config)
0033         : m_configuration(config)
0034         , m_episodeNumber(-1)
0035     {}
0036 
0037     const Configuration &m_configuration;
0038 
0039     int m_episodeNumber;
0040     QDate m_airDate;
0041 
0042     QString m_name;
0043     QString m_overview;
0044     QString m_stillPath;
0045 };
0046 
0047 TvEpisodeDb::TvEpisodeDb(const Configuration& config)
0048     : d(new TvEpisodeDbPrivate(config))
0049 {
0050 }
0051 
0052 TvEpisodeDb::TvEpisodeDb(const TvEpisodeDb& other)
0053     : d(other.d)
0054 {
0055 }
0056 
0057 TvEpisodeDb::~TvEpisodeDb()
0058 {
0059 }
0060 
0061 
0062 TvEpisodeDb &TvEpisodeDb::operator=(const TvEpisodeDb& other)
0063 {
0064     d = other.d;
0065     return *this;
0066 }
0067 
0068 QDate TvEpisodeDb::airDate() const
0069 {
0070     return d->m_airDate;
0071 }
0072 
0073 QString TvEpisodeDb::name() const
0074 {
0075     return d->m_name;
0076 }
0077 
0078 int TvEpisodeDb::episodeNumber() const
0079 {
0080     return d->m_episodeNumber;
0081 }
0082 
0083 QString TvEpisodeDb::overview() const
0084 {
0085     return d->m_overview;
0086 }
0087 
0088 QString TvEpisodeDb::stillPath() const
0089 {
0090     return d->m_stillPath;
0091 }
0092 
0093 QUrl TvEpisodeDb::stillUrl(const QString& size) const
0094 {
0095     QUrl url = d->m_configuration.imageBaseUrl();
0096     if (url.isEmpty())
0097         qWarning() << "No image base URL, did you wait for the initialized() signal before starting jobs?";
0098     url.setPath(url.path() + size + d->m_stillPath);
0099     return url;
0100 }
0101 
0102 void TvEpisodeDb::load(const QJsonObject& json)
0103 {
0104     d->m_episodeNumber = json.value(QStringLiteral("episode_number")).toInt();
0105     const QString date = json.value(QStringLiteral("air_date")).toString();
0106     d->m_airDate = QDate::fromString(date, Qt::ISODate);
0107 
0108     d->m_stillPath = json.value(QStringLiteral("still_path")).toString();
0109     d->m_name = json.value(QStringLiteral("name")).toString();
0110     d->m_overview = json.value(QStringLiteral("overview")).toString();
0111 }