QtMessageSender.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "QtMessageSender.h"
  2. #include "QtBootSender.h"
  3. #include <thread>
  4. #include "Widgets/BootWidget.h"
  5. #include "MessageSender.h"
  6. #include <QApplication>
  7. #include "SpBase.h"
  8. #include "memutil.h"
  9. int qt_gui_create_format(sp_gui_format_t** p_gui)
  10. {
  11. int result = 0;
  12. sp_gui_format_t* gui = ZALLOC_T(sp_gui_format_t);
  13. if (gui != nullptr) {
  14. gui->gui_inst = (void*)(new QtBootSender());
  15. gui->display = &qt_gui_display;
  16. gui->hide = &qt_gui_undisplay;
  17. gui->show_entity_info = &qt_gui_show_entity_info;
  18. gui->show_running_info = &qt_gui_show_running_info;
  19. gui->post_message = &qt_gui_post_message;
  20. *p_gui = gui;
  21. }
  22. return result;
  23. }
  24. void qt_gui_destroy_format(sp_gui_format_t* p_gui)
  25. {
  26. if (p_gui->gui_inst) {
  27. delete p_gui->gui_inst;
  28. }
  29. FREE(p_gui);
  30. }
  31. int qt_gui_show_running_info(void* gui, const char* msg, int type)
  32. {
  33. QtMessageInfo message{ QString(msg), TextEvent };
  34. QtBootSender* senderInst = (QtBootSender*)gui;
  35. emit senderInst->ShowMessage(message);
  36. return 0;
  37. }
  38. int qt_gui_show_entity_info(void* gui, const char* entity, int state)
  39. {
  40. return 0;
  41. }
  42. int qt_gui_display(void* gui)
  43. {
  44. return 0;
  45. }
  46. int qt_gui_undisplay(void* gui)
  47. {
  48. return 0;
  49. }
  50. void qt_gui_post_message(void* gui, unsigned long param1, unsigned long param2)
  51. {
  52. }
  53. QtMessageSender::QtMessageSender():mWinInitialized(false), sender(nullptr) {
  54. //sender = new QtBootSender();
  55. kSenderInst = new QtBootSender();
  56. std::thread uiThread(QtWinThread, this);
  57. uiThread.detach();
  58. Sleep(300);
  59. }
  60. QtMessageSender::~QtMessageSender()
  61. {
  62. if (sender) {
  63. delete sender;
  64. sender = nullptr;
  65. }
  66. }
  67. void QtMessageSender::ShowMessage(const SP::UI::MessageInfo& msg)
  68. {
  69. QtMessageInfo message{ QString(msg.content.GetData()), msg.type };
  70. if (kSenderInst) {
  71. emit kSenderInst->ShowMessage(message);
  72. }
  73. }