|
1 /* |
|
2 * Copyright (c) 2002 - 2005 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: |
|
15 * Static class to help mtm service queries. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 // INCLUDE FILES |
|
23 #include <e32base.h> |
|
24 #include <bldvariant.hrh> // For feature flags |
|
25 #include <msvuids.h> // KUidMsvServiceEntry |
|
26 #include <data_caging_path_literals.hrh> // KDC_RESOURCE_FILES_DIR |
|
27 #include <msvapi.h> |
|
28 #include <msvstd.hrh> |
|
29 #include <msvids.h> |
|
30 #include <mtclreg.h> // CClientMtmRegistry |
|
31 #include <mtclbase.h> // CBaseMtm |
|
32 #include <centralrepository.h> // CRepository |
|
33 #include <UiklafInternalCRKeys.h> // KCRUidUiklaf, KUikOODDiskCriticalThreshold |
|
34 |
|
35 #include "muiumsvuiserviceutilitiesinternal.h" |
|
36 |
|
37 #include "MuiuMsvUiServiceUtilities.h" |
|
38 |
|
39 // CONSTANTS |
|
40 const TInt KMuiuCharQuote = '\"'; |
|
41 const TInt KMuiuCharBackSlash = '\\'; |
|
42 const TInt KMuiuCharDot = '.'; |
|
43 const TInt KMuiuCharSpace = ' '; |
|
44 const TInt KMuiuCharDel = 127; |
|
45 const TInt KMuiuCharAt = '@'; |
|
46 const TInt KMuiuSpecialCharStrLen = 12; |
|
47 _LIT( KRFC822Specials,"()<>@,;:\\\"[]"); |
|
48 |
|
49 |
|
50 |
|
51 // ============================ MEMBER FUNCTIONS =============================== |
|
52 |
|
53 |
|
54 // --------------------------------------------------------- |
|
55 // MsvUiServiceUtilitiesr::GetListOfAccountsL |
|
56 // |
|
57 // --------------------------------------------------------- |
|
58 // |
|
59 EXPORT_C CMsvEntrySelection* MsvUiServiceUtilities::GetListOfAccountsL( CMsvSession& aSession, |
|
60 TBool aAlwaysListHidden ) |
|
61 { // static |
|
62 return DoGetListOfAccountsL( aSession, KNullUid, aAlwaysListHidden ); |
|
63 } |
|
64 |
|
65 |
|
66 // --------------------------------------------------------- |
|
67 // MsvUiServiceUtilitiesr::GetListOfAccountsWithMTML |
|
68 // |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 EXPORT_C CMsvEntrySelection* MsvUiServiceUtilities::GetListOfAccountsWithMTML( |
|
72 CMsvSession& aSession, |
|
73 TUid aMtm, TBool aAlwaysListHidden ) |
|
74 { // static |
|
75 return DoGetListOfAccountsL( aSession, aMtm, aAlwaysListHidden ); |
|
76 } |
|
77 |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // MsvUiServiceUtilitiesr::DoGetListOfAccountsL |
|
81 // |
|
82 // --------------------------------------------------------- |
|
83 // |
|
84 CMsvEntrySelection* MsvUiServiceUtilities::DoGetListOfAccountsL( CMsvSession& aSession, |
|
85 TUid aMtm, |
|
86 TBool aAlwaysListHidden ) |
|
87 { |
|
88 CMsvEntrySelection* sel = new( ELeave ) CMsvEntrySelection(); |
|
89 CleanupStack::PushL( sel ); |
|
90 CMsvEntry* entry = aSession.GetEntryL( KMsvRootIndexEntryIdValue ); |
|
91 CleanupStack::PushL( entry ); |
|
92 TBool visible = EFalse; |
|
93 TInt err; |
|
94 |
|
95 TInt cnt = entry->Count(); |
|
96 if ( cnt != 0 ) |
|
97 { |
|
98 entry->SetSortTypeL( TMsvSelectionOrdering( KMsvGroupByType | KMsvGroupByStandardFolders, |
|
99 EMsvSortByDetailsReverse, ETrue ) ); |
|
100 const TMsvEntry* tentry; |
|
101 for (TInt cc = entry->Count(); --cc >= 0; ) |
|
102 { |
|
103 tentry=&(*entry)[cc]; |
|
104 if ( aMtm == KNullUid || tentry->iMtm == aMtm ) |
|
105 { |
|
106 if ( tentry->iType.iUid == KUidMsvServiceEntryValue && |
|
107 tentry->Id() != KMsvLocalServiceIndexEntryIdValue ) |
|
108 { |
|
109 const TBool noRelatedId = tentry->iRelatedId == KMsvNullIndexEntryId || |
|
110 tentry->iRelatedId == tentry->Id(); |
|
111 if ( tentry->Visible() || noRelatedId || aAlwaysListHidden ) |
|
112 { |
|
113 // Add this service if: |
|
114 // it is visible, or,there is no associated related service, or, |
|
115 // we have been asked to list all services. |
|
116 sel->AppendL( tentry->Id() ); |
|
117 } |
|
118 else |
|
119 { |
|
120 // This service is invisible and has a related service. |
|
121 // If the related service is visible we will add it later. |
|
122 // If the related service is also invisible, and has not yet been added, |
|
123 // add this service. |
|
124 TRAP( err, visible = entry->ChildDataL( tentry->iRelatedId ).Visible() ) |
|
125 if ( err == KErrNone && !visible && |
|
126 sel->Find(tentry->iRelatedId) != KErrNone ) |
|
127 { |
|
128 sel->AppendL( tentry->Id() ); |
|
129 } |
|
130 } |
|
131 } |
|
132 } |
|
133 } |
|
134 } |
|
135 CleanupStack::PopAndDestroy( entry ); |
|
136 CleanupStack::Pop( sel ); |
|
137 return sel; |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------- |
|
141 // MsvUiServiceUtilities::IsValidEmailAddressL |
|
142 // |
|
143 // ---------------------------------------------------- |
|
144 EXPORT_C TBool MsvUiServiceUtilities::IsValidEmailAddressL( const TDesC& aAddress ) |
|
145 { |
|
146 TInt c; |
|
147 TInt length = aAddress.Length (); |
|
148 TBufC<KMuiuSpecialCharStrLen> rfc822Specials ( KRFC822Specials ); |
|
149 |
|
150 // first we validate the name portion (name@domain) |
|
151 if ( length && aAddress[0] == KMuiuCharDot ) |
|
152 { |
|
153 return EFalse; |
|
154 } |
|
155 for ( c = 0 ; c < length ; c++ ) |
|
156 { |
|
157 if ( aAddress[c] == KMuiuCharQuote && ( c == 0 || |
|
158 aAddress[c-1] == KMuiuCharDot || aAddress[c-1] == KMuiuCharQuote ) ) |
|
159 { |
|
160 while ( ++c < length ) |
|
161 { |
|
162 if ( aAddress[c] == KMuiuCharQuote ) |
|
163 { |
|
164 if( (c + 1) == length) |
|
165 { |
|
166 return EFalse; |
|
167 } |
|
168 break; |
|
169 } |
|
170 if ( aAddress[c] == KMuiuCharBackSlash && |
|
171 ( aAddress[++c] == KMuiuCharSpace) ) |
|
172 { |
|
173 continue; |
|
174 } |
|
175 if ( aAddress[c] <= KMuiuCharSpace || |
|
176 aAddress[c] >= KMuiuCharDel ) |
|
177 { |
|
178 return EFalse; |
|
179 } |
|
180 } |
|
181 if ( c++ == length ) |
|
182 { |
|
183 return EFalse; |
|
184 } |
|
185 if ( aAddress[c] == KMuiuCharAt ) |
|
186 { |
|
187 break; |
|
188 } |
|
189 if ( aAddress[c] != KMuiuCharDot ) |
|
190 { |
|
191 return EFalse; |
|
192 } |
|
193 continue; |
|
194 } |
|
195 if ( aAddress[c] == KMuiuCharAt ) |
|
196 { |
|
197 break; |
|
198 } |
|
199 if ( aAddress[c] <= KMuiuCharSpace || aAddress[c] >= KMuiuCharDel ) |
|
200 { |
|
201 return EFalse; |
|
202 } |
|
203 if ( rfc822Specials.Locate ( aAddress[c] ) != KErrNotFound ) |
|
204 { |
|
205 return EFalse; |
|
206 } |
|
207 } |
|
208 if ( c == 0 || aAddress[c-1] == KMuiuCharDot ) |
|
209 { |
|
210 return EFalse; |
|
211 } |
|
212 // next we validate the domain portion (name@domain) |
|
213 if ( c == length ) |
|
214 { |
|
215 return EFalse; |
|
216 } |
|
217 else |
|
218 { |
|
219 c++; |
|
220 return IsValidDomainL ( aAddress.Mid ( ( c ) , length-c ) ); |
|
221 } |
|
222 } |
|
223 |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // MsvUiServiceUtilities::IsValidDomainL |
|
227 // ----------------------------------------------------------------------------- |
|
228 EXPORT_C TBool MsvUiServiceUtilities::IsValidDomainL ( const TDesC& aDomain ) |
|
229 { |
|
230 TInt c = 0; |
|
231 TInt length = aDomain.Length (); |
|
232 TBufC<KMuiuSpecialCharStrLen> rfc822Specials ( KRFC822Specials ); |
|
233 |
|
234 if ( length == 0 ) |
|
235 { |
|
236 return EFalse; |
|
237 } |
|
238 |
|
239 do |
|
240 { |
|
241 if ( aDomain[c] == KMuiuCharDot ) |
|
242 { |
|
243 if ( c == 0 || aDomain[c-1] == KMuiuCharDot ) |
|
244 { |
|
245 return EFalse; |
|
246 } |
|
247 } |
|
248 if ( aDomain[c] <= KMuiuCharSpace || aDomain[c] >= KMuiuCharDel ) |
|
249 { |
|
250 return EFalse; |
|
251 } |
|
252 if ( rfc822Specials.Locate( aDomain[c] ) != KErrNotFound ) |
|
253 { |
|
254 return EFalse; |
|
255 } |
|
256 } |
|
257 while ( ++c < length ); |
|
258 |
|
259 return ( aDomain[length-1] != '.' ); |
|
260 } |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 // --------------------------------------------------------- |
|
266 // MsvUiServiceUtilitiesr::DiskSpaceBelowCriticalLevelL |
|
267 // |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C TBool MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelL( CMsvSession& aSession, |
|
271 TInt aBytesToWrite ) |
|
272 { |
|
273 RFs& fs = aSession.FileSession(); |
|
274 TInt err = KErrNone; |
|
275 TVolumeInfo vinfo; |
|
276 TInt currentDrive = TInt( aSession.CurrentDriveL() ); |
|
277 err = fs.Volume( vinfo, currentDrive ); |
|
278 if ( err != KErrNone ) |
|
279 { |
|
280 User::LeaveIfError( err ); |
|
281 } |
|
282 |
|
283 TInt64 freespace = vinfo.iFree; |
|
284 TInt64 newFree = freespace - ( TInt64 )aBytesToWrite; |
|
285 TInt criticalLevel; |
|
286 CRepository* repository = CRepository::NewLC( KCRUidUiklaf ); |
|
287 repository->Get( KUikOODDiskCriticalThreshold, criticalLevel ); |
|
288 CleanupStack::PopAndDestroy( repository ); //repository |
|
289 return ( newFree <= (TInt64)criticalLevel ); |
|
290 } |
|
291 |
|
292 |
|
293 |
|
294 // --------------------------------------------------------- |
|
295 // MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelWithOverheadL |
|
296 // |
|
297 // --------------------------------------------------------- |
|
298 // |
|
299 EXPORT_C TBool MsvUiServiceUtilities::DiskSpaceBelowCriticalLevelWithOverheadL( |
|
300 CMsvSession& aSession, |
|
301 TInt aBytesToWrite, |
|
302 TInt aPhoneMemoryOverheadBytes ) |
|
303 { |
|
304 RFs& fs = aSession.FileSession(); |
|
305 TInt err = KErrNone; |
|
306 TBool belowCritical = EFalse; |
|
307 TVolumeInfo vinfo; |
|
308 TInt criticalLevel; |
|
309 CRepository* repository = CRepository::NewLC( KCRUidUiklaf ); |
|
310 repository->Get( KUikOODDiskCriticalThreshold, criticalLevel ); |
|
311 CleanupStack::PopAndDestroy( repository ); //repository |
|
312 |
|
313 TInt currentDrive = TInt( aSession.CurrentDriveL() ); |
|
314 // Sending eat always some memory from C drive |
|
315 if( currentDrive != EDriveC ) |
|
316 { |
|
317 err = fs.Volume( vinfo, EDriveC ); |
|
318 if ( err != KErrNone ) |
|
319 { |
|
320 User::LeaveIfError( err ); |
|
321 } |
|
322 belowCritical = ( vinfo.iFree < ( (TInt64)aPhoneMemoryOverheadBytes + |
|
323 (TInt64)criticalLevel ) ); |
|
324 } |
|
325 |
|
326 if ( !belowCritical ) |
|
327 { |
|
328 err = fs.Volume( vinfo, currentDrive ); |
|
329 if ( err != KErrNone ) |
|
330 { |
|
331 User::LeaveIfError( err ); |
|
332 } |
|
333 if( currentDrive == EDriveC ) |
|
334 { |
|
335 belowCritical = ( vinfo.iFree < ( (TInt64)aBytesToWrite + |
|
336 (TInt64)aPhoneMemoryOverheadBytes + |
|
337 (TInt64)criticalLevel ) ); |
|
338 } |
|
339 else |
|
340 { |
|
341 belowCritical = ( vinfo.iFree < ( (TInt64)aBytesToWrite + (TInt64)criticalLevel ) ); |
|
342 } |
|
343 } |
|
344 |
|
345 return belowCritical; |
|
346 } |
|
347 |
|
348 // ---------------------------------------------------- |
|
349 // MsvUiServiceUtilities::CallToSenderQueryL |
|
350 // |
|
351 // Deprecated! |
|
352 // ---------------------------------------------------- |
|
353 EXPORT_C TBool MsvUiServiceUtilities::CallToSenderQueryL( |
|
354 const TDesC& aNumber, |
|
355 const TDesC& aName, |
|
356 TBool aDialWithoutQueries) |
|
357 { |
|
358 return MsvUiServiceUtilitiesInternal::CallToSenderQueryL( |
|
359 aNumber, |
|
360 aName, |
|
361 aDialWithoutQueries ); |
|
362 } |
|
363 |
|
364 // ---------------------------------------------------- |
|
365 // MsvUiServiceUtilities::InternetCallToSenderQueryL |
|
366 // |
|
367 // Deprecated! |
|
368 // ---------------------------------------------------- |
|
369 EXPORT_C TBool MsvUiServiceUtilities::InternetCallToSenderQueryL( |
|
370 const TDesC& aNumber, |
|
371 const TDesC& aName, |
|
372 TBool aDialWithoutQueries ) |
|
373 { |
|
374 return MsvUiServiceUtilitiesInternal::InternetCallToSenderQueryL( |
|
375 aNumber, |
|
376 aName, |
|
377 aDialWithoutQueries ); |
|
378 } |
|
379 |
|
380 // ---------------------------------------------------- |
|
381 // MsvUiServiceUtilities::DefaultServiceForMTML |
|
382 // |
|
383 // Deprecated! |
|
384 // ---------------------------------------------------- |
|
385 EXPORT_C TMsvId MsvUiServiceUtilities::DefaultServiceForMTML( |
|
386 CMsvSession& aSession, |
|
387 TUid aMtm, |
|
388 TBool aFindFirstServiceIfNoDefault ) |
|
389 { |
|
390 return MsvUiServiceUtilitiesInternal::DefaultServiceForMTML( |
|
391 aSession, |
|
392 aMtm, |
|
393 aFindFirstServiceIfNoDefault ); |
|
394 } |
|
395 |
|
396 // ---------------------------------------------------- |
|
397 // MsvUiServiceUtilities::InternetCallServiceL |
|
398 // |
|
399 // Deprecated! |
|
400 // ---------------------------------------------------- |
|
401 |
|
402 EXPORT_C TBool MsvUiServiceUtilities::InternetCallServiceL( |
|
403 const TDesC& aSenderNumber, |
|
404 const TDesC& aSenderName, |
|
405 const TDesC& aNumberInFocus, |
|
406 CEikonEnv* aEnv ) |
|
407 { |
|
408 return MsvUiServiceUtilitiesInternal::InternetCallServiceL( |
|
409 aSenderNumber, |
|
410 aSenderName, |
|
411 aNumberInFocus, |
|
412 aEnv ); |
|
413 } |
|
414 |
|
415 |
|
416 // End of File |