home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / PrefsDiskMore.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.0 KB  |  304 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.    PrefsDiskMore.cpp -- The more dialog for Offline Disk Space preference
  20.    Created: Linda Wei <lwei@netscape.com>, 16-Dec-96.
  21.  */
  22.  
  23. #include "felocale.h"
  24. #include "structs.h"
  25. #include "fonts.h"
  26. #include "xpassert.h"
  27. #include "xfe.h"
  28. #include "e_kit.h"
  29. #include "PrefsDiskMore.h"
  30.  
  31. #include <Xm/Label.h>
  32. #include <Xm/LabelG.h>
  33. #include <Xm/PushB.h>
  34. #include <Xm/PushBG.h>
  35. #include <Xm/ToggleB.h>
  36. #include <Xm/Form.h>
  37. #include <Xm/Frame.h>
  38. #include <Xm/TextF.h> 
  39. #include <Xm/ToggleBG.h> 
  40. #include <Xfe/Xfe.h>
  41.  
  42. extern int XFE_ERROR_SAVING_OPTIONS;
  43.  
  44. extern "C"
  45. {
  46.     char *XP_GetString(int i);
  47.     void fe_installDiskMore();
  48. }
  49.  
  50. // ==================== Public Member Functions ====================
  51.  
  52. // Member:       XFE_PrefsDiskMoreDialog
  53. // Description:  Constructor
  54. // Inputs:
  55. // Side effects: Creates the More dialog for Offline Disk Space Preferences
  56.  
  57. XFE_PrefsDiskMoreDialog::XFE_PrefsDiskMoreDialog(XFE_PrefsDialog *prefsDialog,
  58.                                      Widget     parent,      // dialog parent
  59.                                      char      *name,        // dialog name
  60.                                      Boolean    modal)       // modal dialog?
  61.     : XFE_Dialog(parent, 
  62.                  name,
  63.                  TRUE,     // ok
  64.                  TRUE,     // cancel
  65.                  FALSE,    // help
  66.                  FALSE,    // apply
  67.                  FALSE,    // separator
  68.                  modal     // modal
  69.                  ),
  70.       m_prefsDialog(prefsDialog),
  71.       m_prefsDataDiskMore(0)
  72. {
  73.     PrefsDataDiskMore *fep = NULL;
  74.  
  75.     fep = new PrefsDataDiskMore;
  76.     memset(fep, 0, sizeof(PrefsDataDiskMore));
  77.     m_prefsDataDiskMore = fep;
  78.     
  79.     Widget     form;
  80.     Widget     desc_label;
  81.     Widget     rm_msg_body_toggle;
  82.     Widget     num_days_text;
  83.     Widget     days_label;
  84.     Widget     kids[100];
  85.     Arg        av[50];
  86.     int        ac;
  87.     int        i;
  88.  
  89.     form = XtVaCreateWidget("form", xmFormWidgetClass, m_chrome,
  90.                             XmNtopAttachment, XmATTACH_FORM,
  91.                             XmNleftAttachment, XmATTACH_FORM,
  92.                             XmNrightAttachment, XmATTACH_FORM,
  93.                             XmNbottomAttachment, XmATTACH_FORM,
  94.                             NULL);
  95.     XtManageChild (form);
  96.  
  97.     ac = 0;
  98.     i = 0;
  99.  
  100.     kids[i++] = desc_label = 
  101.         XmCreateLabelGadget(form, "descLabel", av, ac);
  102.  
  103.     kids[i++] = rm_msg_body_toggle = 
  104.         XmCreateToggleButtonGadget (form, "rmMsgBodyToggle", av, ac);
  105.  
  106.     kids[i++] = num_days_text =
  107.         fe_CreateTextField(form, "numDaysText", av, ac);
  108.  
  109.     kids[i++] = days_label = 
  110.         XmCreateLabelGadget(form, "daysLabel", av, ac);
  111.  
  112.     XtVaSetValues(desc_label,
  113.                   XmNtopAttachment, XmATTACH_FORM,
  114.                   XmNleftAttachment, XmATTACH_FORM,
  115.                   XmNrightAttachment, XmATTACH_NONE,
  116.                   XmNbottomAttachment, XmATTACH_NONE,
  117.                   NULL);
  118.     
  119.     int labels_height;
  120.     labels_height = XfeVaGetTallestWidget(rm_msg_body_toggle,
  121.                                           num_days_text,
  122.                                           days_label,
  123.                                           NULL);
  124.  
  125.     XtVaSetValues(rm_msg_body_toggle,
  126.                   XmNheight, labels_height,
  127.                   XmNtopAttachment, XmATTACH_WIDGET,
  128.                   XmNtopWidget, desc_label,
  129.                   XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
  130.                   XmNleftWidget, desc_label,
  131.                   XmNrightAttachment, XmATTACH_NONE,
  132.                   XmNbottomAttachment, XmATTACH_NONE,
  133.                   NULL);
  134.     
  135.     XtVaSetValues(num_days_text,
  136.                   XmNheight, labels_height,
  137.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  138.                   XmNtopWidget, rm_msg_body_toggle,
  139.                   XmNleftAttachment, XmATTACH_WIDGET,
  140.                   XmNleftWidget, rm_msg_body_toggle,
  141.                   XmNrightAttachment, XmATTACH_NONE,
  142.                   XmNbottomAttachment, XmATTACH_NONE,
  143.                   NULL);
  144.     
  145.     XtVaSetValues(days_label,
  146.                   XmNheight, labels_height,
  147.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  148.                   XmNtopWidget, rm_msg_body_toggle,
  149.                   XmNleftAttachment, XmATTACH_WIDGET,
  150.                   XmNleftWidget, num_days_text,
  151.                   XmNrightAttachment, XmATTACH_NONE,
  152.                   XmNbottomAttachment, XmATTACH_NONE,
  153.                   NULL);
  154.     
  155.     fep->rm_msg_body_toggle = rm_msg_body_toggle;
  156.     fep->num_days_text = num_days_text;
  157.  
  158.     // Add callbacks
  159.  
  160.     XtAddCallback(m_chrome, XmNokCallback, prefsDiskMoreCb_ok, this);
  161.     XtAddCallback(m_chrome, XmNcancelCallback, prefsDiskMoreCb_cancel, this);
  162.  
  163.     XtManageChildren(kids, i);
  164. }
  165.  
  166. // Member:       ~XFE_PrefsDiskMoreDialog
  167. // Description:  Destructor
  168. // Inputs:
  169. // Side effects: 
  170.  
  171. XFE_PrefsDiskMoreDialog::~XFE_PrefsDiskMoreDialog()
  172. {
  173.     // Clean up
  174.  
  175.     delete m_prefsDataDiskMore;
  176. }
  177.  
  178. // Member:       show
  179. // Description:  Pop up dialog
  180. // Inputs:
  181. // Side effects: 
  182.  
  183. void XFE_PrefsDiskMoreDialog::show()
  184. {
  185.     // TODO: Initialize the dialog
  186.  
  187.     // Manage the top level
  188.  
  189.     XFE_Dialog::show();
  190.  
  191.     // Set focus to the OK button
  192.  
  193.     XmProcessTraversal(m_okButton, XmTRAVERSE_CURRENT);
  194. }
  195.  
  196. // Member:       initPage
  197. // Description:  Initializes page for MailNewsDiskMore
  198. // Inputs:
  199. // Side effects: 
  200.  
  201. void XFE_PrefsDiskMoreDialog::initPage()
  202. {
  203.     XP_ASSERT(m_prefsDataDiskMore);
  204.  
  205.     PrefsDataDiskMore  *fep = m_prefsDataDiskMore;
  206.     XFE_GlobalPrefs    *prefs = &fe_globalPrefs;
  207.     char                buf[1024];
  208.     
  209.     XtVaSetValues(fep->rm_msg_body_toggle, XmNset, prefs->news_remove_bodies_by_age, 0);
  210.     PR_snprintf(buf, sizeof(buf), "%d", prefs->news_remove_bodies_days);
  211.     XtVaSetValues(fep->num_days_text, XmNvalue, buf, 0);
  212. }
  213.  
  214. // Member:       verifyPage
  215. // Description:  verify page for MailNewsDiskMore
  216. // Inputs:
  217. // Side effects: 
  218.  
  219. Boolean XFE_PrefsDiskMoreDialog::verifyPage()
  220. {
  221.     return TRUE;
  222. }
  223.  
  224. // Member:       installChanges
  225. // Description:  install changes for MailNewsDiskMore
  226. // Inputs:
  227. // Side effects: 
  228.  
  229. void XFE_PrefsDiskMoreDialog::installChanges()
  230. {
  231.     fe_installDiskMore();
  232. }
  233.  
  234. // Member:       getContext
  235. // Description:  returns context
  236. // Inputs:
  237. // Side effects: 
  238.  
  239. MWContext *XFE_PrefsDiskMoreDialog::getContext()
  240. {
  241.     return (m_prefsDialog->getContext());
  242. }
  243.  
  244. // Member:       prefsDiskMoreCb_ok
  245. // Description:  
  246. // Inputs:
  247. // Side effects: 
  248.  
  249. void XFE_PrefsDiskMoreDialog::prefsDiskMoreCb_ok(Widget    w,
  250.                                                  XtPointer closure,
  251.                                                  XtPointer callData)
  252. {
  253.     XFE_PrefsDiskMoreDialog *theDialog = (XFE_PrefsDiskMoreDialog *)closure;
  254.     PrefsDataDiskMore       *fep = theDialog->m_prefsDataDiskMore;
  255.  
  256.     XP_ASSERT(fep);
  257.     if (! theDialog->verifyPage()) return;
  258.     
  259.     Boolean                     b;
  260.     char                        c;
  261.     char                       *s = 0;
  262.     int                         n;
  263.  
  264.     XtVaGetValues(fep->rm_msg_body_toggle, XmNset, &b, 0);
  265.     fe_globalPrefs.news_remove_bodies_by_age = b;
  266.  
  267.     XtVaGetValues(fep->num_days_text, XmNvalue, &s, 0);
  268.     fe_globalPrefs.news_remove_bodies_days = 0;
  269.     if (1 == sscanf (s, " %d %c", &n, &c))
  270.       fe_globalPrefs.news_remove_bodies_days = n;
  271.  
  272.     // Simulate a cancel
  273.  
  274.     prefsDiskMoreCb_cancel(w, closure, callData);
  275.  
  276.     // Install preferences
  277.  
  278.     theDialog->installChanges();
  279.  
  280.     // Save the preferences at the end, so that if we've found some 
  281.     // setting that crashes, it won't get saved...
  282.  
  283.     if (! fe_CheckVersionAndSavePrefs((char *) fe_globalData.user_prefs_file, &fe_globalPrefs))
  284.         fe_perror (theDialog->getContext(), XP_GetString( XFE_ERROR_SAVING_OPTIONS));
  285. }
  286.  
  287. // Member:       prefsDiskMoreCb_cancel
  288. // Description:  
  289. // Inputs:
  290. // Side effects: 
  291.  
  292. void XFE_PrefsDiskMoreDialog::prefsDiskMoreCb_cancel(Widget    /* w */,
  293.                                                      XtPointer closure,
  294.                                                      XtPointer /* callData */)
  295. {
  296.     XFE_PrefsDiskMoreDialog *theDialog = (XFE_PrefsDiskMoreDialog *)closure;
  297.  
  298.     // Delete the dialog
  299.  
  300.     delete theDialog;
  301. }
  302.  
  303.  
  304.