qmlhandler.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. #ifndef QMLHANDLER_H
  2. #define QMLHANDLER_H
  3. #include <QObject>
  4. #include <QUrl>
  5. extern bool _RESTART;
  6. /**
  7. * @class QMLHandler
  8. *
  9. * This class is the connection between Qml and C++, where signals can be emitted using code to interact with the forms
  10. * and slots can be used to run code from a Qml form.
  11. */
  12. class QMLHandler : public QObject {
  13. Q_OBJECT
  14. public:
  15. /**
  16. * This class
  17. */
  18. explicit QMLHandler(QObject *parent = 0);
  19. /**
  20. * Handle the closing of the main window
  21. */
  22. void onExit();
  23. /**
  24. * Get the settings from the config class and adjust the gui settings accordingly
  25. */
  26. void loadSettingsToGUI();
  27. /**
  28. * Set the _RESTART variable
  29. * @param restart The new value
  30. */
  31. void setRestart(bool restart);
  32. /**
  33. * Set the configExists variable
  34. * @param exists The new value
  35. */
  36. void setConfigExists(bool exists);
  37. // C++ -> QML
  38. signals:
  39. // No Config Found Popup
  40. /**
  41. * Open the popup for when no config has been found
  42. */
  43. void noConfigFoundPopupOpen();
  44. /**
  45. * Close the popup for when no config has been found
  46. */
  47. void noConfigFoundPopupClose();
  48. // Invalid Cli Path Popup
  49. /**
  50. * Open the popup for when the cli path is not valid
  51. */
  52. void invalidCliPathPopupOpen();
  53. /**
  54. * Close the popup for when the cli path is not valid
  55. */
  56. void invalidCliPathPopupClose();
  57. // Invalid Config Popup
  58. /**
  59. * Open the popup for when the config is invalid
  60. */
  61. void invalidConfigPopupOpen();
  62. /**
  63. * Close the popup for when the config is invalid
  64. */
  65. void invalidConfigPopupClose();
  66. // Server Files
  67. /**
  68. * Set the text that shows the selected file to be uploaded
  69. * @param signalText The new file url
  70. */
  71. void serverFilesSetFileUrlText(QString signalText);
  72. /**
  73. * Enable the Upload File button
  74. */
  75. void serverFilesEnableSendButton();
  76. /**
  77. * Disable the Upload File button
  78. */
  79. void serverFilesDisableSendButton();
  80. /**
  81. * Clear the list of files that are on the server
  82. */
  83. void serverFilesClearFileList();
  84. /**
  85. * List a new file in the file list
  86. * @param fileName The name of the file
  87. * @param fileSize The size of the file
  88. * @param fileDecryptable Is the file decryptable for the current user?
  89. * @param existsLocally Is the file already downloaded?
  90. */
  91. void serverFilesListFile(QString fileName, QString fileSize, QString fileDecryptable, bool existsLocally);
  92. /**
  93. * Update an existing file in the file list
  94. * @param fileName The name of the file
  95. * @param fileProgress The download or upload progress of the file
  96. * @param isQueued Is the file queued on the server?
  97. */
  98. void serverFilesUpdateFile(QString fileName, QString fileProgress, bool isQueued);
  99. /**
  100. * Disable the download button for a specific file
  101. * @param The name of the file
  102. */
  103. void serverFilesDisableDownloadButton(QString fileName);
  104. /**
  105. * Close the delete popup for a file
  106. */
  107. void serverFilesCloseConfirmDeletePopup();
  108. // Settings
  109. /**
  110. * Close the main window
  111. */
  112. void closeWindow();
  113. /**
  114. * Load the settings to the GUI
  115. * @param saveIP Should the autofill ip toggle be switched on or off?
  116. * @param saveUsername Should the autofill username toggle be switched on or off?
  117. * @param cliPath The path to the cli
  118. * @param keyPath The path to the keyfile
  119. */
  120. void loadSettings(bool saveIP, bool saveUsername, QString cliPath, QString keyPath);
  121. /**
  122. * Update the status of the keyfile
  123. * @param success Has the keyfile successfully been loaded?
  124. * @param msg The message to be shown
  125. */
  126. void keyfileStatus(bool success, QString msg);
  127. /**
  128. * Signal for when the keyfile has been successfully closed and should be shown in the settings
  129. */
  130. void keyfileClosedOK();
  131. // Delete Me Popup
  132. /**
  133. * Set the status on the delete me popup (when a user want's to delete their acccount)
  134. * @param status The status message
  135. */
  136. void deleteMePopupSetStatus(QString status);
  137. // Ip Popup
  138. /**
  139. * Set the status on the ip popup
  140. * @param status The status messsage
  141. */
  142. void ipPopupSetStatus(QString status);
  143. /**
  144. * Set the ip address in the ip input field (used for autofill ip)
  145. * @param default_ip The ip address
  146. */
  147. void ipPopupSetIP(QString default_ip);
  148. /**
  149. * Close the ip popup
  150. */
  151. void ipPopupClose();
  152. /**
  153. * Open the ip popup
  154. */
  155. void ipPopupOpen();
  156. /**
  157. * Enable the connect button in the ip popup
  158. */
  159. void ipPopupEnableConnectButton();
  160. /**
  161. * Disbale the connect button in the ip popup
  162. */
  163. void ipPopupDisableConnectButton();
  164. /**
  165. * Tick the "Save IP" checkbox in the ip popup
  166. */
  167. void ipPopupCheckSaveCheckbox();
  168. // Login Signup Popup
  169. /**
  170. * Close the login/signup popup
  171. */
  172. void loginSignupPopupClose();
  173. /**
  174. * Open the login/signup popup
  175. */
  176. void loginSignupPopupOpen();
  177. /**
  178. * Tick the "Save Username" checkbox in the login/signup popup
  179. */
  180. void loginSignupCheckSaveCheckbox();
  181. // Login
  182. /**
  183. * Set the status for the login tab in the login/signup popup
  184. * @param status The status message
  185. */
  186. void loginSetStatus(QString status);
  187. /**
  188. * Enable the login button for the login tab in the login/signup popup
  189. */
  190. void loginEnableLoginButton();
  191. /**
  192. * Disable the login button for the login tab in the login/signup popup
  193. */
  194. void loginDisableLoginButton();
  195. /**
  196. * Set the username input field for the login tab in the login/signup popup (used for autofill username)
  197. * @param username The username
  198. */
  199. void loginSetUsername(QString username);
  200. // Signup
  201. /**
  202. * Set the status for the signup tab in the login/signup popup
  203. * @param status The status message
  204. */
  205. void signupSetStatus(QString status);
  206. /**
  207. * Disable the register button for the signup tab in the login/signup popup
  208. */
  209. void signupEnableRegisterButton();
  210. /**
  211. * Disable the register button for the signup tab in the login/signup popup
  212. */
  213. void signupDisableRegisterButton();
  214. // Footer
  215. /**
  216. * Set the status in the footer
  217. * @param status The new status
  218. */
  219. void footerSetStatus(QString status);
  220. /**
  221. * Set the error in the footer
  222. * @param error The error message
  223. */
  224. void footerSetError(QString error);
  225. // Notifications
  226. /**
  227. * Add a new notification to the notifications tab
  228. * @param message The new notification message
  229. */
  230. void notification(QString message);
  231. /**
  232. * Dismiss an existing notification in the notifications tab
  233. * @param index The index of the notification
  234. */
  235. void dismissNotification(int index);
  236. /**
  237. * Show a desktop notification
  238. * @param title The title of the notification
  239. * @param message The message of the notification
  240. */
  241. void showDesktopNotification(QString title, QString message);
  242. // Log
  243. /**
  244. * Add a message to the log
  245. * @param logText The message to be added
  246. */
  247. void log(QString logText);
  248. // QML -> C++
  249. public slots:
  250. // Main
  251. /**
  252. * Handle the start of the main window
  253. *
  254. * Check the configuration, load the values to the GUI and start the CLI is needed
  255. * Opens the according popup in the window
  256. * @param startWithCli Should the CLI be started?
  257. */
  258. void onStart(bool startWithCli);
  259. /**
  260. * Handle the "Switch Server" button
  261. *
  262. * Disconnect from the server
  263. */
  264. void onSwitchServer();
  265. // No Config Found Popup
  266. /**
  267. * Handle the continue button after a CLI has been selected
  268. *
  269. * Creates a default config with the path to the selected CLI and runs the onStart method
  270. * @param cli_path The path to the CLI
  271. */
  272. void onNoConfigFoundPopupContinueButton(QString cli_path);
  273. // Invalid Cli Path Popup
  274. /**
  275. * Handle the continue button after a CLI has been selected
  276. *
  277. * Sets the new CLI path in the config and runs the onStart method
  278. * @param cli_path The path to the CLI
  279. */
  280. void onInvalidCliPathPopupContinueButton(QString cli_path);
  281. /**
  282. * Handle the quit button
  283. *
  284. * Emits a signal to close the main window
  285. */
  286. void onInvalidCliPathPopupQuitButton();
  287. // Invalid Config Popup
  288. /**
  289. * Handle the "create default" button
  290. *
  291. * Sets up a default config and opens the "invalid cli path" popup so that the user can select a CLI
  292. */
  293. void onInvalidConfigPopupCreateDefaultButton();
  294. /**
  295. * Handle the quit button
  296. *
  297. * Emits a signal to close the main window
  298. */
  299. void onInvalidConfigPopupQuitButton();
  300. // Server Files
  301. /**
  302. * Handle the selection of a file with the file dialog
  303. *
  304. * Sets the text for the selected file and enables the "send file" button
  305. * @param url The new file url
  306. */
  307. void onServerFilesSelectFileButton(QUrl url);
  308. /**
  309. * Handle the "send file" button
  310. *
  311. * Upload the selected file to the server
  312. */
  313. void onServerFilesSendFileButton();
  314. /**
  315. * Handle the "clear selection" button
  316. *
  317. * Resets the selected file
  318. */
  319. void onServerFilesClearSelectionButton();
  320. /**
  321. * Handle the download button for a file
  322. *
  323. * Downloads the file from the server
  324. * @param fileName The name of the file
  325. */
  326. void onServerFilesDownloadFileButton(QString fileName);
  327. /**
  328. * Handle the delete button in the delete confirmation popup
  329. *
  330. * Deletes the file from the server
  331. * @param filename The name of the file
  332. */
  333. void onServerFilesConfirmDeleteFileButton(QString fileName);
  334. /**
  335. * Handle the queue button for a file
  336. *
  337. * Puts the file into the queue on the server
  338. * @param fileName The name of the file
  339. */
  340. void onReceivingQueueFileButton(QString fileName);
  341. /**
  342. * Handle the queue button for a file
  343. *
  344. * Dequeues the file on the server
  345. * @param fileName The name of the file
  346. */
  347. void onReceivingDequeueFileButton(QString fileName);
  348. // Settings
  349. /**
  350. * Handle the selection of a keyfile with the file dialog
  351. *
  352. * Selects the new keyfile on the CLI for further use
  353. * @param path The path to the keyfile
  354. */
  355. void onKeyfileSelected(QString path);
  356. /**
  357. * Handle the "close keyfile" button
  358. *
  359. * Closes the keyfile on the CLi
  360. */
  361. void onKeyfileClosed();
  362. /**
  363. * Handle the delete button in the delete me confirmation popup
  364. *
  365. * Tries to delete the current user from the server when the password is correct
  366. * @param password The entered password
  367. */
  368. void onSettingsDeleteMeButton(QString password);
  369. /**
  370. * Handle the "revert changes" button
  371. *
  372. * Sets the settings values to those in the config file
  373. */
  374. void onSettingsRevertChangesButton();
  375. /**
  376. * Handle the reset button
  377. *
  378. * Sets the settings to the default values
  379. */
  380. void onSettingsResetButton();
  381. /**
  382. * Handle the save button
  383. *
  384. * Saves the current values of the settings in the GUI to the config file
  385. * @param saveIP Should the autofill ip toggle be switched on or off?
  386. * @param saveUsername Should the autofill username toggle be switched on or off?
  387. * @param cliPath The path to the cli
  388. * @param keyPath The path to the keyfile
  389. */
  390. void onSettingsSaveButton(bool saveIP, bool saveUsername, QString cliPath, QString keyPath);
  391. // Ip Popup
  392. /**
  393. * Handle the connect button
  394. *
  395. * Connects to the server and saves the ip in the config if desired
  396. * @param ip The entered ip address
  397. * @param saveAsDefault Was the "Save IP" checkbox ticked?
  398. */
  399. void onIpPopupConnectButton(QString ip, bool saveAsDefault);
  400. // Login
  401. /**
  402. * Handle the login button
  403. *
  404. * Logs in on the server and saves the username in the config if desired
  405. * @param username The entered username
  406. * @param password The entered password
  407. * @param saveAsDefault Was the "Save Username" checkbox ticked?
  408. */
  409. void onLoginLoginButton(QString username, QString password, bool saveAsDefault);
  410. // Signup
  411. /**
  412. * Handle the register button
  413. *
  414. * Registers on the server and saves the username in the config if desired
  415. * @param username The entered username
  416. * @param passwordOne The entered first password
  417. * @param passwordTwo The entered confirmation password
  418. * @param saveAsDefault Was the "Save Username" checkbox ticked?
  419. */
  420. void onSignupRegisterButton(QString username, QString passwordOne, QString passwordTwo, bool saveAsDefault);
  421. // Notifications
  422. /**
  423. * Handle the "x" button on a noticiation
  424. *
  425. * Dismiss the notification in the notifications tab
  426. * @param id The id of the notification
  427. */
  428. void onDismissNotificationButton(int id);
  429. };
  430. #endif // QMLHANDLER_H