MainDlg.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. // MainDlg.cpp : implementation of the CMainDlg class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "MainDlg.h"
  6. #include <helper/SAdapterBase.h>
  7. #include "CallerInfo.h"
  8. struct flashtime {
  9. int timeEnd;
  10. wchar_t szFlash[50];
  11. }g_flashs[] =
  12. {
  13. { 0, L"morning.swf" },
  14. { 8,L"noon.swf" },
  15. { 12,L"afternoon.swf" },
  16. { 18,L"night.swf" }
  17. };
  18. class CTestAdapterFix : public SAdapterBase
  19. {
  20. public:
  21. struct UserInfo {
  22. SStringT strName;
  23. SStringT strAccount;
  24. int iIcon;
  25. };
  26. protected:
  27. SArray<UserInfo> m_userInfo;
  28. public:
  29. CTestAdapterFix()
  30. {
  31. UserInfo ui[] =
  32. {//SOUI管理员列表
  33. {
  34. _T("想象元素"),
  35. _T("100"),
  36. 0
  37. },
  38. {
  39. _T("启程软件"),
  40. _T("101"),
  41. 1
  42. },
  43. {
  44. _T("L.K"),
  45. _T("102"),
  46. 2
  47. },
  48. {
  49. _T("多点WIFI"),
  50. _T("103"),
  51. 3
  52. },
  53. {
  54. _T("ID-1008"),
  55. _T("104"),
  56. 4
  57. },
  58. {
  59. _T("小可"),
  60. _T("105"),
  61. 5
  62. },
  63. {
  64. _T("任明星"),
  65. _T("106"),
  66. 6
  67. },
  68. };
  69. for (int i = 0; i < ARRAYSIZE(ui); i++)
  70. {
  71. m_userInfo.Add(ui[i]);
  72. }
  73. }
  74. virtual int getCount()
  75. {
  76. return m_userInfo.GetCount();
  77. }
  78. virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
  79. {
  80. if (pItem->GetChildrenCount() == 0)
  81. {
  82. pItem->InitFromXml(xmlTemplate);
  83. }
  84. SImageWnd *pAvatar = pItem->FindChildByID2<SImageWnd>(1);
  85. pAvatar->SetIcon(m_userInfo.GetAt(position).iIcon);
  86. SWindow *pName = pItem->FindChildByID(2);
  87. pName->SetWindowText(m_userInfo.GetAt(position).strName);
  88. SWindow *pAccount = pItem->FindChildByID(3);
  89. pAccount->SetWindowText(m_userInfo.GetAt(position).strAccount);
  90. SWindow *pBtn = pItem->FindChildByID(4);
  91. pBtn->SetUserData(position);
  92. pBtn->GetEventSet()->subscribeEvent(EVT_CMD, Subscriber(&CTestAdapterFix::OnButtonClick, this));
  93. pItem->GetEventSet()->subscribeEvent(EventItemPanelClick::EventID, Subscriber(&CTestAdapterFix::OnItemClick, this));
  94. }
  95. bool OnButtonClick(EventArgs *pEvt)
  96. {
  97. SButton *pBtn = sobj_cast<SButton>(pEvt->sender);
  98. int iItem = pBtn->GetUserData();
  99. STRACE(SStringT().Format(_T("button of %d item was clicked"), iItem));
  100. m_userInfo.RemoveAt(iItem);
  101. this->notifyDataSetChanged();
  102. return true;
  103. }
  104. bool OnItemClick(EventArgs *pEvt)
  105. {
  106. EventItemPanelClick *pEvt2 = sobj_cast<EventItemPanelClick>(pEvt);
  107. SASSERT(pEvt2);
  108. SWindow *pPanel = sobj_cast<SWindow>(pEvt2->sender);
  109. CPoint pt(GET_X_LPARAM(pEvt2->lParam), GET_Y_LPARAM(pEvt2->lParam));
  110. SWND swnd = pPanel->SwndFromPoint(pt, FALSE);
  111. SWindow *pClicked = NULL;
  112. if (swnd) pClicked = SWindowMgr::GetWindow(swnd);
  113. if (pClicked && pClicked->GetID() == 4)
  114. {//点击删除按钮
  115. pEvt->bubbleUp = false;
  116. }
  117. return true;
  118. }
  119. SStringT getItemDesc(int position)
  120. {
  121. return m_userInfo.GetAt(position).strName;
  122. }
  123. // BOOL onLVSelChanged(EventLVSelChanged *pEvt)
  124. // {
  125. // if(pEvt->hHitWnd)
  126. // {
  127. // SWindow *pSwnd = SWindowMgr::GetWindow(pEvt->hHitWnd);
  128. // if(pSwnd && pSwnd->GetID() == 4)
  129. // {//id of 4 is to remove the click item
  130. // pEvt->bCancel = TRUE;
  131. // }
  132. // return pEvt->bCancel;
  133. // }else
  134. // {
  135. // return FALSE;
  136. // }
  137. // }
  138. UserInfo getItem(int position)
  139. {
  140. SASSERT(position >= 0 && position < m_userInfo.GetCount());
  141. return m_userInfo[position];
  142. }
  143. };
  144. CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND"))
  145. {
  146. m_nRetCode = -1;
  147. m_bLayoutInited = FALSE;
  148. }
  149. CMainDlg::~CMainDlg()
  150. {
  151. }
  152. int CMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
  153. {
  154. SetMsgHandled(FALSE);
  155. return 0;
  156. }
  157. BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
  158. {
  159. m_bLayoutInited = TRUE;
  160. #if 0 // 测试curl库是否正常;
  161. //SStringT url = L"http://p.lyfz.net/ImgDownload.aspx?id=C5BC7BD1841EF1C32C3B61F8E7C3DBB7";// L"http://platinumoss.oss-cn-shanghai.aliyuncs.com/E81011418061848821/SSN001/ET17111800035/1bc42a1971bba0b7260d81cf90274936";
  162. SStringT url = L"http://platinumoss.oss-cn-shanghai.aliyuncs.com/E81011418061848821/SSN001/ET17111800035/1bc42a1971bba0b7260d81cf90274936";
  163. CCurlClient *pCurl = new CCurlClient();
  164. SStringT response;
  165. pCurl->DownloadFile(url, L"D:\\1.jpg");
  166. #endif
  167. #if 1 // 测试来电精灵;
  168. // 打开来电精灵设备;
  169. if (callproc::GetInstance()->OpenCaller())
  170. LOGW("log", L"加载来电精灵驱动成功\n");
  171. else
  172. LOGW("log", L"加载来电精灵驱动失败\n");
  173. // 关联来电回调和挂机回调;
  174. callproc::GetInstance()->SetCallBack(&CMainDlg::CallInCallBack, &CMainDlg::HangUPCallBack);
  175. #endif
  176. SShellNotifyIcon *notify = FindChildByID2<SShellNotifyIcon>(120);
  177. notify->ShowNotify(L"利亚方舟", L"来电精灵启动成功");
  178. SFlashCtrl * pFlash = FindChildByName2<SFlashCtrl>(L"flash_bkgnd");
  179. if (pFlash)
  180. {
  181. wchar_t szCurDir[MAX_PATH + 1];
  182. GetCurrentDirectoryW(MAX_PATH, szCurDir);
  183. time_t long_time;
  184. time(&long_time);
  185. struct tm * t = localtime(&long_time);
  186. wchar_t szFlash[MAX_PATH];
  187. for (int i = 3; i >= 0; i--)
  188. {
  189. if (t->tm_hour >= g_flashs[i].timeEnd)
  190. {
  191. swprintf(szFlash, L"%s\\flash\\%s", szCurDir, g_flashs[i].szFlash);
  192. break;
  193. }
  194. }
  195. pFlash->Play(szFlash);
  196. }
  197. SComboView *pComboView = FindChildByName2<SComboView>(L"cbx_account");
  198. if (pComboView)
  199. {
  200. SListView *pLstView = pComboView->GetListView();
  201. CTestAdapterFix *pAdapter = new CTestAdapterFix;
  202. pLstView->SetAdapter(pAdapter);
  203. pAdapter->Release();
  204. pComboView->SetCurSel(1);
  205. }
  206. return 0;
  207. }
  208. //关闭;
  209. void CMainDlg::OnClose()
  210. {
  211. ShowWindow(SW_HIDE);
  212. OutputDebugString(L"CMainDlg::OnClose\n");
  213. }
  214. // 最大化;
  215. void CMainDlg::OnMaximize()
  216. {
  217. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
  218. }
  219. // 恢复;
  220. void CMainDlg::OnRestore()
  221. {
  222. SendMessage(WM_SYSCOMMAND, SC_RESTORE);
  223. }
  224. // 最小化;
  225. void CMainDlg::OnMinimize()
  226. {
  227. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
  228. }
  229. void CMainDlg::OnBtnSetting()
  230. {
  231. STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
  232. if (pTab)
  233. {
  234. STurn3dView * pTurn3d = FindChildByName2<STurn3dView>(L"turn3d");
  235. if (pTurn3d)
  236. {
  237. pTurn3d->Turn(pTab->GetPage(_T("login")), pTab->GetPage(_T("settings")), FALSE);
  238. }
  239. }
  240. }
  241. void CMainDlg::OnBtnSettingOK()
  242. {
  243. STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
  244. if (pTab)
  245. {
  246. STurn3dView * pTurn3d = FindChildByName2<STurn3dView>(L"turn3d");
  247. if (pTurn3d)
  248. {
  249. pTurn3d->Turn(pTab->GetPage(_T("settings")), pTab->GetPage(_T("login")), TRUE);
  250. }
  251. }
  252. }
  253. void CMainDlg::OnBtnSettingCancel()
  254. {
  255. STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
  256. if (pTab)
  257. {
  258. STurn3dView * pTurn3d = FindChildByName2<STurn3dView>(L"turn3d");
  259. if (pTurn3d)
  260. {
  261. pTurn3d->Turn(pTab->GetPage(_T("settings")), pTab->GetPage(_T("login")), TRUE);
  262. }
  263. }
  264. }
  265. BOOL CMainDlg::OnTurn3D(EventArgs *pEvt)
  266. {
  267. EventTurn3d *pEvt3dTurn = (EventTurn3d*)pEvt;
  268. STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
  269. if (pEvt3dTurn->bTurn2Front_)
  270. {
  271. pTab->SetCurSel(_T("login"));
  272. }
  273. else
  274. {
  275. pTab->SetCurSel(_T("settings"));
  276. }
  277. return TRUE;
  278. }
  279. BOOL CMainDlg::OnUserChanged(EventArgs *pEvt)
  280. {
  281. EventCBSelChange *pEvt2 = sobj_cast<EventCBSelChange>(pEvt);
  282. SASSERT(pEvt2);
  283. SImageWnd *pAvatar = FindChildByName2<SImageWnd>(L"img_avatar");
  284. SASSERT(pAvatar);
  285. if (pEvt2->nCurSel != -1)
  286. {
  287. SComboView *pComboView = sobj_cast<SComboView>(pEvt->sender);
  288. CTestAdapterFix *pAdapter = (CTestAdapterFix*)pComboView->GetListView()->GetAdapter();
  289. CTestAdapterFix::UserInfo ui = pAdapter->getItem(pEvt2->nCurSel);
  290. pAvatar->SetIcon(ui.iIcon);
  291. }
  292. else
  293. {
  294. pAvatar->SetIcon(0);
  295. }
  296. return TRUE;
  297. }
  298. void CMainDlg::OnBtnLogin()
  299. {
  300. m_nRetCode = 0; // 登陆
  301. /*CallerInfo dlg;
  302. dlg.Create(GetActiveWindow(), 0, 0, 0, 0);
  303. dlg.SendMessage(WM_INITDIALOG);
  304. dlg.CenterWindow(dlg.m_hWnd);
  305. // 显示效果;
  306. dlg.AnimateHostWindow(150, AW_CENTER);
  307. dlg.ShowWindow(SW_SHOWNORMAL);
  308. //this->Run(dlg.m_hWnd);*/
  309. OnClose();
  310. /*
  311. CallerInfo dlg;
  312. dlg.DoModal(m_hWnd);*/
  313. #ifdef _DEBUG
  314. callproc::GetInstance()->GetCallInCallbackPtr()(257, L"测试webkit");
  315. #endif
  316. }
  317. //演示如何响应菜单事件
  318. void CMainDlg::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl)
  319. {
  320. if (uNotifyCode == 0)
  321. {
  322. switch (nID)
  323. {
  324. case 6: // 退出菜单ID;
  325. //PostMessage(WM_CLOSE);
  326. CSimpleWnd::DestroyWindow();
  327. break;
  328. default:
  329. break;
  330. }
  331. }
  332. }
  333. // 来电回调;
  334. void CMainDlg::CallInCallBack(UBOX_HANDLE hbox, LPCTSTR lpCallInTelNumber)
  335. {
  336. std::thread t([](UBOX_HANDLE hbox, LPCTSTR lpTelNumber) {
  337. // lpTelNumber变量为外部变量, 可能会出现变化,应该及时存储;
  338. TString strTelNumber = lpTelNumber;
  339. LOGW("log", "----------------执行来电回调\n:电话=" << strTelNumber.c_str() << "----------------- ");
  340. // 弹出来电详情框;
  341. /*CDlgCaller dlg;
  342. callproc::GetInstance()->SetPopWindows(hbox, (CWnd*)&dlg);
  343. dlg.DoModal();
  344. if (pObj) delete pObj;*/
  345. CallerInfo dlg;
  346. callproc::GetInstance()->SetPopWindows(hbox, &dlg);
  347. dlg.m_strTelPhone = strTelNumber.c_str();
  348. dlg.DoModal();
  349. }, hbox, lpCallInTelNumber);
  350. t.detach();
  351. }
  352. // 挂机回调;
  353. void CMainDlg::HangUPCallBack(UBOX_HANDLE hbox, BOOL bCallType, LPCTSTR lpTelNumber, LPCTSTR lpRecordFile)
  354. {
  355. std::thread t([](UBOX_HANDLE hbox, BOOL bCallType, LPCTSTR lpTelNumber, LPCTSTR lpRecordFile) {
  356. TString strTelNumber = lpTelNumber;
  357. TString strRecordFile = lpRecordFile;
  358. if (bCallType)
  359. {
  360. LOGW("log", "----------------执行挂机回调\n:来电电话=" << strTelNumber.c_str() << ", 录音文件=" << strRecordFile.c_str() << "-----------------");
  361. // 挂机后,关闭来电详情框;
  362. CallerInfo *pWnd = (CallerInfo*)callproc::GetInstance()->GetPopWindows(hbox, true);
  363. if (pWnd)
  364. pWnd->PostMessage(WM_CLOSE, 0, 0);
  365. }
  366. else
  367. {
  368. LOGW("log", "----------------执行挂机回调\n:去电电话=" << strTelNumber.c_str() << ", 录音文件=" << strRecordFile.c_str() << "-----------------");
  369. }
  370. }, hbox, bCallType, lpTelNumber, lpRecordFile);
  371. t.detach();
  372. }