-
Notifications
You must be signed in to change notification settings - Fork 4
/
reverseimagesearch.h
53 lines (41 loc) · 1.41 KB
/
reverseimagesearch.h
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
45
46
47
48
49
50
51
52
53
#ifndef REVERSEIMAGESEARCH_H
#define REVERSEIMAGESEARCH_H
#include "imageitem.h"
#include <QObject>
#include <QNetworkAccessManager>
#include <curl/curl.h>
#define C_RIS_URL "http://www.google.co.in/searchbyimage/upload" ///< URL for image upload
/**
* @brief The ReverseImageSearch class
*
* Reverse image search is a service offered by Google. You upload an image to the
* server (\ref C_RIS_SearchURL) and it returns a token which you use to query google
* again in order to get the search result.
*/
typedef struct
{
void *memory;
size_t size;
} T_RIS_Memory;
class ReverseImageSearch : public QObject
{
Q_OBJECT
public:
explicit ReverseImageSearch(QObject *parent = nullptr);
~ReverseImageSearch();
QString prepareImageSearch(ImageItem item, QString baseDir); ///< Create image upload
void getResult(QString url);
public slots:
void slotRequestFinished(QNetworkReply *reply);
void slotFinishedGet(void);
private:
bool isRedirected(QNetworkReply *reply); ///< check whether we got a 302 moved answer
QString getRedirectUrl(QString html); ///< get the redirection url from the response
QString copyImageToTemp(ImageItem item, QString baseDir);
CURL *m_curl;
QNetworkAccessManager m_manager;
T_RIS_Memory m_chunk;
QNetworkReply *reply;
};
extern QString G_response;
#endif // REVERSEIMAGESEARCH_H