Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Attributes
Stream Class Reference

#include <Stream.h>

Inheritance diagram for Stream:
Inheritance graph
Collaboration diagram for Stream:
Collaboration graph

List of all members.

Public Member Functions

nsresult Init (Core *controller)
 If the class reads any prefs, it must happen here.
nsresult Download ()
nsresult Upload ()
nsresult DownUpLoad (PRBool download)

Protected Attributes

nsCString mRemoteBaseUrl
 Directory on server, where profile files are.
nsString mPassword
PRBool mSavePassword
 If we have to ask for a password, this is the default for the "save password" checkbox.
nsCOMPtr< nsIURImProfileDir
nsRegistryKey mRegkeyStream

Detailed Description

Definition at line 53 of file Stream.h.

Member Function Documentation

nsresult Stream::Download ( ) [virtual]

Implements Protocol.

Definition at line 165 of file Stream.cpp.

  return DownUpLoad(PR_TRUE);


Here is the call graph for this function:

Definition at line 176 of file Stream.cpp.

  nsresult rv = NS_OK;

  if (!mController)

  /* Design

  I'd really like to
  - open a few channels (one per file) here in this function,
  - attach |nsIProgressEventSink|s to each and
  - let a Progress dialog track/reflect the progress sinks.
  That way, I would have a generic dialog for the UI somewhere
  and the logic (transfer) here in this file, where it belongs.

  Unfortunately, this doesn't work. I have to
  block this function until the transfer is done, but have the transfer
  itself and the progress UI working. darin says, I will get threading
  issues then. He suggested to initiate the transfer from the dialog
  (because that dialog uses another event quene) and let the dialog
  close itself when the transfer is done. Here in this function, I can
  block until the dialog is dismissed.
  (At least, that's what I understood from darin.)
  That's what I do, and it seems to work. It's still a poor design.

  Actually, it's really crap. It destroys my whole design with the
  pluggable "method"s (like stream, copy etc.). Basically everything
  contacting remote servers (i.e. needing a progress dialog) now has to
  either mess around in sroamingTransfer.js or duplicate a certain
  portion of code.

  nsCOMPtr<nsIWindowWatcher> windowWatcher
              (do_GetService(";1", &rv));

  /* nsIDialogParamBlock is a method to pass ints and strings
     to and from XUL dialogs.
     To dialog (upon open)
       Int array
         Item 0: 1 = download, 2 = upload
         Item 1: 1 = serial (transfer one file after the other),
                 2 = parallel (start all file transfers at once)
         Item 2: Number of files (n below)
         Item 3: Save password (should pw be stored by default when asked?)
                 1 = true
                 0 = false
       String array
         Item 0: unused
         Item 1: URL of profile dir
         Item 2: URL of remote dir
         Item 3: Password
         Item 4..(n+3): filenames
     From dialog (upon close)
       Int array
         Item 0: 0 = do nothing
                 1 = Save Password (user checked the box in the prompt)
                 2 = Set SavePassword pref to false, ignore PW/Usern. retval
       String array
         Item 0: Saved username (as entered in the prompt)
         Item 1: Saved password (as entered in the prompt)
  nsCOMPtr<nsIDialogParamBlock> ioParamBlock
             (do_CreateInstance(";1", &rv));

  // download/upload
  ioParamBlock->SetInt(0, download ? 1 : 2);
  ioParamBlock->SetInt(1, 2);

  const nsCStringArray* files = mController->GetFilesToRoam();
  ioParamBlock->SetInt(2, files->Count());

  ioParamBlock->SetInt(3, mSavePassword ? 1 : 0);

  nsXPIDLCString profile;
  ioParamBlock->SetString(1, NS_ConvertUTF8toUTF16(profile).get());
  ioParamBlock->SetString(2, NS_ConvertUTF8toUTF16(mRemoteBaseUrl).get());
  ioParamBlock->SetString(3, mSavePassword
                          ? mPassword.get()
                          : EmptyString().get());

  // filenames
  for (PRInt32 i = files->Count() - 1; i >= 0; i--)
    NS_ConvertASCIItoUTF16 filename(*files->CStringAt(i));
    ioParamBlock->SetString(i + 4, filename.get());
                                                 // filenames start at item 4

  nsCOMPtr<nsIDOMWindow> window;
  rv = windowWatcher->OpenWindow(nsnull,

  PRInt32 savepw = 0;
  ioParamBlock->GetInt(0, &savepw);
  if (savepw == 1)
    nsXPIDLString password, username;
    ioParamBlock->GetString(0, getter_Copies(username));
    ioParamBlock->GetString(1, getter_Copies(password));

    mPassword = password;
    nsCOMPtr<nsIRegistry> registry;
    rv = mController->GetRegistry(registry);
    rv = registry->SetInt(mRegkeyStream, kRegKeySavePassword.get(),  1);
    rv = registry->SetString(mRegkeyStream, kRegKeyUsername.get(),
    rv = registry->SetString(mRegkeyStream, kRegKeyPassword.get(),
    // failure is not fatal. then it's not saved *shrug*. ;-)
  return NS_OK;

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Stream::Init ( Core ) [virtual]

If the class reads any prefs, it must happen here.

Implements Protocol.

Definition at line 75 of file Stream.cpp.

  nsresult rv;
  mController = aController;
  NS_ASSERTION(mController, "mController is null");

  // Get prefs
  nsCOMPtr<nsIRegistry> registry;
  rv = mController->GetRegistry(registry);

  nsRegistryKey regkey;
  rv = mController->GetRegistryTree(regkey);

  rv = registry->GetKey(regkey,

  mRegkeyStream = regkey;

  nsXPIDLString remoteUrlPref;
  rv = registry->GetString(regkey, kRegKeyURL.get(),

  mRemoteBaseUrl = NS_ConvertUTF16toUTF8(remoteUrlPref);

  /* For easier mass-personalisation via scripts in corporate setups and
     for easier instructed setup by normal users,
     we allow the username to be separate from the URL. */
  nsXPIDLString usernamePref;
  rv = registry->GetString(regkey, kRegKeyUsername.get(),
  if (NS_SUCCEEDED(rv) && !usernamePref.IsEmpty() )
    /* failure is non-fatal, because username might be in the URL, and
       even if it isn't, the transfer will pull up a prompt. */
    nsCOMPtr<nsIIOService> ioserv = do_GetService(kIOServiceCID, &rv);
    if (NS_SUCCEEDED(rv))
      nsCOMPtr<nsIURI> uri;
      rv = NS_NewURI(getter_AddRefs(uri), mRemoteBaseUrl);

      if (NS_SUCCEEDED(rv))
        rv = uri->SetUsername(NS_ConvertUTF16toUTF8(usernamePref));
        if (NS_SUCCEEDED(rv))
          // Yikes. Did I mention that I hate that C/wide string crap?
          nsXPIDLCString spec;
          mRemoteBaseUrl = spec;

  // we need a / at the end (base URL), fix up, if user error
  if (mRemoteBaseUrl.Last() != (PRUnichar) '/')
    mRemoteBaseUrl += (PRUnichar) '/';

  nsXPIDLString passwordPref;
  rv = registry->GetString(regkey, kRegKeyPassword.get(),
  /* failure is non-fatal, because if there's no password, the
     transfer will pull up a prompt. */
  mPassword = passwordPref;

  PRInt32 savepw = 0;
  rv = registry->GetInt(regkey, kRegKeySavePassword.get(),
  mSavePassword = savepw == 0 ? PR_FALSE : PR_TRUE;

  nsCOMPtr<nsIFile> profiledir;
  rv = mController->GetProfileDir(getter_AddRefs(profiledir));

  nsCOMPtr<nsIIOService> ioserv = do_GetService(kIOServiceCID, &rv);

  rv = NS_NewFileURI(getter_AddRefs(mProfileDir), profiledir);

  return NS_OK;

Here is the call graph for this function:

nsresult Stream::Upload ( ) [virtual]

Implements Protocol.

Definition at line 171 of file Stream.cpp.

  return DownUpLoad(PR_FALSE);

Here is the call graph for this function:

Member Data Documentation

Core* Protocol::mController [protected, inherited]

Definition at line 70 of file Protocol.h.

Definition at line 68 of file Stream.h.

Definition at line 74 of file Stream.h.

Definition at line 75 of file Stream.h.

Directory on server, where profile files are.

This is already with the concrete username.

Definition at line 67 of file Stream.h.

If we have to ask for a password, this is the default for the "save password" checkbox.

Definition at line 73 of file Stream.h.

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