home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / MsgFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  26.2 KB  |  896 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.    MsgFrame.cpp -- Msg window stuff
  20.    Created: Chris Toshok <toshok@netscape.com>, 29-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "MsgFrame.h"
  26. #include "MsgView.h"
  27. #include "ThreadView.h"
  28. #include "AttachmentMenu.h"
  29. #include "FolderMenu.h"
  30. #include "Command.h"
  31. #include "xpassert.h"
  32. #include "MozillaApp.h"
  33. #include "Dashboard.h"
  34. #include "MailDownloadFrame.h"
  35. #include "Xfe/Xfe.h"
  36.  
  37. #include "libi18n.h"
  38. #include "libmime.h"
  39. #include "intl_csi.h"
  40. #include "felocale.h"
  41.  
  42.  
  43. #include "xpgetstr.h"
  44. extern int XFE_MESSAGE;
  45. extern int XFE_MESSAGE_SUBTITLE;
  46. extern int XFE_MN_UNREAD_AND_TOTAL;
  47.  
  48. extern "C" void fe_set_scrolled_default_size(MWContext *context);
  49.  
  50. MenuSpec XFE_MsgFrame::file_menu_spec[] = {
  51.   { "newSubmenu", CASCADEBUTTON, (MenuSpec *) &XFE_Frame::new_submenu_spec },
  52.   MENU_SEPARATOR,
  53.   { xfeCmdSaveMessagesAs,    PUSHBUTTON },
  54.   { xfeCmdEditMessage,        PUSHBUTTON },
  55.   MENU_SEPARATOR,
  56.   { xfeCmdRenameFolder,        PUSHBUTTON },
  57.   { xfeCmdEmptyTrash,        PUSHBUTTON },
  58.   { xfeCmdCompressAllFolders,    PUSHBUTTON },
  59.   { xfeCmdCleanUpDisk,      PUSHBUTTON },
  60.   MENU_SEPARATOR,
  61.   { "newMsgSubmenu", CASCADEBUTTON, (MenuSpec *) &XFE_Frame::newMsg_submenu_spec },
  62.   { xfeCmdSendMessagesInOutbox,    PUSHBUTTON },
  63.   { xfeCmdAddNewsgroup,            PUSHBUTTON },
  64.   MENU_SEPARATOR,
  65.   { xfeCmdPrint,        PUSHBUTTON },
  66.   MENU_SEPARATOR,
  67.   { xfeCmdClose,        PUSHBUTTON },
  68.   { xfeCmdExit,            PUSHBUTTON },
  69.   { NULL }
  70. };
  71.  
  72. MenuSpec XFE_MsgFrame::offline_submenu_spec[] = {
  73.   { xfeCmdGetSelectedMessagesForOffline, PUSHBUTTON },
  74.   { xfeCmdGetFlaggedMessagesForOffline,     PUSHBUTTON },
  75.   { xfeCmdChooseMessagesForOffline,     PUSHBUTTON },
  76.   { NULL }
  77. };
  78.  
  79. MenuSpec XFE_MsgFrame::edit_menu_spec[] = {
  80.   { xfeCmdUndo,            PUSHBUTTON },
  81.   { xfeCmdRedo,            PUSHBUTTON },
  82.   MENU_SEPARATOR,
  83.   { xfeCmdCut,            PUSHBUTTON },
  84.   { xfeCmdCopy,            PUSHBUTTON },
  85.   { xfeCmdPaste,        PUSHBUTTON },
  86.   { xfeCmdDeleteMessage,    PUSHBUTTON },
  87.  
  88.   { "selectSubmenu",    CASCADEBUTTON, (MenuSpec *) &XFE_Frame::select_submenu_spec },
  89.   MENU_SEPARATOR,
  90.   { xfeCmdFindInObject,        PUSHBUTTON },
  91.   { xfeCmdFindAgain,        PUSHBUTTON },
  92.   { xfeCmdSearch,        PUSHBUTTON },
  93.   { xfeCmdSearchAddress,    PUSHBUTTON },
  94.   MENU_SEPARATOR,
  95.   { xfeCmdEditConfiguration,    PUSHBUTTON },
  96.   { xfeCmdModerateDiscussion,    PUSHBUTTON },
  97.   MENU_SEPARATOR,
  98.   { xfeCmdEditMailFilterRules,PUSHBUTTON },
  99.   { xfeCmdEditPreferences,    PUSHBUTTON },
  100.   { NULL }
  101. };
  102.  
  103. MenuSpec XFE_MsgFrame::view_menu_spec[] = {
  104.   { xfeCmdToggleNavigationToolbar,PUSHBUTTON },
  105.   { xfeCmdToggleLocationToolbar,  PUSHBUTTON },
  106.   MENU_SEPARATOR,
  107.   { "headersSubmenu",     CASCADEBUTTON, (MenuSpec *) &XFE_Frame::headers_submenu_spec },
  108.   // This should just be a toggle.  -slamm
  109.   { "attachmentsSubmenu", CASCADEBUTTON, (MenuSpec *) &XFE_Frame::attachments_submenu_spec },
  110.   MENU_SEPARATOR,
  111.   { xfeCmdIncreaseFont,        PUSHBUTTON },
  112.   { xfeCmdDecreaseFont,        PUSHBUTTON },
  113.   MENU_SEPARATOR,
  114.   { xfeCmdReload,            PUSHBUTTON },
  115.   { xfeCmdShowImages,        PUSHBUTTON },
  116.   { xfeCmdRefresh,          PUSHBUTTON },
  117.   { xfeCmdStopLoading,        PUSHBUTTON },
  118.   //{ xfeCmdStopAnimations,    PUSHBUTTON },
  119.   MENU_SEPARATOR,
  120.   { xfeCmdRot13Message,        PUSHBUTTON },
  121.   { xfeCmdWrapLongLines,    TOGGLEBUTTON },
  122.   MENU_SEPARATOR,
  123.   { xfeCmdViewPageSource,    PUSHBUTTON },
  124.   { xfeCmdViewPageInfo,        PUSHBUTTON },
  125.   MENU_SEPARATOR,
  126.   { "encodingSubmenu",      CASCADEBUTTON,(MenuSpec*)&XFE_Frame::encoding_menu_spec },
  127.   { NULL }
  128. };
  129.  
  130. MenuSpec XFE_MsgFrame::message_menu_spec[] = {
  131.   { xfeCmdComposeMessage,        PUSHBUTTON },
  132.   { "replySubmenu",    CASCADEBUTTON, (MenuSpec *) &XFE_Frame::reply_submenu_spec },
  133.   { xfeCmdForwardMessage,        PUSHBUTTON },
  134.   { xfeCmdForwardMessageQuoted,        PUSHBUTTON },
  135.   MENU_SEPARATOR,
  136.   { "addToABSubmenu", CASCADEBUTTON, (MenuSpec *) &XFE_Frame::addrbk_submenu_spec },
  137.   { "fileSubmenu",  DYNA_CASCADEBUTTON, NULL, NULL, 
  138.     False, (void*)xfeCmdMoveMessage, XFE_FolderMenu::generate },
  139.   { "copySubmenu",  DYNA_CASCADEBUTTON, NULL, NULL, 
  140.     False, (void*)xfeCmdCopyMessage, XFE_FolderMenu::generate },
  141.   MENU_SEPARATOR,
  142.   { "markSubmenu",      CASCADEBUTTON, (MenuSpec *) &XFE_Frame::mark_submenu_spec },
  143.   { xfeCmdMarkMessage,            PUSHBUTTON },
  144.   { xfeCmdUnflagMessage,        PUSHBUTTON },
  145.   MENU_SEPARATOR,
  146.   { xfeCmdIgnoreThread,         PUSHBUTTON },
  147.   { xfeCmdWatchThread,          PUSHBUTTON },
  148.   { NULL }
  149. };
  150.  
  151. MenuSpec XFE_MsgFrame::go_menu_spec[] = {
  152.   { xfeCmdNextMessage,            PUSHBUTTON },
  153.   { xfeCmdNextUnreadMessage,        PUSHBUTTON },
  154.   { xfeCmdNextFlaggedMessage,        PUSHBUTTON },
  155.   { xfeCmdNextUnreadThread,        PUSHBUTTON },
  156.   { xfeCmdNextCollection,        PUSHBUTTON },
  157.   { xfeCmdNextUnreadCollection,     PUSHBUTTON },
  158.   MENU_SEPARATOR,
  159.   { xfeCmdPreviousMessage,        PUSHBUTTON },
  160.   { xfeCmdPreviousUnreadMessage,    PUSHBUTTON },
  161.   { xfeCmdPreviousFlaggedMessage,    PUSHBUTTON },
  162.   MENU_SEPARATOR,
  163.   { xfeCmdFirstFlaggedMessage,        PUSHBUTTON },
  164.   MENU_SEPARATOR,
  165.   { xfeCmdBack,         PUSHBUTTON },
  166.   { xfeCmdForward,        PUSHBUTTON },
  167.   { NULL }
  168. };
  169.  
  170. MenuSpec XFE_MsgFrame::menu_bar_spec[] = {
  171.   { xfeMenuFile,     CASCADEBUTTON, file_menu_spec },
  172.   { xfeMenuEdit,     CASCADEBUTTON, edit_menu_spec },
  173.   { xfeMenuView,     CASCADEBUTTON, view_menu_spec },
  174.   { xfeMenuGo,         CASCADEBUTTON, go_menu_spec },
  175.   { xfeMenuMessage,     CASCADEBUTTON, message_menu_spec },
  176.   { xfeMenuWindow,    CASCADEBUTTON, XFE_Frame::window_menu_spec },
  177.   { xfeMenuHelp,     CASCADEBUTTON, XFE_Frame::help_menu_spec },
  178.   { NULL }
  179. };
  180.  
  181. ToolbarSpec XFE_MsgFrame::toolbar_spec[] = {
  182.     { xfeCmdGetNewMessages,    PUSHBUTTON, &MNTB_GetMsg_group },
  183.         {  // XX mail only
  184.                 xfeCmdComposeMessage,
  185.                 CASCADEBUTTON,
  186.                 &MNTB_Compose_group, NULL, NULL, NULL,                          // Icons
  187.                 compose_message_submenu_spec,                     // Submenu spec
  188.                 NULL, NULL,                             // Generate proc/arg
  189.                 XFE_TOOLBAR_DELAY_LONG                         // Popup delay
  190.         },
  191.         {  // XX newsgroup only
  192.                 xfeCmdComposeArticle,
  193.                 CASCADEBUTTON,
  194.                 &MNTB_Compose_group, NULL, NULL, NULL,                          // Icons
  195.                 compose_article_submenu_spec,                     // Submenu spec
  196.                 NULL, NULL,                             // Generate proc/arg
  197.                 XFE_TOOLBAR_DELAY_LONG                         // Popup delay
  198.         },
  199.  
  200.     TOOLBAR_SEPARATOR,
  201.     {  // XX mail only
  202.         xfeCmdReplyToSender,    
  203.         CASCADEBUTTON, 
  204.         &MNTB_Reply_group, NULL, NULL, NULL,                // Icons
  205.         reply_submenu_spec,                                    // Submenu spec
  206.         NULL, NULL,                                            // Generate proc/arg
  207.         XFE_TOOLBAR_DELAY_LONG                                // Popup delay
  208.     },
  209.     {  // XX news only
  210.         xfeCmdReplyToNewsgroup,    
  211.         CASCADEBUTTON, 
  212.         &MNTB_Reply_group, NULL, NULL, NULL,                // Icons
  213.         reply_submenu_spec,                                    // Submenu spec
  214.         NULL, NULL,                                            // Generate proc/arg
  215.         XFE_TOOLBAR_DELAY_LONG                                // Popup delay
  216.     },
  217.     { xfeCmdForwardMessage,    PUSHBUTTON, &MNTB_Forward_group },
  218.     TOOLBAR_SEPARATOR,
  219.     { xfeCmdCopyMessage, // XX news only
  220.       DYNA_CASCADEBUTTON, 
  221.       &MNTB_File_group, NULL, NULL, NULL, NULL,
  222.       XFE_FolderMenu::generate, (void*)xfeCmdCopyMessage,
  223.       XFE_TOOLBAR_DELAY_SHORT
  224.     },
  225.     { xfeCmdMoveMessage, // XX mail only
  226.       DYNA_CASCADEBUTTON, 
  227.       &MNTB_File_group, NULL, NULL, NULL, NULL,
  228.       XFE_FolderMenu::generate, (void*)xfeCmdMoveMessage,
  229.       XFE_TOOLBAR_DELAY_SHORT
  230.     },
  231.     {
  232.         xfeCmdNextUnreadMessage,
  233.         CASCADEBUTTON, 
  234.         &MNTB_Next_group, NULL, NULL, NULL,                    // Icons
  235.         next_submenu_spec,                                    // Submenu spec
  236.         NULL, NULL,                                            // Generate proc/arg
  237.         XFE_TOOLBAR_DELAY_LONG                                // Popup delay
  238.     },
  239.     { xfeCmdPrint,            PUSHBUTTON, &TB_Print_group },
  240.     { xfeCmdViewSecurity,        PUSHBUTTON, 
  241.             &TB_Unsecure_group,
  242.                         &TB_Secure_group,
  243.                         &MNTB_SignUnsecure_group,
  244.                         &MNTB_SignSecure_group},
  245.     { xfeCmdMarkMessageRead, // XX news only
  246.       CASCADEBUTTON, 
  247.       &MNTB_MarkRead_group, NULL, NULL, NULL,                // Icons
  248.       mark_submenu_spec,                                    // Submenu spec
  249.       NULL, NULL,                                            // Generate proc/arg
  250.       XFE_TOOLBAR_DELAY_LONG                                // Popup delay
  251.     },
  252.     { xfeCmdDeleteMessage,    PUSHBUTTON, &MNTB_Trash_group }, // XX mail only
  253.     { xfeCmdStopLoading,        PUSHBUTTON, &TB_Stop_group },
  254.     { NULL }
  255. };
  256.  
  257. XFE_MsgFrame::XFE_MsgFrame(Widget toplevel, XFE_Frame *parent_frame, Chrome *chromespec)
  258.   : XFE_Frame("MailMsg", toplevel, parent_frame, FRAME_MAILNEWS_MSG, chromespec, True)
  259. {
  260.   INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(m_context);
  261.   INTL_SetCSIWinCSID(c, 
  262.         INTL_DocToWinCharSetID (CONTEXT_DATA (m_context)->xfe_doc_csid));
  263.  
  264.   geometryPrefName = "mail.msg";
  265.  
  266.   // create the msg view
  267.   XFE_MsgView *mview;
  268.  
  269.   mview = new XFE_MsgView(this, getViewParent(), NULL, m_context);
  270.   mview->registerInterest(XFE_MsgView::spacebarAtMsgBottom,
  271.               this,
  272.               (XFE_FunctionNotification)spaceAtMsgEnd_cb);
  273.  
  274.   mview->registerInterest(XFE_MsgView::messageHasChanged,
  275.               this,
  276.               (XFE_FunctionNotification)msgLoaded_cb);
  277.  
  278.   mview->registerInterest(XFE_MsgView::lastMsgDeleted,
  279.               this,
  280.               (XFE_FunctionNotification)msgDeleted_cb);
  281.  
  282.   m_banner = new XFE_MNBanner(this, m_toolbox);
  283.  
  284.   setView(mview);
  285.  
  286.   XtVaSetValues(mview->getBaseWidget(),
  287.           XmNleftAttachment, XmATTACH_FORM,
  288.         XmNtopAttachment, XmATTACH_FORM,
  289.         XmNrightAttachment, XmATTACH_FORM,
  290.         XmNbottomAttachment, XmATTACH_FORM,
  291.         NULL);
  292.  
  293.   setMenubar(menu_bar_spec);
  294.   setToolbar(toolbar_spec);
  295.  
  296.   fe_set_scrolled_default_size(m_context);
  297.  
  298. //  m_banner->show();
  299.   mview->show();
  300.  
  301.   m_banner->setTitle( XP_GetString ( XFE_MESSAGE ));
  302.   m_banner->setSubtitle( "" );
  303.   m_banner->setMommyIcon(&MN_Mommy_group);
  304.  
  305.   // safe defaults.  They will be overridden when we update the banner.
  306.  
  307.   // Configure the dashboard
  308.   XP_ASSERT( m_dashboard != NULL );
  309.  
  310.   m_dashboard->setShowSecurityIcon(True);
  311.   m_dashboard->setShowSignedIcon(True);
  312.   m_dashboard->setShowStatusBar(True);
  313.   m_dashboard->setShowProgressBar(True);
  314.  
  315.   // Configure the toolbox for the first time
  316.   configureToolbox();
  317.  
  318.   XFE_MozillaApp::theApp()->registerInterest(XFE_MNView::MNChromeNeedsUpdating,
  319.                                              this,
  320.                                              (XFE_FunctionNotification)MNChromeUpdate_cb);
  321.   
  322.   XFE_MozillaApp::theApp()->registerInterest(XFE_MNView::folderChromeNeedsUpdating,
  323.                                              this,
  324.                                              (XFE_FunctionNotification)FolderChromeUpdate_cb);
  325.  
  326.   XFE_MozillaApp::theApp()->registerInterest(XFE_MNView::msgWasDeleted,
  327.                                              this,
  328.                                              (XFE_FunctionNotification)msgDeleted_cb);
  329.  
  330.   XFE_MozillaApp::theApp()->registerInterest(XFE_MNView::folderDeleted,
  331.                                              this,
  332.                                              (XFE_FunctionNotification)folderDeleted_cb);
  333. }
  334.  
  335. XFE_MsgFrame::~XFE_MsgFrame()
  336. {
  337.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MNView::MNChromeNeedsUpdating,
  338.                                                this,
  339.                                                (XFE_FunctionNotification)MNChromeUpdate_cb);
  340.   
  341.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MNView::folderChromeNeedsUpdating,
  342.                                                this,
  343.                                                (XFE_FunctionNotification)FolderChromeUpdate_cb);
  344.  
  345.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MNView::msgWasDeleted,
  346.                                                this,
  347.                                                (XFE_FunctionNotification)msgDeleted_cb);
  348.  
  349.   XFE_MozillaApp::theApp()->unregisterInterest(XFE_MNView::folderDeleted,
  350.                                                this,
  351.                                                (XFE_FunctionNotification)folderDeleted_cb);
  352. }
  353.  
  354. XP_Bool
  355. XFE_MsgFrame::isCommandEnabled(CommandType cmd,
  356.                                    void *calldata, XFE_CommandInfo*)
  357. {
  358.     if (cmd == xfeCmdToggleLocationToolbar)
  359.         return True;
  360.     else if (cmd == xfeCmdCleanUpDisk)
  361.         return True;
  362.     else
  363.         return XFE_Frame::isCommandEnabled(cmd, calldata);
  364. }
  365.  
  366. void
  367. XFE_MsgFrame::doCommand(CommandType cmd,
  368.                             void *calldata, XFE_CommandInfo* info)
  369. {
  370.     if (cmd == xfeCmdToggleLocationToolbar)
  371.     {
  372.         if (m_banner)
  373.         {
  374.             // Toggle the showing state
  375.             m_banner->toggle();
  376.             
  377.             // Configure the logo
  378.             configureLogo();
  379.             
  380.             // Do the attachments
  381.             doAttachments();
  382.             
  383.             // Update prefs
  384.             toolboxItemChangeShowing(m_banner);
  385.  
  386.             // Update chrome
  387.             notifyInterested(XFE_View::chromeNeedsUpdating);
  388.         }
  389.  
  390.         return;
  391.     } else if ( (cmd == xfeCmdComposeMessage) ||
  392.                 (cmd == xfeCmdComposeMessagePlain) ||
  393.                 (cmd == xfeCmdComposeMessageHTML) || 
  394.                 (cmd == xfeCmdComposeArticle) ||
  395.                 (cmd == xfeCmdComposeArticlePlain) ||
  396.                 (cmd == xfeCmdComposeArticleHTML) )
  397.  
  398.         {
  399.                 XFE_MsgView *tview = (XFE_MsgView*)m_view;
  400.  
  401.                 tview->doCommand(cmd, calldata,info);  
  402.  
  403.         }
  404.  
  405.     else
  406.         XFE_Frame::doCommand(cmd, calldata, info);
  407. }
  408.  
  409. XP_Bool
  410. XFE_MsgFrame::handlesCommand(CommandType cmd,
  411.                  void *calldata, XFE_CommandInfo*)
  412. {
  413.     if (cmd == xfeCmdToggleLocationToolbar)
  414.         return True;
  415.     else
  416.         return XFE_Frame::handlesCommand(cmd, calldata);
  417. }
  418.  
  419. char *
  420. XFE_MsgFrame::commandToString(CommandType cmd,
  421.                                   void *calldata, XFE_CommandInfo*)
  422. {
  423.     if (cmd == xfeCmdToggleLocationToolbar)
  424.     {
  425.         char *res = NULL;
  426.         
  427.         if (m_banner->isShown())
  428.             res = "hideLocationToolbarCmdString";
  429.         else
  430.             res = "showLocationToolbarCmdString";
  431.         
  432.         return stringFromResource(res);
  433.     }
  434.     else
  435.     {
  436.         return XFE_Frame::commandToString(cmd, calldata);
  437.     }
  438. }
  439.  
  440. void XFE_MsgFrame::setButtonsByContext(MWContextType cxType)
  441. {
  442.     if (cxType == MWContextNewsMsg || cxType == MWContextNews)
  443.     {
  444.         m_toolbar->hideButton(xfeCmdComposeMessage, PUSHBUTTON);
  445.         m_toolbar->hideButton(xfeCmdDeleteMessage, PUSHBUTTON);
  446.         m_toolbar->hideButton(xfeCmdReplyToSender, CASCADEBUTTON);
  447.         m_toolbar->hideButton(xfeCmdMoveMessage, CASCADEBUTTON);
  448.  
  449.         m_toolbar->showButton(xfeCmdMarkMessageRead, CASCADEBUTTON);
  450.         m_toolbar->showButton(xfeCmdComposeArticle, PUSHBUTTON);
  451.         m_toolbar->showButton(xfeCmdReplyToNewsgroup, CASCADEBUTTON);
  452.         m_toolbar->showButton(xfeCmdCopyMessage, CASCADEBUTTON);
  453.     }
  454.     else
  455.     {
  456.         m_toolbar->showButton(xfeCmdComposeMessage, PUSHBUTTON);
  457.         m_toolbar->showButton(xfeCmdDeleteMessage, PUSHBUTTON);
  458.         m_toolbar->showButton(xfeCmdReplyToSender, CASCADEBUTTON);
  459.         m_toolbar->showButton(xfeCmdMoveMessage, CASCADEBUTTON);
  460.                   
  461.         m_toolbar->hideButton(xfeCmdComposeArticle, PUSHBUTTON);
  462.         m_toolbar->hideButton(xfeCmdReplyToNewsgroup, CASCADEBUTTON);
  463.         m_toolbar->hideButton(xfeCmdMarkMessageRead, CASCADEBUTTON);
  464.         m_toolbar->hideButton(xfeCmdCopyMessage, CASCADEBUTTON);
  465.     }
  466. }
  467.  
  468. void
  469. XFE_MsgFrame::allConnectionsComplete()
  470. {
  471.     XFE_Frame::allConnectionsComplete();
  472.     updateReadAndTotalCounts();
  473. }
  474.  
  475. void
  476. XFE_MsgFrame::loadMessage(MSG_FolderInfo *folder_info,
  477.                           MessageKey msg_key)
  478. {
  479.   XFE_MsgView *mview = (XFE_MsgView*)m_view;
  480.   MSG_FolderLine folderline;
  481.  
  482.   if (MSG_GetFolderLineById(XFE_MNView::getMaster(),
  483.                             folder_info, &folderline))
  484.       {
  485.           if (folderline.flags & MSG_FOLDER_FLAG_NEWSGROUP)
  486.               setButtonsByContext(MWContextNewsMsg);
  487.           else
  488.               setButtonsByContext(MWContextMailMsg);
  489.       }
  490.  
  491.   mview->loadMessage(folder_info, msg_key);
  492. }
  493.  
  494. MSG_Pane *
  495. XFE_MsgFrame::getPane()
  496. {
  497.   XFE_MsgView *mview = (XFE_MsgView*)m_view;
  498.  
  499.   return mview->getPane();
  500. }
  501.  
  502. MSG_FolderInfo *
  503. XFE_MsgFrame::getFolderInfo()
  504. {
  505.   XFE_MsgView *mview = (XFE_MsgView*)m_view;
  506.  
  507.   return mview->getFolderInfo();
  508. }
  509.  
  510. MessageKey
  511. XFE_MsgFrame::getMessageKey()
  512. {
  513.   XFE_MsgView *mview = (XFE_MsgView*)m_view;
  514.  
  515.   return mview->getMessageKey();
  516. }
  517.  
  518. XFE_CALLBACK_DEFN(XFE_MsgFrame, spaceAtMsgEnd)(XFE_NotificationCenter*,
  519.                            void *, void *)
  520. {
  521.   if (m_view->isCommandEnabled(xfeCmdNextUnreadMessage))
  522.     m_view->doCommand(xfeCmdNextUnreadMessage);
  523. }
  524.  
  525. XFE_CALLBACK_DEFN(XFE_MsgFrame, msgLoaded)(XFE_NotificationCenter*,
  526.                                            void*, void*)
  527. {
  528.   MSG_FolderInfo *folder_info;
  529.   MessageKey msg_key;
  530.   MSG_MessageLine threadline;
  531.   MSG_FolderLine folderline;
  532.   MSG_ViewIndex index;
  533.   XFE_MsgView *mview = (XFE_MsgView*)m_view;
  534.  
  535.   updateReadAndTotalCounts();
  536.  
  537.   MSG_GetCurMessage(mview->getPane(), &folder_info, &msg_key, &index);
  538.  
  539.   if (MSG_GetThreadLineById(mview->getPane(),
  540.                             msg_key, &threadline))
  541.     {
  542.       char subtitle[1024];
  543.       char *foldername = "";
  544.       char *subject;
  545.       char *author;
  546.  
  547.       m_banner->setTitle( XP_GetString ( XFE_MESSAGE ));
  548.  
  549.       if (MSG_GetFolderLineById(XFE_MNView::getMaster(),
  550.                                 folder_info, &folderline))
  551.         {
  552.             char buf[200];
  553.  
  554.             foldername = (char*)folderline.name;
  555.             
  556.             PR_snprintf(buf, sizeof(buf), XP_GetString(XFE_MN_UNREAD_AND_TOTAL), folderline.unseen, folderline.total);
  557.             
  558.             m_banner->setInfo(buf);
  559.         }
  560.          
  561.       INTL_DECODE_MIME_PART_II(subject, threadline.subject, fe_LocaleCharSetID, FALSE);
  562.       INTL_DECODE_MIME_PART_II(author, threadline.author, fe_LocaleCharSetID, FALSE);
  563.       PR_snprintf(subtitle, sizeof(subtitle),
  564.                   XP_GetString( XFE_MESSAGE_SUBTITLE ),
  565.                   subject,
  566.                   author,
  567.                   foldername);
  568.  
  569.       XP_FREE(subject);
  570.       XP_FREE(author);
  571.       m_banner->setSubtitle(subtitle);
  572.       notifyInterested(XFE_View::chromeNeedsUpdating);
  573.     }
  574. }
  575.  
  576. void
  577. XFE_MsgFrame::updateReadAndTotalCounts()
  578. {
  579.     MSG_FolderLine folderline;
  580.     MSG_FolderInfo *folder_info;
  581.     MessageKey msg_key;
  582.     MSG_ViewIndex index;
  583.     XFE_MsgView *mview = (XFE_MsgView*)m_view;
  584.  
  585.     MSG_GetCurMessage(mview->getPane(), &folder_info, &msg_key, &index);
  586.  
  587.     if (folder_info)
  588.         {
  589.             if (MSG_GetFolderLineById(XFE_MNView::getMaster(),
  590.                                       folder_info, &folderline))
  591.                 {
  592.                     char buf[200];
  593.                     
  594.                     PR_snprintf(buf, sizeof(buf), 
  595.                                 XP_GetString(XFE_MN_UNREAD_AND_TOTAL),
  596.                                 folderline.unseen,
  597.                                 folderline.total);
  598.                     
  599.                     m_banner->setInfo(buf);
  600.                 }
  601.         }
  602. }
  603.     
  604. XFE_CALLBACK_DEFN(XFE_MsgFrame, MNChromeUpdate)(XFE_NotificationCenter*,
  605.                                                 void*, void*)
  606. {
  607.     notifyInterested(XFE_View::chromeNeedsUpdating);
  608.  
  609.     updateReadAndTotalCounts();
  610. }
  611.  
  612. XFE_CALLBACK_DEFN(XFE_MsgFrame, FolderChromeUpdate)(XFE_NotificationCenter*,
  613.                                                     void*, void *cd)
  614. {
  615.     MSG_FolderInfo *info = (MSG_FolderInfo*)cd;
  616.  
  617.     if (info == getFolderInfo())
  618.         {
  619.             notifyInterested(XFE_View::chromeNeedsUpdating);
  620.  
  621.             updateReadAndTotalCounts();
  622.         }
  623. }
  624.  
  625. XFE_CALLBACK_DEFN(XFE_MsgFrame, msgDeleted)(XFE_NotificationCenter*,
  626.                            void *, void *cdata)
  627. {
  628.     /* Need to check if this folder ?
  629.      */
  630.     MessageKey id = (MessageKey) cdata;
  631.     if (id == getMessageKey())
  632.         hide();
  633. }
  634.  
  635. XFE_CALLBACK_DEFN(XFE_MsgFrame, folderDeleted)(XFE_NotificationCenter*,
  636.                            void *, void *cdata)
  637. {
  638.     
  639.     /* Need to check if this folder ?
  640.      */
  641.     MSG_FolderInfo *info = (MSG_FolderInfo *) cdata;
  642.     if (info == getFolderInfo())
  643.         delete_response();
  644. }
  645.  
  646. XFE_MsgFrame *
  647. XFE_MsgFrame::frameForMessage(MSG_FolderInfo *info, MessageKey key)
  648. {
  649.   XP_List *msg_frame_list = XFE_MozillaApp::theApp()->getFrameList( FRAME_MAILNEWS_MSG );
  650.   XP_List *current_list_entry;
  651.  
  652.   for (current_list_entry = msg_frame_list;
  653.        current_list_entry != NULL;
  654.        current_list_entry = current_list_entry->next)
  655.     {
  656.       if (current_list_entry->object
  657.       && ((XFE_Frame*)current_list_entry->object)->getType() == FRAME_MAILNEWS_MSG // sanity check
  658.       && ((XFE_MsgFrame*)current_list_entry->object)->getFolderInfo() == info
  659.       && ((XFE_MsgFrame*)current_list_entry->object)->getMessageKey() == key)
  660.     {
  661.       return (XFE_MsgFrame*)current_list_entry->object;
  662.     }
  663.     }
  664.  
  665.   return NULL;
  666. }
  667.  
  668. MWContext*
  669. fe_showMsg(Widget toplevel,
  670.            XFE_Frame *parent_frame,
  671.            Chrome *chromespec,
  672.            MSG_FolderInfo *folder_info,
  673.            MessageKey msg_key,
  674.            XP_Bool with_reuse)
  675. {
  676.  
  677.     XFE_MsgFrame *theFrame = NULL;
  678.  
  679.     if ( with_reuse )
  680.         {
  681.             XP_List *msg_frame_list = XFE_MozillaApp::theApp()->getFrameList( FRAME_MAILNEWS_MSG );
  682.             
  683.             if (!XP_ListIsEmpty(msg_frame_list))
  684.                 {
  685.                     theFrame = (XFE_MsgFrame*)XP_ListTopObject( msg_frame_list );
  686.                 }
  687.             
  688.             if (theFrame)
  689.                 {
  690.                     theFrame->show();
  691.                     theFrame->loadMessage( folder_info, msg_key );
  692.                     return theFrame->getContext();
  693.                 }
  694.         }
  695.     else
  696.         {
  697.             theFrame = XFE_MsgFrame::frameForMessage( folder_info, msg_key );
  698.             
  699.             if (theFrame)
  700.                 {
  701.                     theFrame->show();
  702.                     return theFrame->getContext();
  703.                 }
  704.         }
  705.     
  706.     // if we get here, either we were trying to reuse and there wasn't a
  707.     // messageframe at all, or we were not trying to reuse and just looking for
  708.     // for the messageframe displaying this message already and failed to find it.
  709.     // At any rate, we need to pop up another window.
  710.     theFrame = new XFE_MsgFrame(toplevel, parent_frame, chromespec);
  711.     theFrame->show();
  712.     theFrame->loadMessage( folder_info, msg_key );
  713.     
  714.     return theFrame->getContext();
  715. }
  716.  
  717. int
  718. XFE_MsgFrame::getSecurityStatus()
  719. {
  720.  XP_Bool is_signed = False;
  721.  XP_Bool is_encrypted = False;
  722.  XFE_MsgView *mview = (XFE_MsgView*)m_view;
  723.  XFE_MailSecurityStatusType status = XFE_UNSECURE_UNSIGNED;
  724.  
  725.  MIME_GetMessageCryptoState(getContext(), 0, 0, &is_signed, &is_encrypted);
  726.  
  727.  if (mview && mview->isDisplayingNews() )
  728.  {
  729.    // If this is displaying news, we decide if a newsgroup is secure(encrypted)
  730.    // or not by checking the security status ...instead of the crypto state
  731.  
  732.     is_encrypted = XFE_Frame::getSecurityStatus() == XFE_SECURE;
  733.  }
  734.  
  735.  if (is_encrypted && is_signed )
  736.  {
  737.      status = XFE_SECURE_SIGNED;
  738.  }
  739.  else if (!is_encrypted && is_signed)
  740.  {
  741.      status = XFE_UNSECURE_SIGNED;
  742.  }
  743.  else if (is_encrypted && !is_signed)
  744.  {
  745.      status = XFE_SECURE_UNSIGNED;
  746.  }
  747.  else if (!is_encrypted && !is_signed )
  748.  {
  749.      status = XFE_UNSECURE_UNSIGNED;
  750.  }
  751.  return status;
  752. }
  753.  
  754. //////////////////////////////////////////////////////////////////////////
  755. //
  756. // Toolbox methods
  757. //
  758. //////////////////////////////////////////////////////////////////////////
  759. void
  760. XFE_MsgFrame::toolboxItemSnap(XFE_ToolboxItem * item)
  761. {
  762.     XP_ASSERT( item == m_toolbar || item == m_banner );
  763.  
  764.     // Navigation
  765.     fe_globalPrefs.messenger_navigation_toolbar_position = m_toolbar->getPosition();
  766.  
  767.     // Location
  768.     fe_globalPrefs.messenger_location_toolbar_position = m_banner->getPosition();
  769. }
  770. //////////////////////////////////////////////////////////////////////////
  771. void
  772. XFE_MsgFrame::toolboxItemClose(XFE_ToolboxItem * item)
  773. {
  774.     XP_ASSERT( item != NULL );
  775.  
  776.     // Navigation
  777.     if (item == m_toolbar)
  778.     {
  779.         fe_globalPrefs.messenger_navigation_toolbar_open = False;
  780.     }
  781.     // Location
  782.     else if (item == m_banner)
  783.     {
  784.         fe_globalPrefs.messenger_location_toolbar_open = False;
  785.     }
  786. }
  787. //////////////////////////////////////////////////////////////////////////
  788. void
  789. XFE_MsgFrame::toolboxItemOpen(XFE_ToolboxItem * item)
  790. {
  791.     XP_ASSERT( item != NULL );
  792.  
  793.     // Navigation
  794.     if (item == m_toolbar)
  795.     {
  796.         fe_globalPrefs.messenger_navigation_toolbar_open = True;
  797.     }
  798.     // Location
  799.     else if (item == m_banner)
  800.     {
  801.         fe_globalPrefs.messenger_location_toolbar_open = True;
  802.     }
  803. }
  804. //////////////////////////////////////////////////////////////////////////
  805. void
  806. XFE_MsgFrame::toolboxItemChangeShowing(XFE_ToolboxItem * item)
  807. {
  808.     XP_ASSERT( item != NULL );
  809.  
  810.     // Navigation
  811.     if (item == m_toolbar)
  812.     {
  813.         fe_globalPrefs.messenger_navigation_toolbar_showing = item->isShown();
  814.     }
  815.     // Location
  816.     else if (item == m_banner)
  817.     {
  818.         fe_globalPrefs.messenger_location_toolbar_showing = item->isShown();
  819.     }
  820. }
  821. //////////////////////////////////////////////////////////////////////////
  822. void
  823. XFE_MsgFrame::configureToolbox()
  824. {
  825.     // If a the frame was constructed with a chromespec, then we ignore
  826.     // all the preference magic.
  827.     if (m_chromespec_provided)
  828.     {
  829.         return;
  830.     }
  831.  
  832.     // Make sure the toolbox is alive
  833.     if (!m_toolbox || (m_toolbox && !m_toolbox->isAlive()))
  834.     {
  835.         return;
  836.     }
  837.  
  838.     // Navigation
  839.     if (m_toolbar)
  840.     {
  841.         m_toolbar->setShowing(fe_globalPrefs.messenger_navigation_toolbar_showing);
  842.         m_toolbar->setOpen(fe_globalPrefs.messenger_navigation_toolbar_open);
  843.         m_toolbar->setPosition(fe_globalPrefs.messenger_navigation_toolbar_position);
  844.     }
  845.  
  846.     // Location
  847.     if (m_banner)
  848.     {
  849.         m_banner->setShowing(fe_globalPrefs.messenger_location_toolbar_showing);
  850.         m_banner->setOpen(fe_globalPrefs.messenger_location_toolbar_open);
  851.         m_banner->setPosition(fe_globalPrefs.messenger_location_toolbar_position);
  852.     }
  853. }
  854. extern int XFE_SEND_UNSENTMAIL;
  855.  
  856. XP_Bool 
  857. XFE_MsgFrame::isOkToClose()
  858. {
  859.    Boolean haveQueuedMail = False;
  860.    XFE_MsgView *tview = (XFE_MsgView*)m_view;
  861.  
  862.    if ( XFE_MozillaApp::theApp()->mailNewsWindowCount() == 1 )
  863.    {    
  864.        MSG_CommandStatus(tview->getPane(), MSG_DeliverQueuedMessages, NULL, 0,
  865.                 &haveQueuedMail, NULL, NULL, NULL );
  866.  
  867.        if (haveQueuedMail) {
  868.           void * sendNow = 0;
  869.           const char *buf =  XP_GetString (XFE_SEND_UNSENTMAIL);
  870.           sendNow = fe_dialog (CONTEXT_WIDGET(m_context),
  871.                                  "sendNow", buf, TRUE, 0, TRUE, FALSE, 0);
  872.           if (sendNow) {
  873.             MSG_Command (tview->getPane(), MSG_DeliverQueuedMessages, NULL, 0);
  874.             return False;
  875.           }
  876.         }
  877.  
  878.  
  879.         // See if we need to clean up based on disk space prefs
  880.         if (MSG_CleanupNeeded(tview->getMaster()))
  881.         {
  882.             // create progress pane
  883.             XFE_MailDownloadFrame* progressFrame = 
  884.                 new XFE_MailDownloadFrame(XfeAncestorFindApplicationShell(getBaseWidget()),
  885.                                           this,
  886.                                           tview->getPane());
  887.             progressFrame->cleanUpNews();
  888.             return True;
  889.         }
  890.     }
  891.     return True;
  892.  
  893. }
  894.  
  895. //////////////////////////////////////////////////////////////////////////
  896.