Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsMsgCopyService Class Reference

#include <nsMsgCopyService.h>

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

List of all members.

Public Member Functions

 nsMsgCopyService ()
virtual ~nsMsgCopyService ()
void CopyMessages (in nsIMsgFolder srcFolder, in nsISupportsArray messages, in nsIMsgFolder dstFolder, in boolean isMove, in nsIMsgCopyServiceListener listener, in nsIMsgWindow msgWindow, in boolean allowUndo)
 
  

void CopyFolders (in nsISupportsArray folders, in nsIMsgFolder dstFolder, in boolean isMove, in nsIMsgCopyServiceListener listener, in nsIMsgWindow msgWindow)
 
  

void CopyFileMessage (in nsIFileSpec fileSpec, in nsIMsgFolder dstFolder, in nsIMsgDBHdr msgToReplace, in boolean isDraftOrTemplate, in unsigned long aMsgFlags, in nsIMsgCopyServiceListener listener, in nsIMsgWindow msgWindow)
void NotifyCompletion (in nsISupports aSupport, in nsIMsgFolder dstFolder, in nsresult result)
 Notify the message copy service that the destination folder has finished it's messages copying operation so that the copy service can continue copying the rest of the messages if there are more to copy with.

Private Member Functions

nsresult ClearRequest (nsCopyRequest *aRequest, nsresult rv)
nsresult DoCopy (nsCopyRequest *aRequest)
nsresult DoNextCopy ()
nsCopyRequestFindRequest (nsISupports *aSupport, nsIMsgFolder *dstFolder)
nsresult QueueRequest (nsCopyRequest *aRequest, PRBool *aCopyImmediately)

Private Attributes

nsVoidArray m_copyRequests

Detailed Description

Definition at line 97 of file nsMsgCopyService.h.


Constructor & Destructor Documentation

Definition at line 163 of file nsMsgCopyService.cpp.

{
}

Definition at line 167 of file nsMsgCopyService.cpp.

{

  PRInt32 i;
  nsCopyRequest* copyRequest;
  
  i = m_copyRequests.Count();

  while(i-- > 0)
  {
      copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
      ClearRequest(copyRequest, NS_ERROR_FAILURE);
  }
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsMsgCopyService::ClearRequest ( nsCopyRequest aRequest,
nsresult  rv 
) [private]

Definition at line 184 of file nsMsgCopyService.cpp.

{
  if (aRequest)
  {
    // Send notifications to nsIGlobalMsgFolderNotificationService
    
    if (aRequest->m_requestType == nsCopyFoldersType)
    {
      nsCOMPtr <nsIMsgFolderNotificationService> notifier = do_GetService(NS_MSGNOTIFICATIONSERVICE_CONTRACTID);
      if (notifier)
      {
        PRBool hasListeners;
        notifier->GetHasListeners(&hasListeners);
        if (hasListeners)
        {
          nsCOMPtr <nsISupportsArray> supportsArray = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID);
          if (supportsArray)
          {
            // Iterate over the copy sources and append their message arrays to this supports array
            // or in the case of folders, the source folder.
            PRInt32 cnt, i;
            cnt =  aRequest->m_copySourceArray.Count();
            for (i=0; i < cnt; i++)
            {
              nsCopySource *copySource = (nsCopySource*) aRequest->m_copySourceArray.ElementAt(i);
              supportsArray->AppendElement(copySource->m_msgFolder);
            }
            notifier->NotifyItemMoveCopyCompleted(aRequest->m_isMoveOrDraftOrTemplate, supportsArray, aRequest->m_dstFolder);
          }
        }
      }
    }
    
    // undo stuff
    if (aRequest->m_allowUndo && aRequest->m_copySourceArray.Count() > 1 && 
        aRequest->m_txnMgr)
        aRequest->m_txnMgr->EndBatch();
        
    m_copyRequests.RemoveElement(aRequest);
    if (aRequest->m_listener)
        aRequest->m_listener->OnStopCopy(rv);
    delete aRequest;
  }
  
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMsgCopyService::CopyFileMessage ( in nsIFileSpec  fileSpec,
in nsIMsgFolder  dstFolder,
in nsIMsgDBHdr  msgToReplace,
in boolean  isDraftOrTemplate,
in unsigned long  aMsgFlags,
in nsIMsgCopyServiceListener  listener,
in nsIMsgWindow  msgWindow 
) [inherited]
void nsIMsgCopyService::CopyFolders ( in nsISupportsArray  folders,
in nsIMsgFolder  dstFolder,
in boolean  isMove,
in nsIMsgCopyServiceListener  listener,
in nsIMsgWindow  msgWindow 
) [inherited]

  

void nsIMsgCopyService::CopyMessages ( in nsIMsgFolder  srcFolder,
in nsISupportsArray  messages,
in nsIMsgFolder  dstFolder,
in boolean  isMove,
in nsIMsgCopyServiceListener  listener,
in nsIMsgWindow  msgWindow,
in boolean  allowUndo 
) [inherited]

  

nsresult nsMsgCopyService::DoCopy ( nsCopyRequest aRequest) [private]

Definition at line 265 of file nsMsgCopyService.cpp.

{
  NS_ENSURE_ARG(aRequest);
  PRBool copyImmediately;
  QueueRequest(aRequest, &copyImmediately);
  m_copyRequests.AppendElement((void*) aRequest);
  if (copyImmediately) // if there wasn't another request for this dest folder then we can copy immediately
    return DoNextCopy();

  return NS_OK;
}

Here is the call graph for this function:

Definition at line 278 of file nsMsgCopyService.cpp.

{
  nsresult rv = NS_OK;
  nsCopyRequest* copyRequest = nsnull;
  nsCopySource* copySource = nsnull;
  PRInt32 i, j, cnt, scnt;

  cnt = m_copyRequests.Count();
  if (cnt > 0)
  {
    nsCOMArray<nsIMsgFolder> activeTargets;

    // ** jt -- always FIFO
    for (i=0; i < cnt; i++)
    {
      copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
      copySource = nsnull;
      scnt = copyRequest->m_copySourceArray.Count();
      if (!copyRequest->m_processed)
      {
        // if the target folder of this request already has an active 
        // copy request, skip this request for now.
        if (activeTargets.IndexOfObject(copyRequest->m_dstFolder) != kNotFound)
        {
          copyRequest = nsnull;
          continue;
        }
        if (scnt <= 0) goto found; // must be CopyFileMessage
        for (j=0; j < scnt; j++)
        {
          copySource = (nsCopySource*) copyRequest->m_copySourceArray.ElementAt(j);
          if (!copySource->m_processed)
            goto found;
        }
        if (j >= scnt) // all processed set the value
          copyRequest->m_processed = PR_TRUE;
      }
      else // keep track of folders actively getting copied to.
        activeTargets.AppendObject(copyRequest->m_dstFolder);
    }
    found:
      if (copyRequest && !copyRequest->m_processed)
      {
          if (copyRequest->m_listener)
              copyRequest->m_listener->OnStartCopy();
          if (copyRequest->m_requestType == nsCopyMessagesType &&
              copySource)
          {
              copySource->m_processed = PR_TRUE;
              rv = copyRequest->m_dstFolder->CopyMessages
                  (copySource->m_msgFolder, copySource->m_messageArray,
                   copyRequest->m_isMoveOrDraftOrTemplate,
                   copyRequest->m_msgWindow, copyRequest->m_listener, PR_FALSE, copyRequest->m_allowUndo);   //isFolder operation PR_FALSE
                                                              
          }
          else if (copyRequest->m_requestType == nsCopyFoldersType )
          {
              copySource->m_processed = PR_TRUE;
              rv = copyRequest->m_dstFolder->CopyFolder
                  (copySource->m_msgFolder,
                   copyRequest->m_isMoveOrDraftOrTemplate,
                   copyRequest->m_msgWindow, copyRequest->m_listener);
              // If it's a copy folder operation and the destination
              // folder already exists, CopyFolder() returns an error w/o sending
              // a completion notification, so clear it here.
              if (NS_FAILED(rv))
                ClearRequest(copyRequest, rv);

          }
          else if (copyRequest->m_requestType == nsCopyFileMessageType)
          {
            nsCOMPtr<nsIFileSpec> aSpec(do_QueryInterface(copyRequest->m_srcSupport, &rv));
            if (NS_SUCCEEDED(rv))
            {
                // ** in case of saving draft/template; the very first
                // time we may not have the original message to replace
                // with; if we do we shall have an instance of copySource
                nsCOMPtr<nsIMsgDBHdr> aMessage;
                if (copySource)
                {
                    aMessage = do_QueryElementAt(copySource->m_messageArray,
                                                 0, &rv);
                    copySource->m_processed = PR_TRUE;
                }
                copyRequest->m_processed = PR_TRUE;
                rv = copyRequest->m_dstFolder->CopyFileMessage
                    (aSpec, aMessage,
                     copyRequest->m_isMoveOrDraftOrTemplate,
                     copyRequest->m_newMsgFlags,
                     copyRequest->m_msgWindow,
                     copyRequest->m_listener);
            }
          }
      }
    }
    return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsCopyRequest * nsMsgCopyService::FindRequest ( nsISupports *  aSupport,
nsIMsgFolder dstFolder 
) [private]

Definition at line 377 of file nsMsgCopyService.cpp.

{
  nsCopyRequest* copyRequest = nsnull;
  PRInt32 cnt, i;

  cnt = m_copyRequests.Count();
  for (i=0; i < cnt; i++)
  {
    copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
    if (copyRequest->m_requestType == nsCopyFoldersType)
    {
        // If the src is different then check next request. 
        if (copyRequest->m_srcSupport.get() != aSupport)
        {
          copyRequest = nsnull;
          continue;
        }

        // See if the parent of the copied folder is the same as the one when the request was made.
        // Note if the destination folder is already a server folder then no need to get parent.
        nsCOMPtr <nsIMsgFolder> parentMsgFolder;
        nsresult rv = NS_OK;
        PRBool isServer=PR_FALSE;
        dstFolder->GetIsServer(&isServer);
        if (!isServer)
          rv = dstFolder->GetParentMsgFolder(getter_AddRefs(parentMsgFolder));
        if ((NS_FAILED(rv)) || (!parentMsgFolder && !isServer) || (copyRequest->m_dstFolder.get() != parentMsgFolder))
        {
          copyRequest = nsnull;
          continue;
        }

        // Now checks if the folder name is the same.
        nsXPIDLString folderName;
        rv = dstFolder->GetName(getter_Copies(folderName));
        if (NS_FAILED(rv))
        {
          copyRequest = nsnull;
          continue;
        }

        if (copyRequest->m_dstFolderName == folderName)
          break;
    }
    else if (copyRequest->m_srcSupport.get() == aSupport &&
        copyRequest->m_dstFolder.get() == dstFolder)
        break;
    else
        copyRequest = nsnull;
  }

  return copyRequest;
}

Here is the call graph for this function:

void nsIMsgCopyService::NotifyCompletion ( in nsISupports  aSupport,
in nsIMsgFolder  dstFolder,
in nsresult  result 
) [inherited]

Notify the message copy service that the destination folder has finished it's messages copying operation so that the copy service can continue copying the rest of the messages if there are more to copy with.

aSupport and dstFolder uniquely identify a copy service request.

aSupport -- the originator of CopyMessages or CopyFileMessage; it can be either a nsIMsgFolder or a nsIFileSpec dstFolder -- the destination folder which performs the copy operation result -- the result of the copy operation

nsresult nsMsgCopyService::QueueRequest ( nsCopyRequest aRequest,
PRBool aCopyImmediately 
) [private]

Definition at line 232 of file nsMsgCopyService.cpp.

{
  NS_ENSURE_ARG_POINTER(aRequest);
  NS_ENSURE_ARG_POINTER(aCopyImmediately);
  *aCopyImmediately = PR_TRUE;
  nsCopyRequest* copyRequest;

  PRInt32 cnt, i;
  cnt = m_copyRequests.Count();
  for (i=0; i < cnt; i++)
  {
    copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
    if (aRequest->m_requestType == nsCopyFoldersType)
    {
      // For copy folder, see if both destination folder (root)
      // (ie, Local Folder) and folder name (ie, abc) are the same.
      if (copyRequest->m_dstFolderName == aRequest->m_dstFolderName &&
          copyRequest->m_dstFolder.get() == aRequest->m_dstFolder.get())
      {
        *aCopyImmediately = PR_FALSE;
        break;
      }
    }
    else if (copyRequest->m_dstFolder.get() == aRequest->m_dstFolder.get())  //if dst are same and we already have a request, we cannot copy immediately
    {
      *aCopyImmediately = PR_FALSE;
      break;
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 115 of file nsMsgCopyService.h.


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