forked from Kernald/redmine-qt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRedmineClient.hpp
167 lines (137 loc) · 4.78 KB
/
RedmineClient.hpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#ifndef __REDMINE_CLIENT_HPP__
#define __REDMINE_CLIENT_HPP__
/* CALLBACK_T */
#define CALLBACK_DISPATCHER(fromClass, toClass, thisptr) \
public: \
typedef void (toClass::*callback_t)(QNetworkReply *reply, QJsonDocument *data, void *);\
\
private: \
fromClass::callback_t operator = (toClass::callback_t & callback) { \
return reinterpret_cast <fromClass::callback_t &> (callback); \
} \
\
Q_SLOT void callback_dispatcher( \
void *obj_ptr, \
callback_t callback, \
QNetworkReply *reply, \
QJsonDocument *data, \
void *argument) \
{ \
/*qDebug("callback_dispatcher: %p %p", this, obj_ptr);*/ \
if (obj_ptr == thisptr)\
(this->*callback)(reply, data, argument);\
else \
callback_call(obj_ptr, callback, reply, data, argument);\
} \
\
Q_SIGNAL void callback_call( \
void *obj_ptr, \
callback_t callback, \
QNetworkReply *reply, \
QJsonDocument *data, \
void *argument);
/* /CALLBACK_DISPATCHER */
class IAuthenticator;
class QNetworkAccessManager;
#include "redmine-qt_global.hpp"
#if _MSC_VER && !__INTEL_COMPILER
#pragma pointers_to_members( full_generality, virtual_inheritance )
#endif
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QUrl>
#include <QHash>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QVariant>
#include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkReply>
typedef void ( *funct_callback_json ) ( void *, QNetworkReply *, QJsonDocument * );
//typedef void (*funct_callback_xml)(void *, QNetworkReply *, QXML *);
/* Base management class.
*
* Handles the connexions to a Redmine instance.
*/
class REDMINEQTSHARED_EXPORT RedmineClient : public QObject
{
Q_OBJECT
public:
typedef void ( RedmineClient::*callback_t ) ( QNetworkReply *reply, QJsonDocument *data, void * );
enum EMode {
GET,
POST,
PUT,
DELETE
};
enum EFormat {
JSON,
XML
};
/* Creates a non-configured client.
*/
RedmineClient();
RedmineClient ( QString base_url );
/* Sets base url (to root URI of redmine site)
*/
void setBaseUrl ( QString base_url );
void setBaseUrl ( const char *base_url );
/* Gets previously set base url (to the root URL of redmine site)
*/
QString getBaseUrl();
/* Set authentification parameters in case of non-configured client
*/
void setAuth ( QString apiKey );
void setAuth ( QString login, QString password );
/* Creates a client using an API key authenticator.
*/
RedmineClient ( QString base_url, QString apiKey, bool checkSsl = true, QObject* parent = NULL );
/* Creates a client using a login/password authenticator.
*/
RedmineClient ( QString base_url, QString login, QString password, bool checkSsl = true, QObject* parent = NULL );
virtual ~RedmineClient();
/* Defines the user agent for the client.
*/
void setUserAgent ( QByteArray ua );
void getIssues (
QUrl url,
void *callback = NULL,
void *callback_arg = NULL,
QString filters = "" );
protected:
/* Sends a request to the Redmine endpoint.
*/
QNetworkReply *sendRequest ( QString uri,
EFormat format = JSON,
EMode mode = GET,
void *obj_ptr = NULL,
callback_t callback = NULL,
void *callback_arg = NULL,
bool free_arg = false,
const QString &getParams = "",
const QByteArray &requestData = "" );
private slots:
void requestFinished_wrapper ( QNetworkReply *reply );
private:
/* Commont initialization steps.
*
* Creates the network access manager.
*/
void init();
bool checkUrl ( const QUrl &url );
struct callback {
void *obj_ptr;
callback_t funct;
void *arg;
bool free_arg;
RedmineClient::EFormat format;
};
QString _base_url;
IAuthenticator* _authenticator = NULL;
QNetworkAccessManager* _nma = NULL;
QHash<QNetworkReply *, struct callback> _callbacks;
QByteArray _ua;
signals:
void requestFinished ( void *obj_ptr, callback_t callback, QNetworkReply *reply, QJsonDocument *data, void * );
};
#endif // __REDMINE_CLIENT_HPP__