-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathayikweb.cpp
44 lines (37 loc) · 1.41 KB
/
ayikweb.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "ayikweb.h"
#include "dictutil.h"
AyikWeb::AyikWeb(QObject *parent) : QObject(parent)
{
networkAccessManager = new QNetworkAccessManager(this);
connect(networkAccessManager, &QNetworkAccessManager::finished, this, &AyikWeb::onFinished);
}
QString AyikWeb::getLastWordMeaning()
{
return lastWordMeaning;
}
//TODO add other methods/sources to lookup and make it configurable
void AyikWeb::lookupWordMeaning(AyikWord ayikWord) {
lookupWordMeaningFromSeslisozluk(ayikWord);
}
void AyikWeb::lookupWordMeaningFromSeslisozluk(AyikWord ayikWord) {
QUrl url("https://www.seslisozluk.net/"+ayikWord.getName()+"-nedir-ne-demek/");
QNetworkRequest request;
request.setUrl(url);
// Optionally, configure SSL (e.g., disable certificate validation)
QSslConfiguration sslConfig = request.sslConfiguration();
sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone);
request.setSslConfiguration(sslConfig);
// Send the request - will callback when finished
networkAccessManager->get(request);
}
void AyikWeb::onFinished(QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
lastHttpResponse = reply->readAll();
qDebug() << "Response:" << lastHttpResponse;
lastWordMeaning = DictUtil::parseSeslisozluk(lastHttpResponse);
emit lookupDone();
} else {
qDebug() << "Error:" << reply->errorString();
}
reply->deleteLater();
}