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

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. // OptionReplyDlg.cpp : implementation file
  12. //
  13. #include "stdafx.h"
  14. #include "myicq.h"
  15. #include "OptionReplyDlg.h"
  16. #include "icqlink.h"
  17. #include "icqdb.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // COptionReplyDlg property page
  25. IMPLEMENT_DYNCREATE(COptionReplyDlg, CPropertyPage)
  26. COptionReplyDlg::COptionReplyDlg() : CPropertyPage(COptionReplyDlg::IDD)
  27. {
  28. //{{AFX_DATA_INIT(COptionReplyDlg)
  29. //}}AFX_DATA_INIT
  30. curAutoReply = -1;
  31. curQuickReply = -1;
  32. IcqOption &options = icqLink->options;
  33. m_autoSwitchStatus = options.flags.test(UF_AUTO_SWITCH_STATUS);
  34. m_autoCancelAway = options.flags.test(UF_AUTO_CANCEL_AWAY);
  35. switch (options.autoStatus) {
  36. case STATUS_AWAY:
  37. m_autoStatus = 0;
  38. break;
  39. case STATUS_INVIS:
  40. m_autoStatus = 1;
  41. break;
  42. case STATUS_OFFLINE:
  43. m_autoStatus = 2;
  44. break;
  45. }
  46. m_autoStatusTime = options.autoStatusTime;
  47. }
  48. COptionReplyDlg::~COptionReplyDlg()
  49. {
  50. }
  51. void COptionReplyDlg::enableControls(BOOL enable)
  52. {
  53. GetDlgItem(IDC_CHOOSER_AUTO_REPLY)->EnableWindow(enable);
  54. GetDlgItem(IDC_TEXT_AUTO_REPLY)->EnableWindow(enable && m_cmbAutoReply.GetCount());
  55. }
  56. void COptionReplyDlg::DoDataExchange(CDataExchange* pDX)
  57. {
  58. CPropertyPage::DoDataExchange(pDX);
  59. //{{AFX_DATA_MAP(COptionReplyDlg)
  60. DDX_Control(pDX, IDC_CHOOSER_QUICK_REPLY, m_cmbQuickReply);
  61. DDX_Control(pDX, IDC_CHOOSER_AUTO_REPLY, m_cmbAutoReply);
  62. DDX_Check(pDX, IDC_AUTO_SWITCH_STATUS, m_autoSwitchStatus);
  63. DDX_Check(pDX, IDC_AUTO_CANCEL_AWAY, m_autoCancelAway);
  64. DDX_Text(pDX, IDC_AUTO_STATUS_TIME, m_autoStatusTime);
  65. DDX_CBIndex(pDX, IDC_SWITCH_STATUS, m_autoStatus);
  66. //}}AFX_DATA_MAP
  67. }
  68. BEGIN_MESSAGE_MAP(COptionReplyDlg, CPropertyPage)
  69. //{{AFX_MSG_MAP(COptionReplyDlg)
  70. ON_BN_CLICKED(IDC_AUTO_REPLY, OnAutoReply)
  71. ON_BN_CLICKED(IDC_ADD_AUTO_REPLY, OnAddAutoReply)
  72. ON_BN_CLICKED(IDC_DEL_AUTO_REPLY, OnDelAutoReply)
  73. ON_CBN_SELCHANGE(IDC_CHOOSER_AUTO_REPLY, OnSelchangeAutoReply)
  74. ON_BN_CLICKED(IDC_ADD_QUICK_REPLY, OnAddQuickReply)
  75. ON_BN_CLICKED(IDC_DEL_QUICK_REPLY, OnDelQuickReply)
  76. ON_CBN_SELCHANGE(IDC_CHOOSER_QUICK_REPLY, OnSelchangeQuickReply)
  77. ON_BN_CLICKED(IDC_AUTO_SWITCH_STATUS, OnAutoSwitchStatus)
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // COptionReplyDlg message handlers
  82. void COptionReplyDlg::OnAutoReply() 
  83. {
  84. enableControls(IsDlgButtonChecked(IDC_AUTO_REPLY));
  85. }
  86. BOOL COptionReplyDlg::OnInitDialog() 
  87. {
  88. CPropertyPage::OnInitDialog();
  89. OnAutoSwitchStatus();
  90. IcqOption &options = icqLink->options;
  91. int sel = -1;
  92. int i = 0;
  93. StrList l;
  94. IcqDB::loadAutoReply(l);
  95. StrList::iterator it;
  96. for (it = l.begin(); it != l.end(); ++it, ++i) {
  97. CString str = (*it).c_str();
  98. if (sel < 0 && str == options.autoReplyText.c_str())
  99. sel = i;
  100. autoReplyList.AddTail(str);
  101. str.Format("%d", i + 1);
  102. m_cmbAutoReply.AddString(str);
  103. }
  104. m_cmbAutoReply.SetCurSel(sel >= 0 ? sel : 0);
  105. OnSelchangeAutoReply();
  106. l.clear();
  107. IcqDB::loadQuickReply(l);
  108. i = 0;
  109. sel = -1;
  110. for (it = l.begin(); it != l.end(); ++it, ++i) {
  111. CString str = (*it).c_str();
  112. if (sel < 0 && str == options.quickReplyText.c_str())
  113. sel = i;
  114. quickReplyList.AddTail(str);
  115. str.Format("%d", i + 1);
  116. m_cmbQuickReply.AddString(str);
  117. }
  118. m_cmbQuickReply.SetCurSel(sel >= 0 ? sel : 0);
  119. OnSelchangeQuickReply();
  120. bool b = options.flags.test(UF_AUTO_REPLY);
  121. CheckDlgButton(IDC_AUTO_REPLY, b);
  122. enableControls(b);
  123. GetDlgItem(IDC_TEXT_QUICK_REPLY)->EnableWindow(m_cmbQuickReply.GetCount() > 0);
  124. return TRUE;  // return TRUE unless you set the focus to a control
  125.               // EXCEPTION: OCX Property Pages should return FALSE
  126. }
  127. void COptionReplyDlg::OnAddAutoReply() 
  128. {
  129. if (autoReplyList.IsEmpty()) {
  130. GetDlgItem(IDC_DEL_AUTO_REPLY)->EnableWindow();
  131. GetDlgItem(IDC_TEXT_AUTO_REPLY)->EnableWindow();
  132. }
  133. autoReplyList.AddTail("");
  134. int n = m_cmbAutoReply.GetCount();
  135. CString str;
  136. str.Format("%d", n + 1);
  137. int i = m_cmbAutoReply.AddString(str);
  138. m_cmbAutoReply.SetCurSel(i);
  139. OnSelchangeAutoReply();
  140. }
  141. void COptionReplyDlg::OnDelAutoReply() 
  142. {
  143. POSITION pos = autoReplyList.FindIndex(curAutoReply);
  144. if (pos)
  145. autoReplyList.RemoveAt(pos);
  146. if (autoReplyList.IsEmpty()) {
  147. GetDlgItem(IDC_DEL_AUTO_REPLY)->EnableWindow(FALSE);
  148. GetDlgItem(IDC_TEXT_AUTO_REPLY)->EnableWindow(FALSE);
  149. }
  150. int n = m_cmbAutoReply.GetCount();
  151. m_cmbAutoReply.DeleteString(n - 1);
  152. if (curAutoReply > 0)
  153. m_cmbAutoReply.SetCurSel(curAutoReply - 1);
  154. else if (--n <= 0)
  155. m_cmbAutoReply.SetCurSel(-1);
  156. curAutoReply = -1;
  157. OnSelchangeAutoReply();
  158. }
  159. void COptionReplyDlg::OnSelchangeAutoReply() 
  160. {
  161. POSITION pos = autoReplyList.FindIndex(curAutoReply);
  162. if (pos)
  163. GetDlgItemText(IDC_TEXT_AUTO_REPLY, autoReplyList.GetAt(pos));
  164. curAutoReply = m_cmbAutoReply.GetCurSel();
  165. pos = autoReplyList.FindIndex(curAutoReply);
  166. SetDlgItemText(IDC_TEXT_AUTO_REPLY, pos ? autoReplyList.GetAt(pos) : "");
  167. }
  168. void COptionReplyDlg::OnAddQuickReply() 
  169. {
  170. if (quickReplyList.IsEmpty()) {
  171. GetDlgItem(IDC_DEL_QUICK_REPLY)->EnableWindow();
  172. GetDlgItem(IDC_TEXT_QUICK_REPLY)->EnableWindow();
  173. }
  174. quickReplyList.AddTail("");
  175. int n = m_cmbQuickReply.GetCount();
  176. CString str;
  177. str.Format("%d", n + 1);
  178. int i = m_cmbQuickReply.AddString(str);
  179. m_cmbQuickReply.SetCurSel(i);
  180. OnSelchangeQuickReply();
  181. }
  182. void COptionReplyDlg::OnDelQuickReply() 
  183. {
  184. POSITION pos = quickReplyList.FindIndex(curQuickReply);
  185. if (pos)
  186. quickReplyList.RemoveAt(pos);
  187. if (quickReplyList.IsEmpty()) {
  188. GetDlgItem(IDC_DEL_QUICK_REPLY)->EnableWindow(FALSE);
  189. GetDlgItem(IDC_TEXT_QUICK_REPLY)->EnableWindow(FALSE);
  190. }
  191. int n = m_cmbQuickReply.GetCount();
  192. m_cmbQuickReply.DeleteString(n - 1);
  193. if (curQuickReply > 0)
  194. m_cmbQuickReply.SetCurSel(curQuickReply - 1);
  195. else if (--n <= 0)
  196. m_cmbQuickReply.SetCurSel(-1);
  197. curQuickReply = -1;
  198. OnSelchangeQuickReply();
  199. }
  200. void COptionReplyDlg::OnSelchangeQuickReply() 
  201. {
  202. POSITION pos = quickReplyList.FindIndex(curQuickReply);
  203. if (pos)
  204. GetDlgItemText(IDC_TEXT_QUICK_REPLY, quickReplyList.GetAt(pos));
  205. curQuickReply = m_cmbQuickReply.GetCurSel();
  206. pos = quickReplyList.FindIndex(curQuickReply);
  207. SetDlgItemText(IDC_TEXT_QUICK_REPLY, pos ? autoReplyList.GetAt(pos) : "");
  208. }
  209. void COptionReplyDlg::OnOK() 
  210. {
  211. OnSelchangeAutoReply();
  212. OnSelchangeQuickReply();
  213. StrList l;
  214. POSITION pos = autoReplyList.GetHeadPosition();
  215. while (pos)
  216. l.push_back((LPCTSTR) autoReplyList.GetNext(pos));
  217. IcqDB::saveAutoReply(l);
  218. l.clear();
  219. pos = quickReplyList.GetHeadPosition();
  220. while (pos)
  221. l.push_back((LPCTSTR) quickReplyList.GetNext(pos));
  222. IcqDB::saveQuickReply(l);
  223. IcqOption &options = icqLink->options;
  224. options.flags.set(UF_AUTO_REPLY, IsDlgButtonChecked(IDC_AUTO_REPLY));
  225. CString str;
  226. GetDlgItemText(IDC_TEXT_AUTO_REPLY, str);
  227. options.autoReplyText = str;
  228. GetDlgItemText(IDC_TEXT_QUICK_REPLY, str);
  229. options.quickReplyText = str;
  230. options.flags.set(UF_AUTO_SWITCH_STATUS, m_autoSwitchStatus);
  231. options.flags.set(UF_AUTO_CANCEL_AWAY, m_autoCancelAway);
  232. switch (m_autoStatus) {
  233. case 0:
  234. options.autoStatus = STATUS_AWAY;
  235. break;
  236. case 1:
  237. options.autoStatus = STATUS_INVIS;
  238. break;
  239. case 2:
  240. options.autoStatus = STATUS_OFFLINE;
  241. break;
  242. }
  243. options.autoStatusTime = m_autoStatusTime;
  244. CPropertyPage::OnOK();
  245. }
  246. void COptionReplyDlg::OnAutoSwitchStatus() 
  247. {
  248. BOOL b = IsDlgButtonChecked(IDC_AUTO_SWITCH_STATUS);
  249. GetDlgItem(IDC_AUTO_CANCEL_AWAY)->EnableWindow(b);
  250. GetDlgItem(IDC_AUTO_STATUS_TIME)->EnableWindow(b);
  251. GetDlgItem(IDC_SWITCH_STATUS)->EnableWindow(b);
  252. }