From 20feb45deb86b81ba92d41bfa418b51a92c23f4e Mon Sep 17 00:00:00 2001 From: "srilatha%netscape.com" Date: Sat, 11 May 2002 03:24:23 +0000 Subject: [PATCH] Fix for bug # 124057. Deleting addressbook from prefs should delete it from the addressbook window r=rdayal, sr=sspitzer --- .../prefs/resources/content/pref-directory.js | 36 +++++++++++++++++-- mailnews/addrbook/public/nsIAddressBook.idl | 2 +- mailnews/addrbook/src/nsAbBSDirectory.cpp | 8 +++++ mailnews/addrbook/src/nsAddressBook.cpp | 12 +++---- mailnews/addrbook/src/nsAddressBook.h | 2 +- 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/mailnews/addrbook/prefs/resources/content/pref-directory.js b/mailnews/addrbook/prefs/resources/content/pref-directory.js index bd8d1114b633..f06c2456c9fa 100644 --- a/mailnews/addrbook/prefs/resources/content/pref-directory.js +++ b/mailnews/addrbook/prefs/resources/content/pref-directory.js @@ -420,7 +420,21 @@ function onAccept() } var am = Components.classes["@mozilla.org/messenger/account-manager;1"] .getService(Components.interfaces.nsIMsgAccountManager); - if (am) { + if (am) { + var RDF, addressbook, addressbookDS; + try { + // the rdf service + RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"]. + getService(Components.interfaces.nsIRDFService); + // get the datasource for the addressdirectory + addressbookDS = RDF.GetDataSource("rdf:addressdirectory"); + addressbook = Components.classes["@mozilla.org/addressbook;1"]. + createInstance(Components.interfaces.nsIAddressBook); + } + catch(ex){ + dump("Failed to get RDF Service or addressbook " + ex + "\n"); + } + var allIdentities = am.allIdentities; var identitiesCount = allIdentities.Count(); var identityServer = new Array(); @@ -442,7 +456,25 @@ function onAccept() identityServer[j].deleted = true; } } - gPrefInt.deleteBranch(gDeletedDirectories[i]); + try { + // delete the directory + var parentArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); + + // moz-abdirectory:// is the RDF root to get all types of addressbooks. + var parentDir = RDF.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory); + parentArray.AppendElement(parentDir); + var resourceArray = Components.classes["@mozilla.org/supports-array;1"].createInstance(Components.interfaces.nsISupportsArray); + + // the RDF resource URI for LDAPDirectory will be moz-abldapdirectory:// + var selectedABURI = "moz-abldapdirectory://" + gDeletedDirectories[i]; + var selectedABDirectory = RDF.GetResource(selectedABURI).QueryInterface(Components.interfaces.nsIAbDirectory); + var selectedABResource = selectedABDirectory.QueryInterface(Components.interfaces.nsIRDFResource); + resourceArray.AppendElement(selectedABResource); + addressbook.deleteAddressBooks(addressbookDS, parentArray, resourceArray); + } + catch(ex){ + dump("Failed to delete the addressbook " + ex + "\n"); + } } var svc = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefService); diff --git a/mailnews/addrbook/public/nsIAddressBook.idl b/mailnews/addrbook/public/nsIAddressBook.idl index ad343b5c0ffb..06d6b6c8d407 100644 --- a/mailnews/addrbook/public/nsIAddressBook.idl +++ b/mailnews/addrbook/public/nsIAddressBook.idl @@ -48,7 +48,7 @@ interface nsIAbDirectory; interface nsIAddressBook : nsISupports { void newAddressBook(in nsIAbDirectoryProperties aProperties); - void deleteAddressBooks(in nsIRDFCompositeDataSource db, in nsISupportsArray parentDir, in nsISupportsArray aResourceArray); + void deleteAddressBooks(in nsIRDFDataSource aDS, in nsISupportsArray aParentDir, in nsISupportsArray aResourceArray); void setDocShellWindow(in nsIDOMWindowInternal win); void exportAddressBook(in nsIAbDirectory aDirectory); void convertLDIFtoMAB(in nsIFileSpec fileSpec, in boolean migrating, in nsIAddrDatabase db, in boolean bStoreLocAsHome, in boolean bImportingComm4x); diff --git a/mailnews/addrbook/src/nsAbBSDirectory.cpp b/mailnews/addrbook/src/nsAbBSDirectory.cpp index fcfef32dba77..a0687b478b27 100644 --- a/mailnews/addrbook/src/nsAbBSDirectory.cpp +++ b/mailnews/addrbook/src/nsAbBSDirectory.cpp @@ -353,6 +353,14 @@ NS_IMETHODIMP nsAbBSDirectory::DeleteDirectory(nsIAbDirectory *directory) if (!directory) return NS_ERROR_NULL_POINTER; + // if addressbook is not launched yet mSevers will not be initialized + // calling GetChidNodes will initialize mServers + if (!mInitialized) { + nsCOMPtr subDirectories; + rv = GetChildNodes(getter_AddRefs(subDirectories)); + NS_ENSURE_SUCCESS(rv, rv); + } + DIR_Server *server = nsnull; nsVoidKey key((void *)directory); server = (DIR_Server* )mServers.Get (&key); diff --git a/mailnews/addrbook/src/nsAddressBook.cpp b/mailnews/addrbook/src/nsAddressBook.cpp index 7d03d77fe753..53909ff7f881 100644 --- a/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mailnews/addrbook/src/nsAddressBook.cpp @@ -201,16 +201,16 @@ NS_IMETHODIMP nsAddressBook::NewAddressBook(nsIAbDirectoryProperties *aPropertie } NS_IMETHODIMP nsAddressBook::DeleteAddressBooks -(nsIRDFCompositeDataSource* db, nsISupportsArray *parentDir, nsISupportsArray *aResourceArray) +(nsIRDFDataSource* aDS, nsISupportsArray *aParentDir, nsISupportsArray *aResourceArray) { - NS_ENSURE_ARG_POINTER(db); - NS_ENSURE_ARG_POINTER(parentDir); + NS_ENSURE_ARG_POINTER(aDS); + NS_ENSURE_ARG_POINTER(aParentDir); NS_ENSURE_ARG_POINTER(aResourceArray); - - return DoCommand(db, NC_RDF_DELETE, parentDir, aResourceArray); + + return DoCommand(aDS, NC_RDF_DELETE, aParentDir, aResourceArray); } -nsresult nsAddressBook::DoCommand(nsIRDFCompositeDataSource* db, +nsresult nsAddressBook::DoCommand(nsIRDFDataSource* db, const char *command, nsISupportsArray *srcArray, nsISupportsArray *argumentArray) diff --git a/mailnews/addrbook/src/nsAddressBook.h b/mailnews/addrbook/src/nsAddressBook.h index f831ca24dbd5..6c70ba98af28 100644 --- a/mailnews/addrbook/src/nsAddressBook.h +++ b/mailnews/addrbook/src/nsAddressBook.h @@ -69,7 +69,7 @@ public: CMDLINEHANDLER_REGISTERPROC_DECLS protected: - nsresult DoCommand(nsIRDFCompositeDataSource *db, const char * command, + nsresult DoCommand(nsIRDFDataSource *db, const char * command, nsISupportsArray *srcArray, nsISupportsArray *arguments); nsresult GetAbDatabaseFromFile(char* pDbFile, nsIAddrDatabase **db);