Back to index

lightning-sunbird  0.9+nobinonly
nsAbPalmSync.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Netscape Communications Corporation.
00018  * Portions created by the Initial Developer are Copyright (C) 2002
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Rajiv Dayal <rdayal@netscape.com>
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 nsAbPalmHotSync_h__
00039 #define nsAbPalmHotSync_h__
00040 
00041 #include "msgMapi.h"
00042 #include "nsString.h"
00043 #include "nsAbIPCCard.h"
00044 #include "nsIAbCard.h"
00045 #include "nsIAddrDatabase.h"
00046 #include "nsILocalFile.h"
00047 #include "nsIAbDirectory.h"
00048 
00049 class nsAbPalmHotSync
00050 {
00051 public:
00052 
00053     // this class will do HotSync for a specific AB
00054     nsAbPalmHotSync(PRBool aIsUnicode, PRUnichar * aAbDescUnicode, const char * aAbDesc, PRInt32 aPalmCatIndex, PRInt32 aPalmCatId);
00055     ~nsAbPalmHotSync();
00056 
00057     // initialize the object, info for AB for the object, etc
00058     nsresult Initialize();
00059 
00060     // this will take in all updated/new Palm records and start Sync.
00061     // Sync process will load updated/new cards and compare with updated/new 
00062     // Palm records to create final list to be sent to Palm and to update AB.
00063     nsresult DoSyncAndGetUpdatedCards(PRInt32 aPalmCount, lpnsABCOMCardStruct aPalmRecords, PRInt32 * aMozCount, lpnsABCOMCardStruct * aMozCards);
00064 
00065     // this will return all cards in an AB
00066     nsresult GetAllCards(PRInt32 * aCount, lpnsABCOMCardStruct * aCardList);
00067 
00068     // this will return the final list created by above Sync methods
00069     // allocates aCardList as a memory block and populates it with mIPCCardList to be sent to Palm
00070     nsresult GetCardsToBeSentToPalm(PRInt32 * aCount, lpnsABCOMCardStruct * aCardList);
00071 
00072     // this will create a new AB and all data into it
00073     nsresult AddAllRecordsToAB(PRBool replaceExisting, PRInt32 aCount, lpnsABCOMCardStruct aPalmRecords);
00074 
00075     // this will be called when an AckSyncDone is recieved from the Conduit
00076     nsresult Done(PRBool aSuccess, PRInt32 aPalmCatIndex, PRUint32 aPalmRecIDListCount = 0, unsigned long * aPalmRecordIDList = nsnull);
00077 
00078     // this will upate AB with new category id and mod time.
00079     nsresult UpdateSyncInfo(long aCategoryIndex);
00080 
00081     // this will delete an AB
00082     nsresult DeleteAB(long aCategoryIndex, const char * aABUrl);
00083 
00084     // this will rename an AB
00085     nsresult RenameAB(long aCategoryIndex, const char * aABUrl);
00086 
00087 protected:
00088 
00089     PRBool mIsPalmDataUnicode;
00090 
00091     // data members related to AB DB
00092     PRUint32  mTotalCardCount;
00093     nsCOMPtr<nsIAddrDatabase> mABDB;
00094     nsCOMPtr <nsILocalFile> mABFile;
00095     PRBool   mDBOpen;
00096     // pref for the AB DB
00097     nsString     mAbName;
00098     PRInt32      mPalmCategoryId;
00099     PRInt32      mPalmCategoryIndex;
00100     nsCString    mFileName;
00101     nsCString    mUri;
00102     nsString     mDescription;
00103     PRUint32     mDirType;
00104     PRUint32     mPalmSyncTimeStamp;
00105     // cards directory for the AB
00106     nsCOMPtr<nsIAbDirectory> mDirectory;
00107 
00108     // previous AB, the AB state before the last sync
00109     nsCOMPtr <nsILocalFile> mPreviousABFile;
00110 
00111     // Palm records list
00112     nsVoidArray mPalmRecords;
00113     // CardList to be sent to Palm
00114     PRUint32 mCardForPalmCount;
00115     lpnsABCOMCardStruct mCardListForPalm;
00116     // since cards are already in memory because the db is open, 
00117     // this doesn't add much to memory overhead
00118     PRUint32 mNewCardCount;
00119     nsCOMPtr <nsISupportsArray> mNewCardsArray;
00120     PRBool   mIsNewCardForPalm;
00121     
00122     PRBool      mInitialized;
00123 protected:
00124     // disallow calling of default constructor
00125     nsAbPalmHotSync();
00126 
00127     // this will take care of opening, nsIAbDirectroy creation, DB backup, etc
00128     nsresult OpenABDBForHotSync(PRBool aCreate);
00129     nsresult KeepCurrentStateAsPrevious();
00130     nsresult UpdateMozABWithPalmRecords();
00131 
00132     // this will load and create a list of cards since last sync
00133     nsresult LoadNewModifiedCardsSinceLastSync();
00134     nsresult LoadDeletedCardsSinceLastSync();
00135 
00136     // Checks with the corresponding Palm record for any discrepencies
00137     // if any modification needed, this will return the modified card
00138     // returns whether card exists (in which case it can be discarded)
00139     PRBool CardExistsInPalmList(nsAbIPCCard  * aIPCCard);
00140 
00141     // utility function
00142     nsresult AddToListForPalm(nsAbIPCCard & ipcCard);
00143     void ConvertAssignPalmIDAttrib(PRUint32 id, nsIAbMDBCard * card);
00144     nsresult GetABInterface();
00145     nsresult UpdateABInfo(PRUint32 modTime, PRInt32 categoryId);
00146     nsresult ModifyAB(const char * ABUrl, nsIAbDirectoryProperties *properties);
00147     nsresult NewAB(const nsString& aAbName);
00148 
00149 };
00150 
00151 #endif