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