This repository has been archived by the owner on Sep 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
ImageShackUploader.hpp
480 lines (411 loc) · 12.7 KB
/
ImageShackUploader.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
/*********************************************************************
* @brief ImageShack Qt lib
*
* An open source Qt lib to upload photos and videos to ImageShack.
* This lib was first created to be plugged on Thumbnail me projet,
* a software generating thumbnails from many types of movies.
*
* @file ImageShackUploader.hpp
* @class ImageShackUploader
* The header of the ImageShackUploader class.
* This class interacts with the application and uploads
* photos and videos to ImageShack web site
*
* @author Christ "Supm4n" Azika-Eros <christ@azika-eros.org>
* @note Copyright (C) 2010-2011 Christ Azika-Eros
* License : Creative Commons GNU GPL
* http://creativecommons.org/licenses/GPL/2.0/
* Web site : http://github.com/Supm4n/ImageShackUploader.git
* @version 0.1
*********************************************************************/
#ifndef HEADER_IMAGESHACKUPLOADER
#define HEADER_IMAGESHACKUPLOADER
#include <QByteArray>
#include <QDebug>
#include <QFile>
#include <QFileInfo>
#include <QHash>
#include <QHashIterator>
#include <QImage>
#include <QMimeData>
#include <QNetworkAccessManager>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QString>
#include <QStringList>
#include <QTimer>
#include <QUrl>
#include <QWidget>
#include "ImageShackError.hpp"
#include "ImageShackObject.hpp"
#include "ImageShackResponse.hpp"
#define TIMEOUT 10000
/**
* @brief ImageShackUploader
*/
class ImageShackUploader : public QObject
{
Q_OBJECT
public : // Public methods
/**
* @brief constructor of ImageShackUploader class
*
* @param developerKey the developer key received by ImageShack to
* use their APIs (optional for the constructor)
* @param userName the user name (optional)
* @param userPassword the user password (optional)
* @param proxy the proxy settings to use (optional)
*/
ImageShackUploader(QString developerKey = "" ,
QNetworkProxy * proxy = NULL );
/**
* @brief destructor of ImageShackUploader class
*/
~ImageShackUploader(void);
/**
* @brief public method uploading a list of images
*
* If uploads are in progress, the signal uploadAlreadyStarted
* is emitted
*
* @see signal uploadAlreadyStarted()
* @see signal authentificationResponse()
* @see signal uploadError(ImageShackError::UploadError)
* @see signal uploadProgress(ImageShackObject ,
* qint64 bytesreceived,
* qint64 bytesTotal )
* @see signal uploadDone(ImageShackResponse)
* @see signal endOfUploads()
* @see signal authentificationRequired(QNetworkReply ,
* QAuthenticator)
* @see signal proxyAuthentificationRequired(QNetworkProxy ,
* QAuthentificator)
*
* @param images images' list to upload
* @param userName the user name (optional)
* @param userPassword the user password (optional)
*/
void uploadImages(QList<ImageShackObject *> images ,
QString userName = "" ,
QString userPassword = "");
/**
* @brief disable the use of the proxy
*
* set proxy attribut to NULL. No proxy will be
* used when uploading files
*/
void noProxy();
/**
* @brief check the user's login and password
*
* @see signal authentificationResponse()
* @param userName the user name
* @param userPassword the user password
*/
void checkUserPassword(QString userName ,
QString userPassword);
signals : // Signals
/**
* @brief this signal is emitted when each image/video is uploaded
*
* return the results of the upload
* @see method ImageShackResponse::getImageShackResponse()
*
* @param uploadResponse the results of the upload
*/
void uploadDone(ImageShackResponse * uploadResponse);
/**
* @brief this signal notifies the end of uploads
*
* it is emitted when the upload of a list of image/video
* submitted is finished
*/
void endOfUploads();
/**
* @brief this signal is emitted when uploads have already started
**/
void uploadAlreadyStarted();
/**
* @brief this signal notifies uploads' progress
*
* @param fileUploaded the being uploaded
* @param bytesReceived number of bytes sent
* @param bytesTotal total bytes to send
*/
void uploadProgress(ImageShackObject * fileUploaded,
qint64 bytesReceived ,
qint64 bytesTotal );
/**
* @brief this signal is emitted when an error occured
* during uploads
*
* @see ImageShackError::UploadError
*
* @param error the error type
*/
void uploadError(ImageShackError::UploadError error);
/**
* @see QNetworkAccessManager signal
*
**/
void authentificationRequired(QNetworkReply * reply ,
QAuthenticator * authentificator);
/**
* @see QNetworkAccessManager signal
*
**/
void proxyAuthentificationRequired(const QNetworkProxy & proxy,
QAuthenticator * authenticator);
/**
* The authentification response
*
**/
void authentificationResponse(bool response);
public slots :
/**
* @brief Aborts uploads
*/
void abortUploads();
private : // Private objects or variables
QList<ImageShackObject *> filesToUpload;
/**
* QString fileBeingUploaded the file being uploading
*
* @access private
**/
ImageShackObject * fileBeingUploaded;
/**
* QString imageUploadUrl The entry point to upload
* images to ImageShack
* @access private
**/
QString imageUploadUrl;
/**
* QString authentificationUrl the url to test the user password
* http://www.imageshack.us/auth.php?username=kwentakill&password=rousseau
*
**/
QString authentificationUrl;
/**
* bool removeInformationBar boolean to leave/remove
* information bar on the thumbnail
* image generated by ImageShack
* @access private
**/
bool removeInformationBar;
/**
* bool uploadsProcessing equals true when a file is being uploaded.
* no upload can start in this case
*
* @access private
**/
bool uploadsProcessing;
/**
* @brief set to true when an error occured.
*
* This is use to not emit multiple signals
*/
bool uploadAborted;
/**
* QNetworkAccessManager networkManager the network manager
*
* @access private
**/
QNetworkAccessManager * networkManager;
/**
* QNetworkProxy the proxy to use when uploading
*
* @access private
**/
QNetworkProxy * proxy;
/**
* QNetworkReply response ImageShack response
*
* @access private
**/
QNetworkReply * networkReply;
/**
* QString developerKey the developer key received
* to use APIs
* @access private
**/
QString developerKey;
/**
* QString lastUserName the user name. Only required to upload
* to a specific account (userUploadImage)
* @access private
**/
QString userName;
/**
* QString userPassword the user name. Only required to upload
* to a specific account (userUploadImage)
* @access private
**/
QString userPassword;
/**
* @brief timer to detect time out processes
*/
QTimer * timeoutTimer;
int nbFilesToUploads;
int nbFilesUploaded;
private slots : // private slots
/**
* Manage replies after the image is uploaded
*
* @access private
**/
void imageUploaded();
/**
* Manage image uploads
*
* @param QString fileUploaded the file uploaded
* @param QHash<QString, QString> informations concerning
* the uploads
* @access private
*/
void manageMultiUploads(ImageShackResponse * uploadResponse);
/**
* manage authentification requirements
*
**/
void manageAuthentificationRequired(QNetworkReply * reply,
QAuthenticator * authentificator);
/**
* manage proxy authentification requirements
*
**/
void manageProxyAuthentificationRequired(const QNetworkProxy & proxy,
QAuthenticator * authenticator);
/**
* manage authentification response
*
**/
void manageAuthentificationResponse();
/**
* Manage upload errors
*
* @access private
**/
void manageUploadError(QNetworkReply::NetworkError errorCode);
/**
* Manage the upload progression
*
* @access private
**/
void manageUploadProgress(qint64 bytesReceived,qint64 bytesTotal);
/**
* @brief slot handling time out
*/
void handleTimeOut();
private : // private methods
/**
* Upload an image to an account
*
* @param QString imagePath the image path
* @param QString tags image tags
* @param QString resizeOption the resize option,
* default value is resample
* @param QString user the user ident
* @param QString password the user password
* @access private
*/
void uploadOneImage(ImageShackObject * image,
QString userName = "" ,
QString userPassword = "");
/**
* Upload an image. This method is called by
* userUploadImage and anonymousUploadImage
* methods
*
* @access private
*/
void sendImage(ImageShackObject * imageToUpload,
QHash<QString, QString> headers );
/**
* Return the mimetype basing on the file extension
*
* @access private
*/
QString mimeType(QString imagePath);
/**
* Return the mimeType list
*
* @access private
*/
QHash<QString, QStringList> mimeTypeList();
public : // Setters and Getters
/**
* the getter of the boolean removeInformationBar
*
* @return removeInformationBar
* @access public
*/
bool getRemoveInformationBar();
/**
* @brief return true if uploads are in progress
*
* @return true/false in uploads are in progress
*/
bool uploadsInProgress();
/**
* the getter of the proxy
*
* @return * QNetworkProxy
* @access public
*/
QNetworkProxy * getProxy();
/**
* the getter of developerKey
*
* @return developerKey
* @access public
*/
QString getDeveloperKey();
/**
* the getter of imageUploadUrl
*
* @return developerKey
* @access public
*/
QString getImageUploadUrl();
/**
* the getter of userName
*
* @return developerKey
* @access public
*/
QString getLastUserName();
/**
* the setter of developerKey
*
* @param developerKey the developer key needed to upload
* to unified ImageShack API
* @access public
*/
void setDeveloperKey(QString developerKey);
/**
* the setter of imageUploadUrl
*
* @param developerKey The entry point to upload
* images to ImageShack
* @access public
*/
void setImageUploadUrl(QString imageUploadUrl);
/**
* the setter of the proxy use to upload
*
* @param QNetworkProxy the proxy to use
* @access public
*/
void setProxy(QNetworkProxy * proxy);
/**
* the setter of imageEntryUpload
*
* @param removeInformationBar the boolean to remove/leave
* the information bar from
* thumbnails
* @access public
*/
void setRemoveInformationBar(bool removeInformationBar);
};
#endif // HEADER_IMAGESHACKUPLOADER