home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / PrefsCacheMore.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.0 KB  |  311 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.  
  20. /*
  21.    PrefsCacheMore.cpp -- The more dialog for cache preferences
  22.  
  23.    Created: Linda Wei <lwei@netscape.com>, 04-Dec-96.
  24.  */
  25.  
  26.  
  27. #include "felocale.h"
  28. #include "structs.h"
  29. #include "fonts.h"
  30. #include "xpassert.h"
  31. #include "xfe.h"
  32. #include "e_kit.h"
  33. #include "PrefsCacheMore.h"
  34. #include "prefapi.h"
  35.  
  36. #include <Xm/Label.h>
  37. #include <Xm/LabelG.h>
  38. #include <Xm/PushB.h>
  39. #include <Xm/PushBG.h>
  40. #include <Xm/ToggleB.h>
  41. #include <Xm/Form.h>
  42. #include <Xm/Frame.h>
  43. #include <Xm/TextF.h> 
  44. #include <Xm/ToggleBG.h> 
  45. #include <Xfe/Xfe.h>
  46.  
  47. extern int XFE_ERROR_SAVING_OPTIONS;
  48.  
  49. extern "C"
  50. {
  51.     void        NET_SetDiskCacheSize(int32 new_size);
  52.     void        NET_SetMemoryCacheSize(int32 new_size);
  53.     int         NET_CleanupCacheDirectory(char * dir_name, const char * prefix);
  54.     void        NET_WriteCacheFAT(char *filename, Bool final_call);
  55.  
  56.     Dimension   XfeWidth(Widget w);
  57.     char       *XP_GetString(int i);
  58. }
  59.  
  60. // ==================== Public Member Functions ====================
  61.  
  62. // Member:       XFE_PrefsCacheMoreDialog
  63. // Description:  Constructor
  64. // Inputs:
  65. // Side effects: Creates the More dialog for Cache Preferences
  66.  
  67. XFE_PrefsCacheMoreDialog::XFE_PrefsCacheMoreDialog(
  68.                           XFE_PrefsDialog *prefsDialog,
  69.                           Widget     parent,      // dialog parent
  70.                           char      *name,        // dialog name
  71.                           Boolean    modal)       // modal dialog?
  72.     : XFE_Dialog(parent, 
  73.                  name,
  74.                  TRUE,     // ok
  75.                  TRUE,     // cancel
  76.                  FALSE,    // help
  77.                  FALSE,    // apply
  78.                  FALSE,    // separator
  79.                  modal     // modal
  80.                  ),
  81.       m_prefsDialog(prefsDialog),
  82.       m_prefsDataCacheMore(0)
  83. {
  84.     PrefsDataCacheMore *fep = NULL;
  85.  
  86.     fep = new PrefsDataCacheMore;
  87.     memset(fep, 0, sizeof(PrefsDataCacheMore));
  88.     m_prefsDataCacheMore = fep;
  89.     
  90.     Widget     kids[100];
  91.     Arg        av[50];
  92.     int        ac;
  93.     int        i;
  94.  
  95.     Widget     form;
  96.     form = XtVaCreateWidget("form", xmFormWidgetClass, m_chrome,
  97.                             XmNtopAttachment, XmATTACH_FORM,
  98.                             XmNleftAttachment, XmATTACH_FORM,
  99.                             XmNrightAttachment, XmATTACH_FORM,
  100.                             XmNbottomAttachment, XmATTACH_FORM,
  101.                             NULL);
  102.     XtManageChild (form);
  103.  
  104.     Widget label;
  105.  
  106.     ac = 0;
  107.     XtSetArg (av [ac], XmNchildType, XmFRAME_TITLE_CHILD); ac++;
  108.     label = XmCreateLabelGadget (form, "cacheLabel", av, ac);
  109.     XtManageChild (label);
  110.  
  111.     Widget clear_disk_cache_button;
  112.     Widget clear_mem_cache_button;
  113.  
  114.     ac = 0;
  115.     i = 0;
  116.  
  117.     kids[i++] = clear_disk_cache_button = 
  118.         XmCreatePushButtonGadget (form, "clearDiskCache", av, ac);
  119.  
  120.     kids[i++] = clear_mem_cache_button =  
  121.         XmCreatePushButtonGadget (form, "clearMemCache", av, ac);
  122.  
  123.     int labels_width;
  124.     labels_width = XfeVaGetWidestWidget(clear_disk_cache_button,
  125.                                         clear_mem_cache_button,
  126.                                         NULL);
  127.  
  128.     XtVaSetValues(label,
  129.                   XmNtopAttachment, XmATTACH_FORM,
  130.                   XmNleftAttachment, XmATTACH_FORM,
  131.                   XmNrightAttachment, XmATTACH_NONE,
  132.                   XmNbottomAttachment, XmATTACH_NONE,
  133.                   NULL);
  134.     
  135.     Dimension form_width = XfeWidth(label);
  136.     int button_offset = (form_width - labels_width) / 2;
  137.     if (button_offset < 0) button_offset = 0;
  138.  
  139.     XtVaSetValues(clear_disk_cache_button,
  140.                   XmNwidth, labels_width,
  141.                   XmNtopAttachment, XmATTACH_WIDGET,
  142.                   XmNtopWidget, label,
  143.                   XmNleftAttachment, XmATTACH_FORM,
  144.                   XmNleftOffset, button_offset,
  145.                   XmNrightAttachment, XmATTACH_NONE,
  146.                   XmNbottomAttachment, XmATTACH_NONE,
  147.                   NULL);
  148.     
  149.     XtVaSetValues(clear_mem_cache_button,
  150.                   XmNwidth, labels_width,
  151.                   XmNtopAttachment, XmATTACH_WIDGET,
  152.                   XmNtopWidget, clear_disk_cache_button,
  153.                   XmNleftAttachment, XmATTACH_FORM,
  154.                   XmNleftOffset, button_offset,
  155.                   XmNrightAttachment, XmATTACH_NONE,
  156.                   XmNbottomAttachment, XmATTACH_NONE,
  157.                   NULL);
  158.     
  159.     // Add callbacks
  160.  
  161.     XtAddCallback(clear_disk_cache_button, XmNactivateCallback,
  162.                   prefsCacheMoreCb_clearDisk, this);
  163.     XtAddCallback(clear_mem_cache_button, XmNactivateCallback,
  164.                   prefsCacheMoreCb_clearMem, this);
  165.  
  166.     XtAddCallback(m_chrome, XmNokCallback, prefsCacheMoreCb_ok, this);
  167.     XtAddCallback(m_chrome, XmNcancelCallback, prefsCacheMoreCb_cancel, this);
  168.  
  169.     XtManageChildren(kids, i);
  170. }
  171.  
  172. // Member:       ~XFE_PrefsCacheMoreDialog
  173. // Description:  Destructor
  174. // Inputs:
  175. // Side effects: 
  176.  
  177. XFE_PrefsCacheMoreDialog::~XFE_PrefsCacheMoreDialog()
  178. {
  179.     // Clean up
  180.  
  181.     delete m_prefsDataCacheMore;
  182. }
  183.  
  184. // Member:       show
  185. // Description:  Pop up dialog
  186. // Inputs:
  187. // Side effects: 
  188.  
  189. void XFE_PrefsCacheMoreDialog::show()
  190. {
  191.     // TODO: Initialize the dialog
  192.  
  193.     // Manage the top level
  194.  
  195.     XFE_Dialog::show();
  196.  
  197.     // Set focus to the OK button
  198.  
  199.     XmProcessTraversal(m_okButton, XmTRAVERSE_CURRENT);
  200. }
  201.  
  202. // Member:       initPage
  203. // Description:  Initializes page for MailNewsCacheMore
  204. // Inputs:
  205. // Side effects: 
  206.  
  207. void XFE_PrefsCacheMoreDialog::initPage()
  208. {
  209. }
  210.  
  211. // Member:       verifyPage
  212. // Description:  verify page for MailNewsCacheMore
  213. // Inputs:
  214. // Side effects: 
  215.  
  216. Boolean XFE_PrefsCacheMoreDialog::verifyPage()
  217. {
  218.     return TRUE;
  219. }
  220.  
  221. // Member:       installChanges
  222. // Description:  install changes for CacheMore
  223. // Inputs:
  224. // Side effects: 
  225.  
  226. void XFE_PrefsCacheMoreDialog::installChanges()
  227. {
  228. }
  229.  
  230. // Member:       getContext
  231. // Description:  returns context
  232. // Inputs:
  233. // Side effects: 
  234.  
  235. MWContext *XFE_PrefsCacheMoreDialog::getContext()
  236. {
  237.     return (m_prefsDialog->getContext());
  238. }
  239.  
  240. // Friend:       prefsCacheMoreCb_ok
  241. // Description:  
  242. // Inputs:
  243. // Side effects: 
  244.  
  245. void prefsCacheMoreCb_ok(Widget    w,
  246.                          XtPointer closure,
  247.                          XtPointer callData)
  248. {
  249.     // Simulate a cancel
  250.  
  251.     prefsCacheMoreCb_cancel(w, closure, callData);
  252. }
  253.  
  254. // Friend:       prefsCacheMoreCb_cancel
  255. // Description:  
  256. // Inputs:
  257. // Side effects: 
  258.  
  259. void prefsCacheMoreCb_cancel(Widget    /* w */,
  260.                              XtPointer closure,
  261.                              XtPointer /* callData */)
  262. {
  263.     XFE_PrefsCacheMoreDialog *theDialog = (XFE_PrefsCacheMoreDialog *)closure;
  264.  
  265.     // Delete the dialog
  266.  
  267.     delete theDialog;
  268. }
  269.  
  270. // Friend:       prefsCacheMoreCb_clearDisk
  271. // Description:  
  272. // Inputs:
  273. // Side effects: 
  274.  
  275. void prefsCacheMoreCb_clearDisk(Widget    /* w */,
  276.                                 XtPointer closure,
  277.                                 XtPointer /* callData */)
  278. {
  279.     XFE_PrefsCacheMoreDialog     *theDialog = (XFE_PrefsCacheMoreDialog *)closure;
  280.     MWContext                    *context = theDialog->getContext();
  281.     int32                         size;
  282.  
  283.     if (XFE_Confirm (context, fe_globalData.clear_disk_cache_message))    {
  284.         PREF_GetIntPref("browser.cache.disk_cache_size", &size);
  285.         PREF_SetIntPref("browser.cache.disk_cache_size", 0);
  286.         PREF_SetIntPref("browser.cache.disk_cache_size", size);
  287.     }
  288. }
  289.  
  290. // Friend:       prefsCacheMoreCb_clearMem
  291. // Description:  
  292. // Inputs:
  293. // Side effects: 
  294.  
  295. void prefsCacheMoreCb_clearMem(Widget    /* w */,
  296.                                XtPointer closure,
  297.                                XtPointer /* callData */)
  298. {
  299.     XFE_PrefsCacheMoreDialog     *theDialog = (XFE_PrefsCacheMoreDialog *)closure;
  300.     MWContext                    *context = theDialog->getContext();
  301.     int32                         size;
  302.  
  303.     if (XFE_Confirm (context, fe_globalData.clear_mem_cache_message)) {
  304.         PREF_GetIntPref("browser.cache.memory_cache_size", &size);
  305.         PREF_SetIntPref("browser.cache.memory_cache_size", 0);
  306.         PREF_SetIntPref("browser.cache.memory_cache_size", size);
  307.     }
  308. }
  309.  
  310.  
  311.