Verified Commit 6c88a6fa authored by Fushan Wen's avatar Fushan Wen
Browse files

dict: Add `dictLoadingChanged` signal to indicate the downloading status

parent 528c551b
......@@ -174,6 +174,7 @@ void DictEngine::getDicts()
m_tcpSocket->disconnectFromHost();
m_availableDictsCache.insert(m_serverName, availableDicts);
Q_EMIT dictsRecieved(availableDicts);
Q_EMIT dictLoadingChanged(false);
}
void DictEngine::requestDicts()
......@@ -188,11 +189,13 @@ void DictEngine::requestDicts()
m_tcpSocket = nullptr;
}
Q_EMIT dictLoadingChanged(true);
m_tcpSocket = new QTcpSocket(this);
connect(m_tcpSocket, &QTcpSocket::disconnected, this, &DictEngine::socketClosed);
connect(m_tcpSocket, &QTcpSocket::readyRead, this, &DictEngine::getDicts);
m_tcpSocket->connectToHost(m_serverName, 2628);
}
void DictEngine::requestDefinition(const QString &query)
{
if (m_tcpSocket) {
......@@ -233,6 +236,8 @@ void DictEngine::requestDefinition(const QString &query)
void DictEngine::socketClosed()
{
Q_EMIT dictLoadingChanged(false);
if (m_tcpSocket) {
m_tcpSocket->deleteLater();
}
......
......@@ -27,8 +27,15 @@ public:
~DictEngine() override;
Q_SIGNALS:
/**
* @param loading @c true if the dict finder is downloading dict list from
* the Internet, @c false otherwise.
*/
void dictLoadingChanged(bool loading);
void dictsRecieved(const QMap<QString, QString> &dicts);
void definitionRecieved(const QString &html);
public Q_SLOTS:
void requestDicts();
void requestDefinition(const QString &query);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment