2024-07-25 10:04:47 -04:00
|
|
|
#ifndef BRAVESEARCH_H
|
|
|
|
#define BRAVESEARCH_H
|
|
|
|
|
2024-07-31 14:54:38 -04:00
|
|
|
#include "tool.h"
|
2024-07-25 10:04:47 -04:00
|
|
|
|
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
#include <QNetworkAccessManager>
|
|
|
|
#include <QNetworkReply>
|
|
|
|
|
|
|
|
class BraveAPIWorker : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
BraveAPIWorker()
|
|
|
|
: QObject(nullptr)
|
2024-07-31 22:46:30 -04:00
|
|
|
, m_networkManager(nullptr) {}
|
2024-07-25 10:04:47 -04:00
|
|
|
virtual ~BraveAPIWorker() {}
|
|
|
|
|
2024-07-31 14:54:38 -04:00
|
|
|
QString response() const { return m_response; }
|
2024-08-07 10:44:52 -04:00
|
|
|
ToolEnums::Error error() const { return m_error; }
|
|
|
|
QString errorString() const { return m_errorString; }
|
2024-07-25 10:04:47 -04:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2024-07-31 22:46:30 -04:00
|
|
|
void request(const QString &apiKey, const QString &query, int count);
|
2024-07-25 10:04:47 -04:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
void finished();
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
2024-08-07 10:44:52 -04:00
|
|
|
QString cleanBraveResponse(const QByteArray& jsonResponse);
|
2024-07-25 10:04:47 -04:00
|
|
|
void handleFinished();
|
|
|
|
void handleErrorOccurred(QNetworkReply::NetworkError code);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QNetworkAccessManager *m_networkManager;
|
2024-07-31 14:54:38 -04:00
|
|
|
QString m_response;
|
2024-08-07 10:44:52 -04:00
|
|
|
ToolEnums::Error m_error;
|
|
|
|
QString m_errorString;
|
2024-07-25 10:04:47 -04:00
|
|
|
};
|
|
|
|
|
2024-07-31 14:54:38 -04:00
|
|
|
class BraveSearch : public Tool {
|
2024-07-25 10:04:47 -04:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-08-07 10:44:52 -04:00
|
|
|
BraveSearch() : Tool(), m_error(ToolEnums::Error::NoError) {}
|
2024-07-25 10:04:47 -04:00
|
|
|
virtual ~BraveSearch() {}
|
|
|
|
|
2024-07-31 14:54:38 -04:00
|
|
|
QString run(const QJsonObject ¶meters, qint64 timeout = 2000) override;
|
2024-08-07 10:44:52 -04:00
|
|
|
ToolEnums::Error error() const override { return m_error; }
|
|
|
|
QString errorString() const override { return m_errorString; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ToolEnums::Error m_error;
|
|
|
|
QString m_errorString;
|
2024-07-25 10:04:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BRAVESEARCH_H
|