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

0001 /***************************************************************************
0002     Copyright (C) 2007-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_GCSTARPLUGINFETCHER_H
0026 #define TELLICO_GCSTARPLUGINFETCHER_H
0027 
0028 #include "fetcher.h"
0029 #include "configwidget.h"
0030 
0031 #include <QShowEvent>
0032 #include <QLabel>
0033 #include <QList>
0034 
0035 class QLabel;
0036 
0037 namespace Tellico {
0038   namespace GUI {
0039     class ComboBox;
0040     class CollectionTypeCombo;
0041   }
0042   namespace Fetch {
0043 
0044   class GCstarThread;
0045 
0046 /**
0047  * @author Robby Stephenson
0048  */
0049 class GCstarPluginFetcher : public Fetcher {
0050 Q_OBJECT
0051 
0052 public:
0053 
0054   GCstarPluginFetcher(QObject* parent);
0055   /**
0056    */
0057   virtual ~GCstarPluginFetcher();
0058 
0059   virtual QString source() const Q_DECL_OVERRIDE;
0060   virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; }
0061   virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE { return k == Title; }
0062 
0063   virtual void stop() Q_DECL_OVERRIDE;
0064   virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE;
0065   virtual Type type() const Q_DECL_OVERRIDE { return GCstarPlugin; }
0066   virtual bool canFetch(int type) const Q_DECL_OVERRIDE;
0067   virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE;
0068   virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE;
0069 
0070   class ConfigWidget;
0071   friend class ConfigWidget;
0072 
0073   static QString defaultName();
0074   static QString defaultIcon();
0075   static StringHash allOptionalFields() { return StringHash(); }
0076 
0077 private Q_SLOTS:
0078   void slotData(const QByteArray& data);
0079   void slotError(const QByteArray& data);
0080   void slotProcessExited();
0081 
0082 private:
0083   virtual void search() Q_DECL_OVERRIDE;
0084   virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE;
0085 
0086   // map Author, Name, Lang, etc...
0087   typedef QHash<QString, QVariant> PluginInfo;
0088   typedef QList<PluginInfo> PluginList;
0089   // map collection type to all available plugins
0090   typedef QHash<int, PluginList> CollectionPlugins;
0091   static CollectionPlugins collectionPlugins;
0092   static PluginList plugins(int collType);
0093   // we need to keep track if we've searched for plugins yet and by what method
0094   enum PluginParse { NotYet, Old, New };
0095   static PluginParse pluginParse;
0096   static void readPluginsNew(int collType, const QString& exe);
0097   static void readPluginsOld(int collType, const QString& exe);
0098   static QString gcstarType(int collType);
0099 
0100   bool m_started;
0101   int m_collType;
0102   QString m_plugin;
0103 
0104   GCstarThread* m_thread;
0105   QByteArray m_data;
0106   QHash<uint, Data::EntryPtr> m_entries; // map from search result id to entry
0107   QStringList m_errors;
0108 };
0109 
0110 class GCstarPluginFetcher::ConfigWidget : public Fetch::ConfigWidget {
0111 Q_OBJECT
0112 
0113 public:
0114   explicit ConfigWidget(QWidget* parent, const GCstarPluginFetcher* fetcher = nullptr);
0115   ~ConfigWidget();
0116 
0117   virtual void saveConfigHook(KConfigGroup& config) Q_DECL_OVERRIDE;
0118   virtual QString preferredName() const Q_DECL_OVERRIDE;
0119 
0120 private Q_SLOTS:
0121   void slotTypeChanged();
0122   void slotPluginChanged();
0123 
0124 private:
0125   void showEvent(QShowEvent* event) Q_DECL_OVERRIDE;
0126 
0127   bool m_needPluginList;
0128   QString m_originalPluginName;
0129   GUI::CollectionTypeCombo* m_collCombo;
0130   GUI::ComboBox* m_pluginCombo;
0131   QLabel* m_authorLabel;
0132 };
0133 
0134   } // end namespace
0135 } // end namespace
0136 
0137 #endif