Fix for bug 79792. Added observers for ldap prefs. Added sessions list for all the

recipients. Added AddSession, RemoveSession and SyncSessions
r=ducarroz, sr=hewitt, a=asa
This commit is contained in:
srilatha%netscape.com 2001-06-22 01:12:32 +00:00
Родитель a821a77707
Коммит c5f6c14b8a
3 изменённых файлов: 197 добавлений и 79 удалений

Просмотреть файл

@ -48,6 +48,10 @@ var LDAPPrefsService = Components.classes[
LDAPPrefsService = LDAPPrefsService.QueryInterface(
Components.interfaces.nsILDAPPrefsService);
var ldapSession = Components.classes[
"@mozilla.org/autocompleteSession;1?type=ldap"].createInstance().
QueryInterface(Components.interfaces.nsILDAPAutoCompleteSession);
var msgCompose = null;
var MAX_RECIPIENTS = 0;
var currentAttachment = null;
@ -56,6 +60,8 @@ var contentChanged = false;
var currentIdentity = null;
var defaultSaveOperation = "draft";
var sendOrSaveOperationInProgress = false;
var isOffline = false;
var sessionAdded = false;
var gComposeMsgsBundle;
@ -563,7 +569,12 @@ var messageComposeOfflineObserver = {
Observe: function(subject, topic, state) {
// sanity checks
if (topic != "network:offline-status-changed") return;
MessageComposeOfflineStateChanged(state == "offline");
if (state == "offline")
isOffline = true;
else
isOffline = false;
MessageComposeOfflineStateChanged(isOffline);
setupLdapAutocompleteSession();
}
}
@ -572,8 +583,9 @@ function AddMessageComposeOfflineObserver()
var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.AddObserver(messageComposeOfflineObserver, "network:offline-status-changed");
isOffline = ioService.offline;
// set the initial state of the send button
MessageComposeOfflineStateChanged(ioService.offline);
MessageComposeOfflineStateChanged(isOffline);
}
function RemoveMessageComposeOfflineObserver()
@ -601,6 +613,135 @@ function MessageComposeOfflineStateChanged(goingOffline)
} catch(e) {}
}
var directoryServerObserver = {
Observe: function(subject, topic, value) {
setupLdapAutocompleteSession();
}
}
function AddDirectoryServerObserver(flag) {
if (flag) {
prefs.addObserver("ldap_2.autoComplete.useDirectory", directoryServerObserver);
prefs.addObserver("ldap_2.autoComplete.directoryServer", directoryServerObserver);
}
else
{
var prefstring = "mail.identity." + currentIdentity.key + ".overrideGlobal_Pref";
prefs.addObserver(prefstring, directoryServerObserver);
prefstring = "mail.identity." + currentIdentity.key + ".directoryServer";
prefs.addObserver(prefstring, directoryServerObserver);
}
}
function RemoveDirectoryServerObserver(prefstring)
{
if (!prefstring) {
prefs.removeObserver("ldap_2.autoComplete.useDirectory", directoryServerObserver);
prefs.removeObserver("ldap_2.autoComplete.directoryServer", directoryServerObserver);
}
else
{
var str = prefstring + ".overrideGlobal_Pref";
prefs.removeObserver(str, directoryServerObserver);
str = prefstring + ".directoryServer";
prefs.removeObserver(str, directoryServerObserver);
}
}
function setupLdapAutocompleteSession()
{
var autocompleteLdap = false;
var autocompleteDirectory = null;
try {
autocompleteLdap = prefs.GetBoolPref(
"ldap_2.autoComplete.useDirectory");
if (autocompleteLdap)
autocompleteDirectory = prefs.CopyCharPref(
"ldap_2.autoComplete.directoryServer");
} catch(ex) {
dump("ERROR: " + ex + "\n");
}
if(currentIdentity.overrideGlobalPref) {
autocompleteDirectory = currentIdentity.directoryServer;
}
if (autocompleteDirectory && !isOffline) {
if (ldapSession) {
if (!sessionAdded) {
// add session for all the recipients
for (var i=1; i <= MAX_RECIPIENTS; i++)
document.getElementById("msgRecipient#" + i).addSession(ldapSession);
sessionAdded = true;
}
var serverURL = Components.classes[
"@mozilla.org/network/ldap-url;1"].
createInstance().QueryInterface(
Components.interfaces.nsILDAPURL);
try {
serverURL.spec = prefs.CopyCharPref(autocompleteDirectory +
".uri");
} catch (ex) {
dump("ERROR: " + ex + "\n");
}
ldapSession.serverURL = serverURL;
// don't search on strings shorter than this
//
try {
ldapSession.minStringLength = prefs.GetIntPref(
autocompleteDirectory + ".autoComplete.minStringLength");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default.
}
// override autocomplete entry formatting?
//
try {
ldapSession.outputFormat =
prefs.CopyUnicharPref(autocompleteDirectory +
".autoComplete.outputFormat");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default.
}
// override default search filter template?
//
try {
ldapSession.filterTemplate = prefs.CopyUnicharPref(
autocompleteDirectory + ".autoComplete.filterTemplate");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default
}
// override default maxHits (currently 100)
//
try {
// XXXdmose should really use .autocomplete.maxHits,
// but there's no UI for that yet
//
ldapSession.maxHits =
prefs.GetIntPref(autocompleteDirectory + ".maxHits");
} catch (ex) {
// if this pref isn't there, or is out of range, no big deal.
// just let nsLDAPAutoCompleteSession use its default.
}
}
} else {
if (ldapSession && sessionAdded) {
for (var i=1; i <= MAX_RECIPIENTS; i++)
document.getElementById("msgRecipient#" + i).removeSession(ldapSession);
sessionAdded = false;
}
}
}
function DoCommandClose()
{
var retVal;
@ -713,6 +854,7 @@ function ComposeFieldsReady(msgType)
}
CompFields2Recipients(msgCompose.compFields, msgCompose.type);
setupLdapAutocompleteSession();
SetComposeWindowTitle(13);
AdjustFocus();
try {
@ -914,6 +1056,7 @@ function WizCallback(state)
function ComposeLoad()
{
AddMessageComposeOfflineObserver();
AddDirectoryServerObserver(true);
if (msgComposeService)
msgComposeService.TimeStamp("Start Initializing the compose window (ComposeLoad)", false);
@ -961,6 +1104,8 @@ function ComposeUnload()
{
dump("\nComposeUnload from XUL\n");
RemoveMessageComposeOfflineObserver();
RemoveDirectoryServerObserver(null);
RemoveDirectoryServerObserver("mail.identity." + currentIdentity.key);
msgCompose.UnregisterStateListener(stateListener);
}
@ -1794,6 +1939,8 @@ function LoadIdentity(startup)
if (!startup && prevIdentity && idKey != prevIdentity.key)
{
var prefstring = "mail.identity." + prevIdentity.key;
RemoveDirectoryServerObserver(prefstring);
var prevReplyTo = prevIdentity.replyTo;
var prevBcc = "";
if (prevIdentity.bccSelf)
@ -1853,82 +2000,9 @@ function LoadIdentity(startup)
var start = emailAddr.lastIndexOf("@");
session.defaultDomain = emailAddr.slice(start + 1, emailAddr.length);
}
var autocompleteLdap = false;
var autocompleteDirectory = null;
try {
autocompleteLdap = prefs.GetBoolPref("ldap_2.autoComplete.useDirectory");
if (autocompleteLdap)
autocompleteDirectory = prefs.CopyCharPref("ldap_2.autoComplete.directoryServer");
}
catch(ex) {dump("ERROR: " + ex + "\n");}
if(currentIdentity.overrideGlobalPref)
{
autocompleteDirectory = currentIdentity.directoryServer;
}
if (autocompleteDirectory)
{
document.getElementById('msgRecipient#1').setAttribute("searchSessions", "addrbook ldap");
var session2 = Components.classes["@mozilla.org/autocompleteSession;1?type=ldap"].getService(Components.interfaces.nsILDAPAutoCompleteSession);
if (session2)
{
var serverURL = Components.classes[
"@mozilla.org/network/ldap-url;1"].
createInstance().QueryInterface(
Components.interfaces.nsILDAPURL);
try {
serverURL.spec = prefs.CopyCharPref(autocompleteDirectory + ".uri");
} catch (ex) {dump("ERROR: " + ex + "\n");}
session2.serverURL = serverURL;
// don't search on strings shorter than this
//
try {
session2.minStringLength =
prefs.GetIntPref(autocompleteDirectory +
".autoComplete.minStringLength");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default.
}
// override autocomplete entry formatting?
//
try {
session2.outputFormat =
prefs.CopyUnicharPref(autocompleteDirectory +
".autoComplete.outputFormat");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default.
}
// override default search filter template?
//
try {
session2.filterTemplate =
prefs.CopyUnicharPref(autocompleteDirectory +
".autoComplete.filterTemplate");
} catch (ex) {
// if this pref isn't there, no big deal. just let
// nsLDAPAutoCompleteSession use its default
}
// override default maxHits (currently 100)
//
try {
// XXXdmose should really use .autocomplete.maxHits,
// but there's no UI for that yet
//
session2.maxHits =
prefs.GetIntPref(autocompleteDirectory +
".maxHits");
} catch (ex) {
// if this pref isn't there, or is out of range, no big deal.
// just let nsLDAPAutoCompleteSession use its default.
}
}
}
AddDirectoryServerObserver(false);
if (!startup)
setupLdapAutocompleteSession();
}
}

Просмотреть файл

@ -430,6 +430,9 @@ function awAppendNewRow(setFocus)
input[0].setAttribute("value", "");
input[0].setAttribute("id", "msgRecipient#" + top.MAX_RECIPIENTS);
//this copies the autocomplete sessions list from recipient#1
input[0].syncSessions(document.getElementById('msgRecipient#1'));
// We always clone the first row. The problem is that the first row
// could be focused. When we clone that row, we end up with a cloned
// XUL textbox that has a focused attribute set. Therefore we think

Просмотреть файл

@ -326,6 +326,47 @@
]]></body>
</method>
<!-- add a session by reference -->
<method name="addSession">
<parameter name="aSession"/>
<body><![CDATA[
++this.sessionCount;
var name = "anon_"+this.sessionCount;
this.mSessions[name] = aSession;
this.mListeners[name] = new (this.mAutoCompleteListener)(name);
]]></body>
</method>
<!-- remove a session by reference -->
<method name="removeSession">
<parameter name="aSession"/>
<body><![CDATA[
for (var name in this.mSessions) {
if (this.mSessions[name] == aSession) {
delete this.mSessions[name];
delete this.mListeners[name];
--this.sessionCount;
break;
}
}
]]></body>
</method>
<!-- make this widget listen to all of the same autocomplete sessions
from another autocomplete widget -->
<method name="syncSessions">
<parameter name="aCopyFrom"/>
<body><![CDATA[
this.sessionCount = aCopyFrom.sessionCount;
this.mSessions = {};
this.mListeners = {};
for (var name in aCopyFrom.mSessions) {
this.mSessions[name] = aCopyFrom.mSessions[name];
this.mListeners[name] = new (this.mAutoCompleteListener)(name);
}
]]></body>
</method>
<!-- get the first session that has results -->
<method name="getDefaultSession">
<body><![CDATA[