home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / turlwind.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  5.5 KB  |  195 lines

  1. //    Copyright (c) 1993, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TURLWindow
  4. //    Include File:    turlwind.h
  5. //    Purpose:    Provide a window for a URL
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        12-27-93    created
  9. //        02-09-94    Split all members into seperate files.
  10. #include"turlwind.h"
  11. #include"urltodos.h"
  12. #include"trace.h"
  13. #include<string.h>
  14.  
  15. void TURLWindow::URLoader(const char *cp_URL, const char *cp_Index)    {
  16. //    Purpose:    Load a URL in a standard manner.
  17. //    Arguments:    cp_URL        the next url to load.
  18. //            cp_Index    Will be NULL unless trying to load
  19. //                    and search request, say to a CSO
  20. //                    server.
  21. //    Return Value:    void
  22. //    Remarks/Portability/Dependencies/Restrictions:
  23. //        Should be called whenever the window needs to load a url.
  24. //        Will destroy an older URL view if it exists.
  25. //    Revision History:
  26. //        01-31-94    created
  27. //        03-30-94    Will no longer notify the user in this
  28. //                function if a document was unable to load.
  29. //        04-07-94    Modified to load an error file on no loads.
  30. //                Will definately hang if the user didn't
  31. //                specify the errorhtml in the config file.
  32.  
  33.     //    Save the name, might get destroyed.
  34.     //    Will not free this since will be in a collection.
  35.     auto char *cp_load = newStr(cp_URL);
  36.  
  37.     //    If this is an index search.
  38.     if(cp_Index != NULL)    {
  39.         //    cut out any searching done in this older url.
  40.         auto char *cp_nosearch = strchr(cp_load, '?');
  41.         if(cp_nosearch != NULL)    {
  42.             *cp_nosearch = '\0';
  43.             cp_nosearch = newStr(cp_load);
  44.             delete(cp_load);
  45.             cp_load = cp_nosearch;
  46.         }
  47.     }
  48.  
  49.     //    First the message.
  50.     doslynxmessage("Loading " << cp_load << (cp_Index == NULL ? "" : "?")
  51.         << (cp_Index == NULL ? "" : cp_Index));
  52.  
  53.     //    Disable the search command until something enables it.
  54.     disableCommand(cmSearchIndex);
  55.  
  56.     //    Get the window size and adjust for a view.
  57.     TRect TR = getExtent();
  58.     TR.grow(-1, -1);
  59.  
  60.     //    If we have a current view, save pointer to get rid of it.
  61.     auto TURLView *TURLVp_old = TURLV;
  62.  
  63.     //    Create the view.
  64.     TURLV = new TURLView(TR, standardScrollBar(
  65.         sbHorizontal | sbHandleKeyboard), standardScrollBar(
  66.         sbVertical | sbHandleKeyboard), cp_load, cp_Index);
  67.  
  68.     //    If the creation is valid.
  69.     if(TURLV != NULL && TURLV->valid(cmValid) == True)    {
  70.         //    If not the same document, change title here.
  71.         if(title != NULL)
  72.             delete((void *)title);
  73.         title = newStr(TURLV->getTitle());
  74.  
  75.         //    If there isn't a title, provide one.
  76.         if(title == NULL)    {
  77.             title = newStr("Untitled");
  78.         }
  79.  
  80.         //    Insert the new url title in our visited stack.
  81.         //    Be sure and check to see if it was a search.
  82. #ifndef RELEASE
  83.         trace("inserting loaded document into window history.");
  84. #endif // RELEASE
  85.         if(cp_Index == NULL)    {
  86.             TNSCp_visited->insert((void *)cp_load);
  87.         }
  88.         else    {
  89.             //    Remove any other search strings before.
  90.             auto char *cp_delsearch = strchr(cp_load, '?');
  91.             if(cp_delsearch != NULL)    {
  92.                 *cp_delsearch = '\0';
  93.             }
  94.             //    Create the string to insert.
  95.             auto char *cp_loadandsearch = new char[strlen(cp_load)
  96.                 + strlen(cp_Index) + 2];
  97.             //    Copy over the information.
  98.             strcpy(cp_loadandsearch, cp_load);
  99.             strcat(cp_loadandsearch, "?");
  100.             strcat(cp_loadandsearch, cp_Index);
  101.             //    Remove the old name.
  102.             delete(cp_load);
  103.             //    Insert it.
  104.             TNSCp_visited->insert((void *)cp_loadandsearch);
  105.         }
  106.  
  107.         //    Remove the old view from the window now.
  108. #ifndef RELEASE
  109.         trace("swapping views.");
  110. #endif // RELEASE
  111.         if(TURLVp_old != NULL)    {
  112.             remove(TURLVp_old);
  113.             destroy(TURLVp_old);
  114.         }
  115.  
  116.         //    Insert the view in the window and bring this window
  117.         //    to the front.
  118.         insert(TURLV);
  119.         makeFirst();
  120.  
  121.         //    See if the the new view is an index.  If so, set
  122.         //    so that we will know in the future.
  123.         if(TURLV->isIndex() == True)    {
  124.             IndexInit();
  125.         }
  126.         else    {
  127.             //    Otherwise set the index to false.
  128.             B_isIndex = False;
  129.             disableCommand(cmSearchIndex);
  130.         }
  131.     }
  132.     else    {
  133.         //    Do not insert the attempted URL in the window's
  134.         //    history.
  135.         delete(cp_load);
  136.  
  137.         //    Here's the catch.  On a file download we will get to
  138.         //    this code anyhow.  Check for it.  If so, we only want
  139.         //    to put back up the old view.
  140.         if(TURLV != NULL && TURLV->isDownload() == True)    {
  141. #ifndef RELEASE
  142.             trace("download detected.");
  143. #endif // RELEASE
  144.             //    Bring us up to the front.
  145.             makeFirst();
  146.  
  147.             //    Destroy the view that downloaded.
  148. #ifndef RELEASE
  149.             trace("attempting to destory downloading view.");
  150. #endif // RELEASE
  151.             destroy(TURLV);
  152.  
  153.             //    Reinstate the old view.
  154.             TURLV = TURLVp_old;
  155.  
  156.             //    Worst case scenario, there is no view....
  157.             //    Attempt to close the window.
  158.             if(TURLV == NULL)    {
  159.                 OwnerClose();
  160.             }
  161.             return;
  162.         }
  163. #ifndef RELEASE
  164.         trace("attempting to destroy failed load.");
  165. #endif // RELEASE
  166.         //    If a view was actually created, get rid of it.
  167.         if(TURLV != NULL)    {
  168.             destroy(TURLV);
  169.         }
  170.         TURLV = TURLVp_old;
  171.  
  172.         //    Load up our Error HTML file.
  173.         //    First convert to a URL, then call recusively.
  174. #ifndef RELEASE
  175.         trace("loading error html local file.");
  176. #endif // RELEASE
  177.         auto char *cp_Errorfile = new char[strlen(::cp_ErrorHTML) +
  178.             (cp_inipath != NULL) ? strlen(::cp_inipath) : 0 + 2];
  179.         if(cp_inipath != NULL)    {
  180.             strcpy(cp_Errorfile, cp_inipath);
  181.             strcat(cp_Errorfile, "\\");
  182.         }
  183.         else    {
  184.             *cp_Errorfile = '\0';
  185.         }
  186.         strcat(cp_Errorfile, cp_ErrorHTML);
  187.         auto char ca_errorURL[usi_TILURLSize];
  188.         dostourl(ca_errorURL, cp_Errorfile);
  189.         delete(cp_Errorfile);
  190.  
  191.         //    Recursive call will destroy the current view if one
  192.         //    exists.
  193.         URLoader(ca_errorURL);
  194.     }
  195. }