Back to index

lightning-sunbird  0.9+nobinonly
nsMsgSpecialViews.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "msgCore.h"
00039 #include "nsMsgSpecialViews.h"
00040 #include "nsIMsgThread.h"
00041 
00042 nsMsgThreadsWithUnreadDBView::nsMsgThreadsWithUnreadDBView()
00043 {
00044 }
00045 
00046 nsMsgThreadsWithUnreadDBView::~nsMsgThreadsWithUnreadDBView()
00047 {
00048 }
00049 
00050 NS_IMETHODIMP nsMsgThreadsWithUnreadDBView::GetViewType(nsMsgViewTypeValue *aViewType)
00051 {
00052     NS_ENSURE_ARG_POINTER(aViewType);
00053     *aViewType = nsMsgViewType::eShowThreadsWithUnread;
00054     return NS_OK;
00055 }
00056 
00057 PRBool nsMsgThreadsWithUnreadDBView::WantsThisThread(nsIMsgThread *threadHdr)
00058 {
00059        if (threadHdr)
00060   {
00061     PRUint32 numNewChildren;
00062 
00063     threadHdr->GetNumUnreadChildren(&numNewChildren);
00064     if (numNewChildren > 0) 
00065       return PR_TRUE;
00066   }
00067   return PR_FALSE;
00068 }
00069 
00070 nsresult nsMsgThreadsWithUnreadDBView::AddMsgToThreadNotInView(nsIMsgThread *threadHdr, nsIMsgDBHdr *msgHdr, PRBool ensureListed)
00071 {
00072   nsresult rv = NS_OK;
00073 
00074   nsCOMPtr <nsIMsgDBHdr> parentHdr;
00075   PRUint32 msgFlags;
00076   msgHdr->GetFlags(&msgFlags);
00077   GetFirstMessageHdrToDisplayInThread(threadHdr, getter_AddRefs(parentHdr));
00078   if (parentHdr && (ensureListed || !(msgFlags & MSG_FLAG_READ)))
00079   {
00080     nsMsgKey key;
00081     PRUint32 numMsgsInThread;
00082     rv = AddHdr(parentHdr);
00083     threadHdr->GetNumChildren(&numMsgsInThread);
00084     if (numMsgsInThread > 1)
00085     {
00086       parentHdr->GetMessageKey(&key);
00087       nsMsgViewIndex viewIndex = FindViewIndex(key);
00088       if (viewIndex != nsMsgViewIndex_None)
00089         OrExtraFlag(viewIndex, MSG_FLAG_ELIDED | MSG_VIEW_FLAG_HASCHILDREN);
00090     }
00091   }
00092   return rv;
00093 }
00094 
00095 NS_IMETHODIMP
00096 nsMsgThreadsWithUnreadDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
00097 {
00098   nsMsgThreadsWithUnreadDBView* newMsgDBView;
00099   NS_NEWXPCOM(newMsgDBView, nsMsgThreadsWithUnreadDBView);
00100 
00101   if (!newMsgDBView)
00102     return NS_ERROR_OUT_OF_MEMORY;
00103 
00104   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
00105   NS_ENSURE_SUCCESS(rv,rv);
00106 
00107   NS_IF_ADDREF(*_retval = newMsgDBView);
00108   return NS_OK;
00109 }
00110 
00111 NS_IMETHODIMP nsMsgWatchedThreadsWithUnreadDBView::GetViewType(nsMsgViewTypeValue *aViewType)
00112 {
00113     NS_ENSURE_ARG_POINTER(aViewType);
00114     *aViewType = nsMsgViewType::eShowWatchedThreadsWithUnread;
00115     return NS_OK;
00116 }
00117 
00118 PRBool nsMsgWatchedThreadsWithUnreadDBView::WantsThisThread(nsIMsgThread *threadHdr)
00119 {
00120        if (threadHdr)
00121   {
00122     PRUint32 numNewChildren;
00123     PRUint32 threadFlags;
00124 
00125     threadHdr->GetNumUnreadChildren(&numNewChildren);
00126     threadHdr->GetFlags(&threadFlags);
00127     if (numNewChildren > 0 && (threadFlags & MSG_FLAG_WATCHED) != 0) 
00128       return PR_TRUE;
00129   }
00130   return PR_FALSE;
00131 }
00132 
00133 nsresult nsMsgWatchedThreadsWithUnreadDBView::AddMsgToThreadNotInView(nsIMsgThread *threadHdr, nsIMsgDBHdr *msgHdr, PRBool ensureListed)
00134 {
00135   nsresult rv = NS_OK;
00136   PRUint32 threadFlags;
00137   PRUint32 msgFlags;
00138   msgHdr->GetFlags(&msgFlags);
00139   threadHdr->GetFlags(&threadFlags);
00140   if (threadFlags & MSG_FLAG_WATCHED)
00141   {
00142     nsCOMPtr <nsIMsgDBHdr> parentHdr;
00143     GetFirstMessageHdrToDisplayInThread(threadHdr, getter_AddRefs(parentHdr));
00144     if (parentHdr && (ensureListed || !(msgFlags & MSG_FLAG_READ)))
00145     {
00146       PRUint32 numChildren;
00147       threadHdr->GetNumChildren(&numChildren);
00148       rv = AddHdr(parentHdr);
00149       if (numChildren > 1)
00150       {
00151         nsMsgKey key;
00152         parentHdr->GetMessageKey(&key);
00153         nsMsgViewIndex viewIndex = FindViewIndex(key);
00154         if (viewIndex != nsMsgViewIndex_None)
00155           OrExtraFlag(viewIndex, MSG_FLAG_ELIDED | MSG_VIEW_FLAG_ISTHREAD | MSG_VIEW_FLAG_HASCHILDREN | MSG_FLAG_WATCHED);
00156       }
00157     }
00158   }
00159   return rv;
00160 }
00161 
00162 NS_IMETHODIMP
00163 nsMsgWatchedThreadsWithUnreadDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
00164 {
00165   nsMsgWatchedThreadsWithUnreadDBView* newMsgDBView;
00166   NS_NEWXPCOM(newMsgDBView, nsMsgWatchedThreadsWithUnreadDBView);
00167 
00168   if (!newMsgDBView)
00169     return NS_ERROR_OUT_OF_MEMORY;
00170 
00171   nsresult rv = CopyDBView(newMsgDBView, aMessengerInstance, aMsgWindow, aCmdUpdater);
00172   NS_ENSURE_SUCCESS(rv,rv);
00173 
00174   NS_IF_ADDREF(*_retval = newMsgDBView);
00175   return NS_OK;
00176 }