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

This commit is contained in:
bienvenu%nventure.com 2006-01-06 18:44:35 +00:00
Родитель ed0267097b
Коммит 02c3dc5507
2 изменённых файлов: 36 добавлений и 36 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
};