From a624232f7926d818aba165e72b1814e2e0899cbe Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Fri, 18 May 2001 00:53:21 +0000 Subject: [PATCH] add ability to persist view info r=naving, sr=sspitzer part of work for 12896 --- mailnews/base/public/nsIMsgDBView.idl | 4 - .../base/resources/content/commandglue.js | 24 ++++-- .../base/resources/content/folderPane.xul | 2 +- .../resources/content/msgSelectOffline.xul | 3 +- mailnews/base/resources/content/threadPane.js | 15 ---- mailnews/base/src/nsMsgDBView.cpp | 33 +++++++- mailnews/base/src/nsMsgDBView.h | 1 + mailnews/base/src/nsMsgThreadedDBView.cpp | 2 +- mailnews/db/msgdb/public/nsDBFolderInfo.h | 11 +-- mailnews/db/msgdb/public/nsIDBFolderInfo.idl | 6 ++ mailnews/db/msgdb/public/nsIMsgDatabase.idl | 2 +- mailnews/db/msgdb/src/nsDBFolderInfo.cpp | 77 +++++++++++++------ mailnews/db/msgdb/src/nsMsgDatabase.cpp | 13 ++-- mailnews/public/MailNewsTypes2.idl | 4 + 14 files changed, 128 insertions(+), 69 deletions(-) diff --git a/mailnews/base/public/nsIMsgDBView.idl b/mailnews/base/public/nsIMsgDBView.idl index b4cd88b96aa..777ded382bc 100644 --- a/mailnews/base/public/nsIMsgDBView.idl +++ b/mailnews/base/public/nsIMsgDBView.idl @@ -29,13 +29,9 @@ interface nsIMessenger; interface nsIMsgDBHdr; interface nsIMsgDBViewCommandUpdater; -typedef long nsMsgViewSortOrderValue; -typedef long nsMsgViewSortTypeValue; -typedef long nsMsgViewTypeValue; typedef long nsMsgViewNotificationCodeValue; typedef long nsMsgViewCommandCheckStateValue; typedef long nsMsgViewCommandTypeValue; -typedef long nsMsgViewFlagsTypeValue; typedef long nsMsgNavigationTypeValue; [scriptable, uuid(682a18be-fd18-11d4-a5be-0060b0fc04b7)] diff --git a/mailnews/base/resources/content/commandglue.js b/mailnews/base/resources/content/commandglue.js index 7bd5c5c349c..10b69f1fe29 100644 --- a/mailnews/base/resources/content/commandglue.js +++ b/mailnews/base/resources/content/commandglue.js @@ -107,11 +107,24 @@ function ChangeFolderByDOMNode(folderNode) dump(uri + "\n"); if (!uri) return; - var sortType = folderNode.getAttribute('sortType'); - var sortOrder = folderNode.getAttribute('sortOrder'); - var viewFlags = folderNode.getAttribute('viewFlags'); - var viewType = folderNode.getAttribute('viewType'); - + var sortType = 0; + var sortOrder = 0; + var viewFlags = 0; + var viewType = 0; + var resource = RDF.GetResource(uri); + var msgfolder = resource.QueryInterface(Components.interfaces.nsIMsgFolder); + if (msgfolder) + { + var msgdb = msgfolder.getMsgDatabase(msgWindow); + if (msgdb) + { + var dbFolderInfo = msgdb.dBFolderInfo; + sortType = dbFolderInfo.sortType; + sortOrder = dbFolderInfo.sortOrder; + viewFlags = dbFolderInfo.viewFlags; + viewType = dbFolderInfo.viewType; + } + } ChangeFolderByURI(uri, viewType, viewFlags, sortType, sortOrder); } @@ -600,7 +613,6 @@ function CreateDBView(msgFolder, viewType, viewFlags, sortType, sortOrder) gDBView.supressMsgDisplay = IsThreadAndMessagePaneSplitterCollapsed(); UpdateSortIndicators(gCurSortType, sortOrder); - PersistViewAttributesOnFolder(); } function SetViewFlags(viewFlags) diff --git a/mailnews/base/resources/content/folderPane.xul b/mailnews/base/resources/content/folderPane.xul index 9edd0fccf8b..bfcdef967aa 100644 --- a/mailnews/base/resources/content/folderPane.xul +++ b/mailnews/base/resources/content/folderPane.xul @@ -59,7 +59,7 @@ CanSubscribe="rdf:http://home.netscape.com/NC-rdf#CanSubscribe" CanFileMessages="rdf:http://home.netscape.com/NC-rdf#CanFileMessages" NoSelect="rdf:http://home.netscape.com/NC-rdf#NoSelect" - persist="open viewType viewFlags sortOrder sortType"> + persist="open"> + Synchronize="rdf:http://home.netscape.com/NC-rdf#Synchronize"> diff --git a/mailnews/base/resources/content/threadPane.js b/mailnews/base/resources/content/threadPane.js index 15e72eeb6f9..a6daf7a88f6 100644 --- a/mailnews/base/resources/content/threadPane.js +++ b/mailnews/base/resources/content/threadPane.js @@ -102,18 +102,6 @@ function HandleColumnClick(columnID) } } -function PersistViewAttributesOnFolder() -{ - var folder = GetSelectedFolder(); - - if (folder) { - folder.setAttribute("viewType", gDBView.viewType); - folder.setAttribute("viewFlags", gDBView.viewFlags); - folder.setAttribute("sortType", gDBView.sortType); - folder.setAttribute("sortOrder", gDBView.sortOrder); - } -} - function MsgComposeDraftMessage() { var loadedFolder = GetLoadedMsgFolder(); @@ -215,7 +203,6 @@ function MsgSortThreadPane(sortType) var dbview = GetDBView(); dbview.sort(sortType, nsMsgViewSortOrder.ascending); UpdateSortIndicators(sortType, nsMsgViewSortOrder.ascending); - PersistViewAttributesOnFolder(); } function MsgReverseSortThreadPane() @@ -234,7 +221,6 @@ function MsgSortAscending() var dbview = GetDBView(); dbview.sort(dbview.sortType, nsMsgViewSortOrder.ascending); UpdateSortIndicators(dbview.sortType, nsMsgViewSortOrder.ascending); - PersistViewAttributesOnFolder(); } function MsgSortDescending() @@ -242,7 +228,6 @@ function MsgSortDescending() var dbview = GetDBView(); dbview.sort(dbview.sortType, nsMsgViewSortOrder.descending); UpdateSortIndicators(dbview.sortType, nsMsgViewSortOrder.descending); - PersistViewAttributesOnFolder(); } function UpdateSortIndicators(sortType, sortOrder) diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index 451c26f749c..141ac22ef96 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -1062,6 +1062,7 @@ NS_IMETHODIMP nsMsgDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTypeValue sor m_viewFlags = viewFlags; m_sortOrder = sortOrder; m_sortType = sortType; + nsMsgViewTypeValue viewType; if (folder) // search view will have a null folder { @@ -1070,6 +1071,12 @@ NS_IMETHODIMP nsMsgDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTypeValue sor NS_ENSURE_SUCCESS(rv,rv); m_db->AddListener(this); m_folder = folder; + // save off sort type and order, view type and flags + folderInfo->SetSortType(sortType); + folderInfo->SetSortOrder(sortOrder); + folderInfo->SetViewFlags(viewFlags); + GetViewType(&viewType); + folderInfo->SetViewType(viewType); // determine if we are in a news folder or not. // if yes, we'll show lines instead of size, and special icons in the thread pane @@ -2124,16 +2131,36 @@ nsMsgDBView::GetLocationCollationKey(nsIMsgHdr *msgHdr, PRUint8 **result, PRUint return NS_OK; } +nsresult nsMsgDBView::SaveSortInfo(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder) +{ + if (m_folder) + { + nsCOMPtr folderInfo; + nsresult rv = m_folder->GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(m_db)); + if (NS_SUCCEEDED(rv) && folderInfo) + { + // save off sort type and order, view type and flags + folderInfo->SetSortType(sortType); + folderInfo->SetSortOrder(sortOrder); + } + } + return NS_OK; +} + NS_IMETHODIMP nsMsgDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder) { nsresult rv; - if (m_sortType == sortType && m_sortValid) { - if (m_sortOrder == sortOrder) { + if (m_sortType == sortType && m_sortValid) + { + if (m_sortOrder == sortOrder) + { // same as it ever was. do nothing return NS_OK; } - else { + else + { + SaveSortInfo(sortType, sortOrder); if (m_sortType != nsMsgViewSortType::byThread) { rv = ReverseSort(); NS_ENSURE_SUCCESS(rv,rv); diff --git a/mailnews/base/src/nsMsgDBView.h b/mailnews/base/src/nsMsgDBView.h index e3aaca12b15..3ae02de3f21 100644 --- a/mailnews/base/src/nsMsgDBView.h +++ b/mailnews/base/src/nsMsgDBView.h @@ -168,6 +168,7 @@ protected: nsresult ExpansionDelta(nsMsgViewIndex index, PRInt32 *expansionDelta); nsresult ReverseSort(); nsresult ReverseThreads(); + nsresult SaveSortInfo(nsMsgViewSortTypeValue sortType, nsMsgViewSortOrderValue sortOrder); nsMsgKey GetAt(nsMsgViewIndex index) ; nsMsgViewIndex FindViewIndex(nsMsgKey key) diff --git a/mailnews/base/src/nsMsgThreadedDBView.cpp b/mailnews/base/src/nsMsgThreadedDBView.cpp index 017f7024237..9a35df90b29 100644 --- a/mailnews/base/src/nsMsgThreadedDBView.cpp +++ b/mailnews/base/src/nsMsgThreadedDBView.cpp @@ -139,6 +139,7 @@ NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgVi { if (sortType == nsMsgViewSortType::byThread) { + SaveSortInfo(sortType, sortOrder); m_sortType = sortType; m_viewFlags |= nsMsgViewFlagsType::kThreadedDisplay; if ( m_havePrevView) @@ -150,7 +151,6 @@ NS_IMETHODIMP nsMsgThreadedDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgVi m_flags.InsertAt(0, &m_prevFlags); m_levels.RemoveAll(); m_levels.InsertAt(0, &m_prevLevels); - // m_messageDB->SetSortInfo(sortType, sortOrder); m_sortValid = PR_TRUE; // the sort may have changed the number of rows diff --git a/mailnews/db/msgdb/public/nsDBFolderInfo.h b/mailnews/db/msgdb/public/nsDBFolderInfo.h index 5702f7833d1..2d2915dbb55 100644 --- a/mailnews/db/msgdb/public/nsDBFolderInfo.h +++ b/mailnews/db/msgdb/public/nsDBFolderInfo.h @@ -44,7 +44,7 @@ class nsMsgDatabase; class nsDBFolderInfo : public nsIDBFolderInfo { public: -// friend class nsMsgDatabase; + friend class nsMsgDatabase; nsDBFolderInfo(nsMsgDatabase *mdb); virtual ~nsDBFolderInfo(); @@ -61,11 +61,6 @@ public: nsMsgKey GetLateredAt(PRInt32 laterIndex, PRTime pUntil); void RemoveLateredAt(PRInt32 laterIndex); - void SetViewType(PRInt32 viewType); - PRInt32 GetViewType(); - // we would like to just store the property name we're sorted by - void SetSortInfo(nsMsgSortType, nsMsgSortOrder); - void GetSortInfo(nsMsgSortType *, nsMsgSortOrder *); PRBool TestFlag(PRInt32 flags); PRInt16 GetIMAPHierarchySeparator() ; void SetIMAPHierarchySeparator(PRInt16 hierarchySeparator) ; @@ -103,10 +98,9 @@ protected: nsMsgKey m_lastMessageLoaded; // set by the FE's to remember the last loaded message PRUint16 m_version; // for upgrading... - PRInt32 m_sortType; // the last sort type open on this db. PRInt16 m_csid; // default csid for these messages PRInt16 m_IMAPHierarchySeparator; // imap path separator - PRInt8 m_sortOrder; // the last sort order (up or down + // mail only (for now) // IMAP only @@ -116,7 +110,6 @@ protected: // news only (for now) nsMsgKey m_expiredMark; // Highest invalid article number in group - for expiring - PRInt32 m_viewType; // for news, the last view type open on this db. // the db folder info will have to know what db and row it belongs to, since it is really // just a wrapper around the singleton folder info row in the mdb. nsMsgDatabase *m_mdb; diff --git a/mailnews/db/msgdb/public/nsIDBFolderInfo.idl b/mailnews/db/msgdb/public/nsIDBFolderInfo.idl index bf01ef7b829..b27e028bf8f 100644 --- a/mailnews/db/msgdb/public/nsIDBFolderInfo.idl +++ b/mailnews/db/msgdb/public/nsIDBFolderInfo.idl @@ -53,6 +53,12 @@ interface nsIDBFolderInfo : nsISupports { attribute long ImapTotalPendingMessages; attribute long ImapUnreadPendingMessages; attribute wchar IMAPHierarchySeparator; + + attribute nsMsgViewTypeValue viewType; + attribute nsMsgViewFlagsTypeValue viewFlags; + attribute nsMsgViewSortTypeValue sortType; + attribute nsMsgViewSortOrderValue sortOrder; + void ChangeExpungedBytes(in long delta); void GetCharPtrProperty(in string propertyName, out string resultProperty); diff --git a/mailnews/db/msgdb/public/nsIMsgDatabase.idl b/mailnews/db/msgdb/public/nsIMsgDatabase.idl index e911c076af5..64cc42c96eb 100644 --- a/mailnews/db/msgdb/public/nsIMsgDatabase.idl +++ b/mailnews/db/msgdb/public/nsIMsgDatabase.idl @@ -100,7 +100,7 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer { // In 4.x, it was mainly used to remove corrupted databases. void ForceClosed(); - readonly attribute nsIDBFolderInfo DBFolderInfo; + readonly attribute nsIDBFolderInfo dBFolderInfo; // get a message header for the given key. Caller must release()! diff --git a/mailnews/db/msgdb/src/nsDBFolderInfo.cpp b/mailnews/db/msgdb/src/nsDBFolderInfo.cpp index 36cafa2a7de..9965730626a 100644 --- a/mailnews/db/msgdb/src/nsDBFolderInfo.cpp +++ b/mailnews/db/msgdb/src/nsDBFolderInfo.cpp @@ -28,6 +28,8 @@ #include "nsIPref.h" #include "nsIObserver.h" #include "nsIObserverService.h" +#include "nsIMsgDBView.h" + static const char *kDBFolderInfoScope = "ns:msg:db:row:scope:dbfolderinfo:all"; static const char *kDBFolderInfoTableKind = "ns:msg:db:table:kind:dbfolderinfo"; @@ -138,7 +140,6 @@ nsDBFolderInfo::nsDBFolderInfo(nsMsgDatabase *mdb) : m_flags(0), m_lastMessageLoaded(0), m_expiredMark(0), - m_viewType(0), m_numVisibleMessagesColumnToken(0), m_expiredMarkColumnToken(0) { @@ -146,10 +147,8 @@ nsDBFolderInfo::nsDBFolderInfo(nsMsgDatabase *mdb) m_mdbTable = NULL; m_mdbRow = NULL; m_version = 1; // for upgrading... - m_sortType = 0; // the last sort type open on this db. m_csid = 0; // default csid for these messages m_IMAPHierarchySeparator = 0; // imap path separator - m_sortOrder = 0; // the last sort order (up or down // mail only (for now) m_folderSize = 0; m_folderDate = 0; @@ -340,7 +339,6 @@ nsresult nsDBFolderInfo::InitMDBInfo() store->StringToToken(env, kUnreadPendingMessagesColumnName, &m_unreadPendingMessagesColumnToken); store->StringToToken(env, kExpiredMarkColumnName, &m_expiredMarkColumnToken); store->StringToToken(env, kVersionColumnName, &m_versionColumnToken); - store->StringToToken(env, kNumVisibleMessagesColumnName, &m_numVisibleMessagesColumnToken); m_mdbTokensInitialized = PR_TRUE; } return ret; @@ -484,24 +482,6 @@ NS_IMETHODIMP nsDBFolderInfo::GetMailboxName(nsString *boxName) return GetPropertyWithToken(m_mailboxNameColumnToken, boxName); } -void nsDBFolderInfo::SetViewType(PRInt32 viewType) -{ - m_viewType = viewType; -} - -PRInt32 nsDBFolderInfo::GetViewType() -{ - return m_viewType; -} - -void nsDBFolderInfo::SetSortInfo(nsMsgSortType type, nsMsgSortOrder order) -{ -} - -void nsDBFolderInfo::GetSortInfo(nsMsgSortType *type, nsMsgSortOrder *orde) -{ -} - NS_IMETHODIMP nsDBFolderInfo::ChangeNumNewMessages(PRInt32 delta) { m_numNewMessages += delta; @@ -774,6 +754,59 @@ void nsDBFolderInfo::ChangeImapUnreadPendingMessages(PRInt32 delta) SetInt32PropertyWithToken(m_unreadPendingMessagesColumnToken, m_unreadPendingMessages); } +/* attribute nsMsgViewTypeValue viewType; */ +NS_IMETHODIMP nsDBFolderInfo::GetViewType(nsMsgViewTypeValue *aViewType) +{ + PRUint32 viewTypeValue; + nsresult rv = GetUint32Property("viewType", &viewTypeValue, nsMsgViewType::eShowAllThreads); + *aViewType = viewTypeValue; + return rv; +} +NS_IMETHODIMP nsDBFolderInfo::SetViewType(nsMsgViewTypeValue aViewType) +{ + return SetUint32Property("viewType", aViewType); +} + +/* attribute nsMsgViewFlagsTypeValue viewFlags; */ +NS_IMETHODIMP nsDBFolderInfo::GetViewFlags(nsMsgViewFlagsTypeValue *aViewFlags) +{ + PRUint32 viewFlagsValue; + nsresult rv = GetUint32Property("viewFlags", &viewFlagsValue, nsMsgViewFlagsType::kNone); + *aViewFlags = viewFlagsValue; + return rv; +} +NS_IMETHODIMP nsDBFolderInfo::SetViewFlags(nsMsgViewFlagsTypeValue aViewFlags) +{ + return SetUint32Property("viewFlags", aViewFlags); +} + +/* attribute nsMsgViewSortTypeValue sortType; */ +NS_IMETHODIMP nsDBFolderInfo::GetSortType(nsMsgViewSortTypeValue *aSortType) +{ + PRUint32 sortTypeValue; + nsresult rv = GetUint32Property("sortType", &sortTypeValue, nsMsgViewSortType::byDate); + *aSortType = sortTypeValue; + return rv; +} +NS_IMETHODIMP nsDBFolderInfo::SetSortType(nsMsgViewSortTypeValue aSortType) +{ + return SetUint32Property("sortType", aSortType); +} + +/* attribute nsMsgViewSortOrderValue sortOrder; */ +NS_IMETHODIMP nsDBFolderInfo::GetSortOrder(nsMsgViewSortOrderValue *aSortOrder) +{ + PRUint32 sortOrderValue; + nsresult rv = GetUint32Property("sortOrder", &sortOrderValue, nsMsgViewSortOrder::none); + *aSortOrder = sortOrderValue; + return rv; +} + +NS_IMETHODIMP nsDBFolderInfo::SetSortOrder(nsMsgViewSortOrderValue aSortOrder) +{ + return SetUint32Property("sortOrder", aSortOrder); +} + NS_IMETHODIMP nsDBFolderInfo::SetKnownArtsSet(nsString *newsArtSet) { diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index 95eac2749aa..d98d0fbce5b 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -965,7 +965,9 @@ NS_IMETHODIMP nsMsgDatabase::ForceClosed() NotifyAnnouncerGoingAway(); // OK, remove from cache first and close the store. // RemoveFromCache(this); - + // clear out db ptr in folder info; it's about to be invalid + if (m_dbFolderInfo) + m_dbFolderInfo->m_mdb = nsnull; NS_IF_RELEASE(m_dbFolderInfo); m_dbFolderInfo = nsnull; @@ -982,6 +984,7 @@ NS_IMETHODIMP nsMsgDatabase::ForceClosed() if (m_mdbStore) { m_mdbStore->CloseMdbObject(m_mdbEnv); + m_mdbEnv = nsnull; m_mdbStore = nsnull; } Release(); @@ -991,11 +994,11 @@ NS_IMETHODIMP nsMsgDatabase::ForceClosed() // caller must Release result. NS_IMETHODIMP nsMsgDatabase::GetDBFolderInfo(nsIDBFolderInfo **result) { - *result = m_dbFolderInfo; - if (m_dbFolderInfo) + *result = m_dbFolderInfo; + if (m_dbFolderInfo) { - m_dbFolderInfo->AddRef(); - return NS_OK; + m_dbFolderInfo->AddRef(); + return NS_OK; } else { diff --git a/mailnews/public/MailNewsTypes2.idl b/mailnews/public/MailNewsTypes2.idl index 0612aa1481c..ce4f2d0aaa4 100644 --- a/mailnews/public/MailNewsTypes2.idl +++ b/mailnews/public/MailNewsTypes2.idl @@ -37,3 +37,7 @@ interface nsMsgPriority { const nsMsgPriorityValue highest = 6; }; +typedef long nsMsgViewSortOrderValue; +typedef long nsMsgViewSortTypeValue; +typedef long nsMsgViewTypeValue; +typedef long nsMsgViewFlagsTypeValue;