Add getters and setters for the identity associated with the url. If the caller attempts to get an identity and we don't have one, then we go out and return the default identity....

This commit is contained in:
mscott%netscape.com 1999-04-06 21:02:07 +00:00
parent 66a9f51d6a
commit d558c8be39
2 changed files with 67 additions and 3 deletions

View File

@ -24,7 +24,9 @@
#include "nsIURL.h"
#include "nsImapUrl.h"
#include "nsINetService.h"
#include "nsIMsgMailSession.h"
#include "nsString.h"
#include "prmem.h"
@ -37,12 +39,14 @@
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID);
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
nsImapUrl::nsImapUrl()
{
NS_INIT_REFCNT();
m_errorMessage = nsnull;
m_identity = nsnull;
// nsINetLibUrl specific state
m_URL_s = nsnull;
@ -73,6 +77,7 @@ nsImapUrl::~nsImapUrl()
NS_IF_RELEASE(m_imapMessage);
NS_IF_RELEASE(m_imapExtension);
NS_IF_RELEASE(m_imapMiscellaneous);
NS_IF_RELEASE(m_identity);
NS_IF_RELEASE(m_urlListeners);
PR_FREEIF(m_errorMessage);
@ -134,6 +139,53 @@ NS_IMETHODIMP nsImapUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
// Begin nsIImapUrl specific support
////////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsImapUrl::SetIdentity(nsIMsgIdentity * aMsgIdentity)
{
if (aMsgIdentity)
{
NS_IF_RELEASE(m_identity);
m_identity = aMsgIdentity;
NS_ADDREF(m_identity);
return NS_OK;
}
else
return NS_ERROR_NULL_POINTER;
}
NS_IMETHODIMP nsImapUrl::GetIdentity(nsIMsgIdentity **aMsgIdentity)
{
nsresult rv = NS_OK;
if (aMsgIdentity) // valid argument to return result in?
{
// if we weren't given an identity, let's be creative and go fetch the default current
// identity.
if (!m_identity)
{
nsIMsgMailSession * session = nsnull;
rv = nsServiceManager::GetService(kMsgMailSessionCID, nsIMsgMailSession::GetIID(),
(nsISupports **) &session);
if (NS_SUCCEEDED(rv) && session)
{
// store the identity in m_identity so we don't have to do this again.
rv = session->GetCurrentIdentity(&m_identity);
nsServiceManager::ReleaseService(kMsgMailSessionCID, session);
}
}
// if we were given an identity then use it.
if (m_identity)
{
*aMsgIdentity = m_identity;
NS_ADDREF(m_identity);
}
else
*aMsgIdentity = nsnull;
} // if aMsgIdentity
return rv;
}
NS_IMETHODIMP nsImapUrl::GetImapLog(nsIImapLog ** aImapLog)
{
if (aImapLog)

View File

@ -21,7 +21,8 @@
#include "nsIImapUrl.h"
#include "nsIUrlListenerManager.h"
#include "nsINetlibURL.h" /* this should be temporary until Network N2 project lands */
#include "nsINetlibURL.h" /* this should be temporary until nunet project lands */
#include "nsIMsgIdentity.h"
class nsImapUrl : public nsIImapUrl, public nsINetlibURL
{
@ -43,6 +44,9 @@ public:
///////////////////////////////////////////////////////////////////////////////
// we support the nsIImapUrl interface
///////////////////////////////////////////////////////////////////////////////
NS_IMETHOD SetIdentity(nsIMsgIdentity * aMsgIdentity);
NS_IMETHOD GetIdentity(nsIMsgIdentity ** aMsgIdentity);
NS_IMETHOD GetImapLog(nsIImapLog ** aImapLog);
NS_IMETHOD SetImapLog(nsIImapLog * aImapLog);
@ -60,11 +64,17 @@ public:
NS_IMPL_CLASS_GETSET(ImapAction, nsImapAction, m_imapAction);
// from nsINetlibURL:
///////////////////////////////////////////////////////////////////////////////
// we support the nsINetlibURL interface
///////////////////////////////////////////////////////////////////////////////
NS_IMETHOD GetURLInfo(URL_Struct_ **aResult) const;
NS_IMETHOD SetURLInfo(URL_Struct_ *URL_s);
// from nsIURL:
///////////////////////////////////////////////////////////////////////////////
// we support the nsIURL interface
///////////////////////////////////////////////////////////////////////////////
// mscott: some of these we won't need to implement..as part of the netlib re-write we'll be removing them
// from nsIURL and then we can remove them from here as well....
NS_IMETHOD_(PRBool) Equals(const nsIURL *aURL) const;
@ -124,6 +134,8 @@ protected:
nsIImapMessage* m_imapMessage;
nsIImapExtension* m_imapExtension;
nsIImapMiscellaneous* m_imapMiscellaneous;
nsIMsgIdentity *m_identity;
};
#endif /* nsImapUrl_h___ */