1 /***************************************************************************
2     Copyright (C) 2003-2009 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_SRUFETCHER_H
26 #define TELLICO_SRUFETCHER_H
27 
28 #include "fetcher.h"
29 #include "configwidget.h"
30 
31 #include <QPointer>
32 
33 class QSpinBox;
34 
35 class KJob;
36 namespace KIO {
37   class StoredTransferJob;
38 }
39 
40 namespace Tellico {
41   class XSLTHandler;
42   namespace GUI {
43     class LineEdit;
44     class ComboBox;
45     class StringMapWidget;
46   }
47   namespace Fetch {
48 
49 /**
50  * A fetcher for SRU servers.
51  * Right now, only MODS is supported.
52  *
53  * @author Robby Stephenson
54  */
55 class SRUFetcher : public Fetcher {
56 Q_OBJECT
57 
58 public:
59   /**
60    */
61   SRUFetcher(QObject* parent);
62   SRUFetcher(const QString& name, const QString& host, uint port,
63              const QString& dbname, const QString& format,
64              QObject* parent);
65   /**
66    */
67   virtual ~SRUFetcher();
68 
69   /**
70    */
71   virtual QString source() const Q_DECL_OVERRIDE;
isSearching()72   virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; }
73   virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE;
74   virtual void stop() Q_DECL_OVERRIDE;
75   virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE;
type()76   virtual Type type() const Q_DECL_OVERRIDE { return SRU; }
77   virtual bool canFetch(int type) const Q_DECL_OVERRIDE;
78   virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE;
79 
80   virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE;
81 
82   class ConfigWidget;
83   friend class ConfigWidget;
84 
85   static QString defaultName();
86   static QString defaultIcon();
87   static StringHash allOptionalFields();
88 
89   static Fetcher::Ptr libraryOfCongress(QObject* parent);
90 
91 private Q_SLOTS:
92   void slotComplete(KJob* job);
93 
94 private:
95   virtual void search() Q_DECL_OVERRIDE;
96   virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE;
97   bool initMARCXMLHandler();
98   bool initMODSHandler();
99   bool initSRWHandler();
100 
101   QString m_host;
102   uint m_port;
103   QString m_path;
104   QString m_format;
105   StringMap m_queryMap;
106 
107   QHash<uint, Data::EntryPtr> m_entries;
108   QPointer<KIO::StoredTransferJob> m_job;
109   XSLTHandler* m_MARCXMLHandler;
110   XSLTHandler* m_MODSHandler;
111   XSLTHandler* m_SRWHandler;
112   bool m_started;
113 };
114 
115 class SRUFetcher::ConfigWidget : public Fetch::ConfigWidget {
116 Q_OBJECT
117 
118 public:
119   explicit ConfigWidget(QWidget* parent_, const SRUFetcher* fetcher = nullptr);
120   virtual void saveConfigHook(KConfigGroup& config) Q_DECL_OVERRIDE;
121   virtual QString preferredName() const Q_DECL_OVERRIDE;
122 
123 private Q_SLOTS:
124   void slotCheckHost();
125 
126 private:
127   GUI::LineEdit* m_hostEdit;
128   QSpinBox* m_portSpinBox;
129   GUI::LineEdit* m_pathEdit;
130   GUI::ComboBox* m_formatCombo;
131   GUI::StringMapWidget* m_queryTree;
132 };
133 
134   } // end namespace
135 } // end namespace
136 #endif
137