move GetPath/SetPath into a base class, combining all the .sbd directory creators. reduces calls to FindServer() by about 2 calls per folder

r=sspitzer
a=chofmann
This commit is contained in:
alecf%netscape.com 1999-12-18 01:09:51 +00:00
Родитель cc6016af14
Коммит f0be7a9f12
8 изменённых файлов: 68 добавлений и 49 удалений

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

@ -465,6 +465,7 @@ nsMsgFolder::parseURI(PRBool needServer)
rv = parentMsgFolder->GetServer(getter_AddRefs(server));
}
// no parent. do the extra work of asking
if (!server && needServer) {
// Get username and hostname so we can get the server
nsXPIDLCString userName;
@ -498,12 +499,58 @@ nsMsgFolder::parseURI(PRBool needServer)
if (NS_FAILED(rv)) return rv;
}
// keep weak ref to server - do not addref!
m_server = server;
} /* !m_server */
// now try to find the local path for this folder
if (m_server) {
nsXPIDLCString urlPath;
url->GetFilePath(getter_Copies(urlPath));
// transform the filepath from the URI, such as
// "/folder1/folder2/foldern"
// to
// "folder1.sbd/folder2.sbd/foldern"
// (remove leading / and add .sbd to first n-1 folders)
// to be appended onto the server's path
nsCAutoString newPath;
char *newStr;
char *token =
nsCRT::strtok(NS_CONST_CAST(char *,(const char*)urlPath), "/", &newStr);
// trick to make sure we only add the path to the first n-1 folders
PRBool haveFirst=PR_FALSE;
while (token) {
// skip leading '/' (and other // style things)
if (nsCRT::strcmp(token, "")==0) continue;
// add .sbd onto the previous path
if (haveFirst) newPath+=".sbd";
newPath += "/";
newPath += token;
haveFirst=PR_TRUE;
token = nsCRT::strtok(newStr, "/", &newStr);
}
// now append munged path onto server path
nsCOMPtr<nsIFileSpec> serverPath;
rv = m_server->GetLocalPath(getter_AddRefs(serverPath));
if (NS_FAILED(rv)) return rv;
if (serverPath) {
serverPath->AppendRelativeUnixPath(newPath.GetBuffer());
mPath = serverPath;
}
}
return NS_OK;
}
@ -1701,24 +1748,25 @@ nsMsgFolder::GetMsgDatabase(nsIMsgDatabase** aMsgDatabase)
NS_IMETHODIMP
nsMsgFolder::GetPath(nsIFileSpec * *aPath)
{
nsresult rv;
nsCOMPtr<nsIMsgIncomingServer> server;
NS_ENSURE_ARG_POINTER(aPath);
nsresult rv=NS_OK;
if (!mPath)
rv = parseURI(PR_TRUE);
*aPath = mPath;
NS_IF_ADDREF(*aPath);
rv = GetServer(getter_AddRefs(server));
if (NS_FAILED(rv)) return rv;
if (!server) return NS_ERROR_FAILURE;
nsCOMPtr<nsIFileSpec> path;
rv = server->GetLocalPath(getter_AddRefs(path));
return rv;
}
NS_IMETHODIMP
nsMsgFolder::SetPath(nsIFileSpec * /* aPath */)
nsMsgFolder::SetPath(nsIFileSpec *aPath)
{
return NS_ERROR_NOT_IMPLEMENTED;
// XXX - make a local copy!
mPath = aPath;
return NS_OK;
}
NS_IMETHODIMP

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

@ -270,7 +270,7 @@ protected:
PRBool mIsServerIsValid;
PRBool mIsServer;
nsString mName;
nsCOMPtr<nsIFileSpec> mPath;
};
#endif

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

@ -161,6 +161,7 @@ NS_IMETHODIMP nsImapMailFolder::QueryInterface(REFNSIID aIID, void** aInstancePt
return nsMsgDBFolder::QueryInterface(aIID, aInstancePtr);
}
#if 0
NS_IMETHODIMP nsImapMailFolder::GetPath(nsIFileSpec** aPathName)
{
nsresult rv;
@ -178,6 +179,7 @@ NS_IMETHODIMP nsImapMailFolder::GetPath(nsIFileSpec** aPathName)
return NS_OK;
}
NS_IMETHODIMP nsImapMailFolder::SetPath(nsIFileSpec * aPathName)
{
if (!aPathName)
@ -190,6 +192,7 @@ NS_IMETHODIMP nsImapMailFolder::SetPath(nsIFileSpec * aPathName)
}
return aPathName->GetFileSpec(m_pathName);
}
#endif
NS_IMETHODIMP nsImapMailFolder::Enumerate(nsIEnumerator* *result)

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

@ -165,8 +165,10 @@ public:
**message);
NS_IMETHOD GetNewMessages(nsIMsgWindow *aWindow);
#if 0
NS_IMETHOD GetPath(nsIFileSpec** aPathName);
NS_IMETHOD SetPath(nsIFileSpec * aPath);
#endif
// nsIMsgImapMailFolder methods
NS_DECL_NSIMSGIMAPMAILFOLDER

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

@ -1032,21 +1032,6 @@ NS_IMETHODIMP nsMsgLocalMailFolder::GetRememberedPassword(char ** password)
return NS_OK;
}
NS_IMETHODIMP nsMsgLocalMailFolder::GetPath(nsIFileSpec ** aPathName)
{
nsresult rv;
if (! mPath) {
mPath = new nsFileSpec("");
if (! mPath)
return NS_ERROR_OUT_OF_MEMORY;
rv = nsLocalURI2Path(kMailboxRootURI, mURI, *mPath);
if (NS_FAILED(rv)) return rv;
}
rv = NS_NewFileSpecWithSpec(*mPath, aPathName);
return rv;
}
nsresult
nsMsgLocalMailFolder::GetTrashFolder(nsIMsgFolder** result)

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

@ -131,9 +131,6 @@ public:
NS_IMETHOD CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **message);
NS_IMETHOD GetNewMessages(nsIMsgWindow *aWindow);
// nsIMsgMailFolder
NS_IMETHOD GetPath(nsIFileSpec ** aPathName);
// overriding nsMsgDBFolder::GetMsgDatabase() method
NS_IMETHOD GetMsgDatabase(nsIMsgDatabase **aMsgDatabase);

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

@ -813,21 +813,6 @@ NS_IMETHODIMP nsMsgNewsFolder::GetRememberedPassword(char ** password)
return NS_OK;
}
NS_IMETHODIMP nsMsgNewsFolder::GetPath(nsIFileSpec** aPathName)
{
nsresult rv;
if (! mPath) {
mPath = new nsNativeFileSpec("");
if (! mPath)
return NS_ERROR_OUT_OF_MEMORY;
rv = nsNewsURI2Path(kNewsRootURI, mURI, *mPath);
if (NS_FAILED(rv)) return rv;
}
rv = NS_NewFileSpecWithSpec(*mPath, aPathName);
return rv;
}
/* this is news, so remember that DeleteMessage is really CANCEL */
NS_IMETHODIMP nsMsgNewsFolder::DeleteMessages(nsISupportsArray *messages,
nsIMsgWindow *msgWindow, PRBool deleteStorage)

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

@ -90,7 +90,6 @@ public:
NS_IMETHOD CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **message);
NS_IMETHOD GetNewMessages(nsIMsgWindow *aWindow);
NS_IMETHOD GetPath(nsIFileSpec** aPathName);
NS_IMETHOD GetCanSubscribe(PRBool *aResult);
NS_IMETHOD GetCanFileMessages(PRBool *aResult);
NS_IMETHOD GetCanCreateSubfolders(PRBool *aResult);