File indexing completed on 2024-05-19 16:31:38
0001 /* 0002 * SPDX-FileCopyrightText: 2017 David Faure <faure@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 #ifndef DICT_OBJECT_H 0007 #define DICT_OBJECT_H 0008 0009 #include "../../dict/dictengine.h" 0010 #include <QObject> 0011 0012 class QQuickWebEngineProfile; 0013 0014 class DictObject : public QObject 0015 { 0016 Q_OBJECT 0017 Q_PROPERTY(QQuickWebEngineProfile *webProfile READ webProfile CONSTANT) 0018 Q_PROPERTY(QString selectedDictionary READ selectedDictionary WRITE setSelectedDictionary) 0019 0020 /** 0021 * @return @c true if there is a network error when finding the definition, 0022 * @c false otherwise. 0023 */ 0024 Q_PROPERTY(bool hasError READ hasError NOTIFY hasErrorChanged) 0025 0026 /** 0027 * @return the type of the last socket error 0028 */ 0029 Q_PROPERTY(QAbstractSocket::SocketError errorCode READ errorCode NOTIFY errorCodeChanged) 0030 0031 /** 0032 * @return a human-readable description of the last socket error 0033 */ 0034 Q_PROPERTY(QString errorString READ errorString NOTIFY errorStringChanged) 0035 0036 public: 0037 explicit DictObject(QObject *parent = nullptr); 0038 0039 QQuickWebEngineProfile *webProfile() const; 0040 0041 QString selectedDictionary() const; 0042 void setSelectedDictionary(const QString &dict); 0043 0044 bool hasError() const; 0045 QAbstractSocket::SocketError errorCode() const; 0046 QString errorString() const; 0047 0048 public Q_SLOTS: 0049 void lookup(const QString &word); 0050 0051 Q_SIGNALS: 0052 void searchInProgress(); 0053 void definitionFound(const QString &html); 0054 0055 void hasErrorChanged(); 0056 void errorCodeChanged(); 0057 void errorStringChanged(); 0058 0059 private Q_SLOTS: 0060 void slotDictErrorOccurred(QAbstractSocket::SocketError socketError, const QString &errorString); 0061 0062 private: 0063 QString m_source; 0064 QString m_dataEngineName; 0065 QString m_selectedDict; 0066 0067 DictEngine m_engine; 0068 QQuickWebEngineProfile *m_webProfile; 0069 0070 bool m_hasError = false; 0071 QAbstractSocket::SocketError m_errorCode = QAbstractSocket::UnknownSocketError; 0072 QString m_errorString; 0073 }; 0074 0075 #endif