File indexing completed on 2024-05-12 05:09:46

0001 /***************************************************************************
0002     Copyright (C) 2003-2020 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  *   In addition, as a special exception, the author gives permission to   *
0024  *   link the code of this program with the OpenSSL library released by    *
0025  *   the OpenSSL Project (or with modified versions of OpenSSL that use    *
0026  *   the same license as OpenSSL), and distribute linked combinations      *
0027  *   including the two.  You must obey the GNU General Public License in   *
0028  *   all respects for all of the code used other than OpenSSL.  If you     *
0029  *   modify this file, you may extend this exception to your version of    *
0030  *   the file, but you are not obligated to do so.  If you do not wish to  *
0031  *   do so, delete this exception statement from your version.             *
0032  *                                                                         *
0033  ***************************************************************************/
0034 
0035 #ifndef TELLICO_Z3950FETCHER_H
0036 #define TELLICO_Z3950FETCHER_H
0037 
0038 #include "fetcher.h"
0039 #include "configwidget.h"
0040 
0041 #include <QPointer>
0042 #include <QEvent>
0043 
0044 class QSpinBox;
0045 
0046 class KComboBox;
0047 
0048 namespace Tellico {
0049   class XSLTHandler;
0050   namespace GUI {
0051     class LineEdit;
0052     class ComboBox;
0053   }
0054   namespace Fetch {
0055     class Z3950Connection;
0056 
0057 /**
0058  * @author Robby Stephenson
0059  */
0060 class Z3950Fetcher : public Fetcher {
0061 Q_OBJECT
0062 
0063 public:
0064   Z3950Fetcher(QObject* parent);
0065   Z3950Fetcher(QObject* parent, const QString& preset);
0066   Z3950Fetcher(QObject* parent, const QString& host, int port, const QString& dbName, const QString& syntax);
0067 
0068   virtual ~Z3950Fetcher();
0069 
0070   virtual QString source() const Q_DECL_OVERRIDE;
0071   virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; }
0072   virtual void continueSearch() Q_DECL_OVERRIDE;
0073   virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE;
0074   virtual void stop() Q_DECL_OVERRIDE;
0075   virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE;
0076   virtual Type type() const Q_DECL_OVERRIDE { return Z3950; }
0077   virtual bool canFetch(int type) const Q_DECL_OVERRIDE;
0078   virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE;
0079   virtual void saveConfigHook(KConfigGroup& config) Q_DECL_OVERRIDE;
0080 
0081   const QString& host() const { return m_host; }
0082   void setCharacterSet(const QString& qcs, const QString& rcs = QString());
0083 
0084   virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE;
0085 
0086   class ConfigWidget;
0087   friend class ConfigWidget;
0088 
0089   static QString defaultName();
0090   static QString defaultIcon();
0091   static StringHash allOptionalFields();
0092 
0093 protected:
0094   virtual void customEvent(QEvent* event) Q_DECL_OVERRIDE;
0095 
0096 private:
0097   virtual void search() Q_DECL_OVERRIDE;
0098   virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE;
0099   bool initMARC21Handler();
0100   bool initUNIMARCHandler();
0101   bool initMODSHandler();
0102   void process();
0103   void handleResult(const QString& result);
0104   void done();
0105 
0106   Z3950Connection* m_conn;
0107 
0108   QString m_host;
0109   uint m_port;
0110   QString m_dbname;
0111   QString m_user;
0112   QString m_password;
0113   QString m_queryCharSet;
0114   QString m_responseCharSet;
0115   QString m_syntax;
0116   QString m_pqn; // prefix query notation
0117   QString m_esn; // element set name
0118 
0119   QHash<uint, Data::EntryPtr> m_entries;
0120   bool m_started;
0121   bool m_done;
0122   QString m_preset;
0123 
0124   XSLTHandler* m_MARC21XMLHandler;
0125   XSLTHandler* m_UNIMARCXMLHandler;
0126   XSLTHandler* m_MODSHandler;
0127 
0128   friend class Z3950Connection;
0129 };
0130 
0131 class Z3950Fetcher::ConfigWidget : public Fetch::ConfigWidget {
0132 Q_OBJECT
0133 
0134 public:
0135   explicit ConfigWidget(QWidget* parent, const Z3950Fetcher* fetcher = nullptr);
0136   virtual ~ConfigWidget();
0137   virtual void saveConfigHook(KConfigGroup& config_) Q_DECL_OVERRIDE;
0138   virtual QString preferredName() const Q_DECL_OVERRIDE;
0139 
0140 private Q_SLOTS:
0141   void slotTogglePreset(bool on);
0142   void slotPresetChanged();
0143 
0144 private:
0145   void loadPresets(const QString& current);
0146 
0147   QCheckBox* m_usePreset;
0148   GUI::ComboBox* m_serverCombo;
0149   GUI::LineEdit* m_hostEdit;
0150   QSpinBox* m_portSpinBox;
0151   GUI::LineEdit* m_databaseEdit;
0152   GUI::LineEdit* m_userEdit;
0153   GUI::LineEdit* m_passwordEdit;
0154   KComboBox* m_charSetCombo1;
0155   KComboBox* m_charSetCombo2;
0156   GUI::ComboBox* m_syntaxCombo;
0157   // have to remember syntax
0158   QString m_syntax;
0159 };
0160 
0161   } // end namespace
0162 } // end namespace
0163 #endif