home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / BookmarkWhatsNewDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.8 KB  |  203 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.    BookmarkWhatsNewDialog.cpp -- dialog for checking "What's New".
  20.    Created: Stephen Lamm <slamm@netscape.com>, 28-May-97.
  21.  */
  22.  
  23.  
  24.  
  25. #include "BookmarkWhatsNewDialog.h"
  26. #include "bkmks.h"
  27. #include "xfe.h"
  28. #include "xpgetstr.h"
  29.  
  30. extern int XFE_LOOK_FOR_DOCUMENTS_THAT_HAVE_CHANGED_ON;
  31. extern int XFE_ESTIMATED_TIME_REMAINING_CHECKED;
  32. extern int XFE_ESTIMATED_TIME_REMAINING_CHECKING;
  33. extern int XFE_DONE_CHECKING_ETC;
  34.  
  35. XFE_BookmarkWhatsNewDialog::XFE_BookmarkWhatsNewDialog(MWContext *context, Widget parent)
  36.   : XFE_Dialog(parent, "bookmarksWhatsChanged",
  37.                TRUE,   // ok
  38.                TRUE,   // cancel
  39.                FALSE,  // help
  40.                TRUE,   // apply
  41.                TRUE,   // Separator
  42.                FALSE  // Modal
  43.                )
  44. {
  45.   m_context = context;
  46.  
  47.   fe_UnmanageChild_safe (m_okButton);
  48.  
  49.   XtVaSetValues(m_chrome, XmNchildPlacement, XmPLACE_BELOW_SELECTION, NULL);
  50.  
  51.   m_text   = XmSelectionBoxGetChild (m_chrome, XmDIALOG_SELECTION_LABEL);
  52.  
  53.   XtManageChild(m_text);
  54.  
  55.   XtAddCallback(m_chrome, XmNdestroyCallback, destroy_cb, this);
  56.   XtAddCallback(m_chrome, XmNcancelCallback, close_cb, this);
  57.   XtAddCallback(m_chrome, XmNapplyCallback, apply_cb, this);
  58.   XtAddCallback(m_chrome, XmNokCallback, ok_cb, this);
  59.  
  60.   m_radioBox =
  61.     XmVaCreateSimpleRadioBox(m_chrome, "radiobox", 0, NULL,
  62.                  XmVaRADIOBUTTON, NULL, NULL, NULL, NULL,
  63.                  XmVaRADIOBUTTON, NULL, NULL, NULL, NULL,
  64.                  NULL);
  65.  
  66.   int numKids;
  67.   Widget* kids;
  68.  
  69.   XtVaGetValues(m_radioBox, XmNnumChildren, &numKids, XmNchildren, &kids, 0);
  70.   XP_ASSERT(numKids == 2);
  71.  
  72.   m_doAll      = kids[0];
  73.   m_doSelected = kids[1];
  74.  
  75.   XtManageChildren(kids, numKids);
  76.  
  77.   XtManageChild(m_radioBox);
  78.  
  79.   XmString str = XmStringCreate( XP_GetString( XFE_LOOK_FOR_DOCUMENTS_THAT_HAVE_CHANGED_ON ), 
  80.                                  XmFONTLIST_DEFAULT_TAG); 
  81.   XtVaSetValues(m_text, XmNlabelString, str, NULL);
  82.   XmStringFree(str);
  83.  
  84.   fe_HackDialogTranslations (m_chrome);
  85. }
  86.  
  87. XFE_BookmarkWhatsNewDialog::~XFE_BookmarkWhatsNewDialog()
  88. {
  89.   close();
  90. }
  91.  
  92. void
  93. XFE_BookmarkWhatsNewDialog::destroy_cb(Widget /*widget*/,
  94.                                    XtPointer closure, XtPointer /*call_data*/)
  95. {
  96.   XFE_BookmarkWhatsNewDialog* obj = (XFE_BookmarkWhatsNewDialog *)closure;
  97.  
  98.   obj->close();
  99. }
  100.  
  101.  
  102. void
  103. XFE_BookmarkWhatsNewDialog::close()
  104. {
  105.   BM_CancelWhatsChanged(m_context);
  106. }
  107.  
  108. void
  109. XFE_BookmarkWhatsNewDialog::close_cb(Widget /*widget*/,
  110.                                  XtPointer closure, XtPointer /*call_data*/)
  111. {
  112.   XFE_BookmarkWhatsNewDialog* obj = (XFE_BookmarkWhatsNewDialog *)closure;
  113.  
  114.   XtDestroyWidget(obj->getBaseWidget());
  115. }
  116.  
  117. void
  118. XFE_BookmarkWhatsNewDialog::apply()
  119. {
  120.   Boolean doselected = FALSE;
  121.   XtVaGetValues(m_doSelected, XmNset, &doselected, NULL);
  122.   BM_StartWhatsChanged(m_context, doselected);
  123. }
  124.  
  125. void
  126. XFE_BookmarkWhatsNewDialog::apply_cb(Widget /*widget*/,
  127.                               XtPointer closure, XtPointer /*call_data*/)
  128. {
  129.   XFE_BookmarkWhatsNewDialog* obj = (XFE_BookmarkWhatsNewDialog *)closure;
  130.  
  131.   obj->apply();
  132. }
  133.  
  134. void
  135. XFE_BookmarkWhatsNewDialog::ok()
  136. {
  137.   ; // nothing more to do
  138. }
  139.  
  140. void
  141. XFE_BookmarkWhatsNewDialog::ok_cb(Widget /*widget*/,
  142.                               XtPointer closure, XtPointer /*call_data*/)
  143. {
  144.   XFE_BookmarkWhatsNewDialog* obj = (XFE_BookmarkWhatsNewDialog *)closure;
  145.  
  146.   obj->ok();
  147.  
  148.   XtDestroyWidget(obj->getBaseWidget());
  149. }
  150.  
  151. void
  152. XFE_BookmarkWhatsNewDialog::updateWhatsChanged(const char* url,
  153.                                                int32 done, int32 total,
  154.                                                const char* totaltime)
  155. {
  156.   char buf[1024];
  157.   XmString str;
  158.  
  159.   if (!m_chrome) return;
  160.  
  161.   if (m_radioBox) {
  162.     fe_UnmanageChild_safe(m_radioBox);
  163.     fe_UnmanageChild_safe(m_applyButton);
  164.     m_radioBox = NULL;
  165.   }
  166.  
  167.   if ( url )
  168.     PR_snprintf(buf, sizeof(buf),
  169.                 XP_GetString( XFE_ESTIMATED_TIME_REMAINING_CHECKED ),
  170.                 url,
  171.                 total - done,
  172.                 total > 0 ? done * 100 / total : 0,
  173.                 totaltime);
  174.   else
  175.     PR_snprintf(buf, sizeof(buf),
  176.                 XP_GetString( XFE_ESTIMATED_TIME_REMAINING_CHECKING ),
  177.                 total - done,
  178.                 total > 0 ? done * 100 / total : 0,
  179.                 totaltime);
  180.  
  181.   str = XmStringCreateLtoR(buf, XmFONTLIST_DEFAULT_TAG);
  182.   XtVaSetValues(m_text, XmNlabelString, str, NULL);
  183.   XmStringFree(str);
  184. }
  185.  
  186. void 
  187. XFE_BookmarkWhatsNewDialog::finishedWhatsChanged(int32 totalchecked,
  188.                                                  int32 numreached, 
  189.                                                  int32 numchanged)
  190. {
  191.   char buf[1024];
  192.   XmString str;
  193.   fe_UnmanageChild_safe(m_radioBox);
  194.   fe_UnmanageChild_safe(m_cancelButton);
  195.   XtManageChild(m_okButton);
  196.   PR_snprintf(buf, sizeof(buf), XP_GetString( XFE_DONE_CHECKING_ETC ),
  197.           totalchecked, numreached, numchanged);
  198.  
  199.   str = XmStringCreateLtoR(buf, XmFONTLIST_DEFAULT_TAG);
  200.   XtVaSetValues(m_text, XmNlabelString, str, NULL);
  201.   XmStringFree(str);
  202. }
  203.