LoginDlg.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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_network_tools)
  87. {
  88. m_network_tools->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  89. }
  90. /*if (m_curl)
  91. {
  92. m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
  93. }*/
  94. //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
  95. return true;
  96. }
  97. //TODO:消息映射
  98. void CLoginDlg::OnClose()
  99. {
  100. CSimpleWnd::DestroyWindow();
  101. }
  102. void CLoginDlg::OnMaximize()
  103. {
  104. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  105. }
  106. void CLoginDlg::OnRestore()
  107. {
  108. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  109. }
  110. void CLoginDlg::OnMinimize()
  111. {
  112. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  113. }
  114. void CLoginDlg::OnLogin()
  115. {
  116. if (!m_network_tools)
  117. {
  118. return;
  119. }
  120. SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
  121. SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
  122. if (m_edit_username && m_edit_password)
  123. {
  124. auto username = m_edit_username->GetWindowTextW();
  125. auto password = m_edit_password->GetWindowTextW();
  126. /*if (m_base_curl) {
  127. char data[256] = { 0 };
  128. HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
  129. SLOG_DEBUG(data);
  130. }*/
  131. m_network_tools->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
  132. }
  133. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  134. if (onlogin)
  135. {
  136. onlogin->SetWindowTextW(L"正在登录...");
  137. onlogin->EnableWindow(FALSE);
  138. onlogin->Invalidate();
  139. }
  140. /**/
  141. }
  142. void CLoginDlg::ToMain()
  143. {
  144. CApp::getSingletonPtr()->SetOut(1);
  145. CSimpleWnd::DestroyWindow();
  146. }
  147. void CLoginDlg::OnLoginFinish(EventArgs* e)
  148. {
  149. EventLogin* e2 = sobj_cast<EventLogin>(e);
  150. if (!e2)
  151. {
  152. return;
  153. }
  154. if (e2->status == 0)
  155. {
  156. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  157. if (onlogin)
  158. {
  159. onlogin->SetWindowTextW(e2->msg);
  160. onlogin->EnableWindow(TRUE);
  161. onlogin->Invalidate();
  162. }
  163. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  164. } else if (e2->status == -1)
  165. {
  166. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  167. if (onlogin)
  168. {
  169. onlogin->SetWindowTextW(e2->msg);
  170. onlogin->EnableWindow(TRUE);
  171. onlogin->Invalidate();
  172. }
  173. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  174. } else if (e2->status == 200)
  175. {
  176. /*if (m_network_tools)
  177. {
  178. m_network_tools->DonloadConfg();
  179. }*/
  180. ToMain();
  181. }
  182. }
  183. void CLoginDlg::OnDonloadFinish(EventArgs* e)
  184. {
  185. EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
  186. if (e2)
  187. {
  188. if (e2->status != 200)
  189. {
  190. SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
  191. if (onlogin)
  192. {
  193. onlogin->SetWindowTextW(e2->msg);
  194. onlogin->EnableWindow(TRUE);
  195. onlogin->Invalidate();
  196. }
  197. SMessageBox(m_hWnd, e2->msg, L"提示", 0);
  198. }
  199. else {
  200. ToMain();
  201. }
  202. }
  203. }