| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423 |
- // MainDlg.cpp : implementation of the CMainDlg class
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MainDlg.h"
- #include <helper/SAdapterBase.h>
- #include "CallerInfo.h"
- struct flashtime {
- int timeEnd;
- wchar_t szFlash[50];
- }g_flashs[] =
- {
- { 0, L"morning.swf" },
- { 8,L"noon.swf" },
- { 12,L"afternoon.swf" },
- { 18,L"night.swf" }
- };
- class CTestAdapterFix : public SAdapterBase
- {
- public:
- struct UserInfo {
- SStringT strName;
- SStringT strAccount;
- int iIcon;
- };
- protected:
- SArray<UserInfo> m_userInfo;
- public:
- CTestAdapterFix()
- {
- UserInfo ui[] =
- {//SOUI管理员列表
- {
- _T("想象元素"),
- _T("100"),
- 0
- },
- {
- _T("启程软件"),
- _T("101"),
- 1
- },
- {
- _T("L.K"),
- _T("102"),
- 2
- },
- {
- _T("多点WIFI"),
- _T("103"),
- 3
- },
- {
- _T("ID-1008"),
- _T("104"),
- 4
- },
- {
- _T("小可"),
- _T("105"),
- 5
- },
- {
- _T("任明星"),
- _T("106"),
- 6
- },
- };
- for (int i = 0; i < ARRAYSIZE(ui); i++)
- {
- m_userInfo.Add(ui[i]);
- }
- }
- virtual int getCount()
- {
- return m_userInfo.GetCount();
- }
- virtual void getView(int position, SWindow * pItem, pugi::xml_node xmlTemplate)
- {
- if (pItem->GetChildrenCount() == 0)
- {
- pItem->InitFromXml(xmlTemplate);
- }
- SImageWnd *pAvatar = pItem->FindChildByID2<SImageWnd>(1);
- pAvatar->SetIcon(m_userInfo.GetAt(position).iIcon);
- SWindow *pName = pItem->FindChildByID(2);
- pName->SetWindowText(m_userInfo.GetAt(position).strName);
- SWindow *pAccount = pItem->FindChildByID(3);
- pAccount->SetWindowText(m_userInfo.GetAt(position).strAccount);
- SWindow *pBtn = pItem->FindChildByID(4);
- pBtn->SetUserData(position);
- pBtn->GetEventSet()->subscribeEvent(EVT_CMD, Subscriber(&CTestAdapterFix::OnButtonClick, this));
- pItem->GetEventSet()->subscribeEvent(EventItemPanelClick::EventID, Subscriber(&CTestAdapterFix::OnItemClick, this));
- }
- bool OnButtonClick(EventArgs *pEvt)
- {
- SButton *pBtn = sobj_cast<SButton>(pEvt->sender);
- int iItem = pBtn->GetUserData();
- STRACE(SStringT().Format(_T("button of %d item was clicked"), iItem));
- m_userInfo.RemoveAt(iItem);
- this->notifyDataSetChanged();
- return true;
- }
- bool OnItemClick(EventArgs *pEvt)
- {
- EventItemPanelClick *pEvt2 = sobj_cast<EventItemPanelClick>(pEvt);
- SASSERT(pEvt2);
- SWindow *pPanel = sobj_cast<SWindow>(pEvt2->sender);
- CPoint pt(GET_X_LPARAM(pEvt2->lParam), GET_Y_LPARAM(pEvt2->lParam));
- SWND swnd = pPanel->SwndFromPoint(pt, FALSE);
- SWindow *pClicked = NULL;
- if (swnd) pClicked = SWindowMgr::GetWindow(swnd);
- if (pClicked && pClicked->GetID() == 4)
- {//点击删除按钮
- pEvt->bubbleUp = false;
- }
- return true;
- }
- SStringT getItemDesc(int position)
- {
- return m_userInfo.GetAt(position).strName;
- }
- // BOOL onLVSelChanged(EventLVSelChanged *pEvt)
- // {
- // if(pEvt->hHitWnd)
- // {
- // SWindow *pSwnd = SWindowMgr::GetWindow(pEvt->hHitWnd);
- // if(pSwnd && pSwnd->GetID() == 4)
- // {//id of 4 is to remove the click item
- // pEvt->bCancel = TRUE;
- // }
- // return pEvt->bCancel;
- // }else
- // {
- // return FALSE;
- // }
- // }
- UserInfo getItem(int position)
- {
- SASSERT(position >= 0 && position < m_userInfo.GetCount());
- return m_userInfo[position];
- }
- };
- CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND"))
- {
- m_nRetCode = -1;
- m_bLayoutInited = FALSE;
- }
- CMainDlg::~CMainDlg()
- {
- }
- int CMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- SetMsgHandled(FALSE);
- return 0;
- }
- BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
- {
- m_bLayoutInited = TRUE;
- #if 0 // 测试curl库是否正常;
- //SStringT url = L"http://p.lyfz.net/ImgDownload.aspx?id=C5BC7BD1841EF1C32C3B61F8E7C3DBB7";// L"http://platinumoss.oss-cn-shanghai.aliyuncs.com/E81011418061848821/SSN001/ET17111800035/1bc42a1971bba0b7260d81cf90274936";
- SStringT url = L"http://platinumoss.oss-cn-shanghai.aliyuncs.com/E81011418061848821/SSN001/ET17111800035/1bc42a1971bba0b7260d81cf90274936";
- CCurlClient *pCurl = new CCurlClient();
- SStringT response;
- pCurl->DownloadFile(url, L"D:\\1.jpg");
- #endif
- #if 1 // 测试来电精灵;
- // 打开来电精灵设备;
- if (callproc::GetInstance()->OpenCaller())
- LOGW("log", L"加载来电精灵驱动成功\n");
- else
- LOGW("log", L"加载来电精灵驱动失败\n");
- // 关联来电回调和挂机回调;
- callproc::GetInstance()->SetCallBack(&CMainDlg::CallInCallBack, &CMainDlg::HangUPCallBack);
- #endif
- SShellNotifyIcon *notify = FindChildByID2<SShellNotifyIcon>(120);
- notify->ShowNotify(L"利亚方舟", L"来电精灵启动成功");
- SFlashCtrl * pFlash = FindChildByName2<SFlashCtrl>(L"flash_bkgnd");
- if (pFlash)
- {
- wchar_t szCurDir[MAX_PATH + 1];
- GetCurrentDirectoryW(MAX_PATH, szCurDir);
- time_t long_time;
- time(&long_time);
- struct tm * t = localtime(&long_time);
- wchar_t szFlash[MAX_PATH];
- for (int i = 3; i >= 0; i--)
- {
- if (t->tm_hour >= g_flashs[i].timeEnd)
- {
- swprintf(szFlash, L"%s\\flash\\%s", szCurDir, g_flashs[i].szFlash);
- break;
- }
- }
- pFlash->Play(szFlash);
- }
- SComboView *pComboView = FindChildByName2<SComboView>(L"cbx_account");
- if (pComboView)
- {
- SListView *pLstView = pComboView->GetListView();
- CTestAdapterFix *pAdapter = new CTestAdapterFix;
- pLstView->SetAdapter(pAdapter);
- pAdapter->Release();
- pComboView->SetCurSel(1);
- }
- return 0;
- }
- //关闭;
- void CMainDlg::OnClose()
- {
- ShowWindow(SW_HIDE);
- OutputDebugString(L"CMainDlg::OnClose\n");
- }
- // 最大化;
- void CMainDlg::OnMaximize()
- {
- SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
- }
- // 恢复;
- void CMainDlg::OnRestore()
- {
- SendMessage(WM_SYSCOMMAND, SC_RESTORE);
- }
- // 最小化;
- void CMainDlg::OnMinimize()
- {
- SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
- }
- void CMainDlg::OnBtnSetting()
- {
- STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
- if (pTab)
- {
- STurn3dView * pTurn3d = FindChildByName2<STurn3dView>(L"turn3d");
- if (pTurn3d)
- {
- pTurn3d->Turn(pTab->GetPage(_T("login")), pTab->GetPage(_T("settings")), FALSE);
- }
- }
- }
- void CMainDlg::OnBtnSettingOK()
- {
- STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
- if (pTab)
- {
- STurn3dView * pTurn3d = FindChildByName2<STurn3dView>(L"turn3d");
- if (pTurn3d)
- {
- pTurn3d->Turn(pTab->GetPage(_T("settings")), pTab->GetPage(_T("login")), TRUE);
- }
- }
- }
- void CMainDlg::OnBtnSettingCancel()
- {
- STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
- if (pTab)
- {
- STurn3dView * pTurn3d = FindChildByName2<STurn3dView>(L"turn3d");
- if (pTurn3d)
- {
- pTurn3d->Turn(pTab->GetPage(_T("settings")), pTab->GetPage(_T("login")), TRUE);
- }
- }
- }
- BOOL CMainDlg::OnTurn3D(EventArgs *pEvt)
- {
- EventTurn3d *pEvt3dTurn = (EventTurn3d*)pEvt;
- STabCtrl *pTab = FindChildByName2<STabCtrl>(L"tab_main");
- if (pEvt3dTurn->bTurn2Front_)
- {
- pTab->SetCurSel(_T("login"));
- }
- else
- {
- pTab->SetCurSel(_T("settings"));
- }
- return TRUE;
- }
- BOOL CMainDlg::OnUserChanged(EventArgs *pEvt)
- {
- EventCBSelChange *pEvt2 = sobj_cast<EventCBSelChange>(pEvt);
- SASSERT(pEvt2);
- SImageWnd *pAvatar = FindChildByName2<SImageWnd>(L"img_avatar");
- SASSERT(pAvatar);
- if (pEvt2->nCurSel != -1)
- {
- SComboView *pComboView = sobj_cast<SComboView>(pEvt->sender);
- CTestAdapterFix *pAdapter = (CTestAdapterFix*)pComboView->GetListView()->GetAdapter();
- CTestAdapterFix::UserInfo ui = pAdapter->getItem(pEvt2->nCurSel);
- pAvatar->SetIcon(ui.iIcon);
- }
- else
- {
- pAvatar->SetIcon(0);
- }
- return TRUE;
- }
- void CMainDlg::OnBtnLogin()
- {
- m_nRetCode = 0; // 登陆
- /*CallerInfo dlg;
- dlg.Create(GetActiveWindow(), 0, 0, 0, 0);
- dlg.SendMessage(WM_INITDIALOG);
- dlg.CenterWindow(dlg.m_hWnd);
- // 显示效果;
- dlg.AnimateHostWindow(150, AW_CENTER);
- dlg.ShowWindow(SW_SHOWNORMAL);
- //this->Run(dlg.m_hWnd);*/
- OnClose();
- /*
- CallerInfo dlg;
- dlg.DoModal(m_hWnd);*/
- #ifdef _DEBUG
- callproc::GetInstance()->GetCallInCallbackPtr()(257, L"测试webkit");
- #endif
- }
- //演示如何响应菜单事件
- void CMainDlg::OnCommand(UINT uNotifyCode, int nID, HWND wndCtl)
- {
- if (uNotifyCode == 0)
- {
- switch (nID)
- {
- case 6: // 退出菜单ID;
- //PostMessage(WM_CLOSE);
- CSimpleWnd::DestroyWindow();
- break;
- default:
- break;
- }
- }
- }
- // 来电回调;
- void CMainDlg::CallInCallBack(UBOX_HANDLE hbox, LPCTSTR lpCallInTelNumber)
- {
- std::thread t([](UBOX_HANDLE hbox, LPCTSTR lpTelNumber) {
- // lpTelNumber变量为外部变量, 可能会出现变化,应该及时存储;
- TString strTelNumber = lpTelNumber;
- LOGW("log", "----------------执行来电回调\n:电话=" << strTelNumber.c_str() << "----------------- ");
- // 弹出来电详情框;
- /*CDlgCaller dlg;
- callproc::GetInstance()->SetPopWindows(hbox, (CWnd*)&dlg);
- dlg.DoModal();
- if (pObj) delete pObj;*/
- CallerInfo dlg;
- callproc::GetInstance()->SetPopWindows(hbox, &dlg);
- dlg.m_strTelPhone = strTelNumber.c_str();
- dlg.DoModal();
- }, hbox, lpCallInTelNumber);
- t.detach();
- }
- // 挂机回调;
- void CMainDlg::HangUPCallBack(UBOX_HANDLE hbox, BOOL bCallType, LPCTSTR lpTelNumber, LPCTSTR lpRecordFile)
- {
- std::thread t([](UBOX_HANDLE hbox, BOOL bCallType, LPCTSTR lpTelNumber, LPCTSTR lpRecordFile) {
- TString strTelNumber = lpTelNumber;
- TString strRecordFile = lpRecordFile;
- if (bCallType)
- {
- LOGW("log", "----------------执行挂机回调\n:来电电话=" << strTelNumber.c_str() << ", 录音文件=" << strRecordFile.c_str() << "-----------------");
- // 挂机后,关闭来电详情框;
- CallerInfo *pWnd = (CallerInfo*)callproc::GetInstance()->GetPopWindows(hbox, true);
- if (pWnd)
- pWnd->PostMessage(WM_CLOSE, 0, 0);
- }
- else
- {
- LOGW("log", "----------------执行挂机回调\n:去电电话=" << strTelNumber.c_str() << ", 录音文件=" << strRecordFile.c_str() << "-----------------");
- }
- }, hbox, bCallType, lpTelNumber, lpRecordFile);
- t.detach();
- }
|