File indexing completed on 2024-05-12 16:45:45
0001 /*************************************************************************** 0002 Copyright (C) 2019 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_COLNECTFETCHER_H 0026 #define TELLICO_COLNECTFETCHER_H 0027 0028 #include "fetcher.h" 0029 #include "configwidget.h" 0030 #include "../datavectors.h" 0031 0032 #include <QPointer> 0033 #include <QVariantMap> 0034 0035 class KJob; 0036 namespace KIO { 0037 class StoredTransferJob; 0038 } 0039 0040 class ColnectFetcherTest; 0041 namespace Tellico { 0042 0043 namespace GUI { 0044 class ComboBox; 0045 } 0046 0047 namespace Fetch { 0048 0049 /** 0050 * A fetcher for colnect.org 0051 * 0052 * @author Robby Stephenson 0053 */ 0054 class ColnectFetcher : public Fetcher { 0055 Q_OBJECT 0056 0057 friend class ::ColnectFetcherTest; 0058 0059 public: 0060 /** 0061 */ 0062 ColnectFetcher(QObject* parent); 0063 /** 0064 */ 0065 virtual ~ColnectFetcher(); 0066 0067 /** 0068 */ 0069 virtual QString source() const Q_DECL_OVERRIDE; 0070 virtual QString attribution() const Q_DECL_OVERRIDE; 0071 virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } 0072 virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE; 0073 virtual void stop() Q_DECL_OVERRIDE; 0074 virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; 0075 virtual Type type() const Q_DECL_OVERRIDE { return Colnect; } 0076 virtual bool canFetch(int type) const Q_DECL_OVERRIDE; 0077 virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; 0078 0079 /** 0080 * Returns a widget for modifying the fetcher's config. 0081 */ 0082 virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; 0083 0084 class ConfigWidget; 0085 friend class ConfigWidget; 0086 0087 static QString defaultName(); 0088 static QString defaultIcon(); 0089 static StringHash allOptionalFields(); 0090 0091 private Q_SLOTS: 0092 void slotComplete(KJob* job); 0093 0094 private: 0095 static QString URLize(const QString& name); 0096 static QString imageUrl(const QString& name, const QString& id); 0097 0098 virtual void search() Q_DECL_OVERRIDE; 0099 virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; 0100 void populateEntry(Data::EntryPtr entry, const QVariantList& resultList); 0101 void loadImage(Data::EntryPtr entry, const QString& fieldName); 0102 0103 void readDataList(); 0104 void readStampColors(); 0105 0106 QHash<uint, Data::EntryPtr> m_entries; 0107 0108 bool m_started; 0109 QString m_locale; 0110 QPointer<KIO::StoredTransferJob> m_job; 0111 QString m_year; 0112 QString m_category; 0113 0114 // map from field name to position in result list 0115 QHash<QString, int> m_colnectFields; 0116 // color names, for stamp collections 0117 QHash<int, QString> m_stampColors; 0118 }; 0119 0120 class ColnectFetcher::ConfigWidget : public Fetch::ConfigWidget { 0121 Q_OBJECT 0122 0123 public: 0124 explicit ConfigWidget(QWidget* parent_, const ColnectFetcher* fetcher = nullptr); 0125 virtual void saveConfigHook(KConfigGroup&) Q_DECL_OVERRIDE; 0126 virtual QString preferredName() const Q_DECL_OVERRIDE; 0127 0128 private Q_SLOTS: 0129 void slotLangChanged(); 0130 0131 private: 0132 GUI::ComboBox* m_langCombo; 0133 }; 0134 0135 } // end namespace 0136 } // end namespace 0137 #endif