home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / central / ULocationIndependence.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.1 KB  |  189 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. // ULocationIndependence.cp - MacFE specific location independence code
  20.  
  21. #include "uapp.h"
  22. #include "li_public.h"
  23. #include "pprthred.h"
  24. #include "plevent.h"
  25. #include <LCommander.h>
  26.  
  27. // CLICommander
  28. // Location independence commands
  29. class CLICommander : public LCommander, public LEventDispatcher    {
  30.     enum EQuitState    {
  31.         eWaitingForUploadAll,
  32.         eUploadAllStarted,
  33.         eUploadAllComplete
  34.     };
  35.     
  36. public:
  37.     int                fVerifyLoginCount;
  38.     int             fNumOfCriticalFiles;
  39.     EQuitState        fState;
  40.  
  41. // Constructors
  42.     CLICommander(LCommander * inSuper);
  43.     virtual ~CLICommander() {};
  44.  
  45. // Startup logic
  46.     static void GetCriticalClosure(void * closure,  LIStatus result);
  47.     void GetCriticalFiles();
  48.     void VerifyLogin();
  49.  
  50. // Quit logic
  51.     virtual Boolean    AttemptQuit(long inSaveOption);
  52. private:
  53.     static void VerifyLoginCallback(void * closure, LIStatus result);
  54.     static void uploadAllClosure( void * closure, LIStatus result);
  55.  
  56.     void UploadAllComplete(LIStatus status);
  57.     
  58.     // Does a busy wait, while processing events
  59.     void WaitOnInt(int * boolean);
  60. };
  61.  
  62.  
  63. CLICommander::CLICommander(LCommander * inSuper) 
  64.     : LCommander(inSuper) 
  65. {
  66.     fState = eWaitingForUploadAll;
  67.     
  68. /*
  69.     LIFile * file1 = new LIFile ("/Speedy/coreprofile/file1", "FirstFile", "Test file 1");
  70.     LIFile * file2 = new LIFile ("/Speedy/coreprofile/file2", "SecondFile", "Test file 2");
  71.     LIFile * file3 = new LIFile ("/Speedy/coreprofile/file3", "ThirdFile", "Test file 3");
  72.     fGroup = new LIClientGroup();
  73.     fGroup->addFile( file1, NULL, NULL, NULL, NULL);
  74.     fGroup->addFile( file2, NULL, NULL, NULL, NULL);
  75.     fGroup->addFile( file3, NULL, NULL, NULL, NULL);
  76. */
  77. }
  78.  
  79. extern PREventQueue *mozilla_event_queue;
  80.  
  81. void CLICommander::GetCriticalFiles()
  82. {
  83.     fNumOfCriticalFiles = 0;
  84.     LI_StartGettingCriticalFiles( &fNumOfCriticalFiles );
  85.     WaitOnInt(&fNumOfCriticalFiles);
  86. }
  87.  
  88. void CLICommander::VerifyLoginCallback(void * closure, LIStatus result)
  89. {
  90.     CLICommander * commander = (CLICommander*) closure;
  91.     commander->fVerifyLoginCount = 0;
  92. }
  93.  
  94. void CLICommander::VerifyLogin()
  95. {
  96.     fVerifyLoginCount = 1;
  97.     LIMediator::verifyLogin(VerifyLoginCallback, this);
  98.     WaitOnInt(&fVerifyLoginCount);
  99. }
  100.  
  101. void CLICommander::WaitOnInt(int * waitInt)
  102. {
  103.     EventRecord macEvent;
  104.     
  105.     while (*waitInt > 0)
  106.     {
  107.         if (IsOnDuty()) {
  108.             ::OSEventAvail(0, &macEvent);
  109.             AdjustCursor(macEvent);
  110.         }
  111.  
  112.         SetUpdateCommandStatus(false);
  113.  
  114.         Boolean gotEvent = ::WaitNextEvent(everyEvent, &macEvent,
  115.                                             1, mMouseRgnH);
  116.         
  117.             // Let Attachments process the event. Continue with normal
  118.             // event dispatching unless suppressed by an Attachment.
  119.         
  120.         if (LEventDispatcher::ExecuteAttachments(msg_Event, &macEvent)) {
  121.             if (gotEvent) {
  122.                 DispatchEvent(macEvent);
  123.             } else {
  124.                 UseIdleTime(macEvent);
  125.             }
  126.         }
  127.  
  128.                                         // Repeaters get time after every event
  129.         LPeriodical::DevoteTimeToRepeaters(macEvent);
  130.         
  131.                                         // Update status of menu items
  132.         if (IsOnDuty() && GetUpdateCommandStatus()) {
  133.             UpdateMenus();
  134.         }
  135.         // This pumps the mocha thread
  136.         PL_ProcessPendingEvents(mozilla_event_queue);
  137.     }
  138.     // We need to give time to idlers once again because:
  139.     // HTML conflict dialogs are being destroyed on a timer by libsec
  140.     // CreateStartupEnvironment() will not display any new windows if any HTML windows are visible
  141.     // => Must let timers run to destroy HTML dialogs before we proceed
  142.     macEvent.when = ::TickCount();
  143.     LPeriodical::DevoteTimeToIdlers(macEvent);
  144. }
  145.  
  146.  
  147. void CLICommander::uploadAllClosure( void * closure, LIStatus status)
  148. {
  149.     CLICommander * c = (CLICommander*) closure;
  150.     c->UploadAllComplete(status);
  151. }
  152.  
  153. void CLICommander::UploadAllComplete(LIStatus status)
  154. {
  155.     fState = eUploadAllComplete;
  156.     LI_Shutdown();
  157.     (CFrontApp::GetApplication())->DoQuit();
  158. }
  159.  
  160. Boolean    CLICommander::AttemptQuit(long    inSaveOption)
  161. {
  162.     switch (fState)
  163.     {
  164.         case eWaitingForUploadAll:
  165.             LIMediator::uploadAll(uploadAllClosure, this);
  166.             break;
  167.  
  168.         case eUploadAllStarted:
  169.             return false;
  170.             break;
  171.  
  172.         case eUploadAllComplete:
  173.             return true;    // We can quit now
  174.     }
  175.     return false;
  176. }
  177.  
  178. #ifndef MOZ_LITE
  179. // InitializeLocationIndependence
  180. // Busy wait until all the Critical Files have been downloaded
  181. void CFrontApp::InitializeLocationIndependence()
  182. {
  183. //    LI_Startup();
  184. //    CLICommander * newCommander = new CLICommander(this);
  185. //    newCommander->VerifyLogin();
  186. //    newCommander->GetCriticalFiles();    
  187. }
  188. #endif
  189.