123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- // MainDlg.cpp : implementation of the CLoginDlg class
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "LoginDlg.h"
- #include "StabtypeControl.h"
- #include "CApp.h"
- #include "CNetWork.h"
-
- CLoginDlg::CLoginDlg() : SHostWnd(_T("LAYOUT:XML_LOGIN")), m_network_tools(nullptr)
- {
- m_bLayoutInited = FALSE;
-
-
- }
- CLoginDlg::~CLoginDlg()
- {
- if (m_network_tools)
- {
- delete m_network_tools;
- m_network_tools = nullptr;
- }
- }
- int CLoginDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- SetMsgHandled(FALSE);
- return 0;
- }
- BOOL CLoginDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
- {
- m_bLayoutInited = TRUE;
- Init();
- return 0;
- }
- void CLoginDlg::Init()
- {
- if (m_network_tools == nullptr)
- {
- m_network_tools = new CManageNetWork();
- //m_network_tools.Attach(new CManageNetWork());
- m_network_tools->init();
- }
-
- ServerListUrl list;
- list.id = 0;
- list.name = L"首选";
- list.url = "https://api.ruanjian.buzz";
- ServerListUrl list1;
- list1.id = 1;
- list1.name = L"备用1";
- list1.url = "https://api.ruanjian1.buzz";
- ServerListUrl list2;
- list2.id = 2;
- list2.name = L"备用2";
- list2.url = "https://ruanjian2.xyz";
- vctInfo.push_back(list);
- vctInfo.push_back(list1);
- vctInfo.push_back(list2);
- StabtypeControl* tabtype = FindChildByName2<StabtypeControl>(L"nodeclass");
- if (tabtype)
- {
- for (auto i = 0; i < vctInfo.size(); i++)
- {
- tabtype->ItemCreateChildren(vctInfo[i].id, vctInfo[i].name, i == 0 ? true : false);
- }
- if (vctInfo.size() > 0)
- {
-
- m_network_tools->SetUrl(vctInfo[0].url.c_str());
- //Curl::getSingletonPtr()->SetUrl(vctInfo[0].url);
- }
- tabtype->GetEventSet()->subscribeEvent(EVT_TABTYPE_CONTROL,
- Subscriber(&CLoginDlg::OnTabtypeControl, this));
- }
- SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
- SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
- if (m_edit_username) {
- m_edit_username->SetWindowTextW(S_CA2W(m_network_tools->GetUsername()));
- m_edit_username->Invalidate();
- }
- if (m_edit_password)
- {
- m_edit_password->SetWindowTextW(S_CA2W(m_network_tools->GetPassWord()));
- m_edit_password->Invalidate();
- }
- }
- bool CLoginDlg::OnTabtypeControl(SOUI::EventArgs* pEvt)
- {
- SOUI::EventTabtypeControl* pTestControlEvent =
- SOUI::sobj_cast<SOUI::EventTabtypeControl>(pEvt);
- if (m_network_tools)
- {
- m_network_tools->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
- }
-
- /*if (m_curl)
- {
- m_curl->SetUrl(vctInfo[pTestControlEvent->nIndex].url.c_str());
- }*/
- //Curl::getSingletonPtr()->SetUrl(vctInfo[pTestControlEvent->nIndex].url);
- return true;
- }
- //TODO:消息映射
- void CLoginDlg::OnClose()
- {
- CSimpleWnd::DestroyWindow();
- }
- void CLoginDlg::OnMaximize()
- {
- SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
- }
- void CLoginDlg::OnRestore()
- {
- SendMessage(WM_SYSCOMMAND, SC_RESTORE);
- }
- void CLoginDlg::OnMinimize()
- {
- SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
- }
- void CLoginDlg::OnLogin()
- {
- if (!m_network_tools)
- {
- return;
- }
- SEdit* m_edit_username = FindChildByName2<SEdit>(L"edit_username");
- SEdit* m_edit_password = FindChildByName2<SEdit>(L"edit_password");
- if (m_edit_username && m_edit_password)
- {
- auto username = m_edit_username->GetWindowTextW();
- auto password = m_edit_password->GetWindowTextW();
- /*if (m_base_curl) {
- char data[256] = { 0 };
- HTTPRET httpret = m_base_curl->PostLogin(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0), data);
- SLOG_DEBUG(data);
- }*/
- m_network_tools->Login(S_CW2A(username).GetBuffer(0), S_CW2A(password).GetBuffer(0));
- }
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(L"正在登录...");
- onlogin->EnableWindow(FALSE);
- onlogin->Invalidate();
- }
- /**/
- }
- void CLoginDlg::ToMain()
- {
- CApp::getSingletonPtr()->SetOut(1);
- CSimpleWnd::DestroyWindow();
- }
- void CLoginDlg::OnLoginFinish(EventArgs* e)
- {
- EventLogin* e2 = sobj_cast<EventLogin>(e);
- if (!e2)
- {
- return;
- }
- if (e2->status == 0)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- } else if (e2->status == -1)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- } else if (e2->status == 200)
- {
- /*if (m_network_tools)
- {
- m_network_tools->DonloadConfg();
- }*/
- ToMain();
- }
-
- }
- void CLoginDlg::OnDonloadFinish(EventArgs* e)
- {
- EventDoWNload* e2 = sobj_cast<EventDoWNload>(e);
- if (e2)
- {
- if (e2->status != 200)
- {
- SImageButton* onlogin = FindChildByName2<SImageButton>(L"onlogin");
- if (onlogin)
- {
- onlogin->SetWindowTextW(e2->msg);
- onlogin->EnableWindow(TRUE);
- onlogin->Invalidate();
- }
- SMessageBox(m_hWnd, e2->msg, L"提示", 0);
- }
- else {
- ToMain();
- }
- }
- }
|