View | Details | Raw Unified | Return to issue 4954
Collapse All | Expand All

(-)mailnews/addrbook/src/nsAbOutlookDirectory.h (+3 lines)
Lines 46-51 Link Here
46
#include "nsHashtable.h"
46
#include "nsHashtable.h"
47
47
48
#include "nsISupportsArray.h"
48
#include "nsISupportsArray.h"
49
#include "nsVoidArray.h"
49
50
50
struct nsMapiEntry ;
51
struct nsMapiEntry ;
51
52
Lines 91-96 Link Here
91
protected:
92
protected:
92
    // Retrieve hierarchy as cards, with an optional restriction
93
    // Retrieve hierarchy as cards, with an optional restriction
93
    nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction) ;
94
    nsresult GetChildCards(nsISupportsArray **aCards, void *aRestriction) ;
95
    // Retrieve hierarchy as URIs, with an optional restriction
96
    nsresult GetChildCards(nsCStringArray& aURI, void *aRestriction) ;
94
    // Retrieve hierarchy as directories
97
    // Retrieve hierarchy as directories
95
    nsresult GetChildNodes(nsISupportsArray **aNodes) ;
98
    nsresult GetChildNodes(nsISupportsArray **aNodes) ;
96
    // Create a new card
99
    // Create a new card
(-)mailnews/addrbook/src/nsAbOutlookDirectory.cpp (-32 / +70 lines)
Lines 162-200 Link Here
162
    return retCode ;
162
    return retCode ;
163
}
163
}
164
164
165
static nsresult BuildCardFromURI(nsCString& uriName,nsIAbCard **aNewCard)
166
{   
167
    nsresult retCode = NS_OK ;
168
    nsCOMPtr<nsIRDFResource> resource ;
169
170
    nsCOMPtr<nsIAbCard> childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
171
    NS_ENSURE_SUCCESS(retCode, retCode) ;
172
    resource = do_QueryInterface(childCard, &retCode) ;
173
    NS_ENSURE_SUCCESS(retCode, retCode) ;
174
    retCode = resource->Init(uriName.get()) ;
175
    NS_ENSURE_SUCCESS(retCode, retCode) ;
176
    NS_IF_ADDREF(*aNewCard = childCard);
177
    return retCode ;
178
}
179
165
NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
180
NS_IMETHODIMP nsAbOutlookDirectory::GetChildCards(nsIEnumerator **aCards)
166
{
181
{
167
    if (!aCards) { return NS_ERROR_NULL_POINTER ; }
182
    if (!aCards) { return NS_ERROR_NULL_POINTER ; }
168
    *aCards = nsnull ;
183
    *aCards = nsnull ;
169
    nsCOMPtr<nsISupportsArray> cardList ;
184
    nsCOMPtr<nsISupportsArray> cardList ;
185
    nsCStringArray uriList ;
170
    nsresult retCode ;
186
    nsresult retCode ;
171
    
187
    
172
    mCardList.Reset() ;
188
    mCardList.Reset() ;
173
    if (mIsQueryURI) {
189
    if (mIsQueryURI) {
174
        retCode = StartSearch() ;
190
        retCode = StartSearch() ;
175
        NS_NewISupportsArray(getter_AddRefs(cardList)) ;
176
    }
191
    }
177
    else {
192
    else {
178
        retCode = GetChildCards(getter_AddRefs(cardList), nsnull) ;
193
        retCode = GetChildCards(uriList, nsnull) ;
179
    }
194
    }
195
    NS_NewISupportsArray(getter_AddRefs(cardList)) ;
180
    if (NS_SUCCEEDED(retCode)) {
196
    if (NS_SUCCEEDED(retCode)) {
181
        // Fill the results array and update the card list
197
        // Fill the results array and update the card list
182
        // Also update the address list and notify any changes.
198
        // Also update the address list and notify any changes.
183
        PRUint32 nbCards = 0 ;
199
        PRUint32 nbCards = 0 ;
184
        nsCOMPtr<nsISupports> element ;
200
        nsCAutoString uriName;
185
        
201
        nsCOMPtr <nsIAbCard> childCard;
186
        cardList->Enumerate(aCards) ;
202
187
        cardList->Count(&nbCards) ;
203
        nbCards = uriList.Count();
188
        for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
204
        for (PRUint32 i = 0 ; i < nbCards ; ++ i) {
189
            cardList->GetElementAt(i, getter_AddRefs(element)) ;
205
            uriList.CStringAt(i,uriName);
190
            nsVoidKey newKey (NS_STATIC_CAST(void *, element)) ;
206
            retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard));
207
            NS_ENSURE_SUCCESS(retCode, retCode) ;
208
            cardList->AppendElement(childCard);
209
            nsVoidKey newKey (NS_STATIC_CAST(void *, childCard)) ;
191
            nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
210
            nsCOMPtr<nsISupports> oldElement = mCardList.Get(&newKey) ;
192
211
193
            if (!oldElement) {
212
            if (!oldElement) {
194
                // We are dealing with a new element (probably directly
213
                // We are dealing with a new element (probably directly
195
                // added from Outlook), we may need to sync m_AddressList
214
                // added from Outlook), we may need to sync m_AddressList
196
                mCardList.Put(&newKey, element) ;
215
                mCardList.Put(&newKey, childCard) ;
197
                nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
216
                nsCOMPtr<nsIAbCard> card (do_QueryInterface(childCard, &retCode)) ;
198
217
199
                NS_ENSURE_SUCCESS(retCode, retCode) ;
218
                NS_ENSURE_SUCCESS(retCode, retCode) ;
200
                PRBool isMailList = PR_FALSE ;
219
                PRBool isMailList = PR_FALSE ;
Lines 224-234 Link Here
224
                }
243
                }
225
            }
244
            }
226
            else {
245
            else {
227
                NS_ASSERTION(oldElement == element, "Different card stored") ;
246
                NS_ASSERTION(oldElement == childCard, "Different card stored") ;
228
            }
247
            }
229
        }
248
        }
230
    }
249
    }
231
    return retCode ;
250
    return cardList->Enumerate(aCards) ;
232
}
251
}
233
252
234
NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
253
NS_IMETHODIMP nsAbOutlookDirectory::HasCard(nsIAbCard *aCard, PRBool *aHasCard)
Lines 1049-1062 Link Here
1049
    retCode = BuildRestriction(aArguments, arguments) ;
1068
    retCode = BuildRestriction(aArguments, arguments) ;
1050
    NS_ENSURE_SUCCESS(retCode, retCode) ;
1069
    NS_ENSURE_SUCCESS(retCode, retCode) ;
1051
    nsCOMPtr<nsISupportsArray> resultsArray ;
1070
    nsCOMPtr<nsISupportsArray> resultsArray ;
1071
    nsCStringArray uriArray ;
1052
    PRUint32 nbResults = 0 ;
1072
    PRUint32 nbResults = 0 ;
1053
    
1073
    
1054
    retCode = GetChildCards(getter_AddRefs(resultsArray), 
1074
    retCode = GetChildCards(uriArray, 
1055
                            arguments.rt == RES_COMMENT ? nsnull : &arguments) ;
1075
                            arguments.rt == RES_COMMENT ? nsnull : &arguments) ;
1056
    DestroyRestriction(arguments) ;
1076
    DestroyRestriction(arguments) ;
1057
    NS_ENSURE_SUCCESS(retCode, retCode) ;
1077
    NS_ENSURE_SUCCESS(retCode, retCode) ;
1058
    retCode = resultsArray->Count(&nbResults) ;
1078
    nbResults = uriArray.Count() ;
1059
    NS_ENSURE_SUCCESS(retCode, retCode) ;
1060
    nsCOMPtr<nsIAbDirectoryQueryResult> result ;
1079
    nsCOMPtr<nsIAbDirectoryQueryResult> result ;
1061
    nsAbDirectoryQueryResult *newResult = nsnull ;
1080
    nsAbDirectoryQueryResult *newResult = nsnull ;
1062
1081
Lines 1064-1078 Link Here
1064
        nbResults = NS_STATIC_CAST(PRUint32, aResultLimit) ; 
1083
        nbResults = NS_STATIC_CAST(PRUint32, aResultLimit) ; 
1065
    }
1084
    }
1066
    PRUint32 i = 0 ;
1085
    PRUint32 i = 0 ;
1067
    nsCOMPtr<nsISupports> element ;
1068
    nsCOMPtr<nsISupportsArray> propertyValues ;
1086
    nsCOMPtr<nsISupportsArray> propertyValues ;
1069
    
1087
1088
    nsCAutoString uriName;
1089
    nsCOMPtr <nsIAbCard> card;
1090
1070
    for (i = 0 ; i < nbResults ; ++ i) {
1091
    for (i = 0 ; i < nbResults ; ++ i) {
1071
        retCode = resultsArray->GetElementAt(i, getter_AddRefs(element)) ;
1092
        uriArray.CStringAt(i,uriName);
1093
        retCode = BuildCardFromURI(uriName,getter_AddRefs(card));
1072
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1094
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1073
        nsCOMPtr<nsIAbCard> card (do_QueryInterface(element, &retCode)) ;
1074
        
1095
        
1075
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1076
        FillPropertyValues(card, aArguments, getter_AddRefs(propertyValues)) ;
1096
        FillPropertyValues(card, aArguments, getter_AddRefs(propertyValues)) ;
1077
        newResult = new nsAbDirectoryQueryResult(0, aArguments,
1097
        newResult = new nsAbDirectoryQueryResult(0, aArguments,
1078
                                                 nsIAbDirectoryQueryResult::queryResultMatch, 
1098
                                                 nsIAbDirectoryQueryResult::queryResultMatch, 
Lines 1098-1103 Link Here
1098
    *aCards = nsnull ;
1118
    *aCards = nsnull ;
1099
    nsresult retCode = NS_OK ;
1119
    nsresult retCode = NS_OK ;
1100
    nsCOMPtr<nsISupportsArray> cards ;
1120
    nsCOMPtr<nsISupportsArray> cards ;
1121
    nsCStringArray uriList;
1122
1123
    retCode = GetChildCards(uriList,aRestriction);
1124
    NS_ENSURE_SUCCESS(retCode, retCode) ;
1125
    
1126
    nsCAutoString uriName;
1127
    nsCOMPtr <nsIAbCard> childCard;
1128
    PRUint32 nbURIs = 0 ;
1129
    nbURIs = uriList.Count();
1130
    PRUint32 i = 0 ;
1131
        
1132
    for (i = 0 ; i < nbURIs ; ++ i) {
1133
        uriList.CStringAt(i,uriName);
1134
        retCode = BuildCardFromURI(uriName,getter_AddRefs(childCard));
1135
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1136
        cards->AppendElement(childCard);
1137
    }        
1138
    
1139
    NS_IF_ADDREF(*aCards = cards);
1140
    return retCode ;
1141
}
1142
1143
nsresult nsAbOutlookDirectory::GetChildCards(nsCStringArray& aURI, 
1144
                                             void *aRestriction)
1145
{
1146
    nsresult retCode = NS_OK ;
1147
    nsCOMPtr<nsISupportsArray> cards ;
1101
    nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
1148
    nsAbWinHelperGuard mapiAddBook (mAbWinType) ;
1102
    nsMapiEntryArray cardEntries ;
1149
    nsMapiEntryArray cardEntries ;
1103
    LPSRestriction restriction = (LPSRestriction) aRestriction ;
1150
    LPSRestriction restriction = (LPSRestriction) aRestriction ;
Lines 1111-1133 Link Here
1111
    }
1158
    }
1112
    nsCAutoString entryId ;
1159
    nsCAutoString entryId ;
1113
    nsCAutoString uriName ;
1160
    nsCAutoString uriName ;
1114
    nsCOMPtr<nsIRDFResource> resource ;
1161
               
1115
    nsCOMPtr <nsIAbCard> childCard;
1116
        
1117
    for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
1162
    for (ULONG card = 0 ; card < cardEntries.mNbEntries ; ++ card) {
1118
        cardEntries.mEntries [card].ToString(entryId) ;
1163
        cardEntries.mEntries [card].ToString(entryId) ;
1119
        buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
1164
        buildAbWinUri(kOutlookCardScheme, mAbWinType, uriName) ;
1120
        uriName.Append(entryId) ;
1165
        uriName.Append(entryId) ;
1121
        childCard = do_CreateInstance(NS_ABOUTLOOKCARD_CONTRACTID, &retCode);
1166
        aURI.AppendCString(uriName);
1122
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1123
        resource = do_QueryInterface(childCard, &retCode) ;
1124
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1125
        retCode = resource->Init(uriName.get()) ;
1126
        NS_ENSURE_SUCCESS(retCode, retCode) ;
1127
        cards->AppendElement(childCard) ;
1128
    }
1167
    }
1129
    *aCards = cards ;
1168
1130
    NS_ADDREF(*aCards) ;
1131
    return retCode ;
1169
    return retCode ;
1132
}
1170
}
1133
1171

Return to issue 4954