|
1 /* |
|
2 * Copyright (c) 2007 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: Implementation of the class PbkxRclUtils. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include <centralrepository.h> |
|
21 #include <CPbkContactEngine.h> |
|
22 #include <CPbkFieldsInfo.h> |
|
23 #include <CPbkFieldInfo.h> |
|
24 #include <AknUtils.h> |
|
25 |
|
26 #include "pbkxrclutils.h" |
|
27 #include "pbkxrclsettings.hrh" |
|
28 #include "pbkxrclengineconstants.h" |
|
29 |
|
30 // ======== MEMBER FUNCTIONS ======== |
|
31 |
|
32 // --------------------------------------------------------------------------- |
|
33 // PbkxRclUtils::FieldTextL |
|
34 // --------------------------------------------------------------------------- |
|
35 // |
|
36 HBufC* PbkxRclUtils::FieldTextL( const CPbkContactItem* aItem, TPbkFieldId aId ) |
|
37 { |
|
38 FUNC_LOG; |
|
39 |
|
40 TPbkContactItemField* field = aItem->FindField( aId ); |
|
41 if ( field != NULL ) |
|
42 { |
|
43 return PbkxRclUtils::FieldTextL( *field ); |
|
44 } |
|
45 return KNullDesC().AllocL(); |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------------------------- |
|
49 // PbkxRclUtils::FieldTextL |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 HBufC* PbkxRclUtils::FieldTextL( TPbkContactItemField& aField ) |
|
53 { |
|
54 FUNC_LOG; |
|
55 if ( aField.StorageType() == KStorageTypeText ) |
|
56 { |
|
57 TPtrC text = aField.Text(); |
|
58 HBufC* textBuffer = HBufC::NewL( text.Length() ); |
|
59 textBuffer->Des() = text; |
|
60 return textBuffer; |
|
61 } |
|
62 else if ( aField.StorageType() == KStorageTypeDateTime ) |
|
63 { |
|
64 HBufC* textBuffer = HBufC::NewL( 50 ); |
|
65 TPtr des = textBuffer->Des(); |
|
66 TTime time = aField.Time(); |
|
67 time.FormatL( des, _L("%D%M%Y%/0%1%/1%2%/2%3%/3") ); |
|
68 return textBuffer; |
|
69 } |
|
70 else |
|
71 { |
|
72 return KNullDesC().AllocL(); |
|
73 } |
|
74 } |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // PbkxRclUtils::FieldText |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 TPtrC PbkxRclUtils::FieldText( const CContactCard* aCard, TFieldType aFieldType ) |
|
81 { |
|
82 FUNC_LOG; |
|
83 CContactItemFieldSet& fields = aCard->CardFields(); |
|
84 |
|
85 TInt index = fields.Find( aFieldType ); |
|
86 if ( index != KErrNotFound ) |
|
87 { |
|
88 const CContactItemField& field = fields[index]; |
|
89 if ( field.StorageType() == KStorageTypeText ) |
|
90 { |
|
91 return field.TextStorage()->Text(); |
|
92 } |
|
93 } |
|
94 TPtrC empty; |
|
95 return empty; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // PbkxRclUtils::DefaultProtocolAccountIdL |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 TPbkxRemoteContactLookupProtocolAccountId PbkxRclUtils::DefaultProtocolAccountIdL() |
|
103 { |
|
104 FUNC_LOG; |
|
105 CRepository *cr = CRepository::NewLC( TUid::Uid( KPbkxRclCrUid ) ); |
|
106 |
|
107 TInt protocolUid( 0 ); |
|
108 User::LeaveIfError( cr->Get( KPbkxRclProtocolUidKey, protocolUid ) ); |
|
109 |
|
110 TInt accountId( 0 ); |
|
111 User::LeaveIfError( cr->Get( KPbkxRclAccountUidKey, accountId ) ); |
|
112 |
|
113 CleanupStack::PopAndDestroy( cr ); |
|
114 |
|
115 TPbkxRemoteContactLookupProtocolAccountId account( |
|
116 TUid::Uid( protocolUid ), |
|
117 accountId ); |
|
118 |
|
119 return account; |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // PbkxRclUtils::StoreDefaultProtocolAccountIdL |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void PbkxRclUtils::StoreDefaultProtocolAccountIdL( |
|
127 TPbkxRemoteContactLookupProtocolAccountId aId ) |
|
128 { |
|
129 FUNC_LOG; |
|
130 CRepository* cr = CRepository::NewLC( TUid::Uid( KPbkxRclCrUid ) ); |
|
131 TInt uidValue = aId.iProtocolUid.iUid; |
|
132 TInt accountValue = ( TInt )aId.iAccountId; |
|
133 |
|
134 User::LeaveIfError( cr->Set( KPbkxRclProtocolUidKey, uidValue ) ); |
|
135 User::LeaveIfError( cr->Set( KPbkxRclAccountUidKey, accountValue ) ); |
|
136 |
|
137 CleanupStack::PopAndDestroy( cr ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // PbkxRclUtils::IsAlphaString |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 TBool PbkxRclUtils::HasAlphaCharsInString( const TDesC& aText ) |
|
145 { |
|
146 FUNC_LOG; |
|
147 for ( TInt i = 0; i < aText.Length(); i++ ) |
|
148 { |
|
149 TChar c( aText[i] ); |
|
150 if ( c.IsAlpha() ) |
|
151 { |
|
152 return ETrue; |
|
153 } |
|
154 } |
|
155 return ETrue; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // PbkxRclUtils::CreateContactItemL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 CPbkContactItem* PbkxRclUtils::CreateContactItemL( |
|
163 CContactCard* aCard, |
|
164 CPbkContactEngine& aEngine ) |
|
165 { |
|
166 FUNC_LOG; |
|
167 CContactCard* copy = CContactCard::NewLC( aCard ); |
|
168 |
|
169 CPbkContactItem* contactItem = CPbkContactItem::NewL( |
|
170 copy, |
|
171 aEngine.FieldsInfo(), |
|
172 aEngine.ContactNameFormat() ); |
|
173 |
|
174 CleanupStack::Pop( copy ); |
|
175 |
|
176 return contactItem; |
|
177 } |
|
178 |