home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / NewsServerPropDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.5 KB  |  332 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.    NewsServerPropDialog.cpp -- property dialogs for news servers.
  20.    Created: Chris Toshok <toshok@netscape.com>, 08-Apr-97
  21.  */
  22.  
  23.  
  24.  
  25. #include "NewsServerPropDialog.h"
  26. #include "PropertySheetView.h"
  27. #include <Xm/LabelG.h>
  28. #include <Xm/SeparatoG.h>
  29. #include <Xm/Form.h>
  30. #include <Xm/ToggleB.h>
  31. #include <Xfe/Xfe.h>
  32.  
  33. #include "xfe.h"
  34.  
  35. #include "xpgetstr.h"
  36. extern int XFE_GENERAL;
  37. extern int XFE_HTML_NEWSGROUP_MSG;
  38. extern int XFE_SEC_ENCRYPTED;
  39. extern int XFE_SEC_NONE;
  40.  
  41. static XFE_NewsServerPropDialog *theDialog = NULL;
  42.  
  43. XFE_NewsServerPropGeneralTab::XFE_NewsServerPropGeneralTab(XFE_Component *top,
  44.                                                            XFE_View *view,
  45.                                                            MSG_NewsHost *host)
  46.     : XFE_PropertyTabView(top, view, XFE_GENERAL)
  47. {
  48.     int widest_width;
  49.     char buf[100];
  50.     XmString str;
  51.  
  52.     Widget top_form, middle_form;
  53.     Widget sep1;
  54.  
  55.     Widget name_label, name_value;
  56.     Widget port_label, port_value;
  57.     Widget security_label, security_value;
  58.     Widget desc_label, desc_value;
  59.  
  60.     m_newshost = host;
  61.  
  62.     top_form = XtCreateManagedWidget("top_form",
  63.                                      xmFormWidgetClass,
  64.                                      getBaseWidget(),
  65.                                      NULL, 0);
  66.     middle_form = XtCreateManagedWidget("middle_form",
  67.                                         xmFormWidgetClass,
  68.                                         getBaseWidget(),
  69.                                         NULL, 0);
  70.  
  71.     sep1 = XtCreateManagedWidget("sep1",
  72.                                  xmSeparatorGadgetClass,
  73.                                  getBaseWidget(),
  74.                                  NULL, 0);
  75.  
  76.     name_label = XtCreateManagedWidget("name_label",
  77.                                        xmLabelGadgetClass,
  78.                                        top_form,
  79.                                        NULL, 0);
  80.  
  81.     str = XmStringCreate((char*)MSG_GetNewsHostName(m_newshost),
  82.                          XmFONTLIST_DEFAULT_TAG);
  83.     name_value = XtVaCreateManagedWidget("name_value",
  84.                                          xmLabelGadgetClass,
  85.                                          top_form,
  86.                                          XmNlabelString, str,
  87.                                          NULL);
  88.     XmStringFree(str);
  89.  
  90.     port_label = XtCreateManagedWidget("port_label",
  91.                                        xmLabelGadgetClass,
  92.                                        top_form,
  93.                                        NULL, 0);
  94.  
  95.     PR_snprintf(buf, sizeof(buf), "%d", MSG_GetNewsHostPort(m_newshost));
  96.     str = XmStringCreate(buf, XmFONTLIST_DEFAULT_TAG);
  97.     port_value = XtVaCreateManagedWidget("port_value",
  98.                                          xmLabelGadgetClass,
  99.                                          top_form,
  100.                                          XmNlabelString, str,
  101.                                          NULL);
  102.     XmStringFree(str);
  103.  
  104.     security_label = XtCreateManagedWidget("security_label",
  105.                                            xmLabelGadgetClass,
  106.                                            top_form,
  107.                                            NULL, 0);
  108.     str = XmStringCreate(MSG_IsNewsHostSecure(m_newshost)
  109.                          ? XP_GetString(XFE_SEC_ENCRYPTED)
  110.                          : XP_GetString(XFE_SEC_NONE),
  111.                          XmFONTLIST_DEFAULT_TAG);
  112.     security_value = XtVaCreateManagedWidget("security_value",
  113.                                              xmLabelGadgetClass,
  114.                                              top_form,
  115.                                              XmNlabelString, str,
  116.                                              NULL);
  117.     XmStringFree(str);
  118.     desc_label = XtCreateManagedWidget("desc_label",
  119.                                        xmLabelGadgetClass,
  120.                                        top_form,
  121.                                        NULL, 0);
  122.  
  123.     str = XmStringCreate("", XmFONTLIST_DEFAULT_TAG); // XXXX 
  124.     desc_value = XtVaCreateManagedWidget("desc_value",
  125.                                          xmLabelGadgetClass,
  126.                                          top_form,
  127.                                          XmNlabelString, str,
  128.                                          NULL);
  129.     XmStringFree(str);
  130.  
  131.     m_prompt_toggle = XtCreateManagedWidget("prompt_toggle",
  132.                                             xmToggleButtonWidgetClass,
  133.                                             middle_form,
  134.                                             NULL, 0);
  135.     m_anonymous_toggle = XtCreateManagedWidget("anonymous_toggle",
  136.                                                xmToggleButtonWidgetClass,
  137.                                                middle_form,
  138.                                                NULL, 0);
  139.     XtVaSetValues(m_prompt_toggle,
  140.                   XmNalignment, XmALIGNMENT_BEGINNING,
  141.                   XmNindicatorType, XmONE_OF_MANY,
  142.                   XmNleftAttachment, XmATTACH_FORM,
  143.                   XmNtopAttachment, XmATTACH_FORM,
  144.                   XmNbottomAttachment, XmATTACH_NONE,
  145.                   XmNrightAttachment, XmATTACH_FORM,
  146.                   NULL);
  147.     XtVaSetValues(m_anonymous_toggle,
  148.                   XmNalignment, XmALIGNMENT_BEGINNING,
  149.                   XmNindicatorType, XmONE_OF_MANY,
  150.                   XmNleftAttachment, XmATTACH_FORM,
  151.                   XmNtopAttachment, XmATTACH_WIDGET,
  152.                   XmNtopWidget, m_prompt_toggle,
  153.                   XmNbottomAttachment, XmATTACH_FORM,
  154.                   XmNrightAttachment, XmATTACH_FORM,
  155.                   NULL);
  156.  
  157.     widest_width = XfeVaGetWidestWidget(name_label, port_label, security_label, desc_label, NULL);
  158.  
  159.     XtVaSetValues(name_label,
  160.                   XmNalignment, XmALIGNMENT_BEGINNING,
  161.                   XmNleftAttachment, XmATTACH_FORM,
  162.                   XmNtopAttachment, XmATTACH_FORM,
  163.                   XmNbottomAttachment, XmATTACH_NONE,
  164.                   XmNrightAttachment, XmATTACH_NONE,
  165.                   NULL);
  166.     XtVaSetValues(port_label,
  167.                   XmNalignment, XmALIGNMENT_BEGINNING,
  168.                   XmNleftAttachment, XmATTACH_FORM,
  169.                   XmNtopAttachment, XmATTACH_WIDGET,
  170.                   XmNtopWidget, name_label,
  171.                   XmNbottomAttachment, XmATTACH_NONE,
  172.                   XmNrightAttachment, XmATTACH_NONE,
  173.                   NULL);
  174.     XtVaSetValues(security_label,
  175.                   XmNalignment, XmALIGNMENT_BEGINNING,
  176.                   XmNleftAttachment, XmATTACH_FORM,
  177.                   XmNtopAttachment, XmATTACH_WIDGET,
  178.                   XmNtopWidget, port_label,
  179.                   XmNbottomAttachment, XmATTACH_NONE,
  180.                   XmNrightAttachment, XmATTACH_NONE,
  181.                   NULL);
  182.     XtVaSetValues(desc_label,
  183.                   XmNalignment, XmALIGNMENT_BEGINNING,
  184.                   XmNleftAttachment, XmATTACH_FORM,
  185.                   XmNtopAttachment, XmATTACH_WIDGET,
  186.                   XmNtopWidget, security_label,
  187.                   XmNbottomAttachment, XmATTACH_NONE,
  188.                   XmNrightAttachment, XmATTACH_NONE,
  189.                   NULL);
  190.  
  191.     XtVaSetValues(name_value,
  192.                   XmNalignment, XmALIGNMENT_BEGINNING,
  193.                   XmNleftAttachment, XmATTACH_WIDGET,
  194.                   XmNleftWidget, name_label,
  195.                   XmNleftOffset, widest_width - XfeWidth(name_label),
  196.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  197.                   XmNtopWidget, name_label,
  198.                   XmNbottomAttachment, XmATTACH_NONE,
  199.                   XmNrightAttachment, XmATTACH_FORM,
  200.                   NULL);
  201.     XtVaSetValues(port_value,
  202.                   XmNalignment, XmALIGNMENT_BEGINNING,
  203.                   XmNleftAttachment, XmATTACH_WIDGET,
  204.                   XmNleftWidget, port_label,
  205.                   XmNleftOffset, widest_width - XfeWidth(port_label),
  206.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  207.                   XmNtopWidget, port_label,
  208.                   XmNbottomAttachment, XmATTACH_NONE,
  209.                   XmNrightAttachment, XmATTACH_FORM,
  210.                   NULL);
  211.     XtVaSetValues(security_value,
  212.                   XmNalignment, XmALIGNMENT_BEGINNING,
  213.                   XmNleftAttachment, XmATTACH_WIDGET,
  214.                   XmNleftWidget, security_label,
  215.                   XmNleftOffset, widest_width - XfeWidth(security_label),
  216.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  217.                   XmNtopWidget, security_label,
  218.                   XmNbottomAttachment, XmATTACH_NONE,
  219.                   XmNrightAttachment, XmATTACH_FORM,
  220.                   NULL);
  221.     XtVaSetValues(desc_value,
  222.                   XmNalignment, XmALIGNMENT_BEGINNING,
  223.                   XmNleftAttachment, XmATTACH_WIDGET,
  224.                   XmNleftWidget, desc_label,
  225.                   XmNleftOffset, widest_width - XfeWidth(desc_label),
  226.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  227.                   XmNtopWidget, desc_label,
  228.                   XmNbottomAttachment, XmATTACH_NONE,
  229.                   XmNrightAttachment, XmATTACH_FORM,
  230.                   NULL);
  231.  
  232.     XtVaSetValues(top_form,
  233.                   XmNalignment, XmALIGNMENT_BEGINNING,
  234.                   XmNleftAttachment, XmATTACH_FORM,
  235.                   XmNrightAttachment, XmATTACH_FORM,
  236.                   XmNtopAttachment, XmATTACH_FORM,
  237.                   XmNbottomAttachment, XmATTACH_NONE,
  238.                   NULL);
  239.  
  240.     XtVaSetValues(sep1,
  241.                   XmNleftAttachment, XmATTACH_FORM,
  242.                   XmNrightAttachment, XmATTACH_FORM,
  243.                   XmNtopAttachment, XmATTACH_WIDGET,
  244.                   XmNtopWidget, top_form,
  245.                   XmNbottomAttachment, XmATTACH_NONE,
  246.                   NULL);
  247.  
  248.     XtVaSetValues(middle_form,
  249.                   XmNleftAttachment, XmATTACH_FORM,
  250.                   XmNrightAttachment, XmATTACH_FORM,
  251.                   XmNtopAttachment, XmATTACH_WIDGET,
  252.                   XmNtopWidget, sep1,
  253.                   XmNbottomAttachment, XmATTACH_FORM,
  254.                   NULL);
  255.  
  256. #define setPromptToggle() \
  257.     if (MSG_GetNewsHostPushAuth(m_newshost)) { \
  258.         XmToggleButtonSetState(m_prompt_toggle, True, False); \
  259.         XmToggleButtonSetState(m_anonymous_toggle, False, False); \
  260.     } else { \
  261.         XmToggleButtonSetState(m_prompt_toggle, False, False); \
  262.         XmToggleButtonSetState(m_anonymous_toggle, True, False); \
  263.     }
  264.  
  265.     setPromptToggle();
  266.  
  267.     XtAddCallback(m_prompt_toggle, XmNvalueChangedCallback,
  268.                   promptForPasswd_cb, this);
  269.     XtAddCallback(m_anonymous_toggle, XmNvalueChangedCallback,
  270.                   promptForPasswd_cb, this);
  271. }
  272.  
  273. XFE_NewsServerPropGeneralTab::~XFE_NewsServerPropGeneralTab()
  274. {
  275. }
  276.  
  277. void
  278. XFE_NewsServerPropGeneralTab::setPushAuth(Widget w)
  279. {
  280.     XP_Bool pushAuth = (w == m_prompt_toggle) ? True : False;
  281.     MSG_SetNewsHostPushAuth (m_newshost, pushAuth);
  282.     setPromptToggle();
  283. }
  284.  
  285. void
  286. XFE_NewsServerPropGeneralTab::promptForPasswd_cb(Widget w,
  287.                                                  XtPointer clientData,
  288.                                                  XtPointer)
  289. {
  290.     XFE_NewsServerPropGeneralTab* obj
  291.         = (XFE_NewsServerPropGeneralTab*)clientData;
  292.     if (obj)
  293.         obj->setPushAuth(w);
  294. }
  295.  
  296. XFE_NewsServerPropDialog::XFE_NewsServerPropDialog(Widget parent,
  297.                                                    char *name,
  298.                                                    MWContext *context,
  299.                                                    MSG_NewsHost *host)
  300.     : XFE_PropertySheetDialog((XFE_View*)0, parent, name,
  301.                           context,
  302.                           TRUE, /* ok */
  303.                           TRUE, /* cancel */
  304.                           TRUE, /* help */
  305.                           FALSE, /* apply */
  306.                           FALSE, /* separator */
  307.                           True) /* modal */
  308. {
  309.     XFE_PropertySheetView* folderView = (XFE_PropertySheetView *) m_view;
  310.  
  311.     folderView->addTab(new XFE_NewsServerPropGeneralTab(this,
  312.                                                         folderView, host));
  313. }
  314.                           
  315. XFE_NewsServerPropDialog::~XFE_NewsServerPropDialog()
  316. {
  317.     theDialog = NULL;
  318. }
  319.  
  320. void 
  321. fe_showNewsServerProperties(Widget parent,
  322.                             MWContext *context,
  323.                             MSG_NewsHost *host)
  324. {
  325.     if (theDialog)
  326.         delete theDialog;
  327.  
  328.     theDialog = new XFE_NewsServerPropDialog(parent, "NewsServerProps", context, host);
  329.  
  330.     theDialog->show();
  331. }
  332.