summaryrefslogtreecommitdiffstats
path: root/src/fetch/fetcher.h
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
commite38d2351b83fa65c66ccde443777647ef5cb6cff (patch)
tree1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/fetch/fetcher.h
downloadtellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz
tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/fetch/fetcher.h')
-rw-r--r--src/fetch/fetcher.h151
1 files changed, 151 insertions, 0 deletions
diff --git a/src/fetch/fetcher.h b/src/fetch/fetcher.h
new file mode 100644
index 0000000..0d2496e
--- /dev/null
+++ b/src/fetch/fetcher.h
@@ -0,0 +1,151 @@
+/***************************************************************************
+ copyright : (C) 2003-2006 by Robby Stephenson
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of version 2 of the GNU General Public License as *
+ * published by the Free Software Foundation; *
+ * *
+ ***************************************************************************/
+
+#ifndef FETCHER_H
+#define FETCHER_H
+
+#include "fetch.h"
+#include "../datavectors.h"
+
+#include <kapplication.h> // for KApplication::random()
+
+#include <qobject.h>
+#include <qstring.h>
+
+class KConfigGroup;
+
+namespace Tellico {
+ namespace Fetch {
+ class ConfigWidget;
+ class MessageHandler;
+ class SearchResult;
+
+/**
+ * The top-level abstract class for fetching data.
+ *
+ * @author Robby Stephenson
+ */
+class Fetcher : public QObject, public KShared {
+Q_OBJECT
+
+public:
+ typedef KSharedPtr<Fetcher> Ptr;
+ typedef KSharedPtr<const Fetcher> CPtr;
+
+ /**
+ */
+ Fetcher(QObject* parent, const char* name = 0) : QObject(parent, name), KShared(),
+ m_updateOverwrite(false), m_hasMoreResults(false),
+ m_messager(0) {}
+ /**
+ */
+ virtual ~Fetcher();
+
+ /**
+ * Returns true if the fetcher might return entries from a certain collection type.
+ */
+ virtual bool canFetch(int type) const = 0;
+ /**
+ * Returns true if the fetcher can search using a certain key.
+ */
+ virtual bool canSearch(FetchKey key) const = 0;
+ virtual bool canUpdate() const { return true; }
+
+ /**
+ * Returns the type of the data source.
+ */
+ virtual Type type() const = 0;
+ /**
+ * Returns the name of the data source, as defined by the user.
+ */
+ virtual QString source() const = 0;
+ /**
+ * Returns whether the fetcher will overwite existing info when updating
+ */
+ bool updateOverwrite() const { return m_updateOverwrite; }
+ /**
+ * Starts a search, using a key and value.
+ */
+ virtual void search(FetchKey key, const QString& value) = 0;
+ virtual void continueSearch() {}
+ virtual void updateEntry(Data::EntryPtr);
+ // mopst fetchers won't support this. it's particular useful for text fetchers
+ virtual void updateEntrySynchronous(Data::EntryPtr) {}
+ /**
+ * Returns true if the fetcher is currently searching.
+ */
+ virtual bool isSearching() const = 0;
+ /**
+ * Returns true if the fetcher can continue and fetch more results
+ * The fetcher is responsible for remembering state.
+ */
+ virtual bool hasMoreResults() const { return m_hasMoreResults; }
+ /**
+ * Stops the fetcher.
+ */
+ virtual void stop() = 0;
+ /**
+ * Fetches an entry, given the uid of the search result.
+ */
+ virtual Data::EntryPtr fetchEntry(uint uid) = 0;
+
+ void setMessageHandler(MessageHandler* handler) { m_messager = handler; }
+ MessageHandler* messageHandler() const { return m_messager; }
+ /**
+ */
+ void message(const QString& message, int type) const;
+ void infoList(const QString& message, const QStringList& list) const;
+
+ /**
+ * Reads the config for the widget, given a config group.
+ */
+ void readConfig(const KConfigGroup& config, const QString& groupName);
+ /**
+ * Returns a widget for modifying the fetcher's config.
+ */
+ virtual ConfigWidget* configWidget(QWidget* parent) const = 0;
+
+signals:
+// void signalStatus(const QString& status);
+ void signalResultFound(Tellico::Fetch::SearchResult* result);
+ void signalDone(Tellico::Fetch::Fetcher::Ptr);
+
+protected:
+ QString m_name;
+ bool m_updateOverwrite : 1;
+ bool m_hasMoreResults : 1;
+
+private:
+ virtual void readConfigHook(const KConfigGroup&) = 0;
+ virtual void saveConfigHook(KConfigGroup&) {}
+
+ MessageHandler* m_messager;
+ QString m_configGroup;
+};
+
+class SearchResult {
+public:
+ SearchResult(Fetcher::Ptr f, const QString& t, const QString& d, const QString& i)
+ : uid(KApplication::random()), fetcher(f), title(t), desc(d), isbn(i) {}
+ Data::EntryPtr fetchEntry();
+ uint uid;
+ Fetcher::Ptr fetcher;
+ QString title;
+ QString desc;
+ QString isbn;
+};
+
+ } // end namespace
+} // end namespace
+
+#endif