Fix for 124059. Made creating and modifying addrbooks work the right way. r=shliang, sr=sspitzer.
git-svn-id: svn://10.0.0.236/trunk@138909 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
/* -*- Mode: Java; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
var gPrefstring = "ldap_2.servers.";
|
||||
var gPref_string_desc = "";
|
||||
var gPrefInt = null;
|
||||
var gCurrentDirectory = null;
|
||||
var gCurrentDirectoryString = null;
|
||||
@@ -8,6 +6,7 @@ var gCurrentDirectoryString = null;
|
||||
const kDefaultMaxHits = 100;
|
||||
const kDefaultLDAPPort = 389;
|
||||
const kDefaultSecureLDAPPort = 636;
|
||||
const kLDAPDirectory = 0; // defined in nsDirPrefs.h
|
||||
|
||||
function Startup()
|
||||
{
|
||||
@@ -135,54 +134,6 @@ function fillDefaultSettings()
|
||||
sub.radioGroup.selectedItem = sub;
|
||||
}
|
||||
|
||||
// find a unique server-name for the new directory server
|
||||
// from the description entered by the user.
|
||||
function createUniqueServername()
|
||||
{
|
||||
// gPref_string_desc is the description entered by the user.
|
||||
// Just get the alphabets and digits from the description.
|
||||
// remove spaces and special characters from description.
|
||||
var user_Id = 0;
|
||||
var re = /[A-Za-z0-9]/g;
|
||||
var str = gPref_string_desc.match(re);
|
||||
var temp = "";
|
||||
|
||||
if (!str) {
|
||||
try {
|
||||
user_Id = gPrefInt.getIntPref("ldap_2.user_id");
|
||||
}
|
||||
catch(ex){
|
||||
user_Id = 0;
|
||||
}
|
||||
++user_Id;
|
||||
temp = "user_directory_" + user_Id;
|
||||
str = temp;
|
||||
try {
|
||||
gPrefInt.setIntPref("ldap_2.user_id", user_Id);
|
||||
}
|
||||
catch(ex) {}
|
||||
}
|
||||
else {
|
||||
var len = str.length;
|
||||
if (len > 20) len = 20;
|
||||
for (var count = 0; count < len; count++)
|
||||
{
|
||||
temp += str[count];
|
||||
}
|
||||
}
|
||||
|
||||
gPref_string_desc = temp;
|
||||
while (temp) {
|
||||
temp = "";
|
||||
try{
|
||||
temp = gPrefInt.getComplexValue(gPrefstring+gPref_string_desc+".description",
|
||||
Components.interfaces.nsISupportsString).data;
|
||||
} catch(e){}
|
||||
if (temp)
|
||||
gPref_string_desc += str[0];
|
||||
}
|
||||
}
|
||||
|
||||
function hasOnlyWhitespaces(string)
|
||||
{
|
||||
// get all the whitespace characters of string and assign them to str.
|
||||
@@ -208,15 +159,14 @@ function hasCharacters(number)
|
||||
|
||||
function onAccept()
|
||||
{
|
||||
var properties = Components.classes["@mozilla.org/addressbook/properties;1"].createInstance(Components.interfaces.nsIAbDirectoryProperties);
|
||||
var addressbook = Components.classes["@mozilla.org/addressbook;1"].createInstance(Components.interfaces.nsIAddressBook);
|
||||
properties.dirType = kLDAPDirectory;
|
||||
|
||||
try {
|
||||
var pref_string_content = "";
|
||||
var pref_string_title = "";
|
||||
|
||||
if (!gPrefInt) {
|
||||
gPrefInt = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
}
|
||||
|
||||
var ldapUrl = Components.classes["@mozilla.org/network/ldap-url;1"];
|
||||
ldapUrl = ldapUrl.createInstance().
|
||||
QueryInterface(Components.interfaces.nsILDAPURL);
|
||||
@@ -228,8 +178,7 @@ function onAccept()
|
||||
var dn = document.getElementById("login").value;
|
||||
var results = document.getElementById("results").value;
|
||||
var errorValue = null;
|
||||
gPref_string_desc = description;
|
||||
if ((!gPref_string_desc) || hasOnlyWhitespaces(gPref_string_desc))
|
||||
if ((!description) || hasOnlyWhitespaces(description))
|
||||
errorValue = "invalidName";
|
||||
else if ((!hostname) || hasOnlyWhitespaces(hostname))
|
||||
errorValue = "invalidHostname";
|
||||
@@ -239,20 +188,7 @@ function onAccept()
|
||||
else if (results && hasCharacters(results))
|
||||
errorValue = "invalidResults";
|
||||
if (!errorValue) {
|
||||
pref_string_content = gPref_string_desc;
|
||||
if (gCurrentDirectory && gCurrentDirectoryString) {
|
||||
gPref_string_desc = gCurrentDirectoryString;
|
||||
} else {
|
||||
createUniqueServername();
|
||||
gPref_string_desc = gPrefstring + gPref_string_desc;
|
||||
}
|
||||
|
||||
pref_string_title = gPref_string_desc + "." + "description";
|
||||
var str = Components.classes["@mozilla.org/supports-string;1"]
|
||||
.createInstance(Components.interfaces.nsISupportsString);
|
||||
str.data = pref_string_content;
|
||||
gPrefInt.setComplexValue(pref_string_title,
|
||||
Components.interfaces.nsISupportsString, str);
|
||||
properties.description = description;
|
||||
|
||||
ldapUrl.host = hostname;
|
||||
ldapUrl.dn = document.getElementById("basedn").value;
|
||||
@@ -272,49 +208,42 @@ function onAccept()
|
||||
}
|
||||
if (secure.checked)
|
||||
ldapUrl.options |= ldapUrl.OPT_SECURE;
|
||||
pref_string_title = gPref_string_desc + ".uri";
|
||||
|
||||
var uri = Components.classes["@mozilla.org/supports-string;1"]
|
||||
.createInstance(Components.interfaces.nsISupportsString);
|
||||
uri.data = ldapUrl.spec;
|
||||
gPrefInt.setComplexValue(pref_string_title,
|
||||
Components.interfaces.nsISupportsString, uri);
|
||||
properties.URI = ldapUrl.spec;
|
||||
properties.maxHits = results;
|
||||
properties.authDn = dn;
|
||||
|
||||
pref_string_content = results;
|
||||
pref_string_title = gPref_string_desc + ".maxHits";
|
||||
if (pref_string_content != kDefaultMaxHits) {
|
||||
gPrefInt.setIntPref(pref_string_title, pref_string_content);
|
||||
} else {
|
||||
try {
|
||||
gPrefInt.clearUserPref(pref_string_title);
|
||||
} catch (ex) {
|
||||
}
|
||||
// check if we are modifying an existing directory or adding a new directory
|
||||
if (gCurrentDirectory && gCurrentDirectoryString) {
|
||||
// we are modifying an existing directory
|
||||
// the rdf service
|
||||
var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].
|
||||
getService(Components.interfaces.nsIRDFService);
|
||||
// get the datasource for the addressdirectory
|
||||
var addressbookDS = RDF.GetDataSource("rdf:addressdirectory");
|
||||
|
||||
// moz-abdirectory:// is the RDF root to get all types of addressbooks.
|
||||
var parentDir = RDF.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory);
|
||||
|
||||
// the RDF resource URI for LDAPDirectory will be moz-abldapdirectory://<prefName>
|
||||
var selectedABURI = "moz-abldapdirectory://" + gCurrentDirectoryString;
|
||||
var selectedABDirectory = RDF.GetResource(selectedABURI).QueryInterface(Components.interfaces.nsIAbDirectory);
|
||||
|
||||
// Carry over existing palm category id and mod time if it was synced before.
|
||||
var oldProperties = selectedABDirectory.directoryProperties;
|
||||
properties.categoryId = oldProperties.categoryId;
|
||||
properties.syncTimeStamp = oldProperties.syncTimeStamp;
|
||||
|
||||
// Now do the modification.
|
||||
addressbook.modifyAddressBook(addressbookDS, parentDir, selectedABDirectory, properties);
|
||||
window.opener.gNewServerString = gCurrentDirectoryString;
|
||||
}
|
||||
|
||||
pref_string_title = gPref_string_desc + ".auth.dn";
|
||||
var dnWString = Components.classes["@mozilla.org/supports-string;1"]
|
||||
.createInstance(Components.interfaces.nsISupportsString);
|
||||
dnWString.data = dn;
|
||||
gPrefInt.setComplexValue(pref_string_title,
|
||||
Components.interfaces.nsISupportsString,
|
||||
dnWString);
|
||||
|
||||
// We don't actually allow the password to be saved in the preferences;
|
||||
// this preference is (effectively) ignored by the current code base.
|
||||
// It's here because versions of Mozilla 1.0 and earlier (maybe 1.1alpha
|
||||
// too?) would blow away the .auth.dn preference if .auth.savePassword
|
||||
// is not set. To avoid trashing things for users who switch between
|
||||
// versions, we'll set it. Once the versions in question become
|
||||
// obsolete enough, this workaround can be gotten rid of.
|
||||
//
|
||||
try {
|
||||
gPrefInt.setBoolPref(gPref_string_desc + ".auth.savePassword", true);
|
||||
} catch (ex) {
|
||||
// if this fails, we can live with that; keep going
|
||||
else { // adding a new directory
|
||||
addressbook.newAddressBook(properties);
|
||||
window.opener.gNewServerString = properties.prefName;
|
||||
}
|
||||
|
||||
window.opener.gNewServer = description;
|
||||
window.opener.gNewServerString = gPref_string_desc;
|
||||
// set window.opener.gUpdate to true so that LDAP Directory Servers
|
||||
// dialog gets updated
|
||||
window.opener.gUpdate = true;
|
||||
|
||||
@@ -55,6 +55,11 @@ interface nsIAbDirectoryProperties : nsISupports {
|
||||
attribute string URI;
|
||||
attribute string prefName;
|
||||
attribute string fileName;
|
||||
attribute unsigned long dirType;
|
||||
attribute unsigned long maxHits;
|
||||
attribute string authDn;
|
||||
attribute unsigned long syncTimeStamp;
|
||||
attribute long categoryId;
|
||||
};
|
||||
|
||||
[scriptable, uuid(AA920C90-1DD1-11B2-96D3-AA81268ADAFC)]
|
||||
@@ -75,7 +80,7 @@ interface nsIAbDirectory : nsISupports {
|
||||
// The supported operations
|
||||
readonly attribute long operations;
|
||||
|
||||
// The name of the directory
|
||||
// The description of the directory
|
||||
attribute wstring dirName;
|
||||
|
||||
// will be used for LDAP replication
|
||||
@@ -85,6 +90,8 @@ interface nsIAbDirectory : nsISupports {
|
||||
// list or not
|
||||
attribute PRBool isMailList;
|
||||
|
||||
// Get the directory properties
|
||||
readonly attribute nsIAbDirectoryProperties directoryProperties;
|
||||
|
||||
// Get the children directories
|
||||
readonly attribute nsIEnumerator childNodes;
|
||||
@@ -94,6 +101,9 @@ interface nsIAbDirectory : nsISupports {
|
||||
// the mailing lists too
|
||||
readonly attribute nsIEnumerator childCards;
|
||||
|
||||
// Modifies a top level directory,
|
||||
// which also updates the preferences
|
||||
void modifyDirectory(in nsIAbDirectory directory, in nsIAbDirectoryProperties aProperties);
|
||||
|
||||
// Deletes either a mailing list or a top
|
||||
// level directory, which also updates the
|
||||
@@ -192,4 +202,7 @@ interface nsIAbDirectory : nsISupports {
|
||||
|
||||
wstring getValueForCard(in nsIAbCard card, in string name);
|
||||
void setValueForCard(in nsIAbCard card, in string name, in wstring value);
|
||||
|
||||
// the id of the directory used in prefs
|
||||
attribute ACString dirPrefId;
|
||||
};
|
||||
|
||||
@@ -48,6 +48,7 @@ interface nsIAbDirectory;
|
||||
interface nsIAddressBook : nsISupports
|
||||
{
|
||||
void newAddressBook(in nsIAbDirectoryProperties aProperties);
|
||||
void modifyAddressBook(in nsIRDFDataSource aDS, in nsIAbDirectory aParentDir, in nsIAbDirectory aDirectory, in nsIAbDirectoryProperties aProperties);
|
||||
void deleteAddressBooks(in nsIRDFDataSource aDS, in nsISupportsArray aParentDir, in nsISupportsArray aResourceArray);
|
||||
void setDocShellWindow(in nsIDOMWindowInternal win);
|
||||
void exportAddressBook(in nsIAbDirectory aDirectory);
|
||||
|
||||
@@ -61,7 +61,16 @@ var gAddressBookPanelAbListener = {
|
||||
}
|
||||
},
|
||||
onItemPropertyChanged: function(item, property, oldValue, newValue) {
|
||||
// will not be called
|
||||
try {
|
||||
var directory = item.QueryInterface(Components.interfaces.nsIAbDirectory);
|
||||
// check if the item being changed is the directory
|
||||
// that we are showing in the addressbook sidebar
|
||||
if (directory == GetAbView().directory) {
|
||||
LoadPreviouslySelectedAB();
|
||||
}
|
||||
}
|
||||
catch (ex) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -104,10 +113,12 @@ function AbPanelLoad()
|
||||
LoadPreviouslySelectedAB();
|
||||
|
||||
// add a listener, so we can switch directories if
|
||||
// the current directory is deleted
|
||||
// the current directory is deleted, and change the name if the
|
||||
// selected directory's name is modified
|
||||
var addrbookSession = Components.classes["@mozilla.org/addressbook/services/session;1"].getService().QueryInterface(Components.interfaces.nsIAddrBookSession);
|
||||
// this listener only cares when a directory is removed
|
||||
addrbookSession.addAddressBookListener(gAddressBookPanelAbListener, Components.interfaces.nsIAbListener.directoryRemoved);
|
||||
// this listener only cares when a directory is removed or modified
|
||||
addrbookSession.addAddressBookListener(gAddressBookPanelAbListener,
|
||||
Components.interfaces.nsIAbListener.directoryRemoved | Components.interfaces.nsIAbListener.changed);
|
||||
|
||||
gSearchInput = document.getElementById("searchInput");
|
||||
}
|
||||
@@ -115,7 +126,8 @@ function AbPanelLoad()
|
||||
|
||||
function AbPanelOnChange(event)
|
||||
{
|
||||
abList.setAttribute("selectedAB", abList.value);
|
||||
var abPopup = document.getElementById('addressbookList');
|
||||
abPopup.setAttribute("selectedAB", abPopup.value);
|
||||
}
|
||||
|
||||
function AbPanelUnload()
|
||||
|
||||
@@ -56,6 +56,7 @@ var gCardViewBoxEmail1;
|
||||
const kDisplayName = 0;
|
||||
const kLastNameFirst = 1;
|
||||
const kFirstNameFirst = 2;
|
||||
const kPABDirectory = 2; // defined in nsDirPrefs.h
|
||||
|
||||
var gAddressBookAbListener = {
|
||||
onItemAdded: function(parentDir, item) {
|
||||
@@ -286,9 +287,46 @@ function AbCreateNewAddressBook(name)
|
||||
{
|
||||
var properties = Components.classes["@mozilla.org/addressbook/properties;1"].createInstance(Components.interfaces.nsIAbDirectoryProperties);
|
||||
properties.description = name;
|
||||
properties.dirType = kPABDirectory;
|
||||
top.addressbook.newAddressBook(properties);
|
||||
}
|
||||
|
||||
// not used yet. just here for when we fix bug #17230
|
||||
function AbRenameAddressBook()
|
||||
{
|
||||
// When the UI code for renaming addrbooks (bug #17230) is ready, just
|
||||
// change 'properties.description' setting below and it should just work.
|
||||
// get select ab
|
||||
var selectedABURI = GetSelectedDirectory();
|
||||
//dump("In AbRenameAddressBook() selectedABURI=" + selectedABURI + "\n");
|
||||
|
||||
// the rdf service
|
||||
var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
|
||||
// get the datasource for the addressdirectory
|
||||
var addressbookDS = RDF.GetDataSource("rdf:addressdirectory");
|
||||
|
||||
// moz-abdirectory:// is the RDF root to get all types of addressbooks.
|
||||
var parentDir = RDF.GetResource("moz-abdirectory://").QueryInterface(Components.interfaces.nsIAbDirectory);
|
||||
|
||||
// the RDF resource URI for LDAPDirectory will be like: "moz-abmdbdirectory://abook-3.mab"
|
||||
var selectedABDirectory = RDF.GetResource(selectedABURI).QueryInterface(Components.interfaces.nsIAbDirectory);
|
||||
|
||||
// Copy existing dir type category id and mod time so they won't get reset.
|
||||
var oldProperties = selectedABDirectory.directoryProperties;
|
||||
|
||||
// Create and fill in properties info
|
||||
var properties = Components.classes["@mozilla.org/addressbook/properties;1"].createInstance(Components.interfaces.nsIAbDirectoryProperties);
|
||||
properties.URI = selectedABURI;
|
||||
properties.dirType = oldProperties.dirType;
|
||||
properties.categoryId = oldProperties.categoryId;
|
||||
properties.syncTimeStamp = oldProperties.syncTimeStamp;
|
||||
// XXX TODO: set description to whatever users enter. hard coded for now.
|
||||
properties.description = "Foo bar";
|
||||
|
||||
// Now do the modification.
|
||||
addressbook.modifyAddressBook(addressbookDS, parentDir, selectedABDirectory, properties);
|
||||
}
|
||||
|
||||
function GetPrintSettings()
|
||||
{
|
||||
var prevPS = gPrintSettings;
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsAbBSDirectory.h"
|
||||
#include "nsAbUtils.h"
|
||||
|
||||
@@ -246,11 +247,27 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(nsIAbDirectoryProperties *aPro
|
||||
|
||||
nsAutoString description;
|
||||
nsXPIDLCString fileName;
|
||||
nsXPIDLCString uri;
|
||||
nsXPIDLCString authDn;
|
||||
|
||||
rv = aProperties->GetDescription(description);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aProperties->GetFileName(getter_Copies(fileName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aProperties->GetURI(getter_Copies(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRUint32 dirType;
|
||||
rv = aProperties->GetDirType(&dirType);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
PRUint32 maxHits;
|
||||
rv = aProperties->GetMaxHits(&maxHits);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aProperties->GetAuthDn(getter_Copies(authDn));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
/*
|
||||
@@ -265,8 +282,9 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(nsIAbDirectoryProperties *aPro
|
||||
DIR_Server* server = nsnull;
|
||||
rv = DIR_AddNewAddressBook(description.get(),
|
||||
(fileName.Length ()) ? fileName.get () : nsnull,
|
||||
PR_FALSE /* is_migrating */,
|
||||
PABDirectory,
|
||||
PR_FALSE /* is_migrating */, uri.get(),
|
||||
maxHits, authDn,
|
||||
(DirectoryType)dirType,
|
||||
&server);
|
||||
NS_ENSURE_SUCCESS (rv, rv);
|
||||
|
||||
@@ -274,10 +292,15 @@ NS_IMETHODIMP nsAbBSDirectory::CreateNewDirectory(nsIAbDirectoryProperties *aPro
|
||||
rv = aProperties->SetFileName(server->fileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (dirType != LDAPDirectory) {
|
||||
// Add the URI property
|
||||
nsCAutoString URI(NS_LITERAL_CSTRING(kMDBDirectoryRoot) + nsDependentCString(server->fileName));
|
||||
rv = aProperties->SetURI(URI.get());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
rv = aProperties->SetPrefName(server->prefName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = CreateDirectoriesFromFactory(aProperties, server, PR_TRUE /* notify */);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
@@ -298,7 +321,7 @@ NS_IMETHODIMP nsAbBSDirectory::CreateDirectoryByURI(const PRUnichar *aDisplayNam
|
||||
fileName = aURI + kMDBDirectoryRootLen;
|
||||
|
||||
DIR_Server * server = nsnull;
|
||||
rv = DIR_AddNewAddressBook(aDisplayName, fileName, migrating, PABDirectory, &server);
|
||||
rv = DIR_AddNewAddressBook(aDisplayName, fileName, migrating, aURI, 0, nsnull, PABDirectory, &server);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIAbDirectoryProperties> properties;
|
||||
@@ -348,13 +371,12 @@ PRBool PR_CALLBACK GetDirectories_getDirectory (nsHashKey *aKey, void *aData, vo
|
||||
|
||||
NS_IMETHODIMP nsAbBSDirectory::DeleteDirectory(nsIAbDirectory *directory)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsresult rv;
|
||||
|
||||
if (!directory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ENSURE_ARG_POINTER(directory);
|
||||
|
||||
// if addressbook is not launched yet mSevers will not be initialized
|
||||
// calling GetChidNodes will initialize mServers
|
||||
// calling GetChildNodes will initialize mServers
|
||||
if (!mInitialized) {
|
||||
nsCOMPtr<nsIEnumerator> subDirectories;
|
||||
rv = GetChildNodes(getter_AddRefs(subDirectories));
|
||||
@@ -407,6 +429,84 @@ NS_IMETHODIMP nsAbBSDirectory::DeleteDirectory(nsIAbDirectory *directory)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbBSDirectory::ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ENSURE_ARG_POINTER(directory);
|
||||
NS_ENSURE_ARG_POINTER(aProperties);
|
||||
|
||||
// if addressbook is not launched yet mSevers will not be initialized
|
||||
// calling GetChildNodes will initialize mServers
|
||||
if (!mInitialized) {
|
||||
nsCOMPtr<nsIEnumerator> 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);
|
||||
|
||||
if (!server)
|
||||
return NS_ERROR_FAILURE;
|
||||
GetDirectories getDirectories (server);
|
||||
mServers.Enumerate (GetDirectories_getDirectory, (void *)&getDirectories);
|
||||
|
||||
nsAutoString description;
|
||||
nsXPIDLCString uri;
|
||||
nsXPIDLCString authDn;
|
||||
PRUint32 maxHits, palmSyncTimeStamp;
|
||||
PRInt32 palmCategoryId;
|
||||
|
||||
rv = aProperties->GetDescription(description);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_ConvertUTF8toUCS2 oldValue(server->description);
|
||||
nsCRT::free(server->description);
|
||||
NS_ConvertUCS2toUTF8 utf8str(description.get());
|
||||
server->description = ToNewCString(utf8str);
|
||||
|
||||
rv = aProperties->GetURI(getter_Copies(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCRT::free(server->uri);
|
||||
server->uri = ToNewCString(uri);
|
||||
|
||||
rv = aProperties->GetMaxHits(&maxHits);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
server->maxHits = maxHits;
|
||||
|
||||
rv=aProperties->GetAuthDn(getter_Copies(authDn));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
server->authDn = ToNewCString(authDn);
|
||||
|
||||
rv = aProperties->GetSyncTimeStamp(&palmSyncTimeStamp);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
server->PalmSyncTimeStamp = palmSyncTimeStamp;
|
||||
|
||||
rv = aProperties->GetCategoryId(&palmCategoryId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
server->PalmCategoryId = palmCategoryId;
|
||||
|
||||
DIR_SavePrefsForOneServer(server);
|
||||
|
||||
if (!oldValue.Equals(description)) {
|
||||
nsCOMPtr<nsIAbDirectory> modifiedDir;
|
||||
getDirectories.directories->GetElementAt (0, getter_AddRefs(modifiedDir));
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession =
|
||||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
abSession->NotifyItemPropertyChanged(modifiedDir, "DirName", oldValue.get(), description.get());
|
||||
}
|
||||
|
||||
// Save modified address book into pref file.
|
||||
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
return prefService->SavePrefFile(nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbBSDirectory::HasDirectory(nsIAbDirectory *dir, PRBool *hasDir)
|
||||
{
|
||||
if (!hasDir)
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
NS_IMETHOD GetChildNodes(nsIEnumerator* *result);
|
||||
NS_IMETHOD CreateNewDirectory(nsIAbDirectoryProperties *aProperties);
|
||||
NS_IMETHOD CreateDirectoryByURI(const PRUnichar *dirName, const char *uri, PRBool migrating);
|
||||
NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties);
|
||||
NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
|
||||
NS_IMETHOD HasDirectory(nsIAbDirectory *dir, PRBool *hasDir);
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "nsIAbCard.h"
|
||||
|
||||
#include "nsDirPrefs.h"
|
||||
#include "prmem.h"
|
||||
#include "rdf.h"
|
||||
|
||||
#include "mdb.h"
|
||||
@@ -82,6 +83,7 @@ NS_IMETHODIMP nsAbDirProperty::GetOperations(PRInt32 *aOperations)
|
||||
// Default is to support all operations.
|
||||
// Inheriting implementations may override
|
||||
// to reduce supported operations
|
||||
NS_ENSURE_ARG_POINTER(aOperations);
|
||||
*aOperations = nsIAbDirectory::opRead |
|
||||
nsIAbDirectory::opWrite |
|
||||
nsIAbDirectory::opSearch;
|
||||
@@ -222,6 +224,11 @@ NS_IMETHODIMP
|
||||
nsAbDirProperty::GetChildCards(nsIEnumerator **childCards)
|
||||
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAbDirProperty::ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties)
|
||||
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAbDirProperty::DeleteDirectory(nsIAbDirectory *dierctory)
|
||||
{ return NS_ERROR_NOT_IMPLEMENTED; }
|
||||
@@ -294,10 +301,79 @@ NS_IMETHODIMP nsAbDirProperty::GetSearchDuringLocalAutocomplete(PRBool *aSearchD
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirProperty::GetDirPrefId(nsACString &aDirPrefId)
|
||||
{
|
||||
aDirPrefId = m_DirPrefId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirProperty::SetDirPrefId(const nsACString &aDirPrefId)
|
||||
{
|
||||
m_DirPrefId.Assign(aDirPrefId);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirProperty::GetDirectoryProperties(nsIAbDirectoryProperties **aDirectoryProperties)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDirectoryProperties);
|
||||
|
||||
nsresult rv;
|
||||
DIR_Server *server = (DIR_Server *)PR_Malloc(sizeof(DIR_Server));
|
||||
if (!server)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
DIR_InitServer(server);
|
||||
nsCString prefId;
|
||||
rv = GetDirPrefId(prefId);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
server->prefName = nsCRT::strdup(prefId.get());
|
||||
DIR_GetPrefsForOneServer(server, PR_FALSE, PR_FALSE);
|
||||
|
||||
// Now create the obj and move info in DIR_Server to it.
|
||||
nsCOMPtr <nsIAbDirectoryProperties> properties;
|
||||
properties = do_CreateInstance(NS_ABDIRECTORYPROPERTIES_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
NS_ConvertUTF8toUCS2 description (server->description);
|
||||
rv = properties->SetDescription(description);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetFileName(server->fileName);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetPrefName(server->prefName);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetURI(server->uri);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetDirType(server->dirType);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetMaxHits(server->maxHits);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetAuthDn(server->authDn);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetCategoryId(server->PalmCategoryId);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = properties->SetSyncTimeStamp(server->PalmSyncTimeStamp);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
NS_IF_ADDREF(*aDirectoryProperties = properties);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsAbDirectoryProperties::nsAbDirectoryProperties(void)
|
||||
{
|
||||
mDirType = LDAPDirectory;
|
||||
mMaxHits = 0;
|
||||
mSyncTimeStamp = 0;
|
||||
mCategoryId = -1;
|
||||
}
|
||||
|
||||
nsAbDirectoryProperties::~nsAbDirectoryProperties(void)
|
||||
@@ -350,17 +426,80 @@ nsAbDirectoryProperties::GetFileName(char **aFileName)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAbDirectoryProperties::SetPrefName(const char *aPrefName)
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::SetPrefName(const char *aPrefName)
|
||||
{
|
||||
mPrefName = aPrefName;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAbDirectoryProperties::GetPrefName(char **aPrefName)
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::GetPrefName(char **aPrefName)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aPrefName);
|
||||
*aPrefName = ToNewCString(mPrefName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::SetDirType(PRUint32 aDirType)
|
||||
{
|
||||
mDirType = aDirType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::GetDirType(PRUint32 *aDirType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDirType);
|
||||
*aDirType = mDirType;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::SetMaxHits(PRUint32 aMaxHits)
|
||||
{
|
||||
mMaxHits = aMaxHits;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::GetMaxHits(PRUint32 *aMaxHits)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMaxHits);
|
||||
*aMaxHits = mMaxHits;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::SetAuthDn(const char *aAuthDn)
|
||||
{
|
||||
mAuthDn = aAuthDn;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::GetAuthDn(char **aAuthDn)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAuthDn);
|
||||
*aAuthDn = ToNewCString(mAuthDn);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::SetCategoryId(PRInt32 aCategoryId)
|
||||
{
|
||||
mCategoryId = aCategoryId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::GetCategoryId(PRInt32 *aCategoryId)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCategoryId);
|
||||
*aCategoryId = mCategoryId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::SetSyncTimeStamp(PRUint32 aSyncTimeStamp)
|
||||
{
|
||||
mSyncTimeStamp = aSyncTimeStamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryProperties::GetSyncTimeStamp(PRUint32 *aSyncTimeStamp)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aSyncTimeStamp);
|
||||
*aSyncTimeStamp = mSyncTimeStamp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,8 @@ protected:
|
||||
nsString m_ListNickName;
|
||||
nsString m_Description;
|
||||
PRBool m_IsMailList;
|
||||
nsCString m_DirPrefId; // ie,"ldap_2.servers.pab"
|
||||
|
||||
|
||||
nsCOMPtr<nsISupportsArray> m_AddressList;
|
||||
|
||||
@@ -97,5 +99,10 @@ private:
|
||||
nsCString mURI;
|
||||
nsCString mFileName;
|
||||
nsCString mPrefName;
|
||||
PRUint32 mDirType;
|
||||
PRUint32 mMaxHits;
|
||||
nsCString mAuthDn;
|
||||
PRUint32 mSyncTimeStamp;
|
||||
PRInt32 mCategoryId;
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -76,6 +76,7 @@ NS_IMETHODIMP nsAbLDAPDirFactory::CreateDirectory(nsIAbDirectoryProperties *aPro
|
||||
|
||||
nsXPIDLCString uri;
|
||||
nsAutoString description;
|
||||
nsXPIDLCString prefName;
|
||||
|
||||
rv = aProperties->GetDescription(description);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -83,6 +84,9 @@ NS_IMETHODIMP nsAbLDAPDirFactory::CreateDirectory(nsIAbDirectoryProperties *aPro
|
||||
rv = aProperties->GetURI(getter_Copies(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aProperties->GetPrefName(getter_Copies(prefName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
@@ -125,6 +129,9 @@ NS_IMETHODIMP nsAbLDAPDirFactory::CreateDirectory(nsIAbDirectoryProperties *aPro
|
||||
rv = directory->SetDirName(description.get());
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = directory->SetDirPrefId(prefName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
NS_IF_ADDREF(*aDirectories = new nsSingletonEnumerator(directory));
|
||||
return *aDirectories ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
@@ -108,11 +108,15 @@ NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProp
|
||||
|
||||
nsXPIDLCString uri;
|
||||
nsAutoString description;
|
||||
nsXPIDLCString prefName;
|
||||
|
||||
rv = aProperties->GetDescription(description);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aProperties->GetURI(getter_Copies(uri));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = aProperties->GetPrefName(getter_Copies(prefName));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIRDFService> rdf = do_GetService (NS_RDF_CONTRACTID "/rdf-service;1", &rv);
|
||||
@@ -128,6 +132,9 @@ NS_IMETHODIMP nsAbMDBDirFactory::CreateDirectory(nsIAbDirectoryProperties *aProp
|
||||
rv = directory->SetDirName(description.get());
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = directory->SetDirPrefId(prefName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession = do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
||||
@@ -134,6 +134,12 @@ nsresult nsAbMDBDirectory::RemoveCardFromAddressList(nsIAbCard* card)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::DeleteDirectory(nsIAbDirectory *directory)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@@ -88,6 +88,7 @@ public:
|
||||
// nsIAbDirectory methods:
|
||||
NS_IMETHOD GetChildNodes(nsIEnumerator* *result);
|
||||
NS_IMETHOD GetChildCards(nsIEnumerator* *result);
|
||||
NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties);
|
||||
NS_IMETHOD DeleteDirectory(nsIAbDirectory *directory);
|
||||
NS_IMETHOD DeleteCards(nsISupportsArray *cards);
|
||||
NS_IMETHOD HasCard(nsIAbCard *cards, PRBool *hasCard);
|
||||
|
||||
@@ -331,6 +331,12 @@ NS_IMETHODIMP nsAbOutlookDirectory::DeleteCards(nsISupportsArray *aCardList)
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsAbOutlookDirectory::DeleteDirectory(nsIAbDirectory *aDirectory)
|
||||
{
|
||||
if (mIsQueryURI) { return NS_ERROR_NOT_IMPLEMENTED ; }
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
NS_IMETHOD HasCard(nsIAbCard *aCard, PRBool *aHasCard) ;
|
||||
NS_IMETHOD HasDirectory(nsIAbDirectory *aDirectory, PRBool *aHasDirectory) ;
|
||||
NS_IMETHOD DeleteCards(nsISupportsArray *aCardList) ;
|
||||
NS_IMETHOD ModifyDirectory(nsIAbDirectory *directory, nsIAbDirectoryProperties *aProperties);
|
||||
NS_IMETHOD DeleteDirectory(nsIAbDirectory *aDirectory) ;
|
||||
NS_IMETHOD AddCard(nsIAbCard *aData, nsIAbCard **addedCard);
|
||||
NS_IMETHOD DropCard(nsIAbCard *aData, PRBool needToCopyCard);
|
||||
|
||||
@@ -140,6 +140,34 @@ NS_IMETHODIMP nsAddressBook::NewAddressBook(nsIAbDirectoryProperties *aPropertie
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddressBook::ModifyAddressBook
|
||||
(nsIRDFDataSource* aDS, nsIAbDirectory *aParentDir, nsIAbDirectory *aDirectory, nsIAbDirectoryProperties *aProperties)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aDS);
|
||||
NS_ENSURE_ARG_POINTER(aParentDir);
|
||||
NS_ENSURE_ARG_POINTER(aDirectory);
|
||||
NS_ENSURE_ARG_POINTER(aProperties);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISupportsArray> parentArray (do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsISupportsArray> resourceElement (do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsISupportsArray> resourceArray (do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
parentArray->AppendElement(aParentDir);
|
||||
|
||||
nsCOMPtr<nsIRDFResource> dirSource(do_QueryInterface(aDirectory, &rv));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
resourceElement->AppendElement(dirSource);
|
||||
resourceElement->AppendElement(aProperties);
|
||||
resourceArray->AppendElement(resourceElement);
|
||||
|
||||
return DoCommand(aDS, NS_LITERAL_CSTRING(NC_RDF_MODIFY), parentArray, resourceArray);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddressBook::DeleteAddressBooks
|
||||
(nsIRDFDataSource* aDS, nsISupportsArray *aParentDir, nsISupportsArray *aResourceArray)
|
||||
{
|
||||
|
||||
@@ -51,6 +51,7 @@ class nsILocalFile;
|
||||
class nsIAbDirectory;
|
||||
|
||||
#define NC_RDF_NEWABCARD "http://home.netscape.com/NC-rdf#NewCard"
|
||||
#define NC_RDF_MODIFY "http://home.netscape.com/NC-rdf#Modify"
|
||||
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
|
||||
#define NC_RDF_DELETECARD "http://home.netscape.com/NC-rdf#DeleteCards"
|
||||
#define NC_RDF_NEWDIRECTORY "http://home.netscape.com/NC-rdf#NewDirectory"
|
||||
|
||||
@@ -425,7 +425,7 @@ nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DirectoryType dirType, DIR_Server** pServer)
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, const char * uri, int maxHits, const char * authDn, DirectoryType dirType, DIR_Server** pServer)
|
||||
{
|
||||
DIR_Server * server = (DIR_Server *) PR_Malloc(sizeof(DIR_Server));
|
||||
DIR_InitServerWithType (server, dirType);
|
||||
@@ -443,6 +443,22 @@ nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, P
|
||||
server->fileName = nsCRT::strdup(fileName);
|
||||
else
|
||||
DIR_SetFileName(&server->fileName, kPersonalAddressbook);
|
||||
if (dirType == LDAPDirectory) {
|
||||
// We don't actually allow the password to be saved in the preferences;
|
||||
// this preference is (effectively) ignored by the current code base.
|
||||
// It's here because versions of Mozilla 1.0 and earlier (maybe 1.1alpha
|
||||
// too?) would blow away the .auth.dn preference if .auth.savePassword
|
||||
// is not set. To avoid trashing things for users who switch between
|
||||
// versions, we'll set it. Once the versions in question become
|
||||
// obsolete enough, this workaround can be gotten rid of.
|
||||
server->savePassword = PR_TRUE;
|
||||
if (uri)
|
||||
server->uri = nsCRT::strdup(uri);
|
||||
if (authDn)
|
||||
server->authDn = nsCRT::strdup(authDn);
|
||||
}
|
||||
if (maxHits)
|
||||
server->maxHits = maxHits;
|
||||
|
||||
dir_ServerList->AppendElement(server);
|
||||
if (!migrating) {
|
||||
@@ -492,18 +508,17 @@ nsresult DIR_IncrementServerRefCount (DIR_Server *server)
|
||||
nsresult DIR_InitServerWithType(DIR_Server * server, DirectoryType dirType)
|
||||
{
|
||||
DIR_InitServer(server);
|
||||
server->dirType = dirType;
|
||||
if (dirType == LDAPDirectory)
|
||||
{
|
||||
server->columnAttributes = nsCRT::strdup(kDefaultLDAPColumnHeaders);
|
||||
server->dirType = LDAPDirectory;
|
||||
server->isOffline = PR_TRUE;
|
||||
server->csid = CS_UTF8;
|
||||
server->locale = nsnull;
|
||||
}
|
||||
else if (dirType == PABDirectory)
|
||||
else if (dirType == PABDirectory || dirType == MAPIDirectory)
|
||||
{
|
||||
server->columnAttributes = nsCRT::strdup(kDefaultPABColumnHeaders);
|
||||
server->dirType = PABDirectory;
|
||||
server->isOffline = PR_FALSE;
|
||||
server->csid = CS_UTF8;
|
||||
// server->csid = INTL_GetCharSetID(INTL_DefaultTextWidgetCsidSel);
|
||||
@@ -3890,6 +3905,9 @@ void DIR_SavePrefsForOneServer(DIR_Server *server)
|
||||
DIR_SetIntPref (prefstring, "dirType", tempstring, server->dirType, LDAPDirectory);
|
||||
DIR_SetBoolPref (prefstring, "isOffline", tempstring, server->isOffline, kDefaultIsOffline);
|
||||
|
||||
if (server->dirType == LDAPDirectory)
|
||||
DIR_SetStringPref(prefstring, "uri", tempstring, server->uri, "");
|
||||
|
||||
/* save the column attributes */
|
||||
if (server->dirType == PABDirectory)
|
||||
DIR_SetStringPref(prefstring, "columns", tempstring, server->columnAttributes, kDefaultPABColumnHeaders);
|
||||
|
||||
@@ -282,7 +282,7 @@ nsVoidArray* DIR_GetDirectories();
|
||||
nsresult DIR_GetDirServers();
|
||||
nsresult DIR_ShutDown(void); /* FEs should call this when the app is shutting down. It frees all DIR_Servers regardless of ref count values! */
|
||||
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, DirectoryType dirType, DIR_Server** pServer);
|
||||
nsresult DIR_AddNewAddressBook(const PRUnichar *dirName, const char *fileName, PRBool migrating, const char * uri, int maxHits, const char * authDn, DirectoryType dirType, DIR_Server** pServer);
|
||||
nsresult DIR_ContainsServer(DIR_Server* pServer, PRBool *hasDir);
|
||||
|
||||
nsresult DIR_DecrementServerRefCount (DIR_Server *);
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
#define NC_RDF_ISWRITEABLE "http://home.netscape.com/NC-rdf#IsWriteable"
|
||||
|
||||
//Directory Commands
|
||||
#define NC_RDF_MODIFY "http://home.netscape.com/NC-rdf#Modify"
|
||||
#define NC_RDF_DELETE "http://home.netscape.com/NC-rdf#Delete"
|
||||
#define NC_RDF_DELETECARDS "http://home.netscape.com/NC-rdf#DeleteCards"
|
||||
|
||||
@@ -157,6 +158,8 @@ nsAbDirectoryDataSource::Init()
|
||||
rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_ISWRITEABLE),
|
||||
getter_AddRefs(kNC_IsWriteable));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_MODIFY), getter_AddRefs(kNC_Modify));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
rv = rdf->GetResource(NS_LITERAL_CSTRING(NC_RDF_DELETE),
|
||||
getter_AddRefs(kNC_Delete));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
@@ -383,7 +386,8 @@ nsAbDirectoryDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/*
|
||||
directory = do_QueryElementAt(aSources, i, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// we don't care about the arguments -- directory commands are always enabled
|
||||
if (!((aCommand == kNC_Delete) || (aCommand == kNC_DeleteCards))) {
|
||||
if (!((aCommand == kNC_Delete) || (aCommand == kNC_DeleteCards)
|
||||
||(aCommand == kNC_Modify))) {
|
||||
*aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -402,6 +406,11 @@ nsAbDirectoryDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSource
|
||||
nsresult rv = aSources->Count(&cnt);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (aCommand == kNC_Modify) {
|
||||
rv = DoModifyDirectory(aSources,aArguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((aCommand == kNC_Delete))
|
||||
rv = DoDeleteFromDirectory(aSources, aArguments);
|
||||
else {
|
||||
@@ -413,6 +422,7 @@ nsAbDirectoryDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSource
|
||||
rv = DoDeleteCardsFromDirectory(directory, aArguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//for the moment return NS_OK, because failure stops entire DoCommand process.
|
||||
return NS_OK;
|
||||
@@ -452,6 +462,37 @@ NS_IMETHODIMP nsAbDirectoryDataSource::OnItemAdded(nsISupports *parentDirectory,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsAbDirectoryDataSource::DoModifyDirectory(nsISupportsArray *parentDir, nsISupportsArray *arguments)
|
||||
{
|
||||
PRUint32 itemCount;
|
||||
// Parent dir count should be 1.
|
||||
nsresult rv = parentDir->Count(&itemCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(itemCount == 1, "DoModifyDirectory() must have parent directory count = 1.");
|
||||
if (itemCount != 1)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> parent = do_QueryElementAt(parentDir, 0, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Argument count should be 2. 1st one is nsIAbDirectory and 2nd is nsIAbDirectoryProperties.
|
||||
nsCOMPtr<nsISupportsArray> resourceArray = do_QueryElementAt(arguments, 0, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
rv = resourceArray->Count(&itemCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
NS_ASSERTION(itemCount == 2, "DoModifyDirectory() must have resource argument count = 2.");
|
||||
if (itemCount != 2)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCOMPtr<nsIAbDirectory> modifiedDir = do_QueryElementAt(resourceArray, 0, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsCOMPtr<nsIAbDirectoryProperties> properties = do_QueryElementAt(resourceArray, 1, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
if (modifiedDir && properties)
|
||||
rv = parent->ModifyDirectory(modifiedDir, properties);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbDirectoryDataSource::OnItemRemoved(nsISupports *parentDirectory, nsISupports *item)
|
||||
{
|
||||
nsresult rv;
|
||||
@@ -647,9 +688,6 @@ nsresult nsAbDirectoryDataSource::DoDeleteFromDirectory(nsISupportsArray *parent
|
||||
nsresult rv = parentDirs->Count(&itemCount);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISupportsArray> dirArray;
|
||||
NS_NewISupportsArray(getter_AddRefs(dirArray));
|
||||
|
||||
for (item = 0; item < itemCount; item++)
|
||||
{
|
||||
nsCOMPtr<nsIAbDirectory> parent = do_QueryElementAt(parentDirs, item, &rv);
|
||||
|
||||
@@ -128,6 +128,8 @@ protected:
|
||||
nsresult getDirectoryArcLabelsOut(nsIAbDirectory *directory,
|
||||
nsISupportsArray **arcs);
|
||||
|
||||
nsresult DoModifyDirectory(nsISupportsArray *parentDir,
|
||||
nsISupportsArray *arguments);
|
||||
nsresult DoDeleteFromDirectory(nsISupportsArray *parentDirs,
|
||||
nsISupportsArray *delDirs);
|
||||
nsresult DoDeleteCardsFromDirectory(nsIAbDirectory *directory,
|
||||
@@ -152,6 +154,7 @@ protected:
|
||||
nsCOMPtr<nsIRDFResource> kNC_IsWriteable;
|
||||
|
||||
// commands
|
||||
nsCOMPtr<nsIRDFResource> kNC_Modify;
|
||||
nsCOMPtr<nsIRDFResource> kNC_Delete;
|
||||
nsCOMPtr<nsIRDFResource> kNC_DeleteCards;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user