home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / FolderPromptDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.5 KB  |  199 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.    FolderPromptDialog.cpp -- "New Folder" dialog
  20.    Created: Akkana Peck <akkana@netscape.com>, 11-Dec-97.
  21.  */
  22.  
  23.  
  24.  
  25. #include "FolderPromptDialog.h"
  26.  
  27. #include "felocale.h"
  28.  
  29. #include <Xm/Form.h>
  30. #include <Xm/LabelG.h>
  31. #include <Xm/TextF.h>
  32.  
  33. #include "FolderDropdown.h"
  34.  
  35. // we need this in the post() method.
  36. extern "C" void fe_EventLoop();
  37.  
  38. XFE_FolderPromptDialog::XFE_FolderPromptDialog(Widget parent, char *name,
  39.                                                XFE_Frame *frame,
  40.                                                XFE_Component* toplevel)
  41.     : XFE_Dialog(parent, 
  42.                  name, 
  43.                  TRUE, // ok
  44.                  TRUE, // cancel
  45.                  FALSE, // help
  46.                  FALSE, // apply
  47.                  TRUE, // separator
  48.                  TRUE // modal
  49.         )
  50. {
  51.     m_frame = frame;
  52.     m_toplevel = toplevel;
  53.  
  54.     Widget form = XtCreateManagedWidget("form",
  55.                                         xmFormWidgetClass,
  56.                                         m_chrome,
  57.                                         NULL, 0);
  58.  
  59.     m_text = XtVaCreateManagedWidget("folderText",
  60.                                      xmTextFieldWidgetClass,
  61.                                      form,
  62.                                      XmNtopAttachment, XmATTACH_FORM,
  63.                                      XmNrightAttachment, XmATTACH_FORM,
  64.                                      0);
  65.     XtVaCreateManagedWidget("name", xmLabelGadgetClass, form,
  66.                             XmNleftAttachment, XmATTACH_FORM,
  67.                             XmNrightAttachment, XmATTACH_WIDGET,
  68.                             XmNrightWidget, m_text,
  69.                             XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
  70.                             XmNbottomWidget, m_text,
  71.                             0);
  72.     Widget w = XtVaCreateManagedWidget("subFolderOf", xmLabelGadgetClass, form,
  73.                                        XmNtopAttachment, XmATTACH_WIDGET,
  74.                                        XmNtopWidget, m_text,
  75.                                        XmNleftAttachment, XmATTACH_FORM,
  76.                                        0);
  77.  
  78.     m_folderDropDown = new XFE_FolderDropdown(getToplevel(),
  79.                                               form,
  80.                                               TRUE, /* allowServerSelection */
  81.                                               FALSE /* showNewsgroups */);
  82.     XtVaSetValues(m_folderDropDown->getBaseWidget(),
  83.                   XmNleftAttachment, XmATTACH_FORM,
  84.                   XmNtopAttachment, XmATTACH_WIDGET,
  85.                   XmNtopWidget, w,
  86.                   XmNrightAttachment, XmATTACH_FORM,
  87.                   0);
  88.     m_folderDropDown->setPopupServer(False);
  89.     m_folderDropDown->show();
  90.  
  91.     XtAddCallback(m_chrome, XmNokCallback, ok_cb, this);
  92.     XtAddCallback(m_chrome, XmNcancelCallback, cancel_cb, this);
  93. }
  94.  
  95. XFE_FolderPromptDialog::~XFE_FolderPromptDialog()
  96. {
  97.     //delete m_folderDropDown;
  98. }
  99.  
  100. MSG_FolderInfo*
  101. XFE_FolderPromptDialog::prompt(MSG_FolderInfo* finfo)
  102. {
  103.     m_folderDropDown->selectFolder(finfo);
  104.  
  105.     m_doneWithLoop = False;
  106.   
  107.     XtVaSetValues(m_chrome,
  108.                   XmNdeleteResponse, XmUNMAP,
  109.                   NULL);
  110.  
  111.     show();
  112.  
  113.     while(!m_doneWithLoop)
  114.         fe_EventLoop();
  115.  
  116.     return m_retVal;
  117. }
  118.  
  119. void
  120. XFE_FolderPromptDialog::ok()
  121. {
  122.     m_doneWithLoop = True;
  123.     char* name = fe_GetTextField(m_text);
  124.     m_retVal = 0;
  125.  
  126.     //
  127.     // Supposedly, MSG_CreateMailFolder() is obsoleted by
  128.     // MSG_CreateMailFolderWithPane(); but we don't necessarily have
  129.     //  a pane here, e.g. we might have been called from the prefs win.
  130.     //
  131.     MSG_Master* master = FE_GetMaster();
  132.     if (MSG_CreateMailFolder(master,
  133.                              m_folderDropDown->getSelectedFolder(),
  134.                              name) == 0)
  135.     {
  136. #if 0
  137.         // NOTE!  This is fraught with problems!  MSG_CreateMailFolder()
  138.         // doesn't return a pointer to the folder it just created; so we
  139.         // search by name, but there's no guarantee that the folder found
  140.         // by the folder dropdown is the same folder that we just created,
  141.         // only that it has the same name. :-(
  142.         m_folderDropDown->selectFolder(name);
  143.         m_retVal = m_folderDropDown->getSelectedFolder();
  144. #endif
  145.         int32 numchildren = 
  146.             MSG_GetFolderChildren(master,
  147.                                   m_folderDropDown->getSelectedFolder(),
  148.                                   NULL, 0);
  149.         if (numchildren > 0)
  150.         {
  151.             MSG_FolderInfo** result = new MSG_FolderInfo* [ numchildren ];
  152.             MSG_GetFolderChildren(master,
  153.                                   m_folderDropDown->getSelectedFolder(),
  154.                                   result,
  155.                                   sizeof result / sizeof *result);
  156.             for (int i=0; i<numchildren; ++i)
  157.             {
  158.                 char* childname = fe_Basename(MSG_GetFolderNameFromID(result[i]));
  159.                 printf("'%s' vs '%s'\n", name, childname);
  160.                 if (!XP_STRCMP(name, childname))
  161.                 {
  162.                     m_retVal = result[i];
  163.                     printf("matched!\n");
  164.                     break;
  165.                 }
  166.             }
  167.             delete[] result;
  168.         }
  169.     }
  170.  
  171.     hide();
  172. }
  173.  
  174. void
  175. XFE_FolderPromptDialog::cancel()
  176. {
  177.     m_doneWithLoop = True;
  178.     m_retVal = 0;
  179.  
  180.     hide();
  181. }
  182.  
  183. void 
  184. XFE_FolderPromptDialog::ok_cb(Widget, XtPointer clientData, XtPointer)
  185. {
  186.     XFE_FolderPromptDialog *obj = (XFE_FolderPromptDialog*)clientData;
  187.  
  188.     obj->ok();
  189. }
  190.  
  191. void
  192. XFE_FolderPromptDialog::cancel_cb(Widget, XtPointer clientData, XtPointer)
  193. {
  194.     XFE_FolderPromptDialog *obj = (XFE_FolderPromptDialog*)clientData;
  195.  
  196.     obj->cancel();
  197. }
  198.  
  199.