From 02c3dc55078edfe42d8256742534462d453664c9 Mon Sep 17 00:00:00 2001 From: "bienvenu%nventure.com" Date: Fri, 6 Jan 2006 18:44:35 +0000 Subject: [PATCH] fix crash in nsMsgGroupView::~nsMsgGroupView() by storing the group by date thread subjects per view, 301308 patch by b.jacques@planet.nl, sr=bienvenu, also add grouping by hasAttachment to fix crash when user accidentally gets into group by attachment mode --- mailnews/base/src/nsMsgGroupView.cpp | 61 ++++++++++++++-------------- mailnews/base/src/nsMsgGroupView.h | 11 ++--- 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/mailnews/base/src/nsMsgGroupView.cpp b/mailnews/base/src/nsMsgGroupView.cpp index dbdad3406750..ce188eb2084e 100755 --- a/mailnews/base/src/nsMsgGroupView.cpp +++ b/mailnews/base/src/nsMsgGroupView.cpp @@ -48,38 +48,14 @@ #define MSGHDR_CACHE_MAX_SIZE 8192 // Max msghdr cache entries. #define MSGHDR_CACHE_DEFAULT_SIZE 100 -PRUnichar * nsMsgGroupView::kTodayString = nsnull; -PRUnichar * nsMsgGroupView::kYesterdayString = nsnull; -PRUnichar * nsMsgGroupView::kLastWeekString = nsnull; -PRUnichar * nsMsgGroupView::kTwoWeeksAgoString = nsnull; -PRUnichar * nsMsgGroupView::kOldMailString = nsnull; - nsMsgGroupView::nsMsgGroupView() { - if (!kTodayString) - { - // priority strings - kTodayString = GetString(NS_LITERAL_STRING("today").get()); - kYesterdayString = GetString(NS_LITERAL_STRING("yesterday").get()); - kLastWeekString = GetString(NS_LITERAL_STRING("lastWeek").get()); - kTwoWeeksAgoString = GetString(NS_LITERAL_STRING("twoWeeksAgo").get()); - kOldMailString = GetString(NS_LITERAL_STRING("older").get()); - } m_dayChanged = PR_FALSE; m_lastCurExplodedTime.tm_mday = 0; } nsMsgGroupView::~nsMsgGroupView() { - // release our global strings - if (gInstanceCount <= 1) - { - nsCRT::free(kTodayString); - nsCRT::free(kYesterdayString); - nsCRT::free(kLastWeekString); - nsCRT::free(kTwoWeeksAgoString); - nsCRT::free(kOldMailString); - } } NS_IMETHODIMP nsMsgGroupView::Open(nsIMsgFolder *aFolder, nsMsgViewSortTypeValue aSortType, nsMsgViewSortOrderValue aSortOrder, nsMsgViewFlagsTypeValue aViewFlags, PRInt32 *aCount) @@ -177,6 +153,12 @@ nsHashKey *nsMsgGroupView::AllocHashKeyForHdr(nsIMsgDBHdr *msgHdr) return new nsPRUint32Key(label); } break; + case nsMsgViewSortType::byAttachments: + { + PRUint32 flags; + msgHdr->GetFlags(&flags); + return new nsPRUint32Key(flags & MSG_FLAG_ATTACHMENT ? 1 : 0); + } case nsMsgViewSortType::byPriority: { nsMsgPriorityValue priority; @@ -348,7 +330,7 @@ NS_IMETHODIMP nsMsgGroupView::OpenWithHdrs(nsISimpleEnumerator *aHeaders, nsMsgV nsresult rv = NS_OK; if (aSortType == nsMsgViewSortType::byThread || aSortType == nsMsgViewSortType::byId - || aSortType == nsMsgViewSortType::byNone) + || aSortType == nsMsgViewSortType::byNone || aSortType == nsMsgViewSortType::bySize) return NS_ERROR_INVALID_ARG; m_sortType = aSortType; @@ -638,19 +620,29 @@ NS_IMETHODIMP nsMsgGroupView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsA switch (((nsPRUint32Key *)hashKey)->GetValue()) { case 1: - aValue.Assign(kTodayString); + if (!m_kTodayString.get()) + m_kTodayString.Adopt(GetString(NS_LITERAL_STRING("today").get())); + aValue.Assign(m_kTodayString); break; case 2: - aValue.Assign(kYesterdayString); + if (!m_kYesterdayString.get()) + m_kYesterdayString.Adopt(GetString(NS_LITERAL_STRING("yesterday").get())); + aValue.Assign(m_kYesterdayString); break; case 3: - aValue.Assign(kLastWeekString); + if (!m_kLastWeekString.get()) + m_kLastWeekString.Adopt(GetString(NS_LITERAL_STRING("lastWeek").get())); + aValue.Assign(m_kLastWeekString); break; case 4: - aValue.Assign(kTwoWeeksAgoString); + if (!m_kTwoWeeksAgoString.get()) + m_kTwoWeeksAgoString.Adopt(GetString(NS_LITERAL_STRING("twoWeeksAgo").get())); + aValue.Assign(m_kTwoWeeksAgoString); break; case 5: - aValue.Assign(kOldMailString); + if (!m_kOldMailString.get()) + m_kOldMailString.Adopt(GetString(NS_LITERAL_STRING("older").get())); + aValue.Assign(m_kOldMailString); break; default: NS_ASSERTION(PR_FALSE, "bad age thread"); @@ -688,6 +680,12 @@ NS_IMETHODIMP nsMsgGroupView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsA FetchRecipients(msgHdr, getter_Copies(valueText)); aValue.Assign(valueText); break; + case nsMsgViewSortType::byAttachments: + valueText.Adopt(GetString(((nsPRUint32Key *)hashKey)->GetValue() + ? NS_LITERAL_STRING("attachments").get() + : NS_LITERAL_STRING("noAttachments").get())); + aValue.Assign(valueText); + break; default: NS_ASSERTION(PR_FALSE, "we don't sort by group for this type"); break; @@ -762,7 +760,8 @@ nsresult nsMsgGroupView::GetThreadContainingMsgHdr(nsIMsgDBHdr *msgHdr, nsIMsgTh return (*pThread) ? NS_OK : NS_ERROR_FAILURE; } -PRInt32 nsMsgGroupView::FindLevelInThread(nsIMsgDBHdr *msgHdr, nsMsgViewIndex startOfThread, nsMsgViewIndex viewIndex) +PRInt32 nsMsgGroupView::FindLevelInThread(nsIMsgDBHdr *msgHdr, + nsMsgViewIndex startOfThread, nsMsgViewIndex viewIndex) { return (startOfThread == viewIndex) ? 0 : 1; } diff --git a/mailnews/base/src/nsMsgGroupView.h b/mailnews/base/src/nsMsgGroupView.h index 00a2d49d6870..a84039f859b6 100755 --- a/mailnews/base/src/nsMsgGroupView.h +++ b/mailnews/base/src/nsMsgGroupView.h @@ -81,10 +81,11 @@ protected: PRExplodedTime m_lastCurExplodedTime; PRBool m_dayChanged; - static PRUnichar* kTodayString; - static PRUnichar* kYesterdayString; - static PRUnichar* kLastWeekString; - static PRUnichar* kTwoWeeksAgoString; - static PRUnichar* kOldMailString; +private: + nsXPIDLString m_kTodayString; + nsXPIDLString m_kYesterdayString; + nsXPIDLString m_kLastWeekString; + nsXPIDLString m_kTwoWeeksAgoString; + nsXPIDLString m_kOldMailString; };