From 34eb2167ddd89481f0b166e4cdf050df30f562a7 Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Wed, 3 Mar 1999 01:21:38 +0000 Subject: [PATCH] Update to latest version of nsIMsgMailNewsUrl which includes url listener registration and notification stuff. --- mailnews/compose/src/nsSmtpUrl.cpp | 50 ++++++++++++++++++++++++++++++ mailnews/compose/src/nsSmtpUrl.h | 20 +++++++----- 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/mailnews/compose/src/nsSmtpUrl.cpp b/mailnews/compose/src/nsSmtpUrl.cpp index 8dabe9e7d7ba..02022a6e4584 100644 --- a/mailnews/compose/src/nsSmtpUrl.cpp +++ b/mailnews/compose/src/nsSmtpUrl.cpp @@ -33,6 +33,7 @@ // that doesn't allow you to call ::nsISupports::IID() inside of a class // that multiply inherits from nsISupports static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID); nsSmtpUrl::nsSmtpUrl(nsISupports* aContainer, nsIURLGroup* aGroup) : m_fileName(""), m_userName(""), m_userPassword("") { @@ -70,6 +71,9 @@ nsSmtpUrl::nsSmtpUrl(nsISupports* aContainer, nsIURLGroup* aGroup) : m_fileName( m_search = nsnull; m_errorMessage = nsnull; m_runningUrl = PR_FALSE; + + nsServiceManager::GetService(kUrlListenerManagerCID, nsIUrlListenerManager::IID(), + (nsISupports **)&m_urlListeners); m_container = aContainer; NS_IF_ADDREF(m_container); @@ -80,6 +84,8 @@ nsSmtpUrl::~nsSmtpUrl() { CleanupSmtpState(); + NS_IF_RELEASE(m_urlListeners); + NS_IF_RELEASE(m_container); PR_FREEIF(m_errorMessage); @@ -124,6 +130,13 @@ nsresult nsSmtpUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr) return NS_OK; } + if (aIID.Equals(nsIMsgMailNewsUrl::IID())) + { + *aInstancePtr = (void *) ((nsIMsgMailNewsUrl*) this); + AddRef(); + return NS_OK; + } + #if defined(NS_DEBUG) /* * Check for the debug-only interface indicating thread-safety @@ -139,8 +152,45 @@ nsresult nsSmtpUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr) //////////////////////////////////////////////////////////////////////////////////// // Begin nsISmtpUrl specific support + //////////////////////////////////////////////////////////////////////////////////// +nsresult nsSmtpUrl::GetUrlState(PRBool * aRunningUrl) +{ + if (aRunningUrl) + *aRunningUrl = m_runningUrl; + + return NS_OK; +} + +nsresult nsSmtpUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode) +{ + m_runningUrl = aRunningUrl; + if (m_urlListeners) + { + if (m_runningUrl) + m_urlListeners->OnStartRunningUrl(this); + else + m_urlListeners->OnStopRunningUrl(this, aExitCode); + } + + return NS_OK; +} + +nsresult nsSmtpUrl::RegisterListener (nsIUrlListener * aUrlListener) +{ + if (m_urlListeners) + m_urlListeners->RegisterListener(aUrlListener); + return NS_OK; +} + +nsresult nsSmtpUrl::UnRegisterListener (nsIUrlListener * aUrlListener) +{ + if (m_urlListeners) + m_urlListeners->UnRegisterListener(aUrlListener); + return NS_OK; +} + nsresult nsSmtpUrl::SetErrorMessage (char * errorMessage) { NS_LOCK_INSTANCE(); diff --git a/mailnews/compose/src/nsSmtpUrl.h b/mailnews/compose/src/nsSmtpUrl.h index 99b526044a74..08a79f5a4630 100644 --- a/mailnews/compose/src/nsSmtpUrl.h +++ b/mailnews/compose/src/nsSmtpUrl.h @@ -21,6 +21,7 @@ #include "nsISmtpUrl.h" #include "nsINetlibURL.h" /* this should be temporary until Network N2 project lands */ +#include "nsIUrlListenerManager.h" class nsSmtpUrl : public nsISmtpUrl, public nsINetlibURL { @@ -56,8 +57,9 @@ public: NS_IMETHOD GetServerStatus(PRInt32 *status); // make obsolete NS_IMETHOD ToString(PRUnichar* *aString) const; - NS_IMPL_CLASS_GETSET(RunningUrlFlag, PRBool, m_runningUrl); - + NS_IMETHOD SetUrlState(PRBool aRunningUrl, nsresult aStatusCode); + NS_IMETHOD GetUrlState(PRBool * aRunningUrl); + // from nsINetlibURL: NS_IMETHOD GetURLInfo(URL_Struct_ **aResult) const; @@ -103,14 +105,13 @@ public: NS_IMETHOD GetUserPassword(const nsString ** aUserPassword); NS_IMETHOD SetUserPassword(const nsString& aUserPassword); - // mscott: this interface really belongs in nsIURL and I will move it there after talking - // it over with core netlib. This error message replaces the err_msg which was in the - // old URL_struct. Also, it should probably be a nsString or a PRUnichar *. I don't know what - // XP_GetString is going to return in mozilla. - + // nsIMsgMailNewsUrl NS_IMETHOD SetErrorMessage (char * errorMessage); // caller must free using PR_FREE NS_IMETHOD GetErrorMessage (char ** errorMessage) const; + + NS_IMETHOD RegisterListener (nsIUrlListener * aUrlListener); + NS_IMETHOD UnRegisterListener (nsIUrlListener * aUrlListener); // nsSmtpUrl @@ -158,6 +159,9 @@ protected: PRInt32 m_port; nsISupports* m_container; + // manager of all of current url listeners.... + nsIUrlListenerManager * m_urlListeners; + /* Smtp specific event sinks */ nsString m_userPassword; char *m_userNameString; // char * version of m_userName @@ -174,4 +178,4 @@ protected: nsresult CleanupSmtpState(); }; -#endif // nsSmtpUrl_h__ \ No newline at end of file +#endif // nsSmtpUrl_h__