Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes
PageGrabber Class Reference
Collaboration diagram for PageGrabber:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 PageGrabber ()
 ~PageGrabber ()
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
nsresult 
Init (nsILocalFile *aDirectory)
nsresult Grab (const nsAFlatCString &aURL)

Protected Member Functions

nsILocalFileNextFile (const char *aExtension)

Protected Attributes

nsILocalFilemDirectory
PRInt32 mFileNum

Detailed Description

Definition at line 172 of file grabpage.cpp.


Constructor & Destructor Documentation

Definition at line 190 of file grabpage.cpp.

{
}

Definition at line 194 of file grabpage.cpp.

{
}

Member Function Documentation

Definition at line 219 of file grabpage.cpp.

{
  nsresult rv;
  // Create the Event Queue for this thread...
  // Unix needs this
  nsCOMPtr<nsIEventQueueService> eventQService =
           do_GetService(kEventQueueServiceCID, &rv);
  if (NS_FAILED(rv)) return rv;

  eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);

  nsCOMPtr<nsILocalFile> file = NextFile("html");
  if (!file) {
    return NS_ERROR_OUT_OF_MEMORY;
  }
  FILE* fp;
  rv = file->OpenANSIFileDesc("wb", &fp);
  if (NS_FAILED(rv)) {
    return rv;
  }
  printf("Copying ");
  fputs(aURL.get(), stdout);
  nsAutoString path;
  file->GetPath(path);
  NS_ConvertUCS2toUTF8 cpath(path);
  printf(" to %s\n", cpath.get());

  // Create the URL object...
  nsCOMPtr<nsIURI> url;

  nsCOMPtr<nsIIOService> ioService(do_GetService(kIOServiceCID, &rv));
  if (NS_FAILED(rv)) return rv;

  rv = ioService->NewURI(aURL, nsnull, nsnull, getter_AddRefs(url));
  nsIChannel *channel = nsnull;
  rv = ioService->NewChannelFromURI(url, &channel);
  if (NS_FAILED(rv)) return rv;

  // Start the URL load...
  StreamToFile* copier = new StreamToFile(fp);
  if (!copier)
    return NS_ERROR_OUT_OF_MEMORY;

  NS_ADDREF(copier);

  rv = channel->AsyncOpen(copier, nsnull);

  if (NS_FAILED(rv)) {
    NS_RELEASE(copier);
    return rv;
  }
    
  // Enter the message pump to allow the URL load to proceed.
  while ( !copier->IsDone() ) {
    PLEvent *gEvent;
    gEventQ->WaitForEvent(&gEvent);
    gEventQ->HandleEvent(gEvent);
  }

  rv = copier->HaveError() ? NS_ERROR_FAILURE : NS_OK;
  NS_RELEASE(copier);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 199 of file grabpage.cpp.

{
  mDirectory = aDirectory;
  return NS_OK;
}

Here is the caller graph for this function:

nsILocalFile * PageGrabber::NextFile ( const char *  aExtension) [protected]

Definition at line 206 of file grabpage.cpp.

{
  nsCAutoString name(NS_LITERAL_CSTRING("grab."));
  name += nsDependentCString(aExtension);
  nsIFile *cfile;
  mDirectory->Clone(&cfile);
  nsCOMPtr<nsILocalFile> file = do_QueryInterface(cfile);
  file->AppendRelativeNativePath(name);
  file->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0660);
  return file;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 186 of file grabpage.cpp.

Definition at line 187 of file grabpage.cpp.


The documentation for this class was generated from the following file: