1 /*************************************************************************** 2 Copyright (C) 2011 Robby Stephenson <robby@periapsis.org> 3 ***************************************************************************/ 4 5 /*************************************************************************** 6 * * 7 * This program is free software; you can redistribute it and/or * 8 * modify it under the terms of the GNU General Public License as * 9 * published by the Free Software Foundation; either version 2 of * 10 * the License or (at your option) version 3 or any later version * 11 * accepted by the membership of KDE e.V. (or its successor approved * 12 * by the membership of KDE e.V.), which shall act as a proxy * 13 * defined in Section 14 of version 3 of the license. * 14 * * 15 * This program is distributed in the hope that it will be useful, * 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 18 * GNU General Public License for more details. * 19 * * 20 * You should have received a copy of the GNU General Public License * 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 22 * * 23 ***************************************************************************/ 24 25 #ifndef TELLICO_GOOGLEBOOKFETCHER_H 26 #define TELLICO_GOOGLEBOOKFETCHER_H 27 28 #include "fetcher.h" 29 #include "configwidget.h" 30 #include "../datavectors.h" 31 32 #include <QPointer> 33 #include <QVariantMap> 34 35 class KJob; 36 namespace KIO { 37 class StoredTransferJob; 38 } 39 40 class QLineEdit; 41 42 namespace Tellico { 43 44 namespace Fetch { 45 46 /** 47 * A fetcher for Google Book Search 48 * 49 * @author Robby Stephenson 50 */ 51 class GoogleBookFetcher : public Fetcher { 52 Q_OBJECT 53 54 public: 55 /** 56 */ 57 GoogleBookFetcher(QObject* parent); 58 /** 59 */ 60 virtual ~GoogleBookFetcher(); 61 62 /** 63 */ 64 virtual QString source() const Q_DECL_OVERRIDE; isSearching()65 virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } 66 virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE; 67 virtual void stop() Q_DECL_OVERRIDE; 68 virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; type()69 virtual Type type() const Q_DECL_OVERRIDE { return GoogleBook; } 70 virtual bool canFetch(int type) const Q_DECL_OVERRIDE; 71 virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; 72 virtual void continueSearch() Q_DECL_OVERRIDE; 73 74 /** 75 * Returns a widget for modifying the fetcher's config. 76 */ 77 virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; 78 79 class ConfigWidget : public Fetch::ConfigWidget { 80 public: 81 explicit ConfigWidget(QWidget* parent_, const GoogleBookFetcher* fetcher = nullptr); 82 virtual void saveConfigHook(KConfigGroup&) Q_DECL_OVERRIDE; 83 virtual QString preferredName() const Q_DECL_OVERRIDE; 84 private: 85 QLineEdit* m_apiKeyEdit; 86 }; 87 friend class ConfigWidget; 88 89 static QString defaultName(); 90 static QString defaultIcon(); 91 static StringHash allOptionalFields(); 92 93 private Q_SLOTS: 94 void slotComplete(KJob* job); 95 96 private: 97 virtual void search() Q_DECL_OVERRIDE; 98 virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; 99 void doSearch(const QString& term); 100 void endJob(KIO::StoredTransferJob* job); 101 void populateEntry(Data::EntryPtr entry, const QVariantMap& resultMap); 102 103 QHash<uint, Data::EntryPtr> m_entries; 104 QList< QPointer<KIO::StoredTransferJob> > m_jobs; 105 106 bool m_started; 107 108 int m_start; 109 int m_total; 110 QString m_apiKey; 111 }; 112 113 } // end namespace 114 } // end namespace 115 #endif 116