home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / SubscribeView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.9 KB  |  269 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.    SubscribeView.cpp -- 4.x subscribe view.
  20.    Created: Chris Toshok <toshok@netscape.com>, 16-Oct-1996.
  21.    */
  22.  
  23.  
  24.  
  25. #include "MozillaApp.h"
  26. #include "SubscribeView.h"
  27. #include "SubTabView.h"
  28. #include "SubAllView.h"
  29. #include "SubSearchView.h"
  30. #include "SubNewView.h"
  31.  
  32. #include "xfe.h"
  33. #include "msgcom.h"
  34. #include "xp_mem.h"
  35.  
  36. #include <XmL/Folder.h>
  37.  
  38. XFE_SubscribeView::XFE_SubscribeView(XFE_Component *toplevel_component, 
  39.                                      Widget parent,
  40.                                      XFE_View *parent_view,
  41.                                      MWContext *context,
  42.                                      MSG_Host *host,
  43.                                      MSG_Pane *p)
  44.     : XFE_MNView(toplevel_component, parent_view, context, p)
  45. {
  46.     Widget folder;
  47.     XFE_SubAllView *suballview;
  48.     XFE_SubSearchView *subsearchview;
  49.     XFE_SubNewView *subnewview;
  50.     int all_buttons_maxwidth, search_buttons_maxwidth, new_buttons_maxwidth;
  51.     int max_button_width;
  52.  
  53.     if (!p)
  54.         {
  55.             setPane(MSG_CreateSubscribePaneForHost(m_contextData,
  56.                                                    XFE_MNView::m_master,
  57.                                                    host));
  58.             XP_ASSERT(m_pane != 0);
  59.         }
  60.  
  61.     getToplevel()->registerInterest(XFE_View::chromeNeedsUpdating,
  62.                                     this,
  63.                                     (XFE_FunctionNotification)updateButtons_cb);
  64.  
  65.     folder = XtVaCreateWidget("subscribeFolder",
  66.                               xmlFolderWidgetClass,
  67.                               parent,
  68.                               NULL);
  69.  
  70.     setBaseWidget(folder);
  71.  
  72.     XtAddCallback(folder, XmNactivateCallback, tab_activate_callback, this);
  73.  
  74.     suballview = new XFE_SubAllView(toplevel_component, folder, this, m_contextData, m_pane);
  75.     subsearchview = new XFE_SubSearchView(toplevel_component, folder, this, m_contextData, m_pane);  
  76.     subnewview = new XFE_SubNewView(toplevel_component, folder, this, m_contextData, m_pane);
  77.  
  78.     addView(suballview);
  79.     addView(subsearchview);
  80.     addView(subnewview);
  81.  
  82.     all_buttons_maxwidth = suballview->getButtonsMaxWidth();
  83.     search_buttons_maxwidth = subsearchview->getButtonsMaxWidth();
  84.     new_buttons_maxwidth = subnewview->getButtonsMaxWidth();
  85.  
  86.     max_button_width = all_buttons_maxwidth;
  87.     if (search_buttons_maxwidth > max_button_width)
  88.       max_button_width = search_buttons_maxwidth;
  89.     if (new_buttons_maxwidth > max_button_width)
  90.       max_button_width = new_buttons_maxwidth;
  91.  
  92.     suballview->setButtonsWidth(max_button_width);
  93.     subsearchview->setButtonsWidth(max_button_width);
  94.     subnewview->setButtonsWidth(max_button_width);
  95.  
  96.     suballview->show();
  97.     subsearchview->show();
  98.     subnewview->show();
  99.  
  100.     // make the subtabview generate the list of of servers.
  101.     XFE_SubTabView::syncServerList();
  102.  
  103.     static MSG_SubscribeCallbacks subscribe_callbacks = {
  104.       XFE_SubscribeView::do_fetch_group,
  105.       XFE_SubscribeView::fetch_completed
  106.     };
  107.  
  108.     // since the all tab is the visible one when we start.
  109.     tab_activate(0);
  110.  
  111.     MSG_SubscribeSetCallbacks(m_pane, &subscribe_callbacks, this);
  112. }
  113.  
  114. XFE_SubscribeView::~XFE_SubscribeView()
  115. {
  116.     destroyPane();
  117.  
  118. #if notyet
  119. /* This line is needed to fix bug #77615.  The problem is that if it's present,
  120.    when you close the subscribe UI it hangs for anywhere from 10 seconds to
  121.    a couple of minutes depending on the number of newsgroups the server has. */
  122.     XFE_MozillaApp::theApp()->notifyInterested(XFE_MNView::foldersHaveChanged);
  123. #endif
  124. }
  125.  
  126. Boolean
  127. XFE_SubscribeView::isCommandEnabled(CommandType command, void *calldata, XFE_CommandInfo*)
  128. {
  129.     MWContext *c = MSG_GetContext(m_pane);
  130.     XP_Bool busy = XP_IsContextBusy(c);
  131.     XP_Bool stoppable = fe_IsContextStoppable(c);
  132.  
  133.     if (command == xfeCmdDialogOk
  134.         || command == xfeCmdDialogCancel)
  135.         {
  136.             return True;
  137.         }
  138.     else if (command == xfeCmdStopLoading)
  139.         {
  140.             return ((busy && stoppable) != 0);
  141.         }
  142.     else
  143.         {
  144.             return m_activeView->isCommandEnabled(command, calldata);
  145.         }
  146. }
  147.  
  148. Boolean
  149. XFE_SubscribeView::handlesCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  150. {
  151.     if (command == xfeCmdDialogOk
  152.         || command == xfeCmdDialogCancel
  153.         || command == xfeCmdStopLoading
  154.         )
  155.         {
  156.             return True;
  157.         }
  158.     else
  159.         {
  160.             return m_activeView->handlesCommand(command, calldata);
  161.         }
  162. }
  163.  
  164. void
  165. XFE_SubscribeView::doCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  166. {
  167.     if (command == xfeCmdDialogCancel)
  168.         {
  169.             MSG_SubscribeCancel(m_pane);
  170.         }
  171.     else if (command == xfeCmdStopLoading)
  172.         {
  173.             MWContext *c = MSG_GetContext(m_pane);
  174.  
  175.             XP_InterruptContext(c);
  176.         }
  177.     else if (command == xfeCmdDialogOk)
  178.         {
  179.             MSG_SubscribeCommit(m_pane);
  180.         }
  181.     else
  182.         {
  183.             m_activeView->doCommand(command, calldata);
  184.         }
  185. }
  186.  
  187. void
  188. XFE_SubscribeView::tab_activate(int pos)
  189. {
  190.     XP_ASSERT(pos >=0 && pos <=2);
  191.  
  192.     m_activeView = (XFE_SubTabView*)m_subviews[pos];
  193.  
  194.     // associate the active view with the pane, so we have a way
  195.     // to get to the right outliner.
  196.     m_activeView->setPane(m_pane);
  197.  
  198.     m_activeView->defaultFocus();
  199.  
  200.     m_activeView->syncServerCombo();
  201.  
  202.     switch(pos)
  203.         {
  204.         case 0: // All tab
  205.             MSG_SubscribeSetMode(m_pane, MSG_SubscribeAll);
  206.             break;
  207.         case 1: // Search tab
  208.             MSG_SubscribeSetMode(m_pane, MSG_SubscribeSearch);
  209.             break;
  210.         case 2: // New tab
  211.             MSG_SubscribeSetMode(m_pane, MSG_SubscribeNew);
  212.             m_activeView->doCommand(xfeCmdGetNewGroups);
  213.             break;
  214.         default:
  215.             XP_ASSERT(0);
  216.             break;
  217.         }
  218.  
  219.     m_activeView->updateButtons();
  220. }
  221.  
  222. void
  223. XFE_SubscribeView::tab_activate_callback(Widget /*w*/,
  224.                                          XtPointer clientData,
  225.                                          XtPointer callData)
  226. {
  227.     XFE_SubscribeView *obj = (XFE_SubscribeView*)clientData;
  228.     XmLFolderCallbackStruct *cbs = (XmLFolderCallbackStruct*)callData;
  229.  
  230.     cbs->layoutNeeded = True;
  231.     obj->tab_activate(cbs->pos);
  232. }
  233.  
  234. XFE_CALLBACK_DEFN(XFE_SubscribeView, updateButtons)(XFE_NotificationCenter *,
  235.                                                     void *, void *)
  236. {
  237.     m_activeView->updateButtons();
  238. }
  239.  
  240. void
  241. XFE_SubscribeView::fetchCompleted()
  242. {
  243.   m_activeView->updateButtons();
  244. }
  245.  
  246. void
  247. XFE_SubscribeView::doFetchGroup()
  248. {
  249.   m_activeView->doCommand(xfeCmdFetchGroupList);
  250. }
  251.  
  252. void
  253. XFE_SubscribeView::fetch_completed(MSG_Pane *,
  254.                                    void *closure)
  255. {
  256.   XFE_SubscribeView *obj = (XFE_SubscribeView*)closure;
  257.  
  258.   obj->fetchCompleted();
  259. }
  260.  
  261. void
  262. XFE_SubscribeView::do_fetch_group(MSG_Pane *,
  263.                                   void *closure)
  264. {
  265.   XFE_SubscribeView *obj = (XFE_SubscribeView*)closure;
  266.  
  267.   obj->doFetchGroup();
  268. }
  269.