From 7d2a82beee70058b0631cbc0e146ece33161fa09 Mon Sep 17 00:00:00 2001 From: "putterman%netscape.com" Date: Fri, 29 Oct 1999 20:46:15 +0000 Subject: [PATCH] Fix for 17556. Reviewed by alecf. Newsgroups show abbreviated name in folder pane. --- mailnews/base/public/nsIFolder.idl | 1 + .../base/resources/content/folderPane.xul | 4 +- .../resources/content/msgMail3PaneWindow.js | 2 +- mailnews/base/src/nsMsgAccountManagerDS.cpp | 13 ++++- mailnews/base/src/nsMsgAccountManagerDS.h | 2 + mailnews/base/src/nsMsgFolderDataSource.cpp | 57 +++++++++++++++---- mailnews/base/src/nsMsgFolderDataSource.h | 4 ++ mailnews/base/src/nsMsgRDFUtils.h | 2 + mailnews/base/util/nsMsgFolder.cpp | 6 ++ mailnews/news/src/nsNewsFolder.cpp | 40 ++++++++----- mailnews/news/src/nsNewsFolder.h | 3 +- 11 files changed, 102 insertions(+), 32 deletions(-) diff --git a/mailnews/base/public/nsIFolder.idl b/mailnews/base/public/nsIFolder.idl index c3cad2ed074c..7ae2bcf74495 100644 --- a/mailnews/base/public/nsIFolder.idl +++ b/mailnews/base/public/nsIFolder.idl @@ -25,6 +25,7 @@ interface nsIFolder : nsICollection { readonly attribute string URI; attribute wstring name; attribute wstring prettyName; + readonly attribute wstring abbreviatedName; nsISupports GetChildNamed(in string name); attribute nsIFolder parent; diff --git a/mailnews/base/resources/content/folderPane.xul b/mailnews/base/resources/content/folderPane.xul index f63cd8855b25..aebefe0ba377 100644 --- a/mailnews/base/resources/content/folderPane.xul +++ b/mailnews/base/resources/content/folderPane.xul @@ -41,7 +41,7 @@ IsServer="rdf:http://home.netscape.com/NC-rdf#IsServer" ServerType="rdf:http://home.netscape.com/NC-rdf#ServerType"> - + @@ -50,7 +50,7 @@ - + diff --git a/mailnews/base/resources/content/msgMail3PaneWindow.js b/mailnews/base/resources/content/msgMail3PaneWindow.js index 010a9130c8c4..ebe294637dc4 100644 --- a/mailnews/base/resources/content/msgMail3PaneWindow.js +++ b/mailnews/base/resources/content/msgMail3PaneWindow.js @@ -288,7 +288,7 @@ function OnLoadFolderPane(folderTree) { dump('In onLoadfolderPane\n'); gFolderTree = folderTree; - SortFolderPane('FolderColumn', 'http://home.netscape.com/NC-rdf#Name'); + SortFolderPane('FolderColumn', 'http://home.netscape.com/NC-rdf#FolderTreeName'); //Add folderDataSource and accountManagerDataSource to folderPane accountManagerDataSource = accountManagerDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource); folderDataSource = folderDataSource.QueryInterface(Components.interfaces.nsIRDFDataSource); diff --git a/mailnews/base/src/nsMsgAccountManagerDS.cpp b/mailnews/base/src/nsMsgAccountManagerDS.cpp index c0786debf6c1..11eb7e53c91b 100644 --- a/mailnews/base/src/nsMsgAccountManagerDS.cpp +++ b/mailnews/base/src/nsMsgAccountManagerDS.cpp @@ -59,7 +59,9 @@ typedef struct _serverCreationParams { // static members nsIRDFResource* nsMsgAccountManagerDataSource::kNC_Child=nsnull; nsIRDFResource* nsMsgAccountManagerDataSource::kNC_Name=nsnull; +nsIRDFResource* nsMsgAccountManagerDataSource::kNC_FolderTreeName=nsnull; nsIRDFResource* nsMsgAccountManagerDataSource::kNC_NameSort=nsnull; +nsIRDFResource* nsMsgAccountManagerDataSource::kNC_FolderTreeNameSort=nsnull; nsIRDFResource* nsMsgAccountManagerDataSource::kNC_PageTag=nsnull; nsIRDFResource* nsMsgAccountManagerDataSource::kNC_Settings=nsnull; nsIRDFResource* nsMsgAccountManagerDataSource::kNC_AccountRoot=nsnull; @@ -110,7 +112,9 @@ nsMsgAccountManagerDataSource::~nsMsgAccountManagerDataSource() { NS_IF_RELEASE(kNC_Child); NS_IF_RELEASE(kNC_Name); + NS_IF_RELEASE(kNC_FolderTreeName); NS_IF_RELEASE(kNC_NameSort); + NS_IF_RELEASE(kNC_FolderTreeNameSort); NS_IF_RELEASE(kNC_PageTag); NS_IF_RELEASE(kNC_Account); NS_IF_RELEASE(kNC_Server); @@ -148,7 +152,9 @@ nsMsgAccountManagerDataSource::Init() if (gAccountManagerResourceRefCnt++ == 0) { getRDFService()->GetResource(NC_RDF_CHILD, &kNC_Child); getRDFService()->GetResource(NC_RDF_NAME, &kNC_Name); + getRDFService()->GetResource(NC_RDF_FOLDERTREENAME, &kNC_FolderTreeName); getRDFService()->GetResource(NC_RDF_NAME_SORT, &kNC_NameSort); + getRDFService()->GetResource(NC_RDF_FOLDERTREENAME_SORT, &kNC_FolderTreeNameSort); getRDFService()->GetResource(NC_RDF_PAGETAG, &kNC_PageTag); getRDFService()->GetResource(NC_RDF_ACCOUNT, &kNC_Account); getRDFService()->GetResource(NC_RDF_SERVER, &kNC_Server); @@ -187,7 +193,7 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source, rv = NS_RDF_NO_VALUE; nsString str=""; - if (property == kNC_Name) { + if (property == kNC_Name || property == kNC_FolderTreeName) { // XXX these should be localized if (source == kNC_PageTitleMain) @@ -220,7 +226,6 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source, } } } - else if (property == kNC_PageTag) { // do NOT localize these strings. these are the urls of the XUL files if (source == kNC_PageTitleServer) @@ -236,7 +241,7 @@ nsMsgAccountManagerDataSource::GetTarget(nsIRDFResource *source, } // handle sorting of servers - else if (property == kNC_NameSort) { + else if ((property == kNC_NameSort) || (property == kNC_FolderTreeNameSort)) { // make sure we're handling a root folder that is a server nsCOMPtr folder = do_QueryInterface(source,&rv); if (NS_FAILED(rv)) @@ -436,7 +441,9 @@ nsMsgAccountManagerDataSource::ArcLabelsOut(nsIRDFResource *source, arcs->AppendElement(kNC_Settings); arcs->AppendElement(kNC_Name); + arcs->AppendElement(kNC_FolderTreeName); arcs->AppendElement(kNC_NameSort); + arcs->AppendElement(kNC_FolderTreeNameSort); arcs->AppendElement(kNC_PageTag); #ifdef DEBUG_amds_ diff --git a/mailnews/base/src/nsMsgAccountManagerDS.h b/mailnews/base/src/nsMsgAccountManagerDS.h index 7af7e6044b8f..182836c2a321 100644 --- a/mailnews/base/src/nsMsgAccountManagerDS.h +++ b/mailnews/base/src/nsMsgAccountManagerDS.h @@ -62,7 +62,9 @@ public: protected: static nsIRDFResource* kNC_Name; + static nsIRDFResource* kNC_FolderTreeName; static nsIRDFResource* kNC_NameSort; + static nsIRDFResource* kNC_FolderTreeNameSort; static nsIRDFResource* kNC_PageTag; static nsIRDFResource* kNC_Child; static nsIRDFResource* kNC_AccountRoot; diff --git a/mailnews/base/src/nsMsgFolderDataSource.cpp b/mailnews/base/src/nsMsgFolderDataSource.cpp index 6249ffc09983..12608ed01031 100644 --- a/mailnews/base/src/nsMsgFolderDataSource.cpp +++ b/mailnews/base/src/nsMsgFolderDataSource.cpp @@ -52,7 +52,9 @@ nsIRDFResource* nsMsgFolderDataSource::kNC_Child = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_MessageChild = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_Folder= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_Name= nsnull; +nsIRDFResource* nsMsgFolderDataSource::kNC_FolderTreeName= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_NameSort= nsnull; +nsIRDFResource* nsMsgFolderDataSource::kNC_FolderTreeNameSort= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_SpecialFolder= nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_ServerType = nsnull; nsIRDFResource* nsMsgFolderDataSource::kNC_IsServer = nsnull; @@ -97,7 +99,9 @@ nsMsgFolderDataSource::~nsMsgFolderDataSource (void) NS_RELEASE2(kNC_MessageChild, refcnt); NS_RELEASE2(kNC_Folder, refcnt); NS_RELEASE2(kNC_Name, refcnt); + NS_RELEASE2(kNC_FolderTreeName, refcnt); NS_RELEASE2(kNC_NameSort, refcnt); + NS_RELEASE2(kNC_FolderTreeNameSort, refcnt); NS_RELEASE2(kNC_SpecialFolder, refcnt); NS_RELEASE2(kNC_ServerType, refcnt); NS_RELEASE2(kNC_IsServer, refcnt); @@ -138,7 +142,9 @@ nsresult nsMsgFolderDataSource::Init() rdf->GetResource(NC_RDF_MESSAGECHILD, &kNC_MessageChild); rdf->GetResource(NC_RDF_FOLDER, &kNC_Folder); rdf->GetResource(NC_RDF_NAME, &kNC_Name); + rdf->GetResource(NC_RDF_FOLDERTREENAME, &kNC_FolderTreeName); rdf->GetResource(NC_RDF_NAME_SORT, &kNC_NameSort); + rdf->GetResource(NC_RDF_FOLDERTREENAME_SORT, &kNC_FolderTreeNameSort); rdf->GetResource(NC_RDF_SPECIALFOLDER, &kNC_SpecialFolder); rdf->GetResource(NC_RDF_SERVERTYPE, &kNC_ServerType); rdf->GetResource(NC_RDF_ISSERVER, &kNC_IsServer); @@ -356,6 +362,7 @@ NS_IMETHODIMP nsMsgFolderDataSource::GetTargets(nsIRDFResource* source, } } else if ((kNC_Name == property) || + (kNC_FolderTreeName == property) || (kNC_SpecialFolder == property) || (kNC_IsServer == property) || (kNC_ServerType == property)) @@ -469,6 +476,7 @@ nsMsgFolderDataSource::getFolderArcLabelsOut(nsISupportsArray **arcs) return rv; (*arcs)->AppendElement(kNC_Name); + (*arcs)->AppendElement(kNC_FolderTreeName); (*arcs)->AppendElement(kNC_SpecialFolder); (*arcs)->AppendElement(kNC_ServerType); (*arcs)->AppendElement(kNC_IsServer); @@ -789,8 +797,12 @@ nsresult nsMsgFolderDataSource::createFolderNode(nsIMsgFolder* folder, if (kNC_NameSort == property) rv = createFolderNameNode(folder, target, PR_TRUE); + else if(kNC_FolderTreeNameSort == property) + rv = createFolderTreeNameNode(folder, target, PR_TRUE); else if (kNC_Name == property) rv = createFolderNameNode(folder, target, PR_FALSE); + else if (kNC_FolderTreeName == property) + rv = createFolderTreeNameNode(folder, target, PR_FALSE); else if ((kNC_SpecialFolder == property)) rv = createFolderSpecialNode(folder,target); else if ((kNC_ServerType == property)) @@ -825,21 +837,45 @@ nsresult nsMsgFolderDataSource::createFolderNameNode(nsIMsgFolder *folder, nsString nameString(name); if(sort) { - PRInt32 order; - rv = GetFolderSortOrder(folder, &order); - if(NS_FAILED(rv)) - return rv; - char * orderString = PR_smprintf("%d", order); - if(!orderString) - return NS_ERROR_OUT_OF_MEMORY; - - nameString.Insert(orderString, 0); - PR_smprintf_free(orderString); + CreateNameSortString(folder, nameString); } createNode(nameString, target, getRDFService()); return NS_OK; } + +nsresult nsMsgFolderDataSource::createFolderTreeNameNode(nsIMsgFolder *folder, + nsIRDFNode **target, PRBool sort) +{ + + nsXPIDLString name; + nsresult rv = folder->GetAbbreviatedName(getter_Copies(name)); + if (NS_FAILED(rv)) return rv; + nsString nameString(name); + if(sort) + { + CreateNameSortString(folder, nameString); + } + createNode(nameString, target, getRDFService()); + return NS_OK; +} + +nsresult nsMsgFolderDataSource::CreateNameSortString(nsIMsgFolder *folder, nsString &name) +{ + PRInt32 order; + nsresult rv = GetFolderSortOrder(folder, &order); + if(NS_FAILED(rv)) + return rv; + char * orderString = PR_smprintf("%d", order); + if(!orderString) + return NS_ERROR_OUT_OF_MEMORY; + + name.Insert(orderString, 0); + PR_smprintf_free(orderString); + + return NS_OK; +} + nsresult nsMsgFolderDataSource::createFolderSpecialNode(nsIMsgFolder *folder, nsIRDFNode **target) @@ -1226,6 +1262,7 @@ nsresult nsMsgFolderDataSource::DoFolderHasAssertion(nsIMsgFolder *folder, rv = folder->HasMessage(message, hasAssertion); } else if ((kNC_Name == property) || + (kNC_FolderTreeName == property) || (kNC_SpecialFolder == property) || (kNC_ServerType == property) || (kNC_IsServer == property) || diff --git a/mailnews/base/src/nsMsgFolderDataSource.h b/mailnews/base/src/nsMsgFolderDataSource.h index 4122c5b6f20d..00aea0aa2bba 100644 --- a/mailnews/base/src/nsMsgFolderDataSource.h +++ b/mailnews/base/src/nsMsgFolderDataSource.h @@ -113,6 +113,7 @@ protected: nsresult createFolderNode(nsIMsgFolder *folder, nsIRDFResource* property, nsIRDFNode **target); nsresult createFolderNameNode(nsIMsgFolder *folder, nsIRDFNode **target, PRBool sort); + nsresult createFolderTreeNameNode(nsIMsgFolder *folder, nsIRDFNode **target, PRBool sort); nsresult createFolderSpecialNode(nsIMsgFolder *folder, nsIRDFNode **target); nsresult createFolderServerTypeNode(nsIMsgFolder *folder, nsIRDFNode **target); @@ -147,6 +148,7 @@ protected: nsresult GetBiffStateString(PRUint32 biffState, nsCAutoString & biffStateStr); + nsresult CreateNameSortString(nsIMsgFolder *folder, nsString &name); nsresult GetFolderSortOrder(nsIMsgFolder *folder, PRInt32* order); nsresult CreateArcsOutEnumerator(); @@ -155,7 +157,9 @@ protected: static nsIRDFResource* kNC_MessageChild; static nsIRDFResource* kNC_Folder; static nsIRDFResource* kNC_Name; + static nsIRDFResource* kNC_FolderTreeName; static nsIRDFResource* kNC_NameSort; + static nsIRDFResource* kNC_FolderTreeNameSort; static nsIRDFResource* kNC_Columns; static nsIRDFResource* kNC_MSGFolderRoot; static nsIRDFResource* kNC_SpecialFolder; diff --git a/mailnews/base/src/nsMsgRDFUtils.h b/mailnews/base/src/nsMsgRDFUtils.h index bde5e6c8939a..5c6134f4fe91 100644 --- a/mailnews/base/src/nsMsgRDFUtils.h +++ b/mailnews/base/src/nsMsgRDFUtils.h @@ -45,6 +45,7 @@ typedef struct _nsMsgRDFNotification { #define NC_RDF_CHILD NC_NAMESPACE_URI "child" #define NC_RDF_MESSAGECHILD NC_NAMESPACE_URI "MessageChild" #define NC_RDF_NAME NC_NAMESPACE_URI "Name" +#define NC_RDF_FOLDERTREENAME NC_NAMESPACE_URI "FolderTreeName" #define NC_RDF_FOLDER NC_NAMESPACE_URI "Folder" #define NC_RDF_SPECIALFOLDER NC_NAMESPACE_URI "SpecialFolder" #define NC_RDF_SERVERTYPE NC_NAMESPACE_URI "ServerType" @@ -59,6 +60,7 @@ typedef struct _nsMsgRDFNotification { #define NC_RDF_SENDER_COLLATION_SORT NC_NAMESPACE_URI "Sender?collation=true" #define NC_RDF_NAME_SORT NC_NAMESPACE_URI "Name?sort=true" +#define NC_RDF_FOLDERTREENAME_SORT NC_NAMESPACE_URI "FolderTreeName?sort=true" //Folder Commands #define NC_RDF_DELETE NC_NAMESPACE_URI "Delete" diff --git a/mailnews/base/util/nsMsgFolder.cpp b/mailnews/base/util/nsMsgFolder.cpp index b9ea358f58b7..326713c499c1 100644 --- a/mailnews/base/util/nsMsgFolder.cpp +++ b/mailnews/base/util/nsMsgFolder.cpp @@ -481,6 +481,12 @@ NS_IMETHODIMP nsMsgFolder::SetName(const PRUnichar * name) return NS_OK; } +//For default, just return name +NS_IMETHODIMP nsMsgFolder::GetAbbreviatedName(PRUnichar * *aAbbreviatedName) +{ + return GetName(aAbbreviatedName); +} + NS_IMETHODIMP nsMsgFolder::GetChildNamed(const char *name, nsISupports ** aChild) { NS_ASSERTION(aChild, "NULL child"); diff --git a/mailnews/news/src/nsNewsFolder.cpp b/mailnews/news/src/nsNewsFolder.cpp index 33383f077e5a..fe54ff528d79 100644 --- a/mailnews/news/src/nsNewsFolder.cpp +++ b/mailnews/news/src/nsNewsFolder.cpp @@ -544,38 +544,39 @@ nsMsgNewsFolder::GetChildNamed(const char *name, nsISupports ** aChild) return NS_OK; } -NS_IMETHODIMP nsMsgNewsFolder::GetPrettyName(PRUnichar ** prettyName) +NS_IMETHODIMP nsMsgNewsFolder::GetAbbreviatedName(PRUnichar * *aAbbreviatedName) { nsresult rv = NS_OK; - if (!prettyName) + if (!aAbbreviatedName) return NS_ERROR_NULL_POINTER; - rv = nsMsgFolder::GetPrettyName(prettyName); + rv = nsMsgFolder::GetPrettyName(aAbbreviatedName); + if(NS_FAILED(rv)) return rv; - //not ready for prime time yet, as I don't know how to test this yet. -#ifdef NOT_READY_FOR_PRIME_TIME // only do this for newsgroup names, not for newsgroup hosts. PRBool isNewsServer = PR_FALSE; rv = GetIsServer(&isNewsServer); if (NS_FAILED(rv)) return rv; if (!isNewsServer) { - NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); + NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv); if (NS_FAILED(rv)) return rv; PRInt32 numFullWords; rv = prefs->GetIntPref(PREF_NEWS_ABBREVIATE_PRETTY_NAMES, &numFullWords); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + numFullWords = 1; if (numFullWords != 0) { - rv = AbbreviatePrettyName(prettyName, numFullWords); - } + rv = AbbreviatePrettyName(aAbbreviatedName, numFullWords); + } } -#endif /* NOT_READY_FOR_PRIME_TIME */ + return rv; } + // original code from Oleg Rekutin // rekusha@asan.com // Public domain, created by Oleg Rekutin @@ -597,10 +598,21 @@ nsresult nsMsgNewsFolder::AbbreviatePrettyName(PRUnichar ** prettyName, PRInt32 PRInt32 totalwords = 0; // total no. of words // get the total no. of words - for (PRInt32 pos = 0; - (pos++) != name.Length(); - pos = name.FindChar('.', PR_FALSE,pos)) - totalwords ++; + PRInt32 pos = 0; + while(1) + { + pos = name.FindChar('.', PR_FALSE, pos); + if(pos == -1) + { + totalwords++; + break; + } + else + { + totalwords++; + pos++; + } + } // get the no. of words to abbreviate PRInt32 abbrevnum = totalwords - fullwords; diff --git a/mailnews/news/src/nsNewsFolder.h b/mailnews/news/src/nsNewsFolder.h index 3d7e546657e8..5d36d746f1c9 100644 --- a/mailnews/news/src/nsNewsFolder.h +++ b/mailnews/news/src/nsNewsFolder.h @@ -64,8 +64,7 @@ public: NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos); NS_IMETHOD GetChildNamed(const char* name, nsISupports ** aChild); - - NS_IMETHOD GetPrettyName(PRUnichar ** prettyName); // Override of the base, for top-level news folder + NS_IMETHODIMP GetAbbreviatedName(PRUnichar * *aAbbreviatedName); NS_IMETHOD GetFolderURL(char **url);