1 /*********************************************************************** 2 * 3 * Copyright (C) 2009, 2013, 2014 Graeme Gott <graeme@gottcode.org> 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 ***********************************************************************/ 19 20 #ifndef DICTIONARY_H 21 #define DICTIONARY_H 22 23 class WordList; 24 25 #include <QHash> 26 #include <QObject> 27 #include <QUrl> 28 #include <QUrlQuery> 29 class QNetworkAccessManager; 30 class QNetworkReply; 31 32 class Dictionary : public QObject { 33 Q_OBJECT 34 35 public: 36 Dictionary(const WordList* wordlist, QObject* parent = 0); 37 url()38 QUrl url() const { 39 return m_url; 40 } 41 42 signals: 43 void wordDefined(const QString& word, const QString& definition); 44 45 public slots: 46 void lookup(const QString& word); 47 void wait(); 48 49 private slots: 50 void lookupFinished(QNetworkReply* reply); 51 void setLanguage(const QString& langcode); 52 53 private: 54 const WordList* m_wordlist; 55 QUrl m_url; 56 QUrlQuery m_query; 57 QNetworkAccessManager* m_manager; 58 QHash<QNetworkReply*, QString> m_reply_details; 59 QHash<QString, QString> m_spellings; 60 QHash<QString, QString> m_definitions; 61 QString m_cache_path; 62 }; 63 64 #endif 65