LoginDlg.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // MainDlg.cpp : implementation of the CLoginDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "LoginDlg.h"
  6. #include "StabtypeControl.h"
  7. #include "CApp.h"
  8. #include "CNetWork.h"
  9. CLoginDlg::CLoginDlg() : SHostWnd(_T("LAYOUT:XML_LOGIN")), m_network_tools(nullptr)
  10. {
  11. m_bLayoutInited = FALSE;
  12. }
  13. CLoginDlg::~CLoginDlg()
  14. {
  15. if (m_network_tools)
  16. {
  17. delete m_network_tools;
  18. m_network_tools = nullptr;
  19. }
  20. }
  21. int CLoginDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  22. {
  23. SetMsgHandled(FALSE);
  24. return 0;
  25. }
  26. BOOL CLoginDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
  27. {
  28. m_bLayoutInited = TRUE;
  29. Init();
  30. return 0;
  31. }
  32. void CLoginDlg::Init()
  33. {
  34. if (m_network_tools == nullptr)
  35. {
  36. m_network_tools = new CManageNetWork();
  37. //m_network_tools.Attach(new CManageNetWork());
  38. m_network_tools->init();
  39. }
  40. ServerListUrl list;
  41. list.id = 0;
  42. list.name = L"首选";
  43. list.url = "https://api.ruanjian.buzz";
  44. ServerListUrl list1;
  45. list1.id = 1;
  46. list1.name = L"备用1";
  47. list1.url = "https://api.ruanjian1.buzz";
  48. ServerListUrl list2;
  49. list2.id = 2;
  50. list2.name = L"备用2";
  51. list2.url = "https://ruanjian2.xyz";
  52. vctInfo.push_back(list);
  53. vctInfo.push_back(list1);
  54. vctInfo.push_back(list2);
  55. StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"nodeclass");
  56. if (tabtype)
  57. {
  58. for (auto i = 0; i < vctInfo.size(); i++)
  59. {
  60. tabtype->ItemCreateChildren(vctInfo[i].id, vctInfo[i].name, i == 0 ? true : false);
  61. }
  62. if (vctInfo.size() > 0)
  63. {
  64. m_network_tools->SetUrl(vctInfo[0].url.c_str());
  65. //Curl::getSingletonPtr()->SetUrl(vctInfo[0].url);
  66. }
  67. tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
  68. Subscriber(&CLoginDlg::OnTabtypeControl, this));
  69. }
  70. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  71. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  72. if (m_edit_username) {
  73. m_edit_username->SetWindowTextW(S_CA2W(m_network_tools->GetUsername()));
  74. m_edit_username->Invalidate();
  75. }
  76. if (m_edit_password)
  77. {
  78. m_edit_password->SetWindowTextW(S_CA2W(m_network_tools->GetPassWord()));
  79. m_edit_password->Invalidate();
  80. }
  81. }
  82. bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
  83. {
  84. SOUI::EventTabtypeControl* pTestControlEvent =
  85. SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
  86. /*if (m_curl)
  87. {
  88. m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  89. }*/
  90. //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
  91. return true;
  92. }
  93. //TODO:消息映射
  94. void CLoginDlg::OnClose()
  95. {
  96. CSimpleWnd::DestroyWindow();
  97. }
  98. void CLoginDlg::OnMaximize()
  99. {
  100. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  101. }
  102. void CLoginDlg::OnRestore()
  103. {
  104. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  105. }
  106. void CLoginDlg::OnMinimize()
  107. {
  108. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  109. }
  110. void CLoginDlg::OnLogin()
  111. {
  112. if (!m_network_tools)
  113. {
  114. return;
  115. }
  116. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  117. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  118. if (m_edit_username && m_edit_password)
  119. {
  120. auto username = m_edit_username->GetWindowTextW();
  121. auto password = m_edit_password->GetWindowTextW();
  122. /*if (m_base_curl) {
  123. char data[256] = { 0 };
  124. HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
  125. SLOG_DEBUG(data);
  126. }*/
  127. m_network_tools->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  128. }
  129. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  130. if (onlogin)
  131. {
  132. onlogin->SetWindowTextW(L"正在登录...");
  133. onlogin->EnableWindow(FALSE);
  134. onlogin->Invalidate();
  135. }
  136. /*CApp::getSingletonPtr()->SetOut(1);
  137. CSimpleWnd::DestroyWindow();*/
  138. }