File indexing completed on 2024-05-12 05:09:36

0001 /***************************************************************************
0002     Copyright (C) 2004-2009 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_IMDBFETCHER_H
0026 #define TELLICO_IMDBFETCHER_H
0027 
0028 #include "fetcher.h"
0029 #include "configwidget.h"
0030 
0031 #include <QUrl>
0032 #include <QPointer>
0033 
0034 class QSpinBox;
0035 class QRadioButton;
0036 
0037 class KJob;
0038 namespace KIO {
0039   class Job;
0040   class StoredTransferJob;
0041 }
0042 
0043 class ImdbFetcherTest;
0044 namespace Tellico {
0045   namespace GUI {
0046     class ComboBox;
0047     class LineEdit;
0048   }
0049   namespace Fetch {
0050 
0051 /**
0052  * @author Robby Stephenson
0053  */
0054 class IMDBFetcher : public Fetcher {
0055 Q_OBJECT
0056 
0057 public:
0058   IMDBFetcher(QObject* parent);
0059   /**
0060    */
0061   virtual ~IMDBFetcher();
0062 
0063   virtual QString source() const Q_DECL_OVERRIDE;
0064   virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; }
0065   virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE;
0066   virtual void stop() Q_DECL_OVERRIDE;
0067   virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE;
0068   virtual Type type() const Q_DECL_OVERRIDE { return IMDB; }
0069   virtual bool canFetch(int type) const Q_DECL_OVERRIDE;
0070   virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE;
0071 
0072   virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE;
0073 
0074   class ConfigWidget;
0075   friend class ConfigWidget;
0076 
0077   static QString defaultName();
0078   static QString defaultIcon();
0079   static StringHash allOptionalFields();
0080 
0081 private Q_SLOTS:
0082   void slotComplete(KJob* job);
0083 
0084 private:
0085   friend class ::ImdbFetcherTest;
0086   static QString searchQuery();
0087   static QString titleQuery();
0088   static QString episodeQuery();
0089 
0090   virtual void search() Q_DECL_OVERRIDE;
0091   virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE;
0092 
0093   void configureJob(QPointer<KIO::StoredTransferJob> job);
0094   Data::EntryPtr readGraphQL(const QString& imdbId, const QString& titleType);
0095   Data::EntryPtr parseResult(const QByteArray& data);
0096 
0097   QHash<uint, Data::EntryPtr> m_entries;
0098   QHash<uint, QString> m_matches;
0099   QHash<uint, QString> m_titleTypes;
0100   QPointer<KIO::StoredTransferJob> m_job;
0101 
0102   bool m_started;
0103 
0104   enum ImageSize {
0105     NoImage=0,
0106     SmallImage=1, // 256x256 max
0107     MediumImage=2, // 640x640 max
0108     LargeImage=3 // max returned
0109   };
0110   ImageSize m_imageSize;
0111   int m_numCast;
0112   QUrl m_url;
0113   bool m_useSystemLocale;
0114   QString m_customLocale;
0115 };
0116 
0117 class IMDBFetcher::ConfigWidget : public Fetch::ConfigWidget {
0118 Q_OBJECT
0119 
0120 public:
0121   explicit ConfigWidget(QWidget* parent_, const IMDBFetcher* fetcher = nullptr);
0122 
0123   virtual void saveConfigHook(KConfigGroup& config) Q_DECL_OVERRIDE;
0124   virtual QString preferredName() const Q_DECL_OVERRIDE;
0125 
0126 private Q_SLOTS:
0127   void slotLocaleChanged(int id);
0128 
0129 private:
0130   GUI::ComboBox* m_imageCombo;
0131   QSpinBox* m_numCast;
0132   QRadioButton* m_systemLocaleRadioButton;
0133   QRadioButton* m_customLocaleRadioButton;
0134   GUI::LineEdit* m_customLocaleEdit;
0135 };
0136 
0137   } // end namespace
0138 } // end namespace
0139 
0140 #endif