|
1 /* |
|
2 * Copyright (c) 2004 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Contact DB reader class |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "cntdbreader.h" |
|
22 #include <cntdb.h> |
|
23 #include <cntfield.h> |
|
24 #include <cntitem.h> |
|
25 #include <cntfldst.h> |
|
26 |
|
27 // CONSTANTS |
|
28 static const TUid EPbkFieldIdWVID = { KIntContactFieldVCardMapWV }; |
|
29 |
|
30 // ============================ MEMBER FUNCTIONS =============================== |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // CContactDBReader::CContactDBReader |
|
34 // C++ default constructor can NOT contain any code, that |
|
35 // might leave. |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CContactDBReader::CContactDBReader() |
|
39 { |
|
40 |
|
41 } |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // CContactDBReader::ConstructL |
|
45 // Symbian 2nd phase constructor can leave. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 void CContactDBReader::ConstructL() |
|
49 { |
|
50 iContactDB = CContactDatabase::OpenL(); |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CContactDBReader::NewL |
|
55 // Two-phased constructor. |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 CContactDBReader* CContactDBReader::NewL() |
|
59 { |
|
60 CContactDBReader* self = new( ELeave ) CContactDBReader(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 // Destructor |
|
69 CContactDBReader::~CContactDBReader() |
|
70 { |
|
71 delete iContactDB; // should this be Closed before deleting? |
|
72 } |
|
73 |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // CContactDBReader::ReadWVIdsL |
|
77 // |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 void CContactDBReader::ReadWVIdsL( const CContactIdArray& aContactArray, |
|
81 CDesCArray& aWVUserIds ) |
|
82 { |
|
83 |
|
84 TInt count ( aContactArray.Count() ); |
|
85 for ( TInt i( 0 ) ; i < count ; i++ ) |
|
86 { |
|
87 HBufC* userId = NULL; |
|
88 CContactItem* newContacItem = |
|
89 iContactDB->ReadMinimalContactLC( aContactArray[i] ); // << |
|
90 |
|
91 CContactItemFieldSet& cardFieldSet = newContacItem->CardFields(); |
|
92 |
|
93 TInt fieldIndex ( cardFieldSet.FindNext( |
|
94 EPbkFieldIdWVID, |
|
95 KContactFieldSetSearchAll ) ); |
|
96 |
|
97 // now read all wv ID fields |
|
98 while ( fieldIndex != KErrNotFound ) |
|
99 { |
|
100 // TextStorage() does not transfer the ownership |
|
101 CContactTextField* textField = |
|
102 ( cardFieldSet[fieldIndex] ).TextStorage(); |
|
103 |
|
104 userId = textField->Text( ).AllocL(); |
|
105 CleanupStack::PushL( userId ); |
|
106 aWVUserIds.AppendL( *userId ); |
|
107 CleanupStack::Pop(); // >> userId |
|
108 fieldIndex = cardFieldSet.FindNext( |
|
109 EPbkFieldIdWVID, |
|
110 fieldIndex + 1 ); |
|
111 } |
|
112 CleanupStack::PopAndDestroy( );// >> newContacItem |
|
113 } |
|
114 } |
|
115 |
|
116 // ----------------------------------------------------------------------------- |
|
117 // CContactDBReader::ReadWVIdL |
|
118 // |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 void CContactDBReader::GetWVIdL( const TContactItemId& aConatctId, |
|
122 CDesCArray& aWVUserIds ) |
|
123 { |
|
124 HBufC* userId = NULL; |
|
125 CContactItem* newContacItem = |
|
126 iContactDB->ReadMinimalContactLC( aConatctId ); // << |
|
127 |
|
128 CContactItemFieldSet& cardFieldSet = newContacItem->CardFields(); |
|
129 |
|
130 TInt fieldIndex ( cardFieldSet.FindNext( |
|
131 EPbkFieldIdWVID, |
|
132 KContactFieldSetSearchAll ) ); |
|
133 |
|
134 // now read all wv ID fields |
|
135 while ( fieldIndex != KErrNotFound ) |
|
136 { |
|
137 // TextStorage() does not transfer the ownership |
|
138 CContactTextField* textField = |
|
139 ( cardFieldSet[fieldIndex] ).TextStorage(); |
|
140 |
|
141 userId = textField->Text( ).AllocL(); |
|
142 CleanupStack::PushL( userId ); |
|
143 aWVUserIds.AppendL( *userId ); |
|
144 CleanupStack::Pop(); // >> userId |
|
145 fieldIndex = cardFieldSet.FindNext( |
|
146 EPbkFieldIdWVID, |
|
147 fieldIndex + 1 ); |
|
148 } |
|
149 CleanupStack::PopAndDestroy( );// >> newContacItem |
|
150 |
|
151 } |
|
152 |
|
153 // End of File |