|
1 /* |
|
2 * Copyright (c) 2004-2006 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: Utils for IM modules. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CCAPCUtils.h" |
|
20 #include "CCAStorageManagerFactory.h" |
|
21 #include "MCAStoredContacts.h" |
|
22 #include "ChatDebugPrint.h" |
|
23 #include "impsbuilddefinitions.h" |
|
24 |
|
25 #include <EscapeUtils.h> |
|
26 #include <collate.h> |
|
27 #include "MCAError.h" |
|
28 #include "CCAProcessManagerFactory.h" |
|
29 #include "MCAProcessManager.h" |
|
30 #include "CCAEngine.h" |
|
31 #include "MCAStoredContact.h" |
|
32 #include "CAUtils.h" |
|
33 |
|
34 // general colon needed in various places |
|
35 _LIT( KColon, ":" ); |
|
36 |
|
37 // general slash needed in various places |
|
38 _LIT( KSlash, "/" ); |
|
39 |
|
40 // needed to skip domains in domain-neutral comparison |
|
41 _LIT( KAt, "@" ); |
|
42 |
|
43 _LIT( KSpace, " " ); |
|
44 |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CCAPCUtils::DisplayId |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 |
|
51 |
|
52 EXPORT_C TPtrC CCAPCUtils::DisplayId( const TDesC& aId, TBool aListHiding ) |
|
53 { |
|
54 TPtrC ret( aId ); |
|
55 |
|
56 MCAStoredContacts* contacts = NULL; |
|
57 TRAPD( err, contacts = CCAStorageManagerFactory::ContactListInterfaceL() ); |
|
58 if ( err != KErrNone || !contacts ) |
|
59 { |
|
60 // some error, don't modify |
|
61 CHAT_DP_FUNC_DP( "DisplayId", "Got some error, not hiding" ); |
|
62 return ret; |
|
63 } |
|
64 |
|
65 // if we've branded the feature out, don't modify anything |
|
66 if ( contacts->WVHiding() || contacts->WVHidingPrefixOnly() ) |
|
67 { |
|
68 // locate ":" for userid, groupid. |
|
69 // locate "/" for list id. |
|
70 TInt pos = aId.FindC( aListHiding ? KSlash : KColon ); |
|
71 |
|
72 if ( ( pos != KErrNotFound ) && ( pos != aId.Length() - 1 ) ) |
|
73 { |
|
74 // contains the special character, and it is not the last char |
|
75 // remove everything before the special char (including the char) |
|
76 ret.Set( aId.Mid( pos + 1 ) ); |
|
77 } |
|
78 if ( contacts->WVHiding() || aListHiding ) |
|
79 { |
|
80 // remove also the domain part |
|
81 TInt domainPos = ret.FindC( KAt ); |
|
82 if ( ( domainPos != KErrNotFound ) && ( domainPos != 0 ) ) |
|
83 { |
|
84 ret.Set( ret.Mid( 0, domainPos ) ); |
|
85 } |
|
86 } |
|
87 } |
|
88 |
|
89 return ret; |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // CCAPCUtils::CreateBufLC |
|
94 // (other items were commented in a header). |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 EXPORT_C HBufC* CCAPCUtils::CreateBufLC( const CDesCArray& aArray, TBool aDisplayId /*= EFalse*/ ) |
|
98 { |
|
99 // calculate required space for the combined buffer |
|
100 TInt bufLength( 0 ); |
|
101 TInt count( aArray.MdcaCount() ); |
|
102 TInt i( 0 ); |
|
103 for ( ; i < count; ++i ) |
|
104 { |
|
105 bufLength += aArray.MdcaPoint( i ).Length() + KSpace().Length(); |
|
106 } |
|
107 |
|
108 // allocate the buffer and fill it up |
|
109 HBufC* buf = HBufC::NewLC( bufLength ); |
|
110 TPtr bufPtr( buf->Des() ); |
|
111 for ( i = 0; i < count; ++i ) |
|
112 { |
|
113 TPtrC ptr( aArray.MdcaPoint( i ) ); |
|
114 if ( aDisplayId ) |
|
115 { |
|
116 ptr.Set( DisplayId( ptr ) ); |
|
117 } |
|
118 |
|
119 bufPtr.Append( ptr ); |
|
120 bufPtr.Append( KSpace ); |
|
121 } |
|
122 return buf; |
|
123 } |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CCAPCUtils::PartialSucessCountL |
|
126 // (other items were commented in a header). |
|
127 // ----------------------------------------------------------------------------- |
|
128 // |
|
129 |
|
130 EXPORT_C TInt CCAPCUtils::PartialSucessCountL() |
|
131 { |
|
132 MCAProcessManager *processManager = CCAProcessManagerFactory::InstanceL()->GetProcessManager(); |
|
133 CCAEngine* engine = processManager->GetEngine(); |
|
134 const RPointerArray<MCAError>* errorArray = engine->PartialSuccessData(); |
|
135 return errorArray->Count(); |
|
136 } |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CCAPCUtils::GetErrorCodeL |
|
139 // (other items were commented in a header). |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 |
|
143 EXPORT_C TInt CCAPCUtils::GetErrorCodeL( TInt aIndex ) |
|
144 { |
|
145 MCAProcessManager *processManager = CCAProcessManagerFactory::InstanceL()->GetProcessManager(); |
|
146 CCAEngine* engine = processManager->GetEngine(); |
|
147 const RPointerArray<MCAError>* errorArray = engine->PartialSuccessData(); |
|
148 return ( *errorArray )[ aIndex ]->Code(); |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CCAPCUtils::RemoveDuplicateWVIds |
|
153 // (other items were commented in a header). |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 EXPORT_C void CCAPCUtils::RemoveDuplicateWVIds( CDesCArray& aArray ) |
|
157 { |
|
158 TInt count = aArray.Count(); |
|
159 |
|
160 // Go through whole array |
|
161 for ( TInt i = 0; i < count; i++ ) |
|
162 { |
|
163 const TDesC& curId = aArray[i]; |
|
164 |
|
165 for ( TInt j = i + 1; j < count; j++ ) |
|
166 { |
|
167 if ( CAUtils::NeutralCompare( curId, aArray[j] ) == 0 ) |
|
168 { |
|
169 // Duplicate found, remove from array |
|
170 aArray.Delete( j ); |
|
171 count = aArray.Count(); |
|
172 j--; // decrease by one to keep index the same in next for-loop |
|
173 } |
|
174 } |
|
175 } |
|
176 } |