Back to index

lightning-sunbird  0.9+nobinonly
TerminalWin.c
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code, released
00016  * March 31, 1998.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Samir Gehani <sgehani@netscape.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "MacInstallWizard.h"
00041 
00042 
00043 /*-----------------------------------------------------------*
00044  *   Terminal Window
00045  *-----------------------------------------------------------*/
00046 
00047 static Boolean bDownloadedRedirect = false;
00048 
00049 void 
00050 ShowTerminalWin(void)
00051 {
00052        Str255        next, back;
00053        Handle        rectH;
00054        Rect          viewRect;
00055        short         reserr;
00056        MenuHandle                  popupMenu;
00057        PopupPrivateData ** pvtDataHdl;
00058        unsigned char *             currMenuItem;
00059        short                       i, vRefNum;
00060        long                        cwdDirID, dirID;
00061        Boolean                            isDir = false;
00062        Str255                      pModulesDir;
00063        OSErr                       err = noErr;
00064        GrafPtr              oldPort;
00065        GetPort(&oldPort);
00066 
00067        if (gWPtr != NULL)
00068        {
00069               SetPort(gWPtr);
00070        
00071               gCurrWin = kTerminalID; 
00072               /* gControls->tw = (TermWin*) NewPtrClear(sizeof(TermWin)); */
00073        
00074               GetResourcedString(next, rInstList, sInstallBtn);
00075               GetResourcedString(back, rInstList, sBackBtn);
00076        
00077               // malloc and get control
00078               rectH = Get1Resource('RECT', rStartMsgBox);
00079               reserr = ResError();
00080               if (reserr == noErr && rectH != NULL)
00081               {
00082                      viewRect = (Rect) **((Rect **)rectH);
00083                      ReleaseResource(rectH);
00084         }
00085               else
00086               {
00087                      ErrorHandler(reserr, nil);
00088                      return;
00089               }
00090               
00091               gControls->tw->siteSelector = NULL;
00092               gControls->tw->saveBitsCheckbox = NULL;
00093               
00094               gControls->tw->startMsgBox = viewRect;
00095        
00096               gControls->tw->startMsg = TENew(&viewRect, &viewRect);
00097         if (gControls->tw->startMsg == NULL)
00098         {
00099               ErrorHandler(eMem, nil);
00100               return;
00101         }
00102     
00103               // save bits after download and install
00104        
00105               /* get the "Installer Modules" relative subdir */
00106               ERR_CHECK(GetCWD(&cwdDirID, &vRefNum));
00107               GetIndString(pModulesDir, rStringList, sInstModules);
00108               GetDirectoryID(vRefNum, cwdDirID, pModulesDir, &dirID, &isDir);
00109               if (isDir)
00110               {
00111                      if (!ExistArchives(vRefNum, dirID))  // going to download
00112                      {                        
00113                      if (gControls->cfg->numSites > 0)
00114                      {
00115                     // download settings groupbox
00116                     Str255 dlSettingsGBTitle;
00117                     gControls->tw->dlSettingsGB = GetNewControl(rDLSettingsGB, gWPtr);
00118                     if (gControls->tw->dlSettingsGB)
00119                     {
00120                         GetResourcedString(dlSettingsGBTitle, rInstList, sDLSettings);
00121                         SetControlTitle(gControls->tw->dlSettingsGB, dlSettingsGBTitle);
00122                         ShowControl(gControls->tw->dlSettingsGB);
00123                     }
00124                     
00125                     // site selector label
00126                     Str255 siteSelMsgStr;
00127                     gControls->tw->siteSelMsg = GetNewControl(rSiteSelMsg, gWPtr);
00128                     if (gControls->tw->siteSelMsg)
00129                     {
00130                         GetResourcedString(siteSelMsgStr, rInstList, sSiteSelMsg);
00131                         SetControlData(gControls->tw->siteSelMsg, kControlNoPart, 
00132                             kControlStaticTextTextTag, siteSelMsgStr[0], (Ptr)&siteSelMsgStr[1]); 
00133                         ShowControl(gControls->tw->siteSelMsg);
00134                     }
00135                     
00136                       // site selector
00137                             gControls->tw->siteSelector = GetNewControl( rSiteSelector, gWPtr );
00138                             if (!gControls->tw->siteSelector)
00139                             {
00140                                    ErrorHandler(eMem, nil);
00141                                    return;
00142                             }
00143                             
00144                             // populate popup button menus
00145                             HLock((Handle)gControls->tw->siteSelector);
00146                             pvtDataHdl = (PopupPrivateData **) (*(gControls->tw->siteSelector))->contrlData;
00147                             HLock((Handle)pvtDataHdl);
00148                             popupMenu = (MenuHandle) (**pvtDataHdl).mHandle;
00149                             for (i=0; i<gControls->cfg->numSites; i++)
00150                             {
00151                                    HLock(gControls->cfg->site[i].desc);
00152                                    currMenuItem = CToPascal(*gControls->cfg->site[i].desc);              
00153                                    HUnlock(gControls->cfg->site[i].desc);
00154                                    InsertMenuItem( popupMenu, currMenuItem, i );
00155                             }
00156                             HUnlock((Handle)pvtDataHdl);
00157                             HUnlock((Handle)gControls->tw->siteSelector);
00158                             SetControlMaximum(gControls->tw->siteSelector, gControls->cfg->numSites);
00159                             SetControlValue(gControls->tw->siteSelector, gControls->opt->siteChoice);
00160                             ShowControl(gControls->tw->siteSelector);
00161                      }
00162               
00163                             // show check box and message
00164                             gControls->tw->saveBitsCheckbox = GetNewControl( rSaveCheckbox, gWPtr );
00165                             if (!gControls->tw->saveBitsCheckbox)
00166                             {
00167                                    ErrorHandler(eMem, nil);
00168                                    return;
00169                             }
00170                             if (gControls->opt->saveBits)
00171                                 SetControlValue(gControls->tw->saveBitsCheckbox, 1);
00172                             ShowControl(gControls->tw->saveBitsCheckbox);
00173                             
00174                             // get rect for save bits message
00175                             rectH = Get1Resource('RECT', rSaveBitsMsgBox);
00176                             reserr = ResError();
00177                             if (reserr == noErr && rectH != NULL)
00178                             {
00179                                     gControls->tw->saveBitsMsgBox  = (Rect) **((Rect **)rectH);
00180                                     DisposeHandle(rectH);
00181                          }
00182                             else
00183                             {
00184                                    ErrorHandler(reserr, nil);
00185                                    return;
00186                             }
00187                             
00188                             // get text edit record for save bits message
00189                             gControls->tw->saveBitsMsg = TENew(&gControls->tw->saveBitsMsgBox,
00190                                                                                        &gControls->tw->saveBitsMsgBox );
00191                          if (gControls->tw->saveBitsMsg == NULL)
00192                          {
00193                             ErrorHandler(eMem, nil);
00194                             return;
00195                          }
00196                          HLock(gControls->cfg->saveBitsMsg);
00197                             TESetText(*gControls->cfg->saveBitsMsg, strlen(*gControls->cfg->saveBitsMsg),
00198                                    gControls->tw->saveBitsMsg);
00199                             HUnlock(gControls->cfg->saveBitsMsg);
00200                             
00201                             // show save bits msg
00202                             TEUpdate(&gControls->tw->saveBitsMsgBox, gControls->tw->saveBitsMsg);
00203                             
00204                             // proxy settings button
00205                             gControls->tw->proxySettingsBtn = GetNewControl(rProxySettgBtn, gWPtr);
00206                             if (!gControls->tw->proxySettingsBtn)
00207                             {
00208                                    ErrorHandler(eMem, nil);
00209                                    return;
00210                             }
00211                             Str255 proxySettingsTitle;
00212                             GetResourcedString(proxySettingsTitle, rInstList, sProxySettings);
00213                             SetControlTitle(gControls->tw->proxySettingsBtn, proxySettingsTitle);
00214                             ShowControl(gControls->tw->proxySettingsBtn);
00215             }
00216               }
00217                             
00218               // populate control
00219               HLock(gControls->cfg->startMsg);
00220               TESetText(*gControls->cfg->startMsg, strlen(*gControls->cfg->startMsg), 
00221                                    gControls->tw->startMsg);
00222               HUnlock(gControls->cfg->startMsg);
00223        
00224               // show controls
00225               TEUpdate(&viewRect, gControls->tw->startMsg);
00226               ShowNavButtons( back, next );
00227        }
00228        
00229        SetPort(oldPort);
00230 }
00231 
00232 short
00233 GetRectFromRes(Rect *outRect, short inResID)
00234 {
00235     Handle rectH;
00236     short reserr;
00237     
00238     if (!outRect)
00239         return eParam;
00240         
00241        // get rect for save bits message
00242        rectH = Get1Resource('RECT', inResID);
00243        reserr = ResError();
00244        if (reserr == noErr && rectH != NULL)
00245        {
00246                *outRect  = (Rect) **((Rect **)rectH);
00247                DisposeHandle(rectH);
00248     }
00249        else
00250        {
00251               ErrorHandler(reserr, nil);
00252               return reserr;
00253        }
00254        
00255        return 0;
00256 }
00257 
00258 void
00259 UpdateTerminalWin(void)
00260 {
00261        GrafPtr       oldPort;
00262        int i;
00263        Rect   instMsgRect;
00264        GetPort(&oldPort);
00265        SetPort(gWPtr);
00266        
00267        if (!gInstallStarted)
00268        TEUpdate(&gControls->tw->startMsgBox, gControls->tw->startMsg);
00269 
00270     if (gControls->tw->dlProgressBar)
00271     {
00272         for (i = 0; i < kNumDLFields; ++i)
00273         {
00274             if (gControls->tw->dlLabels[i])
00275             {
00276                 ShowControl(gControls->tw->dlLabels[i]);
00277             }
00278         }
00279 
00280         // XXX   TO DO
00281         // update the dl TEs
00282     }
00283        else if (gControls->tw->allProgressMsg)
00284        {
00285               HLock((Handle)gControls->tw->allProgressMsg);
00286               SetRect(&instMsgRect, (*gControls->tw->allProgressMsg)->viewRect.left,
00287                             (*gControls->tw->allProgressMsg)->viewRect.top,
00288                             (*gControls->tw->allProgressMsg)->viewRect.right,
00289                             (*gControls->tw->allProgressMsg)->viewRect.bottom );
00290               HUnlock((Handle)gControls->tw->allProgressMsg);
00291               
00292               TEUpdate(&instMsgRect, gControls->tw->allProgressMsg);
00293        }
00294        else
00295        { 
00296            if (gControls->tw->saveBitsMsg)
00297            {
00298                TEUpdate(&gControls->tw->saveBitsMsgBox, gControls->tw->saveBitsMsg);
00299            }
00300        }
00301        
00302        SetPort(oldPort);
00303 }
00304 
00305 void 
00306 InTerminalContent(EventRecord* evt, WindowPtr wCurrPtr)
00307 {      
00308        Point                localPt;
00309        Rect                 r;
00310        ControlPartCode      part;
00311        ControlHandle currCntl;
00312        short                checkboxVal;
00313        GrafPtr                     oldPort;
00314        GetPort(&oldPort);
00315        
00316        SetPort(wCurrPtr);
00317        localPt = evt->where;
00318        GlobalToLocal( &localPt);
00319        
00320        if (gControls->tw->siteSelector)
00321        {
00322               HLock((Handle)gControls->tw->siteSelector);
00323               r = (**(gControls->tw->siteSelector)).contrlRect;
00324               HUnlock((Handle)gControls->tw->siteSelector);
00325               if (PtInRect(localPt, &r))
00326               {
00327                      part = FindControl(localPt, gWPtr, &currCntl);
00328                      part = TrackControl(currCntl, localPt, (ControlActionUPP) -1);
00329                      gControls->opt->siteChoice = GetControlValue(currCntl);
00330                      return;
00331               }             
00332        }
00333 
00334        if (gControls->tw->saveBitsCheckbox)
00335        {
00336               HLock((Handle)gControls->tw->saveBitsCheckbox);
00337               r = (**(gControls->tw->saveBitsCheckbox)).contrlRect;
00338               HUnlock((Handle)gControls->tw->saveBitsCheckbox);
00339               if (PtInRect(localPt, &r))
00340               {
00341                      part = FindControl(localPt, gWPtr, &currCntl);
00342                      part = TrackControl(currCntl, localPt, (ControlActionUPP) -1);
00343                      checkboxVal = GetControlValue(currCntl);
00344                      SetControlValue(currCntl, 1 - checkboxVal);
00345                      if (checkboxVal)  // was selected so now toggling off
00346                             gControls->opt->saveBits = false;
00347                      else                   // was not selected so now toggling on
00348                             gControls->opt->saveBits = true;
00349                      return;
00350               }
00351        }
00352 
00353     if (gControls->tw->proxySettingsBtn)
00354     {
00355         HLock((Handle)gControls->tw->proxySettingsBtn);
00356         r = (**(gControls->tw->proxySettingsBtn)).contrlRect;
00357         HUnlock((Handle)gControls->tw->proxySettingsBtn);
00358         if (PtInRect(localPt, &r))
00359         {
00360             part = TrackControl(gControls->tw->proxySettingsBtn, evt->where, NULL);
00361             if (part != 0)
00362                 OpenProxySettings();
00363             return;
00364         }
00365     }
00366                                    
00367        HLock((Handle)gControls->backB);
00368        SetRect(&r, (**(gControls->backB)).contrlRect.left,
00369                             (**(gControls->backB)).contrlRect.top,
00370                             (**(gControls->backB)).contrlRect.right,
00371                             (**(gControls->backB)).contrlRect.bottom);
00372        HUnlock((Handle)gControls->backB);
00373        if (PtInRect( localPt, &r))
00374        {
00375               part = TrackControl(gControls->backB, evt->where, NULL);
00376               if (part)
00377               {
00378                   /* before install has started */
00379                   if (gControls->state == eInstallNotStarted)
00380                   {
00381                      KillControls(gWPtr);
00382                      if (&gControls->tw->startMsgBox)
00383                      {
00384                             EraseRect(&gControls->tw->startMsgBox);
00385                             InvalRect(&gControls->tw->startMsgBox);
00386                      }
00387                      else
00388                      {
00389                             ErrorHandler(eParam, nil);  
00390                             return;
00391                      }
00392                      ClearSaveBitsMsg();
00393                      
00394                      /* treat last setup type  selection as custom */
00395                      if (gControls->opt->instChoice == gControls->cfg->numSetupTypes)
00396                      {
00397                             if (gControls->cfg->bAdditionsExist)
00398                                    ShowAdditionsWin();
00399                             else
00400                                    ShowComponentsWin();
00401                      }
00402                      else
00403                             ShowSetupTypeWin();
00404                      return;
00405             }
00406             
00407             /* pause button pressed */
00408             else if (gControls->state == eDownloading || gControls->state == eResuming)
00409             {
00410                 SetPausedState();
00411             }
00412               }
00413        }
00414                      
00415        HLock((Handle)gControls->nextB);          
00416        SetRect(&r, (**(gControls->nextB)).contrlRect.left,
00417                             (**(gControls->nextB)).contrlRect.top,
00418                             (**(gControls->nextB)).contrlRect.right,
00419                             (**(gControls->nextB)).contrlRect.bottom);       
00420        HUnlock((Handle)gControls->nextB);
00421        if (PtInRect( localPt, &r))
00422        {
00423               part = TrackControl(gControls->nextB, evt->where, NULL);
00424               if (part)
00425               {
00426             BeginInstall();
00427               }
00428        }
00429        
00430        SetPort(oldPort);
00431 }
00432 
00433 void 
00434 BeginInstall(void)
00435 {
00436     ThreadID tid;
00437 
00438     /* starting download first time or resume download */
00439     if (gControls->state == eInstallNotStarted || gControls->state == ePaused)
00440     {
00441         if (gControls->state == eInstallNotStarted)
00442         {
00443             SetupPauseResumeButtons();
00444             ClearDownloadSettings();
00445             gInstallStarted = true;
00446         }
00447         else if (gControls->state == ePaused)
00448             SetResumedState();
00449 
00450         SpawnSDThread(Install, &tid);
00451     }
00452 }
00453 
00454 void
00455 my_c2pstrcpy(const char *aCStr, Str255 aPStr)
00456 {
00457     if (!aCStr)
00458         return;
00459     
00460     memcpy(&aPStr[1], aCStr, strlen(aCStr) > 255 ? 255 : strlen(aCStr));
00461     aPStr[0] = strlen(aCStr);
00462 }
00463 
00464 #define rProxyHostItem 3
00465 #define rProxyPortItem 4
00466 #define rProxyUserItem 5
00467 #define rProxyPswdItem 6
00468 #define rProxyStrOK                1
00469 #define rProxyStrCancel            2
00470 #define rProxyStrHostLab    7
00471 #define rProxyStrPortLab    8
00472 #define rProxyStrUserLab    9
00473 #define rProxyStrPswdLab    10
00474  
00475 void
00476 OpenProxySettings(void)
00477 {
00478     short itemHit = 999;
00479     short itemType;
00480     Handle item;
00481     Rect itemBox;
00482     Str255 itemText, pswdBuf, blindPswdText;
00483     DialogPtr psDlg;
00484     Boolean bDefault = true;
00485     
00486     /* show dialog */
00487     psDlg = GetNewDialog(rDlgProxySettg, NULL, (WindowPtr) -1);
00488 
00489     /* show dialog title, button and lable from install.ini */
00490     GetResourcedString(itemText, rInstList, sProxyDlg);
00491     SetWTitle(psDlg, itemText);
00492     GetDialogItem(psDlg, rProxyStrOK, &itemType, &item, &itemBox);
00493     GetResourcedString(itemText, rInstList, sOKBtn);
00494     SetControlTitle((ControlRecord **)item, itemText);
00495     SetControlData((ControlRecord **)item, kControlNoPart, 
00496             kControlPushButtonDefaultTag, sizeof(bDefault),(Ptr) &bDefault);
00497     GetDialogItem(psDlg, rProxyStrCancel, &itemType, &item, &itemBox);
00498     GetResourcedString(itemText, rInstList, sCancel);
00499     SetControlTitle((ControlRecord **)item, itemText);
00500     GetDialogItem(psDlg, rProxyStrHostLab, &itemType, &item, &itemBox);
00501     GetResourcedString(itemText, rInstList, sProxyHost);
00502     SetDialogItemText(item, itemText);
00503     GetDialogItem(psDlg, rProxyStrPortLab, &itemType, &item, &itemBox);
00504     GetResourcedString(itemText, rInstList, sProxyPort);
00505     SetDialogItemText(item, itemText);
00506     GetDialogItem(psDlg, rProxyStrUserLab, &itemType, &item, &itemBox);
00507     GetResourcedString(itemText, rInstList, sProxyUsername);
00508     SetDialogItemText(item, itemText);
00509     GetDialogItem(psDlg, rProxyStrPswdLab, &itemType, &item, &itemBox);
00510     GetResourcedString(itemText, rInstList, sProxyPassword);
00511     SetDialogItemText(item, itemText);
00512 
00513     /* pre-populate text fields */
00514     if (gControls->opt->proxyHost)
00515     {
00516         my_c2pstrcpy(gControls->opt->proxyHost, itemText);
00517         GetDialogItem(psDlg, rProxyHostItem, &itemType, &item, &itemBox);
00518         SetDialogItemText(item, itemText);
00519     }
00520     
00521     if (gControls->opt->proxyPort)
00522     {
00523         my_c2pstrcpy(gControls->opt->proxyPort, itemText);
00524         GetDialogItem(psDlg, rProxyPortItem, &itemType, &item, &itemBox);
00525         SetDialogItemText(item, itemText);    
00526     }
00527     
00528     if (gControls->opt->proxyUsername)
00529     {
00530         my_c2pstrcpy(gControls->opt->proxyUsername, itemText);
00531         GetDialogItem(psDlg, rProxyUserItem, &itemType, &item, &itemBox);
00532         SetDialogItemText(item, itemText);    
00533     }
00534     
00535     if (gControls->opt->proxyPassword)
00536     {
00537         int pswdLen = strlen(gControls->opt->proxyPassword);
00538         memset(&blindPswdText[1], '', pswdLen);
00539         blindPswdText[0] = pswdLen;
00540         GetDialogItem(psDlg, rProxyPswdItem, &itemType, &item, &itemBox);
00541         SetDialogItemText(item, blindPswdText);    
00542     }
00543     
00544     if (gControls->opt->proxyPassword)
00545         my_c2pstrcpy(gControls->opt->proxyPassword, pswdBuf);
00546     else
00547         pswdBuf[0] = 0;
00548     do
00549     {
00550         ModalDialog(NULL, &itemHit);
00551         
00552         /* special handling for "blind" password field */
00553         if (itemHit == rProxyPswdItem)
00554         {
00555             GetDialogItem(psDlg, rProxyPswdItem, &itemType, &item, &itemBox);
00556             GetDialogItemText(item, itemText);
00557             
00558             /* char deleted ? */
00559             if (itemText[0] < pswdBuf[0])
00560             {
00561                 /* truncate password buffer */
00562                 pswdBuf[0] = itemText[0];
00563             }
00564             else
00565             {
00566                 /* store new char in password buffer */
00567                 pswdBuf[itemText[0]] = itemText[itemText[0]];
00568                 pswdBuf[0] = itemText[0];
00569             }
00570             
00571             memset(&blindPswdText[1], '', pswdBuf[0]);
00572             blindPswdText[0] = itemText[0];
00573             
00574             SetDialogItemText(item, blindPswdText);
00575         }
00576     } while(itemHit != 1 && itemHit != 2);
00577     
00578     /* if OK was hit then take changed settings */
00579     if (itemHit == 1)
00580     {
00581         GetDialogItem(psDlg, rProxyHostItem, &itemType, &item, &itemBox);
00582         GetDialogItemText(item, itemText);
00583         if (itemText[0] > 0)
00584         {
00585             if (gControls->opt->proxyHost)
00586                 free(gControls->opt->proxyHost);
00587             gControls->opt->proxyHost = (char *) malloc(itemText[0] + 1);
00588             strncpy(gControls->opt->proxyHost, (const char *)&itemText[1], itemText[0]);
00589             *(gControls->opt->proxyHost + itemText[0]) = 0;
00590         }
00591         
00592         GetDialogItem(psDlg, rProxyPortItem, &itemType, &item, &itemBox);
00593         GetDialogItemText(item, itemText);
00594         if (itemText[0] > 0)
00595         {
00596             if (gControls->opt->proxyPort)
00597                 free(gControls->opt->proxyPort);        
00598             gControls->opt->proxyPort = (char *) malloc(itemText[0] + 1);
00599             strncpy(gControls->opt->proxyPort, (const char *)&itemText[1], itemText[0]);
00600             *(gControls->opt->proxyPort + itemText[0]) = 0;
00601         }
00602             
00603         GetDialogItem(psDlg, rProxyUserItem, &itemType, &item, &itemBox);
00604         GetDialogItemText(item, itemText);
00605         if (itemText[0] > 0)
00606         {
00607             if (gControls->opt->proxyUsername)
00608                 free(gControls->opt->proxyUsername);        
00609             gControls->opt->proxyUsername = (char *) malloc(itemText[0] + 1);
00610             strncpy(gControls->opt->proxyUsername, (const char *)&itemText[1], itemText[0]);
00611             *(gControls->opt->proxyUsername + itemText[0]) = 0;
00612         }
00613             
00614         if (pswdBuf[0] > 0)
00615         {
00616             if (gControls->opt->proxyPassword)
00617                 free(gControls->opt->proxyPassword);        
00618             gControls->opt->proxyPassword = (char *) malloc(pswdBuf[0] + 1);
00619             strncpy(gControls->opt->proxyPassword, (const char *)&pswdBuf[1], pswdBuf[0]);
00620             *(gControls->opt->proxyPassword + pswdBuf[0]) = 0;
00621         }
00622     }
00623         
00624     DisposeDialog(psDlg);
00625 }
00626 
00627 Boolean
00628 SpawnSDThread(ThreadEntryProcPtr threadProc, ThreadID *tid)
00629 {
00630        OSErr                err;
00631        
00632        err = NewThread(kCooperativeThread, (ThreadEntryProcPtr)threadProc, (void*) nil, 
00633                                    0, kCreateIfNeeded, (void**)nil, tid);
00634                             //  ^---- 0 means gimme the default stack size from Thread Manager
00635        if (err == noErr)
00636               YieldToThread(*tid); /* force ctx switch */
00637        else
00638        {
00639               return false;
00640        }
00641        
00642        return true;
00643 }
00644 
00645 void
00646 ClearDownloadSettings(void)
00647 {
00648     GrafPtr oldPort;
00649     
00650     GetPort(&oldPort);
00651     if (gWPtr)
00652     {
00653         SetPort(gWPtr);
00654         
00655         if (gControls->tw->dlSettingsGB)
00656             DisposeControl(gControls->tw->dlSettingsGB);
00657             
00658        if (gControls->tw->startMsg)
00659             EraseRect(&gControls->tw->startMsgBox);
00660             
00661        if (gControls->tw->siteSelector)
00662               DisposeControl(gControls->tw->siteSelector);       
00663         if (gControls->tw->siteSelMsg)
00664             DisposeControl(gControls->tw->siteSelMsg);
00665                      
00666         if (gControls->tw->saveBitsMsg)
00667             EraseRect(&gControls->tw->saveBitsMsgBox);
00668         if (gControls->tw->saveBitsCheckbox)
00669             DisposeControl(gControls->tw->saveBitsCheckbox);
00670             
00671         if (gControls->tw->proxySettingsBtn)
00672             DisposeControl(gControls->tw->proxySettingsBtn);
00673     }
00674     
00675     SetPort(oldPort);            
00676 }
00677 
00678 void
00679 ClearSaveBitsMsg(void)
00680 {
00681     if (gControls->tw->saveBitsMsg)
00682         EraseRect(&gControls->tw->saveBitsMsgBox);
00683 }
00684 
00685 void
00686 EnableTerminalWin(void)
00687 {
00688     if (gControls->state == eInstallNotStarted)
00689     {
00690            EnableNavButtons();
00691        
00692        if (gControls->tw->siteSelector)
00693               HiliteControl(gControls->tw->siteSelector, kEnableControl);
00694        if (gControls->tw->saveBitsCheckbox)
00695            HiliteControl(gControls->tw->saveBitsCheckbox, kEnableControl);
00696         if (gControls->tw->proxySettingsBtn)
00697             HiliteControl(gControls->tw->proxySettingsBtn, kEnableControl);      
00698     }
00699     else if (gControls->state == eDownloading || gControls->state == eResuming)
00700     {
00701         if (gControls->nextB)
00702             HiliteControl(gControls->nextB, kDisableControl);       
00703         if (gControls->backB)
00704             HiliteControl(gControls->backB, kEnableControl);    
00705         if (gControls->cancelB)
00706             HiliteControl(gControls->cancelB, kDisableControl);
00707     }
00708     else if (gControls->state == ePaused)
00709     {
00710         if (gControls->nextB)
00711             HiliteControl(gControls->nextB, kEnableControl);       
00712         if (gControls->backB)
00713             HiliteControl(gControls->backB, kDisableControl); 
00714         if (gControls->cancelB)
00715             HiliteControl(gControls->cancelB, kDisableControl);    
00716     } 
00717 }
00718 
00719 void
00720 DisableTerminalWin(void)
00721 {
00722        DisableNavButtons();
00723 
00724        if (gControls->tw->siteSelector)
00725               HiliteControl(gControls->tw->siteSelector, kDisableControl);
00726        if (gControls->tw->saveBitsCheckbox)
00727            HiliteControl(gControls->tw->saveBitsCheckbox, kDisableControl);
00728     if (gControls->tw->proxySettingsBtn)
00729         HiliteControl(gControls->tw->proxySettingsBtn, kDisableControl);                
00730 }
00731 
00732 void
00733 SetupPauseResumeButtons(void)
00734 {
00735     Str255 pPauseLabel, pResumeLabel;
00736     
00737     /* rename labels to pause/resume */
00738     if (gControls->backB)
00739     {
00740        GetResourcedString(pPauseLabel, rInstList, sPauseBtn);
00741         SetControlTitle(gControls->backB, pPauseLabel); 
00742         ShowControl(gControls->backB);
00743     }
00744     
00745     if (gControls->nextB)
00746     {
00747            GetResourcedString(pResumeLabel, rInstList, sResumeBtn);
00748         SetControlTitle(gControls->nextB, pResumeLabel); 
00749         ShowControl(gControls->nextB);    
00750     }
00751     
00752     /* disable cancel button */
00753     if (gControls->cancelB)
00754         HiliteControl(gControls->cancelB, kDisableControl);
00755         
00756     /* disable pause button  */
00757     if (gControls->nextB)
00758         HiliteControl(gControls->nextB, kDisableControl);   
00759     
00760     /* enable resume button */
00761     if (gControls->backB)
00762         HiliteControl(gControls->backB, kEnableControl);    
00763 
00764     gControls->state = eDownloading;
00765 }
00766 
00767 void
00768 SetPausedState(void)
00769 {   
00770     /*  disable resume button */
00771     if (gControls->backB)
00772         HiliteControl(gControls->backB, kDisableControl);
00773     
00774     /* enable pause button */
00775     if (gControls->nextB)
00776         HiliteControl(gControls->nextB, kEnableControl);     
00777           
00778     gControls->state = ePaused;
00779 }
00780 
00781 void
00782 SetResumedState(void)
00783 {    
00784     /* disable pause button  */
00785     if (gControls->nextB)
00786         HiliteControl(gControls->nextB, kDisableControl);   
00787     
00788     /* enable resume button */
00789     if (gControls->backB)
00790         HiliteControl(gControls->backB, kEnableControl);
00791         
00792     gControls->state = eResuming;
00793 }
00794 
00795 void
00796 DisablePauseAndResume()
00797 {
00798     /* disable pause button  */
00799     if (gControls->nextB)
00800         HiliteControl(gControls->nextB, kDisableControl);   
00801     
00802     /* disable resume button */
00803     if (gControls->backB)
00804         HiliteControl(gControls->backB, kDisableControl);
00805 
00806 }