RegFinishDlg.cpp
上传用户:zslianheng
上传日期:2013-04-03
资源大小:946k
文件大小:5k
源码类别:

Linux/Unix编程

开发平台:

Visual C++

  1. /***************************************************************************
  2.  *                                                                         *
  3.  *   This program is free software; you can redistribute it and/or modify  *
  4.  *   it under the terms of the GNU General Public License as published by  *
  5.  *   the Free Software Foundation; either version 2 of the License, or     *
  6.  *   (at your option) any later version.                                   *
  7.  *                                                                         *
  8.  *   copyright            : (C) 2002 by Zhang Yong                         *
  9.  *   email                : z-yong163@163.com                              *
  10.  ***************************************************************************/
  11. // RegFinishDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "RegFinishDlg.h"
  16. #include "RegWizard.h"
  17. #include "myicqDlg.h"
  18. #include "serversession.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CRegFinishDlg property page
  26. IMPLEMENT_DYNCREATE(CRegFinishDlg, CPropertyPage)
  27. CRegFinishDlg::CRegFinishDlg() : CPropertyPage(CRegFinishDlg::IDD)
  28. {
  29. //{{AFX_DATA_INIT(CRegFinishDlg)
  30. // NOTE: the ClassWizard will add member initialization here
  31. //}}AFX_DATA_INIT
  32. }
  33. CRegFinishDlg::~CRegFinishDlg()
  34. {
  35. }
  36. void CRegFinishDlg::onSendError(uint32 seq)
  37. {
  38. onTimeOut();
  39. }
  40. void CRegFinishDlg::onTimeOut()
  41. {
  42. CString str;
  43. str.LoadString(IDS_FAILED);
  44. SetDlgItemText(IDC_STATUS, str);
  45. str.LoadString(IDS_TIMEOUT);
  46. SetDlgItemText(IDC_STATUS_DETAIL, str);
  47. CRegWizard *wiz = (CRegWizard *) GetParent();
  48. wiz->SetWizardButtons(PSWIZB_BACK | PSWIZB_DISABLEDFINISH);
  49. m_anim.stop();
  50. }
  51. void CRegFinishDlg::onNewUINReply(uint32 uin)
  52. {
  53. CRegWizard *wiz = (CRegWizard *) GetParent();
  54. wiz->uin = uin;
  55. CString str;
  56. if (uin) {
  57. wiz->isFinished = TRUE;
  58. str.LoadString(IDS_FINISHED);
  59. SetDlgItemText(IDC_STATUS, str);
  60. str.Format(IDS_REG_SUCCESS, uin);
  61. SetDlgItemText(IDC_STATUS_DETAIL, str);
  62. CRegWizard *wiz = (CRegWizard *) GetParent();
  63. wiz->SetWizardButtons(PSWIZB_FINISH);
  64. wiz->GetDlgItem(IDCANCEL)->EnableWindow(FALSE);
  65. } else {
  66. str.LoadString(IDS_FAILED);
  67. SetDlgItemText(IDC_STATUS, str);
  68. str.LoadString(IDS_REG_FAILED);
  69. SetDlgItemText(IDC_STATUS_DETAIL, str);
  70. }
  71. m_anim.stop();
  72. }
  73. void CRegFinishDlg::onContactListReply()
  74. {
  75. CRegWizard *wiz = (CRegWizard *) GetParent();
  76. wiz->isFinished = TRUE;
  77. CString str;
  78. str.LoadString(IDS_FINISHED);
  79. SetDlgItemText(IDC_STATUS, str);
  80. str.LoadString(IDS_SUCCESS_CONTACTLIST);
  81. SetDlgItemText(IDC_STATUS_DETAIL, str);
  82. wiz->SetWizardButtons(PSWIZB_FINISH);
  83. m_anim.stop();
  84. serverSession()->logout();
  85. }
  86. void CRegFinishDlg::onLoginReply(uint8 error)
  87. {
  88. CRegWizard *wiz = (CRegWizard *) GetParent();
  89. if (error == LOGIN_SUCCESS)
  90. wiz->seq = serverSession()->getContactList();
  91. else {
  92. CString str;
  93. str.LoadString(IDS_FAILED);
  94. SetDlgItemText(IDC_STATUS, str);
  95. if (error == LOGIN_WRONG_PASSWD)
  96. str.LoadString(IDS_WRONG_PASSWD);
  97. else
  98. str.LoadString(IDS_INVALID_UIN);
  99. SetDlgItemText(IDC_STATUS_DETAIL, str);
  100. wiz->SetWizardButtons(PSWIZB_BACK | PSWIZB_DISABLEDFINISH);
  101. m_anim.stop();
  102. }
  103. }
  104. void CRegFinishDlg::onConnect(bool success)
  105. {
  106. if (success) {
  107. CRegWizard *wiz = (CRegWizard *) GetParent();
  108. if (wiz->modeDlg.m_mode == 0)
  109. wiz->seq = serverSession()->regNewUIN(wiz->basicDlg.m_passwd);
  110. else {
  111. icqLink->myInfo.uin = wiz->modeDlg.m_uin;
  112. wiz->seq = serverSession()->login(wiz->modeDlg.m_passwd);
  113. }
  114. } else
  115. onTimeOut();
  116. }
  117. void CRegFinishDlg::onHostFound(struct in_addr &addr)
  118. {
  119. if (addr.s_addr != INADDR_NONE) {
  120. CRegWizard *wiz = (CRegWizard *) GetParent();
  121. serverSession()->connect(inet_ntoa(addr), wiz->networkDlg.m_port);
  122. } else
  123. onTimeOut();
  124. }
  125. void CRegFinishDlg::resolveHost()
  126. {
  127. CRegWizard *wiz = (CRegWizard *) GetParent();
  128. const char *host = wiz->networkDlg.m_host;
  129. if (wiz->networkDlg.m_useProxy && !wiz->networkDlg.m_proxyResolve)
  130. serverSession()->connect(host, wiz->networkDlg.m_port);
  131. else {
  132. struct in_addr addr;
  133. addr.s_addr = inet_addr(host);
  134. if (addr.s_addr != INADDR_NONE)
  135. onHostFound(addr);
  136. else
  137. ((CIcqDlg *) AfxGetMainWnd())->getHostByName(host);
  138. }
  139. }
  140. void CRegFinishDlg::DoDataExchange(CDataExchange* pDX)
  141. {
  142. CPropertyPage::DoDataExchange(pDX);
  143. //{{AFX_DATA_MAP(CRegFinishDlg)
  144. DDX_Control(pDX, IDC_PIC, m_anim);
  145. //}}AFX_DATA_MAP
  146. }
  147. BEGIN_MESSAGE_MAP(CRegFinishDlg, CPropertyPage)
  148. //{{AFX_MSG_MAP(CRegFinishDlg)
  149. //}}AFX_MSG_MAP
  150. END_MESSAGE_MAP()
  151. /////////////////////////////////////////////////////////////////////////////
  152. // CRegFinishDlg message handlers
  153. BOOL CRegFinishDlg::OnSetActive() 
  154. {
  155. CRegWizard *wiz = (CRegWizard *) GetParent();
  156. wiz->getData(&icqLink->myInfo, &icqLink->options);
  157. wiz->uin = 0;
  158. CString str;
  159. str.LoadString(IDS_PLEASE_WAIT);
  160. SetDlgItemText(IDC_STATUS, str);
  161. str.LoadString(IDS_REG_REGISTERING);
  162. SetDlgItemText(IDC_STATUS_DETAIL, str);
  163. wiz->SetWizardButtons(PSWIZB_DISABLEDFINISH);
  164. m_anim.start();
  165. resolveHost();
  166. return CPropertyPage::OnSetActive();
  167. }
  168. BOOL CRegFinishDlg::OnKillActive() 
  169. {
  170. m_anim.stop();
  171. return CPropertyPage::OnKillActive();
  172. }