fix autocomplete so that it completes against the currently selected identity, rather than the 'current' identity (which was bogus anyway)

r=ducarroz
This commit is contained in:
alecf%netscape.com 2000-02-02 01:54:32 +00:00
Родитель b8355c48b1
Коммит 49dee0901a
4 изменённых файлов: 66 добавлений и 24 удалений

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

@ -24,9 +24,13 @@
#include "nsrootidl.idl"
interface nsIAutoCompleteListener;
interface nsIMsgIdentity;
[scriptable, uuid(CA2A6B07-3625-11d3-988E-001083010E9B)]
interface nsIAutoCompleteSession : nsISupports {
void autoComplete(in nsISupports aParam, in wstring aSearchString, in nsIAutoCompleteListener aResultListener);
void autoComplete(in nsIMsgIdentity relativeId,
in nsISupports aParam,
in wstring aSearchString,
in nsIAutoCompleteListener aResultListener);
};

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

@ -29,8 +29,8 @@
#include "nsIAbCard.h"
#include "nsXPIDLString.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgAccountManager.h"
#include "nsMsgI18N.h"
#include "nsIMsgIdentity.h"
static NS_DEFINE_CID(kHeaderParserCID, NS_MSGHEADERPARSER_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
@ -58,24 +58,6 @@ nsAbAutoCompleteSession::nsAbAutoCompleteSession()
NS_INIT_REFCNT();
m_numEntries = 0;
m_tableInitialized = PR_FALSE;
// temporary hack to get the current identity
nsresult rv;
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager,
NS_MSGACCOUNTMANAGER_PROGID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIMsgIdentity> identity;
rv = accountManager->GetCurrentIdentity(getter_AddRefs(identity));
if (NS_SUCCEEDED(rv))
{
char * email;
identity->GetEmail(&email);
if (email && *email)
m_domain = PL_strchr(email, '@');
PR_FREEIF(email);
}
}
}
nsresult nsAbAutoCompleteSession::PopulateTableWithAB(nsIEnumerator * aABCards)
@ -184,7 +166,11 @@ nsAbAutoCompleteSession::~nsAbAutoCompleteSession()
}
}
NS_IMETHODIMP nsAbAutoCompleteSession::AutoComplete(nsISupports *aParam, const PRUnichar *aSearchString, nsIAutoCompleteListener *aResultListener)
NS_IMETHODIMP
nsAbAutoCompleteSession::AutoComplete(nsIMsgIdentity *aIdentity,
nsISupports *aParam,
const PRUnichar *aSearchString,
nsIAutoCompleteListener *aResultListener)
{
// mscott - right now I'm not even going to bother to make this synchronous...
// I'll beef it up with some test data later but we want to see if this idea works for right now...
@ -194,6 +180,18 @@ NS_IMETHODIMP nsAbAutoCompleteSession::AutoComplete(nsISupports *aParam, const P
rv = InitializeTable();
if (NS_FAILED(rv)) return rv;
}
nsXPIDLCString domain;
if (aIdentity) {
nsXPIDLCString email;
rv = aIdentity->GetEmail(getter_Copies(email));
if (NS_SUCCEEDED(rv) && email) {
char *domainStart = PL_strchr(email, '@');
if (domainStart)
domain = domainStart; // makes a copy
}
}
if (nsCRT::strlen(aSearchString) == 0)
return NS_OK;
@ -268,7 +266,7 @@ NS_IMETHODIMP nsAbAutoCompleteSession::AutoComplete(nsISupports *aParam, const P
fullAddress = uStr;
if (fullAddress.FindChar('@') < 0) /* no domain? */
fullAddress += m_domain; /* then add the default domain */
fullAddress += domain; /* then add the default domain */
searchResult += fullAddress;

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

@ -56,7 +56,6 @@ protected:
PRBool m_tableInitialized;
nsAbStubEntry m_searchNameCompletionEntryTable[MAX_ENTRIES];
PRInt32 m_numEntries;
nsString m_domain;
};
// factory method

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

@ -1,3 +1,34 @@
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Jean-Francois Ducarroz <ducarroz@netscape.com>
* Seth Spitzer <sspitzer@netscape.com>
* Alec Flett <alecf@netscape.com>
*/
// get the current identity from the UI
var identityElement;
var accountManager = Components.classes["component://netscape/messenger/account-manager"].getService(Components.interfaces.nsIMsgAccountManager);
var AddressAutoCompleteListener = {
onAutoCompleteResult: function(aItem, aOriginalString, aMatch) {
dump("aItem = " + aItem + "\n");
@ -42,5 +73,15 @@ function AutoCompleteAddress(inputElement)
ac = ac.QueryInterface(Components.interfaces.nsIAutoCompleteSession);
}
ac.autoComplete(inputElement, inputElement.value, AddressAutoCompleteListener);
if (!identityElement)
identityElement = document.getElementById("msgIdentity");
var identity=null;
if (identityElement) {
idKey = identityElement.value;
identity = accountManager.getIdentity(idKey);
}
ac.autoComplete(identity, inputElement, inputElement.value, AddressAutoCompleteListener);
}