home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / mnwizard.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  24.1 KB  |  966 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20.  
  21. #include "property.h"
  22. #include "styles.h"
  23.  
  24. #include "helper.h"
  25. #include "display.h"
  26. #include "dialog.h"
  27.  
  28. #include "secnav.h"
  29. #include "custom.h"
  30. #include "cxabstra.h"
  31.  
  32. #include "mnwizard.h"
  33. #include "mnprefs.h"
  34. #include "prefapi.h"
  35. #include "msgcom.h"
  36. #include "wfemsg.h"
  37.  
  38. #define BUFSZ 1000
  39.  
  40. #ifdef _DEBUG
  41. #undef THIS_FILE
  42. static char BASED_CODE THIS_FILE[] = __FILE__;
  43. #endif
  44.  
  45. extern "C" BOOL IsNumeric(char* pStr);
  46.  
  47. extern "C" BOOL EmailValid(char* pEmail)
  48. {
  49.     if (strlen(pEmail))
  50.     {
  51.         char* pAddress = pEmail;
  52.         while (*pAddress != '\0')
  53.         {
  54.             if (*pAddress == '@' && *(++pAddress) != '\0')
  55.                 return TRUE;
  56.             pAddress++;
  57.         }
  58.         return FALSE;
  59.     }
  60.     else
  61.         return FALSE;
  62. }
  63.  
  64. #ifdef _WIN32
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CCoverPage
  67.  
  68. CCoverPage::CCoverPage(CWnd *pParent)
  69.     : CNetscapePropertyPage(IDD)
  70. {
  71.     //{{AFX_DATA_INIT(CCoverPage)
  72.     //}}AFX_DATA_INIT
  73.     m_pParent = (CMailNewsWizard*)pParent;
  74. }
  75.  
  76. BOOL CCoverPage::OnInitDialog()
  77. {   
  78.     CString text;
  79.     text.LoadString(IDS_WIZARD_COVER);
  80.     SetDlgItemText(IDC_STATIC_TITLE, LPCTSTR(text));
  81.     return CNetscapePropertyPage::OnInitDialog();
  82. }
  83.  
  84. BOOL CCoverPage::OnSetActive()
  85. {
  86.     m_pParent->SetWizardButtons(PSWIZB_NEXT);
  87.     return CNetscapePropertyPage::OnSetActive();
  88. }
  89.  
  90. void CCoverPage::DoDataExchange(CDataExchange* pDX)
  91. {
  92.     CDialog::DoDataExchange(pDX);
  93. }
  94.  
  95. BEGIN_MESSAGE_MAP(CCoverPage, CNetscapePropertyPage)
  96. END_MESSAGE_MAP()
  97.  
  98. /////////////////////////////////////////////////////////////////////////////
  99. // CSendMailPage
  100.  
  101. CSendMailPage::CSendMailPage(CWnd *pParent, BOOL bVerify)
  102.     : CNetscapePropertyPage(IDD)
  103. {
  104.     //{{AFX_DATA_INIT(CSendMailPage)
  105.     //}}AFX_DATA_INIT
  106.     m_pParent = (CMailNewsWizard*)pParent;
  107.     m_bVerify = bVerify;   //No verification on profile wizard
  108. }
  109.  
  110. BOOL CSendMailPage::OnInitDialog()
  111. {
  112.     BOOL ret;
  113.     ret = CNetscapePropertyPage::OnInitDialog();
  114.  
  115.     CString text;
  116.     text.LoadString(IDS_WIZARD_SENDMAIL);
  117.     SetDlgItemText(IDC_STATIC_TITLE, LPCTSTR(text));
  118.  
  119.     char buffer[256];
  120.     int nLen = 255;
  121.  
  122.     if (PREF_NOERROR == PREF_GetCharPref("mail.identity.username", buffer, &nLen))
  123.         SetDlgItemText(IDC_EDIT_NAME, buffer);
  124.     if (PREF_NOERROR == PREF_GetCharPref("mail.identity.useremail", buffer, &nLen))
  125.         SetDlgItemText(IDC_EDIT_ADDRESS, buffer);
  126.     if (PREF_NOERROR == PREF_GetCharPref("network.hosts.smtp_server", buffer, &nLen))
  127.         SetDlgItemText(IDC_EDIT_SMTP_SERVER, buffer);
  128.     return ret;
  129. }
  130.  
  131. BOOL CSendMailPage::OnSetActive()
  132. {
  133.     m_pParent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  134.     return CNetscapePropertyPage::OnSetActive();
  135. }
  136.  
  137. LRESULT CSendMailPage::OnWizardNext()
  138. {
  139.     if (!m_bVerify)
  140.         return 0;
  141.  
  142.     char text[BUFSZ];
  143.     text[0] = '\0';
  144.     int nLen = GetDlgItemText(IDC_EDIT_ADDRESS, text, BUFSZ); 
  145.     if (nLen)
  146.     {
  147.         text[nLen] = '\0';
  148.         if (EmailValid(text))
  149.             return 0;
  150.         else
  151.         {
  152.             AfxMessageBox(IDS_INVALID_EMAIL);
  153.             GetDlgItem(IDC_EDIT_ADDRESS)->SetFocus();
  154.             return -1;
  155.         }
  156.     }
  157.     return 0;
  158. }
  159.  
  160. void CSendMailPage::DoFinish()
  161. {
  162.     char text[BUFSZ];
  163.     text[0] = '\0';
  164.     GetDlgItemText(IDC_EDIT_NAME, text, BUFSZ);
  165.     PREF_SetCharPref("mail.identity.username", text);
  166.     
  167.     text[0] = '\0';
  168.     GetDlgItemText(IDC_EDIT_ADDRESS, text, BUFSZ);  
  169.     PREF_SetCharPref("mail.identity.useremail", text);
  170.  
  171.     text[0] = '\0';
  172.     GetDlgItemText(IDC_EDIT_SMTP_SERVER, text, BUFSZ); 
  173.     PREF_SetCharPref("network.hosts.smtp_server", text);
  174. }
  175.  
  176. void CSendMailPage::DoDataExchange(CDataExchange* pDX)
  177. {
  178.     CDialog::DoDataExchange(pDX);
  179. }
  180.  
  181. BEGIN_MESSAGE_MAP(CSendMailPage, CNetscapePropertyPage)
  182. END_MESSAGE_MAP()
  183.  
  184. /////////////////////////////////////////////////////////////////////////////
  185. // CReceiveMailPage
  186.  
  187. CReceiveMailPage::CReceiveMailPage(CWnd *pParent, BOOL bVerify)
  188.     : CNetscapePropertyPage(IDD)
  189. {
  190.     //{{AFX_DATA_INIT(CReceiveMailPage)
  191.     //}}AFX_DATA_INIT
  192.     m_pParent = (CMailNewsWizard*)pParent;
  193.     m_bVerify = bVerify;   //No verification on profile wizard
  194. }
  195.  
  196. BOOL CReceiveMailPage::OnInitDialog()
  197. {
  198.     BOOL ret;
  199.     ret = CNetscapePropertyPage::OnInitDialog();
  200.  
  201.     CString text;
  202.     text.LoadString(IDS_WIZARD_READMAIL);
  203.     SetDlgItemText(IDC_STATIC_TITLE, LPCTSTR(text));
  204.  
  205.     char buffer[256];
  206.     int nLen = 255;
  207.  
  208.     if (PREF_NOERROR == PREF_GetCharPref("mail.pop_name", buffer, &nLen))
  209.         SetDlgItemText(IDC_EDIT_USER_NAME, buffer);
  210.     if (PREF_NOERROR == PREF_GetCharPref("network.hosts.pop_server", buffer, &nLen))
  211.     {
  212.         int nameLen = strlen(buffer);
  213.         if (nameLen)
  214.             SetDlgItemText(IDC_EDIT_MAIL_SERVER, buffer);
  215.         else
  216.         {
  217.             if (PREF_NOERROR == PREF_GetCharPref("network.hosts.smtp_server", buffer, &nLen))
  218.                 SetDlgItemText(IDC_EDIT_MAIL_SERVER, buffer);
  219.         }
  220.     }
  221.     else
  222.     {
  223.         if (PREF_NOERROR == PREF_GetCharPref("network.hosts.smtp_server", buffer, &nLen))
  224.             SetDlgItemText(IDC_EDIT_MAIL_SERVER, buffer);
  225.     }
  226.     
  227.     long prefLong = MSG_Pop3;
  228.     PREF_GetIntPref("mail.server_type",&prefLong);
  229.     if (prefLong == MSG_Imap4)
  230.         CheckDlgButton(IDC_RADIO_IMAP, TRUE);
  231.     else
  232.         CheckDlgButton(IDC_RADIO_POP, TRUE);
  233.     return ret;
  234. }
  235.  
  236. BOOL CReceiveMailPage::OnSetActive()
  237. {
  238.     m_pParent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  239.     return CNetscapePropertyPage::OnSetActive();
  240. }
  241.  
  242. LRESULT CReceiveMailPage::OnWizardNext()
  243. {
  244.     if (!m_bVerify)
  245.         return 0;
  246.  
  247.     char text[BUFSZ];
  248.     text[0] = '\0';
  249.     int nLen = GetDlgItemText(IDC_EDIT_USER_NAME, text, BUFSZ); 
  250.     
  251.     if (nLen)
  252.     {
  253.         text[0] = '\0';
  254.         nLen = GetDlgItemText(IDC_EDIT_MAIL_SERVER, text, BUFSZ); 
  255.         if (nLen)
  256.             return 0;
  257.         else
  258.         {
  259.             AfxMessageBox(IDS_EMPTY_STRING);
  260.             GetDlgItem(IDC_EDIT_MAIL_SERVER)->SetFocus();
  261.             return -1;
  262.         }
  263.     }
  264.     else
  265.     {
  266.         AfxMessageBox(IDS_EMPTY_STRING);
  267.         GetDlgItem(IDC_EDIT_USER_NAME)->SetFocus();
  268.         return -1;
  269.     }
  270. }
  271.  
  272. void CReceiveMailPage::DoFinish()
  273. {
  274.     char text[BUFSZ];
  275.     text[0] = '\0';
  276.     GetDlgItemText(IDC_EDIT_USER_NAME, text, BUFSZ);
  277.     PREF_SetCharPref("mail.pop_name", text);
  278.     
  279.     text[0] = '\0';
  280.     GetDlgItemText(IDC_EDIT_MAIL_SERVER, text, BUFSZ);  
  281.     PREF_SetCharPref("network.hosts.pop_server", text);
  282.  
  283.     if (IsDlgButtonChecked(IDC_RADIO_IMAP)) 
  284.         PREF_SetIntPref("mail.server_type", (int32)MSG_Imap4);
  285.     else
  286.         PREF_SetIntPref("mail.server_type", (int32)MSG_Pop3);
  287. }
  288.  
  289. void CReceiveMailPage::DoDataExchange(CDataExchange* pDX)
  290. {
  291.     CDialog::DoDataExchange(pDX);
  292. }
  293.  
  294. BEGIN_MESSAGE_MAP(CReceiveMailPage, CNetscapePropertyPage)
  295. END_MESSAGE_MAP()
  296.  
  297. /////////////////////////////////////////////////////////////////////////////
  298. // CReadNewsPage
  299.  
  300. CReadNewsPage::CReadNewsPage(CWnd *pParent)
  301.     : CNetscapePropertyPage(IDD)
  302. {
  303.     //{{AFX_DATA_INIT(CReadNewsPage)
  304.     //}}AFX_DATA_INIT
  305.     m_pParent = (CMailNewsWizard*)pParent;
  306.     m_bPEFinish = FALSE;   
  307. }
  308.  
  309. CReadNewsPage::~CReadNewsPage()
  310. {
  311. }
  312.  
  313. BOOL CReadNewsPage::OnInitDialog()
  314. {
  315.     BOOL ret;
  316.     ret = CNetscapePropertyPage::OnInitDialog();
  317.  
  318.     CString text;
  319.     text.LoadString(IDS_WIZARD_READNEWS);
  320.     SetDlgItemText(IDC_STATIC_TITLE, LPCTSTR(text));
  321.  
  322.     char buffer[256];
  323.     int nLen = 255;
  324.  
  325.     if (PREF_NOERROR == PREF_GetCharPref("network.hosts.nntp_server", buffer, &nLen))
  326.         SetDlgItemText(IDC_EDIT_NEWS_SERVER, buffer);
  327.     ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetLimitText(5);
  328.     if (strlen(buffer) > 0)
  329.     {
  330.         XP_Bool bSecure;
  331.         int32    lPort;
  332.         char    szPort[16];
  333.  
  334.         PREF_GetBoolPref("news.server_is_secure", &bSecure);
  335.         CheckDlgButton(IDC_SECURE, bSecure);
  336.         PREF_GetIntPref("news.server_port", &lPort);
  337.         sprintf(szPort, "%ld", lPort);
  338.         SetDlgItemText(IDC_EDIT_PORT, szPort);
  339.     }
  340.     else
  341.     {
  342.         SetDlgItemInt(IDC_EDIT_PORT, NEWS_PORT);
  343.     }
  344.     if(theApp.m_bPEEnabled && !m_bPEFinish)
  345.     {
  346.         text.LoadString(IDS_PEMUC_READNEWS_FINISH);
  347.         GetDlgItem(IDC_MNWIZ_READNEWS_FINISH)->SetWindowText(text);
  348.     }
  349.  
  350.     return ret;
  351. }
  352.  
  353. BOOL CReadNewsPage::OnSetActive()
  354. {
  355.     if(theApp.m_bPEEnabled && (!m_bPEFinish))
  356.         m_pParent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  357.     else
  358.         m_pParent->SetWizardButtons(PSWIZB_FINISH | PSWIZB_BACK);
  359.     return CNetscapePropertyPage::OnSetActive();
  360. }
  361.  
  362. BOOL CReadNewsPage::DoFinish()
  363. {
  364.     char    szHostName[MSG_MAXGROUPNAMELENGTH];
  365.     XP_Bool    bIsSecure = FALSE;
  366.     int32    lnPort;
  367.     char    port[16];
  368.  
  369.     szHostName[0] = '\0';
  370.     int nLen = GetDlgItemText(IDC_EDIT_NEWS_SERVER, szHostName, 
  371.                                MSG_MAXGROUPNAMELENGTH);
  372.     PREF_SetCharPref("network.hosts.nntp_server", szHostName);
  373.  
  374.     if (nLen == 0)
  375.     {
  376.         PREF_SetBoolPref("news.server_is_secure", FALSE);
  377.         PREF_SetIntPref("news.server_port", NEWS_PORT);
  378.         return TRUE;
  379.     }
  380.  
  381.     if (IsDlgButtonChecked(IDC_SECURE))    
  382.         bIsSecure = TRUE;
  383.     if (GetDlgItemText(IDC_EDIT_PORT, port, 16))
  384.     {
  385.         int32 lPort = atol(port);
  386.         if (lPort < 0 || lPort> MAX_PORT_NUMBER)
  387.         {
  388.             AfxMessageBox(IDS_PORT_RANGE);
  389.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetFocus();
  390.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetSel((DWORD)MAKELONG(0, -1));
  391.             return FALSE;        
  392.         }
  393.         if (!::IsNumeric(port))
  394.         {
  395.             AfxMessageBox(IDS_NUMBERS_ONLY);
  396.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetFocus();
  397.             ((CEdit*)GetDlgItem(IDC_EDIT_PORT))->SetSel((DWORD)MAKELONG(0, -1));
  398.             return FALSE;
  399.         }
  400.         lnPort = lPort;
  401.     }
  402.     else
  403.     {
  404.         if (bIsSecure)
  405.             lnPort = SECURE_NEWS_PORT;
  406.         else
  407.             lnPort = NEWS_PORT;
  408.     }
  409.  
  410.     PREF_SetBoolPref("news.server_is_secure", bIsSecure);
  411.     PREF_SetIntPref("news.server_port", lnPort);
  412.     return TRUE;
  413. }
  414.  
  415. void CReadNewsPage::SetFinish(BOOL nFinish)
  416. {
  417.     m_bPEFinish = nFinish;
  418.     if(theApp.m_bPEEnabled     && ::IsWindow(this->GetSafeHwnd()))
  419.     {
  420.         CString    text;
  421.         if(!m_bPEFinish )
  422.             text.LoadString(IDS_PEMUC_READNEWS_FINISH);
  423.         else 
  424.             text.LoadString(IDS_CLICK_FINISH);
  425.  
  426.         GetDlgItem(IDC_MNWIZ_READNEWS_FINISH)->SetWindowText(text);
  427.     }
  428. }
  429.  
  430. void CReadNewsPage::DoDataExchange(CDataExchange* pDX)
  431. {
  432.     CDialog::DoDataExchange(pDX);
  433. }
  434.  
  435. void CReadNewsPage::OnCheckSecure() 
  436. {
  437.     char port[16];
  438.     BOOL bIsSecure;
  439.  
  440.     if (IsDlgButtonChecked(IDC_SECURE))
  441.         bIsSecure = TRUE;
  442.     else
  443.         bIsSecure = FALSE;
  444.     if (GetDlgItemText(IDC_EDIT_PORT, port, 16) == 0)
  445.     {
  446.         if (bIsSecure)
  447.             SetDlgItemInt(IDC_EDIT_PORT, SECURE_NEWS_PORT);
  448.         else
  449.             SetDlgItemInt(IDC_EDIT_PORT, NEWS_PORT);
  450.     }
  451.     else
  452.     {
  453.         int32 lPort = atol(port);
  454.         if (bIsSecure && lPort == NEWS_PORT)
  455.             SetDlgItemInt(IDC_EDIT_PORT, SECURE_NEWS_PORT);
  456.         else  if (!bIsSecure && lPort == SECURE_NEWS_PORT)
  457.             SetDlgItemInt(IDC_EDIT_PORT, NEWS_PORT);
  458.     }
  459. }
  460.  
  461. BEGIN_MESSAGE_MAP(CReadNewsPage, CNetscapePropertyPage)
  462.     ON_BN_CLICKED(IDC_SECURE, OnCheckSecure)
  463. END_MESSAGE_MAP()
  464.  
  465. /////////////////////////////////////////////////////////////////////////////
  466. // CMailNewsWizard           
  467. CMailNewsWizard::CMailNewsWizard(CWnd *pParent)
  468.     : CNetscapePropertySheet("", pParent)
  469. {
  470.     m_pCoverPage = new CCoverPage(this);
  471.     m_pSendMailPage = new CSendMailPage(this, TRUE); 
  472.     m_pReceiveMailPage = new CReceiveMailPage(this);
  473.     m_pReadNewsPage = new CReadNewsPage(this);
  474.  
  475.     AddPage(m_pCoverPage);      
  476.     AddPage(m_pSendMailPage);
  477.     AddPage(m_pReceiveMailPage);
  478.     AddPage(m_pReadNewsPage);
  479.     SetWizardMode();
  480. }
  481.  
  482. CMailNewsWizard::~CMailNewsWizard()
  483. {
  484.     if (m_pCoverPage)
  485.         delete m_pCoverPage;
  486.     if (m_pSendMailPage)
  487.         delete m_pSendMailPage;
  488.     if (m_pReceiveMailPage)
  489.         delete m_pReceiveMailPage;   
  490.     if (m_pReadNewsPage)
  491.         delete m_pReadNewsPage;   
  492. }
  493.  
  494. BOOL CMailNewsWizard::OnInitDialog()
  495. {
  496.     BOOL ret = CNetscapePropertySheet::OnInitDialog();
  497.  
  498.     GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);
  499.  
  500.     return ret;
  501. }
  502.  
  503. void CMailNewsWizard::DoFinish()
  504. {
  505.     BOOL bFinished = TRUE;
  506.     if (m_pSendMailPage && ::IsWindow(m_pSendMailPage->GetSafeHwnd()))
  507.         m_pSendMailPage->DoFinish();
  508.     if (m_pReceiveMailPage && ::IsWindow(m_pReceiveMailPage->GetSafeHwnd()))
  509.         m_pReceiveMailPage->DoFinish();   
  510.     if (m_pReadNewsPage && ::IsWindow(m_pReadNewsPage->GetSafeHwnd()))
  511.         bFinished = m_pReadNewsPage->DoFinish(); 
  512.     if (bFinished)
  513.     {
  514.         PressButton(PSBTN_FINISH);
  515.         PREF_SavePrefFile();
  516.     }
  517. }
  518.  
  519. BEGIN_MESSAGE_MAP(CMailNewsWizard, CNetscapePropertySheet)
  520.     ON_BN_CLICKED(ID_WIZFINISH, DoFinish)
  521. END_MESSAGE_MAP()
  522.  
  523. #else  //Win16 Code 
  524.  
  525. /////////////////////////////////////////////////////////////////////////////
  526. // CMailNewsWizard           
  527. CMailNewsWizard::CMailNewsWizard(CWnd *pParent)
  528.     : CDialog(IDD, pParent)
  529. {
  530.     m_nCurrentPage = ID_PAGE_COVER;
  531.  
  532.     char* pPrefStr;
  533.  
  534.     pPrefStr = NULL;
  535.     PREF_CopyCharPref("mail.identity.username", &pPrefStr);
  536.     m_szFullName = pPrefStr;
  537.     if (pPrefStr) XP_FREE(pPrefStr); 
  538.     
  539.     pPrefStr = NULL;
  540.     PREF_CopyCharPref("mail.identity.useremail", &pPrefStr);
  541.     m_szEmail = pPrefStr;
  542.     if (pPrefStr) XP_FREE(pPrefStr); 
  543.  
  544.     pPrefStr = NULL;
  545.     PREF_CopyCharPref("network.hosts.smtp_server", &pPrefStr);
  546.     m_szMailServer = pPrefStr;
  547.     if (pPrefStr) XP_FREE(pPrefStr); 
  548.  
  549.     pPrefStr = NULL;
  550.     PREF_CopyCharPref("mail.pop_name", &pPrefStr);
  551.     m_szPopName = pPrefStr;
  552.     if (pPrefStr) XP_FREE(pPrefStr); 
  553.  
  554.     pPrefStr = NULL;
  555.     PREF_CopyCharPref("network.hosts.pop_server", &pPrefStr);
  556.     m_szInMailServer = pPrefStr;
  557.     if (pPrefStr) XP_FREE(pPrefStr); 
  558.  
  559.     long prefLong = MSG_Pop3;
  560.     PREF_GetIntPref("mail.server_type",&prefLong);
  561.     if (prefLong == MSG_Imap4)
  562.         m_bUseIMAP = TRUE;
  563.     else
  564.         m_bUseIMAP = FALSE;
  565.  
  566.     pPrefStr = NULL;
  567.     PREF_CopyCharPref("network.hosts.nntp_server", &pPrefStr);
  568.     m_szNewsServer = pPrefStr;
  569.     if (pPrefStr) XP_FREE(pPrefStr); 
  570.  
  571.     if (m_szNewsServer.IsEmpty())
  572.     {
  573.         m_bIsSecure = FALSE;
  574.         m_lPort = NEWS_PORT;
  575.     }
  576.     else
  577.     {
  578.         PREF_GetBoolPref("news.server_is_secure", &m_bIsSecure);
  579.         PREF_GetIntPref("news.server_port", &m_lPort);
  580.     }
  581. }
  582.  
  583. void CMailNewsWizard::DoDataExchange(CDataExchange* pDX)
  584. {
  585.     CDialog::DoDataExchange(pDX);
  586. }
  587.  
  588. BOOL CMailNewsWizard::OnInitDialog()
  589. {
  590.     GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);
  591.     GetDlgItem(IDC_STATIC_EG1)->ShowWindow(SW_HIDE);
  592.     GetDlgItem(IDC_STATIC2)->ShowWindow(SW_HIDE);
  593.     GetDlgItem(IDC_EDIT2)->ShowWindow(SW_HIDE);
  594.     GetDlgItem(IDC_STATIC_EG2)->ShowWindow(SW_HIDE);
  595.     GetDlgItem(IDC_STATIC3)->ShowWindow(SW_HIDE);
  596.     GetDlgItem(IDC_EDIT3)->ShowWindow(SW_HIDE);
  597.     GetDlgItem(IDC_READMAIL_POP)->ShowWindow(SW_HIDE);
  598.     GetDlgItem(IDC_READMAIL_IMAP)->ShowWindow(SW_HIDE);
  599.     GetDlgItem(IDC_STATIC5)->ShowWindow(SW_HIDE);
  600.     GetDlgItem(IDC_SECURE)->ShowWindow(SW_HIDE);
  601.  
  602.     GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(FALSE);
  603.  
  604.     SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_COVER);
  605.     SetControlText(IDC_STATIC1, IDS_COVER_STATIC1);
  606.     return CDialog::OnInitDialog();
  607. }
  608.  
  609. void CMailNewsWizard::DoBack()
  610. {
  611.     m_nCurrentPage -= 1;
  612.     switch     (m_nCurrentPage)
  613.     {
  614.     case ID_PAGE_COVER:        // 1st page
  615.         ShowHideSendMailControls(SW_HIDE); 
  616.         ShowCoverPage();
  617.         GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(FALSE);
  618.         break;
  619.     case ID_PAGE_SENDMAIL:  // 2nd page
  620.         ShowHideReadMailControls(SW_HIDE);
  621.         ShowSendMailPage();
  622.         break;
  623.     case ID_PAGE_READMAIL:    // 3rd page
  624.         SetControlText(IDOK, IDS_NEXT);
  625.         ShowHideReadNewsControls(SW_HIDE);
  626.         ShowReadMailPage();
  627.         break;
  628.     default:
  629.         break;
  630.     }
  631. }
  632.  
  633. void CMailNewsWizard::DoNext()
  634. {
  635.     char text[BUFSZ];
  636.     int nLen = 0;
  637.  
  638.     m_nCurrentPage += 1;
  639.     switch     (m_nCurrentPage)
  640.     {
  641.     case ID_PAGE_SENDMAIL:  // 2nd page
  642.         ShowSendMailPage();
  643.         GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(TRUE);
  644.         break;
  645.     case ID_PAGE_READMAIL:    // 3rd page
  646.         nLen = GetDlgItemText(IDC_EDIT2, text, BUFSZ); 
  647.         text[nLen] = '\0';
  648.         if (nLen == 0 || (nLen && EmailValid(text)))
  649.         {
  650.             ShowHideSendMailControls(SW_HIDE); 
  651.             if (m_szInMailServer.IsEmpty())
  652.                 m_szInMailServer = m_szMailServer;
  653.             ShowReadMailPage();
  654.         }
  655.         else
  656.         {
  657.             AfxMessageBox(IDS_INVALID_EMAIL);
  658.             GetDlgItem(IDC_EDIT2)->SetFocus();
  659.             m_nCurrentPage -= 1;
  660.         }
  661.         break;
  662.     case ID_PAGE_READNEWS:    // 4th page
  663.         SetControlText(IDOK, IDS_FINISH);
  664.         ShowHideReadMailControls(SW_HIDE); 
  665.         ShowReadNewsPage();
  666.         break;
  667.     case ID_PAGE_FINISH:    // done, save value
  668.         if (DoFinish())
  669.             EndDialog(IDOK);
  670.         break;
  671.     default:
  672.         break;
  673.     }
  674. }
  675.  
  676. BOOL CMailNewsWizard::CheckValidText() 
  677. {
  678.     char text[BUFSZ];
  679.     text[0] = '\0';
  680.     int nLen = GetDlgItemText(IDC_EDIT1, text, BUFSZ); 
  681.     
  682.     if (nLen)
  683.     {
  684.         text[0] = '\0';
  685.         nLen = GetDlgItemText(IDC_EDIT2, text, BUFSZ); 
  686.         if (nLen)
  687.             return TRUE;
  688.         else
  689.         {
  690.             AfxMessageBox(IDS_EMPTY_STRING);
  691.             GetDlgItem(IDC_EDIT2)->SetFocus();
  692.             return FALSE;
  693.         }
  694.     }
  695.     else
  696.     {
  697.         AfxMessageBox(IDS_EMPTY_STRING);
  698.         GetDlgItem(IDC_EDIT1)->SetFocus();
  699.         return FALSE;
  700.     }
  701. }
  702.  
  703. void CMailNewsWizard::SetControlText(int nID, int nStringID) 
  704. {
  705.     CString text;
  706.     text.LoadString(nStringID);
  707.     SetDlgItemText(nID, LPCTSTR(text));
  708. }
  709.  
  710. void CMailNewsWizard::ShowCoverPage() 
  711. {
  712.     GetDlgItem(IDC_STATIC5)->ShowWindow(SW_HIDE);
  713.     SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_COVER);
  714.     SetControlText(IDC_STATIC1, IDS_COVER_STATIC1);
  715. }
  716.  
  717. void CMailNewsWizard::ShowSendMailPage()
  718. {
  719.     ShowHideSendMailControls(SW_SHOW);
  720.     SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_SENDMAIL);
  721.     SetControlText(IDC_STATIC1, IDS_SENDMAIL_STATIC1);
  722.     SetControlText(IDC_STATIC_EG1, IDS_SENDMAIL_EG1);
  723.     SetControlText(IDC_STATIC2, IDS_SENDMAIL_STATIC2);
  724.     SetControlText(IDC_STATIC_EG2, IDS_SENDMAIL_EG2);
  725.     SetControlText(IDC_STATIC3, IDS_SENDMAIL_STATIC3);
  726.     SetControlText(IDC_STATIC5, IDS_SENDREADMAIL_STATIC5);
  727. }
  728.  
  729. void CMailNewsWizard::ShowHideSendMailControls(int nShowCmd)
  730. {
  731.     GetDlgItem(IDC_EDIT1)->ShowWindow(nShowCmd);
  732.     GetDlgItem(IDC_STATIC_EG1)->ShowWindow(nShowCmd);
  733.     GetDlgItem(IDC_STATIC2)->ShowWindow(nShowCmd);
  734.     GetDlgItem(IDC_EDIT2)->ShowWindow(nShowCmd);
  735.     GetDlgItem(IDC_STATIC_EG2)->ShowWindow(nShowCmd);
  736.     GetDlgItem(IDC_STATIC3)->ShowWindow(nShowCmd);
  737.     GetDlgItem(IDC_EDIT3)->ShowWindow(nShowCmd);
  738.     GetDlgItem(IDC_STATIC5)->ShowWindow(nShowCmd);
  739.     if (nShowCmd == SW_SHOW)
  740.     {    // init value
  741.         SetDlgItemText(IDC_EDIT1, m_szFullName);
  742.         SetDlgItemText(IDC_EDIT2, m_szEmail);
  743.         SetDlgItemText(IDC_EDIT3, m_szMailServer);
  744.     }
  745.     else
  746.     {    // save value
  747.         char text[BUFSZ];
  748.         if (GetDlgItemText(IDC_EDIT1, text, BUFSZ)) 
  749.             m_szFullName = text;
  750.         else 
  751.             m_szFullName = "";
  752.         if (GetDlgItemText(IDC_EDIT2, text, BUFSZ))  
  753.             m_szEmail = text;
  754.         else
  755.             m_szEmail = "";
  756.         if (GetDlgItemText(IDC_EDIT3, text, BUFSZ))  
  757.             m_szMailServer = text;
  758.         else 
  759.             m_szMailServer = "";
  760.     }
  761. }
  762.  
  763. void CMailNewsWizard::ShowReadMailPage()
  764. {
  765.     ShowHideReadMailControls(SW_SHOW);
  766.     SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_READMAIL);
  767.     SetControlText(IDC_STATIC1, IDS_READMAIL_STATIC1);
  768.     SetControlText(IDC_STATIC_EG1, IDS_READMAIL_EG1);
  769.     SetControlText(IDC_STATIC2, IDS_READMAIL_STATIC2);
  770.     SetControlText(IDC_STATIC3, IDS_READMAIL_STATIC3);
  771.     SetControlText(IDC_STATIC5, IDS_SENDREADMAIL_STATIC5);
  772. }
  773.  
  774. void CMailNewsWizard::ShowHideReadMailControls(int nShowCmd)
  775. {
  776.     GetDlgItem(IDC_EDIT1)->ShowWindow(nShowCmd);
  777.     GetDlgItem(IDC_STATIC_EG1)->ShowWindow(nShowCmd);
  778.     GetDlgItem(IDC_STATIC2)->ShowWindow(nShowCmd);
  779.     GetDlgItem(IDC_EDIT2)->ShowWindow(nShowCmd);
  780.     GetDlgItem(IDC_STATIC3)->ShowWindow(nShowCmd);
  781.     GetDlgItem(IDC_READMAIL_POP)->ShowWindow(nShowCmd);
  782.     GetDlgItem(IDC_READMAIL_IMAP)->ShowWindow(nShowCmd);
  783.     GetDlgItem(IDC_STATIC5)->ShowWindow(nShowCmd);
  784.     if (nShowCmd == SW_SHOW)
  785.     {    // init value
  786.         SetDlgItemText(IDC_EDIT1, m_szPopName);
  787.         SetDlgItemText(IDC_EDIT2, m_szInMailServer);
  788.         if (m_bUseIMAP)
  789.             ((CButton*)GetDlgItem(IDC_READMAIL_IMAP))->SetCheck(TRUE);
  790.         else
  791.             ((CButton*)GetDlgItem(IDC_READMAIL_POP))->SetCheck(TRUE);
  792.     }
  793.     else
  794.     {    // save value
  795.         char text[BUFSZ];
  796.  
  797.         m_bUseIMAP = FALSE;
  798.         if (GetDlgItemText(IDC_EDIT1, text, BUFSZ))  
  799.             m_szPopName = text;
  800.         else 
  801.             m_szPopName = "";
  802.         if (GetDlgItemText(IDC_EDIT2, text, BUFSZ)) 
  803.             m_szInMailServer = text;
  804.         else
  805.             m_szInMailServer = "";
  806.         if (IsDlgButtonChecked(IDC_READMAIL_IMAP)) 
  807.             m_bUseIMAP = TRUE;
  808.     }
  809. }
  810.  
  811. void CMailNewsWizard::ShowReadNewsPage()
  812. {
  813.     ShowHideReadNewsControls(SW_SHOW);
  814.     SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_READNEWS);
  815.     SetControlText(IDC_STATIC1, IDS_READNEWS_STATIC1);
  816.     SetControlText(IDC_STATIC2, IDS_READNEWS_STATIC2);
  817.     SetControlText(IDC_STATIC5, IDS_READNEWS_STATIC5);
  818. }
  819.  
  820. void CMailNewsWizard::ShowHideReadNewsControls(int nShowCmd)
  821. {
  822.     GetDlgItem(IDC_EDIT1)->ShowWindow(nShowCmd);
  823.     GetDlgItem(IDC_STATIC2)->ShowWindow(nShowCmd);
  824.     GetDlgItem(IDC_EDIT2)->ShowWindow(nShowCmd);
  825.     GetDlgItem(IDC_STATIC5)->ShowWindow(nShowCmd);
  826.     GetDlgItem(IDC_SECURE)->ShowWindow(nShowCmd);
  827.     if (nShowCmd == SW_SHOW)
  828.     {    // init value
  829.         char szPort[16];
  830.         SetDlgItemText(IDC_EDIT1, m_szNewsServer); 
  831.         sprintf(szPort, "%ld", m_lPort);
  832.         SetDlgItemText(IDC_EDIT2, szPort);
  833.         if (m_bIsSecure)
  834.             ((CButton*)GetDlgItem(IDC_SECURE))->SetCheck(TRUE);
  835.         else
  836.             ((CButton*)GetDlgItem(IDC_SECURE))->SetCheck(FALSE);
  837.     }
  838.     else
  839.     {    // save value
  840.         char text[BUFSZ];
  841.         if(m_nNewsServerLen = GetDlgItemText(IDC_EDIT1, text, BUFSZ)) 
  842.             m_szNewsServer = text;
  843.         else 
  844.             m_szNewsServer = "";
  845.         if (IsDlgButtonChecked(IDC_SECURE)) 
  846.             m_bIsSecure = TRUE;
  847.         else
  848.             m_bIsSecure = FALSE;
  849.         if (GetDlgItemText(IDC_EDIT2, text, BUFSZ))
  850.             m_lPort = atol(text);
  851.         else
  852.         {
  853.             if (m_bIsSecure)
  854.                 m_lPort = SECURE_NEWS_PORT;
  855.             else
  856.                 m_lPort = NEWS_PORT;
  857.         }
  858.     }
  859. }
  860.  
  861. BOOL CMailNewsWizard::DoFinish()
  862. {
  863.     char text[BUFSZ], szPort[10];
  864.     int  nPortLen = 0;
  865.  
  866.     if (m_nNewsServerLen = GetDlgItemText(IDC_EDIT1, text, BUFSZ)) 
  867.         m_szNewsServer = text;
  868.     else 
  869.         m_szNewsServer = "";
  870.  
  871.     if (IsDlgButtonChecked(IDC_SECURE)) 
  872.         m_bIsSecure = TRUE;
  873.     else
  874.         m_bIsSecure = FALSE;
  875.     if (nPortLen = GetDlgItemText(IDC_EDIT2, szPort, 10) > 0)
  876.         m_lPort = atol(szPort);
  877.     else
  878.     {
  879.         if (m_bIsSecure)
  880.             m_lPort = SECURE_NEWS_PORT;
  881.         else
  882.             m_lPort = NEWS_PORT;
  883.     }
  884.  
  885.     if (m_nNewsServerLen && nPortLen)
  886.     {
  887.         if (m_lPort < 0 || m_lPort> MAX_PORT_NUMBER)
  888.         {
  889.             AfxMessageBox(IDS_PORT_RANGE);
  890.             ((CEdit*)GetDlgItem(IDC_EDIT2))->SetFocus();
  891.             ((CEdit*)GetDlgItem(IDC_EDIT2))->SetSel((DWORD)MAKELONG(0, -1));
  892.             return FALSE;        
  893.         }
  894.         if (!::IsNumeric(szPort))
  895.         {
  896.             AfxMessageBox(IDS_NUMBERS_ONLY);
  897.             ((CEdit*)GetDlgItem(IDC_EDIT2))->SetFocus();
  898.             ((CEdit*)GetDlgItem(IDC_EDIT2))->SetSel((DWORD)MAKELONG(0, -1));
  899.             return FALSE;
  900.         }
  901.     }
  902.  
  903.     if (m_nNewsServerLen)
  904.     {
  905.         PREF_SetBoolPref("news.server_is_secure", m_bIsSecure);
  906.         PREF_SetIntPref("news.server_port", m_lPort);
  907.     }
  908.     else
  909.     {
  910.         PREF_SetBoolPref("news.server_is_secure", FALSE);
  911.         PREF_SetIntPref("news.server_port", NEWS_PORT);
  912.     }
  913.  
  914.     PREF_SetCharPref("mail.identity.username", LPCTSTR(m_szFullName));
  915.     PREF_SetCharPref("mail.identity.useremail", LPCTSTR(m_szEmail));
  916.     PREF_SetCharPref("network.hosts.smtp_server", LPCTSTR(m_szMailServer));
  917.  
  918.     PREF_SetCharPref("mail.pop_name", LPCTSTR(m_szPopName));
  919.     PREF_SetCharPref("network.hosts.pop_server", LPCTSTR(m_szInMailServer));
  920.  
  921.     long imapPref = m_bUseIMAP ? MSG_Imap4 : MSG_Pop3;
  922.     PREF_SetIntPref("mail.server_type", imapPref);
  923.  
  924.     PREF_SetCharPref("network.hosts.nntp_server", LPCTSTR(m_szNewsServer));
  925.  
  926.     PREF_SavePrefFile();
  927.  
  928.     return TRUE;
  929. }
  930.  
  931. void CMailNewsWizard::OnCheckSecure()
  932. {
  933.     char port[16];
  934.     BOOL bIsSecure;
  935.  
  936.     if (IsDlgButtonChecked(IDC_SECURE))
  937.         bIsSecure = TRUE;
  938.     else
  939.         bIsSecure = FALSE;
  940.     if (GetDlgItemText(IDC_EDIT2, port, 16) == 0)
  941.     {
  942.         if (bIsSecure)
  943.             SetDlgItemInt(IDC_EDIT2, SECURE_NEWS_PORT);
  944.         else
  945.             SetDlgItemInt(IDC_EDIT2, NEWS_PORT);
  946.     }
  947.     else
  948.     {
  949.         int32 lPort = atol(port);
  950.  
  951.         if (bIsSecure && lPort == NEWS_PORT)
  952.             SetDlgItemInt(IDC_EDIT2, SECURE_NEWS_PORT);
  953.         else  if (!bIsSecure && lPort == SECURE_NEWS_PORT)
  954.             SetDlgItemInt(IDC_EDIT2, NEWS_PORT);
  955.     }
  956. }
  957.  
  958. BEGIN_MESSAGE_MAP(CMailNewsWizard, CDialog)
  959.     ON_BN_CLICKED(IDC_BUTTON_BACK, DoBack)
  960.     ON_BN_CLICKED(IDC_SECURE, OnCheckSecure)
  961.     ON_BN_CLICKED(IDOK, DoNext)
  962. END_MESSAGE_MAP()
  963.  
  964. #endif
  965.  
  966.