Back to index

lightning-sunbird  0.9+nobinonly
nsMsgAccountManagerDS.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; 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) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #ifndef __nsMsgAccountManagerDS_h
00040 #define __nsMsgAccountManagerDS_h
00041 
00042 #include "nscore.h"
00043 #include "nsError.h"
00044 #include "nsIID.h"
00045 #include "nsCOMPtr.h"
00046 #include "nsIStringBundle.h"
00047 
00048 #include "nsMsgRDFDataSource.h"
00049 #include "nsIMsgAccountManager.h"
00050 #include "nsIIncomingServerListener.h"
00051 #include "nsIMsgProtocolInfo.h"
00052 #include "nsWeakPtr.h"
00053 
00054 /* {3f989ca4-f77a-11d2-969d-006008948010} */
00055 #define NS_MSGACCOUNTMANAGERDATASOURCE_CID \
00056   {0x3f989ca4, 0xf77a, 0x11d2, \
00057     {0x96, 0x9d, 0x00, 0x60, 0x08, 0x94, 0x80, 0x10}}
00058 
00059 class nsMsgAccountManagerDataSource : public nsMsgRDFDataSource,
00060                                       public nsIFolderListener,
00061                                       public nsIIncomingServerListener
00062 {
00063 
00064 public:
00065     
00066   nsMsgAccountManagerDataSource();
00067   virtual ~nsMsgAccountManagerDataSource();
00068   virtual nsresult Init();
00069 
00070   virtual void Cleanup();
00071   // service manager shutdown method
00072 
00073     NS_DECL_ISUPPORTS_INHERITED
00074     NS_DECL_NSIFOLDERLISTENER
00075     NS_DECL_NSIINCOMINGSERVERLISTENER
00076     NS_DECL_NSIOBSERVER
00077   // RDF datasource methods
00078   
00079   /* nsIRDFNode GetTarget (in nsIRDFResource aSource, in nsIRDFResource property, in boolean aTruthValue); */
00080   NS_IMETHOD GetTarget(nsIRDFResource *source,
00081                        nsIRDFResource *property,
00082                        PRBool aTruthValue,
00083                        nsIRDFNode **_retval);
00084 
00085   /* nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource property, in boolean aTruthValue); */
00086   NS_IMETHOD GetTargets(nsIRDFResource *source,
00087                         nsIRDFResource *property,
00088                         PRBool aTruthValue,
00089                         nsISimpleEnumerator **_retval);
00090   /* nsISimpleEnumerator ArcLabelsOut (in nsIRDFResource aSource); */
00091   NS_IMETHOD ArcLabelsOut(nsIRDFResource *source, nsISimpleEnumerator **_retval);
00092 
00093   NS_IMETHOD HasAssertion(nsIRDFResource *aSource, nsIRDFResource *aProperty,
00094                           nsIRDFNode *aTarget, PRBool aTruthValue,
00095                           PRBool *_retval);
00096   NS_IMETHOD HasArcOut(nsIRDFResource *source, nsIRDFResource *aArc, PRBool *result);
00097     
00098 protected:
00099 
00100   nsresult HasAssertionServer(nsIMsgIncomingServer *aServer,
00101                               nsIRDFResource *aProperty,
00102                               nsIRDFNode *aTarget,
00103                               PRBool aTruthValue, PRBool *_retval);
00104 
00105   nsresult HasAssertionAccountRoot(nsIRDFResource *aProperty,
00106                                    nsIRDFNode *aTarget,
00107                                    PRBool aTruthValue, PRBool *_retval);
00108   
00109   PRBool isDefaultServer(nsIMsgIncomingServer *aServer);
00110   PRBool supportsFilters(nsIMsgIncomingServer *aServer);
00111   PRBool canGetMessages(nsIMsgIncomingServer *aServer);
00112   PRBool canGetIncomingMessages(nsIMsgIncomingServer *aServer);
00113   
00114   static PRBool isContainment(nsIRDFResource *aProperty);
00115   nsresult getServerForFolderNode(nsIRDFNode *aResource,
00116                                   nsIMsgIncomingServer **aResult);
00117   
00118   nsresult createRootResources(nsIRDFResource *aProperty,
00119                                nsISupportsArray* aNodeArray);
00120   nsresult createSettingsResources(nsIRDFResource *aSource,
00121                                    nsISupportsArray *aNodeArray);
00122   nsresult appendGenericSettingsResources(nsIMsgIncomingServer *server, nsISupportsArray *aNodeArray);
00123   nsresult appendGenericSetting(const char *name, nsISupportsArray *aNodeArray);
00124 
00125   PRBool IsFakeAccountRequired();
00126   nsresult GetFakeAccountHostName(char **aHostName);
00127   nsresult IsIncomingServerForFakeAccount(nsIMsgIncomingServer* aServer, PRBool *aResult);
00128 
00129   static nsIRDFResource* kNC_Name;
00130   static nsIRDFResource* kNC_FolderTreeName;
00131   static nsIRDFResource* kNC_FolderTreeSimpleName;
00132   static nsIRDFResource* kNC_NameSort;
00133   static nsIRDFResource* kNC_FolderTreeNameSort;
00134   static nsIRDFResource* kNC_PageTag;
00135   static nsIRDFResource* kNC_IsDefaultServer;
00136   static nsIRDFResource* kNC_SupportsFilters;
00137   static nsIRDFResource* kNC_CanGetMessages;
00138   static nsIRDFResource* kNC_CanGetIncomingMessages;
00139   
00140   static nsIRDFResource* kNC_Child;
00141   static nsIRDFResource* kNC_AccountRoot;
00142   
00143   static nsIRDFResource* kNC_Account;
00144   static nsIRDFResource* kNC_Server;
00145   static nsIRDFResource* kNC_Identity;
00146   static nsIRDFResource* kNC_Settings;
00147   static nsIRDFResource* kNC_Junk;
00148 
00149   static nsIRDFResource* kNC_PageTitleMain;
00150   static nsIRDFResource* kNC_PageTitleServer;
00151   static nsIRDFResource* kNC_PageTitleCopies;
00152   static nsIRDFResource* kNC_PageTitleOfflineAndDiskSpace;
00153   static nsIRDFResource* kNC_PageTitleDiskSpace;
00154   static nsIRDFResource* kNC_PageTitleAddressing;
00155   static nsIRDFResource* kNC_PageTitleSMTP;
00156   static nsIRDFResource* kNC_PageTitleJunk;
00157   static nsIRDFResource* kNC_PageTitleFakeAccount;
00158 
00159   static nsIRDFLiteral* kTrueLiteral;
00160 
00161   static nsIAtom* kDefaultServerAtom;
00162 
00163   static nsrefcnt gAccountManagerResourceRefCnt;
00164 
00165   static nsresult getAccountArcs(nsISupportsArray **aResult);
00166   static nsresult getAccountRootArcs(nsISupportsArray **aResult);
00167   
00168 private:
00169   // enumeration function to convert each server (element)
00170   // to an nsIRDFResource and append it to the array (in data)
00171   static PRBool createServerResources(nsISupports *element, void *data);
00172 
00173   // search for an account by key
00174   static PRBool findServerByKey(nsISupports *aElement, void *aData);
00175 
00176   nsresult serverHasIdentities(nsIMsgIncomingServer *aServer, PRBool *aResult);
00177   nsresult getStringBundle();
00178 
00179   static nsCOMPtr<nsISupportsArray> mAccountArcsOut;
00180   static nsCOMPtr<nsISupportsArray> mAccountRootArcsOut;
00181   nsWeakPtr mAccountManager;
00182 
00183   nsCOMPtr<nsIStringBundle> mStringBundle;
00184 
00185 };
00186 
00187 
00188 
00189 #endif