Back to index

lightning-sunbird  0.9+nobinonly
nsAbAutoCompleteSession.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) 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 #ifndef nsAbAutoCompleteSession_h___
00039 #define nsAbAutoCompleteSession_h___
00040 
00041 #include "msgCore.h"
00042 #include "nsCOMPtr.h"
00043 #include "nsReadableUtils.h"
00044 #include "nsIMsgHeaderParser.h"
00045 #include "nsIAbDirectory.h"
00046 #include "nsIAbAutoCompleteSession.h"
00047 
00048 class nsIPrefBranch;
00049 
00050 typedef struct
00051 {
00052   char * userName;
00053   char * emailAddress;
00054   char * nickName;
00055 } nsAbStubEntry;
00056 
00057 #define MAX_ENTRIES 100
00058 
00059 
00060 class nsAbAutoCompleteSearchString
00061 {
00062 public:
00063   nsAbAutoCompleteSearchString(const PRUnichar *uSearchString);
00064   virtual ~nsAbAutoCompleteSearchString();
00065   
00066   const PRUnichar*  mFullString;
00067   PRUint32          mFullStringLen;
00068   
00069   const PRUnichar*  mFirstPart;
00070   PRUint32          mFirstPartLen;
00071   
00072   const PRUnichar*  mSecondPart;
00073   PRUint32          mSecondPartLen;
00074 };
00075 
00076 
00077 class nsAbAutoCompleteSession : public nsIAbAutoCompleteSession
00078 {
00079 public:
00080   NS_DECL_ISUPPORTS
00081     NS_DECL_NSIAUTOCOMPLETESESSION
00082     NS_DECL_NSIABAUTOCOMPLETESESSION
00083 
00084   nsAbAutoCompleteSession();
00085   virtual ~nsAbAutoCompleteSession(); 
00086 
00087 protected:    
00088     PRBool ItsADuplicate(PRUnichar* fullAddrStr, PRInt32 aPopularityIndex, nsIAutoCompleteResults* results);
00089     void AddToResult(const PRUnichar* pNickNameStr, 
00090                      const PRUnichar* pDisplayNameStr, 
00091                      const PRUnichar* pFirstNameStr,
00092                      const PRUnichar* pLastNameStr, 
00093                      const PRUnichar* pEmailStr, const PRUnichar* pNotes,
00094                      const PRUnichar* pDirName, 
00095                      PRUint32 aPopularityIndex, PRBool bIsMailList, 
00096                      PRBool pDefaultMatch, nsIAutoCompleteResults* results);
00097     PRBool CheckEntry(nsAbAutoCompleteSearchString* searchStr, const PRUnichar* nickName,const PRUnichar* displayName, 
00098                       const PRUnichar* firstName, const PRUnichar* lastName, const PRUnichar* emailAddress);
00099         
00100     nsCOMPtr<nsIMsgHeaderParser> mParser;
00101     nsString mDefaultDomain;
00102 
00103     // how to process the comment column, if at all.  this value
00104     // comes from "mail.autoComplete.commentColumn", or, if that
00105     // doesn't exist, defaults to 0
00106     //
00107     // 0 = none
00108     // 1 = name of addressbook this card came from
00109     // 2 = other per-addressbook format (currrently unused here)
00110     //
00111     PRInt32 mAutoCompleteCommentColumn;
00112 
00113 private:
00114     #define MAX_NUMBER_OF_EMAIL_ADDRESSES     2
00115 
00116     nsresult SearchCards(nsIAbDirectory* directory, nsAbAutoCompleteSearchString* searchStr, nsIAutoCompleteResults* results);
00117     nsresult SearchDirectory(const nsACString& aURI, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results);
00118     nsresult SearchPreviousResults(nsAbAutoCompleteSearchString *uSearchString, nsIAutoCompleteResults *previousSearchResult, nsIAutoCompleteResults* results);
00119 
00120     nsresult SearchReplicatedLDAPDirectories(nsIPrefBranch *aPrefs, nsAbAutoCompleteSearchString* searchStr, PRBool searchSubDirectory, nsIAutoCompleteResults* results);
00121 };
00122 
00123 
00124 #define NS_ABAUTOCOMPLETEPARAM_IID_STR "a3093c00-1469-11d4-a449-e55aa307c5bc"
00125 #define NS_ABAUTOCOMPLETEPARAM_IID \
00126   {0xa3093c00, 0x1469, 0x11d4, \
00127     { 0xa4, 0x49, 0xe5, 0x5a, 0xa3, 0x07, 0xc5, 0xbc }}
00128 
00129 class nsAbAutoCompleteParam : public nsISupports
00130 {
00131 public:
00132   NS_DECL_ISUPPORTS
00133   
00134   nsAbAutoCompleteParam(const PRUnichar* nickName,
00135                           const PRUnichar* displayName,
00136                           const PRUnichar* firstName,
00137                           const PRUnichar* lastName,
00138                           const PRUnichar* emailAddress,
00139                           const PRUnichar* notes,
00140                           const PRUnichar* dirName,
00141                           PRUint32 aPopularityIndex,
00142                           PRBool isMailList)
00143   {
00144     const PRUnichar *empty = EmptyString().get();
00145 
00146     mNickName = nsCRT::strdup(nickName ? nickName : empty);
00147     mDisplayName = nsCRT::strdup(displayName ? displayName : empty);
00148     mFirstName = nsCRT::strdup(firstName ? firstName : empty);
00149     mLastName = nsCRT::strdup(lastName ? lastName : empty);
00150     mEmailAddress = nsCRT::strdup(emailAddress ? emailAddress : empty);
00151     mNotes = nsCRT::strdup(notes ? notes : empty);
00152     mDirName = nsCRT::strdup(dirName ? dirName : empty);
00153     mIsMailList = isMailList;
00154     mPopularityIndex = aPopularityIndex;
00155   }
00156   
00157   virtual ~nsAbAutoCompleteParam()
00158   {
00159     CRTFREEIF(mNickName);
00160     CRTFREEIF(mDisplayName);
00161     CRTFREEIF(mFirstName);
00162     CRTFREEIF(mLastName);
00163     CRTFREEIF(mEmailAddress);
00164     CRTFREEIF(mNotes);
00165     CRTFREEIF(mDirName);
00166   };
00167   
00168 protected:
00169     PRUnichar* mNickName;
00170     PRUnichar* mDisplayName;
00171     PRUnichar* mFirstName;
00172     PRUnichar* mLastName;
00173     PRUnichar* mEmailAddress;
00174     PRUnichar* mNotes;
00175     PRUnichar* mDirName;
00176     PRUint32 mPopularityIndex;
00177     PRBool mIsMailList;
00178 
00179 public:
00180     friend class nsAbAutoCompleteSession;
00181 };
00182 
00183 #endif /* nsAbAutoCompleteSession_h___ */
00184 
00185