|
1 /* |
|
2 * Copyright (c) 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: General utilities |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef ASPUTIL_H |
|
21 #define ASPUTIL_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <ecom.h> |
|
26 #include <eikenv.h> |
|
27 |
|
28 |
|
29 #include <ApSettingsHandlerUI.h> |
|
30 |
|
31 #include <SyncMLClient.h> // for RSyncMLSession |
|
32 #include <SyncMLClientDS.h> // for RSyncMLDataSyncProfile |
|
33 |
|
34 #include <csch_cli.h> // RScheduler |
|
35 |
|
36 |
|
37 #include "AspDefines.h" |
|
38 |
|
39 |
|
40 // CONSTANTS |
|
41 |
|
42 |
|
43 |
|
44 // FORWARD DECLARATIONS |
|
45 class CAspProfile; |
|
46 class CAspProfileList; |
|
47 class CAspContentList; |
|
48 class CAspTask; |
|
49 class CAspFilter; |
|
50 class CAspSchedule; |
|
51 |
|
52 // CLASS DECLARATION |
|
53 |
|
54 |
|
55 /** |
|
56 * TAspParam |
|
57 * |
|
58 * This class is used as general parameter type. |
|
59 */ |
|
60 NONSHARABLE_CLASS (TAspParam) |
|
61 { |
|
62 public: |
|
63 // calling application id |
|
64 TInt iApplicationId; |
|
65 |
|
66 // profile id |
|
67 TInt iProfileId; |
|
68 |
|
69 // dialog mode |
|
70 TInt iMode; |
|
71 |
|
72 // general id number |
|
73 TInt iId; |
|
74 |
|
75 // return value to caller. |
|
76 TInt iReturnValue; |
|
77 |
|
78 // data provider id |
|
79 TInt iDataProviderId; |
|
80 |
|
81 // sync task id |
|
82 TInt iSyncTaskId; |
|
83 |
|
84 // sync profile |
|
85 CAspProfile* iProfile; |
|
86 |
|
87 // sync task |
|
88 CAspTask* iSyncTask; |
|
89 |
|
90 // sync filter |
|
91 CAspFilter* iSyncFilter; |
|
92 |
|
93 // session with sync server |
|
94 RSyncMLSession* iSyncSession; |
|
95 |
|
96 // profile list |
|
97 CAspProfileList* iProfileList; |
|
98 |
|
99 // content list |
|
100 CAspContentList* iContentList; |
|
101 |
|
102 //auto sync schedule setting |
|
103 CAspSchedule* iSchedule; |
|
104 |
|
105 |
|
106 public: |
|
107 TAspParam(TInt aApplicationId); |
|
108 TAspParam(TInt aApplicationId, RSyncMLSession* aSyncSession); |
|
109 }; |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 /** |
|
116 * TAspUtil |
|
117 * |
|
118 * This class contains general utility functions. |
|
119 */ |
|
120 NONSHARABLE_CLASS (TUtil) |
|
121 { |
|
122 public: |
|
123 static void Panic(TInt aReason); |
|
124 static void StrCopy(TDes& aTarget, const TDesC& aSource); |
|
125 static void StrCopy(TDes& aTarget, const TDesC8& aSource); |
|
126 static void StrCopy(TDes8& aTarget, const TDesC& aSource); |
|
127 static HBufC* StrConversion(const TDesC& aText); |
|
128 |
|
129 static void StrAppend(TDes& aTarget, const TDesC& aSource); |
|
130 static void StrInsert(TDes& aTarget, const TDesC& aSource); |
|
131 static void Fill(TDes& aTarget, const TDesC& aOneCharStr, TInt aLength); |
|
132 static TInt StrToInt(const TDesC& aText, TInt& aNum); |
|
133 static TInt AddResFileL(const TDesC& aFile); |
|
134 static TBool IsEmpty(const TDesC& aText); |
|
135 |
|
136 static TInt ProviderIdFromAppId(TInt aApplicationId); |
|
137 static TInt AppIdFromProviderId(TInt aAdapterId); |
|
138 static TBool IsValidAppId(TInt aApplicationId); |
|
139 static TBool IsValidSID(TInt aApplicationId); |
|
140 |
|
141 static void GetDateTextL(TDes& aText, TTime aDateTime); |
|
142 static void GetTimeTextL(TDes& aText, TTime aDateTime); |
|
143 static HBufC* SyncTimeLC(TTime aLastSync); |
|
144 static void GetDateTimeTextL(TDes& aText, TTime aDateTime); |
|
145 static TBool IsToday(TTime aTime); |
|
146 static TTime ConvertUniversalToHomeTime(const TTime& aUniversalTime); |
|
147 static void LaunchHelpAppL(); |
|
148 static void LaunchHelpAppL(CEikonEnv* aEikonkEnv); |
|
149 static TBool SettingEnforcementStateL(); |
|
150 static TBool SettingEnforcementState(); |
|
151 static CDesCArray* NumberConversionLC(CDesCArray* aList); |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 #ifdef _DEBUG |
|
157 public: |
|
158 static void GetMandatoryFieldText(TDes& aText, TInt aStatus); |
|
159 static void Print(const TDesC& aText); |
|
160 static void Print(const TDesC& aText, TInt aNum); |
|
161 |
|
162 static TTime TimeBefore(); |
|
163 static TInt TimeAfter(TTime aBefore); |
|
164 static void TimeAfter(TTime aBefore, const TDesC& aText); |
|
165 static void GetApplicationName(TDes& aText, TInt aApplicationId); |
|
166 #endif |
|
167 }; |
|
168 |
|
169 |
|
170 |
|
171 /** |
|
172 * TStr contains descriptor operations with range checking. |
|
173 */ |
|
174 NONSHARABLE_CLASS (TStr) |
|
175 { |
|
176 public: |
|
177 TStr(const TDesC& aStr); |
|
178 |
|
179 public: |
|
180 TPtrC Mid(TInt aPos, TInt aLen); |
|
181 TPtrC Mid(TInt aPos); |
|
182 TPtrC Left(TInt aPos); |
|
183 TPtrC Right(TInt aPos); |
|
184 TPtrC Trim(); |
|
185 TPtrC SubStr(TInt aStartPos, TInt aEndPos); |
|
186 TPtrC SubStrEx(TInt aStartPos, TInt aEndPos); |
|
187 TInt LastPos(); |
|
188 TInt Len(); |
|
189 TBool Compare(TInt aPos, TChar aChar); |
|
190 TInt Find(TInt aPos, TChar aChar); |
|
191 |
|
192 public: |
|
193 TInt FirstNonSpace(); |
|
194 TInt LastNonSpace(); |
|
195 |
|
196 private: |
|
197 // reference to descriptor |
|
198 const TDesC& iStr; |
|
199 }; |
|
200 |
|
201 |
|
202 /** |
|
203 * TURIParser is used for parsing URI. |
|
204 */ |
|
205 NONSHARABLE_CLASS (TURIParser) |
|
206 { |
|
207 public: |
|
208 enum TDefaultPortNumber |
|
209 { |
|
210 EDefaultHttpPort = 80, |
|
211 EDefaultHttpsPort = 443 |
|
212 }; |
|
213 |
|
214 enum TPortNumberRange |
|
215 { |
|
216 EMinURIPortNumber = 1, |
|
217 EMaxURIPortNumber = 65535 |
|
218 }; |
|
219 |
|
220 public: |
|
221 TURIParser(const TDesC& aStr); |
|
222 |
|
223 public: |
|
224 void GetUriWithoutPort(TDes& aText); |
|
225 void GetUriWithPort(TDes& aText, const TInt aPort); |
|
226 TInt Port(); |
|
227 TInt DefaultPort(); |
|
228 static TBool IsValidUri(const TDesC& aText); |
|
229 static TBool IsValidBluetoothHostAddress(const TDesC& aText); |
|
230 static TBool IsValidPort(const TInt aPort); |
|
231 |
|
232 private: |
|
233 TPtrC ParseHttp(); |
|
234 TPtrC ParseAddress(); |
|
235 TPtrC ParseDocument(); |
|
236 TInt ParsePort(TInt& aPortNumber); |
|
237 TPtrC ParsePort(); |
|
238 |
|
239 private: |
|
240 void GetHttpPos(TInt& aStartPos, TInt& aEndPos); |
|
241 void SkipHttp(); |
|
242 |
|
243 private: |
|
244 // reference to original URI text |
|
245 const TDesC& iOriginalStr; |
|
246 |
|
247 // pointer to original URI text |
|
248 TPtrC iPtr; |
|
249 |
|
250 }; |
|
251 |
|
252 |
|
253 /** |
|
254 * TFlag contains integer flag operations. |
|
255 */ |
|
256 class TFlag |
|
257 { |
|
258 public: |
|
259 /** |
|
260 * C++ default constructor. |
|
261 */ |
|
262 TFlag(TUint32& aFlag); |
|
263 public: |
|
264 /** |
|
265 * Turns given bit(s) on. |
|
266 * @since 2.5 |
|
267 * @param aValue Bits to be turned on. |
|
268 * @return None. |
|
269 */ |
|
270 void SetOn(const TUint32 aValue); |
|
271 |
|
272 /** |
|
273 * Turns given bit(s) off. |
|
274 * @since 2.5 |
|
275 * @param aValue Bits to be turned off. |
|
276 * @return None. |
|
277 */ |
|
278 void SetOff(const TUint32 aValue); |
|
279 |
|
280 /** |
|
281 * Checks if given bit(s) is/are set. |
|
282 * @since 2.5 |
|
283 * @param aValue Bitmap to be checked. |
|
284 * @return None. |
|
285 */ |
|
286 TBool IsOn(const TUint32 aValue) const; |
|
287 |
|
288 private: |
|
289 // reference to flag (integer) |
|
290 TUint32& iFlag; |
|
291 }; |
|
292 |
|
293 |
|
294 /** |
|
295 * CAspIdleWait |
|
296 * |
|
297 * This class is used for waiting synchronously until |
|
298 * active scheduler has completed all pending events. |
|
299 */ |
|
300 NONSHARABLE_CLASS (CAspIdleWait) : public CBase |
|
301 { |
|
302 public: |
|
303 /** |
|
304 * Two-phased constructor. |
|
305 */ |
|
306 static CAspIdleWait* NewL(); |
|
307 |
|
308 /** |
|
309 * Destructor. |
|
310 */ |
|
311 virtual ~CAspIdleWait(); |
|
312 |
|
313 private: |
|
314 |
|
315 /** |
|
316 * C++ default constructor. |
|
317 */ |
|
318 CAspIdleWait(); |
|
319 |
|
320 public: |
|
321 /** |
|
322 * Waits until active schedure has nothing to do. |
|
323 * @param None. |
|
324 * @return None. |
|
325 */ |
|
326 static void CAspIdleWait::WaitL(); |
|
327 |
|
328 private: |
|
329 static TInt IdleCallback(TAny* aThisPtr); |
|
330 |
|
331 private: |
|
332 CActiveSchedulerWait iWait; |
|
333 }; |
|
334 |
|
335 |
|
336 |
|
337 |
|
338 /** |
|
339 * MAspActiveCallerObserver |
|
340 * |
|
341 * MAspActiveCallerObserver is for observing CAspActiveCaller. |
|
342 */ |
|
343 class MAspActiveCallerObserver |
|
344 { |
|
345 public: |
|
346 virtual void HandleActiveCallL(TInt aCallId) = 0; |
|
347 }; |
|
348 |
|
349 |
|
350 /** |
|
351 * CAspActiveCaller |
|
352 * |
|
353 * CAspActiveCaller is used for generating a call from active scheduler. |
|
354 */ |
|
355 NONSHARABLE_CLASS (CAspActiveCaller) : public CActive |
|
356 { |
|
357 public: |
|
358 /** |
|
359 * Two-phased constructor. |
|
360 */ |
|
361 static CAspActiveCaller* NewL(MAspActiveCallerObserver* aObserver); |
|
362 |
|
363 /** |
|
364 * Destructor. |
|
365 */ |
|
366 virtual ~CAspActiveCaller(); |
|
367 |
|
368 private: |
|
369 /** |
|
370 * C++ default constructor. |
|
371 */ |
|
372 CAspActiveCaller(MAspActiveCallerObserver* aObserver); |
|
373 |
|
374 /** |
|
375 * By default Symbian 2nd phase constructor is private. |
|
376 */ |
|
377 void ConstructL(); |
|
378 |
|
379 public: |
|
380 /** |
|
381 * Calls observer using active object framework. |
|
382 * @param aCallId. |
|
383 * @param aMilliseconds Delay before observer is called. |
|
384 * @return None |
|
385 */ |
|
386 void Start(TInt aCallId, TInt aMilliseconds); |
|
387 |
|
388 /** |
|
389 * Make active scheduler call RunL. |
|
390 * @param None |
|
391 * @return None |
|
392 */ |
|
393 void Request(); |
|
394 |
|
395 private: |
|
396 /** |
|
397 * From CActive. Called when asynchronous request completes. |
|
398 * @param None |
|
399 * @return None |
|
400 */ |
|
401 void RunL(); |
|
402 |
|
403 /** |
|
404 * From CActive. Cancels asynchronous request. |
|
405 * @param None |
|
406 * @return None |
|
407 */ |
|
408 void DoCancel(); |
|
409 |
|
410 private: |
|
411 // call that is passed to observer |
|
412 TInt iCallId; |
|
413 |
|
414 // timer |
|
415 RTimer iTimer; |
|
416 |
|
417 // observer that gets called |
|
418 MAspActiveCallerObserver* iObserver; |
|
419 }; |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 /** |
|
426 * TAspBearerItem |
|
427 * |
|
428 */ |
|
429 NONSHARABLE_CLASS (TAspBearerItem) |
|
430 { |
|
431 public: |
|
432 TInt iBearerType; |
|
433 TBuf<KBufSize> iBearerName; |
|
434 }; |
|
435 |
|
436 |
|
437 |
|
438 /** |
|
439 * CAspBearerHandler |
|
440 * |
|
441 * CAspBearerHandler is for constructing list control for selecting |
|
442 * bearer type (internet, bluetooth etc.) |
|
443 */ |
|
444 NONSHARABLE_CLASS (CAspBearerHandler) : public CBase |
|
445 { |
|
446 public: |
|
447 /** |
|
448 * Two-phased constructor. |
|
449 */ |
|
450 static CAspBearerHandler* NewL(const TAspParam& aParam); |
|
451 |
|
452 /** |
|
453 * Destructor. |
|
454 */ |
|
455 virtual ~CAspBearerHandler(); |
|
456 |
|
457 private: |
|
458 /** |
|
459 * C++ default constructor. |
|
460 */ |
|
461 CAspBearerHandler(const TAspParam& aParam); |
|
462 |
|
463 /** |
|
464 * By default Symbian 2nd phase constructor is private. |
|
465 */ |
|
466 void ConstructL(); |
|
467 |
|
468 public: |
|
469 /** |
|
470 * Finds out whether bearer type is supported. |
|
471 * @param aBearer Bearer type. |
|
472 * @return ETrue if supported, EFalse otherwise. |
|
473 */ |
|
474 TBool IsSupported(TInt aBearer); |
|
475 |
|
476 /** |
|
477 * Finds out bearer type for list item. |
|
478 * @param aIndex List index. |
|
479 * @return Bearer type. |
|
480 */ |
|
481 TInt BearerForListIndex(TInt aIndex); |
|
482 |
|
483 /** |
|
484 * Finds out list position for aBearer. |
|
485 * @param aBearer. |
|
486 * @return List array index. |
|
487 */ |
|
488 TInt ListIndexForBearer(TInt aBearer); |
|
489 |
|
490 /** |
|
491 * Creates supported bearer list. |
|
492 * @param None. |
|
493 * @return None. |
|
494 */ |
|
495 void CreateSupportedBearerListL(); |
|
496 |
|
497 /** |
|
498 * Finds out default bearer for a device. |
|
499 * @param None. |
|
500 * @return Bearer type. |
|
501 */ |
|
502 TInt DefaultBearer(); |
|
503 |
|
504 /** |
|
505 * Gets bearer name string. |
|
506 * @param aText. |
|
507 * @param aBearer. |
|
508 * @return None. |
|
509 */ |
|
510 void GetBearerName(TDes& aText, TInt aBearerType); |
|
511 |
|
512 /** |
|
513 * Builds array of bearer names for ui list control. |
|
514 * @param None. |
|
515 * @return Bearer name array. |
|
516 */ |
|
517 CDesCArray* BuildBearerListLC(); |
|
518 |
|
519 /** |
|
520 * Finds out how many bearer types are supported. |
|
521 * @param None. |
|
522 * @return Bearer count. |
|
523 */ |
|
524 TInt SupportedBearerCount(); |
|
525 |
|
526 /** |
|
527 * Convert asp bearer id to sml beareer id. |
|
528 * @param aId. |
|
529 * @return Bearer id. |
|
530 */ |
|
531 static TInt SmlBearerId(const TInt aId); |
|
532 |
|
533 /** |
|
534 * Convert sml bearer id to asp beareer id. |
|
535 * @param aId. |
|
536 * @return Bearer id. |
|
537 */ |
|
538 static TInt AspBearerId(const TInt aId); |
|
539 |
|
540 private: |
|
541 // sync session |
|
542 RSyncMLSession* iSyncSession; |
|
543 |
|
544 // list of bearers that can shown in ui list |
|
545 RArray<TAspBearerItem> iList; |
|
546 }; |
|
547 |
|
548 |
|
549 /** |
|
550 * TAspAccessPointItem |
|
551 * |
|
552 */ |
|
553 NONSHARABLE_CLASS (TAspAccessPointItem) |
|
554 { |
|
555 public: |
|
556 TInt iUid; |
|
557 TBuf<KBufSize> iName; |
|
558 |
|
559 TInt iUid2; |
|
560 }; |
|
561 |
|
562 |
|
563 |
|
564 /** |
|
565 * CAspAccessPointHandler |
|
566 * |
|
567 * CAspAccessPointHandler is for setting internet access points. |
|
568 */ |
|
569 NONSHARABLE_CLASS (CAspAccessPointHandler) : public CBase |
|
570 { |
|
571 public: |
|
572 enum TExitMode |
|
573 { |
|
574 EAspDialogSelect, |
|
575 EAspDialogCancel, |
|
576 EAspDialogExit |
|
577 }; |
|
578 |
|
579 // when ap is set to -1, ap is always asked before sync |
|
580 static const TInt KAskAlways = -1; |
|
581 |
|
582 static const TInt KDefaultConnection = -2; |
|
583 |
|
584 public: |
|
585 /** |
|
586 * Two-phased constructor. |
|
587 */ |
|
588 static CAspAccessPointHandler* NewL(const TAspParam& aParam); |
|
589 |
|
590 /** |
|
591 * Destructor. |
|
592 */ |
|
593 virtual ~CAspAccessPointHandler(); |
|
594 |
|
595 private: |
|
596 /** |
|
597 * C++ default constructor. |
|
598 */ |
|
599 CAspAccessPointHandler(const TAspParam& aParam); |
|
600 |
|
601 /** |
|
602 * By default Symbian 2nd phase constructor is private. |
|
603 */ |
|
604 void ConstructL(); |
|
605 |
|
606 public: |
|
607 /** |
|
608 * Displays dialog for selecting one access point. |
|
609 * @param aItem. |
|
610 * @return ETrue if user selected access point, EFalse otherwise. |
|
611 */ |
|
612 TInt ShowApSelectDialogL(TAspAccessPointItem& aItem); |
|
613 |
|
614 /** |
|
615 * Gets access point info. |
|
616 * @param aItem. |
|
617 * @return Error value. |
|
618 */ |
|
619 TInt GetInternetApInfo(TAspAccessPointItem& aItem); |
|
620 |
|
621 private: |
|
622 /** |
|
623 * Gets access point info. |
|
624 * @param aItem. |
|
625 * @return Error value. |
|
626 */ |
|
627 TInt GetApInfo(TAspAccessPointItem& aItem); |
|
628 |
|
629 /** |
|
630 * Gets access point info. |
|
631 * @param aItem. |
|
632 * @return Error value. |
|
633 */ |
|
634 TInt GetApInfoL(TAspAccessPointItem& aItem); |
|
635 |
|
636 /** |
|
637 * Utility function. |
|
638 * @param None. |
|
639 * @return Bearer flags. |
|
640 */ |
|
641 TInt BearerFlags(); |
|
642 |
|
643 |
|
644 private: |
|
645 |
|
646 // communications database |
|
647 CCommsDatabase* iCommDb; |
|
648 |
|
649 //access point utilities |
|
650 CApUtils* iApUtil; |
|
651 |
|
652 // access point selection utility |
|
653 CApSelect* iApSelect; |
|
654 |
|
655 // dialog parameters |
|
656 TAspParam* iParam; |
|
657 |
|
658 }; |
|
659 |
|
660 |
|
661 |
|
662 /** |
|
663 * TAspSyncError |
|
664 * |
|
665 * TAspSyncError is used for error code handling. |
|
666 */ |
|
667 NONSHARABLE_CLASS (TAspSyncError) |
|
668 { |
|
669 |
|
670 public: |
|
671 static HBufC* GetSmlErrorTextL(TInt aErrorCode, TInt aTransport); |
|
672 static HBufC* GetSmlErrorText(TInt aErrorCode, TInt aTransport); |
|
673 static TInt GetSmlErrorValue(TInt aErrorCode); |
|
674 |
|
675 #ifdef _DEBUG |
|
676 public: |
|
677 static void GetSyncMLErrorText(TDes& aText, TInt aError); |
|
678 #endif |
|
679 |
|
680 }; |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 #endif // ASPUTIL_H |
|
686 |
|
687 |
|
688 // End of file |