From 69c079006546757dbc2829681e2498e41465e7b2 Mon Sep 17 00:00:00 2001 From: "mscott%netscape.com" Date: Mon, 15 May 2000 20:34:33 +0000 Subject: [PATCH] Bug #31058 -->Add nsIMsgI18NUrl and Get/Set URI support. --- mailnews/news/src/nsNntpService.cpp | 2 + mailnews/news/src/nsNntpUrl.cpp | 96 ++++++++++++++++++----------- mailnews/news/src/nsNntpUrl.h | 34 +++++----- 3 files changed, 80 insertions(+), 52 deletions(-) diff --git a/mailnews/news/src/nsNntpService.cpp b/mailnews/news/src/nsNntpService.cpp index 8ea5759badf8..c26fe9c25f7b 100644 --- a/mailnews/news/src/nsNntpService.cpp +++ b/mailnews/news/src/nsNntpService.cpp @@ -803,6 +803,8 @@ nsresult nsNntpService::ConstructNntpUrl(const char * urlString, const char * ne if (NS_FAILED(rv) || !nntpUrl) return rv; nsCOMPtr mailnewsurl = do_QueryInterface(nntpUrl); + nsCOMPtr msgUrl = do_QueryInterface(nntpUrl); + msgUrl->SetUri(urlString); // don't worry this cast is really okay...there'a bug in XPIDL compiler that is preventing // a "const char *" in paramemter for uri SetSpec... mailnewsurl->SetSpec((char *) urlString); diff --git a/mailnews/news/src/nsNntpUrl.cpp b/mailnews/news/src/nsNntpUrl.cpp index 832647b4a4d5..7406a6bf0457 100644 --- a/mailnews/news/src/nsNntpUrl.cpp +++ b/mailnews/news/src/nsNntpUrl.cpp @@ -40,6 +40,11 @@ #include "nsXPIDLString.h" #include "nsIMsgDatabase.h" #include "nsMsgDBCID.h" +#include "nsIRDFService.h" +#include "rdf.h" +#include "nsIMsgFolder.h" +#include "nsIMessage.h" + static NS_DEFINE_CID(kCNewsDB, NS_NEWSDB_CID); @@ -51,12 +56,12 @@ nsNntpUrl::nsNntpUrl() m_newsgroup = nsnull; m_offlineNews = nsnull; m_newsgroupList = nsnull; - m_newsgroupPost = nsnull; - m_newsgroupName = nsnull; - m_messageKey = nsMsgKey_None; + m_newsgroupPost = nsnull; + m_newsgroupName = nsnull; + m_messageKey = nsMsgKey_None; m_newsAction = nsINntpUrl::ActionGetNewNews; - m_addDummyEnvelope = PR_FALSE; - m_canonicalLineEnding = PR_FALSE; + m_addDummyEnvelope = PR_FALSE; + m_canonicalLineEnding = PR_FALSE; m_filePath = nsnull; } @@ -67,36 +72,19 @@ nsNntpUrl::~nsNntpUrl() NS_IF_RELEASE(m_newsgroup); NS_IF_RELEASE(m_offlineNews); NS_IF_RELEASE(m_newsgroupList); - NS_IF_RELEASE(m_newsgroupPost); - PR_FREEIF(m_newsgroupName); + NS_IF_RELEASE(m_newsgroupPost); + PR_FREEIF(m_newsgroupName); } NS_IMPL_ADDREF_INHERITED(nsNntpUrl, nsMsgMailNewsUrl) NS_IMPL_RELEASE_INHERITED(nsNntpUrl, nsMsgMailNewsUrl) - -nsresult nsNntpUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr) -{ - if (NULL == aInstancePtr) - { - return NS_ERROR_NULL_POINTER; - } - - if (aIID.Equals(NS_GET_IID(nsINntpUrl))) - { - *aInstancePtr = (void*) ((nsINntpUrl*)this); - NS_ADDREF_THIS(); - return NS_OK; - } - if (aIID.Equals(NS_GET_IID(nsIMsgMessageUrl))) - { - *aInstancePtr = (void *) ((nsIMsgMessageUrl *) this); - NS_ADDREF_THIS(); - return NS_OK; - } - - return nsMsgMailNewsUrl::QueryInterface(aIID, aInstancePtr); -} +NS_INTERFACE_MAP_BEGIN(nsNntpUrl) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsINntpUrl) + NS_INTERFACE_MAP_ENTRY(nsINntpUrl) + NS_INTERFACE_MAP_ENTRY(nsIMsgMessageUrl) + NS_INTERFACE_MAP_ENTRY(nsIMsgI18NUrl) +NS_INTERFACE_MAP_END_INHERITING(nsNntpUrl) //////////////////////////////////////////////////////////////////////////////////// // Begin nsINntpUrl specific support @@ -241,11 +229,22 @@ nsresult nsNntpUrl::GetNewsgroupList (nsINNTPNewsgroupList ** newsgroupList) return NS_OK; } +NS_IMETHODIMP nsNntpUrl::SetUri(const char * aURI) +{ + mURI= aURI; + return NS_OK; +} + // from nsIMsgMessageUrl -NS_IMETHODIMP nsNntpUrl::GetURI(char ** aURI) +NS_IMETHODIMP nsNntpUrl::GetUri(char ** aURI) { - nsresult rv; - if (aURI) + nsresult rv = NS_OK; + // if we have been given a uri to associate with this url, then use it + // otherwise try to reconstruct a URI on the fly.... + + if (!mURI.IsEmpty()) + *aURI = mURI.ToNewCString(); + else { nsXPIDLCString spec; GetSpec(getter_Copies(spec)); @@ -259,9 +258,8 @@ NS_IMETHODIMP nsNntpUrl::GetURI(char ** aURI) *aURI = uriStr.ToNewCString(); return NS_OK; } - else { - return NS_ERROR_NULL_POINTER; - } + + return rv; } NS_IMPL_GETSET(nsNntpUrl, AddDummyEnvelope, PRBool, m_addDummyEnvelope); @@ -435,3 +433,29 @@ nsNntpUrl::SetOriginalSpec(const char *aSpec) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP nsNntpUrl::GetFolderCharset(PRUnichar ** aCharacterSet) +{ + // if we have a RDF URI, then try to get the folder for that URI and then ask the folder + // for it's charset.... + + nsXPIDLCString uri; + GetUri(getter_Copies(uri)); + NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); + nsCOMPtr rdfService = do_GetService(NS_RDF_PROGID "/rdf-service"); + nsCOMPtr resource; + rdfService->GetResource(uri, getter_AddRefs(resource)); + + NS_ENSURE_TRUE(resource, NS_ERROR_FAILURE); + nsCOMPtr msg (do_QueryInterface(resource)); + NS_ENSURE_TRUE(msg, NS_ERROR_FAILURE); + nsCOMPtr folder; + msg->GetMsgFolder(getter_AddRefs(folder)); + NS_ENSURE_TRUE(folder, NS_ERROR_FAILURE); + nsXPIDLString charset; + folder->GetCharset(getter_Copies(charset)); + *aCharacterSet = nsCRT::strdup(charset); + + return NS_OK; +} + + diff --git a/mailnews/news/src/nsNntpUrl.h b/mailnews/news/src/nsNntpUrl.h index fd59d408180c..ce250f2d2e6d 100644 --- a/mailnews/news/src/nsNntpUrl.h +++ b/mailnews/news/src/nsNntpUrl.h @@ -29,40 +29,42 @@ #include "nsFileSpec.h" #include "nsIFileSpec.h" -class nsNntpUrl : public nsINntpUrl, public nsMsgMailNewsUrl, public nsIMsgMessageUrl +class nsNntpUrl : public nsINntpUrl, public nsMsgMailNewsUrl, public nsIMsgMessageUrl, public nsIMsgI18NUrl { public: - NS_DECL_NSINNTPURL - NS_DECL_NSIMSGMESSAGEURL + NS_DECL_NSINNTPURL + NS_DECL_NSIMSGMESSAGEURL + NS_DECL_NSIMSGI18NURL NS_IMETHOD IsUrlType(PRUint32 type, PRBool *isType); - // nsNntpUrl - nsNntpUrl(); - virtual ~nsNntpUrl(); + // nsNntpUrl + nsNntpUrl(); + virtual ~nsNntpUrl(); - NS_DECL_ISUPPORTS_INHERITED + NS_DECL_ISUPPORTS_INHERITED protected: virtual const char * GetUserName() { return nsnull; } - nsINNTPNewsgroupPost *m_newsgroupPost; + nsINNTPNewsgroupPost *m_newsgroupPost; nsNewsAction m_newsAction; // the action this url represents...parse mailbox, display messages, etc. - nsFileSpec *m_filePath; + nsFileSpec *m_filePath; // used by save message to disk nsCOMPtr m_messageFileSpec; - PRBool m_addDummyEnvelope; - PRBool m_canonicalLineEnding; + PRBool m_addDummyEnvelope; + PRBool m_canonicalLineEnding; /* NNTP specific event sinks */ - nsINNTPHost * m_newsHost; + nsINNTPHost * m_newsHost; nsINNTPArticleList * m_articleList; - nsINNTPNewsgroup * m_newsgroup; - nsIMsgOfflineNewsState * m_offlineNews; + nsINNTPNewsgroup * m_newsgroup; + nsIMsgOfflineNewsState* m_offlineNews; nsINNTPNewsgroupList * m_newsgroupList; - nsMsgKey m_messageKey; - char * m_newsgroupName; + nsMsgKey m_messageKey; + char * m_newsgroupName; + nsCString mURI; // the RDF URI associated with this url. }; #endif // nsNntpUrl_h__