Back to index

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

#include <Copy.h>

Inheritance diagram for Copy:
Inheritance graph
[legend]
Collaboration diagram for Copy:
Collaboration graph
[legend]

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 ()

Protected Member Functions

nsresult DownUpLoad (PRBool download)

Protected Attributes

nsCOMPtr< nsIFilemRemoteDir
nsCOMPtr< nsIFilemProfileDir
CoremController

Detailed Description

Definition at line 55 of file Copy.h.


Member Function Documentation

nsresult Copy::Download ( ) [virtual]

Implements Protocol.

Definition at line 139 of file Copy.cpp.

{
  return DownUpLoad(PR_TRUE);
}

Here is the call graph for this function:

nsresult Copy::DownUpLoad ( PRBool  download) [protected]

Definition at line 149 of file Copy.cpp.

{
  nsresult rv = NS_OK;

  const nsCStringArray* files = mController->GetFilesToRoam();

  // Check for conflicts
  nsCStringArray conflicts(10);
  nsCStringArray copyfiles(10);
  PRInt32 i;
  for (i = files->Count() - 1; i >= 0; i--)
  {
    nsCString& file = *files->CStringAt(i);
    NS_ConvertASCIItoUTF16 fileL(file);

    nsCOMPtr<nsIFile> profileFile;
    rv = mProfileDir->Clone(getter_AddRefs(profileFile));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = profileFile->Append(fileL);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIFile> remoteFile;
    rv = mRemoteDir->Clone(getter_AddRefs(remoteFile));
    NS_ENSURE_SUCCESS(rv, rv);

    rv = remoteFile->Append(fileL);
    NS_ENSURE_SUCCESS(rv, rv);

    // avoid conflicts for missing files
    PRBool remoteExists = PR_TRUE;
    PRBool profileExists = PR_TRUE;
    remoteFile->Exists(&remoteExists);
    profileFile->Exists(&profileExists);
    if (download)
    {
      if (!remoteExists)
        continue;

      if (!profileExists) {
        copyfiles.AppendCString(file);
        continue;
        /* actually, this code is not needed given how the last modified
           code below works, but for readability and just in case... */
      }
    }
    else
    {
      if (!profileExists)
        continue;

      if (!remoteExists) {
        copyfiles.AppendCString(file);
        continue;
      }
    }

    PRInt64 profileTime = 0;
    PRInt64 remoteTime = 0;
    profileFile->GetLastModifiedTime(&profileTime);
    remoteFile->GetLastModifiedTime(&remoteTime);

    // do we have a conflict?
    if (download
        ? profileTime > remoteTime
        : profileTime < remoteTime )
      conflicts.AppendCString(file);
    else
      copyfiles.AppendCString(file);
  }

  // Ask user about conflicts
  nsCStringArray copyfiles_conflicts(10);
  rv = mController->ConflictResolveUI(download, conflicts,
                                      &copyfiles_conflicts);
  NS_ENSURE_SUCCESS(rv, rv);

  AppendElementsToStrArray(copyfiles, copyfiles_conflicts);

  // Copy
  for (i = copyfiles.Count() - 1; i >= 0; i--)
  {
    const nsCString& file = *copyfiles.CStringAt(i);
    NS_ConvertASCIItoUTF16 fileL(file);
    if (download)
      rv = CopyFile(mRemoteDir, mProfileDir, fileL);
    else
      rv = CopyFile(mProfileDir, mRemoteDir, fileL);
  }

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult Copy::Init ( Core ) [virtual]

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

Implements Protocol.

Definition at line 97 of file Copy.cpp.

{
  nsresult rv;
  mController = aController;
  if (!mController)
    return NS_ERROR_INVALID_ARG;

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

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

  rv = registry->GetKey(regkey,
                        kRegTreeCopy.get(),
                        &regkey);
  NS_ENSURE_SUCCESS(rv, rv);

  nsXPIDLString remoteDirPref;
  rv = registry->GetString(regkey, kRegKeyRemote.get(),
                           getter_Copies(remoteDirPref));
  NS_ENSURE_SUCCESS(rv, rv);

  nsCOMPtr<nsILocalFile> lf;
  rv = NS_NewLocalFile(remoteDirPref, PR_FALSE,
                       getter_AddRefs(lf));
  NS_ENSURE_SUCCESS(rv, rv);
  
  mRemoteDir = lf;

  rv = mController->GetProfileDir(getter_AddRefs(mProfileDir));
  NS_ENSURE_SUCCESS(rv, rv);

  if (!mProfileDir)
    return NS_ERROR_FILE_NOT_FOUND;

  return NS_OK;
}

Here is the call graph for this function:

nsresult Copy::Upload ( ) [virtual]

Implements Protocol.

Definition at line 144 of file Copy.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 65 of file Copy.h.

Definition at line 64 of file Copy.h.


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