File indexing completed on 2024-04-28 04:43:00
0001 /* 0002 * Copyright (C) 2014 David Faure <faure@kde.org> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 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 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "moviedblist.h" 0021 #include "configuration.h" 0022 0023 #include <QDebug> 0024 #include <QJsonArray> 0025 #include <QJsonObject> 0026 0027 using namespace TmdbQt; 0028 0029 class TmdbQt::MovieDbPrivate : public QSharedData 0030 { 0031 public: 0032 MovieDbPrivate(const Configuration &config) 0033 : m_configuration(config), 0034 m_id(-1), 0035 m_budget(0), 0036 m_revenue(0), 0037 m_runtime(0) 0038 {} 0039 0040 const Configuration &m_configuration; 0041 QString m_backdropPath; 0042 int m_id; 0043 QString m_originalTitle; 0044 QDate m_releaseDate; 0045 QString m_posterPath; 0046 QString m_title; 0047 int m_budget; 0048 QString m_overview; 0049 QStringList m_productionCompanyNames; 0050 int m_revenue; 0051 int m_runtime; 0052 }; 0053 0054 MovieDb::MovieDb(const Configuration &configuration) 0055 : d(new MovieDbPrivate(configuration)) 0056 { 0057 } 0058 0059 MovieDb::MovieDb(const MovieDb &other) 0060 : d(other.d) 0061 { 0062 } 0063 0064 MovieDb::~MovieDb() 0065 { 0066 } 0067 0068 MovieDb &MovieDb::operator=(const MovieDb &other) 0069 { 0070 d = other.d; 0071 return *this; 0072 } 0073 0074 QString MovieDb::backdropPath() const 0075 { 0076 return d->m_backdropPath; 0077 } 0078 0079 int MovieDb::id() const 0080 { 0081 return d->m_id; 0082 } 0083 0084 QString MovieDb::originalTitle() const 0085 { 0086 return d->m_originalTitle; 0087 } 0088 0089 QDate MovieDb::releaseDate() const 0090 { 0091 return d->m_releaseDate; 0092 } 0093 0094 QString MovieDb::posterPath() const 0095 { 0096 return d->m_posterPath; 0097 } 0098 0099 QString MovieDb::title() const 0100 { 0101 return d->m_title; 0102 } 0103 0104 int MovieDb::budget() const 0105 { 0106 return d->m_budget; 0107 } 0108 0109 QString MovieDb::overview() const 0110 { 0111 return d->m_overview; 0112 } 0113 0114 QStringList MovieDb::productionCompanyNames() const 0115 { 0116 return d->m_productionCompanyNames; 0117 } 0118 0119 int MovieDb::revenue() const 0120 { 0121 return d->m_revenue; 0122 } 0123 0124 int MovieDb::runtime() const 0125 { 0126 return d->m_runtime; 0127 } 0128 0129 QUrl MovieDb::backdropUrl(const QString &size) const 0130 { 0131 QUrl url = d->m_configuration.imageBaseUrl(); 0132 if (url.isEmpty()) 0133 qWarning() << "No image base URL, did you wait for the initialized() signal before starting jobs?"; 0134 url.setPath(url.path() + size + d->m_backdropPath); 0135 return url; 0136 } 0137 0138 QUrl MovieDb::posterUrl(const QString &size) const 0139 { 0140 QUrl url = d->m_configuration.imageBaseUrl(); 0141 if (url.isEmpty()) 0142 qWarning() << "No image base URL, did you wait for the initialized() signal before starting jobs?"; 0143 url.setPath(url.path() + size + d->m_posterPath); 0144 return url; 0145 } 0146 0147 void MovieDb::load(const QJsonObject &json) 0148 { 0149 d->m_backdropPath = json.value(QStringLiteral("backdrop_path")).toString(); 0150 d->m_id = json.value(QStringLiteral("id")).toInt(); 0151 d->m_originalTitle = json.value(QStringLiteral("original_title")).toString(); 0152 const QString releaseDate = json.value(QStringLiteral("release_date")).toString(); 0153 d->m_releaseDate = QDate::fromString(releaseDate, Qt::ISODate); 0154 d->m_posterPath = json.value(QStringLiteral("poster_path")).toString(); 0155 d->m_title = json.value(QStringLiteral("title")).toString(); 0156 0157 d->m_budget = json.value(QStringLiteral("budget")).toInt(); 0158 d->m_overview = json.value(QStringLiteral("overview")).toString(); 0159 const QJsonArray productionCompanies = json.value(QStringLiteral("production_companies")).toArray(); 0160 for (int i = 0; i < productionCompanies.count() ; ++i) { 0161 const QJsonObject obj = productionCompanies.at(i).toObject(); 0162 d->m_productionCompanyNames << obj.value(QStringLiteral("name")).toString(); 0163 } 0164 d->m_revenue = json.value(QStringLiteral("revenue")).toInt(); 0165 d->m_runtime = json.value(QStringLiteral("runtime")).toInt(); 0166 0167 } 0168 0169 QDebug operator<<(QDebug dbg, const MovieDb &movie) 0170 { 0171 dbg << '[' << movie.id() << movie.title() << ']'; 0172 return dbg; 0173 }