fix crash in secondary sort when multiple int32 fields have the same value, sr=mscott, 57898

This commit is contained in:
bienvenu%nventure.com 2007-08-03 23:02:36 +00:00
Родитель e19117da6e
Коммит 919145210f
1 изменённых файлов: 49 добавлений и 29 удалений

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

@ -22,6 +22,7 @@
* Contributor(s): * Contributor(s):
* Jan Varga (varga@ku.sk) * Jan Varga (varga@ku.sk)
* Håkan Waara (hwaara@chello.se) * Håkan Waara (hwaara@chello.se)
* Jeremy Morton (bugzilla@game-point.net)
* *
* Alternatively, the contents of this file may be used under the terms of * Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"), * either of the GNU General Public License Version 2 or later (the "GPL"),
@ -456,17 +457,34 @@ nsresult nsMsgDBView::FetchSubject(nsIMsgDBHdr * aMsgHdr, PRUint32 aFlags, nsASt
} }
// in case we want to play around with the date string, I've broken it out into // in case we want to play around with the date string, I've broken it out into
// a separate routine. // a separate routine. Set rcvDate to PR_TRUE to get the Received: date instead
nsresult nsMsgDBView::FetchDate(nsIMsgDBHdr * aHdr, nsAString &aDateString) // of the Date: date.
nsresult nsMsgDBView::FetchDate(nsIMsgDBHdr * aHdr, nsAString &aDateString, PRBool rcvDate)
{ {
PRTime dateOfMsg; PRTime dateOfMsg;
PRTime dateOfMsgLocal; PRTime dateOfMsgLocal;
PRUint32 rcvDateSecs;
nsresult rv;
if (!mDateFormater) if (!mDateFormater)
mDateFormater = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID); mDateFormater = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID);
NS_ENSURE_TRUE(mDateFormater, NS_ERROR_FAILURE); NS_ENSURE_TRUE(mDateFormater, NS_ERROR_FAILURE);
nsresult rv = aHdr->GetDate(&dateOfMsg); if (!rcvDate)
rv = aHdr->GetDate(&dateOfMsg);
else
{
rv = aHdr->GetUint32Property("dateReceived", &rcvDateSecs);
if (rcvDateSecs == 0)
{
// No Received header!
nsAutoString formattedRcvdString;
formattedRcvdString.AssignLiteral("");
aDateString = formattedRcvdString;
return rv;
}
Seconds2PRTime(rcvDateSecs, &dateOfMsg);
}
PRTime currentTime = PR_Now(); PRTime currentTime = PR_Now();
PRExplodedTime explodedCurrentTime; PRExplodedTime explodedCurrentTime;
@ -486,10 +504,9 @@ nsresult nsMsgDBView::FetchDate(nsIMsgDBHdr * aHdr, nsAString &aDateString)
// same day... // same day...
dateFormat = m_dateFormatToday; dateFormat = m_dateFormatToday;
} }
// the following chunk of code causes us to show a day instead of a number if the message was received // the following chunk of code allows us to show a day instead of a number if the message was received
// within the last 7 days. i.e. Mon 5:10pm. // within the last 7 days. i.e. Mon 5:10pm. (depending on the mail.ui.display.dateformat.thisweek pref)
// The concrete format used is dependent on a preference setting (see InitDisplayFormats), but the default // The concrete format used is dependent on a preference setting (see InitDisplayFormats).
// is the format described above.
else if (LL_CMP(currentTime, >, dateOfMsg)) else if (LL_CMP(currentTime, >, dateOfMsg))
{ {
// some constants for calculation // some constants for calculation
@ -1733,8 +1750,11 @@ NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, nsITreeColumn* aCol, nsAStr
rv = FetchStatus(flags, aValue); rv = FetchStatus(flags, aValue);
} }
break; break;
case 'r': // recipient case 'r':
rv = FetchRecipients(msgHdr, aValue); if (colID[3] == 'i') // recipient
rv = FetchRecipients(msgHdr, aValue);
else if (colID[3] == 'e') // received
rv = FetchDate(msgHdr, aValue, PR_TRUE);
break; break;
case 'd': // date case 'd': // date
rv = FetchDate(msgHdr, aValue); rv = FetchDate(msgHdr, aValue);
@ -3358,6 +3378,7 @@ nsresult nsMsgDBView::GetFieldTypeAndLenForSort(nsMsgViewSortTypeValue sortType,
*pMaxLen = kMaxAuthorKey; *pMaxLen = kMaxAuthorKey;
break; break;
case nsMsgViewSortType::byDate: case nsMsgViewSortType::byDate:
case nsMsgViewSortType::byReceived:
case nsMsgViewSortType::byPriority: case nsMsgViewSortType::byPriority:
case nsMsgViewSortType::byThread: case nsMsgViewSortType::byThread:
case nsMsgViewSortType::byId: case nsMsgViewSortType::byId:
@ -3504,6 +3525,9 @@ nsresult nsMsgDBView::GetLongField(nsIMsgDBHdr *msgHdr, nsMsgViewSortTypeValue s
else else
rv = msgHdr->GetDateInSeconds(result); rv = msgHdr->GetDateInSeconds(result);
break; break;
case nsMsgViewSortType::byReceived:
rv = msgHdr->GetUint32Property("dateReceived", result); // Already in seconds...
break;
case nsMsgViewSortType::byCustom: case nsMsgViewSortType::byCustom:
if (colHandler != nsnull) if (colHandler != nsnull)
{ {
@ -3983,30 +4007,26 @@ NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOr
qsPrivateData.isSecondarySort = PR_FALSE; qsPrivateData.isSecondarySort = PR_FALSE;
qsPrivateData.ascendingSort = (sortOrder == nsMsgViewSortOrder::ascending); qsPrivateData.ascendingSort = (sortOrder == nsMsgViewSortOrder::ascending);
// do the sort nsCOMPtr <nsIMsgDatabase> dbToUse = m_db;
switch (fieldType)
if (!dbToUse) // probably search view
GetDBForViewIndex(0, getter_AddRefs(dbToUse));
qsPrivateData.db = dbToUse;
if (dbToUse)
{ {
case kCollationKey: // do the sort
switch (fieldType)
{ {
case kCollationKey:
nsCOMPtr <nsIMsgDatabase> dbToUse = m_db;
if (!dbToUse) // probably search view
GetDBForViewIndex(0, getter_AddRefs(dbToUse));
if (dbToUse)
{
qsPrivateData.db = dbToUse;
NS_QuickSort(pPtrBase, numSoFar, sizeof(IdKey*), FnSortIdKey, &qsPrivateData); NS_QuickSort(pPtrBase, numSoFar, sizeof(IdKey*), FnSortIdKey, &qsPrivateData);
} break;
case kU32:
NS_QuickSort(pPtrBase, numSoFar, sizeof(IdKey*), FnSortIdDWord, &qsPrivateData);
break;
default:
NS_ASSERTION(0, "not supposed to get here");
break;
} }
break;
case kU32:
NS_QuickSort(pPtrBase, numSoFar, sizeof(IdKey*), FnSortIdDWord, &qsPrivateData);
break;
default:
NS_ASSERTION(0, "not supposed to get here");
break;
} }
// now put the IDs into the array in proper order // now put the IDs into the array in proper order