File indexing completed on 2024-05-12 05:09:31
0001 /*************************************************************************** 0002 Copyright (C) 2003-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_FETCHER_H 0026 #define TELLICO_FETCHER_H 0027 0028 #include "fetch.h" 0029 #include "fetchrequest.h" 0030 #include "fetchresult.h" 0031 #include "messagehandler.h" 0032 #include "../datavectors.h" 0033 0034 #include <QObject> 0035 #include <QString> 0036 #include <QStringList> 0037 #include <QPointer> 0038 #include <QUrl> 0039 0040 #include <KConfigGroup> 0041 0042 namespace Tellico { 0043 namespace Fetch { 0044 0045 class ConfigWidget; 0046 0047 /** 0048 * The top-level abstract class for fetching data. 0049 * 0050 * @author Robby Stephenson 0051 */ 0052 class Fetcher : public QObject { 0053 Q_OBJECT 0054 0055 public: 0056 typedef QPointer<Fetcher> Ptr; 0057 0058 /** 0059 */ 0060 Fetcher(QObject* parent); 0061 /** 0062 */ 0063 virtual ~Fetcher(); 0064 0065 /** 0066 * Returns true if the fetcher might return entries from a certain collection type. 0067 */ 0068 virtual bool canFetch(int type) const = 0; 0069 /** 0070 * Returns true if the fetcher can search using a certain key. 0071 */ 0072 virtual bool canSearch(FetchKey key) const = 0; 0073 virtual bool canUpdate() const; 0074 0075 /** 0076 * Returns the type of the data source. 0077 */ 0078 virtual Type type() const = 0; 0079 /** 0080 * Returns the name of the data source, as defined by the user. 0081 */ 0082 virtual QString source() const = 0; 0083 virtual QString attribution() const { return QString(); } 0084 virtual QString icon() const { return QString(); } 0085 /** 0086 * Returns the collection type of the most recent search 0087 */ 0088 int collectionType() const; 0089 /** 0090 * Returns whether the fetcher will overwite existing info when updating 0091 */ 0092 bool updateOverwrite() const; 0093 const FetchRequest& request() const; 0094 QStringList optionalFields() const { return m_fields; } 0095 QString uuid() const { return m_uuid; } 0096 /** 0097 * Starts a search, using a key and value. Calls search() 0098 */ 0099 void startSearch(const FetchRequest& request); 0100 virtual void continueSearch() {} 0101 void startUpdate(Data::EntryPtr entry); 0102 /** 0103 * Returns true if the fetcher is currently searching. 0104 */ 0105 virtual bool isSearching() const = 0; 0106 /** 0107 * Returns true if the fetcher can continue and fetch more results 0108 * The fetcher is responsible for remembering state. 0109 */ 0110 virtual bool hasMoreResults() const { return m_hasMoreResults; } 0111 /** 0112 * Stops the fetcher. 0113 */ 0114 virtual void stop() = 0; 0115 /** 0116 * Fetches an entry, given the uid of the search result. 0117 */ 0118 Data::EntryPtr fetchEntry(uint uid); 0119 0120 void setMessageHandler(MessageHandler* handler); 0121 MessageHandler* messageHandler() const { return m_messager; } 0122 /** 0123 */ 0124 void message(const QString& message, int type) const; 0125 0126 /** 0127 * Reads the config for the widget, given a config group. 0128 */ 0129 void readConfig(const KConfigGroup& config); 0130 void saveConfig(); 0131 void setConfigGroup(const KConfigGroup& config); 0132 /** 0133 * Returns a widget for modifying the fetcher's config. 0134 */ 0135 virtual ConfigWidget* configWidget(QWidget* parent) const = 0; 0136 0137 static QString favIcon(const char* url); 0138 static QString favIcon(const QUrl& url, const QUrl& iconUrl=QUrl()); 0139 0140 Q_SIGNALS: 0141 void signalResultFound(Tellico::Fetch::FetchResult* result); 0142 void signalDone(Tellico::Fetch::Fetcher* fetcher); 0143 0144 protected: 0145 QString m_name; 0146 FetchRequest m_request; 0147 bool m_updateOverwrite; 0148 bool m_hasMoreResults; 0149 0150 private: 0151 /** 0152 * Starts a search, using a key and value. 0153 */ 0154 virtual void search() = 0; 0155 virtual FetchRequest updateRequest(Data::EntryPtr entry) = 0; 0156 virtual void readConfigHook(const KConfigGroup&) = 0; 0157 virtual void saveConfigHook(KConfigGroup&) {} 0158 virtual Data::EntryPtr fetchEntryHook(uint uid) = 0; 0159 0160 MessageHandler* m_messager; 0161 KConfigGroup m_configGroup; 0162 QStringList m_fields; 0163 QString m_uuid; 0164 QHash<uint, Data::EntryPtr> m_entries; 0165 }; 0166 0167 } // end namespace 0168 } // end namespace 0169 0170 #endif