Back to index

lightning-sunbird  0.9+nobinonly
nsAbMDBDirProperty.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Seth Spitzer <sspitzer@netscape.com>
00024  *   Pierre Phaneuf <pp@ludusdesign.com>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsAbMDBDirProperty.h"     
00041 #include "nsIRDFService.h"
00042 #include "nsIRDFResource.h"
00043 #include "nsIServiceManager.h"
00044 #include "nsRDFCID.h"
00045 #include "nsXPIDLString.h"
00046 #include "nsCOMPtr.h"
00047 #include "nsAbBaseCID.h"
00048 #include "nsAddrDatabase.h"
00049 #include "nsIAbCard.h"
00050 #include "nsIAbListener.h"
00051 #include "nsIAddrBookSession.h"
00052 #include "nsIAddressBook.h"
00053 #include "nsIAbMDBCard.h"
00054 
00055 #include "mdb.h"
00056 
00057 nsAbMDBDirProperty::nsAbMDBDirProperty(void)
00058 {
00059   m_dbRowID = 0;
00060 }
00061 
00062 nsAbMDBDirProperty::~nsAbMDBDirProperty(void)
00063 { 
00064 }
00065 
00066 
00067 NS_IMPL_ISUPPORTS_INHERITED1(nsAbMDBDirProperty, nsAbDirProperty, nsIAbMDBDirectory)
00068 
00069 
00070 
00071 
00072 
00073 // nsIAbMDBDirectory attributes
00074 
00075 NS_IMETHODIMP nsAbMDBDirProperty::GetDbRowID(PRUint32 *aDbRowID)
00076 {
00077        *aDbRowID = m_dbRowID;
00078        return NS_OK;
00079 }
00080 
00081 NS_IMETHODIMP nsAbMDBDirProperty::SetDbRowID(PRUint32 aDbRowID)
00082 {
00083        m_dbRowID = aDbRowID;
00084        return NS_OK;
00085 }
00086 
00087 
00088 // nsIAbMDBDirectory methods
00089 
00090 /* add mailing list to the parent directory */
00091 NS_IMETHODIMP nsAbMDBDirProperty::AddMailListToDirectory(nsIAbDirectory *mailList)
00092 {
00093        if (!m_AddressList)
00094               NS_NewISupportsArray(getter_AddRefs(m_AddressList));
00095        PRUint32 i, count;
00096        m_AddressList->Count(&count);
00097        for (i = 0; i < count; i++)
00098        {
00099               nsresult err;
00100               nsCOMPtr<nsIAbDirectory> pList(do_QueryElementAt(m_AddressList, i, &err));
00101               if (mailList == pList)
00102                      return NS_OK;
00103        }
00104        m_AddressList->AppendElement(mailList);
00105        return NS_OK;
00106 }
00107 
00108 /* add addresses to the mailing list */
00109 NS_IMETHODIMP nsAbMDBDirProperty::AddAddressToList(nsIAbCard *card)
00110 {
00111        if (!m_AddressList)
00112               NS_NewISupportsArray(getter_AddRefs(m_AddressList));
00113        PRUint32 i, count;
00114        m_AddressList->Count(&count);
00115        for (i = 0; i < count; i++)
00116        {
00117               nsresult err;
00118               nsCOMPtr<nsIAbCard> pCard(do_QueryElementAt(m_AddressList, i, &err));
00119               if (card == pCard)
00120                      return NS_OK;
00121        }
00122        m_AddressList->AppendElement(card);
00123        return NS_OK;
00124 }
00125 
00126 NS_IMETHODIMP nsAbMDBDirProperty::CopyDBMailList(nsIAbMDBDirectory* srcListDB)
00127 {
00128        nsresult err = NS_OK;
00129        nsCOMPtr<nsIAbDirectory> srcList(do_QueryInterface(srcListDB));
00130        if (NS_FAILED(err)) 
00131               return NS_ERROR_NULL_POINTER;
00132 
00133        CopyMailList (srcList);
00134 
00135        PRUint32 rowID;
00136        srcListDB->GetDbRowID(&rowID);
00137        SetDbRowID(rowID);
00138 
00139        return NS_OK;
00140 }
00141 
00142 
00143 // nsIAbMDBDirectory NOT IMPLEMENTED methods
00144 
00145 /* nsIAbDirectory addDirectory (in string uriName); */
00146 NS_IMETHODIMP nsAbMDBDirProperty::AddDirectory(const char *uriName, nsIAbDirectory **_retval)
00147 {
00148     return NS_ERROR_NOT_IMPLEMENTED;
00149 }
00150 
00151 /* string getDirUri (); */
00152 NS_IMETHODIMP nsAbMDBDirProperty::GetDirUri(char **_retval)
00153 {
00154     return NS_ERROR_NOT_IMPLEMENTED;
00155 }
00156 
00157 /* [noscript] void removeElementsFromAddressList (); */
00158 NS_IMETHODIMP nsAbMDBDirProperty::RemoveElementsFromAddressList()
00159 {
00160     return NS_ERROR_NOT_IMPLEMENTED;
00161 }
00162 
00163 /* void removeEmailAddressAt (in unsigned long aIndex); */
00164 NS_IMETHODIMP nsAbMDBDirProperty::RemoveEmailAddressAt(PRUint32 aIndex)
00165 {
00166     return NS_ERROR_NOT_IMPLEMENTED;
00167 }
00168 
00169 /* [noscript] void notifyDirItemAdded (in nsISupports item); */
00170 NS_IMETHODIMP nsAbMDBDirProperty::NotifyDirItemAdded(nsISupports *item)
00171 {
00172     return NS_ERROR_NOT_IMPLEMENTED;
00173 }
00174 
00175 /* [noscript] void clearDatabase (); */
00176 NS_IMETHODIMP nsAbMDBDirProperty::ClearDatabase()
00177 {
00178     return NS_ERROR_NOT_IMPLEMENTED;
00179 }
00180 
00181 NS_IMETHODIMP nsAbMDBDirProperty::GetValueForCard(nsIAbCard *card, const char *name, PRUnichar **value)
00182 {
00183   nsresult rv;
00184   nsCOMPtr <nsIAbMDBCard> mdbcard = do_QueryInterface(card, &rv);
00185   if (NS_FAILED(rv) || !mdbcard) {
00186     // XXX this shouldn't happen
00187     // but it is, after ab sync
00188     // I think are nsAbCardProperties are getting into the nsAbView
00189     // and later, on paint, we are asking for them.
00190     return NS_OK;
00191   }
00192 
00193   rv = mdbcard->GetStringAttribute(name, value);
00194   NS_ENSURE_SUCCESS(rv,rv);
00195   return rv;
00196 }
00197 
00198 NS_IMETHODIMP nsAbMDBDirProperty::SetValueForCard(nsIAbCard *card, const char *name, const PRUnichar *value)
00199 {
00200   nsresult rv;
00201   nsCOMPtr <nsIAbMDBCard> mdbcard = do_QueryInterface(card, &rv);
00202   NS_ENSURE_SUCCESS(rv,rv);
00203 
00204   rv = mdbcard->SetStringAttribute(name, value);
00205   NS_ENSURE_SUCCESS(rv,rv);
00206   return rv;
00207 }
00208 
00209 NS_IMETHODIMP nsAbMDBDirProperty::HasCardForEmailAddress(const char * aEmailAddress, PRBool * aCardExists)
00210 {
00211   return NS_ERROR_NOT_IMPLEMENTED;
00212 }
00213 
00214 NS_IMETHODIMP nsAbMDBDirProperty::CardForEmailAddress(const char * aEmailAddress, nsIAbCard ** aAbCard)
00215 {
00216   return NS_ERROR_NOT_IMPLEMENTED;
00217 }