Back to index

lightning-sunbird  0.9+nobinonly
nsMsgFolderDataSource.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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) 1999
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 "nsIRDFDataSource.h"
00039 #include "nsIRDFService.h"
00040 
00041 #include "nsIFolderListener.h"
00042 #include "nsMsgRDFDataSource.h"
00043 
00044 #include "nsITransactionManager.h"
00045 #include "nsCOMArray.h"
00049 class nsMsgFolderDataSource : public nsMsgRDFDataSource,
00050                               public nsIFolderListener
00051 {
00052 public:
00053   
00054   NS_DECL_ISUPPORTS_INHERITED
00055   NS_DECL_NSIFOLDERLISTENER
00056 
00057   nsMsgFolderDataSource(void);
00058   virtual ~nsMsgFolderDataSource (void);
00059   virtual nsresult Init();
00060   virtual void Cleanup();
00061 
00062   // nsIRDFDataSource methods
00063   NS_IMETHOD GetURI(char* *uri);
00064 
00065   NS_IMETHOD GetSource(nsIRDFResource* property,
00066                        nsIRDFNode* target,
00067                        PRBool tv,
00068                        nsIRDFResource** source /* out */);
00069 
00070   NS_IMETHOD GetTarget(nsIRDFResource* source,
00071                        nsIRDFResource* property,
00072                        PRBool tv,
00073                        nsIRDFNode** target);
00074 
00075   NS_IMETHOD GetSources(nsIRDFResource* property,
00076                         nsIRDFNode* target,
00077                         PRBool tv,
00078                         nsISimpleEnumerator** sources);
00079 
00080   NS_IMETHOD GetTargets(nsIRDFResource* source,
00081                         nsIRDFResource* property,    
00082                         PRBool tv,
00083                         nsISimpleEnumerator** targets);
00084 
00085   NS_IMETHOD Assert(nsIRDFResource* source,
00086                     nsIRDFResource* property, 
00087                     nsIRDFNode* target,
00088                     PRBool tv);
00089 
00090   NS_IMETHOD Unassert(nsIRDFResource* source,
00091                       nsIRDFResource* property,
00092                       nsIRDFNode* target);
00093 
00094   NS_IMETHOD HasAssertion(nsIRDFResource* source,
00095                           nsIRDFResource* property,
00096                           nsIRDFNode* target,
00097                           PRBool tv,
00098                           PRBool* hasAssertion);
00099 
00100   NS_IMETHOD HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result);
00101 
00102   NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
00103                          nsISimpleEnumerator** labels);
00104 
00105   NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
00106                           nsISimpleEnumerator** labels); 
00107 
00108   NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult);
00109 
00110   NS_IMETHOD GetAllCmds(nsIRDFResource* source,
00111                             nsISimpleEnumerator/*<nsIRDFResource>*/** commands);
00112 
00113   NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
00114                               nsIRDFResource*   aCommand,
00115                               nsISupportsArray/*<nsIRDFResource>*/* aArguments,
00116                               PRBool* aResult);
00117 
00118   NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
00119                        nsIRDFResource*   aCommand,
00120                        nsISupportsArray/*<nsIRDFResource>*/* aArguments);
00121 protected:
00122 
00123   nsresult GetSenderName(nsAutoString& sender, nsAutoString *senderUserName);
00124 
00125   nsresult createFolderNode(nsIMsgFolder *folder, nsIRDFResource* property,
00126                             nsIRDFNode **target);
00127   nsresult createFolderNameNode(nsIMsgFolder *folder, nsIRDFNode **target, PRBool sort);
00128   nsresult createFolderOpenNode(nsIMsgFolder *folder,nsIRDFNode **target);
00129   nsresult createFolderTreeNameNode(nsIMsgFolder *folder, nsIRDFNode **target);
00130   nsresult createFolderTreeSimpleNameNode(nsIMsgFolder *folder, nsIRDFNode **target);
00131   nsresult createFolderSpecialNode(nsIMsgFolder *folder, nsIRDFNode **target);
00132   nsresult createFolderServerTypeNode(nsIMsgFolder *folder,
00133                                       nsIRDFNode **target);
00134   nsresult createServerIsDeferredNode(nsIMsgFolder* folder,
00135                                       nsIRDFNode **target);
00136   nsresult createFolderRedirectorTypeNode(nsIMsgFolder *folder,
00137                                       nsIRDFNode **target);
00138   nsresult createFolderCanCreateFoldersOnServerNode(nsIMsgFolder *folder,
00139                                       nsIRDFNode **target);
00140   nsresult createFolderCanFileMessagesOnServerNode(nsIMsgFolder *folder,
00141                                       nsIRDFNode **target);
00142   nsresult createFolderIsServerNode(nsIMsgFolder *folder,
00143                                       nsIRDFNode **target);
00144   nsresult createFolderIsSecureNode(nsIMsgFolder *folder,
00145                                       nsIRDFNode **target);
00146   nsresult createFolderCanSubscribeNode(nsIMsgFolder *folder,
00147                                       nsIRDFNode **target);
00148   nsresult createFolderSupportsOfflineNode(nsIMsgFolder *folder,
00149                                       nsIRDFNode **target);
00150   nsresult createFolderCanFileMessagesNode(nsIMsgFolder *folder,
00151                                       nsIRDFNode **target);
00152   nsresult createFolderCanCreateSubfoldersNode(nsIMsgFolder *folder,
00153                                       nsIRDFNode **target);
00154   nsresult createFolderCanRenameNode(nsIMsgFolder *folder,
00155                                       nsIRDFNode **target);
00156   nsresult createFolderCanCompactNode(nsIMsgFolder *folder,
00157                                      nsIRDFNode **target);
00158   nsresult createTotalMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
00159   nsresult createUnreadMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
00160   nsresult createFolderSizeNode(nsIMsgFolder *folder, nsIRDFNode **target);
00161   nsresult createCharsetNode(nsIMsgFolder *folder, nsIRDFNode **target);
00162   nsresult createBiffStateNodeFromFolder(nsIMsgFolder *folder, nsIRDFNode **target);
00163   nsresult createBiffStateNodeFromFlag(PRUint32 flag, nsIRDFNode **target);
00164   nsresult createHasUnreadMessagesNode(nsIMsgFolder *folder, PRBool aIncludeSubfolders, nsIRDFNode **target);
00165   nsresult createNewMessagesNode(nsIMsgFolder *folder, nsIRDFNode **target);
00166   nsresult createFolderNoSelectNode(nsIMsgFolder *folder,
00167                                     nsIRDFNode **target);
00168   nsresult createFolderVirtualNode(nsIMsgFolder *folder,
00169                                     nsIRDFNode **target);
00170   nsresult createInVFEditSearchScopeNode(nsIMsgFolder* folder,
00171                                       nsIRDFNode **target);
00172   nsresult createFolderImapSharedNode(nsIMsgFolder *folder,
00173                                     nsIRDFNode **target);
00174   nsresult createFolderSynchronizeNode(nsIMsgFolder *folder, nsIRDFNode **target);
00175   nsresult createFolderSyncDisabledNode(nsIMsgFolder *folder, nsIRDFNode **target);
00176   nsresult createCanSearchMessages(nsIMsgFolder *folder,
00177                                       nsIRDFNode **target);
00178   nsresult createFolderChildNode(nsIMsgFolder *folder, nsIRDFNode **target);
00179 
00180   nsresult getFolderArcLabelsOut(nsISupportsArray **arcs);
00181   
00182   nsresult DoDeleteFromFolder(nsIMsgFolder *folder,
00183                                                    nsISupportsArray *arguments, nsIMsgWindow *msgWindow, PRBool reallyDelete);
00184 
00185   nsresult DoCopyToFolder(nsIMsgFolder *dstFolder, nsISupportsArray *arguments,
00186                                             nsIMsgWindow *msgWindow, PRBool isMove);
00187 
00188   nsresult DoFolderCopyToFolder(nsIMsgFolder *dstFolder, nsISupportsArray *arguments,
00189                                             nsIMsgWindow *msgWindow, PRBool isMoveFolder);
00190 
00191   nsresult DoNewFolder(nsIMsgFolder *folder, nsISupportsArray *arguments, 
00192                         nsIMsgWindow *window);
00193 
00194   nsresult DoFolderAssert(nsIMsgFolder *folder, nsIRDFResource *property, nsIRDFNode *target);
00195   nsresult DoFolderUnassert(nsIMsgFolder *folder, nsIRDFResource *property, nsIRDFNode *target);
00196 
00197   nsresult DoFolderHasAssertion(nsIMsgFolder *folder, nsIRDFResource *property, nsIRDFNode *target,
00198                                 PRBool tv, PRBool *hasAssertion);
00199 
00200   nsresult GetBiffStateString(PRUint32 biffState, nsCAutoString & biffStateStr);
00201 
00202   nsresult CreateUnreadMessagesNameString(PRInt32 unreadMessages, nsAutoString &nameString);
00203   nsresult CreateArcsOutEnumerator();
00204 
00205   virtual nsresult OnItemAddedOrRemoved(nsIRDFResource *parentItem, nsISupports *item, PRBool added);
00206 
00207   nsresult OnUnreadMessagePropertyChanged(nsIRDFResource *folderResource, PRInt32 oldValue, PRInt32 newValue);
00208   nsresult OnTotalMessagePropertyChanged(nsIRDFResource *folderResource, PRInt32 oldValue, PRInt32 newValue);
00209   nsresult OnFolderSizePropertyChanged(nsIRDFResource *folderResource, PRInt32 oldValue, PRInt32 newValue);
00210   nsresult NotifyFolderTreeNameChanged(nsIMsgFolder *folder, nsIRDFResource *folderResource, PRInt32 aUnreadMessages);
00211   nsresult NotifyFolderTreeSimpleNameChanged(nsIMsgFolder *folder, nsIRDFResource *folderResource);
00212   nsresult NotifyFolderNameChanged(nsIMsgFolder *folder, nsIRDFResource *folderResource);
00213   nsresult NotifyAncestors(nsIMsgFolder *aFolder, nsIRDFResource *aPropertyResource, nsIRDFNode *aNode);
00214   nsresult GetNumMessagesNode(PRInt32 numMessages, nsIRDFNode **node);
00215   nsresult GetFolderSizeNode(PRInt32 folderSize, nsIRDFNode **node);
00216   nsresult CreateLiterals(nsIRDFService *rdf);
00217 
00218   virtual nsresult GetFolderDisplayName(nsIMsgFolder *folder, PRUnichar **folderName);
00219 
00220   static nsIRDFResource* kNC_Child;
00221   static nsIRDFResource* kNC_Folder;
00222   static nsIRDFResource* kNC_Name;
00223   static nsIRDFResource* kNC_Open;
00224   static nsIRDFResource* kNC_FolderTreeName;
00225   static nsIRDFResource* kNC_FolderTreeSimpleName;
00226   static nsIRDFResource* kNC_NameSort;
00227   static nsIRDFResource* kNC_FolderTreeNameSort;
00228   static nsIRDFResource* kNC_Columns;
00229   static nsIRDFResource* kNC_MSGFolderRoot;
00230   static nsIRDFResource* kNC_SpecialFolder;
00231   static nsIRDFResource* kNC_ServerType;
00232   static nsIRDFResource* kNC_IsDeferred;
00233   static nsIRDFResource* kNC_RedirectorType;
00234   static nsIRDFResource* kNC_CanCreateFoldersOnServer;
00235   static nsIRDFResource* kNC_CanFileMessagesOnServer;
00236   static nsIRDFResource* kNC_IsServer;
00237   static nsIRDFResource* kNC_IsSecure;
00238   static nsIRDFResource* kNC_CanSubscribe;
00239   static nsIRDFResource* kNC_SupportsOffline;
00240   static nsIRDFResource* kNC_CanFileMessages;
00241   static nsIRDFResource* kNC_CanCreateSubfolders;
00242   static nsIRDFResource* kNC_CanRename;
00243   static nsIRDFResource* kNC_CanCompact;
00244   static nsIRDFResource* kNC_TotalMessages;
00245   static nsIRDFResource* kNC_TotalUnreadMessages;
00246   static nsIRDFResource* kNC_FolderSize;
00247   static nsIRDFResource* kNC_Charset;
00248   static nsIRDFResource* kNC_BiffState;
00249   static nsIRDFResource* kNC_HasUnreadMessages;
00250   static nsIRDFResource* kNC_NewMessages;
00251   static nsIRDFResource* kNC_SubfoldersHaveUnreadMessages;
00252   static nsIRDFResource* kNC_NoSelect;
00253   static nsIRDFResource* kNC_ImapShared;
00254   static nsIRDFResource* kNC_Synchronize;
00255   static nsIRDFResource* kNC_SyncDisabled;
00256   static nsIRDFResource* kNC_CanSearchMessages;
00257   static nsIRDFResource* kNC_VirtualFolder;
00258   static nsIRDFResource* kNC_InVFEditSearchScope;
00259   static nsIRDFResource* kNC_UnreadFolders; // maybe should be in nsMsgFlatFolderDataSource?
00260   static nsIRDFResource* kNC_FavoriteFolders; // maybe should be in nsMsgFlatFolderDataSource?
00261   static nsIRDFResource* kNC_RecentFolders; // maybe should be in nsMsgFlatFolderDataSource?
00262   // commands
00263   static nsIRDFResource* kNC_Delete;
00264   static nsIRDFResource* kNC_ReallyDelete;
00265   static nsIRDFResource* kNC_NewFolder;
00266   static nsIRDFResource* kNC_GetNewMessages;
00267   static nsIRDFResource* kNC_Copy;
00268   static nsIRDFResource* kNC_Move;
00269   static nsIRDFResource* kNC_CopyFolder;
00270   static nsIRDFResource* kNC_MoveFolder;
00271   static nsIRDFResource* kNC_MarkAllMessagesRead;
00272   static nsIRDFResource* kNC_Compact;
00273   static nsIRDFResource* kNC_CompactAll;
00274   static nsIRDFResource* kNC_Rename;
00275   static nsIRDFResource* kNC_EmptyTrash;
00276   static nsIRDFResource* kNC_DownloadFlagged;
00277   //Cached literals
00278   nsCOMPtr<nsIRDFNode> kTrueLiteral;
00279   nsCOMPtr<nsIRDFNode> kFalseLiteral;
00280 
00281   // property atoms
00282   static nsIAtom* kTotalMessagesAtom;
00283   static nsIAtom* kTotalUnreadMessagesAtom;
00284   static nsIAtom* kFolderSizeAtom;
00285   static nsIAtom* kBiffStateAtom;
00286   static nsIAtom* kNewMessagesAtom;
00287   static nsIAtom* kNameAtom;
00288   static nsIAtom* kSynchronizeAtom;
00289   static nsIAtom* kOpenAtom;
00290   static nsIAtom* kIsDeferredAtom;
00291   static nsrefcnt gFolderResourceRefCnt;
00292   static nsIAtom* kCanFileMessagesAtom;
00293   static nsIAtom* kInVFEditSearchScopeAtom;
00294   
00295   nsCOMPtr<nsISupportsArray> kFolderArcsOutArray;
00296 
00297   static PRUnichar* kKiloByteString;
00298   static PRUnichar* kMegaByteString;
00299 
00300 };
00301 
00302 
00303 class nsMsgFlatFolderDataSource : public nsMsgFolderDataSource
00304 {
00305 public:
00306   // constructor could take a filter to filter out folders.
00307   nsMsgFlatFolderDataSource();
00308   virtual ~nsMsgFlatFolderDataSource();
00309   virtual nsresult Init();
00310   virtual void Cleanup();
00311 
00312   NS_IMETHOD GetURI(char* *uri);
00313   NS_IMETHOD GetTargets(nsIRDFResource* source,
00314                         nsIRDFResource* property,    
00315                         PRBool tv,
00316                         nsISimpleEnumerator** targets);
00317   NS_IMETHOD GetTarget(nsIRDFResource* source,
00318                        nsIRDFResource* property,
00319                        PRBool tv,
00320                        nsIRDFNode** target);
00321 
00322   NS_IMETHOD HasAssertion(nsIRDFResource* source,
00323                             nsIRDFResource* property,
00324                             nsIRDFNode* target,
00325                             PRBool tv,
00326                             PRBool* hasAssertion);
00327 protected:
00328   virtual nsresult GetFolderDisplayName(nsIMsgFolder *folder, PRUnichar **folderName);
00329   virtual PRBool WantsThisFolder(nsIMsgFolder *folder);
00330           PRBool ResourceIsOurRoot(nsIRDFResource *resource);
00331   virtual nsresult OnItemAddedOrRemoved(nsIRDFResource *parentItem, nsISupports *item, PRBool added);
00332 
00333   nsCOMArray <nsIMsgFolder> m_folders;
00334   nsCOMPtr<nsIRDFResource>  m_rootResource; // the resource for our root
00335   nsCString m_dsName;
00336 };
00337 
00338 
00339 class nsMsgUnreadFoldersDataSource : public nsMsgFlatFolderDataSource
00340 {
00341 public:
00342   nsMsgUnreadFoldersDataSource() {m_dsName = "mailnewsunreadfolders";}
00343   virtual ~nsMsgUnreadFoldersDataSource() {}
00344   virtual nsresult NotifyPropertyChanged(nsIRDFResource *resource, 
00345                     nsIRDFResource *propertyResource, nsIRDFNode *newNode, 
00346                     nsIRDFNode *oldNode = nsnull);
00347 protected:
00348   virtual PRBool WantsThisFolder(nsIMsgFolder *folder);
00349 };
00350 
00351 class nsMsgFavoriteFoldersDataSource : public nsMsgFlatFolderDataSource
00352 {
00353 public:
00354   nsMsgFavoriteFoldersDataSource() {m_dsName = "mailnewsfavefolders";}
00355   virtual ~nsMsgFavoriteFoldersDataSource() {}
00356 protected:
00357   virtual PRBool WantsThisFolder(nsIMsgFolder *folder);
00358 };
00359 
00360 class nsMsgRecentFoldersDataSource : public nsMsgFlatFolderDataSource
00361 {
00362 public:
00363   nsMsgRecentFoldersDataSource() {m_dsName = "mailnewsrecentfolders"; m_builtRecentFolders = PR_FALSE;
00364                                   m_cutOffDate = 0; m_maxNumFolders = 15;}
00365   virtual ~nsMsgRecentFoldersDataSource() {}
00366   virtual nsresult NotifyPropertyChanged(nsIRDFResource *resource, 
00367                     nsIRDFResource *property, nsIRDFNode *newNode, 
00368                     nsIRDFNode *oldNode);
00369   NS_IMETHOD OnItemAdded(nsIRDFResource *parentItem, nsISupports *item);
00370   virtual void Cleanup();
00371 protected:
00372   PRBool m_builtRecentFolders;
00373   virtual PRBool WantsThisFolder(nsIMsgFolder *folder);
00374   PRUint32 m_cutOffDate;
00375   PRInt32 m_maxNumFolders;
00376 };
00377