From 089264ae0848ea348f2d1cd681560ee7f494029b Mon Sep 17 00:00:00 2001 From: "bugzilla%standard8.demon.co.uk" Date: Fri, 26 Aug 2005 14:47:31 +0000 Subject: [PATCH] Bug 132180 eliminate nsFileSpec in address book. Second patch of serveral. r=dmose,sr=bienvenu --- mailnews/addrbook/public/nsIAbDirectory.idl | 4 +- mailnews/addrbook/public/nsIAbUpgrader.idl | 47 ---- mailnews/addrbook/public/nsIAddrDatabase.idl | 93 +++++--- mailnews/addrbook/src/nsAbBSDirectory.cpp | 2 + mailnews/addrbook/src/nsAbCardProperty.cpp | 3 +- mailnews/addrbook/src/nsAbCardProperty.h | 2 + mailnews/addrbook/src/nsAbDirProperty.h | 2 + .../addrbook/src/nsAbLDAPChangeLogData.cpp | 2 + mailnews/addrbook/src/nsAbLDAPDirectory.cpp | 2 + .../addrbook/src/nsAbLDAPDirectoryQuery.cpp | 3 + .../addrbook/src/nsAbLDAPReplicationData.h | 2 + .../addrbook/src/nsAbLDAPReplicationQuery.cpp | 3 +- mailnews/addrbook/src/nsAbMDBCardProperty.cpp | 2 + mailnews/addrbook/src/nsAbMDBDirFactory.cpp | 3 + mailnews/addrbook/src/nsAbOutlookCard.cpp | 4 +- .../addrbook/src/nsAbOutlookDirFactory.cpp | 2 + .../addrbook/src/nsAbOutlookDirectory.cpp | 3 + mailnews/addrbook/src/nsAbRDFDataSource.cpp | 2 + mailnews/addrbook/src/nsAbView.cpp | 2 + mailnews/addrbook/src/nsAddrDatabase.cpp | 212 +++++------------- mailnews/addrbook/src/nsAddrDatabase.h | 21 +- mailnews/addrbook/src/nsAddressBook.cpp | 3 +- mailnews/addrbook/src/nsDirPrefs.cpp | 3 + .../addrbook/src/nsDirectoryDataSource.cpp | 2 + mailnews/addrbook/src/nsVCardObj.h | 3 +- .../extensions/palmsync/src/nsAbPalmSync.cpp | 8 +- 26 files changed, 174 insertions(+), 261 deletions(-) diff --git a/mailnews/addrbook/public/nsIAbDirectory.idl b/mailnews/addrbook/public/nsIAbDirectory.idl index 6a04b720297..3c0438bbdea 100644 --- a/mailnews/addrbook/public/nsIAbDirectory.idl +++ b/mailnews/addrbook/public/nsIAbDirectory.idl @@ -21,6 +21,7 @@ * * Contributor(s): * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -40,10 +41,7 @@ #include "nsIAbCard.idl" #include "nsISupportsArray.idl" -[ptr] native nsFileSpec(nsFileSpec); - %{C++ -#include "nsFileSpec.h" #include "nsDirPrefs.h" %} diff --git a/mailnews/addrbook/public/nsIAbUpgrader.idl b/mailnews/addrbook/public/nsIAbUpgrader.idl index 019cdce2ec7..e69de29bb2d 100644 --- a/mailnews/addrbook/public/nsIAbUpgrader.idl +++ b/mailnews/addrbook/public/nsIAbUpgrader.idl @@ -1,47 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2000 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#include "nsISupports.idl" -#include "nsIFileSpec.idl" - -[scriptable, uuid(abd6c760-f396-11d3-b9fa-00108335942a)] -interface nsIAbUpgrader : nsISupports { - - void StartUpgrade4xAddrBook(in nsIFileSpec sourceAddrBook, in nsIFileSpec destAddrBook); - void ContinueExport(out boolean done); - attribute string currentCharset; -}; diff --git a/mailnews/addrbook/public/nsIAddrDatabase.idl b/mailnews/addrbook/public/nsIAddrDatabase.idl index 5deba8f9659..31c5072f5a4 100644 --- a/mailnews/addrbook/public/nsIAddrDatabase.idl +++ b/mailnews/addrbook/public/nsIAddrDatabase.idl @@ -21,6 +21,7 @@ * * Contributor(s): * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -36,7 +37,6 @@ * * ***** END LICENSE BLOCK ***** */ -/* nsFileSpec is declared in nsIAbDirectory.idl */ #include "nsIAddrDBAnnouncer.idl" #include "nsIAbCard.idl" #include "nsIAbDirectory.idl" @@ -137,14 +137,34 @@ interface nsAddrDBCommitType const long kCompressCommit = 3; }; -[scriptable, uuid(8175a7ce-4414-489e-ba29-b22d8c4a1cae)] +[scriptable, uuid(3c6e0a41-7f9d-4e46-a77e-cbeed22ed2be)] interface nsIAddrDatabase : nsIAddrDBAnnouncer { - [noscript] attribute nsFileSpec dbPath; + /** + * Path to the address book database that this instance represents. + */ + attribute nsIFile dbPath; nsIAddrDatabase open(in nsIFile dbFile, in boolean create, in boolean upgrading); void close(in boolean forceCommit); - [noscript] void openMDB(in nsFileSpec dbName, in boolean create); + + /** + * Open the MDB database synchronously creating it if required. If + * successful, this routine will set up the m_mdbStore and m_mdbEnv of the + * database object so other database calls can work. + * + * @param dbName The location of the database file + * to open. + * @param create If set to true, will create the + * database file if it does not + * already exist. + * @exception NS_ERROR_FILE_NOT_FOUND The file was not found at the + * specified location (and create was + * false). + * @exception NS_ERROR_FILE_ACCESS_DENIED The file could not be opened as + * access was denied. + */ + void openMDB(in nsIFile dbName, in boolean create); void closeMDB(in boolean commit); void commit(in unsigned long commitType); @@ -183,9 +203,9 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer { void deleteCardFromMailList(in nsIAbDirectory mailList, in nsIAbCard card, in boolean aNotify); readonly attribute wstring directoryName; - /** - * aUTF8Value needs to be in UTF-8 - */ + /** + * aUTF8Value needs to be in UTF-8 + */ nsIAbCard getCardFromAttribute(in nsIAbDirectory directory, in string aName, in string aUTF8Value, in boolean caseInsensitive); PRBool findMailListbyUnicodeName(in wstring listName); @@ -256,37 +276,36 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer { [noscript] void addListDescription(in nsIMdbRow row, in string value); [noscript] void addListDirNode(in nsIMdbRow listRow); - /** - * use for getting and setting generic string attributes - * like _AimScreenName - */ - void setCardValue(in nsIAbCard card, in string name, in wstring value, in boolean notify); - wstring getCardValue(in nsIAbCard card, in string name); + /** + * use for getting and setting generic string attributes + * like _AimScreenName + */ + void setCardValue(in nsIAbCard card, in string name, in wstring value, in boolean notify); + wstring getCardValue(in nsIAbCard card, in string name); - void getDeletedCardList(out unsigned long aCount, out nsISupportsArray aDeletedList); - void getDeletedCardCount(out unsigned long count); + void getDeletedCardList(out unsigned long aCount, out nsISupportsArray aDeletedList); + void getDeletedCardCount(out unsigned long count); - /** - * used for adding a string attributes to a row. - * used during LDIF and addressbook import. - * - * @param aRow - * The row we're adding the column to - * @param aLDIFAttributeName - * The column name (examples: mozillaCategory, - * mozilla_AimScreenName) - * @param aColValue - * The column value (example: jabroni316) - */ - [noscript] void addRowValue(in nsIMdbRow aRow, in ACString aLDIFAttributeName, in AString aColValue); - - void AddListCardColumnsToRow(in nsIAbCard aPCard, - in nsIMdbRow aPListRow, - in unsigned long aPos, - out nsIAbCard aPNewCard, - in boolean aInMailingList); - void InitCardFromRow(in nsIAbCard aNewCard,in nsIMdbRow aCardRow); - void SetListAddressTotal(in nsIMdbRow aListRow, in PRUint32 aTotal); - nsIMdbRow FindRowByCard(in nsIAbCard aCard); + /** + * used for adding a string attributes to a row. + * used during LDIF and addressbook import. + * + * @param aRow + * The row we're adding the column to + * @param aLDIFAttributeName + * The column name (examples: mozillaCategory, + * mozilla_AimScreenName) + * @param aColValue + * The column value (example: jabroni316) + */ + [noscript] void addRowValue(in nsIMdbRow aRow, in ACString aLDIFAttributeName, in AString aColValue); + void AddListCardColumnsToRow(in nsIAbCard aPCard, + in nsIMdbRow aPListRow, + in unsigned long aPos, + out nsIAbCard aPNewCard, + in boolean aInMailingList); + void InitCardFromRow(in nsIAbCard aNewCard,in nsIMdbRow aCardRow); + void SetListAddressTotal(in nsIMdbRow aListRow, in PRUint32 aTotal); + nsIMdbRow FindRowByCard(in nsIAbCard aCard); }; diff --git a/mailnews/addrbook/src/nsAbBSDirectory.cpp b/mailnews/addrbook/src/nsAbBSDirectory.cpp index fdfa1d40910..2d0381c3977 100644 --- a/mailnews/addrbook/src/nsAbBSDirectory.cpp +++ b/mailnews/addrbook/src/nsAbBSDirectory.cpp @@ -23,6 +23,7 @@ * Paul Sandoz * Csaba Borbola * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -56,6 +57,7 @@ #include "nsAbDirFactoryService.h" #include "nsAbMDBDirFactory.h" #include "nsArrayEnumerator.h" +#include "nsCRT.h" nsAbBSDirectory::nsAbBSDirectory() : nsRDFResource(), diff --git a/mailnews/addrbook/src/nsAbCardProperty.cpp b/mailnews/addrbook/src/nsAbCardProperty.cpp index f6838ddbd08..372cb32df14 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.cpp +++ b/mailnews/addrbook/src/nsAbCardProperty.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Seth Spitzer * Pierre Phaneuf + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -50,7 +51,7 @@ #include "plbase64.h" #include "nsIAddrBookSession.h" #include "nsIStringBundle.h" - +#include "plstr.h" #include "nsIRDFResource.h" #include "nsIRDFService.h" #include "nsRDFCID.h" diff --git a/mailnews/addrbook/src/nsAbCardProperty.h b/mailnews/addrbook/src/nsAbCardProperty.h index 09e86b4b913..7fda109c5f1 100644 --- a/mailnews/addrbook/src/nsAbCardProperty.h +++ b/mailnews/addrbook/src/nsAbCardProperty.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -47,6 +48,7 @@ #include "nsIAbCard.h" #include "nsCOMPtr.h" #include "nsIAddressBook.h" +#include "nsString.h" class mozITXTToHTMLConv; struct AppendItem; diff --git a/mailnews/addrbook/src/nsAbDirProperty.h b/mailnews/addrbook/src/nsAbDirProperty.h index f98255dc1da..78ae26b3d07 100644 --- a/mailnews/addrbook/src/nsAbDirProperty.h +++ b/mailnews/addrbook/src/nsAbDirProperty.h @@ -21,6 +21,7 @@ * * Contributor(s): * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -51,6 +52,7 @@ #include "nsCOMPtr.h" #include "nsDirPrefs.h" #include "nsIAddrDatabase.h" +#include "nsString.h" /* * Address Book Directory diff --git a/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp b/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp index 2d3177c9cf4..d6dc542f1a7 100644 --- a/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp +++ b/mailnews/addrbook/src/nsAbLDAPChangeLogData.cpp @@ -21,6 +21,7 @@ * Contributor(s): * Rajiv Dayal * Dan Mosedale + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -52,6 +53,7 @@ #include "nsIStringBundle.h" #include "nsIWindowWatcher.h" #include "nsUnicharUtils.h" +#include "plstr.h" // defined here since to be used // only locally to this file. diff --git a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp index 7523ecdb8cc..43e81d1dd37 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectory.cpp +++ b/mailnews/addrbook/src/nsAbLDAPDirectory.cpp @@ -23,6 +23,7 @@ * Seth Spitzer * Dan Mosedale * Paul Sandoz + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -45,6 +46,7 @@ #include "nsAbBaseCID.h" #include "nsIAddrBookSession.h" #include "nsIRDFService.h" +#include "nsIServiceManager.h" #include "nsString.h" #include "nsXPIDLString.h" diff --git a/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp b/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp index 4f6734f6d25..755695fe9f3 100644 --- a/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp +++ b/mailnews/addrbook/src/nsAbLDAPDirectoryQuery.cpp @@ -23,6 +23,7 @@ * Seth Spitzer * Dan Mosedale * Paul Sandoz + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -53,9 +54,11 @@ #include "nsAutoLock.h" #include "nsIProxyObjectManager.h" #include "prprf.h" +#include "nsCRT.h" #include "nsIWindowWatcher.h" #include "nsIDOMWindow.h" #include "nsICategoryManager.h" +#include "nsIServiceManager.h" #include "nsCategoryManagerUtils.h" #include "nsAbLDAPDirectory.h" diff --git a/mailnews/addrbook/src/nsAbLDAPReplicationData.h b/mailnews/addrbook/src/nsAbLDAPReplicationData.h index ff3bef3c87d..9cfccc67746 100644 --- a/mailnews/addrbook/src/nsAbLDAPReplicationData.h +++ b/mailnews/addrbook/src/nsAbLDAPReplicationData.h @@ -21,6 +21,7 @@ * * Contributor(s): * Dan Mosedale + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -47,6 +48,7 @@ #include "nsILocalFile.h" #include "nsDirPrefs.h" #include "nsIAbLDAPAttributeMap.h" +#include "nsString.h" class nsAbLDAPProcessReplicationData : public nsIAbLDAPProcessReplicationData { diff --git a/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp b/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp index caf56809893..d1168fa7431 100644 --- a/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp +++ b/mailnews/addrbook/src/nsAbLDAPReplicationQuery.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Dan Mosedale + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -48,7 +49,7 @@ #include "nsLDAP.h" #include "nsAbUtils.h" #include "nsDirPrefs.h" - +#include "nsCRT.h" NS_IMPL_ISUPPORTS1(nsAbLDAPReplicationQuery, nsIAbLDAPReplicationQuery) diff --git a/mailnews/addrbook/src/nsAbMDBCardProperty.cpp b/mailnews/addrbook/src/nsAbMDBCardProperty.cpp index bc356098031..45ebe2db71c 100644 --- a/mailnews/addrbook/src/nsAbMDBCardProperty.cpp +++ b/mailnews/addrbook/src/nsAbMDBCardProperty.cpp @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -48,6 +49,7 @@ #include "nsAddrDatabase.h" #include "nsIAddrBookSession.h" #include "nsIAddressBook.h" +#include "nsILocalFile.h" nsAbMDBCardProperty::nsAbMDBCardProperty(void) { diff --git a/mailnews/addrbook/src/nsAbMDBDirFactory.cpp b/mailnews/addrbook/src/nsAbMDBDirFactory.cpp index 63b161e9128..2a331af5318 100644 --- a/mailnews/addrbook/src/nsAbMDBDirFactory.cpp +++ b/mailnews/addrbook/src/nsAbMDBDirFactory.cpp @@ -23,6 +23,7 @@ * Paul Sandoz * Csaba Borbola * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -44,6 +45,8 @@ #include "nsIRDFService.h" #include "nsIRDFResource.h" #include "nsRDFResource.h" +#include "nsIServiceManager.h" +#include "nsILocalFile.h" #include "nsIAbMDBDirectory.h" #include "nsAbDirFactoryService.h" diff --git a/mailnews/addrbook/src/nsAbOutlookCard.cpp b/mailnews/addrbook/src/nsAbOutlookCard.cpp index edb95d48402..2ce0dd50d10 100644 --- a/mailnews/addrbook/src/nsAbOutlookCard.cpp +++ b/mailnews/addrbook/src/nsAbOutlookCard.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -41,7 +42,8 @@ #include "nsIPrefBranch.h" #include "nsIAddrBookSession.h" #include "nsAbBaseCID.h" - +#include "nsServiceManagerUtils.h" +#include "nsCRT.h" #include "prlog.h" #ifdef PR_LOGGING diff --git a/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp b/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp index 0a035d1c3b2..a8a9b8d5045 100644 --- a/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp +++ b/mailnews/addrbook/src/nsAbOutlookDirFactory.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Created by Cyrille Moureaux + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -43,6 +44,7 @@ #include "nsIRDFResource.h" #include "nsRDFResource.h" #include "nsEnumeratorUtils.h" +#include "nsServiceManagerUtils.h" #include "nsAbBaseCID.h" diff --git a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp index 551ba6e7bd8..688518a6126 100644 --- a/mailnews/addrbook/src/nsAbOutlookDirectory.cpp +++ b/mailnews/addrbook/src/nsAbOutlookDirectory.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Created by Cyrille Moureaux + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -51,6 +52,8 @@ #include "nsAbUtils.h" #include "nsIProxyObjectManager.h" #include "nsEnumeratorUtils.h" +#include "nsServiceManagerUtils.h" +#include "nsCRT.h" #include "prlog.h" #include "prthread.h" diff --git a/mailnews/addrbook/src/nsAbRDFDataSource.cpp b/mailnews/addrbook/src/nsAbRDFDataSource.cpp index 0e8207fedb4..e19948139ba 100644 --- a/mailnews/addrbook/src/nsAbRDFDataSource.cpp +++ b/mailnews/addrbook/src/nsAbRDFDataSource.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Pierre Phaneuf + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -55,6 +56,7 @@ #include "nsCOMPtr.h" #include "nsXPIDLString.h" #include "nsAutoLock.h" +#include "nsIServiceManager.h" // this is used for notification of observers using nsVoidArray typedef struct _nsAbRDFNotification { diff --git a/mailnews/addrbook/src/nsAbView.cpp b/mailnews/addrbook/src/nsAbView.cpp index 3748c096447..625d9a89c12 100644 --- a/mailnews/addrbook/src/nsAbView.cpp +++ b/mailnews/addrbook/src/nsAbView.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Paul Sandoz + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -51,6 +52,7 @@ #include "nsXPCOM.h" #include "nsISupportsPrimitives.h" #include "nsITreeColumns.h" +#include "nsCRT.h" #include "nsIPrefService.h" #include "nsIPrefBranch2.h" diff --git a/mailnews/addrbook/src/nsAddrDatabase.cpp b/mailnews/addrbook/src/nsAddrDatabase.cpp index 58fd3930cac..3c067c1504b 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.cpp +++ b/mailnews/addrbook/src/nsAddrDatabase.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Pierre Phaneuf + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -389,7 +390,7 @@ nsAddrDatabase::CleanupCache() //---------------------------------------------------------------------- // FindInCache - this addrefs the db it finds. //---------------------------------------------------------------------- -nsAddrDatabase* nsAddrDatabase::FindInCache(nsFileSpec *dbName) +nsAddrDatabase* nsAddrDatabase::FindInCache(nsIFile *dbName) { PRInt32 i; for (i = 0; i < GetDBCache()->Count(); i++) @@ -420,9 +421,15 @@ PRInt32 nsAddrDatabase::FindInCache(nsAddrDatabase* pAddrDB) return(-1); } -PRBool nsAddrDatabase::MatchDbName(nsFileSpec* dbName) // returns PR_TRUE if they match +PRBool nsAddrDatabase::MatchDbName(nsIFile* dbName) // returns PR_TRUE if they match { - return (m_dbName == (*dbName)); + PRBool dbMatches = PR_FALSE; + + nsresult rv = m_dbName->Equals(dbName, &dbMatches); + if (NS_FAILED(rv)) + return PR_FALSE; + + return dbMatches; } //---------------------------------------------------------------------- @@ -451,100 +458,18 @@ nsIMdbFactory *nsAddrDatabase::GetMDBFactory() return gMDBFactory; } -#if defined(XP_WIN) || defined(XP_OS2) -// this code is stolen from nsFileSpecWin. Since MDB requires a native path, for -// the time being, we'll just take the Unix/Canonical form and munge it -void nsAddrDatabase::UnixToNative(char*& ioPath) -// This just does string manipulation. It doesn't check reality, or canonify, or -// anything -//---------------------------------------------------------------------------------------- -{ - // Allow for relative or absolute. We can do this in place, because the - // native path is never longer. - - if (!ioPath || !*ioPath) - return; - - char* src = ioPath; - if (*ioPath == '/') - { - // Strip initial slash for an absolute path - src++; - } - - // Convert the vertical slash to a colon - char* cp = src + 1; - - // If it was an absolute path, check for the drive letter - if (*ioPath == '/' && strstr(cp, "|/") == cp) - *cp = ':'; - - // Convert '/' to '\'. - while (*++cp) - { - if (*cp == '/') - *cp = '\\'; - } - - if (*ioPath == '/') { - for (cp = ioPath; *cp; ++cp) - *cp = *(cp + 1); - } -} -#endif /* XP_WIN || XP_OS2 */ - -#ifdef XP_MAC -// this code is stolen from nsFileSpecMac. Since MDB requires a native path, for -// the time being, we'll just take the Unix/Canonical form and munge it -void nsAddrDatabase::UnixToNative(char*& ioPath) -// This just does string manipulation. It doesn't check reality, or canonify, or -// anything -//---------------------------------------------------------------------------------------- -{ - // Relying on the fact that the unix path is always longer than the mac path: - size_t len = strlen(ioPath); - char* result = new char[len + 2]; // ... but allow for the initial colon in a partial name - if (result) - { - char* dst = result; - const char* src = ioPath; - if (*src == '/') // * full path - src++; - else if (PL_strchr(src, '/')) // * partial path, and not just a leaf name - *dst++ = ':'; - strcpy(dst, src); - - while ( *dst != 0) - { - if (*dst == '/') - *dst++ = ':'; - else - *dst++; - } - nsCRT::free(ioPath); - ioPath = result; - } -} -#endif /* XP_MAC */ - /* caller need to delete *aDbPath */ -NS_IMETHODIMP nsAddrDatabase::GetDbPath(nsFileSpec * *aDbPath) +NS_IMETHODIMP nsAddrDatabase::GetDbPath(nsIFile* *aDbPath) { if (!aDbPath) return NS_ERROR_NULL_POINTER; - nsFileSpec* pFilePath = new nsFileSpec(); - if (!pFilePath) - return NS_ERROR_OUT_OF_MEMORY; - *pFilePath = m_dbName; - *aDbPath = pFilePath; - return NS_OK; + return m_dbName->Clone(aDbPath); } -NS_IMETHODIMP nsAddrDatabase::SetDbPath(nsFileSpec * aDbPath) +NS_IMETHODIMP nsAddrDatabase::SetDbPath(nsIFile* aDbPath) { - m_dbName = (*aDbPath); - return NS_OK; + return aDbPath->Clone(getter_AddRefs(m_dbName)); } NS_IMETHODIMP nsAddrDatabase::Open @@ -552,23 +477,14 @@ NS_IMETHODIMP nsAddrDatabase::Open { *pAddrDB = nsnull; - nsCOMPtr mabIFileSpec; - nsFileSpec mabFileSpec; - // Convert the nsILocalFile into an nsIFileSpec - // TODO: convert users of nsIFileSpec to nsILocalFile - // and avoid this step. - nsresult rv = NS_NewFileSpecFromIFile(aMabFile, getter_AddRefs(mabIFileSpec)); - NS_ENSURE_SUCCESS(rv, rv); - rv = mabIFileSpec->GetFileSpec(&mabFileSpec); - NS_ENSURE_SUCCESS(rv, rv); + nsAddrDatabase *pAddressBookDB = FindInCache(aMabFile); - nsAddrDatabase *pAddressBookDB = (nsAddrDatabase *) FindInCache(&mabFileSpec); if (pAddressBookDB) { *pAddrDB = pAddressBookDB; return NS_OK; } - rv = OpenInternal(&mabFileSpec, aCreate, pAddrDB); + nsresult rv = OpenInternal(aMabFile, aCreate, pAddrDB); if (NS_SUCCEEDED(rv)) return NS_OK; @@ -579,9 +495,10 @@ NS_IMETHODIMP nsAddrDatabase::Open if (!gAlreadyAlerted) { gAlreadyAlerted = PR_TRUE; - nsXPIDLCString mabFileName; - mabFileName.Adopt(mabFileSpec.GetLeafName()); - AlertAboutLockedMabFile(NS_ConvertASCIItoUCS2(mabFileName).get()); + nsAutoString mabFileName; + rv = aMabFile->GetLeafName(mabFileName); + NS_ENSURE_SUCCESS(rv, rv); + AlertAboutLockedMabFile(mabFileName.get()); } } // try one more time @@ -636,27 +553,17 @@ NS_IMETHODIMP nsAddrDatabase::Open NS_ASSERTION(NS_SUCCEEDED(rv), "failed to rename corrupt mab file"); if (NS_SUCCEEDED(rv)) { - nsCOMPtr newMabIFileSpec; - nsFileSpec newMabFileSpec; - // Convert the nsILocalFile into an nsIFileSpec - // TODO: convert users of nsIFileSpec to nsILocalFile - // and avoid this step. - nsresult rv = NS_NewFileSpecFromIFile(aMabFile, getter_AddRefs(newMabIFileSpec)); - NS_ENSURE_SUCCESS(rv, rv); - - rv = newMabIFileSpec->GetFileSpec(&newMabFileSpec); - NS_ENSURE_SUCCESS(rv, rv); - - rv = OpenInternal(&newMabFileSpec, aCreate, pAddrDB); + // now we can try to recreate the original mab file + rv = OpenInternal(aMabFile, aCreate, pAddrDB); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create .mab file, after rename"); if (NS_SUCCEEDED(rv)) { - nsCAutoString originalMabFileName; - rv = aMabFile->GetNativeLeafName(originalMabFileName); + nsAutoString originalMabFileName; + rv = aMabFile->GetLeafName(originalMabFileName); NS_ENSURE_SUCCESS(rv, rv); // if this fails, we don't care - (void)AlertAboutCorruptMabFile(NS_ConvertASCIItoUCS2(originalMabFileName).get(), + (void)AlertAboutCorruptMabFile(originalMabFileName.get(), NS_ConvertASCIItoUCS2(backupMabFileName).get()); } } @@ -705,7 +612,7 @@ nsresult nsAddrDatabase::AlertAboutLockedMabFile(const PRUnichar *aFileName) } nsresult -nsAddrDatabase::OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase** pAddrDB) +nsAddrDatabase::OpenInternal(nsIFile *aMabFile, PRBool aCreate, nsIAddrDatabase** pAddrDB) { nsAddrDatabase *pAddressBookDB = new nsAddrDatabase(); if (!pAddressBookDB) { @@ -734,7 +641,7 @@ nsAddrDatabase::OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDataba // Open the MDB database synchronously. If successful, this routine // will set up the m_mdbStore and m_mdbEnv of the database object // so other database calls can work. -NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) +NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsIFile *dbName, PRBool create) { nsresult ret = NS_OK; nsIMdbFactory *myMDBFactory = GetMDBFactory(); @@ -744,21 +651,22 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) if (NS_SUCCEEDED(ret)) { nsIMdbThumb *thumb = nsnull; - const char *pFilename = dbName->GetCString(); /* do not free */ - char *nativeFileName = nsCRT::strdup(pFilename); + nsCAutoString filePath; + + ret = dbName->GetNativePath(filePath); + NS_ENSURE_SUCCESS(ret, ret); + nsIMdbHeap* dbHeap = 0; mdb_bool dbFrozen = mdbBool_kFalse; // not readonly, we want modifiable - if (!nativeFileName) - return NS_ERROR_OUT_OF_MEMORY; - if (m_mdbEnv) m_mdbEnv->SetAutoClear(PR_TRUE); -#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MAC) - UnixToNative(nativeFileName); -#endif - if (!dbName->Exists()) + PRBool dbNameExists = PR_FALSE; + ret = dbName->Exists(&dbNameExists); + NS_ENSURE_SUCCESS(ret, ret); + + if (!dbNameExists) ret = NS_ERROR_FILE_NOT_FOUND; else { @@ -766,9 +674,11 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) mdb_bool canOpen; mdbYarn outFormatVersion; nsIMdbFile* oldFile = 0; - PRBool isEmptyFile = !dbName->GetFileSize(); + PRInt64 fileSize; + ret = dbName->GetFileSize(&fileSize); + NS_ENSURE_SUCCESS(ret, ret); - ret = myMDBFactory->OpenOldFile(m_mdbEnv, dbHeap, nativeFileName, + ret = myMDBFactory->OpenOldFile(m_mdbEnv, dbHeap, filePath.get(), dbFrozen, &oldFile); if ( oldFile ) { @@ -785,7 +695,7 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) ret = myMDBFactory->OpenFileStore(m_mdbEnv, dbHeap, oldFile, &inOpenPolicy, &thumb); } - else if (!isEmptyFile) + else if (fileSize != 0) ret = NS_ERROR_FILE_ACCESS_DENIED; } NS_RELEASE(oldFile); // always release our file ref, store has own @@ -794,8 +704,6 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) ret = NS_ERROR_FILE_ACCESS_DENIED; } - nsCRT::free(nativeFileName); - if (NS_SUCCEEDED(ret) && thumb) { mdb_count outTotal; // total somethings to do in operation @@ -825,7 +733,7 @@ NS_IMETHODIMP nsAddrDatabase::OpenMDB(nsFileSpec *dbName, PRBool create) else if (create && ret != NS_ERROR_FILE_ACCESS_DENIED) { nsIMdbFile* newFile = 0; - ret = myMDBFactory->CreateNewFile(m_mdbEnv, dbHeap, dbName->GetCString(), &newFile); + ret = myMDBFactory->CreateNewFile(m_mdbEnv, dbHeap, filePath.get(), &newFile); if ( newFile ) { if (ret == NS_OK) @@ -3465,9 +3373,11 @@ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result rowID = outOid.mOid_Id; char* listURI = nsnull; - char* file = nsnull; - file = m_dbName.GetLeafName(); - listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, file, rowID); + + nsAutoString fileName; + rv = m_dbName->GetLeafName(fileName); + NS_ENSURE_SUCCESS(rv, rv); + listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, NS_ConvertUCS2toUTF8(fileName).get(), rowID); nsCOMPtr personCard; nsCOMPtr dbm_dbDirectory(do_QueryInterface(m_dbDirectory, &rv)); @@ -3495,8 +3405,6 @@ nsresult nsAddrDatabase::CreateABListCard(nsIMdbRow* listRow, nsIAbCard **result NS_IF_ADDREF(*result = personCard); } - if (file) - nsCRT::free(file); if (listURI) PR_smprintf_free(listURI); @@ -3518,10 +3426,12 @@ nsresult nsAddrDatabase::CreateABList(nsIMdbRow* listRow, nsIAbDirectory **resul rowID = outOid.mOid_Id; char* listURI = nsnull; - char* file = nsnull; - file = m_dbName.GetLeafName(); - listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, file, rowID); + nsAutoString fileName; + m_dbName->GetLeafName(fileName); + NS_ENSURE_SUCCESS(rv, rv); + + listURI = PR_smprintf("%s%s/MailList%ld", kMDBDirectoryRoot, NS_ConvertUCS2toUTF8(fileName).get(), rowID); nsCOMPtr mailList; nsCOMPtr dbm_dbDirectory(do_QueryInterface(m_dbDirectory, &rv)); @@ -3554,8 +3464,6 @@ nsresult nsAddrDatabase::CreateABList(nsIMdbRow* listRow, nsIAbDirectory **resul } } - if (file) - nsCRT::free(file); if (listURI) PR_smprintf_free(listURI); @@ -3655,9 +3563,13 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow) { nsCOMPtr parentResource; - char* file = m_dbName.GetLeafName(); - char *parentUri = PR_smprintf("%s%s", kMDBDirectoryRoot, file); - rv = rdfService->GetResource(nsDependentCString(parentUri), getter_AddRefs(parentResource)); + nsAutoString parentURI; + rv = m_dbName->GetLeafName(parentURI); + NS_ENSURE_SUCCESS(rv, rv); + + parentURI = NS_LITERAL_STRING(kMDBDirectoryRoot) + parentURI; + + rv = rdfService->GetResource(NS_ConvertUCS2toUTF8(parentURI), getter_AddRefs(parentResource)); nsCOMPtr parentDir; rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID( nsIAbDirectory), parentResource, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( parentDir)); @@ -3673,10 +3585,6 @@ NS_IMETHODIMP nsAddrDatabase::AddListDirNode(nsIMdbRow * listRow) dbparentDir->NotifyDirItemAdded(mailList); } } - if (parentUri) - PR_smprintf_free(parentUri); - if (file) - nsCRT::free(file); } return rv; } diff --git a/mailnews/addrbook/src/nsAddrDatabase.h b/mailnews/addrbook/src/nsAddrDatabase.h index 88e1ed62c39..ad585d4a9f3 100644 --- a/mailnews/addrbook/src/nsAddrDatabase.h +++ b/mailnews/addrbook/src/nsAddrDatabase.h @@ -21,6 +21,7 @@ * * Contributor(s): * Seth Spitzer + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -43,7 +44,6 @@ #include "mdb.h" #include "nsVoidArray.h" #include "nsString.h" -#include "nsFileSpec.h" #include "nsIAddrDBListener.h" #include "nsISupportsArray.h" #include "nsCOMPtr.h" @@ -74,11 +74,11 @@ public: ////////////////////////////////////////////////////////////////////////////// // nsIAddrDatabase methods: - NS_IMETHOD GetDbPath(nsFileSpec * *aDbPath); - NS_IMETHOD SetDbPath(nsFileSpec * aDbPath); + NS_IMETHOD GetDbPath(nsIFile * *aDbPath); + NS_IMETHOD SetDbPath(nsIFile * aDbPath); NS_IMETHOD Open(nsIFile *aMabFile, PRBool aCreate, PRBool upgrading, nsIAddrDatabase **pCardDB); NS_IMETHOD Close(PRBool forceCommit); - NS_IMETHOD OpenMDB(nsFileSpec *dbName, PRBool create); + NS_IMETHOD OpenMDB(nsIFile *dbName, PRBool create); NS_IMETHOD CloseMDB(PRBool commit); NS_IMETHOD Commit(PRUint32 commitType); NS_IMETHOD ForceClosed(); @@ -301,7 +301,7 @@ public: nsIMdbTableRowCursor *GetTableRowCursor(); nsIMdbTable *GetPabTable() {return m_mdbPabTable;} - static nsAddrDatabase* FindInCache(nsFileSpec *dbName); + static nsAddrDatabase* FindInCache(nsIFile *dbName); static void CleanupCache(); @@ -328,12 +328,7 @@ protected: static void AddToCache(nsAddrDatabase* pAddrDB) {GetDBCache()->AppendElement(pAddrDB);} static void RemoveFromCache(nsAddrDatabase* pAddrDB); static PRInt32 FindInCache(nsAddrDatabase* pAddrDB); - PRBool MatchDbName(nsFileSpec *dbName); // returns TRUE if they match - -#if defined(XP_WIN) || defined(XP_OS2) || defined(XP_MAC) // this should go away when we can provide our own file stream to MDB/Mork - static void UnixToNative(char*& ioPath); -#endif - + PRBool MatchDbName(nsIFile *dbName); // returns TRUE if they match void YarnToUInt32(struct mdbYarn *yarn, PRUint32 *pResult); void GetCharStringYarn(char* str, struct mdbYarn* strYarn); @@ -389,7 +384,7 @@ protected: nsIMdbStore *m_mdbStore; nsIMdbTable *m_mdbPabTable; nsIMdbTable *m_mdbDeletedCardsTable; - nsFileSpec m_dbName; + nsCOMPtr m_dbName; PRBool m_mdbTokensInitialized; nsVoidArray /**/ *m_ChangeListeners; @@ -475,7 +470,7 @@ protected: private: nsresult GetRowForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, PRBool bIsCard, nsIMdbRow **findRow); PRBool HasRowButDeletedForCharColumn(const PRUnichar *unicodeStr, mdb_column findColumn, PRBool aIsCard, nsIMdbRow **aFindRow); - nsresult OpenInternal(nsFileSpec *aMabFile, PRBool aCreate, nsIAddrDatabase **pCardDB); + nsresult OpenInternal(nsIFile *aMabFile, PRBool aCreate, nsIAddrDatabase **pCardDB); nsresult AlertAboutCorruptMabFile(const PRUnichar *aOldFileName, const PRUnichar *aNewFileName); nsresult AlertAboutLockedMabFile(const PRUnichar *aFileName); nsresult DisplayAlert(const PRUnichar *titleName, const PRUnichar *alertStringName, diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index f3f1c4e9238..268c0c4fdb8 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Seth Spitzer * Pierre Phaneuf + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -86,7 +87,7 @@ #include "nsIDocShell.h" #include "nsAutoPtr.h" #include "nsIMsgVCardService.h" - +#include "nsIFileSpec.h" #include "nsCRT.h" #ifdef MOZ_XUL_APP diff --git a/mailnews/addrbook/src/nsDirPrefs.cpp b/mailnews/addrbook/src/nsDirPrefs.cpp index e77ef490f8f..fb3a3e46bdd 100644 --- a/mailnews/addrbook/src/nsDirPrefs.cpp +++ b/mailnews/addrbook/src/nsDirPrefs.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Seth Spitzer * Dan Mosedale + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -51,6 +52,8 @@ #include "nsIAbUpgrader.h" #include "nsXPIDLString.h" #include "nsReadableUtils.h" +#include "nsCRT.h" +#include "nsILocalFile.h" #include "prlog.h" #include "plstr.h" diff --git a/mailnews/addrbook/src/nsDirectoryDataSource.cpp b/mailnews/addrbook/src/nsDirectoryDataSource.cpp index 6a528e65f9c..1399f455a13 100644 --- a/mailnews/addrbook/src/nsDirectoryDataSource.cpp +++ b/mailnews/addrbook/src/nsDirectoryDataSource.cpp @@ -58,6 +58,8 @@ #include "nsILocaleService.h" #include "nsCollationCID.h" #include "prmem.h" +#include "nsServiceManagerUtils.h" +#include "nsCRT.h" static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID); diff --git a/mailnews/addrbook/src/nsVCardObj.h b/mailnews/addrbook/src/nsVCardObj.h index c1a0df2f04a..41c59c97f7c 100644 --- a/mailnews/addrbook/src/nsVCardObj.h +++ b/mailnews/addrbook/src/nsVCardObj.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -131,8 +132,8 @@ they will use an appropriately defined local type |vwchar_t|. #endif #include "prtypes.h" -#include "nsFileSpec.h" +class nsFileSpec; class nsOutputFileStream; PR_BEGIN_EXTERN_C diff --git a/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp b/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp index a0698b10e1b..869842c848b 100644 --- a/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp +++ b/mailnews/extensions/palmsync/src/nsAbPalmSync.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Rajiv Dayal + * Mark Banner * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -280,14 +281,13 @@ nsresult nsAbPalmHotSync::AddAllRecordsToAB(PRBool existingAB, PRInt32 aCount, l rv = OpenABDBForHotSync(PR_FALSE); NS_ENSURE_SUCCESS(rv, rv); // lets try deleting the db out from under ourselves. - nsFileSpec *abFileSpec; - rv = mABDB->GetDbPath(&abFileSpec); + nsCOMPtr abFile; + rv = mABDB->GetDbPath(getter_AddRefs(abFile)); NS_ENSURE_SUCCESS(rv, rv); mABDB->ForceClosed(); mDBOpen = PR_FALSE; mABDB = nsnull; - abFileSpec->Delete(PR_FALSE); - delete abFileSpec; + abFile->Remove(PR_FALSE); } else {