home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / prefs / brpref / src / advpages.cpp next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  23.9 KB  |  788 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 "pch.h"
  20. #include <assert.h>
  21. #include "dllcom.h"
  22. #include "pages.h"
  23. #include "resource.h"
  24. #include "xp_core.h"
  25. #include "xp_help.h"
  26. #include "net.h"
  27. #include "prefapi.h"
  28. #ifdef _WIN32
  29. #include <shlobj.h>
  30. #endif
  31.  
  32. //Bug# 61956 disable mailnews prefs lock check for B4
  33. //also in mnpref\src\pages.h, winfe\mnprefs.cpp
  34. //enable for B6
  35. #define MNPREF_PrefIsLocked(pPrefName) PREF_PrefIsLocked(pPrefName)
  36.  
  37. /////////////////////////////////////////////////////////////////////////////
  38. // Helper functions
  39.  
  40. static int NEAR
  41. PREF_GetUnsignedPref(LPCSTR lpszPref, unsigned *puVal)
  42. {
  43.     int32    n;
  44.     int        nResult;
  45.  
  46.     nResult = PREF_GetIntPref(lpszPref, &n);
  47.     *puVal = (unsigned)n;
  48.     return nResult;
  49. }
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CAdvancedPrefs implementation
  53.  
  54. CAdvancedPrefs::CAdvancedPrefs()
  55.     : CBrowserPropertyPage(IDD_ADVANCED, HELP_PREFS_ADVANCED)
  56. {
  57. }
  58.  
  59. BOOL
  60. CAdvancedPrefs::InitDialog()
  61. {
  62.     // Check for locked preferences
  63.     CheckIfLockedPref("general.always_load_images", IDC_CHECK1);
  64.     CheckIfLockedPref("security.enable_java", IDC_CHECK2);
  65.     CheckIfLockedPref("javascript.enabled", IDC_CHECK3);
  66.     CheckIfLockedPref("browser.enable_style_sheets", IDC_CHECK4);
  67.     CheckIfLockedPref("autoupdate.enabled", IDC_CHECK5);
  68.     CheckIfLockedPref("security.email_as_ftp_password", IDC_CHECK6);
  69.  
  70.     if (PREF_PrefIsLocked("network.cookie.cookieBehavior")) {
  71.         // Disable all the radio buttons in the group
  72.         DisableRadioButtonGroup(IDC_RADIO1);
  73.     }
  74.  
  75.     CheckIfLockedPref("network.cookie.warnAboutCookies", IDC_CHECK7);
  76.  
  77.     return CBrowserPropertyPage::InitDialog();
  78. }
  79.  
  80. // Initialize member data using XP preferences
  81. STDMETHODIMP
  82. CAdvancedPrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  83. {
  84.     if (!m_bHasBeenActivated) {
  85.         PREF_GetBoolPref("general.always_load_images", &m_bAutoLoadImages);
  86.         PREF_GetBoolPref("security.enable_java", &m_bEnableJava);
  87.         PREF_GetBoolPref("javascript.enabled", &m_bEnableJavaScript);
  88.         PREF_GetBoolPref("browser.enable_style_sheets", &m_bEnableStyleSheets);
  89.         PREF_GetBoolPref("autoupdate.enabled", &m_bEnableAutoInstall);
  90.         PREF_GetBoolPref("security.email_as_ftp_password", &m_bSendEmailAddressForFTPPassword);
  91.  
  92.         int32    n;
  93.  
  94.         PREF_GetIntPref("network.cookie.cookieBehavior", &n);
  95.         m_nCookieAcceptance = (int)n;
  96.  
  97.         PREF_GetBoolPref("network.cookie.warnAboutCookies", &m_bWarnAboutCookies);
  98.     }
  99.  
  100.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  101. }
  102.  
  103. BOOL
  104. CAdvancedPrefs::DoTransfer(BOOL bSaveAndValidate)
  105. {
  106.     CheckBoxTransfer(IDC_CHECK1, m_bAutoLoadImages, bSaveAndValidate);
  107.     CheckBoxTransfer(IDC_CHECK2, m_bEnableJava, bSaveAndValidate);
  108.     CheckBoxTransfer(IDC_CHECK3, m_bEnableJavaScript, bSaveAndValidate);
  109.     CheckBoxTransfer(IDC_CHECK4, m_bEnableStyleSheets, bSaveAndValidate);
  110.     CheckBoxTransfer(IDC_CHECK5, m_bEnableAutoInstall, bSaveAndValidate);
  111.     CheckBoxTransfer(IDC_CHECK6, m_bSendEmailAddressForFTPPassword, bSaveAndValidate);
  112.     RadioButtonTransfer(IDC_RADIO1, m_nCookieAcceptance, bSaveAndValidate);
  113.     CheckBoxTransfer(IDC_CHECK7, m_bWarnAboutCookies, bSaveAndValidate);
  114.     return TRUE;
  115. }
  116.  
  117. // Apply changes using XP preferences
  118. BOOL
  119. CAdvancedPrefs::ApplyChanges()
  120. {
  121.     PREF_SetBoolPref("general.always_load_images", m_bAutoLoadImages);
  122.     PREF_SetBoolPref("security.enable_java", m_bEnableJava);
  123.     PREF_SetBoolPref("javascript.enabled", m_bEnableJavaScript);
  124.     PREF_SetBoolPref("browser.enable_style_sheets", m_bEnableStyleSheets);
  125.     PREF_SetBoolPref("autoupdate.enabled", m_bEnableAutoInstall);
  126.     PREF_SetBoolPref("security.email_as_ftp_password", m_bSendEmailAddressForFTPPassword);
  127.     PREF_SetIntPref("network.cookie.cookieBehavior", (int32)m_nCookieAcceptance);
  128.     PREF_SetBoolPref("network.cookie.warnAboutCookies", m_bWarnAboutCookies);
  129.     return TRUE;
  130. }
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CCachePrefs implementation
  134.  
  135. CCachePrefs::CCachePrefs()
  136. #ifdef _WIN32
  137.     : CBrowserPropertyPage(IDD_CACHE, HELP_PREFS_ADVANCED_CACHE)
  138. #else
  139.     : CBrowserPropertyPage(IDD_CACHE16, HELP_PREFS_ADVANCED_CACHE)
  140. #endif
  141. {
  142. }
  143.  
  144. // Initialize member data using XP preferences
  145. STDMETHODIMP
  146. CCachePrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  147. {
  148.     if (!m_bHasBeenActivated) {
  149.         int32    n;
  150.         
  151.         PREF_GetIntPref("browser.cache.disk_cache_size", &n);
  152.         m_uDiskCacheSize = (UINT)n;
  153.  
  154.         PREF_GetIntPref("browser.cache.memory_cache_size", &n);
  155.         m_uMemoryCacheSize = (UINT)n;
  156.  
  157.         PREF_GetStringPref("browser.cache.directory", m_strDiskCacheDir);
  158.         
  159.         PREF_GetIntPref("browser.cache.check_doc_frequency", &n);
  160.         m_nCheckDocFrequency = (int)n;
  161.     }
  162.  
  163.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  164. }
  165.  
  166. BOOL
  167. CCachePrefs::DoTransfer(BOOL bSaveAndValidate)
  168. {
  169.     EditFieldTransfer(IDC_EDIT1, m_uDiskCacheSize, bSaveAndValidate);
  170.     EditFieldTransfer(IDC_EDIT2, m_uMemoryCacheSize, bSaveAndValidate);
  171.     EditFieldTransfer(IDC_EDIT3, m_strDiskCacheDir, bSaveAndValidate);
  172.     RadioButtonTransfer(IDC_RADIO1, m_nCheckDocFrequency, bSaveAndValidate);
  173.     return TRUE;
  174. }
  175.  
  176. // Apply changes using XP preferences
  177. BOOL
  178. CCachePrefs::ApplyChanges()
  179. {
  180.     PREF_SetIntPref("browser.cache.disk_cache_size", (int32)m_uDiskCacheSize);
  181.     PREF_SetIntPref("browser.cache.memory_cache_size", (int32)m_uMemoryCacheSize);
  182.     PREF_SetCharPref("browser.cache.directory", (LPCSTR)m_strDiskCacheDir);
  183.     PREF_SetIntPref("browser.cache.check_doc_frequency", (int32)m_nCheckDocFrequency);
  184.     return TRUE;
  185. }
  186.  
  187. BOOL
  188. CCachePrefs::InitDialog()
  189. {
  190.     // Limit the length of the cache size fields
  191.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT1), 5);
  192.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT2), 5);
  193.  
  194.     // Check for locked preferences
  195.     CheckIfLockedPref("browser.cache.disk_cache_size", IDC_EDIT1);
  196.     CheckIfLockedPref("browser.cache.memory_cache_size", IDC_EDIT2);
  197.     if (CheckIfLockedPref("browser.cache.directory", IDC_EDIT3)) {
  198.         // Disable Choose Folder button
  199.         EnableDlgItem(IDC_BUTTON3, FALSE);
  200.     }
  201.  
  202.     if (PREF_PrefIsLocked("browser.cache.check_doc_frequency")) {
  203.         // Disable all the radio buttons in the group
  204.         DisableRadioButtonGroup(IDC_RADIO1);
  205.     }
  206.  
  207.     return CBrowserPropertyPage::InitDialog();
  208. }
  209.  
  210. #ifdef _WIN32
  211. BOOL
  212. CCachePrefs::BrowseForCacheFolder(LPSTR lpszPath)
  213. {
  214.     char            szDisplayName[MAX_PATH];
  215.     BROWSEINFO        bi;
  216.     LPITEMIDLIST    lpidl;
  217.     CString            strTitle;
  218.  
  219.     strTitle.LoadString(m_hInstance, IDS_CHOOSE_CACHE);
  220.  
  221.     // Initialize the browse info structure
  222.     memset(&bi, 0, sizeof(bi));
  223.     bi.hwndOwner = GetParent(m_hwndDlg);
  224.     bi.pszDisplayName = szDisplayName;
  225.     bi.lpszTitle = (LPCSTR)strTitle;
  226.     bi.ulFlags = BIF_RETURNONLYFSDIRS;
  227.  
  228.     // Display the dialog box to select a shell folder
  229.     lpidl = SHBrowseForFolder(&bi);
  230.     if (lpidl) {
  231.         LPMALLOC    pMalloc;
  232.  
  233.         // Get the file system path
  234.         SHGetPathFromIDList(lpidl, lpszPath);
  235.  
  236.         // Free the identifier list
  237.         SHGetMalloc(&pMalloc);
  238.         assert(pMalloc->DidAlloc(lpidl));
  239.         pMalloc->Free(lpidl);
  240.         pMalloc->Release();
  241.         return TRUE;
  242.     }
  243.  
  244.     return FALSE;
  245. }
  246. #endif
  247.  
  248. BOOL
  249. CCachePrefs::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  250. {
  251.     if (id == IDC_BUTTON1 && notifyCode == BN_CLICKED) {
  252.         CString    strText, strCaption;
  253.         int32    nSize;
  254.  
  255.         strText.LoadString(m_hInstance, IDS_CONTINUE_CLEAR_CACHE);
  256.         strCaption.LoadString(m_hInstance, IDS_DISK_CACHE);
  257.  
  258.         if (MessageBox(GetParent(m_hwndDlg), (LPCSTR)strText, (LPCSTR)strCaption, MB_OKCANCEL | MB_ICONQUESTION) == IDOK) {
  259.             PREF_GetIntPref("browser.cache.disk_cache_size", &nSize);
  260.             PREF_SetIntPref("browser.cache.disk_cache_size", 0);
  261.             PREF_SetIntPref("browser.cache.disk_cache_size", nSize);
  262.         }
  263.         return TRUE;
  264.  
  265.     } else if (id == IDC_BUTTON2 && notifyCode == BN_CLICKED) {
  266.         CString    strText, strCaption;
  267.         int32    nSize;
  268.  
  269.         strText.LoadString(m_hInstance, IDS_CONTINUE_CLEAR_MEM_CACHE);
  270.         strCaption.LoadString(m_hInstance, IDS_MEMORY_CACHE);
  271.  
  272.         if (MessageBox(GetParent(m_hwndDlg), (LPCSTR)strText, (LPCSTR)strCaption, MB_OKCANCEL | MB_ICONQUESTION) == IDOK) {
  273.             PREF_GetIntPref("browser.cache.memory_cache_size", &nSize);
  274.             PREF_SetIntPref("browser.cache.memory_cache_size", 0);
  275.             PREF_SetIntPref("browser.cache.memory_cache_size", nSize);
  276.         }
  277.         return TRUE;
  278.  
  279. #ifdef _WIN32
  280.     } else if (id == IDC_BUTTON3 && notifyCode == BN_CLICKED) {
  281.         char    szPath[_MAX_PATH];
  282.  
  283.         if (BrowseForCacheFolder(szPath))
  284.             Edit_SetText(GetDlgItem(m_hwndDlg, IDC_EDIT3), szPath);
  285. #endif
  286.     }
  287.  
  288.     return CBrowserPropertyPage::OnCommand(id, hwndCtl, notifyCode);
  289. }
  290.  
  291. /////////////////////////////////////////////////////////////////////////////
  292. // CViewProxiesDialog implementation
  293.  
  294. class CViewProxiesDialog : public CDialog {
  295.     public:
  296.         CViewProxiesDialog();
  297.  
  298.     protected:
  299.         BOOL    InitDialog();
  300.         BOOL    DoTransfer(BOOL bSaveAndValidate);
  301.         
  302.         // Event processing
  303.         void    OnOK();
  304.  
  305.     private:
  306.         CString        m_strHTTPServer;
  307.         unsigned    m_nHTTPPort;
  308.         CString        m_strSSLServer;
  309.         unsigned    m_nSSLPort;
  310.         CString        m_strFTPServer;
  311.         unsigned    m_nFTPPort;
  312.         CString        m_strSocksServer;
  313.         unsigned    m_nSocksPort;
  314.         CString        m_strGopherServer;
  315.         unsigned    m_nGopherPort;
  316.         CString        m_strWAISServer;
  317.         unsigned    m_nWAISPort;
  318.         CString        m_strNoProxiesOn;
  319. };
  320.  
  321. CViewProxiesDialog::CViewProxiesDialog()
  322.     : CDialog(CComDll::m_hInstance, IDD_VIEW_PROXIES)
  323. {
  324.     // Set member data using XP preferences
  325.     PREF_GetStringPref("network.proxy.http", m_strHTTPServer);
  326.     PREF_GetUnsignedPref("network.proxy.http_port", &m_nHTTPPort);
  327.  
  328.     PREF_GetStringPref("network.proxy.ssl", m_strSSLServer);
  329.     PREF_GetUnsignedPref("network.proxy.ssl_port", &m_nSSLPort);
  330.     
  331.     PREF_GetStringPref("network.proxy.ftp", m_strFTPServer);
  332.     PREF_GetUnsignedPref("network.proxy.ftp_port", &m_nFTPPort);
  333.     
  334.     PREF_GetStringPref("network.hosts.socks_server", m_strSocksServer);
  335.     PREF_GetUnsignedPref("network.hosts.socks_serverport", &m_nSocksPort);
  336.     
  337.     PREF_GetStringPref("network.proxy.gopher", m_strGopherServer);
  338.     PREF_GetUnsignedPref("network.proxy.gopher_port", &m_nGopherPort);
  339.     
  340.     PREF_GetStringPref("network.proxy.wais", m_strWAISServer);
  341.     PREF_GetUnsignedPref("network.proxy.wais_port", &m_nWAISPort);
  342.     
  343.     PREF_GetStringPref("network.proxy.no_proxies_on", m_strNoProxiesOn);
  344. }
  345.  
  346. BOOL
  347. CViewProxiesDialog::InitDialog()
  348. {
  349.     // Limit the length of the port numbers
  350.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT2), 5);
  351.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT4), 5);
  352.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT6), 5);
  353.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT8), 5);
  354.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT10), 5);
  355.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT12), 5);
  356.     
  357.     //  Disable any locked prefs.
  358.     if(PREF_PrefIsLocked("network.proxy.http")) {
  359.         EnableDlgItem(IDC_EDIT1, FALSE);
  360.     }
  361.     if(PREF_PrefIsLocked("network.proxy.http_port")) {
  362.         EnableDlgItem(IDC_EDIT2, FALSE);
  363.     }
  364.     if(PREF_PrefIsLocked("network.proxy.ssl")) {
  365.         EnableDlgItem(IDC_EDIT3, FALSE);
  366.     }
  367.     if(PREF_PrefIsLocked("network.proxy.ssl_port")) {
  368.         EnableDlgItem(IDC_EDIT4, FALSE);
  369.     }
  370.     if(PREF_PrefIsLocked("network.proxy.ftp")) {
  371.         EnableDlgItem(IDC_EDIT5, FALSE);
  372.     }
  373.     if(PREF_PrefIsLocked("network.proxy.ftp_port")) {
  374.         EnableDlgItem(IDC_EDIT6, FALSE);
  375.     }
  376.     if(PREF_PrefIsLocked("network.hosts.socks_server")) {
  377.         EnableDlgItem(IDC_EDIT7, FALSE);
  378.     }
  379.     if(PREF_PrefIsLocked("network.hosts.socks_serverport")) {
  380.         EnableDlgItem(IDC_EDIT8, FALSE);
  381.     }
  382.     if(PREF_PrefIsLocked("network.proxy.gopher")) {
  383.         EnableDlgItem(IDC_EDIT9, FALSE);
  384.     }
  385.     if(PREF_PrefIsLocked("network.proxy.gopher_port")) {
  386.         EnableDlgItem(IDC_EDIT10, FALSE);
  387.     }
  388.     if(PREF_PrefIsLocked("network.proxy.wais")) {
  389.         EnableDlgItem(IDC_EDIT11, FALSE);
  390.     }
  391.     if(PREF_PrefIsLocked("network.proxy.wais_port")) {
  392.         EnableDlgItem(IDC_EDIT12, FALSE);
  393.     }
  394.     if(PREF_PrefIsLocked("network.proxy.no_proxies_on")) {
  395.         EnableDlgItem(IDC_EDIT13, FALSE);
  396.     }
  397.  
  398.     return CDialog::InitDialog();
  399. }
  400.  
  401. BOOL
  402. CViewProxiesDialog::DoTransfer(BOOL bSaveAndValidate)
  403. {
  404.     EditFieldTransfer(IDC_EDIT1, m_strHTTPServer, bSaveAndValidate);
  405.     EditFieldTransfer(IDC_EDIT2, m_nHTTPPort, bSaveAndValidate);
  406.  
  407.     EditFieldTransfer(IDC_EDIT3, m_strSSLServer, bSaveAndValidate);
  408.     EditFieldTransfer(IDC_EDIT4, m_nSSLPort, bSaveAndValidate);
  409.  
  410.     EditFieldTransfer(IDC_EDIT5, m_strFTPServer, bSaveAndValidate);
  411.     EditFieldTransfer(IDC_EDIT6, m_nFTPPort, bSaveAndValidate);
  412.     
  413.     EditFieldTransfer(IDC_EDIT7, m_strSocksServer, bSaveAndValidate);
  414.     EditFieldTransfer(IDC_EDIT8, m_nSocksPort, bSaveAndValidate);
  415.     
  416.     EditFieldTransfer(IDC_EDIT9, m_strGopherServer, bSaveAndValidate);
  417.     EditFieldTransfer(IDC_EDIT10, m_nGopherPort, bSaveAndValidate);
  418.     
  419.     EditFieldTransfer(IDC_EDIT11, m_strWAISServer, bSaveAndValidate);
  420.     EditFieldTransfer(IDC_EDIT12, m_nWAISPort, bSaveAndValidate);
  421.     
  422.     EditFieldTransfer(IDC_EDIT13, m_strNoProxiesOn, bSaveAndValidate);
  423.     return TRUE;
  424. }
  425.  
  426. void
  427. CViewProxiesDialog::OnOK()
  428. {
  429.     // Transfer data from the dialog and then destroy the dialog window
  430.     CDialog::OnOK();
  431.  
  432.     // Apply changes using XP preferences
  433.     PREF_SetCharPref("network.proxy.http", m_strHTTPServer);
  434.     PREF_SetIntPref("network.proxy.http_port", (int32)m_nHTTPPort);
  435.  
  436.     PREF_SetCharPref("network.proxy.ssl", m_strSSLServer);
  437.     PREF_SetIntPref("network.proxy.ssl_port", (int32)m_nSSLPort);
  438.     
  439.     PREF_SetCharPref("network.proxy.ftp", m_strFTPServer);
  440.     PREF_SetIntPref("network.proxy.ftp_port", (int32)m_nFTPPort);
  441.     
  442.     PREF_SetCharPref("network.hosts.socks_server", m_strSocksServer);
  443.     PREF_SetIntPref("network.hosts.socks_serverport", (int32)m_nSocksPort);
  444.     
  445.     PREF_SetCharPref("network.proxy.gopher", m_strGopherServer);
  446.     PREF_SetIntPref("network.proxy.gopher_port", (int32)m_nGopherPort);
  447.     
  448.     PREF_SetCharPref("network.proxy.wais", m_strWAISServer);
  449.     PREF_SetIntPref("network.proxy.wais_port", (int32)m_nWAISPort);
  450.     
  451.     PREF_SetCharPref("network.proxy.no_proxies_on", m_strNoProxiesOn);
  452. }
  453.  
  454. /////////////////////////////////////////////////////////////////////////////
  455. // CProxiesPrefs implementation
  456.  
  457. CProxiesPrefs::CProxiesPrefs()
  458.     : CBrowserPropertyPage(IDD_PROXIES, HELP_PREFS_ADVANCED_PROXIES)
  459. {
  460. }
  461.  
  462. BOOL
  463. CProxiesPrefs::InitDialog()
  464. {
  465.     // Check for locked preferences
  466.     if (PREF_PrefIsLocked("network.proxy.type")) {
  467.         // Disable all the radio buttons in the group
  468.         DisableRadioButtonGroup(IDC_RADIO1);
  469.  
  470.         // Disable the View button to manually configure proxies
  471.         EnableDlgItem(IDC_BUTTON1, FALSE);
  472.  
  473.         // Disable edit field for the auto proxy config URL
  474.         EnableDlgItem(IDC_EDIT1, FALSE);
  475.     }
  476.  
  477.     return CBrowserPropertyPage::InitDialog();
  478. }
  479.  
  480. // Initialize member data using XP preferences
  481. STDMETHODIMP
  482. CProxiesPrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  483. {
  484.     if (!m_bHasBeenActivated) {
  485.         int32    n;
  486.  
  487.         PREF_GetIntPref("network.proxy.type", &n);
  488.  
  489.         // Map from netlib values
  490.         if (n == PROXY_STYLE_MANUAL)
  491.             m_nProxyType = 1;
  492.         else if (n == PROXY_STYLE_AUTOMATIC)
  493.             m_nProxyType = 2;
  494.         else
  495.             m_nProxyType = 0;
  496.  
  497.         PREF_GetStringPref("network.proxy.autoconfig_url", m_strAutoConfigURL);
  498.     }
  499.  
  500.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  501. }
  502.  
  503. BOOL
  504. CProxiesPrefs::DoTransfer(BOOL bSaveAndValidate)
  505. {
  506.     RadioButtonTransfer(IDC_RADIO1, m_nProxyType, bSaveAndValidate);
  507.     EditFieldTransfer(IDC_EDIT1, m_strAutoConfigURL, bSaveAndValidate);
  508.  
  509.     if (!bSaveAndValidate)
  510.         EnableControls();
  511.  
  512.     return TRUE;
  513. }
  514.  
  515. // Apply changes using XP preferences
  516. BOOL
  517. CProxiesPrefs::ApplyChanges()
  518. {
  519.     int32    n;
  520.  
  521.     // Convert to netlib values
  522.     if (m_nProxyType == 0)
  523.         n = PROXY_STYLE_NONE;
  524.     else if (m_nProxyType == 1)
  525.         n = PROXY_STYLE_MANUAL;
  526.     else {
  527.         assert(m_nProxyType == 2);
  528.         n = PROXY_STYLE_AUTOMATIC;
  529.     }
  530.     PREF_SetIntPref("network.proxy.type", n);
  531.  
  532.     PREF_SetCharPref("network.proxy.autoconfig_url", (LPCSTR)m_strAutoConfigURL);
  533.     return TRUE;
  534. }
  535.  
  536. void
  537. CProxiesPrefs::EnableControls()
  538. {
  539.     int    nProxyType;
  540.  
  541.     // Enable the buttons and edit field as appropriate
  542.     RadioButtonTransfer(IDC_RADIO1, nProxyType, TRUE);
  543.  
  544.     EnableDlgItem(IDC_BUTTON1, nProxyType == 1);
  545.     EnableDlgItem(IDC_EDIT1, nProxyType == 2);
  546.     EnableDlgItem(IDC_BUTTON2, nProxyType == 2);
  547. }
  548.  
  549. BOOL
  550. CProxiesPrefs::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  551. {
  552.     if (id == IDC_BUTTON1 && notifyCode == BN_CLICKED) {
  553.         CViewProxiesDialog    dlg;
  554.  
  555.         // Let the user manually configure the proxies
  556.         dlg.DoModal(GetParent(m_hwndDlg));
  557.         return TRUE;
  558.  
  559.     } else if (id == IDC_BUTTON2 && notifyCode == BN_CLICKED) {
  560.         CString    strAutoConfigURL;
  561.  
  562.         // Reload the auto-configuration proxy
  563.         PREF_GetStringPref("network.proxy.autoconfig_url", strAutoConfigURL);
  564.         PREF_SetCharPref("network.proxy.autoconfig_url", "");
  565.         PREF_SetCharPref("network.proxy.autoconfig_url", strAutoConfigURL);
  566.  
  567.     } else if (id == IDC_RADIO1 || id == IDC_RADIO2 || id == IDC_RADIO3) {
  568.         if (notifyCode == BN_CLICKED)
  569.             EnableControls();
  570.     }
  571.  
  572.     return CBrowserPropertyPage::OnCommand(id, hwndCtl, notifyCode);
  573. }
  574.  
  575. /////////////////////////////////////////////////////////////////////////////
  576. // CDiskSpacePrefs implementation
  577.  
  578. BOOL IsNumeric(char* pStr)
  579. {
  580.     
  581.     for (char* p = pStr; p && *p; p++)
  582.     {
  583.         if (0 == isdigit(*p))
  584.             return FALSE; 
  585.     }
  586.     return TRUE;
  587. }
  588.  
  589. void ValidateNumeric
  590. (HWND hParent, HINSTANCE hInst, int nCaptionID, int nID, int& data)
  591. {
  592.     HWND    hwndCtl = GetDlgItem(hParent, nID);
  593.     char    szBuf[32];
  594.     DWORD    dwStart, dwEnd;
  595.  
  596.     assert(hwndCtl);
  597.     Edit_GetText(hwndCtl, szBuf, sizeof(szBuf));
  598.     SendMessage(hwndCtl, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, 
  599.                 (LPARAM)(LPDWORD)&dwEnd);
  600.     if (!IsNumeric(szBuf))
  601.     {
  602.         CString    strText, strCaption;
  603.  
  604.         strText.LoadString(hInst, IDS_NUMERIC_ONLY);
  605.         strCaption.LoadString(hInst, nCaptionID);
  606.  
  607.         MessageBeep(MB_ICONHAND);
  608.         MessageBox(GetParent(hParent), (LPCSTR)strText, (LPCSTR)strCaption, 
  609.                    MB_OK | MB_ICONSTOP);
  610.  
  611.         wsprintf(szBuf, "%i", data);
  612.         Edit_SetText(hwndCtl, szBuf);
  613.         Edit_SetSel(hwndCtl, dwStart - 1, dwEnd - 1);
  614.     }
  615.     else
  616.     {
  617.         data = atoi(szBuf);
  618.     }
  619. }
  620.  
  621. CDiskSpacePrefs::CDiskSpacePrefs()
  622.     : CBrowserPropertyPage(IDD_DISK_SPACE, HELP_PREFS_ADVANCED_DISK_SPACE)
  623. {
  624. }
  625.  
  626. // Initialize member data using XP preferences
  627. STDMETHODIMP
  628. CDiskSpacePrefs::Activate(HWND hwndParent, LPCRECT lprc, BOOL bModal)
  629. {
  630.     if (!m_bHasBeenActivated) {
  631.         int32    n;
  632.  
  633.         PREF_GetBoolPref("mail.limit_message_size", &m_bLimitSize);
  634.         PREF_GetIntPref("mail.max_size", &n);
  635.         m_nLimitSize = (int)n;
  636.  
  637.         PREF_GetBoolPref("mail.prompt_purge_threshhold", &m_bPromptPurge);
  638.         PREF_GetIntPref("mail.purge_threshhold", &n);
  639.         m_nPurgeSize = (int)n;
  640.  
  641.         PREF_GetIntPref("news.keep.method", &n);
  642.  
  643.         // ui radio buttons do not correspond to the preference
  644.         if (n == 0)
  645.             m_nKeepMethod = 1;
  646.         else if (n == 1)
  647.             m_nKeepMethod = 0;
  648.         else
  649.             m_nKeepMethod = n;
  650.  
  651.         PREF_GetIntPref("news.keep.days", &n);
  652.         m_nKeepDays = (int)n;
  653.         PREF_GetIntPref("news.keep.count", &n);
  654.         m_nKeepCounts = (int)n;
  655.  
  656.         PREF_GetBoolPref("news.keep.only_unread", &m_bKeepUnread);
  657.         PREF_GetBoolPref("news.remove_bodies.by_age", &m_bRemoveBody);
  658.         PREF_GetIntPref("news.remove_bodies.days", &n);
  659.         m_nRemoveDays = (int)n;
  660.     }
  661.  
  662.     return CBrowserPropertyPage::Activate(hwndParent, lprc, bModal);
  663. }
  664.  
  665. BOOL 
  666. CDiskSpacePrefs::InitDialog()
  667. {
  668.     // Limit the length of the string the user can type
  669.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT_MSG_SIZE), 5);
  670.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT_COMPACT_SIZE), 5);
  671.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT_MSG_DAYS), 5);
  672.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT_MSG_COUNT), 5);
  673.     Edit_LimitText(GetDlgItem(m_hwndDlg, IDC_EDIT_MSG_DAYS), 5);
  674.  
  675.     // Check for locked preferences
  676.     if (MNPREF_PrefIsLocked("mail.limit_message_size"))
  677.         EnableDlgItem(IDC_CHECK_MSG_SIZE, FALSE);
  678.     if (MNPREF_PrefIsLocked("mail.max_size"))
  679.         EnableDlgItem(IDC_EDIT_MSG_SIZE, FALSE);
  680.     if (MNPREF_PrefIsLocked("mail.prompt_purge_threshhold"))
  681.         EnableDlgItem(IDC_CHECK_COMPACT_SIZE, FALSE);
  682.     if (MNPREF_PrefIsLocked("mail.purge_threshhold"))
  683.         EnableDlgItem(IDC_EDIT_COMPACT_SIZE, FALSE);
  684.  
  685.     if (MNPREF_PrefIsLocked("news.keep.method")) {
  686.         // Disable all the radio buttons in the group
  687.         DisableRadioButtonGroup(IDC_KEEP_MSG_DAYS);
  688.     }
  689.  
  690.     if (MNPREF_PrefIsLocked("news.keep.days"))
  691.         EnableDlgItem(IDC_EDIT_MSG_DAYS, FALSE);
  692.     if (MNPREF_PrefIsLocked("news.keep.count"))
  693.         EnableDlgItem(IDC_EDIT_MSG_COUNT, FALSE);
  694.     if (MNPREF_PrefIsLocked("news.keep.only_unread"))
  695.         EnableDlgItem(IDC_KEEP_UNREAD, FALSE);
  696.     
  697.     if (MNPREF_PrefIsLocked("news.remove_bodies.by_age"))
  698.         EnableDlgItem(IDC_CHECK_MSG_DAYS, FALSE);
  699.     if (MNPREF_PrefIsLocked("news.remove_bodies.days"))
  700.         EnableDlgItem(IDC_EDIT_MSG_DAYS, FALSE);
  701.  
  702.     return CBrowserPropertyPage::InitDialog();
  703. }
  704.  
  705. BOOL
  706. CDiskSpacePrefs::DoTransfer(BOOL bSaveAndValidate)
  707. {
  708.     CheckBoxTransfer(IDC_CHECK_MSG_SIZE, m_bLimitSize, bSaveAndValidate);
  709.     EditFieldTransfer(IDC_EDIT_MSG_SIZE, m_nLimitSize, bSaveAndValidate);
  710.     CheckBoxTransfer(IDC_CHECK_COMPACT_SIZE, m_bPromptPurge, bSaveAndValidate);
  711.     EditFieldTransfer(IDC_EDIT_COMPACT_SIZE, m_nPurgeSize, bSaveAndValidate);
  712.     RadioButtonTransfer(IDC_KEEP_MSG_DAYS, m_nKeepMethod, bSaveAndValidate);
  713.     EditFieldTransfer(IDC_EDIT_MSG_DAYS, m_nKeepDays, bSaveAndValidate);
  714.     EditFieldTransfer(IDC_EDIT_MSG_COUNT, m_nKeepCounts, bSaveAndValidate);
  715.     CheckBoxTransfer(IDC_KEEP_UNREAD, m_bKeepUnread, bSaveAndValidate);
  716.     CheckBoxTransfer(IDC_CHECK_MSG_DAYS, m_bRemoveBody, bSaveAndValidate);
  717.     EditFieldTransfer(IDC_EDIT_MSG_DAYS, m_nRemoveDays, bSaveAndValidate);
  718.  
  719.     return TRUE;
  720. }
  721.  
  722. // Apply changes using XP preferences
  723. BOOL
  724. CDiskSpacePrefs::ApplyChanges()
  725. {
  726.     PREF_SetBoolPref("mail.limit_message_size", m_bLimitSize);
  727.     PREF_SetIntPref("mail.max_size", (int32)m_nLimitSize);
  728.  
  729.     PREF_SetBoolPref("mail.prompt_purge_threshhold", m_bPromptPurge);
  730.     PREF_SetIntPref("mail.purge_threshhold", (int32)m_nPurgeSize);
  731.  
  732.     // ui radio buttons do not correspond to the preference
  733.     int32    realKeepMethod;
  734.     if (m_nKeepMethod == 0)
  735.         realKeepMethod = 1;
  736.     else if (m_nKeepMethod == 1)
  737.         realKeepMethod = 0;
  738.     else
  739.         realKeepMethod = m_nKeepMethod;
  740.  
  741.     PREF_SetIntPref("news.keep.method", (int32)realKeepMethod);
  742.     PREF_SetIntPref("news.keep.days", (int32)m_nKeepDays);
  743.     PREF_SetIntPref("news.keep.count", (int32)m_nKeepCounts);
  744.  
  745.     PREF_SetBoolPref("news.keep.only_unread", m_bKeepUnread);
  746.     PREF_SetBoolPref("news.remove_bodies.by_age", m_bRemoveBody);
  747.     PREF_SetIntPref("news.remove_bodies.days", (int32)m_nRemoveDays);
  748.  
  749.     return TRUE;
  750. }
  751.  
  752. BOOL
  753. CDiskSpacePrefs::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  754. {
  755.     switch (id)
  756.     {
  757.         case IDC_EDIT_MSG_SIZE:
  758.             if (notifyCode == EN_UPDATE)
  759.                 ValidateNumeric(m_hwndDlg, m_hInstance, IDS_DISK_SPACE,
  760.                                 id, m_nLimitSize);
  761.             return TRUE;
  762.  
  763.         case IDC_EDIT_COMPACT_SIZE:
  764.             if (notifyCode == EN_UPDATE)
  765.                 ValidateNumeric(m_hwndDlg, m_hInstance, IDS_DISK_SPACE, 
  766.                                 id, m_nPurgeSize);
  767.             return TRUE;
  768.  
  769.         case IDC_EDIT_MSG_DAYS:
  770.             if (notifyCode == EN_UPDATE)
  771.                 ValidateNumeric(m_hwndDlg, m_hInstance, IDS_DISK_SPACE, 
  772.                                 id, m_nKeepDays);
  773.             return TRUE;
  774.  
  775.         case IDC_EDIT_MSG_COUNT:
  776.             if (notifyCode == EN_UPDATE)
  777.                 ValidateNumeric(m_hwndDlg, m_hInstance, IDS_DISK_SPACE, 
  778.                                 id, m_nKeepCounts);
  779.             return TRUE;
  780.         case IDC_EDIT_MSG_DAYS2:
  781.             if (notifyCode == EN_UPDATE)
  782.                 ValidateNumeric(m_hwndDlg, m_hInstance, IDC_EDIT_MSG_DAYS, 
  783.                                 id, m_nRemoveDays);
  784.             return TRUE;
  785.     }
  786.     return CBrowserPropertyPage::OnCommand(id, hwndCtl, notifyCode);
  787. }
  788.