home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / setupwiz.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  45.8 KB  |  1,667 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. #include "setupwiz.h"
  32. #include "logindg.h"
  33. #include "prefapi.h"
  34. #include "mnwizard.h"
  35. #include "msgcom.h"
  36. #include "mailmisc.h"
  37. #include "mucproc.h"
  38. #include "profile.h"
  39. #include "mnprefs.h"
  40.  
  41. #define BUFSZ MAX_PATH+1
  42.  
  43. extern "C" BOOL IsNumeric(char* pStr);
  44.  
  45. #ifdef XP_WIN32
  46.  
  47. #ifdef _DEBUG
  48. #undef THIS_FILE
  49. static char BASED_CODE THIS_FILE[] = __FILE__;
  50. #endif
  51.  
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CConfirmPage
  55.  
  56. CConfirmPage::CConfirmPage(CWnd *pParent)
  57.     : CNetscapePropertyPage(IDD)
  58. {
  59.     //{{AFX_DATA_INIT(CIntroPage)
  60.     //}}AFX_DATA_INIT
  61.     m_pParent = (CNewProfileWizard*)pParent;
  62. }
  63.  
  64. CConfirmPage::~CConfirmPage()
  65. {
  66. }
  67.  
  68. BOOL CConfirmPage::OnSetActive()
  69. {
  70.     m_pParent->SetWizardButtons(PSWIZB_FINISH | PSWIZB_BACK);
  71.     return CNetscapePropertyPage::OnSetActive();
  72. }
  73.  
  74. void CConfirmPage::DoDataExchange(CDataExchange* pDX)
  75. {
  76.     CDialog::DoDataExchange(pDX);
  77. }
  78.  
  79. BOOL CConfirmPage::OnInitDialog()
  80. {
  81.     BOOL ret;
  82.     
  83.     ret = CNetscapePropertyPage::OnInitDialog();
  84.  
  85.     CButton * pMove = (CButton *) GetDlgItem(IDC_MOVEFILES);
  86.  
  87.     if (!m_pParent->m_bUpgrade) {
  88.         GetDlgItem(IDC_MOVEFILES)->EnableWindow(FALSE);
  89.         GetDlgItem(IDC_COPYFILES)->EnableWindow(FALSE);
  90.         ((CButton *)GetDlgItem(IDC_IGNOREFILES))->SetCheck(TRUE);
  91.     }
  92.     else if (pMove)
  93.         pMove->SetCheck(TRUE);
  94.  
  95.     return ret;
  96. }
  97.  
  98. int CConfirmPage::DoFinish()
  99. {
  100.     CButton * pMove = (CButton *) GetDlgItem(IDC_MOVEFILES);
  101.     CButton * pCopy = (CButton *) GetDlgItem(IDC_COPYFILES);
  102.     CButton * pIgnore = (CButton *) GetDlgItem(IDC_IGNOREFILES);
  103.     int iMove = TRUE;
  104.     int iCopy = FALSE;
  105.     int iIgnore = FALSE;
  106.  
  107.     if (pMove)
  108.         iMove = pMove->GetCheck();
  109.     if (pCopy)
  110.         iCopy = pCopy->GetCheck();
  111.     if (pIgnore)
  112.         iIgnore = pIgnore->GetCheck();
  113.  
  114.     if (iMove) {
  115.         login_UpdateFilesToNewLocation(m_pParent->m_pProfilePath,m_pParent,FALSE);  // move files
  116.         login_UpdatePreferencesToJavaScript(m_pParent->m_pProfilePath); // upgrade prefs
  117.     } else if (iCopy) {
  118.         login_UpdateFilesToNewLocation(m_pParent->m_pProfilePath,m_pParent,TRUE);  // Copy files
  119.         login_UpdatePreferencesToJavaScript(m_pParent->m_pProfilePath); // upgrade prefs
  120.     } else {
  121.         // just create the directories --
  122.         login_CreateEmptyProfileDir(m_pParent->m_pProfilePath, m_pParent,m_pParent->m_bExistingDir); 
  123.     }
  124.     return TRUE;
  125. }
  126.  
  127. BEGIN_MESSAGE_MAP(CConfirmPage, CNetscapePropertyPage)
  128. END_MESSAGE_MAP()
  129.  
  130. /////////////////////////////////////////////////////////////////////////////
  131. // CIntroPage
  132.  
  133. CIntroPage::CIntroPage(CWnd *pParent)
  134.     : CNetscapePropertyPage(IDD)
  135. {
  136.     //{{AFX_DATA_INIT(CIntroPage)
  137.     //}}AFX_DATA_INIT
  138.     m_pParent = (CNewProfileWizard*)pParent;
  139. }
  140.  
  141. BOOL CIntroPage::OnSetActive()
  142. {
  143.     m_pParent->SetWizardButtons(PSWIZB_NEXT);
  144.     return CNetscapePropertyPage::OnSetActive();
  145. }
  146.  
  147. BOOL CIntroPage::OnInitDialog()
  148. {
  149.     BOOL ret = CNetscapePropertyPage::OnInitDialog();
  150.  
  151.     if(theApp.m_bPEEnabled)
  152.     {
  153.         CString m_str;
  154.         m_str.LoadString(IDS_PE_INTROPAGE_TEXT);
  155.         GetDlgItem(IDC_INTRO_TEXT)->SetWindowText(m_str);
  156.     }
  157.     return ret;
  158. }
  159.  
  160. void CIntroPage::DoDataExchange(CDataExchange* pDX)
  161. {
  162.     CDialog::DoDataExchange(pDX);
  163. }
  164.  
  165.  
  166. BEGIN_MESSAGE_MAP(CIntroPage, CNetscapePropertyPage)
  167. END_MESSAGE_MAP()
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CNamePage
  171.  
  172. CNamePage::CNamePage(CWnd *pParent)
  173.     : CNetscapePropertyPage(IDD)
  174. {
  175.     //{{AFX_DATA_INIT(CProfileNamePage)
  176.     //}}AFX_DATA_INIT
  177.     m_pParent = (CNewProfileWizard*)pParent;
  178. }
  179.  
  180. CNamePage::~CNamePage()
  181. {
  182. }
  183.  
  184. BOOL CNamePage::OnInitDialog()
  185. {
  186.     BOOL ret;
  187.     char * pString = NULL;
  188.     
  189.     ret = CNetscapePropertyPage::OnInitDialog();
  190.  
  191.     if (m_pParent->m_bUpgrade) {
  192.         // if we aren't creating a new profile, we are updating an existing one
  193.         CString csUserAddr = theApp.GetProfileString("User","User_Addr","DefaultUser");
  194.         CString csFullName = theApp.GetProfileString("User","User_Name","");
  195.  
  196.         m_pParent->m_pUserAddr = csUserAddr;
  197.         m_pParent->m_pFullName = csFullName;
  198.     } else {
  199.         char buffer[256];
  200.         int nLen = 255;
  201.  
  202.         if (PREF_NOERROR == PREF_GetCharPref("mail.identity.username", buffer, &nLen))
  203.             m_pParent->m_pFullName = buffer;
  204.         if (PREF_NOERROR == PREF_GetCharPref("mail.identity.useremail", buffer, &nLen))
  205.             m_pParent->m_pUserAddr = buffer;
  206.     }
  207.  
  208.     SetDlgItemText(IDC_USER_NAME, m_pParent->m_pFullName);
  209.     SetDlgItemText(IDC_EMAIL_ADDR, m_pParent->m_pUserAddr);
  210.  
  211.     if(theApp.m_bPEEnabled)
  212.         ShowHideEmailName();
  213.  
  214.     return ret;
  215. }
  216. void CNamePage::ShowHideEmailName()
  217. {
  218.     // PE: disable email entry
  219.     int nShowCmd;
  220.     CString text;
  221.  
  222.     if(theApp.m_bPEEnabled && m_pParent->m_bASWEnabled)
  223.     {
  224.         text.LoadString(IDS_PEMUC_NAMEPAGE_TEXT);
  225.         SetDlgItemText(IDC_EMAIL_TEXT1,(LPCTSTR)text);
  226.         nShowCmd = SW_HIDE;
  227.     }
  228.     else
  229.     {
  230.         text.LoadString(IDS_MUP_NAMEPAGE_TEXT);
  231.         SetDlgItemText(IDC_EMAIL_TEXT1,(LPCTSTR)text);
  232.         nShowCmd = SW_SHOW;
  233.     }
  234.  
  235.     GetDlgItem(IDC_EMAIL_ADDRTEXT)->ShowWindow(nShowCmd);
  236.     GetDlgItem(IDC_EMAIL_ADDR)->ShowWindow(nShowCmd);
  237.     GetDlgItem(IDC_EMAIL_ADDREG)->ShowWindow(nShowCmd);
  238.  
  239. }
  240. BOOL CNamePage::OnSetActive()
  241. {
  242.     m_pParent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  243.     return CNetscapePropertyPage::OnSetActive();
  244. }
  245.  
  246. void CNamePage::DoFinish()
  247. {
  248.     if (!m_pParent->m_pFullName.IsEmpty())
  249.         PREF_SetCharPref("mail.identity.username",m_pParent->m_pFullName);
  250.     if (!m_pParent->m_pUserAddr.IsEmpty())
  251.         PREF_SetCharPref("mail.identity.useremail",m_pParent->m_pUserAddr);
  252. }
  253.  
  254. void CNamePage::DoDataExchange(CDataExchange* pDX)
  255. {
  256.     CDialog::DoDataExchange(pDX);
  257.     if (pDX->m_bSaveAndValidate) {
  258.         char name[BUFSZ];
  259.         if (GetDlgItemText(IDC_EMAIL_ADDR, name, BUFSZ)) 
  260.             m_pParent->m_pUserAddr = name;
  261.         if (GetDlgItemText(IDC_USER_NAME, name, BUFSZ))
  262.             m_pParent->m_pFullName = name;
  263.  
  264.         // Set the preference now so that future pages (like the mail/news pages) will be able
  265.         // to access it.
  266.         if (!m_pParent->m_pFullName.IsEmpty())
  267.             PREF_SetCharPref("mail.identity.username",m_pParent->m_pFullName);
  268.         if (!m_pParent->m_pUserAddr.IsEmpty())
  269.             PREF_SetCharPref("mail.identity.useremail",m_pParent->m_pUserAddr);
  270.  
  271.     }
  272. }
  273.  
  274. BEGIN_MESSAGE_MAP(CNamePage, CNetscapePropertyPage)
  275. END_MESSAGE_MAP()
  276.  
  277. /////////////////////////////////////////////////////////////////////////////
  278. // CProfileNamePage
  279.  
  280. CProfileNamePage::CProfileNamePage(CWnd *pParent)
  281.     : CNetscapePropertyPage(IDD)
  282. {
  283.     //{{AFX_DATA_INIT(CProfileNamePage)
  284.     //}}AFX_DATA_INIT
  285.     m_pParent = (CNewProfileWizard*)pParent;
  286.     m_pParent->m_pProfileName = "";
  287.     m_pParent->m_pProfilePath = "";
  288. }
  289.  
  290. CProfileNamePage::~CProfileNamePage()
  291. {
  292. }
  293.  
  294. BOOL CProfileNamePage::OnInitDialog()
  295. {
  296.     BOOL ret;
  297.     char * pString = NULL;
  298.     
  299.     ret = CNetscapePropertyPage::OnInitDialog();
  300.  
  301.     CString csUserAddrShort;
  302.     CString csUserDirectory;
  303.     
  304.     csUserDirectory.Empty();
  305.  
  306.     int iAtSign = m_pParent->m_pUserAddr.Find('@');
  307.     
  308.     if (iAtSign != -1) 
  309.         csUserAddrShort = m_pParent->m_pUserAddr.Left(iAtSign);
  310.     else
  311.         csUserAddrShort = m_pParent->m_pUserAddr;
  312.  
  313.     if (csUserAddrShort.IsEmpty()) 
  314.         csUserAddrShort = "default";
  315.  
  316.     CUserProfileDB::AssignProfileDirectoryName(csUserAddrShort,csUserDirectory);
  317.  
  318.     SetDlgItemText(IDC_PROFILE_DIR, csUserDirectory);
  319.     SetDlgItemText(IDC_PROFILE_NAME, csUserAddrShort);
  320.     PREF_SetCharPref("mail.pop_name",csUserAddrShort);
  321.     return ret;
  322. }
  323.  
  324. BOOL CProfileNamePage::OnSetActive()
  325. {
  326. #ifndef MOZ_MAIL_NEWS // Is this the correct ifdef?
  327.     if(!theApp.m_bPEEnabled ||( theApp.m_bPEEnabled && (!m_pParent->m_bMucEnabled) && (!m_pParent->m_bASWEnabled)))
  328.     {
  329.         if(!m_pParent->m_bUpgrade)
  330.         {
  331.             m_pParent->SetWizardButtons(PSWIZB_FINISH | PSWIZB_BACK);
  332.  
  333.             CString    text;
  334.             text.LoadString(IDS_CLICK_FINISH);
  335.             GetDlgItem(IDC_PROFILENAME_TEXT)->SetWindowText(text);
  336.         }
  337.  
  338.     }
  339.     else
  340.             m_pParent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  341. #else
  342.     m_pParent->SetWizardButtons(PSWIZB_NEXT | PSWIZB_BACK);
  343. #endif /* MOZ_MAIL_NEWS */
  344.     return CNetscapePropertyPage::OnSetActive();
  345. }
  346.  
  347.  
  348. int CProfileNamePage::DoFinish()
  349. {
  350.     char path[BUFSZ],name[BUFSZ];
  351.     int ret;
  352.     XP_StatStruct statinfo; 
  353.  
  354.     if (!GetDlgItemText(IDC_PROFILE_NAME, name, BUFSZ)) {
  355.         AfxMessageBox(szLoadString(IDS_INVALID_PROFILE_NAME),MB_OK);
  356.         return FALSE;
  357.     }
  358.  
  359.     if (GetDlgItemText(IDC_PROFILE_DIR, path, BUFSZ)) { 
  360.         if (path[strlen(path)-1] == '\\') path[strlen(path)-1] = NULL;  // remove last slash...
  361.  
  362.         ret = _stat((char *) path, &statinfo);
  363.         if (!ret) {
  364.             // Directory already exists!
  365.             if (AfxMessageBox(szLoadString(IDS_PROFDIR_EXISTS),MB_OKCANCEL) == IDCANCEL)
  366.                 return FALSE;
  367.             else 
  368.                 m_pParent->m_bExistingDir = TRUE;
  369.         }
  370.         if(ret == -1) {
  371.             // see if we can just create it
  372.             char * slash = strchr(path,'\\');
  373.             while (slash) {
  374.                 slash[0] = NULL;
  375.                 ret = CreateDirectory(path,NULL);
  376.                 slash[0] = '\\';
  377.                 if (slash+1) slash = strchr(slash+1,'\\');
  378.             }
  379.             ret = CreateDirectory(path,NULL);
  380.             if (!ret) {
  381.                 AfxMessageBox(szLoadString(IDS_UNABLE_CREATE_DIR),MB_OK);
  382.                 return FALSE;
  383.             }
  384.         }
  385.     } else {
  386.         AfxMessageBox(szLoadString(IDS_INVALID_PROFILE_NAME),MB_OK);
  387.         return FALSE;
  388.     }
  389.  
  390.     if (GetDlgItemText(IDC_PROFILE_NAME, name, BUFSZ)) 
  391.         login_CreateNewUserKey(name,path);
  392.     m_pParent->m_pProfileName = name;
  393.     m_pParent->m_pProfilePath = path;
  394.     return TRUE;
  395. }
  396.  
  397. void CProfileNamePage::DoDataExchange(CDataExchange* pDX)
  398. {
  399.     CDialog::DoDataExchange(pDX);
  400. }
  401.  
  402. BOOL CProfileNamePage::UpdateData(BOOL bValidate) 
  403. {
  404.     char path[BUFSZ];
  405.  
  406.     if (bValidate) {
  407.         if (GetDlgItemText(IDC_PROFILE_DIR, path, BUFSZ)) {
  408.             if (!path || !path[0]) {
  409.                 AfxMessageBox(szLoadString(IDS_PROFILE_EMPTY));
  410.                 return FALSE;
  411.             }
  412.         }
  413.         else return FALSE;
  414.     }
  415.     return TRUE;
  416. }
  417.  
  418. void CProfileNamePage::GetProfilePath(char *path)
  419. {
  420.  
  421.     if (GetDlgItemText(IDC_PROFILE_DIR, path, BUFSZ)) 
  422.         if (path[strlen(path)-1] == '\\') 
  423.             path[strlen(path)-1] = NULL;  // remove last slash...
  424. }
  425.  
  426. BEGIN_MESSAGE_MAP(CProfileNamePage, CNetscapePropertyPage)
  427. END_MESSAGE_MAP()
  428.  
  429.  
  430. /////////////////////////////////////////////////////////////////////////////
  431. // CNewProfileWizard               
  432. CNewProfileWizard::CNewProfileWizard(CWnd *pParent, BOOL bUpgrade)
  433.     : CNetscapePropertySheet("", pParent)
  434. {
  435.     m_pIntroPage = new CIntroPage(this);
  436.     m_pNamePage = new CNamePage(this);
  437.     m_pProfileNamePage = new CProfileNamePage(this);
  438.     m_pConfirmPage = new CConfirmPage(this);
  439.  
  440.     m_bUpgrade = bUpgrade;
  441.     m_bExistingDir = FALSE;
  442.     m_pUserAddr = "defaultuser@domain.com";
  443.  
  444. #ifdef MOZ_MAIL_NEWS
  445.     m_pSendMailPage = new CSendMailPage(this);
  446.     m_pReceiveMailPage = new CReceiveMailPage(this);
  447.     m_pReadNewsPage = new CReadNewsPage(this);
  448. #endif /* MOZ_MAIL_NEWS */
  449.  
  450.     // PE: pe multiple user configuration
  451.     if(theApp.m_bPEEnabled){
  452.         m_pMucIntroPage = new CMucIntroPage(this);
  453.         m_pMucEditPage = new CMucEditPage(this,TRUE);
  454.         m_pASWReadyPage = new CASWReadyPage(this);
  455.         m_pMucReadyPage = new CMucReadyPage(this);
  456.     }
  457.  
  458.     // PE: replace intro page with pe intro page
  459.     if(theApp.m_bPEEnabled)
  460.     {
  461.         AddPage(m_pIntroPage);
  462.         AddPage(m_pMucIntroPage);
  463.         AddPage(m_pNamePage);     
  464.         AddPage(m_pProfileNamePage);
  465.         AddPage(m_pASWReadyPage);
  466. #ifdef MOZ_MAIL_NEWS      
  467.         AddPage(m_pSendMailPage);
  468.         AddPage(m_pReceiveMailPage);
  469.         AddPage(m_pReadNewsPage);
  470. #endif // MOZ_MAIL_NEWS      
  471.         AddPage(m_pMucReadyPage);
  472.         AddPage(m_pMucEditPage);
  473.         AddPage(m_pConfirmPage);
  474.     }
  475.     else
  476.     {
  477.         AddPage(m_pIntroPage);
  478.         AddPage(m_pNamePage);     
  479.         AddPage(m_pProfileNamePage);
  480.         if (bUpgrade) 
  481.             AddPage(m_pConfirmPage);
  482.         else 
  483.         {
  484. #ifdef MOZ_MAIL_NEWS      
  485.             AddPage(m_pSendMailPage);
  486.             AddPage(m_pReceiveMailPage);
  487.             AddPage(m_pReadNewsPage);
  488. #endif /* MOZ_MAIL_NEWS */
  489.         }
  490.     }
  491.     SetWizardMode();
  492. }
  493.  
  494. BOOL CNewProfileWizard::OnInitDialog()
  495. {
  496.     BOOL ret = CNetscapePropertySheet::OnInitDialog();
  497.     GetWindowText(m_title);
  498.     GetDlgItem(IDHELP)->ShowWindow(SW_HIDE);
  499.  
  500.     return ret;
  501. }
  502.  
  503. CNewProfileWizard::~CNewProfileWizard()
  504. {
  505.     if (m_pIntroPage)
  506.         delete m_pIntroPage;
  507.     if (m_pNamePage)
  508.         delete m_pNamePage;
  509.     if (m_pProfileNamePage)
  510.         delete m_pProfileNamePage;
  511.     if (m_pConfirmPage)
  512.         delete m_pConfirmPage;
  513. #ifdef MOZ_MAIL_NEWS      
  514.     if (m_pSendMailPage)
  515.         delete m_pSendMailPage;
  516.     if (m_pReceiveMailPage)
  517.         delete m_pReceiveMailPage;   
  518.     if (m_pReadNewsPage)
  519.         delete m_pReadNewsPage;   
  520. #endif // MOZ_MAIL_NEWS
  521.     // PE: MUC
  522.     if (theApp.m_bPEEnabled && m_pMucIntroPage)
  523.         delete m_pMucIntroPage;
  524.     if (theApp.m_bPEEnabled && m_pMucEditPage)
  525.         delete m_pMucEditPage;
  526.     if (theApp.m_bPEEnabled && m_pMucReadyPage)
  527.         delete m_pMucReadyPage;
  528.     if (theApp.m_bPEEnabled && m_pASWReadyPage)
  529.         delete m_pASWReadyPage;
  530. }
  531.  
  532. // flag is to enable finish button push
  533. void CNewProfileWizard::DoFinish()
  534. {
  535.     if (m_pNamePage && ::IsWindow(m_pNamePage->GetSafeHwnd()))
  536.         m_pNamePage->DoFinish();
  537.  
  538.     if (m_pProfileNamePage && ::IsWindow(m_pProfileNamePage->GetSafeHwnd())) {
  539.         if (m_pProfileNamePage->DoFinish())     {
  540.             if (m_bUpgrade) {
  541.                 if (m_pConfirmPage && ::IsWindow(m_pConfirmPage->GetSafeHwnd()))
  542.                     m_pConfirmPage->DoFinish();
  543.             } else {
  544.                 login_CreateEmptyProfileDir(m_pProfilePath, this, m_bExistingDir); 
  545.  
  546. #ifdef MOZ_MAIL_NEWS
  547.                 if (m_pSendMailPage && ::IsWindow(m_pSendMailPage->GetSafeHwnd()))
  548.                     m_pSendMailPage->DoFinish();
  549.                 if (m_pReceiveMailPage && ::IsWindow(m_pReceiveMailPage->GetSafeHwnd()))
  550.                     m_pReceiveMailPage->DoFinish();   
  551.                 if (m_pReadNewsPage && ::IsWindow(m_pReadNewsPage->GetSafeHwnd()))
  552.                     m_pReadNewsPage->DoFinish(); 
  553. #endif // MOZ_MAIL_NEWS               
  554.             }
  555.  
  556.             if (theApp.m_bPEEnabled)
  557.             {
  558.                 // PE: upgrad case
  559.                 if(m_bMucEnabled && m_bUpgrade && m_pMucEditPage 
  560.                     && ::IsWindow(m_pMucEditPage->GetSafeHwnd()))
  561.                         m_pMucEditPage->DoFinish();
  562.  
  563.                 // PE: dialer thread: 
  564.                 if(m_bMucEnabled && m_pMucEditPage 
  565.                     && ::IsWindow(m_pMucEditPage->GetSafeHwnd()))
  566.                         m_pMucEditPage->DoFinish();
  567.  
  568.                 // PE: account setup thread
  569.                 else if (m_bASWEnabled && m_pASWReadyPage 
  570.                     && ::IsWindow(m_pASWReadyPage->GetSafeHwnd()))
  571.                         m_pASWReadyPage->DoFinish();
  572.  
  573.                 // PE: network thread
  574.                 else 
  575.                 {
  576.                     CMucProc        m_mucProc;
  577.                     m_mucProc.SetDialOnDemand("",FALSE);
  578.                 }
  579.             }
  580.  
  581.             PressButton(PSBTN_FINISH);
  582.         }
  583.     }
  584. }
  585.  
  586. void CNewProfileWizard::DoNext()
  587. {
  588.     PressButton(PSBTN_NEXT);
  589.  
  590.     if(theApp.m_bPEEnabled)
  591.     {
  592.         CPropertyPage* curPage = GetActivePage();
  593.  
  594.         if(curPage == m_pMucIntroPage && m_bUpgrade)    // skip muc intro page
  595.                 SetActivePage(m_pNamePage);
  596.         
  597.         if(curPage == m_pNamePage && ::IsWindow(m_pNamePage->GetSafeHwnd()))
  598.                 m_pNamePage->ShowHideEmailName();
  599.         
  600.         if(curPage == m_pASWReadyPage)
  601.         {
  602.             if(!m_bASWEnabled)
  603.             {
  604.                 if (m_bUpgrade) 
  605.                     SetActivePage(m_pMucEditPage);
  606.                 else
  607. #ifdef MOZ_MAIL_NEWS               
  608.                     SetActivePage(m_pSendMailPage);
  609. #else
  610.                     SetActivePage(m_pMucReadyPage);
  611. #endif /* MOZ_MAIL_NEWS */
  612.             }
  613.         }
  614.         
  615. #ifdef MOZ_MAIL_NEWS      
  616.         if(curPage == m_pReceiveMailPage)
  617.             m_pReadNewsPage->SetFinish(!m_bMucEnabled);
  618. #endif /* MOZ_MAIL_NEWS */
  619.         
  620.         if(curPage == m_pMucReadyPage || curPage == m_pMucEditPage)
  621.             SetTitle(m_title);
  622.     }
  623. }
  624.  
  625. void CNewProfileWizard::DoBack()
  626. {
  627.     PressButton(PSBTN_BACK);
  628.  
  629.     if(theApp.m_bPEEnabled)
  630.     {
  631.         CPropertyPage* curPage = GetActivePage();
  632.         
  633.         if(curPage == m_pASWReadyPage)  
  634.             SetActivePage(m_pProfileNamePage);
  635.         
  636.         if(curPage == m_pMucReadyPage && m_bUpgrade)
  637.             SetActivePage(m_pProfileNamePage);
  638.  
  639.         if(curPage == m_pMucIntroPage && m_bUpgrade)
  640.             SetActivePage(m_pIntroPage);
  641.     }
  642. }
  643.  
  644. void CNewProfileWizard::GetProfilePath(char *str)
  645. {
  646.     if (m_pProfileNamePage && ::IsWindow(m_pProfileNamePage->GetSafeHwnd())) 
  647.         m_pProfileNamePage->GetProfilePath(str);
  648. }
  649.  
  650. BEGIN_MESSAGE_MAP(CNewProfileWizard, CNetscapePropertySheet)
  651.     ON_BN_CLICKED(ID_WIZFINISH,DoFinish)
  652.     ON_BN_CLICKED(ID_WIZNEXT,DoNext)
  653.     ON_BN_CLICKED(ID_WIZBACK,DoBack)
  654. END_MESSAGE_MAP()
  655.  
  656. #else
  657. /////////////////////////////////////////////////////////////////////////////
  658. // CNewProfileWizard               
  659. CNewProfileWizard::CNewProfileWizard(CWnd *pParent, BOOL bUpgrade)
  660.     : CDialog(IDD, pParent)
  661. {
  662.     m_nCurrentPage = ID_PAGE_INTRO;
  663.     m_bUpgrade = bUpgrade;
  664.  
  665.     // PE: pe multiple user configuration
  666.     if(theApp.m_bPEEnabled)
  667.     {
  668.         m_pMucIntroPage = new CMucIntroPage(this);
  669.         m_pMucEditPage = new CMucEditPage(this,TRUE);
  670.         m_pASWReadyPage = new CASWReadyPage(this);
  671.         m_pMucReadyPage = new CMucReadyPage(this);  
  672.     }
  673. }
  674.  
  675. CNewProfileWizard::~CNewProfileWizard()
  676. {
  677. }
  678.  
  679. void CNewProfileWizard::DoDataExchange(CDataExchange* pDX)
  680. {
  681.     CDialog::DoDataExchange(pDX);
  682. }
  683.  
  684. void CNewProfileWizard::InitPrefStrings()
  685. {
  686.     CString csUserAddr = "";
  687.     CString csFullName = "";
  688.  
  689.     if (m_bUpgrade) {
  690.         csUserAddr = theApp.GetProfileString("User","User_Addr","");
  691.         csFullName = theApp.GetProfileString("User","User_Name","");   
  692.     }
  693.  
  694.     m_pUserAddr = csUserAddr;
  695.     m_pFullName = csFullName;
  696.     m_pProfileName = "";
  697.     m_pProfilePath = "";
  698.     m_bExistingDir = FALSE;
  699.  
  700. #ifdef MOZ_MAIL_NEWS
  701.     PREF_GetBoolPref("mail.leave_on_server", &m_bLeftOnServer);
  702.  
  703.     m_szFullName = g_MsgPrefs.m_csUsersFullName;
  704.     m_szEmail = g_MsgPrefs.m_csUsersEmailAddr;
  705. #endif /* MOZ_MAIL_NEWS */
  706.  
  707.     char *prefStr = NULL;
  708.  
  709.     PREF_CopyCharPref("network.hosts.smtp_server", &prefStr);
  710.     if (prefStr)
  711.         m_szMailServer = prefStr;
  712.     XP_FREEIF(prefStr);
  713.  
  714.     prefStr = NULL;
  715.     PREF_CopyCharPref("mail.pop_name", &prefStr);
  716.     if (prefStr)
  717.         m_szPopName = prefStr;
  718.     XP_FREEIF(prefStr);
  719.  
  720.     prefStr = NULL;
  721.     PREF_CopyCharPref("network.hosts.pop_server", &prefStr);
  722.     if (prefStr)
  723.         m_szInMailServer = prefStr;
  724.     XP_FREEIF(prefStr);
  725.  
  726.     if (m_szInMailServer.IsEmpty())
  727.         m_szInMailServer = m_szMailServer;
  728.  
  729.     int32 prefInt = 0;
  730.     PREF_GetIntPref("mail.server_type", &prefInt);
  731.     m_bUseIMAP = prefInt == MSG_Imap4;
  732.  
  733.     prefStr = NULL;
  734.     PREF_CopyCharPref("network.hosts.nntp_server", &prefStr);
  735.     if (prefStr)
  736.         m_szNewsServer = prefStr;
  737.     XP_FREEIF(prefStr);
  738.  
  739.     m_bIsSecure = FALSE;
  740.     m_nPort = NEWS_PORT;
  741. }
  742.  
  743. BOOL CNewProfileWizard::OnInitDialog()
  744. {
  745.     GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);
  746.     GetDlgItem(IDC_STATIC_EG1)->ShowWindow(SW_HIDE);
  747.     GetDlgItem(IDC_STATIC2)->ShowWindow(SW_HIDE);
  748.     GetDlgItem(IDC_EDIT2)->ShowWindow(SW_HIDE);
  749.     GetDlgItem(IDC_STATIC_EG2)->ShowWindow(SW_HIDE);
  750.     GetDlgItem(IDC_STATIC3)->ShowWindow(SW_HIDE);
  751.     GetDlgItem(IDC_EDIT3)->ShowWindow(SW_HIDE);
  752.     GetDlgItem(IDC_READMAIL_POP1)->ShowWindow(SW_HIDE);
  753.     GetDlgItem(IDC_READMAIL_POP2)->ShowWindow(SW_HIDE);
  754.     GetDlgItem(IDC_READMAIL_IMAP)->ShowWindow(SW_HIDE);
  755.     GetDlgItem(IDC_STATIC5)->ShowWindow(SW_HIDE);
  756.     GetDlgItem(IDC_SECURE)->ShowWindow(SW_HIDE);
  757.  
  758.     GetDlgItem(IDC_STATIC_TITLE)->ShowWindow(SW_HIDE);
  759.     GetDlgItem(IDC_STATIC1)->ShowWindow(SW_HIDE);
  760.  
  761.     ShowHideNamePage(SW_HIDE); 
  762.     ShowHideProfilePage(SW_HIDE);
  763.     ShowHideConfirmPage(SW_HIDE);
  764.     ShowHideSendPage(SW_HIDE);
  765.     ShowHideReceivePage(SW_HIDE);
  766.     ShowHideNewsPage(SW_HIDE);
  767.  
  768.     InitPrefStrings();
  769.  
  770.     SetDlgItemText(IDC_USER_NAME, m_pFullName);
  771.     SetDlgItemText(IDC_EMAIL_ADDR, m_pUserAddr);
  772.     GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(FALSE);  
  773.  
  774.     if(theApp.m_bPEEnabled)
  775.     {
  776.         m_pMucIntroPage->Create(IDD_MUCWIZARD_INTRO, this);   
  777.         m_pMucEditPage->Create(IDD_MUCWIZARD_EDIT, this);
  778.         m_pASWReadyPage->Create(IDD_MUCWIZARD_ASWREADY, this);
  779.         m_pMucReadyPage->Create(IDD_MUCWIZARD_MUCREADY, this);   
  780.         
  781.         ShowHidePEMucIntroPage(SW_HIDE);
  782.         ShowHidePEMucEditPage(SW_HIDE);
  783.         ShowHidePEMucASWReadyPage(SW_HIDE);
  784.         ShowHidePEMucReadyPage(SW_HIDE);
  785.     }
  786.  
  787.     return CDialog::OnInitDialog();
  788. }
  789.  
  790. void CNewProfileWizard::DoBack()
  791. {
  792.     // PE:
  793.     if(theApp.m_bPEEnabled)
  794.     {
  795.         if(m_nCurrentPage == ID_PEMUC_INTRO) 
  796.             m_nCurrentPage = ID_PAGE_INTRO;
  797.         else if(m_nCurrentPage == ID_PAGE_NAME && !m_bUpgrade) 
  798.             m_nCurrentPage = ID_PEMUC_INTRO;
  799.         else if(m_nCurrentPage == ID_PAGE_NAME && m_bUpgrade) 
  800.             m_nCurrentPage = ID_PAGE_INTRO;
  801.         else if(m_nCurrentPage == ID_PEMUC_ASWREADY) 
  802.             m_nCurrentPage = ID_PAGE_PROFILE;  
  803. #ifdef MOZ_MAIL_NEWS
  804.         else if(m_nCurrentPage == ID_PEMUC_MUCREADY && !m_bUpgrade) 
  805.             m_nCurrentPage = ID_PAGE_READNEWS;     
  806. #else
  807.         else if(m_nCurrentPage == ID_PEMUC_MUCREADY && !m_bUpgrade) 
  808.             m_nCurrentPage = ID_PAGE_PROFILE;     
  809. #endif /* MOZ_MAIL_NEWS */
  810.         else if(m_nCurrentPage == ID_PEMUC_MUCREADY && m_bUpgrade) 
  811.             m_nCurrentPage = ID_PAGE_PROFILE;
  812.         else if(m_nCurrentPage == ID_PEMUC_MUCEDIT) 
  813.             m_nCurrentPage = ID_PEMUC_MUCREADY;   
  814.         else if (m_nCurrentPage == ID_PAGE_SENDMAIL) 
  815.             m_nCurrentPage = ID_PAGE_PROFILE;
  816.         else if (m_nCurrentPage == ID_PAGE_FINISH && m_bUpgrade) 
  817.             m_nCurrentPage = ID_PAGE_CONFIRM;
  818.         else if (m_nCurrentPage == ID_PAGE_CONFIRM) 
  819.             m_nCurrentPage = ID_PEMUC_MUCEDIT;
  820.         else if (m_nCurrentPage == ID_PAGE_FINISH && m_bASWEnabled) 
  821.             m_nCurrentPage = ID_PEMUC_ASWREADY;
  822.         else if (m_nCurrentPage == ID_PAGE_FINISH && m_bMucEnabled) 
  823.             m_nCurrentPage = ID_PEMUC_MUCEDIT;  
  824. #ifndef MOZ_MAIL_NEWS
  825.         else if (m_nCurrentPage == ID_PAGE_FINISH && (!m_bMucEnabled) && (!m_bASWEnabled)) 
  826.             m_nCurrentPage = ID_PAGE_PROFILE;   
  827. #else 
  828.         else if (m_nCurrentPage == ID_PAGE_FINISH && (!m_bMucEnabled) && (!m_bASWEnabled)) 
  829.             m_nCurrentPage = ID_PAGE_READNEWS;   
  830. #endif // MOZ_MAIL_NEWS
  831.         else
  832.             m_nCurrentPage -= 1; 
  833.             
  834.     } //pe
  835.     else
  836.     {   
  837. #ifdef MOZ_MAIL_NEWS
  838.         if (m_nCurrentPage == ID_PAGE_SENDMAIL) 
  839.             m_nCurrentPage = ID_PAGE_PROFILE;
  840.         else     
  841.             m_nCurrentPage -= 1;    
  842. #else           
  843.         if(m_bUpgrade && m_nCurrentPage == ID_PAGE_FINISH) 
  844.             m_nCurrentPage = ID_PAGE_CONFIRM;
  845.         else if(m_bUpgrade && m_nCurrentPage == ID_PAGE_CONFIRM) 
  846.             m_nCurrentPage = ID_PAGE_PROFILE; 
  847.         else m_nCurrentPage -= 1;  
  848. #endif /* MOZ_MAIL_NEWS */
  849.  
  850.     } 
  851.     
  852.     
  853.     switch  (m_nCurrentPage)
  854.     {
  855.     case ID_PAGE_INTRO:             // 1st page
  856.         if(theApp.m_bPEEnabled)
  857.             ShowHidePEMucIntroPage(SW_HIDE);
  858.         ShowHideNamePage(SW_HIDE); 
  859.         ShowHideIntroPage(SW_SHOW);
  860.         GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(FALSE);
  861.         break;
  862.     case ID_PAGE_NAME:  // 2nd page
  863. #ifndef MOZ_MAIL_NEWS // Is this the correct ifdef?
  864.         SetControlText(IDOK, IDS_NEXT);
  865. #endif // MOZ_MAIL_NEWS
  866.         ShowHideProfilePage(SW_HIDE);
  867.         ShowHideNamePage(SW_SHOW);
  868.         break;
  869.     case ID_PEMUC_INTRO:  // PE: 2nd page
  870.         ShowHideNamePage(SW_HIDE);
  871.         ShowHidePEMucIntroPage(SW_SHOW);
  872.         break;
  873.     case ID_PAGE_PROFILE:   // 3rd page
  874. #ifndef MOZ_MAIL_NEWS // Is this the correct ifdef?
  875.         if((!theApp.m_bPEEnabled) && (!m_bUpgrade))
  876.             SetControlText(IDOK, IDS_FINISH);      
  877.         else if (theApp.m_bPEEnabled && (m_bASWEnabled || m_bMucEnabled || m_bUpgrade))
  878.             SetControlText(IDOK, IDS_NEXT);
  879. #else
  880.         SetControlText(IDOK, IDS_NEXT);
  881. #endif // MOZ_MAIL_NEWS
  882.         ShowHideConfirmPage(SW_HIDE);
  883.         ShowHideSendPage(SW_HIDE);
  884.         if(theApp.m_bPEEnabled) 
  885.         {
  886.             ShowHidePEMucASWReadyPage(SW_HIDE);
  887.             ShowHidePEMucReadyPage(SW_HIDE);     //upgrade
  888.         }
  889.         ShowHideProfilePage(SW_SHOW);
  890.         break;
  891. #ifdef MOZ_MAIL_NEWS
  892.     case ID_PAGE_SENDMAIL:  // 4th page
  893.         ShowHideReceivePage(SW_HIDE);
  894.         ShowHideSendPage(SW_SHOW);
  895.         break;
  896.     case ID_PAGE_RECEIVEMAIL:       // 5th page
  897.         SetControlText(IDOK, IDS_NEXT);
  898.         ShowHideNewsPage(SW_HIDE);
  899.         ShowHideReceivePage(SW_SHOW);
  900.         break;
  901.     case ID_PAGE_READNEWS:  // PE: 6th page 
  902.         if(theApp.m_bPEEnabled && m_bMucEnabled)
  903.             SetControlText(IDOK, IDS_NEXT);
  904.         else
  905.             SetControlText(IDOK, IDS_FINISH);
  906.         ShowHidePEMucReadyPage(SW_HIDE);
  907.         ShowHideNewsPage(SW_SHOW);
  908.         break;
  909. #endif /* MOZ_MAIL_NEWS */
  910.     case ID_PEMUC_MUCREADY: // PE: 7th page
  911.         SetControlText(IDOK, IDS_NEXT);
  912.         ShowHidePEMucReadyPage(SW_SHOW);
  913.         ShowHidePEMucEditPage(SW_HIDE);
  914.         break;
  915.     case ID_PEMUC_MUCEDIT: // PE: 8th page 
  916.         if(m_bUpgrade)
  917.         {
  918.             SetControlText(IDOK, IDS_NEXT);
  919.             ShowHideConfirmPage(SW_HIDE);
  920.             ShowHidePEMucEditPage(SW_SHOW); 
  921.         }
  922.         break;
  923.     default:
  924.         break;
  925.     }
  926. }
  927.  
  928. void CNewProfileWizard::DoNext()
  929. {
  930.     CString text;
  931.  
  932.     // PE:
  933.     if(theApp.m_bPEEnabled) 
  934.     {
  935.         if (m_nCurrentPage == ID_PAGE_INTRO && !m_bUpgrade)
  936.             m_nCurrentPage = ID_PEMUC_INTRO;
  937.         else if (m_nCurrentPage == ID_PAGE_INTRO && m_bUpgrade)
  938.             m_nCurrentPage = ID_PAGE_NAME;
  939.         else if (m_nCurrentPage == ID_PEMUC_INTRO)
  940.             m_nCurrentPage = ID_PAGE_NAME;
  941.         else if (m_nCurrentPage == ID_PAGE_PROFILE && m_bASWEnabled && !m_bUpgrade)
  942.             m_nCurrentPage = ID_PEMUC_ASWREADY;   
  943. #ifdef MOZ_MAIL_NEWS 
  944.         else if (m_nCurrentPage == ID_PAGE_PROFILE && (!m_bASWEnabled) && !m_bUpgrade)
  945.             m_nCurrentPage = ID_PAGE_SENDMAIL;
  946. #else  
  947.         else if (m_nCurrentPage == ID_PAGE_PROFILE && (m_bMucEnabled))
  948.             m_nCurrentPage = ID_PEMUC_MUCREADY; 
  949.         else if (m_nCurrentPage == ID_PAGE_PROFILE && (!m_bMucEnabled))
  950.             m_nCurrentPage = ID_PAGE_FINISH; 
  951. #endif /* MOZ_MAIL_NEWS */
  952.         else if (m_nCurrentPage == ID_PAGE_PROFILE && (!m_bASWEnabled) && m_bUpgrade)
  953.             m_nCurrentPage = ID_PEMUC_MUCREADY;
  954.         else if (m_nCurrentPage == ID_PEMUC_ASWREADY)
  955.             m_nCurrentPage = ID_PAGE_FINISH;
  956.         else if (m_nCurrentPage == ID_PEMUC_MUCEDIT && m_bUpgrade)
  957.             m_nCurrentPage = ID_PAGE_CONFIRM;
  958.         else if (m_nCurrentPage == ID_PAGE_CONFIRM)
  959.             m_nCurrentPage = ID_PAGE_FINISH;
  960.         else if (m_nCurrentPage == ID_PEMUC_MUCEDIT&& !m_bUpgrade)
  961.             m_nCurrentPage = ID_PAGE_FINISH;
  962.         else if (m_nCurrentPage == ID_PEMUC_MUCREADY)
  963.             m_nCurrentPage = ID_PEMUC_MUCEDIT;
  964. #ifdef MOZ_MAIL_NEWS
  965.         else if (m_nCurrentPage == ID_PAGE_READNEWS && m_bMucEnabled)
  966.             m_nCurrentPage = ID_PEMUC_MUCREADY;
  967.         else if (m_nCurrentPage == ID_PAGE_READNEWS && (!m_bMucEnabled))
  968.             m_nCurrentPage = ID_PAGE_FINISH;
  969. #endif /* MOZ_MAIL_NEWS */
  970.         else if (m_nCurrentPage == ID_PAGE_FINISH)
  971.             m_nCurrentPage = ID_PAGE_FINISH;
  972.         else
  973.             m_nCurrentPage += 1;
  974.     }
  975.     else
  976.     {
  977.         if (m_nCurrentPage == ID_PAGE_PROFILE) {
  978.             // special magic on this page
  979.             if (m_bUpgrade) m_nCurrentPage = ID_PAGE_CONFIRM;
  980. #ifndef MOZ_MAIL_NEWS 
  981.             else m_nCurrentPage = ID_PAGE_FINISH; 
  982. #else         
  983.             else m_nCurrentPage = ID_PAGE_SENDMAIL; 
  984. #endif /* MOZ_MAIL_NEWS */
  985.         } 
  986.         else if (m_nCurrentPage == ID_PAGE_CONFIRM) 
  987.             // confirm page next is finish
  988.             m_nCurrentPage = ID_PAGE_FINISH;
  989.         else if (m_nCurrentPage == ID_PAGE_FINISH)
  990.             m_nCurrentPage = ID_PAGE_FINISH;
  991.         else
  992.             m_nCurrentPage += 1;
  993.     }
  994.  
  995.     switch  (m_nCurrentPage)
  996.     {
  997.     case ID_PAGE_NAME:  // 2nd page
  998.         if(theApp.m_bPEEnabled)
  999.             ShowHidePEMucIntroPage(SW_HIDE);
  1000.         ShowHideIntroPage(SW_HIDE);
  1001.         ShowHideNamePage(SW_SHOW);
  1002.         GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(TRUE);
  1003.         break;
  1004.     case ID_PEMUC_INTRO:  // PE: 2nd page
  1005.         ShowHideIntroPage(SW_HIDE);
  1006.         ShowHidePEMucIntroPage(SW_SHOW);
  1007.         GetDlgItem(IDC_BUTTON_BACK)->EnableWindow(TRUE);
  1008.         break;
  1009.     case ID_PAGE_PROFILE:   // 3rd page
  1010.         ShowHideNamePage(SW_HIDE); 
  1011.         ShowHideProfilePage(SW_SHOW);    
  1012. #ifndef MOZ_MAIL_NEWS // Is this the correct ifdef??
  1013.         if(!m_bUpgrade)
  1014.             if(!((theApp.m_bPEEnabled && m_bASWEnabled) || (theApp.m_bPEEnabled && m_bMucEnabled))) 
  1015.             {
  1016.                 SetControlText(IDOK, IDS_FINISH);
  1017.                 SetControlText(IDC_NAME3, IDS_CLICK_FINISH);
  1018.             }                
  1019. #endif /* MOZ_MAIL_NEWS */  
  1020.         break;
  1021.     case ID_PAGE_CONFIRM:   // 4th page
  1022.         SetControlText(IDOK, IDS_FINISH);
  1023.         ShowHideProfilePage(SW_HIDE); 
  1024.         ShowHidePEMucEditPage(SW_HIDE);
  1025.         ShowHideConfirmPage(SW_SHOW);
  1026.         break;
  1027.     case ID_PEMUC_ASWREADY: // PE: 4th page
  1028.         SetControlText(IDOK, IDS_FINISH);
  1029.         ShowHideProfilePage(SW_HIDE); 
  1030.         ShowHidePEMucASWReadyPage(SW_SHOW);
  1031.         break;
  1032. #ifdef MOZ_MAIL_NEWS
  1033.     case ID_PAGE_SENDMAIL:  // other 4th page
  1034.         ShowHideProfilePage(SW_HIDE); 
  1035.         ShowHideSendPage(SW_SHOW);
  1036.         break;
  1037.     case ID_PAGE_RECEIVEMAIL:       // 5th page
  1038.         ShowHideSendPage(SW_HIDE); 
  1039.         ShowHideReceivePage(SW_SHOW);
  1040.         break;
  1041.     case ID_PAGE_READNEWS:  // 6th page    
  1042.         if(!(theApp.m_bPEEnabled && m_bMucEnabled))
  1043.             SetControlText(IDOK, IDS_FINISH);
  1044.         ShowHideReceivePage(SW_HIDE); 
  1045.         ShowHideNewsPage(SW_SHOW);
  1046.         break;
  1047. #endif /* MOZ_MAIL_NEWS */
  1048.     case ID_PEMUC_MUCREADY: // PE: 7th page
  1049.         ShowHideNewsPage(SW_HIDE); 
  1050.         ShowHidePEMucReadyPage(SW_SHOW);
  1051.         break;
  1052.     case ID_PEMUC_MUCEDIT:  // PE: 8th page    
  1053.         if(!m_bUpgrade)
  1054.             SetControlText(IDOK, IDS_FINISH); 
  1055.         else
  1056.             SetControlText(IDOK, IDS_NEXT);
  1057.         ShowHidePEMucReadyPage(SW_HIDE); 
  1058.         ShowHidePEMucEditPage(SW_SHOW);
  1059.         break;
  1060.     case ID_PAGE_FINISH:    // done, save value
  1061.         if (DoFinish())
  1062.             EndDialog(IDOK);
  1063.         else
  1064.             DoBack();
  1065.         break;
  1066.     default:
  1067.         break;
  1068.     }
  1069. }
  1070.  
  1071. void CNewProfileWizard::SetControlText(int nID, int nStringID) 
  1072. {
  1073.     CString text;
  1074.     text.LoadString(nStringID);
  1075.     SetDlgItemText(nID, LPCTSTR(text));
  1076. }
  1077.  
  1078. void CNewProfileWizard::ShowHideIntroPage(int nShowCmd) 
  1079. {
  1080.     GetDlgItem(IDC_INTRO1)->ShowWindow(nShowCmd);
  1081.     if(theApp.m_bPEEnabled)
  1082.     {
  1083.         CString m_str;
  1084.         m_str.LoadString(IDS_PE_INTROPAGE_TEXT);
  1085.         SetDlgItemText(IDC_INTRO2, (LPCSTR)m_str);
  1086.     }       
  1087.     GetDlgItem(IDC_INTRO2)->ShowWindow(nShowCmd);
  1088.     GetDlgItem(IDC_INTRO3)->ShowWindow(nShowCmd);
  1089. }
  1090.  
  1091. void CNewProfileWizard::ShowHideNamePage(int nShowCmd)
  1092. {
  1093.     char name[BUFSZ];
  1094.  
  1095.     GetDlgItem(IDC_PROFILE1)->ShowWindow(nShowCmd);
  1096.     GetDlgItem(IDC_PROFILE2)->ShowWindow(nShowCmd);
  1097.     GetDlgItem(IDC_PROFILE3)->ShowWindow(nShowCmd);
  1098.     GetDlgItem(IDC_PROFILE4)->ShowWindow(nShowCmd);
  1099.     GetDlgItem(IDC_USER_NAME)->ShowWindow(nShowCmd);
  1100.     GetDlgItem(IDC_EMAIL_ADDR)->ShowWindow(nShowCmd);
  1101.     if (nShowCmd == SW_HIDE) {
  1102.         if (GetDlgItemText(IDC_EMAIL_ADDR, name, BUFSZ)) 
  1103.             m_pUserAddr = name;
  1104.         if (GetDlgItemText(IDC_USER_NAME, name, BUFSZ))
  1105.             m_pFullName = name;
  1106.         // setup mail/news wizard parts
  1107.         m_szFullName = m_pFullName;
  1108.         m_szEmail = m_pUserAddr;
  1109.     }
  1110.  
  1111.     if (nShowCmd == SW_SHOW) {
  1112.         GetDlgItem(IDC_USER_NAME)->SetFocus();
  1113.     }
  1114.     
  1115.     //PE: disable email addr.
  1116.     if(theApp.m_bPEEnabled & nShowCmd==SW_SHOW)
  1117.     {
  1118.         int nCmd;
  1119.         CString text;
  1120.         if(m_bASWEnabled)
  1121.         {
  1122.             text.LoadString(IDS_PEMUC_NAMEPAGE_TEXT);
  1123.             nCmd = SW_HIDE;
  1124.         }
  1125.         else
  1126.         {
  1127.             text.LoadString(IDS_MUP_NAMEPAGE_TEXT);
  1128.             nCmd = SW_SHOW;
  1129.         } 
  1130.         SetDlgItemText(IDC_PROFILE1,(LPCTSTR)text);
  1131.         GetDlgItem(IDC_PROFILE4)->ShowWindow(nCmd);
  1132.         GetDlgItem(IDC_EMAIL_ADDR)->ShowWindow(nCmd);
  1133.     }
  1134. }
  1135.  
  1136. void CNewProfileWizard::ShowHideProfilePage(int nShowCmd)
  1137. {
  1138.     GetDlgItem(IDC_NAME1)->ShowWindow(nShowCmd);
  1139.     GetDlgItem(IDC_NAME2)->ShowWindow(nShowCmd);
  1140.     GetDlgItem(IDC_NAME3)->ShowWindow(nShowCmd);
  1141.     GetDlgItem(IDC_NAME4)->ShowWindow(nShowCmd);
  1142.     GetDlgItem(IDC_PROFILE_NAME)->ShowWindow(nShowCmd);
  1143.     GetDlgItem(IDC_PROFILE_DIR)->ShowWindow(nShowCmd);
  1144.  
  1145.     if (nShowCmd == SW_SHOW) {
  1146.         CString csUserDirectory;
  1147.         CString csUserAddrShort;
  1148.         char buf[4];
  1149.  
  1150.         int iAtSign = m_pUserAddr.Find('@');
  1151.         
  1152.         if (iAtSign != -1) 
  1153.             csUserAddrShort = m_pUserAddr.Left(iAtSign);
  1154.         else
  1155.             csUserAddrShort = m_pUserAddr;
  1156.  
  1157.         if (csUserAddrShort.IsEmpty()) 
  1158.             csUserAddrShort = "default";
  1159.  
  1160.         CUserProfileDB::AssignProfileDirectoryName(csUserAddrShort,csUserDirectory);
  1161.  
  1162.         PREF_SetCharPref("mail.pop_name",csUserAddrShort);
  1163.  
  1164.         if (!GetDlgItemText(IDC_PROFILE_DIR,buf,4))
  1165.             SetDlgItemText(IDC_PROFILE_DIR, csUserDirectory);
  1166.         if (!GetDlgItemText(IDC_PROFILE_NAME,buf,4))
  1167.             SetDlgItemText(IDC_PROFILE_NAME, csUserAddrShort);
  1168.         GetDlgItem(IDC_PROFILE_NAME)->SetFocus();
  1169.     }
  1170. }
  1171.  
  1172. void CNewProfileWizard::ShowHideConfirmPage(int nShowCmd)
  1173. {
  1174.     GetDlgItem(IDC_CONFIRM1)->ShowWindow(nShowCmd);
  1175.     GetDlgItem(IDC_MOVEFILES)->ShowWindow(nShowCmd);
  1176.     GetDlgItem(IDC_COPYFILES)->ShowWindow(nShowCmd);
  1177.     GetDlgItem(IDC_IGNOREFILES)->ShowWindow(nShowCmd);
  1178.     GetDlgItem(IDC_CONFIRM2)->ShowWindow(nShowCmd);
  1179.     GetDlgItem(IDC_CONFIRM3)->ShowWindow(nShowCmd);
  1180.  
  1181.     if (!m_bUpgrade) {
  1182.         GetDlgItem(IDC_MOVEFILES)->EnableWindow(FALSE);
  1183.         GetDlgItem(IDC_COPYFILES)->EnableWindow(FALSE);
  1184.         ((CButton *)GetDlgItem(IDC_IGNOREFILES))->SetCheck(TRUE);
  1185.     }
  1186.     else ((CButton *)GetDlgItem(IDC_MOVEFILES))->SetCheck(TRUE);
  1187. }
  1188.  
  1189. void CNewProfileWizard::ShowHideSendPage(int nShowCmd)
  1190. {
  1191.     if (nShowCmd == SW_SHOW) {
  1192.         SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_SENDMAIL);
  1193.         SetControlText(IDC_STATIC1, IDS_SENDMAIL_STATIC1);
  1194.         SetControlText(IDC_STATIC_EG1, IDS_SENDMAIL_EG1);
  1195.         SetControlText(IDC_STATIC2, IDS_SENDMAIL_STATIC2);
  1196.         SetControlText(IDC_STATIC_EG2, IDS_SENDMAIL_EG2);
  1197.         SetControlText(IDC_STATIC3, IDS_SENDMAIL_STATIC3);
  1198.         SetControlText(IDC_STATIC5, IDS_SENDREADMAIL_STATIC5);
  1199.     }
  1200.     GetDlgItem(IDC_EDIT1)->ShowWindow(nShowCmd);
  1201.     GetDlgItem(IDC_STATIC_EG1)->ShowWindow(nShowCmd);
  1202.     GetDlgItem(IDC_STATIC2)->ShowWindow(nShowCmd);
  1203.     GetDlgItem(IDC_EDIT2)->ShowWindow(nShowCmd);
  1204.     GetDlgItem(IDC_STATIC_EG2)->ShowWindow(nShowCmd);
  1205.     GetDlgItem(IDC_STATIC3)->ShowWindow(nShowCmd);
  1206.     GetDlgItem(IDC_EDIT3)->ShowWindow(nShowCmd);
  1207.     GetDlgItem(IDC_STATIC5)->ShowWindow(nShowCmd);
  1208.     GetDlgItem(IDC_STATIC_TITLE)->ShowWindow(nShowCmd);
  1209.     GetDlgItem(IDC_STATIC1)->ShowWindow(nShowCmd);
  1210.     if (nShowCmd == SW_SHOW)
  1211.     {       // init value
  1212.         SetDlgItemText(IDC_EDIT1, m_szFullName);
  1213.         SetDlgItemText(IDC_EDIT2, m_szEmail);   
  1214.         SetDlgItemText(IDC_EDIT3, m_szMailServer);
  1215.         GetDlgItem(IDC_EDIT1)->SetFocus();
  1216.     }
  1217.     else
  1218.     {       // save value
  1219.         char text[BUFSZ];
  1220.         if (GetDlgItemText(IDC_EDIT1, text, BUFSZ)) 
  1221.             m_szFullName = text;
  1222.         else 
  1223.             m_szFullName = "";
  1224.         if (GetDlgItemText(IDC_EDIT2, text, BUFSZ))  
  1225.             m_szEmail = text;
  1226.         else
  1227.             m_szEmail = "";
  1228.         if (GetDlgItemText(IDC_EDIT3, text, BUFSZ))  
  1229.             m_szMailServer = text;
  1230.         else 
  1231.             m_szMailServer = "";
  1232.     }
  1233. }
  1234.  
  1235. void CNewProfileWizard::ShowHideReceivePage(int nShowCmd)
  1236. {
  1237.     if (nShowCmd == SW_SHOW) {
  1238.         SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_READMAIL);
  1239.         SetControlText(IDC_STATIC1, IDS_READMAIL_STATIC1);
  1240.         SetControlText(IDC_STATIC_EG1, IDS_READMAIL_EG1);
  1241.         SetControlText(IDC_STATIC2, IDS_READMAIL_STATIC2);
  1242.         SetControlText(IDC_STATIC3, IDS_READMAIL_STATIC3);
  1243.         SetControlText(IDC_STATIC5, IDS_SENDREADMAIL_STATIC5);
  1244.     }
  1245.     GetDlgItem(IDC_EDIT1)->ShowWindow(nShowCmd);
  1246.     GetDlgItem(IDC_STATIC_EG1)->ShowWindow(nShowCmd);
  1247.     GetDlgItem(IDC_STATIC2)->ShowWindow(nShowCmd);
  1248.     GetDlgItem(IDC_EDIT2)->ShowWindow(nShowCmd);
  1249.     GetDlgItem(IDC_STATIC3)->ShowWindow(nShowCmd);
  1250.     GetDlgItem(IDC_READMAIL_POP1)->ShowWindow(nShowCmd);
  1251.     GetDlgItem(IDC_READMAIL_POP2)->ShowWindow(nShowCmd);
  1252.     GetDlgItem(IDC_READMAIL_IMAP)->ShowWindow(nShowCmd);
  1253.     GetDlgItem(IDC_STATIC5)->ShowWindow(nShowCmd);
  1254.     GetDlgItem(IDC_STATIC_TITLE)->ShowWindow(nShowCmd);
  1255.     GetDlgItem(IDC_STATIC1)->ShowWindow(nShowCmd);
  1256.     if (nShowCmd == SW_SHOW)
  1257.     {       // init value
  1258.         SetDlgItemText(IDC_EDIT1, m_szPopName);
  1259.         SetDlgItemText(IDC_EDIT2, m_szInMailServer);
  1260.         if (m_bUseIMAP)
  1261.             ((CButton*)GetDlgItem(IDC_READMAIL_IMAP))->SetCheck(TRUE);
  1262.         else if (m_bLeftOnServer)
  1263.             ((CButton*)GetDlgItem(IDC_READMAIL_POP2))->SetCheck(TRUE);
  1264.         else
  1265.             ((CButton*)GetDlgItem(IDC_READMAIL_POP1))->SetCheck(TRUE);
  1266.         GetDlgItem(IDC_EDIT1)->SetFocus();
  1267.     }
  1268.     else
  1269.     {       // save value
  1270.         char text[BUFSZ];
  1271.  
  1272.         m_bUseIMAP = m_bLeftOnServer = FALSE;
  1273.         if (GetDlgItemText(IDC_EDIT1, text, BUFSZ))  
  1274.             m_szPopName = text;
  1275.         else 
  1276.             m_szPopName = "";
  1277.         if (GetDlgItemText(IDC_EDIT2, text, BUFSZ)) 
  1278.             m_szInMailServer = text;
  1279.         else
  1280.             m_szInMailServer = "";
  1281.         if (IsDlgButtonChecked(IDC_READMAIL_IMAP)) 
  1282.             m_bUseIMAP = TRUE;
  1283.         else if (IsDlgButtonChecked(IDC_READMAIL_POP2))  
  1284.             m_bLeftOnServer = TRUE;
  1285.     }
  1286. }
  1287.  
  1288. void CNewProfileWizard::ShowHideNewsPage(int nShowCmd)
  1289. {
  1290.     if (nShowCmd == SW_SHOW) {
  1291.         SetControlText(IDC_STATIC_TITLE, IDS_WIZARD_READNEWS);
  1292.         SetControlText(IDC_STATIC1, IDS_READNEWS_STATIC1);
  1293.         SetControlText(IDC_STATIC2, IDS_READNEWS_STATIC2);
  1294.         if(theApp.m_bPEEnabled && m_bMucEnabled)
  1295.             SetControlText(IDC_STATIC5, IDS_PEMUC_NEWSPAGE);
  1296.         else
  1297.             SetControlText(IDC_STATIC5, IDS_READNEWS_STATIC5);
  1298.     }
  1299.     GetDlgItem(IDC_EDIT1)->ShowWindow(nShowCmd);
  1300.     GetDlgItem(IDC_STATIC5)->ShowWindow(nShowCmd);
  1301.     GetDlgItem(IDC_STATIC_TITLE)->ShowWindow(nShowCmd);
  1302.     GetDlgItem(IDC_STATIC1)->ShowWindow(nShowCmd);
  1303.     GetDlgItem(IDC_STATIC2)->ShowWindow(nShowCmd);
  1304.     GetDlgItem(IDC_EDIT2)->ShowWindow(nShowCmd);
  1305.     GetDlgItem(IDC_SECURE)->ShowWindow(nShowCmd);
  1306.     if (nShowCmd == SW_SHOW)
  1307.     {       // init value
  1308.         char szPort[16];
  1309.         SetDlgItemText(IDC_EDIT1, m_szNewsServer); 
  1310.         sprintf(szPort, "%ld", m_nPort);
  1311.         SetDlgItemText(IDC_EDIT2, szPort);
  1312.         if (m_bIsSecure)
  1313.             ((CButton*)GetDlgItem(IDC_SECURE))->SetCheck(TRUE);
  1314.         else
  1315.             ((CButton*)GetDlgItem(IDC_SECURE))->SetCheck(FALSE);
  1316.         GetDlgItem(IDC_EDIT1)->SetFocus();
  1317.     }
  1318.     else
  1319.     {       // save value
  1320.         char text[BUFSZ];
  1321.         if(GetDlgItemText(IDC_EDIT1, text, BUFSZ)) 
  1322.             m_szNewsServer = text;
  1323.         else 
  1324.             m_szNewsServer = "";
  1325.  
  1326.         if (IsDlgButtonChecked(IDC_SECURE)) 
  1327.             m_bIsSecure = TRUE;
  1328.         else
  1329.             m_bIsSecure = FALSE;
  1330.         if (GetDlgItemText(IDC_EDIT2, text, BUFSZ))
  1331.             m_nPort = atol(text);
  1332.         else
  1333.         {
  1334.             if (m_bIsSecure)
  1335.                 m_nPort = SECURE_NEWS_PORT;
  1336.             else
  1337.                 m_nPort = NEWS_PORT;
  1338.         }
  1339.     }
  1340. }
  1341.  
  1342. void CNewProfileWizard::ShowHidePEMucIntroPage(int nShowCmd)
  1343. {
  1344.     if(theApp.m_bPEEnabled && m_pMucIntroPage 
  1345.             && ::IsWindow(m_pMucIntroPage->GetSafeHwnd()))
  1346.         m_pMucIntroPage->ShowWindow(nShowCmd);    
  1347.     if(nShowCmd == SW_SHOW)
  1348.         SetFocus();
  1349. }
  1350.  
  1351. void CNewProfileWizard::ShowHidePEMucASWReadyPage(int nShowCmd)
  1352. {
  1353.     if(theApp.m_bPEEnabled && m_pASWReadyPage 
  1354.             && ::IsWindow(m_pASWReadyPage->GetSafeHwnd()))
  1355.         m_pASWReadyPage->ShowWindow(nShowCmd);
  1356.     if(nShowCmd == SW_SHOW)
  1357.         SetFocus();
  1358. }
  1359.  
  1360. void CNewProfileWizard::ShowHidePEMucReadyPage(int nShowCmd)
  1361. {
  1362.     if(theApp.m_bPEEnabled && m_pMucReadyPage 
  1363.             && ::IsWindow(m_pMucReadyPage->GetSafeHwnd()))
  1364.         m_pMucReadyPage->ShowWindow(nShowCmd);
  1365.     if(nShowCmd == SW_SHOW)
  1366.         SetFocus();
  1367. }
  1368.  
  1369. void CNewProfileWizard::ShowHidePEMucEditPage(int nShowCmd)
  1370.     CString m_str;
  1371.  
  1372.     if(theApp.m_bPEEnabled && m_pMucEditPage 
  1373.             && ::IsWindow(m_pMucEditPage->GetSafeHwnd()))
  1374.         m_pMucEditPage->ShowWindow(nShowCmd);
  1375.     if(nShowCmd == SW_SHOW)
  1376.     {
  1377.         if(m_bUpgrade)
  1378.             m_str.LoadString(IDS_PEMUCEDIT_UPGRADE);
  1379.         else
  1380.             m_str.LoadString(IDS_PEMUCEDIT_NORMAL);
  1381.         (m_pMucEditPage->GetDlgItem(IDC_EDIT_TEXT))->SetWindowText(m_str);
  1382.         SetFocus();
  1383.     }
  1384. }
  1385.  
  1386. void CNewProfileWizard::OnMove(int x, int y)
  1387. {
  1388.     CDialog::OnMove(x, y);
  1389.  
  1390.     if(theApp.m_bPEEnabled && m_pMucIntroPage && m_pASWReadyPage 
  1391.                             && m_pMucReadyPage && m_pMucEditPage)
  1392.     {   
  1393.         int     nShowCmd;
  1394.         
  1395.         if (m_nCurrentPage == ID_PEMUC_INTRO)   nShowCmd = SW_SHOW;
  1396.         else    nShowCmd = SW_HIDE;
  1397.         m_pMucIntroPage->SetMove(x,y, nShowCmd);  
  1398.         
  1399.         if (m_nCurrentPage == ID_PEMUC_ASWREADY)        nShowCmd = SW_SHOW;
  1400.         else    nShowCmd = SW_HIDE;
  1401.         m_pASWReadyPage->SetMove(x,y,nShowCmd);
  1402.             
  1403.         if (m_nCurrentPage == ID_PEMUC_MUCREADY)        nShowCmd = SW_SHOW;
  1404.         else    nShowCmd = SW_HIDE;
  1405.         m_pMucReadyPage->SetMove(x,y,nShowCmd);
  1406.         
  1407.         if (m_nCurrentPage == ID_PEMUC_MUCEDIT) nShowCmd = SW_SHOW;
  1408.         else    nShowCmd = SW_HIDE;
  1409.         m_pMucEditPage->SetMove(x,y,nShowCmd);  
  1410.     } 
  1411. }
  1412.  
  1413. // this internal function does not attempt to insure that every aspect of the
  1414. // path is valid.  If they enter an invalid character for example, it will show
  1415. // up when we attempt to create the directory.  This simply insures that there
  1416. // are no parts of the path greater than 8 characters...Since mkdir simply truncates
  1417. // this, it works but we are then screwed because we have the wrong pointer...
  1418. BOOL checkValidWin16Path(char *path) 
  1419. {
  1420.     BOOL bRet = TRUE;
  1421.     char * slash1 = path;  // start of path
  1422.     char * slash2 = strchr(path,'\\');
  1423.     
  1424.     if (!slash2) bRet = FALSE;  // need at least 1 slash!
  1425.  
  1426.     while (slash2) {
  1427.         // the difference between any 2 slashes can't be greater than 8
  1428.         if ((slash2 - slash1) > 9)
  1429.             bRet = FALSE;
  1430.         if (slash2+1) {
  1431.             slash1 = slash2;
  1432.             slash2 = strchr(slash2+1,'\\');
  1433.         } else slash2 = NULL;
  1434.     }
  1435.     // what is on the end can't be too large either
  1436.     if (strlen(slash1) > 9)  // 8 + slash
  1437.         bRet = FALSE;
  1438.     return bRet;    
  1439. }
  1440.  
  1441. BOOL CNewProfileWizard::DoFinish()
  1442. {
  1443.     if (!m_pFullName.IsEmpty())
  1444.         PREF_SetCharPref("mail.identity.username",m_pFullName);
  1445.     if (!m_pUserAddr.IsEmpty())
  1446.         PREF_SetCharPref("mail.identity.useremail",m_pUserAddr);
  1447.  
  1448.     char path[BUFSZ],name[BUFSZ];
  1449.     int ret;
  1450.     XP_StatStruct statinfo; 
  1451.  
  1452.     if (!GetDlgItemText(IDC_PROFILE_NAME, name, BUFSZ)) {
  1453.         AfxMessageBox(szLoadString(IDS_INVALID_PROFILE_NAME),MB_OK);
  1454.         return FALSE;
  1455.     }
  1456.  
  1457.     if (GetDlgItemText(IDC_PROFILE_DIR, path, BUFSZ)) { 
  1458.         if (path[strlen(path)-1] == '\\') path[strlen(path)-1] = NULL;  // remove last slash...
  1459.         
  1460.         if (!checkValidWin16Path(path)) {
  1461.             AfxMessageBox(szLoadString(IDS_INVALID_WIN16_DIR)); 
  1462.             return FALSE;
  1463.         }
  1464.         
  1465.         ret = _stat((char *) path, &statinfo);
  1466.         if (!ret) {
  1467.             // Directory already exists!
  1468.             if (AfxMessageBox(szLoadString(IDS_PROFDIR_EXISTS),MB_OKCANCEL) == IDCANCEL)
  1469.                 return FALSE;
  1470.             else 
  1471.                 m_bExistingDir = TRUE;
  1472.         }
  1473.         if(ret == -1) {
  1474.             char * slash = strchr(path,'\\');
  1475.             while (slash) {
  1476.                 slash[0] = NULL;
  1477.                 ret = _mkdir(path);
  1478.                 slash[0] = '\\';
  1479.                 if (slash+1) slash = strchr(slash+1,'\\');
  1480.             }
  1481.             ret = _mkdir(path);
  1482.             if (ret == -1) {
  1483.                 AfxMessageBox(szLoadString(IDS_UNABLE_CREATE_DIR),MB_OK);
  1484.                 return FALSE;
  1485.             }
  1486.         }
  1487.         // else "Warn already exists"
  1488.     } else {
  1489.         AfxMessageBox(szLoadString(IDS_INVALID_PROFILE_NAME),MB_OK);
  1490.         return FALSE;
  1491.     }
  1492.  
  1493.     
  1494.     if (GetDlgItemText(IDC_PROFILE_NAME, name, BUFSZ)) 
  1495.         login_CreateNewUserKey(name,path);
  1496.     
  1497.     m_pProfileName = name;
  1498.     m_pProfilePath = path;
  1499.  
  1500.     // PE finish - 
  1501.     if (theApp.m_bPEEnabled)
  1502.     {
  1503.         // asw thread
  1504.         if(m_bASWEnabled && m_pASWReadyPage && ::IsWindow(m_pASWReadyPage->GetSafeHwnd()))
  1505.             m_pASWReadyPage->DoFinish();
  1506.  
  1507.         // dialer cfg thread
  1508.         else if (m_bMucEnabled && m_pMucEditPage && ::IsWindow(m_pMucEditPage->GetSafeHwnd()))
  1509.                     m_pMucEditPage->DoFinish();
  1510.  
  1511.         // network thread   
  1512.         else
  1513.         {
  1514.             CMucProc        m_mucProc;
  1515.             m_mucProc.SetDialOnDemand("",FALSE);
  1516.         }
  1517.     }
  1518.  
  1519.     CButton * pMove = (CButton *) GetDlgItem(IDC_MOVEFILES);
  1520.     CButton * pCopy = (CButton *) GetDlgItem(IDC_COPYFILES);
  1521.     CButton * pIgnore = (CButton *) GetDlgItem(IDC_IGNOREFILES);
  1522.     int iMove = TRUE;
  1523.     int iCopy = FALSE;
  1524.     int iIgnore = FALSE;
  1525.  
  1526.     if (m_bUpgrade) {
  1527.         if (pMove)
  1528.             iMove = pMove->GetCheck();
  1529.         if (pCopy)
  1530.             iCopy = pCopy->GetCheck();
  1531.         if (pIgnore)
  1532.             iIgnore = pIgnore->GetCheck();
  1533.     } else {
  1534.         iIgnore = TRUE;
  1535.         iMove = FALSE;
  1536.         iCopy = FALSE;
  1537.     }
  1538.  
  1539.     if (iMove) {
  1540.         login_UpdateFilesToNewLocation(m_pProfilePath,this,FALSE);  // move files
  1541.         login_UpdatePreferencesToJavaScript(m_pProfilePath); // upgrade prefs
  1542.     } else if (iCopy) {
  1543.         login_UpdateFilesToNewLocation(m_pProfilePath,this,TRUE);  // Copy files
  1544.         login_UpdatePreferencesToJavaScript(m_pProfilePath); // upgrade prefs
  1545.     } else {
  1546.         // just create the directories --
  1547.         login_CreateEmptyProfileDir(m_pProfilePath, this, m_bExistingDir); 
  1548.     }
  1549.  
  1550.     if (!m_bUpgrade) {
  1551. #ifdef MOZ_MAIL_NEWS
  1552.         PREF_SetCharPref("mail.identity.username", m_szFullName);
  1553.         PREF_SetCharPref("mail.identity.useremail", m_szEmail);
  1554.         PREF_SetCharPref("network.hosts.smtp_server", m_szMailServer);
  1555.  
  1556.         PREF_SetCharPref("network.hosts.pop_server", m_szInMailServer);
  1557.  
  1558.         PREF_SetCharPref("mail.pop_name", m_szPopName);
  1559.  
  1560.         if (m_bUseIMAP) 
  1561.         {
  1562.             PREF_SetBoolPref("mail.leave_on_server", m_bUseIMAP);
  1563.         }
  1564.         else
  1565.         {
  1566.             PREF_SetBoolPref("mail.leave_on_server", m_bLeftOnServer);
  1567.         }
  1568.         long imapPref = m_bUseIMAP ? MSG_Imap4 : MSG_Pop3;
  1569.         PREF_SetIntPref("mail.server_type", imapPref);
  1570.  
  1571.         char szPort[10];
  1572.         int  nPortLen = 0;
  1573.         int     nNewsServerLen = 0;
  1574.  
  1575.         if (nNewsServerLen = GetDlgItemText(IDC_EDIT1, name, BUFSZ)) 
  1576.             m_szNewsServer = name;
  1577.         else 
  1578.             m_szNewsServer = "";
  1579.  
  1580.         if (IsDlgButtonChecked(IDC_SECURE)) 
  1581.             m_bIsSecure = TRUE;
  1582.         else
  1583.             m_bIsSecure = FALSE;
  1584.         if (nPortLen = GetDlgItemText(IDC_EDIT2, szPort, 10) > 0)
  1585.             m_nPort = atoi(szPort);
  1586.         else
  1587.         {
  1588.             if (m_bIsSecure)
  1589.                 m_nPort = SECURE_NEWS_PORT;
  1590.             else
  1591.                 m_nPort = NEWS_PORT;
  1592.         }
  1593.  
  1594.         if (nNewsServerLen && nPortLen)
  1595.         {
  1596.             if (m_nPort < 0 || m_nPort> MAX_PORT_NUMBER)
  1597.             {
  1598.                 AfxMessageBox(IDS_PORT_RANGE);
  1599.                 ((CEdit*)GetDlgItem(IDC_EDIT2))->SetFocus();
  1600.                 ((CEdit*)GetDlgItem(IDC_EDIT2))->SetSel((DWORD)MAKELONG(0, -1));
  1601.                 return FALSE;        
  1602.             }
  1603.             if (!::IsNumeric(szPort))
  1604.             {
  1605.                 AfxMessageBox(IDS_NUMBERS_ONLY);
  1606.                 ((CEdit*)GetDlgItem(IDC_EDIT2))->SetFocus();
  1607.                 ((CEdit*)GetDlgItem(IDC_EDIT2))->SetSel((DWORD)MAKELONG(0, -1));
  1608.                 return FALSE;
  1609.             }
  1610.         }
  1611.  
  1612.         PREF_SetCharPref("network.hosts.nntp_server", LPCTSTR(m_szNewsServer));
  1613.  
  1614.         if (nNewsServerLen)
  1615.         {
  1616.             PREF_SetBoolPref("news.server_is_secure", m_bIsSecure);
  1617.             PREF_SetIntPref("news.server_port", (int32)m_nPort);
  1618.         }
  1619.         else
  1620.         {
  1621.             PREF_SetBoolPref("news.server_is_secure", FALSE);
  1622.             PREF_SetIntPref("news.server_port", (int32)NEWS_PORT);
  1623.         }
  1624. #endif // MOZ_MAIL_NEWS
  1625.  
  1626.         PREF_SavePrefFile();
  1627.     }
  1628.     return TRUE;
  1629. }
  1630.  
  1631. void CNewProfileWizard::OnCheckSecure()
  1632. {
  1633.     char port[16];
  1634.     BOOL bIsSecure;
  1635.  
  1636.     if (IsDlgButtonChecked(IDC_SECURE))
  1637.         bIsSecure = TRUE;
  1638.     else
  1639.         bIsSecure = FALSE;
  1640.     if (GetDlgItemText(IDC_EDIT2, port, 16) == 0)
  1641.     {
  1642.         if (bIsSecure)
  1643.             SetDlgItemInt(IDC_EDIT2, SECURE_NEWS_PORT);
  1644.         else
  1645.             SetDlgItemInt(IDC_EDIT2, NEWS_PORT);
  1646.     }
  1647.     else
  1648.     {
  1649.         int32 lPort = atol(port);
  1650.  
  1651.         if (bIsSecure && lPort == NEWS_PORT)
  1652.             SetDlgItemInt(IDC_EDIT2, SECURE_NEWS_PORT);
  1653.         else  if (!bIsSecure && lPort == SECURE_NEWS_PORT)
  1654.             SetDlgItemInt(IDC_EDIT2, NEWS_PORT);
  1655.     }
  1656. }
  1657.  
  1658. BEGIN_MESSAGE_MAP(CNewProfileWizard, CDialog)
  1659.     ON_BN_CLICKED(IDC_BUTTON_BACK, DoBack)
  1660.     ON_BN_CLICKED(IDOK, DoNext)
  1661.     ON_BN_CLICKED(IDC_SECURE, OnCheckSecure)
  1662.     ON_WM_MOVE()
  1663. END_MESSAGE_MAP()
  1664.  
  1665. #endif XPWIN_32
  1666.