This commit is contained in:
putterman%netscape.com 1999-05-26 23:47:01 +00:00
Родитель 3437a3de76
Коммит ad215426f7
4 изменённых файлов: 93 добавлений и 74 удалений

Просмотреть файл

@ -497,11 +497,12 @@ NS_IMETHODIMP nsMsgFolderDataSource::OnItemRemoved(nsIFolder *parentFolder, nsIS
{
nsresult rv;
nsCOMPtr<nsIMessage> message;
nsCOMPtr<nsIMsgFolder> folder;
nsCOMPtr<nsIRDFResource> parentResource;
if(NS_SUCCEEDED(parentFolder->QueryInterface(nsIRDFResource::GetIID(), getter_AddRefs(parentResource))))
{
//If we are adding a message
//If we are removing a message
if(NS_SUCCEEDED(item->QueryInterface(nsIMessage::GetIID(), getter_AddRefs(message))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
@ -511,6 +512,16 @@ NS_IMETHODIMP nsMsgFolderDataSource::OnItemRemoved(nsIFolder *parentFolder, nsIS
NotifyObservers(parentResource, kNC_MessageChild, itemNode, PR_FALSE);
}
}
//If we are removing a folder
else if(NS_SUCCEEDED(item->QueryInterface(nsIMsgFolder::GetIID(), getter_AddRefs(folder))))
{
nsCOMPtr<nsIRDFNode> itemNode(do_QueryInterface(item, &rv));
if(NS_SUCCEEDED(rv))
{
//Notify folders that a message was deleted.
NotifyObservers(parentResource, kNC_Child, itemNode, PR_FALSE);
}
}
}
return NS_OK;
}
@ -740,11 +751,11 @@ nsresult nsMsgFolderDataSource::DoDeleteFromFolder(nsIMsgFolder *folder, nsISupp
if (cnt > 0)
rv = folder->DeleteMessages(messageArray);
/* rv = folderArray->Count(&cnt);
rv = folderArray->Count(&cnt);
if (NS_FAILED(rv)) return rv;
if (cnt > 0)
rv = folder->DeleteSubFolders(folderArray);
*/
return rv;
}

Просмотреть файл

@ -48,8 +48,8 @@ nsMsgFolder::nsMsgFolder(void)
mName(""),
mFlags(0),
mParent(nsnull),
mNumUnreadMessages(0),
mNumTotalMessages(0),
mNumUnreadMessages(-1),
mNumTotalMessages(-1),
mCsid(0),
mDepth(0),
mPrefFlags(0)
@ -454,7 +454,25 @@ NS_IMETHODIMP nsMsgFolder::Delete ()
return NS_OK;
}
NS_IMETHODIMP nsMsgFolder::PropagateDelete(nsIMsgFolder **folder, PRBool deleteStorage)
NS_IMETHODIMP nsMsgFolder::DeleteSubFolders(nsISupportsArray *folders)
{
nsresult rv;
PRUint32 count;
rv = folders->Count(&count);
nsCOMPtr<nsIMsgFolder> folder;
for(PRUint32 i = 0; i < count; i++)
{
nsCOMPtr<nsISupports> supports = getter_AddRefs(folders->ElementAt(i));
folder = do_QueryInterface(supports);
if(folder)
PropagateDelete(folder, PR_TRUE);
}
return rv;
}
NS_IMETHODIMP nsMsgFolder::PropagateDelete(nsIMsgFolder *folder, PRBool deleteStorage)
{
nsresult status = NS_OK;
@ -462,44 +480,38 @@ NS_IMETHODIMP nsMsgFolder::PropagateDelete(nsIMsgFolder **folder, PRBool deleteS
// first, find the folder we're looking to delete
PRUint32 cnt;
nsresult rv = mSubFolders->Count(&cnt);
if (NS_FAILED(rv)) return rv;
for (PRUint32 i = 0; i < cnt && *folder; i++)
nsresult rv = mSubFolders->Count(&cnt);
if (NS_FAILED(rv)) return rv;
for (PRUint32 i = 0; i < cnt; i++)
{
nsCOMPtr<nsISupports> supports = getter_AddRefs(mSubFolders->ElementAt(i));
child = do_QueryInterface(supports, &status);
if(NS_SUCCEEDED(status))
{
if (folder == child.get())
{
if (*folder == child.get())
{
// maybe delete disk storage for it, and its subfolders
status = child->RecursiveDelete(deleteStorage);
// maybe delete disk storage for it, and its subfolders
status = child->RecursiveDelete(deleteStorage);
if (status == NS_OK)
{
#ifdef HAVE_MASTER
PR_ASSERT(mMaster);
// Send out a broadcast message that this folder is going away.
// Many important things happen on this broadcast.
mMaster->BroadcastFolderDeleted (child);
#endif
mSubFolders->RemoveElement(child);
}
}
else
if (status == NS_OK)
{
PRUint32 folderDepth, childDepth;
if(NS_SUCCEEDED((*folder)->GetDepth(&folderDepth)) &&
NS_SUCCEEDED(child->GetDepth(&childDepth)) &&
folderDepth > childDepth)
{
status = child->PropagateDelete (folder, deleteStorage);
}
//Remove from list of subfolders.
mSubFolders->RemoveElement(child);
//Remove self as parent
child->SetParent(nsnull);
nsCOMPtr<nsISupports> childSupports(do_QueryInterface(child));
if(childSupports)
NotifyItemDeleted(childSupports);
break;
}
}
else
{
status = child->PropagateDelete (folder, deleteStorage);
}
}
}
return status;
}
@ -524,14 +536,13 @@ NS_IMETHODIMP nsMsgFolder::RecursiveDelete(PRBool deleteStorage)
if(NS_SUCCEEDED(status))
{
status = child->RecursiveDelete(deleteStorage); // recur
#ifdef HAVE_MASTER
// Send out a broadcast message that this folder is going away.
// Many important things happen on this broadcast.
mMaster->BroadcastFolderDeleted (child);
#endif
mSubFolders->RemoveElement(child); // unlink it from this's child list
child->SetParent(nsnull);
nsCOMPtr<nsISupports> childSupports(do_QueryInterface(child));
if(childSupports)
NotifyItemDeleted(childSupports);
}
cnt--;
}
// now delete the disk storage for _this_
@ -728,7 +739,7 @@ NS_IMETHODIMP nsMsgFolder::GetTotalMessages(PRBool deep, PRInt32 *totalMessages)
return NS_ERROR_NULL_POINTER;
nsresult rv;
PRUint32 total = mNumTotalMessages;
PRInt32 total = mNumTotalMessages;
if (deep)
{
nsCOMPtr<nsIMsgFolder> folder;

Просмотреть файл

@ -129,7 +129,8 @@ public:
NS_IMETHOD OnCloseFolder();
NS_IMETHOD Delete();
NS_IMETHOD PropagateDelete(nsIMsgFolder **folder, PRBool deleteStorage);
NS_IMETHOD DeleteSubFolders(nsISupportsArray *folders);
NS_IMETHOD PropagateDelete(nsIMsgFolder *folder, PRBool deleteStorage);
NS_IMETHOD RecursiveDelete(PRBool deleteStorage); // called by PropagateDelete
NS_IMETHOD CreateSubfolder(const char *folderName);

Просмотреть файл

@ -43,6 +43,7 @@
#include "nsIPop3IncomingServer.h"
#include "nsIPop3Service.h"
#include "nsIMsgIncomingServer.h"
#include "nsLocalFolderSummarySpec.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -527,50 +528,45 @@ NS_IMETHODIMP nsMsgLocalMailFolder::CreateSubfolder(const char *folderName)
return rv;
}
NS_IMETHODIMP nsMsgLocalMailFolder::RemoveSubFolder(nsIMsgFolder *which)
NS_IMETHODIMP nsMsgLocalMailFolder::RemoveSubFolder(nsIMsgFolder *folder)
{
#if 0
// Let the base class do list management
nsMsgFolder::RemoveSubFolder(which);
#endif
// Derived class is responsible for managing the subdirectory
#ifdef HAVE_PORT
if (0 == m_subFolders->GetSize())
XP_RemoveDirectory (m_pathName, xpMailSubdirectory);
#endif
return NS_OK;
}
NS_IMETHODIMP nsMsgLocalMailFolder::Delete()
{
#ifdef HAVE_PORT
nsMsgDatabase *db;
// remove the summary file
nsresult status = CloseDatabase (m_pathName, &db);
if (0 == status) {
if (db != NULL)
db->Close(); // decrement ref count, so it will leave cache
XP_FileRemove (m_pathName, xpMailFolderSummary);
}
nsresult rv = GetDatabase();
if (0 == status) {
// remove the mail folder file
status = XP_FileRemove (m_pathName, xpMailFolder);
if(NS_SUCCEEDED(rv))
{
mDatabase->ForceClosed();
mDatabase = null_nsCOMPtr();
}
// if the delete seems to have failed, but the file doesn't
// exist, that's not really an error condition, is it now?
if (status) {
XP_StatStruct fileStat;
if (0 == XP_Stat(m_pathName, &fileStat, xpMailFolder))
status = 0;
}
}
nsFileSpec path;
rv = GetPath(path);
if (0 != status)
status = MK_UNABLE_TO_DELETE_FILE;
return status;
#endif
//Clean up .sbd folder if it exists.
if(NS_SUCCEEDED(rv))
{
nsLocalFolderSummarySpec summarySpec(path);
// Remove summary file.
summarySpec.Delete(PR_FALSE);
//Delete mailbox
path.Delete(PR_FALSE);
if (!path.IsDirectory())
AddDirectorySeparator(path);
//If this is a directory, then remove it.
if (path.IsDirectory())
{
path.Delete(PR_TRUE);
}
}
return NS_OK;
}