home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / MailFolderPropDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.2 KB  |  363 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.    MailFolderPropDialog.cpp -- property dialogs for mail folders
  20.    Created: Chris Toshok <toshok@netscape.com>, 08-Apr-97
  21.  */
  22.  
  23.  
  24.  
  25. #include "MailFolderPropDialog.h"
  26. #include "PropertySheetView.h"
  27. #include "MNView.h"
  28. #include <Xm/TextF.h>
  29. #include <Xm/LabelG.h>
  30. #include <Xm/SeparatoG.h>
  31. #include <Xm/Form.h>
  32. #include <Xm/ToggleBG.h>
  33. #include <Xfe/Xfe.h>
  34.  
  35. #include "xfe.h"
  36. #include "felocale.h"
  37.  
  38. #include "xpgetstr.h"
  39. extern int XFE_GENERAL;
  40.  
  41. static XFE_MailFolderPropDialog *theDialog = NULL;
  42.  
  43. XFE_MailFolderPropGeneralTab::XFE_MailFolderPropGeneralTab(XFE_Component *top,
  44.                                                            XFE_View *view,
  45.                                                            MSG_Pane *pane,
  46.                                                            MSG_FolderInfo *folder)
  47.     : XFE_PropertyTabView(top, view, XFE_GENERAL)
  48. {
  49.     int widest_width;
  50.     char buf[100];
  51.  
  52.     Widget top_form, bottom_form;
  53.     Widget sep1;
  54.  
  55.     Widget name_label;
  56.     Widget location_label, location_value;
  57.  
  58.     Widget unread_label, unread_value;
  59.     Widget total_label, total_value;
  60.     Widget wasted_label, wasted_value;
  61.     Widget space_label, space_value;
  62.  
  63.     XmString str;
  64.     MSG_FolderLine line;
  65.  
  66.     m_folder = folder;
  67.     m_pane = pane;
  68.  
  69.     MSG_GetFolderLineById(fe_getMNMaster(), m_folder, &line);
  70.     int32 sizeOnDisk = MSG_GetFolderSizeOnDisk (line.id);
  71.  
  72.     top_form = XtCreateManagedWidget("top_form",
  73.                                      xmFormWidgetClass,
  74.                                      getBaseWidget(),
  75.                                      NULL, 0);
  76.     bottom_form = XtCreateManagedWidget("bottom_form",
  77.                                         xmFormWidgetClass,
  78.                                         getBaseWidget(),
  79.                                         NULL, 0);
  80.  
  81.     sep1 = XtCreateManagedWidget("sep1",
  82.                                  xmSeparatorGadgetClass,
  83.                                  getBaseWidget(),
  84.                                  NULL, 0);
  85.  
  86.     name_label = XtCreateManagedWidget("name_label",
  87.                                        xmLabelGadgetClass,
  88.                                        top_form,
  89.                                        NULL, 0);
  90.  
  91.     m_namevalue = fe_CreateTextField(top_form, "name_value", NULL, 0);
  92.  
  93.     fe_SetTextFieldAndCallBack(m_namevalue, (char*)line.name);
  94.  
  95.     XtSetSensitive(m_namevalue,
  96.                    !(line.flags & (MSG_FOLDER_FLAG_TRASH
  97.                                    | MSG_FOLDER_FLAG_DRAFTS
  98.                                    | MSG_FOLDER_FLAG_QUEUE
  99.                                    | MSG_FOLDER_FLAG_INBOX)));
  100.                     
  101.     XtManageChild(m_namevalue);
  102.  
  103.     location_label = XtCreateManagedWidget("location_label",
  104.                                            xmLabelGadgetClass,
  105.                                            top_form,
  106.                                            NULL, 0);
  107.  
  108.     str = XmStringCreate("", XmFONTLIST_DEFAULT_TAG); // XXXX
  109.     location_value = XtVaCreateManagedWidget("location_value",
  110.                                              xmLabelGadgetClass,
  111.                                              top_form,
  112.                                              XmNlabelString, str,
  113.                                              NULL);
  114.     XmStringFree(str);
  115.  
  116.     unread_label = XtCreateManagedWidget("unread_label",
  117.                                          xmLabelGadgetClass,
  118.                                          bottom_form,
  119.                                          NULL, 0);
  120.     if (line.unseen >=0)
  121.         PR_snprintf(buf, sizeof(buf), "%d", line.unseen);
  122.     else
  123.         strcpy(buf, "???");
  124.     str = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
  125.     unread_value = XtVaCreateManagedWidget("unread_value",
  126.                                            xmLabelGadgetClass,
  127.                                            bottom_form,
  128.                                            XmNlabelString, str,
  129.                                            NULL);
  130.     XmStringFree(str);
  131.     total_label = XtCreateManagedWidget("total_label",
  132.                                         xmLabelGadgetClass,
  133.                                         bottom_form,
  134.                                         NULL, 0);
  135.     PR_snprintf(buf, sizeof(buf), "%d", line.total);
  136.     str = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
  137.     total_value = XtVaCreateManagedWidget("total_value",
  138.                                           xmLabelGadgetClass,
  139.                                           bottom_form,
  140.                                           XmNlabelString, str,
  141.                                           NULL);
  142.     XmStringFree(str);
  143.     wasted_label = XtCreateManagedWidget("wasted_label",
  144.                                          xmLabelGadgetClass,
  145.                                          bottom_form,
  146.                                          NULL, 0);
  147.     PR_snprintf(buf, sizeof(buf), "%d %%", sizeOnDisk == 0 ? 0 : line.deletedBytes / sizeOnDisk);
  148.     str = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
  149.     wasted_value = XtVaCreateManagedWidget("wasted_value",
  150.                                            xmLabelGadgetClass,
  151.                                            bottom_form,
  152.                                            XmNlabelString, str,
  153.                                            NULL);
  154.     XmStringFree(str);
  155.     space_label = XtCreateManagedWidget("space_label",
  156.                                         xmLabelGadgetClass,
  157.                                         bottom_form,
  158.                                         NULL, 0);
  159.     PR_snprintf(buf, sizeof(buf), "%d k", sizeOnDisk / 1024);
  160.     str = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
  161.     space_value = XtVaCreateManagedWidget("space_value",
  162.                                           xmLabelGadgetClass,
  163.                                           bottom_form,
  164.                                           XmNlabelString, str,
  165.                                           NULL);
  166.     XmStringFree(str);
  167.  
  168.     widest_width = XfeVaGetWidestWidget(unread_label, total_label, wasted_label, space_label, NULL);
  169.  
  170.     XtVaSetValues(unread_label,
  171.                   XmNalignment, XmALIGNMENT_BEGINNING,
  172.                   XmNleftAttachment, XmATTACH_FORM,
  173.                   XmNrightAttachment, XmATTACH_NONE,
  174.                   XmNtopAttachment, XmATTACH_FORM,
  175.                   XmNbottomAttachment, XmATTACH_NONE,
  176.                   NULL);
  177.     XtVaSetValues(unread_value,
  178.                   XmNalignment, XmALIGNMENT_BEGINNING,
  179.                   XmNleftAttachment, XmATTACH_WIDGET,
  180.                   XmNleftWidget, unread_label,
  181.                   XmNleftOffset, widest_width - XfeWidth(unread_label),
  182.                   XmNrightAttachment, XmATTACH_FORM,
  183.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  184.                   XmNtopWidget, unread_label,
  185.                   XmNbottomAttachment, XmATTACH_NONE,
  186.                   NULL);
  187.     XtVaSetValues(total_label,
  188.                   XmNalignment, XmALIGNMENT_BEGINNING,
  189.                   XmNleftAttachment, XmATTACH_FORM,
  190.                   XmNrightAttachment, XmATTACH_NONE,
  191.                   XmNtopAttachment, XmATTACH_WIDGET,
  192.                   XmNtopWidget, unread_label,
  193.                   XmNbottomAttachment, XmATTACH_NONE,
  194.                   NULL);
  195.     XtVaSetValues(total_value,
  196.                   XmNalignment, XmALIGNMENT_BEGINNING,
  197.                   XmNleftAttachment, XmATTACH_WIDGET,
  198.                   XmNleftWidget, total_label,
  199.                   XmNleftOffset, widest_width - XfeWidth(total_label),
  200.                   XmNrightAttachment, XmATTACH_FORM,
  201.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  202.                   XmNtopWidget, total_label,
  203.                   XmNbottomAttachment, XmATTACH_NONE,
  204.                   NULL);
  205.     XtVaSetValues(wasted_label,
  206.                   XmNalignment, XmALIGNMENT_BEGINNING,
  207.                   XmNleftAttachment, XmATTACH_FORM,
  208.                   XmNrightAttachment, XmATTACH_NONE,
  209.                   XmNtopAttachment, XmATTACH_WIDGET,
  210.                   XmNtopWidget, total_label,
  211.                   XmNbottomAttachment, XmATTACH_NONE,
  212.                   NULL);
  213.     XtVaSetValues(wasted_value,
  214.                   XmNalignment, XmALIGNMENT_BEGINNING,
  215.                   XmNleftAttachment, XmATTACH_WIDGET,
  216.                   XmNleftWidget, wasted_label,
  217.                   XmNleftOffset, widest_width - XfeWidth(wasted_label),
  218.                   XmNrightAttachment, XmATTACH_FORM,
  219.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  220.                   XmNtopWidget, wasted_label,
  221.                   XmNbottomAttachment, XmATTACH_NONE,
  222.                   NULL);
  223.     XtVaSetValues(space_label,
  224.                   XmNalignment, XmALIGNMENT_BEGINNING,
  225.                   XmNleftAttachment, XmATTACH_FORM,
  226.                   XmNrightAttachment, XmATTACH_NONE,
  227.                   XmNtopAttachment, XmATTACH_WIDGET,
  228.                   XmNtopWidget, wasted_label,
  229.                   XmNbottomAttachment, XmATTACH_NONE,
  230.                   NULL);
  231.     XtVaSetValues(space_value,
  232.                   XmNalignment, XmALIGNMENT_BEGINNING,
  233.                   XmNleftAttachment, XmATTACH_WIDGET,
  234.                   XmNleftWidget, space_label,
  235.                   XmNleftOffset, widest_width - XfeWidth(space_label),
  236.                   XmNrightAttachment, XmATTACH_FORM,
  237.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  238.                   XmNtopWidget, space_label,
  239.                   XmNbottomAttachment, XmATTACH_NONE,
  240.                   NULL);
  241.  
  242.     widest_width = XfeVaGetWidestWidget(name_label, location_label, NULL);
  243.  
  244.     XtVaSetValues(name_label,
  245.                   XmNalignment, XmALIGNMENT_BEGINNING,
  246.                   XmNleftAttachment, XmATTACH_FORM,
  247.                   XmNtopAttachment, XmATTACH_FORM,
  248.                   XmNbottomAttachment, XmATTACH_NONE,
  249.                   XmNrightAttachment, XmATTACH_NONE,
  250.                   NULL);
  251.     XtVaSetValues(location_label,
  252.                   XmNalignment, XmALIGNMENT_BEGINNING,
  253.                   XmNleftAttachment, XmATTACH_FORM,
  254.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  255.                   XmNtopWidget, location_value,
  256.                   XmNbottomAttachment, XmATTACH_NONE,
  257.                   XmNrightAttachment, XmATTACH_NONE,
  258.                   NULL);
  259.  
  260.     XtVaSetValues(m_namevalue,
  261.                   XmNalignment, XmALIGNMENT_BEGINNING,
  262.                   XmNleftAttachment, XmATTACH_WIDGET,
  263.                   XmNleftWidget, name_label,
  264.                   XmNleftOffset, widest_width - XfeWidth(name_label),
  265.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  266.                   XmNtopWidget, name_label,
  267.                   XmNbottomAttachment, XmATTACH_NONE,
  268.                   XmNrightAttachment, XmATTACH_FORM,
  269.                   NULL);
  270.     XtVaSetValues(location_value,
  271.                   XmNalignment, XmALIGNMENT_BEGINNING,
  272.                   XmNleftAttachment, XmATTACH_OPPOSITE_WIDGET,
  273.                   XmNleftWidget, m_namevalue,
  274.                   XmNleftOffset, widest_width - XfeWidth(location_label),
  275.                   XmNtopAttachment, XmATTACH_WIDGET,
  276.                   XmNtopWidget, m_namevalue,
  277.                   XmNbottomAttachment, XmATTACH_NONE,
  278.                   XmNrightAttachment, XmATTACH_FORM,
  279.                   NULL);
  280.  
  281.     XtVaSetValues(top_form,
  282.                   XmNleftAttachment, XmATTACH_FORM,
  283.                   XmNrightAttachment, XmATTACH_FORM,
  284.                   XmNtopAttachment, XmATTACH_FORM,
  285.                   XmNbottomAttachment, XmATTACH_NONE,
  286.                   NULL);
  287.  
  288.     XtVaSetValues(sep1,
  289.                   XmNleftAttachment, XmATTACH_FORM,
  290.                   XmNrightAttachment, XmATTACH_FORM,
  291.                   XmNtopAttachment, XmATTACH_WIDGET,
  292.                   XmNtopWidget, top_form,
  293.                   XmNbottomAttachment, XmATTACH_NONE,
  294.                   NULL);
  295.  
  296.     XtVaSetValues(bottom_form,
  297.                   XmNleftAttachment, XmATTACH_FORM,
  298.                   XmNrightAttachment, XmATTACH_FORM,
  299.                   XmNtopAttachment, XmATTACH_WIDGET,
  300.                   XmNtopWidget, sep1,
  301.                   XmNbottomAttachment, XmATTACH_FORM,
  302.                   NULL);
  303. }
  304.  
  305. XFE_MailFolderPropGeneralTab::~XFE_MailFolderPropGeneralTab()
  306. {
  307. }
  308.  
  309. void
  310. XFE_MailFolderPropGeneralTab::apply()
  311. {
  312.     /* bstell: do we need to fix this ? */
  313.     char *folder_name = fe_GetTextField(m_namevalue);
  314.     MSG_FolderLine line;
  315.  
  316.     MSG_GetFolderLineById(fe_getMNMaster(),
  317.                           m_folder, &line);
  318.  
  319.     if (strcmp(line.name, folder_name))
  320.         MSG_RenameMailFolder(m_pane, m_folder, folder_name);
  321.  
  322.     XtFree(folder_name);
  323. }
  324.  
  325. XFE_MailFolderPropDialog::XFE_MailFolderPropDialog(Widget parent,
  326.                                                    char *name,
  327.                                                    MWContext *context,
  328.                                                    MSG_Pane *pane,
  329.                                                    MSG_FolderInfo *folder)
  330.     : XFE_PropertySheetDialog((XFE_View*)0, parent, name,
  331.                           context,
  332.                           TRUE, /* ok */
  333.                           TRUE, /* cancel */
  334.                           TRUE, /* help */
  335.                           FALSE, /* apply */
  336.                           FALSE, /* separator */
  337.                           True) /* modal */
  338. {
  339.     XFE_PropertySheetView* folderView = (XFE_PropertySheetView *) m_view;
  340.     
  341.     folderView->addTab(new XFE_MailFolderPropGeneralTab(this,
  342.                                                         folderView, pane, folder));
  343. }
  344.                           
  345. XFE_MailFolderPropDialog::~XFE_MailFolderPropDialog()
  346. {
  347.     theDialog = NULL;
  348. }
  349.  
  350. void 
  351. fe_showMailFolderProperties(Widget parent,
  352.                             MWContext *context,
  353.                             MSG_Pane *pane,
  354.                             MSG_FolderInfo *folder)
  355. {
  356.     if (theDialog)
  357.         delete theDialog;
  358.     
  359.     theDialog = new XFE_MailFolderPropDialog(parent, "MailFolderProps", context, pane, folder);
  360.     
  361.     theDialog->show();
  362. }
  363.