redmine.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #ifndef REDMINE_H
  2. #define REDMINE_H
  3. #include <RedmineClient.hpp>
  4. #include <QEventLoop>
  5. #define REDMINE_BASETIMEOUT 5000
  6. class Redmine : public RedmineClient
  7. {
  8. Q_OBJECT
  9. CALLBACK_DISPATCHER ( RedmineClient, Redmine, this )
  10. private:
  11. QString _apiKey;
  12. QHash <int, QJsonDocument> users;
  13. QHash <int, QJsonObject> issue_statuses;
  14. void set_issue_status ( int status_id, QJsonObject status );
  15. void clear_issue_status();
  16. // Callbacks:
  17. void updateIssueStatuses_callback ( QNetworkReply *reply,
  18. QJsonDocument *statuses,
  19. void *_arg );
  20. void get_user_callback ( QNetworkReply *reply,
  21. QJsonDocument *user_doc,
  22. void *_arg );
  23. QEventLoop initBarrier;
  24. int initBarrier_jobsDone;
  25. QNetworkReply *updateMe ( callback_t callback = NULL, void *arg = NULL );
  26. QNetworkReply *updateMyProject ( callback_t callback = NULL, void *arg = NULL );
  27. QNetworkReply *updateIssueStatuses ( Redmine::callback_t callback = NULL, void *arg = NULL );
  28. QJsonObject _me;
  29. QJsonObject _myProject;
  30. void updateMe_callback ( QNetworkReply *reply, QJsonDocument *me_doc, void *_arg );
  31. void updateMyProject_callback ( QNetworkReply *reply, QJsonDocument *myProject_doc, void *_arg );
  32. /*
  33. void init_quitStatuses (QNetworkReply *reply, QJsonDocument *statuses, void *_null);
  34. void init_quitMe (QNetworkReply *reply, QJsonDocument *me, void *_null);
  35. void init_quitMyProject(QNetworkReply *reply, QJsonDocument *myProject, void *_null);
  36. */
  37. QHash<QString, QJsonDocument> cache;
  38. void callback_cache ( QNetworkReply *reply, QJsonDocument *obj, void *_real_callback_info );
  39. QString cacheBasePath;
  40. public:
  41. QString apiKey ( QString apiKey );
  42. QString apiKey();
  43. int init();
  44. /* Request anything by URI
  45. */
  46. QNetworkReply *request ( RedmineClient::EMode mode,
  47. QString uri,
  48. void *obj_ptr,
  49. callback_t callback,
  50. void *callback_arg = NULL,
  51. bool free_arg = false,
  52. const QString &getParams = "",
  53. const QByteArray &requestData = "",
  54. bool useCache = true );
  55. QNetworkReply *request ( RedmineClient::EMode mode,
  56. QString uri,
  57. void *obj_ptr,
  58. callback_t callback,
  59. void *callback_arg,
  60. bool free_arg,
  61. const QString &getParams,
  62. const QJsonObject &requestJSON );
  63. QNetworkReply *request ( RedmineClient::EMode mode,
  64. QString uri,
  65. void *obj_ptr,
  66. callback_t callback,
  67. void *callback_arg,
  68. bool free_arg,
  69. const QString &getParams,
  70. const QVariantMap &requestVMap );
  71. /* Get information about current user
  72. */
  73. QJsonObject me()
  74. {
  75. return _me;
  76. }
  77. QJsonObject myProject()
  78. {
  79. return _myProject;
  80. }
  81. /* Request all roles
  82. */
  83. QNetworkReply *get_roles ( callback_t callback, void *arg = NULL, bool free_arg = false );
  84. /* Request all issues
  85. */
  86. QNetworkReply *get_issues ( callback_t callback, void *arg = NULL, bool free_arg = false, QString customFilters = "" );
  87. QNetworkReply *get_issues ( void *obj_ptr, callback_t callback, void *arg = NULL, bool free_arg = false, QString customFilters = "" );
  88. /* Request all projects
  89. */
  90. QNetworkReply *get_projects ( callback_t callback, void *arg = NULL, bool free_arg = false, QString filterOptions = "" );
  91. QNetworkReply *get_projects ( void *obj_ptr, callback_t callback, void *arg = NULL, bool free_arg = false, QString filterOptions = "" );
  92. /* Request all memberships
  93. */
  94. QNetworkReply *get_memberships ( callback_t callback, void *arg = NULL, bool free_arg = false );
  95. /* Request all field values enumerations
  96. */
  97. QNetworkReply *get_enumerations ( callback_t callback, void *arg = NULL, bool free_arg = false );
  98. /* Request all issues
  99. */
  100. QNetworkReply *get_time_entries ( int userId, void *obj_ptr, callback_t callback, void *arg = NULL, bool free_arg = false, QString filterOptions = "" );
  101. QNetworkReply *get_time_entries ( void *obj_ptr, callback_t callback, void *arg = NULL, bool free_arg = false, QString filterOptions = "" );
  102. QNetworkReply *get_time_entries ( callback_t callback, void *arg = NULL, bool free_arg = false, QString filterOptions = "" );
  103. /* Get issue status info
  104. */
  105. QJsonObject get_issue_status ( int issue_status_id );
  106. QJsonObject get_issue_status ( QJsonValueRef issues_status_json );
  107. QHash<int, QJsonObject> get_available_statuses_for ( int issue_id );
  108. /* Request user info (with caching). If 2nd argument to callback function
  109. * is NULL then a cached value is passed.
  110. */
  111. QNetworkReply *get_user ( int user_id,
  112. callback_t callback,
  113. void *arg = NULL );
  114. /* Request stuffToDo index info of user with ID "user_id".
  115. * Set "user_id" to zero to get info for current user.
  116. *
  117. * Related to plugin: https://github.com/mephi-ut/stuff_to_do_plugin
  118. */
  119. QNetworkReply *get_stuff_to_do ( void *obj_ptr, callback_t callback,
  120. int user_id = 0,
  121. void *arg = NULL, bool free_arg = false,
  122. QString filterOptions = "" );
  123. /* Parses JSON values like "2015-03-13T21:34:28.000+03:00" to QDateTime
  124. */
  125. QDateTime parseDateTime ( QJsonValueRef dateTime_json );
  126. QDateTime parseDateTime ( QString dateTime_str );
  127. /* Load prevously saved cache into memory (disk -> mem)
  128. */
  129. void cacheLoad();
  130. /* Save cache into disk (mem -> disk)
  131. */
  132. void cacheSave();
  133. /*
  134. */
  135. QUrl getUrl ( QString objectType, int objectId );
  136. /* Constructor/destructor
  137. */
  138. Redmine();
  139. ~Redmine();
  140. };
  141. #endif // REDMINE_H