mainwindow.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <include/ui/argdialog.h>
  4. #include <include/ui/messagedialog.hpp>
  5. #include <QList>
  6. #include <QListView>
  7. #include <QListWidgetItem>
  8. #include <QMainWindow>
  9. #include <QStandardItem>
  10. #include <QStandardItemModel>
  11. #include <QString>
  12. #include <QTableView>
  13. #include <QTimer>
  14. #include <headers/kiq_types.hpp>
  15. #include <include/client/client.hpp>
  16. namespace ProcessState {
  17. static constexpr int READY = 1;
  18. static constexpr int PENDING = 2;
  19. static constexpr int SUCCEEDED = 3;
  20. static constexpr int FAILED = 4;
  21. }
  22. struct KListViewsStates {
  23. bool eventViewBottom;
  24. bool processViewBottom;
  25. bool historyViewBottom;
  26. };
  27. const QString ProcessNames[4] = { "READY", "PENDING", "SUCCEEDED", "FAILED" };
  28. struct Process {
  29. QString name;
  30. int state;
  31. QString start;
  32. QString end;
  33. QString id;
  34. QString result = "";
  35. QString error = "";
  36. bool operator==(const Process &other) const {
  37. return name == other.name && state == other.state;
  38. }
  39. };
  40. // struct Event {};
  41. namespace Ui {
  42. class MainWindow;
  43. }
  44. class MainWindow : public QMainWindow
  45. {
  46. Q_OBJECT
  47. public:
  48. explicit MainWindow(int argc = 0, char** argv = nullptr, QWidget* parent = nullptr);
  49. ~MainWindow();
  50. class MessageParser {
  51. public:
  52. void init(MainWindow* window);
  53. void handleCommands(StringVec commands, QString default_app);
  54. void handleMessage(QString message, StringVec v);
  55. QString handleEventMessage(QString message, StringVec v);
  56. private:
  57. QString parseMessage(const QString& s, StringVec v);
  58. void updateProcessResult(QString id, QString result, bool error);
  59. MainWindow* window;
  60. };
  61. /** UI & Messages */
  62. void connectUi();
  63. void setConnectScreen(bool visible = true);
  64. QString parseTaskInfo(StringVec v);
  65. /** Process arguments */
  66. int cli_argc;
  67. char** cli_argv;
  68. /** UI Members */
  69. MessageParser message_parser;
  70. Ui::MainWindow* ui;
  71. ArgDialog* arg_ui;
  72. MessageDialog message_ui;
  73. /** Client member */
  74. Client* q_client;
  75. /** Models */
  76. std::vector<Process> m_processes;
  77. QList<QString> m_events;
  78. QStandardItemModel* m_process_model;
  79. QStandardItemModel* m_event_model;
  80. KListViewsStates m_view_states;
  81. /** Misc */
  82. QJsonObject m_config;
  83. uint16_t m_consecutive_events;
  84. private slots:
  85. /** Receivers */
  86. void connectClient();
  87. void onMessageReceived(int t, const QString& s, StringVec v);
  88. };
  89. #endif // MAINWINDOW_H