cmdmanager.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #ifndef CMDMANAGER_H
  2. #define CMDMANAGER_H
  3. #include "qmlhandler.h"
  4. #include <json/json.h>
  5. #include <map>
  6. #include <string>
  7. #include <vector>
  8. /**
  9. * The struct for a file entry in the GUI file list
  10. */
  11. struct fileEntry {
  12. bool dirty;
  13. std::string type;
  14. std::string method;
  15. int progress;
  16. float speed;
  17. };
  18. /**
  19. * Namespace which handles the commands received from the CLI
  20. */
  21. namespace CmdManager {
  22. /**
  23. * Initialize the cmdmap with the references to the according methods
  24. */
  25. void init();
  26. /**
  27. * Set the qml handler pointer
  28. * @param q The reference to the qml handler
  29. */
  30. void setQmlHandler(QMLHandler *q);
  31. /**
  32. * Update a file in the file map
  33. * @param name The name of the file
  34. * @param type The new type of the file
  35. * @param method The new method of the file
  36. * @param progress The new progress of the file
  37. * @param speed The new speed of the file
  38. */
  39. void updateInternalFile(std::string name, std::string type, std::string method, int progress, float speed);
  40. /**
  41. * Update the GUI file list to match the file map
  42. */
  43. void emitFileList();
  44. /**
  45. * Clear the file map
  46. */
  47. void cleanInternalList();
  48. /**
  49. * Execute a command received from the CLI
  50. * @param cmd The command to be executed using the cmdmap
  51. * @param root The entire JSON value
  52. */
  53. void executeCmd(std::string cmd, Json::Value root);
  54. /**
  55. * Sets the cached ip address
  56. * @param ip The ip address
  57. */
  58. void setCachedIP(QString ip);
  59. /**
  60. * Sets the cached port
  61. * @param port The port
  62. */
  63. void setCachedPort(QString port);
  64. /**
  65. * Handle the error command
  66. *
  67. * Print the error in the log
  68. * @param root The entire JSON value
  69. */
  70. void handleError(Json::Value root);
  71. /**
  72. * Handle the status command
  73. *
  74. * Update the status text in the GUI
  75. * @param root The entire JSON value
  76. */
  77. void handleStatus(Json::Value root);
  78. /**
  79. * Handle the close command
  80. *
  81. * Set the program as inactive to stop the CLI background threads
  82. * @param root The entire JSON value
  83. */
  84. void handleClose(Json::Value root);
  85. /**
  86. * Handle the list command
  87. *
  88. * List the server files in the GUI
  89. * @param root The entire JSON value
  90. */
  91. void handleList(Json::Value root);
  92. /**
  93. * Handle the extendedlist command
  94. *
  95. * List the server files in the GUI with detailed information
  96. * @param root The entire JSON value
  97. */
  98. void handleExtendedList(Json::Value root);
  99. /**
  100. * Handle the connect command
  101. *
  102. * If there was an error, reactivate the connect button and show the error
  103. * @param root The entire JSON value
  104. */
  105. void handleConnect(Json::Value root);
  106. /**
  107. * Handle the version command
  108. *
  109. * Close the ip popup and open the login/signup popup if it was accepted, else reactivate the connect button and show the error
  110. * @param root The entire JSON value
  111. */
  112. void handleVersion(Json::Value root);
  113. /**
  114. * Handle the login command
  115. *
  116. * Set the loggedin value to true and close the popup if it was accepted, else reactivate the login button and show the error
  117. * @param root The entire JSON value
  118. */
  119. void handleLogin(Json::Value root);
  120. /**
  121. * Handle the signup command
  122. *
  123. * Set the loggedin value to true and close the popup if it was accepted, else reactivate the signup button and show the error
  124. * @param root The entire JSON value
  125. */
  126. void handleSignup(Json::Value root);
  127. /**
  128. * Handle the put command
  129. *
  130. * Show an error if it was not accepted
  131. * @param root The entire JSON value
  132. */
  133. void handlePut(Json::Value root);
  134. /**
  135. * Handle the putdata command
  136. *
  137. * Show an error if it was not accepted
  138. * @param root The entire JSON value
  139. */
  140. void handlePutData(Json::Value root);
  141. /**
  142. * Handle the get command
  143. *
  144. * Show an error if it was not accepted, else disable the file's download button
  145. * @param root The entire JSON value
  146. */
  147. void handleGet(Json::Value root);
  148. /**
  149. * Handle the getdata command
  150. *
  151. * Show an error if it was not accepted
  152. * @param root The entire JSON value
  153. */
  154. void handleGetData(Json::Value root);
  155. /**
  156. * Handle the deleteme command
  157. *
  158. * Show an error if it was not accepted, else disconnect from the server and restart the application
  159. * @param root The entire JSON value
  160. */
  161. void handleDeleteMe(Json::Value root);
  162. /**
  163. * Handle the deletefile command
  164. *
  165. * Show an error if it was not accepted, else show the confirmation in the log
  166. * @param root The entire JSON value
  167. */
  168. void handleDeleteFile(Json::Value root);
  169. /**
  170. * Handle the notifications command
  171. *
  172. * Show an error if it was not accepted, else handle the new notifications if there are some
  173. * @param root The entire JSON value
  174. */
  175. void handleNotifications(Json::Value root);
  176. /**
  177. * Handle the queue command
  178. *
  179. * Show an error if it was not accepted
  180. * @param root The entire JSON value
  181. */
  182. void handleQueue(Json::Value root);
  183. /**
  184. * Handle the dequeue command
  185. *
  186. * Show an error if it was not accepted
  187. * @param root The entire JSON value
  188. */
  189. void handleDequeue(Json::Value root);
  190. /**
  191. * Handle the extendedstatus command
  192. *
  193. * Show an error if it was not accepted, else update the file list with the new data
  194. * @param root The entire JSON value
  195. */
  196. void handleExtendedStatus(Json::Value root);
  197. /**
  198. * Handle the keyfile command
  199. *
  200. * Show an error if it was not accepted, else update the keyfile status in the settings tab
  201. * @param root The entire JSON value
  202. */
  203. void handleKeyfile(Json::Value root);
  204. /**
  205. * Handle the closekey command
  206. *
  207. * Show an error if it was not accepted, else update the keyfile status in the settings tab
  208. * @param root The entire JSON value
  209. */
  210. void handleClosekey(Json::Value root);
  211. /**
  212. * Handle the disconnect command
  213. *
  214. * Set the loggedin variable to false to stop the background CLI threads if it was accepted
  215. * @param root The entire JSON value
  216. */
  217. void handleDisconnect(Json::Value root);
  218. /**
  219. * Handle the connectionerror command
  220. *
  221. * Sets the footer error to encourage the user to restart the application on a lost connection
  222. * @param root The entire JSON value
  223. */
  224. void handleConnectionError(Json::Value root);
  225. } // namespace CmdManager
  226. #endif // CMDMANAGER_H