bug 290043, Tidy address book code, patch by Mark Banner, r=bienvenu, sr=mscott, a=chofmann
git-svn-id: svn://10.0.0.236/trunk@172949 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
d0dddb2d9b
commit
2ec29ebf23
@ -40,17 +40,15 @@
|
||||
|
||||
interface nsIAddrDBListener;
|
||||
|
||||
[scriptable, uuid(A4186D8A-1DD0-11d3-A303-001083003D0C)]
|
||||
[scriptable, uuid(0d8fe8e3-ad48-4dbd-b0c2-a1d374e39b93)]
|
||||
interface nsIAddrDBAnnouncer : nsISupports {
|
||||
|
||||
void addListener(in nsIAddrDBListener listener);
|
||||
void removeListener(in nsIAddrDBListener listener);
|
||||
|
||||
void notifyCardAttribChange(in unsigned long abCode,
|
||||
in nsIAddrDBListener instigator);
|
||||
void notifyCardAttribChange(in unsigned long abCode);
|
||||
void notifyCardEntryChange (in unsigned long abCode,
|
||||
in nsIAbCard card,
|
||||
in nsIAddrDBListener instigator);
|
||||
in nsIAbCard card);
|
||||
|
||||
void notifyAnnouncerGoingAway();
|
||||
};
|
||||
|
||||
@ -40,17 +40,14 @@
|
||||
|
||||
interface nsIAddrDBAnnouncer;
|
||||
|
||||
[scriptable, uuid(A4186D89-1DD0-11d3-A303-001083003D0C)]
|
||||
[scriptable, uuid(96876e1d-50a8-4264-8cd0-953d75d0e81b)]
|
||||
interface nsIAddrDBListener : nsISupports {
|
||||
|
||||
void onCardAttribChange(in unsigned long abCode,
|
||||
in nsIAddrDBListener instigator);
|
||||
void onCardAttribChange(in unsigned long abCode);
|
||||
void onCardEntryChange (in unsigned long abCode,
|
||||
in nsIAbCard card,
|
||||
in nsIAddrDBListener instigator);
|
||||
in nsIAbCard card);
|
||||
void onListEntryChange (in unsigned long abCode,
|
||||
in nsIAbDirectory list,
|
||||
in nsIAddrDBListener instigator);
|
||||
void onAnnouncerGoingAway(in nsIAddrDBAnnouncer instigator);
|
||||
in nsIAbDirectory list);
|
||||
void onAnnouncerGoingAway();
|
||||
|
||||
};
|
||||
|
||||
@ -841,13 +841,13 @@ NS_IMETHODIMP nsAbMDBDirectory::EditMailListToDatabase(const char *uri, nsIAbCar
|
||||
|
||||
// nsIAddrDBListener methods
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator)
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnCardAttribChange(PRUint32 abCode)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnCardEntryChange
|
||||
(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
|
||||
(PRUint32 abCode, nsIAbCard *card)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(card);
|
||||
nsCOMPtr<nsISupports> cardSupports(do_QueryInterface(card));
|
||||
@ -873,7 +873,7 @@ NS_IMETHODIMP nsAbMDBDirectory::OnCardEntryChange
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnListEntryChange
|
||||
(PRUint32 abCode, nsIAbDirectory *list, nsIAddrDBListener *instigator)
|
||||
(PRUint32 abCode, nsIAbDirectory *list)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@ -898,7 +898,7 @@ NS_IMETHODIMP nsAbMDBDirectory::OnListEntryChange
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator)
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnAnnouncerGoingAway()
|
||||
{
|
||||
if (mDatabase)
|
||||
mDatabase->RemoveListener(this);
|
||||
|
||||
@ -1,124 +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) 1998
|
||||
* 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 "nsAbRDFResource.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsAddrDatabase.h"
|
||||
#include "nsIAddrBookSession.h"
|
||||
|
||||
nsAbRDFResource::nsAbRDFResource(void)
|
||||
{
|
||||
mDatabase = nsnull;
|
||||
}
|
||||
|
||||
nsAbRDFResource::~nsAbRDFResource(void)
|
||||
{
|
||||
if (mDatabase)
|
||||
{
|
||||
mDatabase->RemoveListener(this);
|
||||
mDatabase->Close(PR_TRUE);
|
||||
mDatabase = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsAbRDFResource, nsRDFResource, nsIAddrDBListener)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP nsAbRDFResource::OnCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbRDFResource::OnCardEntryChange
|
||||
(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbRDFResource::OnListEntryChange
|
||||
(PRUint32 abCode, nsIAbDirectory *list, nsIAddrDBListener *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbRDFResource::OnAnnouncerGoingAway(nsIAddrDBAnnouncer *instigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsAbRDFResource::GetAbDatabase()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (!mDatabase && mURI)
|
||||
{
|
||||
nsFileSpec* dbPath = nsnull;
|
||||
|
||||
nsCOMPtr<nsIAddrBookSession> abSession =
|
||||
do_GetService(NS_ADDRBOOKSESSION_CONTRACTID, &rv);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
abSession->GetUserProfileDirectory(&dbPath);
|
||||
|
||||
NS_ConvertUTF8toUCS2 file(&(mURI[kMDBDirectoryRootLen]));
|
||||
PRInt32 pos = file.Find("/");
|
||||
if (pos != -1)
|
||||
file.Truncate(pos);
|
||||
(*dbPath) += file;
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> addrDBFactory =
|
||||
do_GetService(NS_ADDRDATABASE_CONTRACTID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && addrDBFactory)
|
||||
rv = addrDBFactory->Open(dbPath, PR_TRUE, getter_AddRefs(mDatabase), PR_TRUE);
|
||||
|
||||
if (mDatabase)
|
||||
mDatabase->AddListener(this);
|
||||
|
||||
delete dbPath;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
if (!mDatabase)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -1,77 +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) 1998
|
||||
* 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 ***** */
|
||||
|
||||
/********************************************************************************************************
|
||||
|
||||
Interface for representing Address Book Directory
|
||||
|
||||
*********************************************************************************************************/
|
||||
|
||||
#ifndef nsAbRDFResource_h__
|
||||
#define nsAbRDFResource_h__
|
||||
|
||||
#include "nsRDFResource.h"
|
||||
#include "nsIAbCard.h"
|
||||
#include "nsIAbDirectory.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsDirPrefs.h"
|
||||
#include "nsIAddrDatabase.h"
|
||||
#include "nsIAddrDBListener.h"
|
||||
|
||||
/*
|
||||
* Address Book RDF Resources and DB listener
|
||||
*/
|
||||
|
||||
class nsAbRDFResource: public nsRDFResource, public nsIAddrDBListener
|
||||
{
|
||||
public:
|
||||
nsAbRDFResource(void);
|
||||
virtual ~nsAbRDFResource(void);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIADDRDBLISTENER
|
||||
|
||||
protected:
|
||||
|
||||
nsresult GetAbDatabase();
|
||||
|
||||
nsCOMPtr<nsIAddrDatabase> mDatabase;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -269,7 +269,7 @@ NS_IMETHODIMP nsAddrDatabase::RemoveListener(nsIAddrDBListener *listener)
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddrDatabase::NotifyCardAttribChange(PRUint32 abCode, nsIAddrDBListener *instigator)
|
||||
NS_IMETHODIMP nsAddrDatabase::NotifyCardAttribChange(PRUint32 abCode)
|
||||
{
|
||||
if (!m_ChangeListeners)
|
||||
return NS_OK;
|
||||
@ -279,13 +279,13 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardAttribChange(PRUint32 abCode, nsIAddrDBL
|
||||
nsIAddrDBListener *changeListener =
|
||||
(nsIAddrDBListener *) m_ChangeListeners->ElementAt(i);
|
||||
|
||||
nsresult rv = changeListener->OnCardAttribChange(abCode, instigator);
|
||||
nsresult rv = changeListener->OnCardAttribChange(abCode);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *card, nsIAddrDBListener *instigator)
|
||||
NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *card)
|
||||
{
|
||||
if (!m_ChangeListeners)
|
||||
return NS_OK;
|
||||
@ -298,7 +298,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *
|
||||
|
||||
if (changeListener)
|
||||
{
|
||||
nsresult rv = changeListener->OnCardEntryChange(abCode, card, instigator);
|
||||
nsresult rv = changeListener->OnCardEntryChange(abCode, card);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else
|
||||
@ -308,7 +308,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyCardEntryChange(PRUint32 abCode, nsIAbCard *
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsAddrDatabase::NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir, nsIAddrDBListener *instigator)
|
||||
nsresult nsAddrDatabase::NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir)
|
||||
{
|
||||
if (!m_ChangeListeners)
|
||||
return NS_OK;
|
||||
@ -320,7 +320,7 @@ nsresult nsAddrDatabase::NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *
|
||||
nsIAddrDBListener *changeListener =
|
||||
(nsIAddrDBListener *) m_ChangeListeners->ElementAt(i);
|
||||
|
||||
nsresult rv = changeListener->OnListEntryChange(abCode, dir, instigator);
|
||||
nsresult rv = changeListener->OnListEntryChange(abCode, dir);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
@ -339,7 +339,7 @@ NS_IMETHODIMP nsAddrDatabase::NotifyAnnouncerGoingAway(void)
|
||||
nsIAddrDBListener *changeListener =
|
||||
(nsIAddrDBListener *) m_ChangeListeners->ElementAt(i);
|
||||
|
||||
nsresult rv = changeListener->OnAnnouncerGoingAway(this);
|
||||
nsresult rv = changeListener->OnAnnouncerGoingAway();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
return NS_OK;
|
||||
@ -1551,7 +1551,7 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewCardAndAddToDB(nsIAbCard *newCard, PRBool
|
||||
// do notification
|
||||
if (notify)
|
||||
{
|
||||
NotifyCardEntryChange(AB_NotifyInserted, newCard, NULL);
|
||||
NotifyCardEntryChange(AB_NotifyInserted, newCard);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@ -1631,7 +1631,7 @@ NS_IMETHODIMP nsAddrDatabase::CreateNewListCardAndAddToDB(nsIAbDirectory *aList,
|
||||
addressList->AppendElement(newCard);
|
||||
|
||||
if (notify)
|
||||
NotifyCardEntryChange(AB_NotifyInserted, newCard, nsnull);
|
||||
NotifyCardEntryChange(AB_NotifyInserted, newCard);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@ -1683,13 +1683,13 @@ NS_IMETHODIMP nsAddrDatabase::AddListCardColumnsToRow
|
||||
NS_IF_ADDREF(*pNewCard = newCard);
|
||||
|
||||
if (cardWasAdded) {
|
||||
NotifyCardEntryChange(AB_NotifyInserted, newCard, nsnull);
|
||||
NotifyCardEntryChange(AB_NotifyInserted, newCard);
|
||||
}
|
||||
else if (!aInMailingList) {
|
||||
NotifyCardEntryChange(AB_NotifyInserted, pCard, nsnull);
|
||||
NotifyCardEntryChange(AB_NotifyInserted, pCard);
|
||||
}
|
||||
else {
|
||||
NotifyCardEntryChange(AB_NotifyPropertyChanged, pCard, nsnull);
|
||||
NotifyCardEntryChange(AB_NotifyPropertyChanged, pCard);
|
||||
}
|
||||
|
||||
//add a column with address row id to the list row
|
||||
@ -1853,7 +1853,7 @@ NS_IMETHODIMP nsAddrDatabase::CreateMailListAndAddToDB(nsIAbDirectory *newList,
|
||||
|
||||
nsCOMPtr<nsIAbCard> listCard;
|
||||
CreateABListCard(listRow, getter_AddRefs(listCard));
|
||||
NotifyCardEntryChange(AB_NotifyInserted, listCard, NULL);
|
||||
NotifyCardEntryChange(AB_NotifyInserted, listCard);
|
||||
|
||||
NS_RELEASE(listRow);
|
||||
return NS_OK;
|
||||
@ -1931,7 +1931,7 @@ NS_IMETHODIMP nsAddrDatabase::DeleteCard(nsIAbCard *card, PRBool notify)
|
||||
|
||||
if (NS_SUCCEEDED(err)) {
|
||||
if (notify)
|
||||
NotifyCardEntryChange(AB_NotifyDeleted, card, NULL);
|
||||
NotifyCardEntryChange(AB_NotifyDeleted, card);
|
||||
}
|
||||
else
|
||||
DeleteRowFromDeletedCardsTable(cardRow);
|
||||
@ -2020,7 +2020,7 @@ NS_IMETHODIMP nsAddrDatabase::DeleteCardFromMailList(nsIAbDirectory *mailList, n
|
||||
|
||||
err = DeleteCardFromListRow(pListRow, cardRowID);
|
||||
if (NS_SUCCEEDED(err) && aNotify) {
|
||||
NotifyCardEntryChange(AB_NotifyDeleted, card, NULL);
|
||||
NotifyCardEntryChange(AB_NotifyDeleted, card);
|
||||
}
|
||||
NS_RELEASE(pListRow);
|
||||
return NS_OK;
|
||||
@ -2221,7 +2221,7 @@ NS_IMETHODIMP nsAddrDatabase::EditCard(nsIAbCard *card, PRBool notify)
|
||||
NS_ENSURE_SUCCESS(err, err);
|
||||
|
||||
if (notify)
|
||||
NotifyCardEntryChange(AB_NotifyPropertyChanged, card, nsnull);
|
||||
NotifyCardEntryChange(AB_NotifyPropertyChanged, card);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -2309,10 +2309,10 @@ NS_IMETHODIMP nsAddrDatabase::EditMailList(nsIAbDirectory *mailList, nsIAbCard *
|
||||
|
||||
if (notify)
|
||||
{
|
||||
NotifyListEntryChange(AB_NotifyPropertyChanged, mailList, nsnull);
|
||||
NotifyListEntryChange(AB_NotifyPropertyChanged, mailList);
|
||||
|
||||
if (listCard) {
|
||||
NotifyCardEntryChange(AB_NotifyPropertyChanged, listCard, nsnull);
|
||||
NotifyCardEntryChange(AB_NotifyPropertyChanged, listCard);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -356,7 +356,7 @@ protected:
|
||||
nsresult CreateCardFromDeletedCardsTable(nsIMdbRow* cardRow, mdb_id listRowID, nsIAbCard **result);
|
||||
nsresult DeleteCardFromListRow(nsIMdbRow* pListRow, mdb_id cardRowID);
|
||||
void DeleteCardFromAllMailLists(mdb_id cardRowID);
|
||||
nsresult NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir, nsIAddrDBListener *instigator);
|
||||
nsresult NotifyListEntryChange(PRUint32 abCode, nsIAbDirectory *dir);
|
||||
|
||||
nsresult AddLowercaseColumn(nsIMdbRow * row, mdb_token columnToken, const char* utf8String);
|
||||
nsresult GetRowFromAttribute(const char *aName, const char *aUTF8Value, PRBool aCaseInsensitive, nsIMdbRow **aCardRow);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user