PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/flickr.h

http://github.com/sepych/QtFlickr
C Header | 184 lines | 38 code | 14 blank | 132 comment | 0 complexity | 733b413617f1df62a155ea5946f54319 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /******************************************************************************
  2. * Copyright (C) 2009 by Evgeni Gordejev *
  3. * evgeni.gordejev@gmail.com *
  4. * Copyright (C) 2015 by Jacob Dawid *
  5. * jacob@omg-it.works *
  6. * *
  7. * This program is free software; you can redistribute it and/or modify *
  8. * it under the terms of the GNU Library Lesser General Public License as *
  9. * published by the Free Software Foundation; either version 2 of the *
  10. * License, or (at your option) any later version. *
  11. * *
  12. * This program is distributed in the hope that it will be useful, *
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15. * GNU Lesser General Public License for more details. *
  16. * *
  17. * You should have received a copy of the GNU Library Lesser General Public *
  18. * License along with this program; if not, write to the *
  19. * Free Software Foundation, Inc., *
  20. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  21. ******************************************************************************/
  22. #pragma once
  23. // Own includes
  24. #include "flickrerror.h"
  25. #include "flickrmethod.h"
  26. #include "flickrrequest.h"
  27. #include "flickrphoto.h"
  28. #include "flickrtag.h"
  29. #include "flickrresponse.h"
  30. // Qt includes
  31. #include <QtCore>
  32. class FlickrPrivate;
  33. class QNetworkAccessManager;
  34. /**
  35. * @class Flickr
  36. * Main class of Flickr API<br>
  37. * Authorization example:
  38. * @code
  39. * UIClass::UIClass
  40. * {
  41. * qtFlickr = new QtFlickr("xxxxxxxxx", "xxxxxxxxxxxxx", this);
  42. * connect(qtFlickr,SIGNAL(requestFinished(int, QtfResponse, QtfError, void*)),
  43. * this,SLOT(requestFinished(int, QtfResponse, QtfError, void*)));
  44. *
  45. * QtfMethod method;
  46. * method.method = "flickr.auth.getFrob";
  47. *
  48. * QtfRequest request;
  49. * request.requests.insert("frob","");
  50. * frobRequest = qtFlickr->get(method,request);
  51. * }
  52. *
  53. * void UIClass::requestFinished(int reqId, QtfResponse data, QtfError err, void* userData)
  54. * {
  55. * if(err.code != 0){
  56. * if(reqId == frobRequest){
  57. * QString frob = data.tags.value("frob").value;
  58. * QUrl authUrl = qtFlickr->authorizationUrl(frob);
  59. * QDesktopServices::openUrl(authUrl);
  60. *
  61. * QMessageBox msgBox;
  62. * msgBox.setText("Press Ok button when you have completed authorization through web browser")
  63. * int result = msgBox.exec();
  64. * if(result == QDialog::Accepted){
  65. * QtfMethod method;
  66. * method.method = "flickr.auth.getToken";
  67. * method.args.insert("frob", frob);
  68. * QtfRequest request;
  69. * request.requests.insert("token","");
  70. * request.requests.insert("user","username,fullname");
  71. * tokenRequest = qtFlickr->get(method, request);
  72. * }
  73. * }else if(reqId == tokenRequest){
  74. * QString token = data.tags.value("token").value;
  75. * QString username = data.tags.value("user").attrs.value("username");
  76. * QString fullname = data.tags.value("user").attrs.value("fullname");
  77. *
  78. * qDebug()<<"Your username: "<<username;
  79. * qDebug()<<"Your fullname: "<<fullname;
  80. *
  81. * qtFlickr->setToken(token);
  82. * //Now you can call authorized calls with "write" permission
  83. * }
  84. * }else{
  85. * qDebug()<<"Error: "<<err.message;
  86. * }
  87. * }
  88. * @endcode
  89. */
  90. class Flickr : public QObject {
  91. friend class FlickrPrivate;
  92. Q_OBJECT
  93. public:
  94. /**
  95. * Constructor
  96. * @param apiKey Flickr api key
  97. * @param apiSecret Flickr api secret
  98. * @param parent object
  99. * @param nam QNetworkAccessManager instance to use for networking requests
  100. * (If nam is 0 a new instance is created)
  101. */
  102. Flickr(const QString &apiKey,
  103. const QString &apiSecret,
  104. QObject *parent = 0);
  105. ~Flickr();
  106. /**
  107. * Sets token for the QtFlickr API
  108. * @param token
  109. */
  110. void setToken(const QString &token);
  111. /**
  112. * Returns authorization url for give frob
  113. * @param frob
  114. * @param perms "write", "read" or "delete"
  115. */
  116. QUrl authorizationUrl(const QString &frob, const QString &perms = "write");
  117. /**
  118. * Fetches data from Flickr API with GET method
  119. * @param method Flickr API method
  120. * @param request XML request data
  121. * @param userData user data to be transfered through signal/slots mechanism,
  122. * this parametr has no effect on this function
  123. * @return request id
  124. */
  125. int get(const FlickrMethod &method,
  126. const FlickrRequest &request = FlickrRequest(),
  127. void* userData = 0);
  128. /**
  129. * Fetches data from Flickr API with POST method
  130. * @param method Flickr API method
  131. * @param request XML request data
  132. * @param userData user data to be transfered through signal/slots mechanism,
  133. * this parametr has no effect on this function
  134. * @return request id
  135. */
  136. int post(const FlickrMethod &method,
  137. const FlickrRequest &request = FlickrRequest(),
  138. void* userData = 0);
  139. /**
  140. * Uploads or replaces photo
  141. * @param photo to be uploaded
  142. * @param request XML request data
  143. * @param userData user data to be transfered through signal/slots mechanism,
  144. * this parametr has no effect on this function
  145. * @return request id
  146. */
  147. int upload(const FlickrPhoto &photo,
  148. const FlickrRequest &request = FlickrRequest(),
  149. void* userData = 0);
  150. signals:
  151. /**
  152. * Emitted after get(), post() and upload() functions
  153. * @param reqId The request id
  154. * @param data Response XML data
  155. * @param err possible error
  156. * @param userData user data transfered through signal/slots mechanism
  157. */
  158. void requestFinished(int reqId,
  159. FlickrResponse response,
  160. FlickrError err,
  161. void* userData);
  162. /**
  163. * Emitted while photo uploading is in progress
  164. * @param percent 0-100, returns -1 when cannot determine uploading
  165. * progress.
  166. */
  167. void uploadProgress(int percent);
  168. private:
  169. FlickrPrivate * const d;
  170. };