File indexing completed on 2024-05-12 05:09:37
0001 /*************************************************************************** 0002 Copyright (C) 2017-2021 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 #ifndef TELLICO_FETCH_KINOPOISKFETCHER_H 0026 #define TELLICO_FETCH_KINOPOISKFETCHER_H 0027 0028 #include "fetcher.h" 0029 #include "configwidget.h" 0030 0031 #include <QPointer> 0032 #include <QJsonValue> 0033 #include <QJsonObject> 0034 0035 class QUrl; 0036 class QSpinBox; 0037 0038 class KJob; 0039 namespace KIO { 0040 class Job; 0041 class StoredTransferJob; 0042 } 0043 0044 namespace Tellico { 0045 namespace Fetch { 0046 0047 /** 0048 * A fetcher for www.kinopoisk.ru 0049 * 0050 * @author Robby Stephenson 0051 */ 0052 class KinoPoiskFetcher : public Fetcher { 0053 Q_OBJECT 0054 0055 public: 0056 KinoPoiskFetcher(QObject* parent); 0057 virtual ~KinoPoiskFetcher(); 0058 0059 virtual QString source() const Q_DECL_OVERRIDE; 0060 virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } 0061 virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE; 0062 virtual void stop() Q_DECL_OVERRIDE; 0063 virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; 0064 virtual Type type() const Q_DECL_OVERRIDE { return KinoPoisk; } 0065 virtual bool canFetch(int type) const Q_DECL_OVERRIDE; 0066 virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; 0067 0068 virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; 0069 0070 class ConfigWidget : public Fetch::ConfigWidget { 0071 public: 0072 explicit ConfigWidget(QWidget* parent_, const KinoPoiskFetcher* fetcher = nullptr); 0073 virtual void saveConfigHook(KConfigGroup&) Q_DECL_OVERRIDE; 0074 virtual QString preferredName() const Q_DECL_OVERRIDE; 0075 private: 0076 QSpinBox* m_numCast; 0077 }; 0078 friend class ConfigWidget; 0079 0080 static QString defaultName(); 0081 static QString defaultIcon(); 0082 static StringHash allOptionalFields(); 0083 0084 private Q_SLOTS: 0085 void slotComplete(KJob* job); 0086 void slotRedirection(KIO::Job* job, const QUrl& toUrl); 0087 0088 private: 0089 static QString fieldNameFromKey(const QString& key); 0090 static QString fieldValueFromObject(const QJsonObject& obj, const QString& field, 0091 const QJsonValue& value, const QStringList& allowed); 0092 static QString mpaaRating(const QString& value, const QStringList& allowed); 0093 0094 virtual void search() Q_DECL_OVERRIDE; 0095 virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; 0096 Data::EntryPtr requestEntry(const QString& filmId); 0097 Data::EntryPtr parseEntry(const QString& str); 0098 Data::EntryPtr parseEntryLinkedData(const QString& str); 0099 0100 QHash<uint, Data::EntryPtr> m_entries; 0101 QHash<uint, QUrl> m_matches; 0102 QPointer<KIO::StoredTransferJob> m_job; 0103 0104 bool m_started; 0105 bool m_redirected; 0106 QUrl m_redirectUrl; 0107 QString m_apiKey; 0108 int m_numCast; 0109 }; 0110 0111 } // end namespace 0112 } // end namespace 0113 #endif