home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / rdfui / URDFUtilities.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  3.4 KB  |  127 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. //
  20. // Miscellaneous RDF utility methods
  21. //
  22.  
  23. #include "URDFUtilities.h"
  24.  
  25. #include "xp_mem.h"
  26. #include "ufilemgr.h" // for CFileMgr::GetURLFromFileSpec
  27. #include "uprefd.h" // for CPrefs::GetFolderSpec & globHistoryName
  28. #include "PascalString.h" // for CStr255
  29.  
  30.  
  31. Boolean URDFUtilities::sIsInited = false;
  32.  
  33.  
  34. //
  35. // StartupRDF
  36. //
  37. // Initialize RDF if it has not already been initialized. This method can be
  38. // called over and over again without bad side effects because it protects the init
  39. // code with a static variable.
  40. //
  41. void URDFUtilities::StartupRDF()
  42. {
  43.     if (!sIsInited)
  44.     {        
  45.         // Point RDF to user's "Navigator ─" preference folder and turn the FSSpec into
  46.         // a URL
  47.         FSSpec prefFolder = CPrefs::GetFolderSpec(CPrefs::MainFolder);
  48.         char* url = CFileMgr::GetURLFromFileSpec(prefFolder);
  49.         CStr255 urlStr(url);
  50.         XP_FREE(url);
  51.         
  52.         // fill in RDF params structure with appropriate file paths
  53.         CStr255 str;
  54.         RDF_InitParamsStruct initParams;
  55.         initParams.profileURL = (char*)urlStr;
  56.         ::GetIndString(str, 300, bookmarkFile);
  57.         initParams.bookmarksURL = (char*)(urlStr + "/" + str);
  58.         ::GetIndString(str, 300, globHistoryName);
  59.         initParams.globalHistoryURL = (char*)(urlStr + "/" + str);
  60.         
  61. //        url = NET_UnEscape(url);
  62.         RDF_Init(&initParams);
  63.         sIsInited = true;
  64.     }
  65. }
  66.  
  67.  
  68. //
  69. // ShutdownRDF
  70. //
  71. // Opposite of above routine. Again, can be called multiple times w/out bad side
  72. // effects.
  73. //
  74. void URDFUtilities::ShutdownRDF()
  75. {
  76.     if (sIsInited)
  77.     {
  78.         RDF_Shutdown();
  79.         sIsInited = false;
  80.     }
  81. }
  82.  
  83. Uint32 URDFUtilities::GetContainerSize(HT_Resource container)
  84. {
  85.     Uint32 result = 0;
  86.     // trust but verify...
  87.     if (HT_IsContainer(container))
  88.     {
  89.         HT_Cursor cursor = HT_NewCursor(container);
  90.         if (cursor)
  91.         {
  92.             HT_Resource node = HT_GetNextItem(cursor);
  93.             while (node != NULL)
  94.             {
  95.                 ++result;
  96.                 if (HT_IsContainer(node) && HT_IsContainerOpen(node))
  97.                     result += GetContainerSize(node);
  98.                 
  99.                 node = HT_GetNextItem(cursor);
  100.             }
  101.         }
  102.     }
  103.     return result;
  104. }
  105.  
  106.  
  107. //
  108. // StHTEventMasking
  109. //
  110. // Change HT's event masking in the given pane for the lifetime of this class. This is
  111. // meant to be used as a stack-based class. The new notification mask is set in the contsructor
  112. // and is reset to the original mask in the destructor.
  113. // 
  114.  
  115. URDFUtilities::StHTEventMasking :: StHTEventMasking ( HT_Pane inPane, HT_NotificationMask inNewMask )
  116.     : mPane(inPane)
  117. {
  118.     HT_GetNotificationMask ( mPane, &mOldMask );
  119.     HT_SetNotificationMask ( mPane, inNewMask );
  120. }
  121.  
  122.  
  123. URDFUtilities::StHTEventMasking :: ~StHTEventMasking ( ) 
  124. {
  125.     HT_SetNotificationMask ( mPane, mOldMask );
  126. }
  127.