1 /*************************************************************************** 2 Copyright (C) 2005-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_EXECEXTERNALFETCHER_H 26 #define TELLICO_EXECEXTERNALFETCHER_H 27 28 #include "fetcher.h" 29 #include "configwidget.h" 30 31 #include <QHash> 32 #include <QPointer> 33 34 class KProcess; 35 class KUrlRequester; 36 class KComboBox; 37 class KConfig; 38 39 class QCheckBox; 40 class QLineEdit; 41 42 namespace Tellico { 43 namespace GUI { 44 class ComboBox; 45 class LineEdit; 46 class CollectionTypeCombo; 47 } 48 namespace Fetch { 49 50 /** 51 * @author Robby Stephenson 52 */ 53 class ExecExternalFetcher : public Fetcher { 54 Q_OBJECT 55 56 public: 57 ExecExternalFetcher(QObject* parent); 58 /** 59 */ 60 virtual ~ExecExternalFetcher(); 61 62 virtual QString source() const Q_DECL_OVERRIDE; isSearching()63 virtual bool isSearching() const Q_DECL_OVERRIDE { return m_started; } 64 virtual bool canSearch(FetchKey k) const Q_DECL_OVERRIDE; canUpdate()65 virtual bool canUpdate() const Q_DECL_OVERRIDE { return m_canUpdate; } 66 virtual void stop() Q_DECL_OVERRIDE; 67 virtual Data::EntryPtr fetchEntryHook(uint uid) Q_DECL_OVERRIDE; type()68 virtual Type type() const Q_DECL_OVERRIDE { return ExecExternal; } 69 virtual bool canFetch(int type) const Q_DECL_OVERRIDE; 70 virtual void readConfigHook(const KConfigGroup& config) Q_DECL_OVERRIDE; 71 virtual Fetch::ConfigWidget* configWidget(QWidget* parent) const Q_DECL_OVERRIDE; 72 execPath()73 const QString& execPath() const { return m_path; } 74 75 class ConfigWidget : public Fetch::ConfigWidget { 76 public: 77 explicit ConfigWidget(QWidget* parent = nullptr, const ExecExternalFetcher* fetcher = nullptr); 78 ~ConfigWidget(); 79 80 void readConfig(const KConfigGroup& config) Q_DECL_OVERRIDE; 81 virtual void saveConfigHook(KConfigGroup& config) Q_DECL_OVERRIDE; 82 virtual void removed() Q_DECL_OVERRIDE; 83 virtual QString preferredName() const Q_DECL_OVERRIDE; 84 85 private: 86 bool m_deleteOnRemove : 1; 87 QString m_name, m_newStuffName; 88 KUrlRequester* m_pathEdit; 89 GUI::CollectionTypeCombo* m_collCombo; 90 GUI::ComboBox* m_formatCombo; 91 QHash<int, QCheckBox*> m_cbDict; 92 QHash<int, GUI::LineEdit*> m_leDict; 93 QCheckBox* m_cbUpdate; 94 GUI::LineEdit* m_leUpdate; 95 }; 96 friend class ConfigWidget; 97 98 static QString defaultName(); 99 static QString defaultIcon(); allOptionalFields()100 static StringHash allOptionalFields() { return StringHash(); } 101 102 private Q_SLOTS: 103 void slotData(); 104 void slotError(); 105 void slotProcessExited(); 106 107 private: 108 static QStringList parseArguments(const QString& str); 109 110 virtual void search() Q_DECL_OVERRIDE; 111 virtual FetchRequest updateRequest(Data::EntryPtr entry) Q_DECL_OVERRIDE; 112 void startSearch(const QStringList& args); 113 114 bool m_started; 115 int m_collType; 116 int m_formatType; 117 QString m_path; 118 QHash<FetchKey, QString> m_args; 119 bool m_canUpdate : 1; 120 QString m_updateArgs; 121 QPointer<KProcess> m_process; 122 QByteArray m_data; 123 QHash<uint, Data::EntryPtr> m_entries; // map from search result id to entry 124 QStringList m_errors; 125 bool m_deleteOnRemove : 1; 126 QString m_newStuffName; 127 }; 128 129 } // end namespace 130 } // end namespace 131 132 #endif 133